Java object size

How is it possible that the minimum size of a Java object is 8 bytes (object header only),

What is the memory consumption of an object in Java?

if in a C ++ class representing a java object,

http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/9b0ca45cd756/src/share/vm/oops/oop.hpp

I see that the class has more members

class oopDesc {
  friend class VMStructs;
 private:
  volatile markOop  _mark; // this is the object header
  union _metadata {
    wideKlassOop    _klass;
    narrowOop       _compressed_klass;
  } _metadata; // what about size of this member?
+1
source share
2 answers

This is possible because the 32-bit JVM object contains 4 bytes of the label header and 4 bytes of the class reference. Header markers contain different information depending on the type of object (bit sizes):

normal objects → unused: 25 hash: 31 cms_free: 1 age: 4 biased_lock: 1 lock: 2

→ JavaThread *: 54 epoch: 2 cms_free: 1 age: 4 biased_lock: 1 lock: 2

+1

. JVMTI .

, oops. , JOL, OpenJDK. , sourc.

0

Source: https://habr.com/ru/post/1583813/


All Articles