@alex
把stripAtrribute设置成false后,即新的方法生成linenumber和localvariable属性
这是原先的属性信息
private String buildString$impl(int length)
Code(max_stack = 3, max_locals = 4, code_length = 51)
0: ldc "" (16)
2: astore_2
3: iconst_0
4: istore_3
5: goto #37
8: new <java.lang.StringBuilder> (18)
11: dup
12: aload_2
13: invokestatic java.lang.String.valueOf (Ljava/lang/Object;)Ljava/lang/String; (20)
16: invokespecial java.lang.StringBuilder.<init> (Ljava/lang/String;)V (26)
19: iload_3
20: bipush 26
22: irem
23: bipush 97
25: iadd
26: i2c
27: invokevirtual java.lang.StringBuilder.append (C)Ljava/lang/StringBuilder; (29)
30: invokevirtual java.lang.StringBuilder.toString ()Ljava/lang/String; (33)
33: astore_2
34: iinc %3 1
37: iload_3
38: iload_1
39: if_icmplt #8
42: getstatic java.lang.System.out Ljava/io/PrintStream; (37)
45: aload_2
46: invokevirtual java.io.PrintStream.println (Ljava/lang/String;)V (43)
49: aload_2
50: areturn
Attribute(s) =
LocalVariable(start_pc = 0, length = 51, index = 0:StringBuilder this)
LocalVariable(start_pc = 0, length = 51, index = 1:int length)
LocalVariable(start_pc = 3, length = 48, index = 2:String result)
LocalVariable(start_pc = 5, length = 40, index = 3:int i)
LineNumber(0, 6), LineNumber(3, 7), LineNumber(8, 8), LineNumber(34, 7),
LineNumber(42, 10), LineNumber(49, 12)
--------------------------------------------------------
完整的code.toString的信息
private String buildString(int length)
Code(max_stack = 6, max_locals = 5, code_length = 37)
0: invokestatic java.lang.System.currentTimeMillis ()J (81)
3: lstore_2
4: aload_0
5: iload_1
6: invokespecial StringBuilder.buildString$impl (I)Ljava/lang/String; (83)
9: astore %4
11: getstatic java.lang.System.out Ljava/io/PrintStream; (37)
14: dup
15: dup
16: ldc "Call to method buildString$impl took " (85)
18: invokevirtual java.io.PrintStream.print (Ljava/lang/String;)V (88)
21: invokestatic java.lang.System.currentTimeMillis ()J (81)
24: lload_2
25: lsub
26: invokevirtual java.io.PrintStream.print (J)V (91)
29: ldc " ms." (93)
31: invokevirtual java.io.PrintStream.println (Ljava/lang/String;)V (43)
34: aload %4
36: areturn
Attribute(s) =
LocalVariable(start_pc = 0, length = 51, index = 0:StringBuilder this)
LocalVariable(start_pc = 0, length = 51, index = 1:int length)
LocalVariable(start_pc = 3, length = 48, index = 2:String result)
LocalVariable(start_pc = 5, length = 40, index = 3:int i)
LineNumber(0, 6), LineNumber(3, 7), LineNumber(8, 8), LineNumber(34, 7),
LineNumber(42, 10), LineNumber(49, 12)
end method method method-----------------------------------
这个属性信息使用还是使用的原先方法的,显然length=55超过了指令的长度
36,执行时会检查类的局部变量属性信息发现不正确就报错了
这两个属性的信息应该是用来调试器来使用的,可以自己在字节码文件中自己添加这些信息,不过自己添加比较麻烦.
不过我另外一个程序的方法也自己生成了属性信息,这些属性信息也改变了,但是改变的不正确,但是程序能够执行。。
这中的原因我现在也搞不清楚了。
回复 更多评论