This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HashCode { | |
public static void main(String[] args) { | |
Object object = new Object(); | |
printHash(object.hashCode()); | |
Field field = Unsafe.class.getDeclaredField("theUnsafe"); | |
field.setAccessible(true); | |
Unsafe unsafe = (Unsafe) field.get(null); | |
long hashCode = 0; | |
for (long index = 7; index > 0; index--) { // First byte is not part of the hash code | |
hashCode |= (unsafe.getByte(object, index) & 0x00FF) << ((index - 1) * 8); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.annotation.*; | |
public class ManifestAnnotation implements SampleAnnotation { | |
private final String value; | |
public ManifestAnnotation(String value) { | |
this.value = value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package benchmark; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.runner.Runner; | |
import org.openjdk.jmh.runner.RunnerException; | |
import org.openjdk.jmh.runner.options.OptionsBuilder; | |
import java.util.concurrent.TimeUnit; | |
@State(Scope.Group) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package benchmark; | |
import org.openjdk.jmh.annotations.*; | |
import java.lang.invoke.MethodHandle; | |
import java.lang.invoke.MethodHandles; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.concurrent.TimeUnit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TypeSafeJPA { | |
class MyBean { | |
private String foo; | |
private int bar; | |
public String getFoo() { | |
return foo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.objectweb.asm.Opcodes; | |
import java.lang.reflect.Array; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.Arrays; | |
import java.util.List; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.hamcrest.CoreMatchers.not; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Java8Rule implements MethodRule { | |
private final boolean java8OrHigher; | |
public Java8Rule() { | |
java8OrHigher = currentByteCodeLevel() >= (0 << 16 | 52); | |
} | |
@Override | |
public Statement apply(Statement base, FrameworkMethod method, Object target) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import java.nio.charset.StandardCharsets; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Optional; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.stream.Collectors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MethodDescriptor { | |
public static final char OBJECT_REFERENCE_SYMBOL = 'L'; | |
public static final char ARRAY_REFERENCE_SYMBOL = '['; | |
public static final char DOUBLE_SYMBOL = 'D'; | |
public static final char LONG_SYMBOL = 'J'; | |
public static final char BOOLEAN_SYMBOL = 'Z'; | |
public static final char BYTE_SYMBOL = 'B'; | |
public static final char SHORT_SYMBOL = 'S'; | |
public static final char CHAR_SYMBOL = 'C'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Before; | |
import org.junit.Test; | |
import sun.misc.Unsafe; | |
import sun.reflect.ReflectionFactory; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.Modifier; | |
import static org.junit.Assert.assertEquals; |