[Java] Laufzeitdatenbereiche von JVM

Runtime Data Areas 62708f0fa456f6c70661446194ae4fd2.png

Each stack frame has the reference for local variable array, Operand stack, and runtime constant pool of a class where the method being executed belongs. The size of local variable array and Operand stack is determined while compiling. Therefore, the size of stack frame is fixed according to the method.

Java Bytecode

public void add(java.lang.String);
  Code:
   Stack=2, Locals=2, Args_size=2
   0:   aload_0
   1:   getfield        #15; //Field admin:Lcom/nhn/user/UserAdmin;
   4:   aload_1
   5:   invokevirtual   #23; //Method com/nhn/user/UserAdmin.addUser:(Ljava/lang/String;)Lcom/nhn/user/User;
   8:   pop
   9:   return  LineNumberTable:
   line 14: 0
   line 15: 9  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      10      0    this       Lcom/nhn/service/UserService;
   0      10      1    userName       Ljava/lang/String; // … Omitted - Other method information …
}

example1 java code

public class SimpleClass {

    public int simpleField = 100;

}

byte code

public SimpleClass();
  Signature: ()V
  flags: ACC_PUBLIC
  Code:
    Stack=2, Locals=1, Args_size=1
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: bipush        100
       7: putfield      #2                  // Field simpleField:I
      10: return

constant pool

   #1 = Methodref          #4.#16         //  java/lang/Object."<init>":()V
   #2 = Fieldref           #3.#17         //  SimpleClass.simpleField:I
   #3 = Class              #13            //  SimpleClass
   #4 = Class              #19            //  java/lang/Object
   #5 = Utf8               simpleField
   #6 = Utf8               I
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               SimpleClass
  #14 = Utf8               SourceFile
  #15 = Utf8               SimpleClass.java
  #16 = NameAndType        #7:#8          //  "<init>":()V
  #17 = NameAndType        #5:#6          //  simpleField:I
  #18 = Utf8               LSimpleClass;
  #19 = Utf8               java/lang/Object

Locals=1, Args_size=1 -> this

  1. aload_0 the first local variable points to this -> load the this reference onto the operand stack

  2. invokespecial #1 invoking the superclass constructor -> corresponding to the index 1 of constant pool -> Methodref #4.#16 -> Object class init

default constructor execute initialization code for class variables (field)

  1. aload_0 the first local variable points to this -> load the this reference onto the operand stack

  2. bipush 100 add a byte as an integer (100) to the operand stack (Stack=2)

  3. putfield #2 reference a field in the index 2 of runtime constant pool -> Fieldref #3.#17 -> the field called simpleField -> pop 100 and this on the operand stack -> 100 to set the simpleField to this object that contains the field

java_class_variable_creation_byte_code.png

example2 java code

public class TestClass {
    public static void main(String[] args)  {
        Object foo = null;
        Object bar = null;
    }
}

byte code

public static void main(java.lang.String[]);
  Code:
   Stack=1, Locals=3, Args_size=1
   0:   aconst_null
   1:   astore_1
   2:   aconst_null
   3:   astore_2
   4:   return

LineNumberTable: 
line 5: 0
line 6: 2
line 7: 4

LocalVariableTable: 
Start  Length  Slot  Name   Signature
0      5      0    args       [Ljava/lang/String;
2      3      1    foo       Ljava/lang/Object;
4      1      2    bar       Ljava/lang/Object;

Args_size=1 -> args Locals=3 -> args, foo, bar

  1. aconst_null push the null onto the operand stack (Stack=1)

  2. astore_1 pop the reference from the operand stack -> store it in the index 1 of local variable correspond to foo

  3. aconst_null push the null onto the operand stack (Stack=1)

  4. astore_2 pop the reference from the operand stack -> store it in the index 2 of local variable correspond to bar

ref.

Recommended Posts

[Java] Laufzeitdatenbereiche von JVM
[Java] Übersicht über Java
[Java] Klassifizierungsnotiz für Kompilierungsfehler und Laufzeitfehler
Abgelaufene Java-Sammlung
[Java] Bedeutung der serialVersionUID
NIO.2 Überprüfung von Java
Bewertung von Java Shilber
[Java] Datentyp ①-Basistyp
Java - Vereinigung von Kommentaren
Geschichte der Java-Annotationen
Java (Verdienste des Polymorphismus)
[Java] Hauptdatentypen
NIO Bewertung von Java
[Java] Drei Funktionen von Java
Zusammenfassung der Java-Unterstützung 2018
Java-Grunddatentypen
Java, das Daten von Android zu Jetson Nanos ROS überspringt
[Java] Um die Typinformationen der Typparameter zur Laufzeit zu kennen
Über Java-Instanzen
[Java] Mirage-Basic-Verwendung von SQL
Java-Lernnotiz (Datentyp)
[Java] Anfängerverständnis von Servlet-②
[Java] Praxis der Ausnahmebehandlung [Ausnahme]
[Java11] Stream-Zusammenfassung - Vorteile von Stream -
Grundlagen der Zeichenoperation (Java)
Java-Programmierung (Variablen und Daten)
[Java] Erstellen von Originalanmerkungen
Java-Lerntag 4
Java Ende des Monats plusMonate
Importieren Sie Excel-Daten mit Java 2
[Java] Zusammenfassung der regulären Ausdrücke
[Java] Zusammenfassung der Operatoren (Operator)
[Java] Implementierung des Faistel-Netzwerks
[Java] Komparator der Collection-Klasse
Java-Zusatz Excel-Datenüberprüfung
Zusammenfassung der Grundlagen der Java-Sprache
Zusammenfassung der Java Math Klasse
Java für Anfänger, Daten verstecken
Aufzählung aller Kombinationen Java
Java (Vererbung von is-ein Prinzip)
Vor- und Nachteile von Java
Importieren Sie Excel-Daten mit Java 3
Vorteile der statischen Java-Methode
[Java] Zusammenfassung der Steuerungssyntax
Java-Implementierung von Tri-Tree
Listendatenstruktur [Java / Scala]
Zusammenfassung der Java-Fehlerverarbeitung
Java Learning 1 (Lernen Sie verschiedene Datentypen)
[Java] Zusammenfassung der Entwurfsmuster
[Java] Zusammenfassung der mathematischen Operationen
[Java] Generieren Sie einen Daten-URI aus einer Byte-Zeichenfolge mit Dateiinhalten. [Kotlin]