I'm having trouble understanding the usage of some Java Bytecode Instructions, partially due to lack of examples. Instead, I use javac
or Jasmin to compile some regular Java code, and then I use javap -c
to inspect the generated bytecode.
My project is built on a framework that optimizes my bytecode for me, so my own code generator doesn't have to manage the constant pool for me. Since the javap
output contains a lot of reference to the constant pool, that doesn't really clear up the usage if I don't have to make use of those references myself.
Is there a way of getting disassembled bytecode without the symbol table (or any references to it)?
To elaborate, suppose we have the following code:
public class MyConcatCode {
public static void main(String[] args){
String a ="Hello ";
String b ="World!";
String c = new StringBuilder().append(a).append(b).toString();
}
}
This resolves to:
...
0: ldc #7 // String Hello
2: astore_1
3: ldc #9 // String World!
5: astore_2
6: new #11 // class java/lang/StringBuilder
9: dup
10: invokespecial #13 // Method java/lang/StringBuilder."<init>":()V
13: aload_1
14: invokevirtual #14 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
17: aload_2
18: invokevirtual #14 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
21: invokevirtual #18 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
24: astore_3
25: return
...
But I'd much rather have the following:
...
0: ldc Hello
2: astore_1
3: ldc World!
5: astore_2
6: new java/lang/StringBuilder
9: dup
10: invokespecial java/lang/StringBuilder."<init>":()V
13: aload_1
14: invokevirtual java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
17: aload_2
18: invokevirtual java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
21: invokevirtual java/lang/StringBuilder.toString:()Ljava/lang/String;
24: astore_3
25: return
...
If, like the framework supplied to me, the compiler creates the constant pool after producing bytecode described in my second example, then it should be possible to get bytecode that doesn't contain a symbol table at all, right?