Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ordinary Object Pointer in JVM

Ordinary Object Pointer in JVM

Go Tanaka

May 20, 2017
Tweet

More Decks by Go Tanaka

Other Decks in Technology

Transcript

  1. Go Tanaka 1)14DBMB+BWB4DSJQU+BWB 8 : 1.5 : 0.5 : 0

    【運営スタッフ】 関西Javaエンジニアの会 Scala関西 Summit Freelance Engineer @UBO@HP
  2. 0SEJOBSZ0CKFDU1PJOUFS _mark _klass Fields 32-bit cpu 64-bit cpu 4 byte

    8 byte 4 byte 8 byte -XX:ObjectAlignmentInBytes=8 ͢΂ͯͷΦϒδΣΫτ͸όΠτڥքʹ഑ஔ͞ΕΔ
  3. 0SEJOBSZ0CKFDU1PJOUFS java.lang.Object object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0

    16 (object header) N/A Instance size: 16 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total +0-Ͱग़ྗͯ͠Έͨ݁Ռ new Object() すると、64-bit cpu では 16 byte 消費することになる
  4. PPQ%FTD private: volatile markOop _mark; union _metadata { wideKlassOop _klass;

    narrowOop _compressed_klass; } _metadata; TSDTIBSFWNPPQTPPQIQQ +%,
  5. PPQ%FTD TSDTIBSFWNPPQTPPQIQQ +%, private: volatile markOop _mark; union _metadata {

    Klass* _klass; narrowKlass _compressed_klass; } _metadata;
  6. PPQ%FTD IPUTQPUTSDTIBSFWNPPQTPPQT)JFSBSDIZIQQ +%, typedef class oopDesc* oop; typedef class instanceOopDesc*

    instanceOop; typedef class methodOopDesc* methodOop; typedef class constMethodOopDesc* constMethodOop; typedef class methodDataOopDesc* methodDataOop; typedef class arrayOopDesc* arrayOop; typedef class objArrayOopDesc* objArrayOop; typedef class typeArrayOopDesc* typeArrayOop; typedef class constantPoolOopDesc* constantPoolOop; typedef class constantPoolCacheOopDesc* constantPoolCacheOop; typedef class klassOopDesc* klassOop; typedef class markOopDesc* markOop; typedef class compiledICHolderOopDesc* compiledICHolderOop; PPQ%FTD͔Β೿ੜͨ͠Ϋϥε ˞Ұ෦ͷΫϥε͕+%,Ͱ.FUBTQBDFʹҠಈ
  7. PPQ%FTD IPUTQPUTSDTIBSFWNPPQTPPQT)JFSBSDIZIQQ +%, typedef class oopDesc* oop; typedef class instanceOopDesc*

    instanceOop; typedef class arrayOopDesc* arrayOop; typedef class objArrayOopDesc* objArrayOop; typedef class typeArrayOopDesc* typeArrayOop; // class MetaspaceObj class ConstMethod; class ConstantPoolCache; class MethodData; // class Metadata class Method; class ConstantPool; // class CHeapObj class CompiledICHolder; PPQ%FTD͔Β೿ੜͨ͠Ϋϥε ˞+%,Ͱ.FUBTQBDFʹҠಈ
  8. 001ͱ,MBTTͷؔ܎ InstanceOop _klass InstanceKlass InstanceKlass _super *OTUBODF0PQTUS ,MBTT4USJOH ,MBTT0CKFDU Metaspace

    InstanceOop PPQ$MBTT4USJOH _java_mirror Java Heap String str = “hoge”; InstanceMirrorKlass _klass
  9. .BSL hash age CJU CJU unused:25 hash:31 -->| unused:1 age:4

    biased_lock:1 lock:2 (normal object) hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) src/share/vm/oops/markOop.hpp ʢྫʣ6OMPDLFE ޙड़ ͷ.BSLͷϝϞϦߏ଄ hash age
  10. .BSLͷঢ়ଶ#JBTFE  ΦϒδΣΫτׂ͕Γ౰ͯΒΕΔ  #JBTFE-PDLJOH͸+BWB͔ΒσϑΥϧτͳͷͰCJBTBCMFPCKFDUʹͳΔ  ϩοΫ͢ΔͱUISFBE*%͕ઃఆ͞ΕΔ CJBTFEPCKFDU  

    SFCJBT͢ΔͱCJBTBCMFPCKFDUʹ໭Δ ҰఆपظͰSFCJBT͢ΔΒ͍͠   ଞͷεϨουͰར༻͞ΕΔͱجຊϩοΫʹͳΔ #JBTFE-PDLJOH͕ղআ͞ΕΔ 0 epoch age 1 01 thread ID epoch age 1 01 JOJUJBMMPDL SFCJBT CJBTBCMFPCKFDU CJBTFEPCKFDU
  11. .BSLͷঢ়ଶ hash code age 0 01 pointer to lock record

    00  #JBTFE-PDLJOH͕ར༻Ͱ͖ͳ͍৔߹͸جຊϩοΫͷϓϩηεʹͳΔ  جຊϩοΫͰϩοΫ͢Δͱ5IJO-PDL͕͔͔Δ  εϨου͕͢ͰʹͦͷΦϒδΣΫτͷϩοΫΛ͍࣋ͬͯΔ৔߹͸3FDVSTJWF-PDLʹͳΔ  ฒߦॲཧͳͲͰෳ਺ͷҟͳΔεϨου͔Βಉ͡ΦϒδΣΫτʹରͯ͠ ಉ࣌ʹಉظॲཧ͕ߦΘΕΔͱ*OqBUF-PDLʹͳΔ pointer to heavyweight monitor 10 6OMPDLFE -JHIUXFJHIU-PDLFE )FBWZXFJHIU-PDLFE 5IJO-PDL *OqBUF-PDL ʜVOMPDLFE ʜMPDLFE ʜNPOJUPS
  12. java.lang.Object object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 16

    (object header) N/A Instance size: 16 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total ѹॖ001ͳ͠ java.lang.Object object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 4 (loss due to the next object alignment) Instance size: 16 bytes Space losses: 0 bytes internal + 4 bytes external = 4 bytes total ѹॖ001͋Γ +BWBΦϒδΣΫτͷϝϞϦߏ଄
  13. class A { byte a; int c; short d; long

    e; Object f; } ᶃ ᶄ ᶆ ᶅ ᶇ jol.samples.A object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 16 (object header) N/A 16 8 long D.e N/A 24 4 int D.c N/A 28 2 short D.d N/A 30 1 byte D.a N/A 31 1 (alignment/padding gap) 32 8 java.lang.Object D.f N/A Instance size: 40 bytes Space losses: 1 bytes internal + 0 bytes external = 1 bytes total ᶃ ᶄ ᶅ ᶆ ᶇ ѹॖ001ͳ͠ +BWBΦϒδΣΫτͷϝϞϦߏ଄
  14. class A { byte a; int c; short d; long

    e; Object f; } ᶃ ᶄ ᶆ ᶅ ᶇ jol.samples.A object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 4 int D.c N/A 16 8 long D.e N/A 24 2 short D.d N/A 26 1 byte D.a N/A 27 1 (alignment/padding gap) 28 4 java.lang.Object D.f N/A Instance size: 32 bytes Space losses: 1 bytes internal + 0 bytes external = 1 bytes total ᶃ ᶄ ᶅ ᶆ ᶇ ѹॖ001͋Γ +BWBΦϒδΣΫτͷϝϞϦߏ଄
  15. class A { byte a; } class B extends A

    { long b; short c; byte d; } jol.samples.B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 1 byte A.a N/A 13 3 (alignment/padding gap) 16 8 long B.b N/A 24 2 short B.c N/A 26 1 byte B.d N/A 27 5 (loss due to the next object alignment) Instance size: 32 bytes Space losses: 3 bytes internal + 5 bytes external = 8 bytes total +BWBΦϒδΣΫτͷϝϞϦߏ଄
  16. +0-Ͱ$MBTT-BZPVUΛΈͯΈΔ java.lang.String object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0

    4 (object header) 01 00 00 00 4 4 (object header) 00 00 00 00 8 4 (object header) da 02 00 f8 12 4 char[] String.value [a, b, c, d, e, f, g, h, i, j] 16 4 int String.hash 0 20 4 (loss due to the next object alignment) Instance size: 24 bytes Space losses: 0 bytes internal + 4 bytes external = 4 bytes total +BWBΦϒδΣΫτͷϝϞϦߏ଄
  17. +0-ͰΠϯελϯεͷ(SBQI-BZPVUΛΈͯΈΔ java.lang.String@532760d8d object externals: ADDRESS SIZE TYPE PATH VALUE 76b98fb58

    24 java.lang.String (object) 76b98fb70 40 [C .value [a, b, c, d, e, f, g, h, i, j] DIBSͷ഑ྻͰCZUFফඅ͍ͯ͠Δ +BWBΦϒδΣΫτͷϝϞϦߏ଄
  18. [C object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4

    (object header) 01 00 00 00 4 4 (object header) 00 00 00 00 8 4 (object header) 41 00 00 f8 12 4 (object header) 0a 00 00 00 16 20 char [C.<elements> N/A 36 4 (loss due to the next object alignment) Instance size: 40 bytes Space losses: 0 bytes internal + 4 bytes external = 4 bytes total ͜ͷDIBSͷ഑ྻͷ$MBTT-BZPVUΛΈͯΈΔ <B C D E F G H I J K>͸ཁૉ਺YB ഑ྻͷ௕͕͞ϔομʹઃఆ͞ΕΔ +BWBΦϒδΣΫτͷϝϞϦߏ଄