天天看点

一些使用javap反编译出来的结果分析

Compiled from “stringTest.java”

public class stringTest.stringTest {undefined

public stringTest.stringTest();

Code:

0: aload_0

1: invokespecial #8 // Method java/lang/Object.""?)V

4: return

public static void main(java.lang.String[]);

//Jerry: ldc 把常量池中的项压入栈

0: ldc #16 // String Jerry

//Jerry: astore_1 将引用类型或returnAddress类型值存入局部变量1

2: astore_1

3: ldc #18 // String JS

5: astore_2

6: ldc #20 // String Developer

8: astore_3

//Jerry: 创建一个新对象

9: new #22 // class java/lang/StringBuilder

12: dup

//Jerry: 从局部变量1中装载引用类型值

13: aload_1

14: invokestatic #24 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;

//Jerry:根据编译时类型来调用实例方法 
  17: invokespecial #30                 // Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V

  20: aload_2       
  21: invokevirtual #33                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  24: aload_3       
  25: invokevirtual #33                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  
  28: invokevirtual #37                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
  31: astore        4
  33: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
  36: aload         4
  38: invokevirtual #47                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
  41: return              

}

Compiled from “stringTestLoop.java”

public class stringTest.stringTestLoop {undefined

public stringTest.stringTestLoop();

0: ldc #16 // String

3: iconst_3

4: anewarray #18 // class java/lang/String

7: dup

8: iconst_0

9: ldc #20 // String 1

11: aastore

13: iconst_1

14: ldc #22 // String 2

16: aastore

17: dup

18: iconst_2

19: ldc #24 // String 3

21: aastore

22: astore_2

23: iconst_0

24: istore_3

25: goto 52

28: new #26 // class java/lang/StringBuilder

31: dup

32: aload_1

33: invokestatic #28 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;

36: invokespecial #32 // Method java/lang/StringBuilder."":(Ljava/lang/String;)V

39: aload_2

40: iload_3

41: aaload

42: invokevirtual #35 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;

45: invokevirtual #39 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;

48: astore_1

49: iinc 3, 1

52: iload_3

53: aload_2

54: arraylength

55: if_icmplt 28

58: getstatic #43 // Field java/lang/System.out:Ljava/io/PrintStream;

61: aload_1

62: invokevirtual #49 // Method java/io/PrintStream.println:(Ljava/lang/String;)V

65: return