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. WWW.SITE2MAX.PRO
    PowerPoint & KeyNote Templates
    001ʹ͍ͭͯௐ΂ͯΈͨ
    @tan_go238
    DDD@N

    View full-size slide

  2. Go Tanaka
    1)14DBMB+BWB4DSJQU+BWB
    8 : 1.5 : 0.5 : 0
    【運営スタッフ】
    関西Javaエンジニアの会
    Scala関西 Summit
    Freelance Engineer
    @UBO@HP

    View full-size slide

  3. ࠂ஌
    ,"/+"7"1"35:
    ೔࣌೥݄೔ ౔

    ৔ॴ೔ຊϚΠΫϩιϑτؔ੢ࢧࣾ

    View full-size slide

  4. ࠂ஌
    4DBMBؔ੢4VNNJU
    ೔࣌೥݄೔ ౔

    ৔ॴఱຬݚमηϯλʔʢ+3େࡕͷྡͷӺͷ͙ۙ͘͢ʣ

    View full-size slide

  5. 0QFO+%,ͷιʔείʔυ΍+0-ɺ)4%#ͳͲͰͰ͖ΔݶΓ֬ೝ͍ͯ͠·͕͢
    001·ΘΓͷ࿩͸+BWBݴޠ࢓༷΍+BWBԾ૝Ϛγϯ࢓༷ʹ͸هࡌ͞Ε͍ͯ·ͤΜɻ
    ΑͬͯɺҰ෦࣮ࡍͷಈ࡞ͱҟͳΔ͜ͱ͕͋Δ͔΋͠Ε·ͤΜɻ
    ঘɺ͜ͷηογϣϯͰ͸+7.͸)PU4QPU7.ͷ͜ͱΛࢦ͠·͢ɻ
    ஫ҙ

    View full-size slide

  6. ໨࣍
    0SEJOBSZ0CKFDU1PJOUFS
    ɹPPQ%FTD
    ɹ$PNQSFTTFE001
    ,MBTT
    ɹ,MBTTϙΠϯλͷѹॖ
    .BSL
    ɹ.BSLͷঢ়ଶ
    ɹ#JBTFE-PDLJOH
    +BWBΦϒδΣΫτͷϝϞϦߏ଄
    001ʹ͍ͭͯͷ֓ཁ

    View full-size slide

  7. ໨࣍
    0SEJOBSZ0CKFDU1PJOUFS
    ɹPPQ%FTD
    ɹ$PNQSFTTFE001
    ,MBTT
    ɹ,MBTTϙΠϯλͷѹॖ
    .BSL
    ɹ.BSLͷঢ়ଶ
    ɹ#JBTFE-PDLJOH
    +BWBΦϒδΣΫτͷϝϞϦߏ଄
    001ϔομͷઆ໌

    View full-size slide

  8. ໨࣍
    0SEJOBSZ0CKFDU1PJOUFS
    ɹPPQ%FTD
    ɹ$PNQSFTTFE001
    ,MBTT
    ɹ,MBTTϙΠϯλͷѹॖ
    .BSL
    ɹ.BSLͷঢ়ଶ
    ɹ#JBTFE-PDLJOH
    +BWBΦϒδΣΫτͷϝϞϦߏ଄ ͲΕ͘Β͍ϝϞϦ࢖͏͔ͱ͔

    View full-size slide

  9. ώʔϓ্ͷ͢΂ͯͷ+BWBΦϒδΣΫτ͸001ͱͯ͠දݱ͞ΕΔ
    001͸$$ͷϙΠϯλͰώʔϓ಺ͷҐஔΛࢦ͢
    001ͷϔομ͸.BSLͱ,MBTTͷ̎ϚγϯޠͰߏ੒͞ΕΔ
    z.BSLz͸($ɺಉظԽͷͨΊͷ৘ใΛ΋͍ͬͯΔ
    z,MBTTz͸Ϋϥεͷϝλσʔλ΁ͷϙΠϯλ
    0SEJOBSZ0CKFDU1PJOUFS

    View full-size slide

  10. 0SEJOBSZ0CKFDU1PJOUFS
    _mark
    _klass
    Fields
    32-bit cpu 64-bit cpu
    4 byte 8 byte
    4 byte 8 byte
    -XX:ObjectAlignmentInBytes=8
    ͢΂ͯͷΦϒδΣΫτ͸όΠτڥքʹ഑ஔ͞ΕΔ

    View full-size slide

  11. 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 消費することになる

    View full-size slide

  12. PPQ%FTD
    IPUTQPUTSDTIBSFWNPPQTPPQIQQ +%,

    PPQ%FTDJTUIFUPQCBTFDMBTTGPSPCKFDUTDMBTTFT
    5IF\OBNF^%FTDDMBTTFTEFTDSJCF
    UIFGPSNBUPG+BWBPCKFDUTTPUIFpFMETDBOCFBDDFTTFEGSPN$
    PPQ%FTDJTBCTUSBDU
    TFFPPQ)JFSBSDIZGPSDPNQMFUFPPQDMBTTIJFSBSDIZ

    PPQ%FTDΫϥε͸($ର৅ͱͳΔΦϒδΣΫτͷந৅తͳجఈΫϥε
    PPQ%FTDΫϥεΛܧঝͨ͠ΫϥεͷΠϯελϯε͕($ର৅ͷΦϒδΣΫτʹͳΔ

    View full-size slide

  13. PPQ%FTD
    private:

    volatile markOop _mark;

    union _metadata {

    wideKlassOop _klass;

    narrowOop _compressed_klass;

    } _metadata;
    TSDTIBSFWNPPQTPPQIQQ +%,

    View full-size slide

  14. PPQ%FTD
    TSDTIBSFWNPPQTPPQIQQ +%,

    private:

    volatile markOop _mark;

    union _metadata {

    Klass* _klass;

    narrowKlass _compressed_klass;

    } _metadata;

    View full-size slide

  15. 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ʹҠಈ

    View full-size slide

  16. 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ʹҠಈ

    View full-size slide

  17. PPQ%FTD
    JOTUBODF0PQ%FTDʜ+BWBΦϒδΣΫτͷ001
    BSSBZ0PQ%FTDʜ഑ྻΛද͢001ͷ਌
    PCK"SSBZ0PQ%FTDʜ഑ྻΦϒδΣΫτͷ001
    UZQF"SSBZ0PQ%FTDʜϓϦϛςΟϒͷ഑ྻͷ001

    View full-size slide

  18. $PNQSFTTFE001
    CJUϚγϯͰ΋ΦϒδΣΫτͷΞυϨεΛCJUʹ཈͑Δ CZUF

    +BWBώʔϓͷ࢖༻ྔΛઅ໿
    ώʔϓͷϕʔεΞυϨε͔ΒͷΦϑηοτΛར༻
    ѹॖ001͸+BWBV͔ΒσϑΥϧτͰΦϯ
    996TF$PNQSFTTFE0PQTͰ੾Δ͜ͱ͕Ͱ͖Δ
    http://www.oracle.com/technetwork/jp/articles/java/compressedoops-427542-ja.html
    ৄ͘͠͸

    View full-size slide

  19. ͜͜·Ͱͷ·ͱΊ
    ώʔϓ্ͷ͢΂ͯͷ+BWBΦϒδΣΫτ͸001ͱͯ͠දݱ͞ΕΔ
    001ͷϔομ͸.BSLͱ,MBTTͰߏ੒͞ΕΔ
    $16͕CJU͔CJU͔Ͱ001ͷαΠζ͕มΘΔ ѹॖͰ͖Δ

    +BWBͰ.FUBTQBDF͕ಋೖ͞Εͨ͜ͱʹΑΓ001ͷߏ଄͕มΘͬͨ

    View full-size slide

  20. ,MBTT
    001ͷϔομͷҰ෦
    ,MBTT͸Ϋϥεͷ.FUBTQBDF಺ͷ؅ཧϙΠϯλΛද͢
    CJUϚγϯͰCZUFɺCJUϚγϯͰCZUF࢖༻͢ΔʢѹॖͰ͖Δʣ
    http://otndnld.oracle.co.jp/ondemand/javaday2014/pdf/C2-JavaDay-304328.pdf

    View full-size slide

  21. ,MBTTϙΠϯλͷѹॖ
    $PNQSFTTFE001ͱಉ͡Α͏ʹ+BWB)FBQΛઅ໿ CZUF

    $PNQSFTTFE$MBTT1PJOUFS4QBDF $$14
    ͱ͍͏ϝϞϦΤϦΞΛ༻ҙ
    *OTUBODF,MBTT "SSBZ,MBTT W5BCMFͳͲύϑΥʔϚϯεʹӨڹ͢ΔΫϥε
    ͷΈ֨ೲ͠ɺͦΕҎ֎͸.FUBTQBDFʹ֨ೲʢϝιουɺίϯελϯτϓʔϧͳͲʣ

    View full-size slide

  22. ,MBTT
    ,MBTT͸͞·͟·ͳܕ৘ใͷந৅తͳجఈΫϥε

    View full-size slide

  23. *OTUBODF,MBTTʜܕΫϥεͷΠϯελϯε
    *OTUBODF.JSSPS,MBTTʜKBWBMBOH$MBTTΛද͢
    *OTUBODF$MBTT-PBEFS,MBTTʜ*OTUBODF,MBTTͷΫϥεϩʔμ༻
    *OTUBODF3FG,MBTTʜKBWBMBOHSFG3FGFSFODFͷαϒΫϥε
    ɹɹɹɹɹɹɹɹɹɹ TPGUXFBLpOBMQIBOUPN

    ,MBTT

    View full-size slide

  24. "SSBZ,MBTTʜ഑ྻΛද͢਌Ϋϥε
    0CK"SSBZ,MBTTʜΦϒδΣΫτͷ഑ྻͷΫϥε
    5ZQF"SSBZ,MBTTʜϓϦϛςΟϒͷ഑ྻͷΫϥε
    ,MBTT

    View full-size slide

  25. 001ͱ,MBTTͷؔ܎
    InstanceOop
    _klass
    InstanceKlass InstanceKlass
    _super
    *OTUBODF0PQTUS ,MBTT4USJOH ,MBTT0CKFDU
    Metaspace
    InstanceOop
    PPQ$MBTT4USJOH
    _java_mirror
    Java Heap
    String str = “hoge”;
    InstanceMirrorKlass
    _klass

    View full-size slide

  26. ͜͜·Ͱͷ·ͱΊ
    ,MBTT͸001ͷϔομͷҰ෦
    ௨ৗͷ ഑ྻ͡Όͳ͍
    +BWBΠϯελϯε͸*OTUBODF0PQͰදݱ͞ΕΔ
    Πϯελϯεͷܕ৘ใ͸*OTUBODF,MBTTʹ֨ೲ͞Ε͍ͯΔ
    *OTUBODF,MBTTͷKBWB@NJSSPSʹKBWBMBOH$MBTTͷ001΁ͷࢀর͕͋Δ

    View full-size slide

  27. .BSL
    ($ɺಉظԽͷͨΊͷ৘ใΛ΋͍ͬͯΔ
    CJUϚγϯͰ͸όΠτɺCJUϚγϯͰ͸όΠτͷ௕͞ʹͳΔ
    .BSL͸ϙΠϯλͰ͸ͳ͘σʔλߏ଄

    View full-size slide

  28. .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

    View full-size slide

  29. .BSL
    .BSLͷঢ়ଶ͸ओʹҎԼͷ̑ͭ
    ɹ#JBTFE
    ɹ6OMPDLFE લड़ͷOPSNBMPCKFDU

    ɹ-JHIUXFJHIU-PDLFE
    ɹ)FBWZXFJHIU-PDLFE
    ɹ.BSLFEʢ($ͷΈʣ
    https://wiki.openjdk.java.net/display/HotSpot/Synchronization
    Mark には5種類のデータ構造がある

    View full-size slide

  30. .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

    View full-size slide

  31. #JBTFE-PDLJOH
    جຊϩοΫͰ͸ճͷϩοΫͰ࠷௿ճͷ$"4໋ྩΛ࢖͏
    #JBTFE-PDLJOHͷίϯηϓτ
    ɹɾ͋ΔεϨου͔ΒϩοΫ͞ΕͨΦϒδΣΫτ͸
    ɹɹಉ͡εϨου͔ΒϩοΫ͞ΕΔ܏޲͕͋Δ
    ɹɾΦϒδΣΫτͷதʹεϨου৘ใΛຒΊࠐΜͰಛఆͷεϨουʹ
    ภ͍ͬͯΔ CJBTFE
    ͜ͱΛࣔ͢ɻͦΕʹΑΓͦͷεϨου͔Βͷ
    ϩοΫ͸$"4໋ྩͳ͠Ͱߦ͏͜ͱ͕Ͱ͖Δ

    View full-size slide

  32. .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

    View full-size slide

  33. ͜͜·Ͱͷ·ͱΊ
    .BSL͸001ϔομͷҰ෦
    .BSL͸ϙΠϯλͰ͸ͳ͘ঢ়ଶΛද͢σʔλߏ଄
    ओʹಉظॲཧͷͨΊʹར༻͞ΕΔ
    ಉظॲཧ͸ύϑΥʔϚϯεʹӨڹ͢ΔͷͰঢ়گʹԠͨ͡ϩοΫॲཧ͕͋Δ
    ϩοΫॲཧʹԠͯ͡σʔλߏ଄͕มΘΔ

    View full-size slide

  34. +BWBΫϥεͷϝϞϦߏ଄

    View full-size slide

  35. ͜͜·Ͱ͸001ϔομͷ࿩

    View full-size slide

  36. _mark
    _klass
    ͜͜·ͰͰCZUF෼ͷ࿩͔ͯ͠͠ͳ͍
    ˞CJUϚγϯͷ৔߹ɻ001͓Αͼ,MBTTϙΠϯλະѹॖ
    CZUF
    CZUF

    View full-size slide

  37. +BWBΦϒδΣΫτͷϝϞϦߏ଄
    -XX:ObjectAlignmentInBytes=8
    ͢΂ͯͷΦϒδΣΫτ͸όΠτڥքʹ഑ஔ͞ΕΔ
    _mark
    _klass
    Fields

    View full-size slide

  38. 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ΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  39. 001ϔομͷޙʹΫϥεϑΟʔϧυ͕ଓ͘
    ϝϞϦઅ໿ͷͨΊʹ+7.͸ఆٛ͞Εͨॱ൪Ͱ͸ͳ͘ฒͼସ͑Λߦ͏
    ϑΟʔϧυ͸جຊతʹ࣍ͷ༏ઌॱҐͰϝϞϦʹߏ੒͢Δ
    1 double, long 8
    2 int, float 4
    3 short, char 2
    4 boolean, byte 1
    5 ΦϒδΣΫτࢀর 8 (64bit)
    +BWBΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  40. 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ΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  41. 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ΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  42. αϒΫϥεͷϝϞϦϨΠΞ΢τ
    ɹ֊૚͕ҟͳΔΫϥεͷϑΟʔϧυ͸ࠞ߹͠ͳ͍
    ɹ਌ΫϥεͷϑΟʔϧυ͕ઌʹ͖ͯɺαϒΫϥεͷϑΟʔϧυ͕ͦͷޙʹ͘Δ
    +BWBΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  43. 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ΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  44. String str = “abcdefghij”;
    ͜ͷίʔυ͸ԿCZUFͷϝϞϦΛফඅ͢Δ͔
    +BWBΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  45. +0-Ͱ$MBTT-BZPVUΛΈͯΈΔ
    String str = “abcdefghij";

    System.out.println(ClassLayout.parseInstance(str).toPrintable());
    +BWBΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  46. +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ΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  47. +BWBΦϒδΣΫτͷϝϞϦߏ଄
    String str = “abcdefghij";

    System.out.println(GraphLayout.parseInstance(str).toPrintable());
    +0-ͰΠϯελϯεͷ(SBQI-BZPVUΛΈͯΈΔ

    View full-size slide

  48. +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ΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  49. [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. 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ΛΈͯΈΔ
    ͸ཁૉ਺YB
    ഑ྻͷ௕͕͞ϔομʹઃఆ͞ΕΔ
    +BWBΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  50. String str = “abcdefghij”;
    ͜ͷίʔυ͸ԿCZUFͷϝϞϦΛফඅ͢Δ͔
    4USJOHCZUF
    DIBS<>CZUF
    ߹ܭɿCZUF
    +BWBΦϒδΣΫτͷϝϞϦߏ଄

    View full-size slide

  51. ·ͱΊͱײ૝
    ώʔϓ্ͷ͢΂ͯͷ+BWBΦϒδΣΫτ͸001ͱͯ͠දݱ͞ΕΔ
    001ͷϔομ͸.BSLͱ,MBTTͰߏ੒͞ΕΔ
    .BSL͸͓΋ʹಉظԽɺ,MBTT͸Ϋϥεͷ৘ใΛ΋͍ͬͯΔ
    001ϔομͷ͋ͱʹ͸ϑΟʔϧυ৘ใ͕͸͍Δ
    ΦϯϥΠϯʹ͋Δ৘ใͷ΄ͱΜͲ͕+BWBҎલͳͷͰ஫ҙ

    View full-size slide

  52. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

    View full-size slide

  53. 4ZODISPOJ[BUJPOBOE0CKFDU-PDLJOH
    )PU4QPUVOEFSUIF)PPE
    -PDLJOHBOE4ZODISPOJ[BUJPO
    +BWBΦϒδΣΫτͷϝϞϦߏ଄
    &WFSZUIJOH*&WFS-FBSOFE"CPVU+7.1FSGPSNBODF5VOJOH!5XJUUFS
    +%,+7.*NQSPWFNFOUT
    ࢀߟࢿྉ
    https://www.infoscoop.org/blogjp/2014/06/16/java-objects-memory-structure/
    https://www.slideshare.net/aszegedi/everything-i-ever-learned-about-jvm-performance-tuning-twitter
    https://www.slideshare.net/nminoru_jp/jvm-readingsynchronization
    https://www.infoq.com/presentations/hotspot-memory-data-structures
    https://wiki.openjdk.java.net/display/HotSpot/Synchronization
    http://otndnld.oracle.co.jp/ondemand/javaday2014/pdf/C2-JavaDay-304328.pdf

    View full-size slide