’new’ in JVM -- What happen when ’new’ is called?

1,146 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,146
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ’new’ in JVM -- What happen when ’new’ is called?

    1. 1. new in JVM (2/2)What happen when new is called? Kengo TODA 2012/May/30
    2. 2. Summary for previousOpcode ‘new’ doesn’t call constructor.Data size is fixed at first (by opcode ‘new’). JVM can decide size from class definition. How?
    3. 3. Answer:the JVM specification has NO page for ourtheme ;(
    4. 4. the IBM says...In the IBM JVM, each data has2 parts: Headers size+flags, mptr, locknflags Object data ↑ quoted from dW
    5. 5. about headersEach instance has headers. It means: each instance eats 16 bytes in 32bit JVM each instance eats 24 bytes in 64bit JVMObject size is decided according to JVMarchitecture.
    6. 6. about Object data Object data = set of instance fields This data eats contiguous space on memoryObject data of class with 3 fields char byte int
    7. 7. about Object dataObject data = set of instance fields boolean and byte eat 1 byte char and short eat 2 bytes int and float eat 4 bytes long and double eat 8 bytes
    8. 8. about Object dataspecial cases: array: eats (length * element size) bytes reference: 4 bytes on 32bit JVM 8 bytes on 64bit JVM
    9. 9. exampleclass which has 2 ‘int’s on 64bit JVM 24 bytes + 4 * 2 bytes = 32 bytesclass which has ‘byte[16]’ on 64bit JVM 24 bytes + 1 * 16 bytes = 40 bytes
    10. 10. example (corner case)class which has 2 reference on 64bit JVM 24 bytes + 8 * 2 bytes = 40 bytes 24 bytes + 4 * 2 bytes = 32 bytes if Ordinary Object Pointer is enabled
    11. 11. example (corner case)class which has 1 ‘int’s on 64bit JVM 24 bytes + 4 bytes -> 32 bytes ≒ 24 + 4 because JVM uses 8 bytes memory block
    12. 12. key pointObject size = size of header + Σ (field).Array requires contiguous space to store.
    13. 13. ReferencesThe Java™ Virtual Machine SpecificationSensible Sanitation -- Understanding the IBMJava Garbage CollectorFrom Java code to Java heap

    ×