#948 Truly strange bytecode generated

open
nobody
emitter (227)
5
2006-04-07
2006-04-07
Anonymous
No

I have a large codebase for which a small set of files
whose source is not changing is occasionally getting
some very odd bytecode emitted. For example, this
function:

public void loadPageData() {
Runtime runtime = Runtime.getRuntime();
System.out.println(">>>" +
(runtime.totalMemory()-
runtime.freeMemory()) +
" bytes used; " +
runtime.freeMemory() +
" bytes available of " +
runtime.totalMemory() +
" [max " +
runtime.maxMemory() + "]");
super.loadPageData();
mecaSiteSummary =
new GetMecaSiteSummaryByNameRequest
(siteNameVar.getValue())
.getSummary();
}

generates this with jikes (some stuff taken out for
brevity's sake):

public void loadPageData();
Code:
Stack=6, Locals=2, Args_size=1
0: invokestatic #37; //Method
java/lang/Runtime.getRuntime:()Ljava/lang\ /Runtime;
3: astore_1
4: getstatic #43; //Field
java/lang/System.out:Ljava/io/PrintStream;
7: new #46; //class StringBuffer
10: dup
....many more lines skipped here, you get the idea...
67: ldc #73; //String ]
69: invokevirtual #54; //Method
java/lang/StringBuffer.append:(Ljava/lang\ /String;)Ljava/lang/StringBuffer;
72: invokevirtual #77; //Method
java/lang/StringBuffer." bytes used; ":()\ Ljava/lang/String;

Note the completely bizarre function call on line 72.
Sometimes on line 7, instead of generating a new
StringBuffer, it generates a new "append". The
constant pool just gets hosed. I've sometime made this
problem go away by adding dummy data or methods to
this class.

On the other hand, the painfully slow javac generates
the right code:

public void loadPageData();
Code:
Stack=6, Locals=2, Args_size=1
0: invokestatic #17; //Method
java/lang/Runtime.getRuntime:()Ljava/lang\ /Runtime;
3: astore_1
4: getstatic #18; //Field
java/lang/System.out:Ljava/io/PrintStream;
7: new #19; //class StringBuffer
10: dup
...lines deleted...
67: ldc #30; //String ]
69: invokevirtual #22; //Method
java/lang/StringBuffer.append:(Ljava/lang\ /String;)Ljava/lang/StringBuffer;
72: invokevirtual #31; //Method
java/lang/StringBuffer.toString:()Ljava/l\ ang/String;

Interetingly, this only seems to happen if the file is
compiled as part of a big blob of classes. If I do
that, but then immediately compile this guy again by
himself, the problem seems to go away.

Discussion