1 | public class HelloWorld { |
invokevirtual
$ javap -c HelloWorld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Compiled from "HelloWorld.java"
public class HelloWorld {
public HelloWorld();
Code:
0: aload_0
// Method java/lang/Object."<init>":()V
1: invokespecial #1
4: return
public static void main(java.lang.String[]);
Code:
// Field java/lang/System.out:Ljava/io/PrintStream;
0: getstatic #2
// String hello world
3: ldc #3
// Method java/io/PrintStream.println:(Ljava/lang/String;)V
5: invokevirtual #4
8: return
}
The property out
in System is a packaged
type PrintStream
.
There is a BufferedOutputStream
inside PrintStream
.
1 | public final class System { |
The init method called after thread initialization, initialize the system class.
1 | private static PrintStream newPrintStream(FileOutputStream fos, String enc) { |
package buffer function into out
. base on encoding, create output stream object.
1
2
3
4
5
6
7
8
9JNIEXPORT void JNICALL
Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
{
jfieldID fid =
(*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
if (fid == 0)
return;
(*env)->SetStaticObjectField(env,cla,fid,stream);
}
The native method
setOut0
will call this c function.fid
the member ofSystem
theout
‘s id."Ljava/io/PrintStream;"
meanjava.io.PrintStream
object
SetStaticObjectField
define here.1
2void (JNICALL *SetStaticObjectField)
(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);