Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
new in JVM (2/2)What happen when new is called?   Kengo TODA 2012/May/30
Summary for previousOpcode ‘new’ doesn’t call constructor.Data size is fixed at first (by opcode ‘new’).  JVM can decide siz...
Answer:the JVM specification has NO page for ourtheme ;(
the IBM says...In the IBM JVM, each data has2 parts:  Headers    size+flags, mptr, locknflags  Object data                  ...
about headersEach instance has headers. It means:  each instance eats 16 bytes in 32bit JVM  each instance eats 24 bytes i...
about Object data Object data = set of instance fields This data eats contiguous space on memoryObject data of class with 3...
about Object dataObject data = set of instance fields  boolean and byte eat 1 byte  char and short eat 2 bytes  int and floa...
about Object dataspecial cases:  array: eats (length * element size) bytes  reference:     4 bytes on 32bit JVM     8 byte...
exampleclass which has 2 ‘int’s on 64bit JVM  24 bytes + 4 * 2 bytes = 32 bytesclass which has ‘byte[16]’ on 64bit JVM  24...
example (corner case)class which has 2 reference on 64bit JVM  24 bytes + 8 * 2 bytes = 40 bytes  24 bytes + 4 * 2 bytes =...
example (corner case)class which has 1 ‘int’s on 64bit JVM  24 bytes + 4 bytes -> 32 bytes ≒ 24 + 4  because JVM uses 8 by...
key pointObject size = size of header + Σ (field).Array requires contiguous space to store.
ReferencesThe Java™ Virtual Machine SpecificationSensible Sanitation -- Understanding the IBMJava Garbage CollectorFrom Jav...
Upcoming SlideShare
Loading in …5
×

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

1,425 views

Published on

Published in: Technology
  • Be the first to comment

’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

×