Java Bytecode Vertical Tasting

Java Bytecode Vertical Tasting

Javaのバイトコードを垂直試飲する

4f31137c606d3d1c06d0d86fc7fd4bdd?s=128

punchdrunker

January 17, 2020
Tweet

Transcript

  1. Java Bytecode Vertical Tasting

  2. 7FSUJDBM5BTUJOHਨ௚ࢼҿͱ͸ ಉ͡໏ฑͷϫΠϯΛ೥౓ҧ͍Ͱࢼҿ͢Δख๏ ೥౓͝ͱͷಛ௃Λ೺ѲͰ͖Δ ϙςϯγϟϧͱมԽΛ֬ೝ͢Δࣄ͕Ͱ͖Δ ࠓճ͸ޙ൒ͷσϞͰ೥౓ҧ͍ͷKBWBDΛ࣮ߦ ͠ɺग़དྷ্͕ͬͨDMBTTϑΝΠϧͷಛ௃΍มԽ ΛςΠεςΟϯά͍ͨ͠ͱࢥ͍·͢ɻ

  3. ຊ೔ఏڙυϦϯΫͷ঺հ 4VOTFU$FMMBSTϫΠϯछ ന੺ 1BVM(JSBVEͿͲ͏δϡʔε ඍ୸ࢎ ʮΤϯδχΞ͚ͩͲถࠃͰϫΠφϦʔΛങͬͨ࿩ʯ ͷϫΠφϦʔͰ͢ ίχϟοΫੜ࢈ऀ͕ຖ೥࡞Δ ͿͲ͏ՌोͷδϡʔεͰ͢ ͓ञͰ͸͋Γ·ͤΜ

  4. ,PUMJO$POGࢀՃ w ϫʔΫγϣοϓࢀՃ w ͋·Γ"OESPJEΆ͘ͳ͍ηογϣϯΛݟΔ w ϏʔϧΛҿΈʹߦ͘ w ಉ͡ళʹଞͷࢀՃऀ΍+BLF΋͍ͨ

  5. ͜ͷτʔΫͷ໨త ͠͹Β͘ಡΉͷΛޙճ͠ʹ͍ͯͨ͠+BLF8IBSUPOͷ࠷ۙͷ CMPH΍ࠓճͷ࿩ΛҰؾʹಡΜͰΈͯɺͱͯ΋໘ന͔ͬͨͰ ͢ɻ IUUQTKBLFXIBSUPODPNCMPH ͨͩɺॳ৺ऀ΍+BWBͷ஌͕ࣝແ͍ͱ͔ͳΓͱ͖ͬͭʹ͍͘಺ ༰ͳͷͰɺཧղʹඞཁͱͳΔલఏ஌ࣝͳͲΛͳΔ΂͘Θ͔Γ ΍͘͢આ໌͠·͢ɻ

  6. ໘ന͔ͬͨτʔΫ w 5IFTIVUUMFDBTF4UFQIFO$BSWFS w LFZOPUFΞʔΧΠϒಈը I ͷ࠷ॳͷηογϣϯ w εϖʔεγϟτϧͷࣄނͱൃలͷྺ࢙Λ঺հ w

    "TZODISPOPVT%BUB4USFBNTXJUI,PUMJO'MPXCZ3PNBO&MJ[BSPW w ਤղ͕Θ͔Γ΍͍͢$PSPVUJOFͷ࿩ w ,PUMJO3VOT5BYFTJO/PSXBZCZ+BSMF)BOTFO"OEFST.JLLFMTFO w ϊϧ΢Σʔͷࠃ੫γεςϜΛ,PUMJOY4QSJOH#PPUͰӡ༻ͯ͠Δ࿩
  7. ࠓճ঺հ͢Δͷ͸

  8. Ͱ΋౰೔ݟ·ͤΜͰͨ͠ w ࠷ۙͷ+BWBͷ࿩ΛΩϟονΞοϓ͍ͯ͠ͳ͔ͬͨ w ࣮ࡍʹ৮ͬͨ͜ͱͷ͋Δ࠷৽ͷ+BWB͸ w ͦ΋ͦ΋࠷৽ͷ"OESPJEͰ΋+BWB·Ͱ͔͠࢖͑ͳ͍ w ࠷ۙͷঢ়گͱ͔Λௐ΂͔ͯΒษڧ͠Α͏ͱࢥͬͨ

  9. ઌʹ+BLFͷ݁࿦Λ·ͱΊΔͱ +BWBͷ৽͍͠ػೳ΍7.ͷਐԽ͸,PUMJOʹ΋Ըܙ͕͋ΔɻͳͥͳΒͦΕΒ͸LPUMJOD͔ Β΋ར༻Մೳ͔ͩΒɻ OVMMഇࢭͷಈ͖͸ͳͦ͞͏ͩΑɻڊେͳܕγεςϜʹͱͬͯ͸OVMMͷԸܙ΋͋Δ͔Β Ͷɻ ,PUMJOʹ͸ϚΠάϨʔγϣϯͱ͔ࣗಈͰग़དྷͪΌ͏͍͢͝*%&͕͋Δ͠ɺͦΕ͸+BWB ʹ͸ग़དྷͳ͔ͬͨࣄͩͶɻ NVMUJQMBUGPSNͷ໘Ͱ΋,PUMJO͸͔ͳΓΠέͯΔ͠ɺ,PUMJO΋࢖ΘΕଓ͚Δͱࢥ͏Αɻ ೥ޙ΋Ҿ͖ଓ͖KBWBͱLPUMJO͸੾᛭ୖຏ͍ͯ͠Δͱࢥ͏ɻ

  10. None
  11. ݁࿦ͷഎܠ ਪଌؚΉ +BWB͸ϦϦʔεαΠΫϧ΋มԽͯ͠ͲΜͲΜਐԽͯ͠ɺ͜ ͷϖʔεͩͱ೥ޙʹ͸$PSPVUJOF૬౰ͷ΋ͷ΋ϦϦʔε ͞ΕΔݟࠐΈɻ 1SPKFDU-PPNͱ͔  ͦ͏ͳΔͱ,PUMJOͬͯଘࡏҙٛͲͷ͘Β͍ͳͷ ͱ͍͍͏ ໰͍ʹର͢ΔΞϯαʔηογϣϯ͕ࠓճͷ͓୊Ͱ͢ɻ

  12. എܠΛཧղ͢ΔͨΊͷॏཁͳτϐοΫ w +BWBϦϦʔεαΠΫϧ w "OESPJEͰಈ͘+BWBͬͯ  w +BLF8IBSUPO#MPHͷ%3TFSJFT ೥݄͘Β͍͔Βͷ࿈࡞ 

    w %ʹΑΔEFTVHBS w +BWBͷ৽ػೳ͍Ζ͍Ζ w +BWBͷόΠτίʔυΛ஌Δ w KBWBDKBWBQͭͷίϚϯυ͕࢖͑Ε͹େৎ෉ େৎ෉͡Όͳ͍
  13. +BWBͷۙگ w ࠷৽όʔδϣϯ͸ w +BWB͸0SBDMF͕ॴ༗ w େମ+BWBͷ్த͘Β͍Ͱ4VO͕0SBDMFʹങऩ͞ΕͯΔ w େࡶ೺ʹݴ͏ͱ0QFO+%,ͱͦΕʹ঎༻ػೳΛ௥Ճͨ͠0SBDMF+%,͕͋Δ w

    +BWB͋ͨΓ͔Β৽͍͠ϦϦʔεαΠΫϧʹͳͬͨ w ΊͬͪΌ৽ػೳ͕௥Ճ͞Ε͍ͯͬͯΔ
  14. 8JLJQFEJBΑΓ

  15. 8JLJQFEJBΑΓ

  16. "OESPJEͱ+BWB w "OESPJE"1*Ҏ߱͸+BWBͷຆͲͷػೳΛ࢖͑Δ w "OESPJE"1*͸+BWB͔͠ಈ͔ͳ͍ w NJO4EL7FSTJPO͕ҎԼͩͱ+BWBͷόΠτίʔυ͕ඞཁ w ͘Θ͘͠͸ެࣜͰˠ+BWBݴޠػೳͷ࢖༻ w

    IUUQTEFWFMPQFSBOESPJEDPNTUVEJPXSJUFKBWBTVQQPSU
  17. Ͱ΋+BWBͰ։ൃͰ͖ͯΔ͚Ͳ

  18. ͦΕɺ%FTVHBS͞Εͯ·͢

  19. EFTVHBS

  20. EFTVHBS

  21. class Java8 { interface Logger { void log(String s); }

    public static void main(String!!... args) { sayHi(s !-> System.out.println(s)); } private static void sayHi(Logger logger) { logger.log("Hello!"); } } DMBTTDPVOU .FUIPEDPVOU ͨͱ͑͹MBNCEB͸
  22. ͜͏ͳΔ +BWBͰ΋ ಈ͖ͦ͏ class Java8 { interface Logger { void

    log(String s); } public static void main(String!!... args) { sayHi(Java8$1.INSTANCE); } static void lambda$main$0(String s) { System.out.println(s); } private static void sayHi(Logger logger) { logger.log("Hello!"); } } class Java8$1 implements Java8.Logger { static final Java8$1 INSTANCE = new Java8$1(); @Override public void log(String s) { Java8.lambda$main$0(s); } }
  23. class Java8 { interface Logger { void log(String s); }

    public static void main(String!!... args) { sayHi(Java8$1.INSTANCE); } static void lambda$main$0(String s) { System.out.println(s); } private static void sayHi(Logger logger) { logger.log("Hello!"); } } class Java8$1 implements Java8.Logger { static final Java8$1 INSTANCE = new Java8$1(); @Override public void log(String s) { Java8.lambda$main$0(s); } } Ͱ΋ ͍Ζ͍Ζ૿͑ͯΔ $MBTTDPVOU .FUIPEDPVOU
  24. ϝιου਺͕૿͑Δͱ MULTIDEX

  25. MBNCEB͸Ͳ͜ʹߦͬͨͷ NJO4EL7FSTJPOʹ͢Ε͹ /BUJWF-BNCEBΛ࢖͑ΔΆ͍Ͱ͢ɻ ૣͯ͘೥ޙ͘Β͍ େମ+BWBͷ࣌ظ

  26. +BWB·Ͱͷ৽ػೳ·ͱΊ w +BWB w MBNCEB w NFUIPESFGFSFODF w TUBUJDBOEEFGBVMUNFUIPETJOJOUFSGBDFT w

    +BWB w $PODJTF5SZ8JUI3FTPVSDFT w "OPOZNPVT%JBNPOE w 1SJWBUF*OUFSGBDF.FUIPET w TUSJOHDPODBUXJUIPVU4USJOH#VJMEFS w +BWB w 7BSGPSMPDBMWBSJBCMF XIFOUIFUZQFDBOCFJOGFSSFE w +BWB w WBSPOMBNCEBWBSJBCMFT w /FTUNBUFT w KBWB w TXJUDIFYQSFTTJPOT OPU੍ޚจ  w KBWB w NVMUJMJOFTUSJOH USJQMFRVPUFT
  27. +BWBҎ߱༧ఆ͍ͯ͠Δ৽ػೳ w KBWB  w SFDPSET EFTUSVDUVSJOH  w TFBMFEJOUFSGBDF

    w UZQFNBUDIJOH w QBUUFSONBUDIJOHPGJOTUBODF w KBWB w MPDBMGVODUJPO w 7JSUVBM5ISFBET -PPN  w KBWB w JOMJOFDMBTT
  28. ͔͜͜Β͕ຊ୊

  29. +BWBͱ+BWBͰϏϧυͯ͠Έ·͢ public class Outer { private String name = "Jake";

    class Inner { String sayHi() { return "Hi " + name + "!"; } } } w
  30. ࢖͏ίϚϯυ w YYE w όΠφϦΛਐ਺Ͱදࣔͯ͘͠ΕΔίϚϯυ w KBWBD w +BWBͷίʔυΛίϯύΠϧͯ͘͠ΕΔίϚϯυ w

    KBWBQ w ίϯύΠϧͨ͠੒Ռ෺ΛٯΞηϯϒϧͯ͘͠ΕΔίϚϯυ
  31. +BWB

  32. +BWB

  33. ,PUMJO

  34. ࠓճ֬ೝͰ͖ͨ఺ w *OOFSDMBTT͔ΒQSJWBUFpFME΁ΞΫηεͨ࣌͠ʹൃੜ͢Δ߹੒ΞΫηα͕ ࣗಈੜ੒͞ΕΔ ϝιου͕૿͑ͯ͠·͏ ໰୊͕ղফ͞Εͨ /FTUNBUFT  w จࣈྻ࿈͕݁಺෦తʹ͸4USJOH#VJMEFSͷBQQFOEͰ͸ͳ͘ɺίΞϥΠϒϥ

    Ϧͷ໋ྩͰॲཧ͞ΕΔΑ͏ʹͳͬͨɻ w ,PUMJOͰॻ͍ͯ΋ੜ੒͞ΕΔόΠτίʔυ͸มΘΒͳ͍
  35. ·ͱΊ w ,PUMJO͸4UZMJTI4IJOZ͕ͩɺੜ੒͞ΕΔCZUFDPEF͸ࠜຊతʹ͸+BWBͰ ॻ͍ͯ΋Ұॹͷ΋ͷ͕ग़དྷΔɻ w ,PUMJO΋+BWBͱڞʹ੒௕͍ͯ͘͠ɻ w "OESPJEͰ+BWB΍͕ಈ͘Α͏ʹͳͬͨͱͯ͠΋͠͹Β͘͸ैདྷͷ "OESPJE +BWBPS

    ͱޓ׵ੑΛอͭҝʹEFTVHBS͠ଓ͚Δඞཁ͕͋Δɻ w ΑΓྑ͍όΠτίʔυͰΞϓϦΛ഑৴͢ΔͨΊʹ͸௕͍͕͔͔࣌ؒΔ w ͍͢͝ൃ໌ͰҰؾʹϏϧυपΓͷվળ͕Ճ଎͢ΔࣄΛظ଴ ଞྗຊئ
  36. None