Compiler bug
Project: | JNode Core |
Component: | Code |
Category: | bug report |
Priority: | normal |
Assigned: | Unassigned |
Status: | closed |
Code snippet from org.jnode.vm.bytecode.BasicBlockFinder
/**
* @see org.jnode.vm.bytecode.BytecodeVisitor#visit_dup2_x2()
*/
public void visit_dup2_x2() {
final int tv1 = tstack.pop();
final int tv2 = tstack.pop();
final int cat1 = JvmType.getCategory(tv1);
final int cat2 = JvmType.getCategory(tv2);
if ((cat1 == 2) && (cat2 == 2)) {
// Form 4
tstack.push(tv1);
tstack.push(tv2);
tstack.push(tv1);
} else {
final int tv3 = tstack.pop();
final int cat3 = JvmType.getCategory(tv3);
if ((cat1 == 1) && (cat2 == 1) && (cat3 == 3)) {
// Form 3
tstack.push(tv2);
tstack.push(tv1);
tstack.push(tv3);
tstack.push(tv2);
tstack.push(tv1);
} else if ((cat1 == 2) && (cat2 == 1) && (cat3 == 1)) {
// Form 2
tstack.push(tv1);
tstack.push(tv3);
tstack.push(tv2);
tstack.push(tv1);
} else {
// Form 4
final int tv4 = tstack.pop();
tstack.push(tv2);
tstack.push(tv1);
tstack.push(tv4);
tstack.push(tv3);
tstack.push(tv2);
tstack.push(tv1);
}
}
}
Should the line before the line - '// Form 3' - be written as :
if ((cat1 == 1) && (cat2 == 1) && (cat3 == 2)) {
There is not a case which the Category value equals 3, and
the second '// Form 4' line should be '// Form 1', right?
- Login to post comments
You're right...
... according to the specs here :
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc...
Maybe a checkCategory method that would throw an InvalidCategoryException would avoid such errors ?
I checked in a patch to svn
I checked in a patch to svn trunk. It is active in l1b compiler by default and it's commented out in l1a.
I do not want to activate it in l1a yet, since I wasn't able to create a testcase to verify the new implementation. If anyone could supply a testcase for this bug, please do so
#1
Changed topic. Bug is still present and we're still missing a testcase. If you ever see the line "####### dup2_x2" in JNode it is very likely you'll run into this bug.
As it will be hard to get a source file as testcase (due to different compilers might use different bytecodes) what do others think, should we add some kind of support for classfile testcases? We'd need that too for Classes testing JNode's verifier and other stuff that needs illegal class files.
#2
The version currently in trunk is quite different from the one when this bug was reported. I created a little bytecode test case to prove that the current version is correct.
Dup2Test.java shows the working of the test case. I compiled it using javac and used the Java Bytecode Editor (JBE) to edit the bytecodes of the test(..) method. You can see one usage of dup2_x2 in the attached class file.
This showed that trunk does the vstack setup correctly (the original cited version didn't). Though I discovered a strange other behavior: If you just do a pair of iload/lloads for use in dup2_x2 (so the values will not be on the stack, just on the vstack) you get some compiler exceptions. This is why I added the extra iloads/iadds/.. to the test method. I'll investigate that or/and open a separate issue for it.
Marking this one as fixed.
Left a TODO for porting the code to ORP style.
#3
Automatically closed -- issue fixed for two weeks with no activity.