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

Java Bytecode Vertical Tasting

punchdrunker
January 17, 2020

Java Bytecode Vertical Tasting

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

punchdrunker

January 17, 2020
Tweet

More Decks by punchdrunker

Other Decks in Programming

Transcript

  1. ໘ന͔ͬͨτʔΫ 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. എܠΛཧղ͢ΔͨΊͷॏཁͳτϐοΫ w +BWBϦϦʔεαΠΫϧ w "OESPJEͰಈ͘+BWBͬͯ  w +BLF8IBSUPO#MPHͷ%3TFSJFT ೥݄͘Β͍͔Βͷ࿈࡞ 

    w %ʹΑΔEFTVHBS w +BWBͷ৽ػೳ͍Ζ͍Ζ w +BWBͷόΠτίʔυΛ஌Δ w KBWBDKBWBQͭͷίϚϯυ͕࢖͑Ε͹େৎ෉ େৎ෉͡Όͳ͍
  3. 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͸
  4. ͜͏ͳΔ +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); } }
  5. 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
  6. +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
  7. +BWBҎ߱༧ఆ͍ͯ͠Δ৽ػೳ w KBWB  w SFDPSET EFTUSVDUVSJOH  w TFBMFEJOUFSGBDF

    w UZQFNBUDIJOH w QBUUFSONBUDIJOHPGJOTUBODF w KBWB w MPDBMGVODUJPO w 7JSUVBM5ISFBET -PPN  w KBWB w JOMJOFDMBTT
  8. +BWBͱ+BWBͰϏϧυͯ͠Έ·͢ public class Outer { private String name = "Jake";

    class Inner { String sayHi() { return "Hi " + name + "!"; } } } w
  9. ·ͱΊ w ,PUMJO͸4UZMJTI4IJOZ͕ͩɺੜ੒͞ΕΔCZUFDPEF͸ࠜຊతʹ͸+BWBͰ ॻ͍ͯ΋Ұॹͷ΋ͷ͕ग़དྷΔɻ w ,PUMJO΋+BWBͱڞʹ੒௕͍ͯ͘͠ɻ w "OESPJEͰ+BWB΍͕ಈ͘Α͏ʹͳͬͨͱͯ͠΋͠͹Β͘͸ैདྷͷ "OESPJE +BWBPS

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