Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 315398

Summary: Verify Error
Product: [Tools] AspectJ Reporter: pmoret <philippe.moret>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: aclement
Version: unspecified   
Target Milestone: 1.6.12   
Hardware: PC   
OS: Linux   
Whiteboard:

Description pmoret CLA 2010-06-02 10:18:02 EDT
A simple method:
static void f(){
    new Test(a[0]++);
}

woven with a simple advice:

after() returning(Object obj) : call(*.new(..)) && scope(..) {
 // do something
}

Causes a Verify Error (both statically and LTW woven)

The bytecodes before weaving:
static void f();
  Code:
   0:	new	#2; //class Test
   3:	dup
   4:	getstatic	#3; //Field a:[I
   7:	iconst_0
   8:	dup2
   9:	iaload
   10:	dup_x2
   11:	iconst_1
   12:	iadd
   13:	iastore
   14:	invokespecial	#4; //Method "<init>":(I)V
   17:	pop
   18:	return


and after weaving:
static void f();
  Code:
   0:	getstatic	#10; //Field a:[I
   3:	iconst_0
   4:	dup2
   5:	iaload
   6:	dup
   7:	iconst_1
   8:	iadd
   9:	iastore
   10:	istore_0
   11:	new	#1; //class Test
   14:	dup
   15:	iload_0
   16:	invokespecial	#28; //Method "<init>":(I)V
   19:	dup
   20:	astore_1
   21:	invokestatic	#37; //Method AllocProf.aspectOf:()LAllocProf;
   24:	aload_1
   25:	invokevirtual	#41; //Method AllocProf.ajc$afterReturning$AllocProf$1$1858a042:(Ljava/lang/Object;)V
   28:	nop
   29:	pop
   30:	return

}

and the Error: 
"Exception in thread "main" java.lang.VerifyError: (class: Test, method: f signature: ()V) Expecting to find array of ints on stack."

It seems that the instructions are reordered (call to new moved, argument stored/loaded) at some point the stack is left in an inconsistent state...
I think the dup at pos 14 should be a dup_x2 instead...
Comment 1 pmoret CLA 2010-06-04 10:03:02 EDT
Forget the comment about pos 14, the problem is that at pos 9 there are three ints on top of the stack ...
Comment 2 Andrew Clement CLA 2011-04-28 14:07:00 EDT
to fix this I had to remove something added long ago.  The thing I removed was a bit of a 'hack' to cope with some unusual bytecode that had been seen out in the wild.  I have never seen a compiler produce the bytecode it was coping with (must have been artificial) whereas the test program here is quite clearly produced by the JDT compiler.   If I get a valid testcase for the case that code was coping with, I'll revisit that hack and do it properly.

Anyway, this case is now fixed. thanks for the clear bug report.