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

入門:JVM 〜5 分で完全に理解する JVM の仕組み〜

ちゅるり
May 11, 2024
140

入門:JVM 〜5 分で完全に理解する JVM の仕組み〜

2024/5/11 (Sat.) UNTIL.LT #0x04 の登壇資料

ちゅるり

May 11, 2024
Tweet

Transcript

  1. ͪΎΔΓ @chururi_ @itsu-dev • ໺຀ थʢͷ·͖ ͍ͭΔʣ • ৘ใϝσΟΞ૑੒ֶྨ ೥

    • ϓϩάϥϛϯάݴޠݚڀࣨʢதҪݚʣ • ֶज़৘ใϝσΟΞηϯλʔʹੜଉ • શ୅ձ ৘ใॲཧਪਐಛผҕһձʢ*1$ʣ • ֶԂࡇ࣮ߦҕһձ ৘ใϝσΟΞਪਐہʢKTZTʣ 👀 8FC ݴޠॲཧܥ FUD 📍
  2. +BWB͕ಈ͘·Ͱ +BWBϓϩάϥϜ ʢ KBWBʣ +BWBΫϥεϑΝΠϧ ʢ DMBTTʣ +BWBԾ૝Ϛγϯ ʢ+7.ʣ Hello,

    World! ਓ͕ಡΊΔ ܇࿅͞ΕͨਓͰ ͳ͍ݶΓಡΊͳ͍ ✅ ❌ javac java public class Main... 0xCA0xFE0xBA0xBE...
  3. +BWBΫϥεϑΝΠϧͷߏ଄ɿ֓؍ • ӈ͸ΫϥεϑΝΠϧͷத਎ • ܕ σʔλ໊ ͷϑΥʔϚοτ • V͸ 

    CZUF੔਺஋ • V΋ಉ༷ɺ΄͔͸ߏ଄ମ • ಛʹॏཁͳ΋ͷ • DPOTUBOU@QPPM • ఆ਺ϓʔϧ • NFUIPET • ໋ྩؚΉϝιου৘ใ u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; 5IF+BWBš7JSUVBM.BDIJOF4QFDJGJDBUJPO+BWB4&&EJUJPO $IBQUFS ΑΓҾ༻
  4. +BWBΫϥεϑΝΠϧͷߏ଄ɿఆ਺ϓʔϧ • ܕ΍ϝιου໊ɺ ϓϩάϥϜதͷจࣈྻ΍ ఆ਺Λ֨ೲ • ਺छྨͷܕͷσʔλͷ഑ྻ • FY6UGܕ •

    VUBHʢܕΛද͢ఆ਺ɺʣ • VMFOHUIʢจࣈྻ௕ʣ • VCZUFT<MFOHUI> ʢ࣮ࡍͷ6UGจࣈྻʣ javap –v -p Main.java ͷ࣮ߦ݁ՌͷҰ෦
  5. +BWBΫϥεϑΝΠϧͷߏ଄ɿϝιου • Ҿ਺΍ฦ஋ɺ+7.໋ྩͳͲ ΛؚΉ • +7.໋ྩ͸ $PEF"UUSJCVUF ͱͯ͠ ؚ·ΕΔ javap

    –v -p Main.java ͷ࣮ߦ݁ՌͷҰ෦ u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; Method ߏ଄ମ – 4.6 Methods ΑΓ
  6. ໋ྩ࣮ߦΤϯδϯɿ࢓૊Έ • +7.໋ྩΛ ࣮ͭͣͭߦ͍ͯ͘͠ • CZUFͷ໋ྩʢΦϖίʔυʣͱ ݸҎ্ͷҾ਺ʢΦϖϥϯυʣͰߏ੒ • ΦϖϥϯυελοΫʹ஋Λ௥ՃɾऔΓग़͠Λߦ͏͜ͱͰ໋ྩΛ࣮ߦ System.out.println(“Hello,

    World!”); getstatic #7 ldc #13 invokevirtual #15 return #7 = Fieldref #8.#9 // java/lang/System.out:Ljava/io/PrintStream; #13 = String #14 // Hello, World! #15 = Methodref #16.#17 // java/io/PrintStream.println:(Ljava/lang/String;)V ίϯύΠϧ͞Εͨ +7.໋ྩ ఆ਺ϓʔϧʢൈਮʣ
  7. ໋ྩ࣮ߦΤϯδϯɿ࣮ߦྫ #7 = Fieldref #8.#9 // java/lang/System.out:Ljava/io/PrintStream; #13 = String

    #14 // Hello, World! #15 = Methodref #16.#17 // java/io/PrintStream.println:(Ljava/lang/String;)V • getstatic #7 • ελοΫʹࢦఆͷ static ม਺ͷࢀরΛੵΉ • ldc #13 • ελοΫʹࢦఆͷఆ਺ΛੵΉ • invokevirtual #15 • ࢦఆͷϝιουΛ࣮ߦ͢Δ • ϝιουͷҾ਺ͷ਺ pop • ϝιουͷॴ༗ऀΛ pop • return System.out System.out “Hello, World!” ্ σΟεΫϦϓλ ʢ͜ͷ৔߹ɺ4USJOHܕͷҾ਺Λ Ұ͚ͭͩऔΔͱΘ͔Δʣ ্ /&8 /&8
  8. ͍͞͝ʹ • ͜͜·Ͱ෼͔Ε͹೚ҙͷݴޠͰ +7.΋Ͳ͖Λ࣮૷Ͱ͖Δʂ • Ϋϥεϩʔμ • ໋ྩ࣮ߦΤϯδϯ • ࣮༻తʹ͢Δͷ͸मཏͷಓ

    • ܧঝɺॳظԽɺಈతϦϯΫɺྫ֎ • +/*ʢ+BWB/BUJWF*OUFSGBDFʣ • ඪ४ϥΠϒϥϦ • 54ʹΑΔ੿ +7.࣮૷ɿ $IVSV7. 1MBZHSPVOE • ্هͷ΄΅શͯΛ࣮૷ ˞+BWBͰίϯύΠϧ͞ΕͨΫϥεϑΝΠϧΛ ࣮ߦՄೳ