new in JVM (1/2)             What happen when new is called?                 Kengo TODA 2012/May/312年5月2日水曜日
On condition that:             You already know               what is reference               what is memory              ...
This code becomes...    public class Test {    ! public static void main(String[] args) {    ! ! Test test = new Test();  ...
this byte code.public static void main(java.lang.String[]);  Code:   0:! new!#1; //class Test   3:! dup   4:! invokespecia...
new => 3 opcodes                               new             new   javac       dup                           invokespeci...
opcode ‘new’                                              new             ‘new’ allocates memory             (Java heap) t...
opcode ‘dup’             ‘dup’ copies a reference   dup             created by ‘new’.12年5月2日水曜日
opcode ‘invokespecial’             ‘invokespecial’ invokes <init> method of             specified class. <init> is name of ...
Summary                                  1.‘new’         Java heap                                    u rn                ...
key point             Opcode ‘new’ doesn’t call constructor.               We can get an reference to uninitialized       ...
References             newするとJVM内で何が起こるのかという話               前編 / 後編             The Java™ Virtual Machine Specification    ...
Upcoming SlideShare
Loading in...5
×

'new' in JVM -- What happen when 'new' is called? 1st

635

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
635
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

'new' in JVM -- What happen when 'new' is called? 1st

  1. 1. new in JVM (1/2) What happen when new is called? Kengo TODA 2012/May/312年5月2日水曜日
  2. 2. On condition that: You already know what is reference what is memory what is ‘class file’12年5月2日水曜日
  3. 3. This code becomes... public class Test { ! public static void main(String[] args) { ! ! Test test = new Test(); ! } }12年5月2日水曜日
  4. 4. this byte code.public static void main(java.lang.String[]); Code: 0:! new!#1; //class Test 3:! dup 4:! invokespecial!#16; //Method "<init>":()V 7:! astore_1 8:! return12年5月2日水曜日
  5. 5. new => 3 opcodes new new javac dup invokespecial12年5月2日水曜日
  6. 6. opcode ‘new’ new ‘new’ allocates memory (Java heap) to store instance data. Allocated memory isn’t initialized. You get a reference to allocated instance.12年5月2日水曜日
  7. 7. opcode ‘dup’ ‘dup’ copies a reference dup created by ‘new’.12年5月2日水曜日
  8. 8. opcode ‘invokespecial’ ‘invokespecial’ invokes <init> method of specified class. <init> is name of constructor. This opcode consumes a reference, so JVM has to call ‘dup’ at first. Finally instance is fully invokespecial initialized!12年5月2日水曜日
  9. 9. Summary 1.‘new’ Java heap u rn .ret 4 instance reference 2.‘dup’ reference 3.‘invokespecial’12年5月2日水曜日
  10. 10. key point Opcode ‘new’ doesn’t call constructor. We can get an reference to uninitialized instance. Data size is fixed at first (by opcode ‘new’). JVM can decide size from class definition. We have to create new instance to expand data size. @see ArrayList#grow(int).12年5月2日水曜日
  11. 11. References newするとJVM内で何が起こるのかという話 前編 / 後編 The Java™ Virtual Machine Specification Java theory and practice: Fixing the Java Memory Model, Part 112年5月2日水曜日
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×