Skip to content

Instantly share code, notes, and snippets.

Dmitry Vyazelenko vyazelenko

Block or report user

Report or block vyazelenko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vyazelenko
vyazelenko / CloneIsShallow.java
Created Dec 10, 2015
Java code to demonstrate that clone() is shallow by default
View CloneIsShallow.java
import java.util.Arrays;
import java.util.List;
class ClassWithState implements Cloneable {
int x = 15;
Long y = Long.MAX_VALUE / 3;
String z = new String("new Z");
List<String> data = Arrays.asList("a", "b", "and", "c");
@Override
@vyazelenko
vyazelenko / clone_complete_asm_code.asm
Last active Dec 27, 2015
Complete ASM code for TestClone case
View clone_complete_asm_code.asm
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/hsdis-amd64.dylib
Decoding compiled method 0x00000001063bb1d0:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'indexOf' '(II)I' in 'java/lang/String'
# this: rsi:rsi = 'java/lang/String'
# parm0: rdx = int
@vyazelenko
vyazelenko / constructor_complete_asm_code.asm
Last active Dec 27, 2015
Complete ASM code for TestConstructor case
View constructor_complete_asm_code.asm
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/hsdis-amd64.dylib
Decoding compiled method 0x000000010c060290:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'indexOf' '(II)I' in 'java/lang/String'
# this: rsi:rsi = 'java/lang/String'
# parm0: rdx = int
@vyazelenko
vyazelenko / TestClonePCM.txt
Created Nov 1, 2013
Intel Performance Counter Monitor output for TestClone case
View TestClonePCM.txt
pcm.x "java -Xms4g -Xmx5g com.vyazelenko.blog.copyobject.TestClone" -nc -ns
Intel(r) Performance Counter Monitor V2.5.1 (2013-06-25 13:44:03 +0200 ID=76b6d1f)
Copyright (c) 2009-2012 Intel Corporation
Num logical cores: 8
Num sockets: 1
Threads per core: 2
Core PMU (perfmon) version: 3
@vyazelenko
vyazelenko / TestConstructorPCM.txt
Last active Dec 27, 2015
Intel Performance Counter Monitor output for TestConstructor case
View TestConstructorPCM.txt
"java -Xms4g -Xmx5g com.vyazelenko.blog.copyobject.TestConstructor" -nc -ns
Intel(r) Performance Counter Monitor V2.5.1 (2013-06-25 13:44:03 +0200 ID=76b6d1f)
Copyright (c) 2009-2012 Intel Corporation
Num logical cores: 8
Num sockets: 1
Threads per core: 2
Core PMU (perfmon) version: 3
View TestConstructor.java
package com.vyazelenko.blog.copyobject;
import com.vyazelenko.blog.copyobject.primitives.clone.CloneCopy;
import com.vyazelenko.blog.copyobject.primitives.constructor.ConstructorCopy;
import java.util.ArrayList;
import java.util.List;
public class TestConstructor {
public static List<Copyable> results;
View TestClone.java
package com.vyazelenko.blog.copyobject;
import com.vyazelenko.blog.copyobject.primitives.clone.CloneCopy;
import java.util.ArrayList;
import java.util.List;
public class TestClone {
public static List<Copyable> results;
@vyazelenko
vyazelenko / CloneGeneratedAssembler.asm
Last active Dec 26, 2015
Assembly dump for TestClone#callCopy() method
View CloneGeneratedAssembler.asm
Decoding compiled method 0x00000001063b9390:
Code:
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'callCopy' '()Lcom/vyazelenko/blog/copyobject/Copyable;' in 'com/vyazelenko/blog/copyobject/TestClone'
# [sp+0x20] (sp of caller)
0x00000001063b94e0: mov %eax,-0x14000(%rsp)
0x00000001063b94e7: push %rbp
0x00000001063b94e8: sub $0x10,%rsp
@vyazelenko
vyazelenko / CopyConstructorGeneratedAssembler.asm
Last active Dec 26, 2015
Assembly dump for TestConstructor#callCopy() method
View CopyConstructorGeneratedAssembler.asm
Decoding compiled method 0x000000010c064b50:
Code:
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'callCopy' '()Lcom/vyazelenko/blog/copyobject/Copyable;' in 'com/vyazelenko/blog/copyobject/TestConstructor'
# [sp+0x20] (sp of caller)
0x000000010c064ca0: mov %eax,-0x14000(%rsp)
0x000000010c064ca7: push %rbp
0x000000010c064ca8: sub $0x10,%rsp ;*synchronization entry
@vyazelenko
vyazelenko / PrintCompilationCopyContructor.txt
Last active Dec 26, 2015
Results of running TestConstructor with -XX:+PrintCompilation
View PrintCompilationCopyContructor.txt
java -XX:+PrintCompilation com.vyazelenko.blog.copyobject.TestConstructor
59 1 java.lang.String::hashCode (55 bytes)
61 2 java.lang.String::indexOf (70 bytes)
70 3 sun.nio.cs.UTF_8$Encoder::encode (361 bytes)
77 4 java.lang.Object::<init> (1 bytes)
80 5 java.util.ArrayList::add (29 bytes)
80 6 java.util.ArrayList::ensureCapacityInternal (23 bytes)
81 7 java.util.ArrayList::ensureExplicitCapacity (26 bytes)
81 8 com.vyazelenko.blog.copyobject.TestConstructor::callCopy (7 bytes)
81 9 com.vyazelenko.blog.copyobject.primitives.constructor.ConstructorCopy::copy (9 bytes)
You can’t perform that action at this time.