对象的内存布局

对象在内存中存储的布局分为:
对象头(Header)、实例数据(Instance Data)和对齐填充(Padding)
1. 对象头包括两部分信息,第一部分用于存储对象自身的运行时数据,如哈希码(HashCode)、GC分代年龄、锁状态标志、线程持有的锁、
   偏向线程ID、偏向时间戳等
   对象头信息是与对象自身定义的数据无关的额外存储成本,考虑到虚拟机的空间效率,Mark Word被设计成一个非固定的数据结构
   以便在 极小的空间内存储尽量多的信息,它会根据对象的状态复用自己的存储空间。例如:在32位的HotSpot虚拟机中,如果对象处于未
   被锁定的状态下,那么Mark Word的32bit空间中的25bit用于存储对象哈希码,4bit用于存储对象分代年龄,2bit用于存储锁标志位,
   1bit固定为0.
   其他状态还有:轻量级锁定、重量级锁定、GC标记、可偏向
   对象头的另外一部分是类型指针,即对象指向他的类元素数据的指针,虚拟机通过这个指针来确定这个对象是哪个类的实例。
2. 实例数据部分是对象真正存储的有效信息,也是在程序代码中所定义的各自类型的字段内容。无论是从父类继承下来的,还是在
   子类中定义的,都需要记录下来。这部分存储顺序会受到虚拟机分配策略参数(FieldsAllocationStyle)和字段在Java源码中定义
   顺序的影响。Hotspot虚拟机默认的分配策略为longs/doubles、ints、shorts/chars、bytes/booleans、opps(Ordinary Object Pointers)
   从分配策略可以看出,相同宽度的字段总是被分配到一起。
   在满足在咱这个前提条件下,在父类中定义的变量会出现在子类之前。
3. 第三部对齐填充并不是必然存在的,也没有特别的含义,仅仅起着占位符的作用。由于HotSpot VM的自动内存管理系统要求对象起始地址
   必须是8字节的整数倍,换句话说,就是对象的大小必须是8字节的整数倍。而且对象部分正好是8字节的倍数(1倍或者2倍),
   因此,当对象实例数据部分没有对齐时,就需要通过对齐填充来补全。

编译hotspot进展

1./usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lgcc_s

2. invalid suffix on literal; C++11 requires a space between literal and string macro [-Werror=literal-suffix]
     gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]"
无效的后缀文字;c++ 11需要在文字和字符串宏之间有一个空格[-Werror= literalsuffix]
修改为gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
3. error: "__LEAF" redefined [-Werror]
 #define __LEAF(result_type, header)                                  \
修改为:
 429 #ifdef __LEAF
    430 #undef __LEAF
    431 #define __LEAF(result_type, header)                                  \
    432   TRACE_CALL(result_type, header)                                    \
    433   debug_only(NoHandleMark __hm;)                                     \
    434   /* begin of body */
    435 #endif
4. error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated [-Werror=deprecated-declarations]
   if((status = ::readdir_r(dirp, dbuf, &p)) != 0)  未解决
vi /usr/include/dirent.h
#pragma disable(warning:4244)
For existing releases (7,8, 9), I think the right thing is to just disable the deprecation warning
错误:'int readdir_r(DIR*, dirent*, dirent**)'被弃用[-Werror=不支持声明]
/* Reentrant version of `readdir'.  Return in RESULT a pointer to the
        next entry.
        This function is a possible cancellation point and therefore not
        marked with __THROW.  */
     # ifndef __USE_FILE_OFFSET64
     extern int readdir_r (DIR *__restrict __dirp,
                           struct dirent *__restrict __entry,
                           struct dirent **__restrict __result)
          __nonnull ((1, 2, 3)) __attribute_deprecated__;
     # else
     #  ifdef __REDIRECT
    extern int __REDIRECT (readdir_r,
                           (DIR *__restrict __dirp,
                             struct dirent *__restrict __entry,
                             struct dirent **__restrict __result),
                            readdir64_r)
      __nonnull ((1, 2, 3)) __attribute_deprecated__;
    #  else
     #   define readdir_r readdir64_r
     #  endif
    # endif

猜你喜欢

转载自www.cnblogs.com/mutong1228/p/9011852.html