Java Bytecode Vertical Tasting

Java Bytecode Vertical Tasting

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

4f31137c606d3d1c06d0d86fc7fd4bdd?s=128

punchdrunker

January 17, 2020
Tweet

Transcript

  1. 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Ͱӡ༻ͯ͠Δ࿩
  2. 10.
  3. 12.

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

    w %ʹΑΔEFTVHBS w +BWBͷ৽ػೳ͍Ζ͍Ζ w +BWBͷόΠτίʔυΛ஌Δ w KBWBDKBWBQͭͷίϚϯυ͕࢖͑Ε͹େৎ෉ େৎ෉͡Όͳ͍
  4. 19.
  5. 20.
  6. 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͸
  7. 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); } }
  8. 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
  9. 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
  10. 27.

    +BWBҎ߱༧ఆ͍ͯ͠Δ৽ػೳ w KBWB  w SFDPSET EFTUSVDUVSJOH  w TFBMFEJOUFSGBDF

    w UZQFNBUDIJOH w QBUUFSONBUDIJOHPGJOTUBODF w KBWB w MPDBMGVODUJPO w 7JSUVBM5ISFBET -PPN  w KBWB w JOMJOFDMBTT
  11. 29.

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

    class Inner { String sayHi() { return "Hi " + name + "!"; } } } w
  12. 31.
  13. 32.
  14. 33.
  15. 35.

    ·ͱΊ w ,PUMJO͸4UZMJTI4IJOZ͕ͩɺੜ੒͞ΕΔCZUFDPEF͸ࠜຊతʹ͸+BWBͰ ॻ͍ͯ΋Ұॹͷ΋ͷ͕ग़དྷΔɻ w ,PUMJO΋+BWBͱڞʹ੒௕͍ͯ͘͠ɻ w "OESPJEͰ+BWB΍͕ಈ͘Α͏ʹͳͬͨͱͯ͠΋͠͹Β͘͸ैདྷͷ "OESPJE +BWBPS

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