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 static org.junit.Assert.*; | |
import static org.hamcrest.CoreMatchers.*; | |
import java.io.File; | |
import java.io.IOException; | |
import org.junit.Test; | |
import org.junit.rules.TemporaryFolder; | |
public class TemporaryFolderTest { |
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 static void copyFieldByField(Object src, Object dest) { | |
copyFields(src, dest, src.getClass()); | |
} | |
private static void copyFields(Object src, Object dest, Class<?> klass) { | |
Field[] fields = klass.getDeclaredFields(); | |
for (Field f : fields) { | |
f.setAccessible(true); | |
copyFieldValue(src, dest, f); | |
} |
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
@GenerateMicroBenchmark | |
public Object copyFieldByFieldGetFieldsEveryTime() { | |
return FieldsCopy.INSTANCE.copy(); | |
} | |
@GenerateMicroBenchmark | |
public Object copyFieldByFieldUseCacheFields() { | |
return CachedFieldsCopy.INSTANCE.copy(); | |
} |
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.invoke.MethodHandle; | |
import java.lang.invoke.MethodHandles; | |
class Base { | |
int x = 13; | |
} | |
class Derived extends Base { | |
public long m; | |
} |
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
private static MethodHandle prepareGetter(MethodHandle mh) { | |
return mh.asType(mh.type().changeParameterType(0, Object.class) | |
.changeReturnType(Object.class)); | |
} | |
private static MethodHandle prepareSetter(MethodHandle mh) { | |
return mh.asType(mh.type().changeParameterType(0, Object.class) | |
.changeParameterType(1, Object.class)); | |
} |
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 com.vyazelenko.blog.copyobject.primitives.clone; | |
import com.vyazelenko.blog.copyobject.primitives.BaseClass; | |
public class CloneCopy extends BaseClass implements Cloneable { | |
public static final CloneCopy INSTANCE; | |
static { | |
INSTANCE = new CloneCopy(); | |
INSTANCE.init(); |
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 com.vyazelenko.blog.copyobject.primitives.constructor; | |
import com.vyazelenko.blog.copyobject.primitives.BaseClass; | |
public class ConstructorCopy extends BaseClass implements Cloneable { | |
public static final ConstructorCopy INSTANCE; | |
static { | |
INSTANCE = new ConstructorCopy(); | |
INSTANCE.init(); |
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 com.vyazelenko.blog.copyobject.primitives; | |
import com.vyazelenko.blog.copyobject.Copyable; | |
import com.vyazelenko.blog.copyobject.HashUtils; | |
abstract class Root implements Copyable { | |
private int field1; | |
private char field2; | |
public boolean field6; | |
byte abc; |
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
/* | |
* Defined in the hotspot/src/share/vm/classfile/vmSymbols.hpp | |
*/ | |
#define VM_SYMBOLS_DO(template, do_alias) \ | |
/* commonly used class names */ \ | |
template(java_lang_System, "java/lang/System") \ | |
template(java_lang_Object, "java/lang/Object") \ | |
... |
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
java -XX:+PrintCompilation com.vyazelenko.blog.copyobject.TestClone | |
59 1 java.lang.String::hashCode (55 bytes) | |
61 2 java.lang.String::indexOf (70 bytes) | |
69 3 sun.nio.cs.UTF_8$Encoder::encode (361 bytes) | |
77 4 java.util.ArrayList::add (29 bytes) | |
77 5 java.util.ArrayList::ensureCapacityInternal (23 bytes) | |
77 7 n java.lang.Object::clone (native) | |
78 6 java.util.ArrayList::ensureExplicitCapacity (26 bytes) | |
78 8 com.vyazelenko.blog.copyobject.TestClone::callCopy (7 bytes) | |
78 9 com.vyazelenko.blog.copyobject.primitives.clone.CloneCopy::copy (5 bytes) |
OlderNewer