JVM bytecode question when use `System.out.println`

Viewed 23

here is an example of https://blogs.oracle.com/javamagazine/post/java-class-file-constant-pool

class Hello {
    public static void main( String[] args ) {
        for( int i = 0; i < 10; i++ )
            System.out.println( "Hello from Hello.main!" );
  }
}

bytecode as below

 0: iconst_0
 1: istore_1
 2: iload_1
 3: bipush        10
 5: if_icmpge     22
 8: getstatic     #2  // Field java/lang/System.out:Ljava/io/PrintStream;
11: ldc           #3  // String Hello from Hello.main!
13: invokevirtual #4  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
16: iinc          1, 1
19: goto          2
22: return

Now my question is why there is 8: getstatic step?

1 Answers

The getstatic instruction loads the value of the static field System.out.

Related