Bug 538115 - EXCEPTION_PRIV_INSTRUCTION - unimplemented bytecode
Summary: EXCEPTION_PRIV_INSTRUCTION - unimplemented bytecode
Status: RESOLVED WORKSFORME
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.9.1   Edit
Hardware: PC Windows 7
: P3 blocker with 10 votes (vote)
Target Milestone: 1.9.2   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-21 07:00 EDT by Lachezar Stoev CLA
Modified: 2018-08-28 12:26 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lachezar Stoev CLA 2018-08-21 07:00:14 EDT
When using aspectjweaver version=1.7.1/1.9.1, OS=Windows7 with the following code:

public class Foo {
	
	private Bar bar = new Bar();
	
	public static void main(String[] args) {
		Foo foo = new Foo();
		foo.f();
	}
	 
	public void f() {
		boolean bool = false;
		if (bool) {
			new ArrayList<>().forEach(x -> {
			});
		}
		bar.f();
	}

	static class Bar {
		@RecordingMethodOutput(id = "Shit")
		public String f() {
			return "";
		}
	}
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface RecordingMethodOutput {
	public String id();
}

@Aspect
class MyAspect {

	@Around("@annotation(com.rbsfm.component.test.recording.RecordingMethodOutput)")
	public Object aroundProducer(ProceedingJoinPoint joinPoint) throws Throwable {
		return joinPoint.proceed();
	}
}

META-INF/aop.xml:
<aspectj>
	<weaver options="-verbose">
		<include within="com.rbsfm..*" />
	</weaver>

	<aspects>
		<aspect name="com.rbsfm.component.test.recording.MyAspect"/>
	</aspects>
</aspectj>

VM arguments: -javaagent:${path_to_jar}\aspectjweaver-1.7.1.jar -noverify

We get an exception:
=============== DEBUG MESSAGE: unimplemented bytecode ================

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_PRIV_INSTRUCTION (0xc0000096) at pc=0x0000000002b95936, pid=12000, tid=0x0000000000002d08
#
# JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# j  com.rbsfm.component.test.recording.Foo.f()V+0
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\stoezar\eclipse-workspace\component.test.recording\hs_err_pid12000.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#
Comment 1 Nikolay Tsankov CLA 2018-08-21 09:13:10 EDT
When testing the actual code we get a different error (could not reproduce it with this test code):

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006f5f14ad, pid=16268, tid=0x00000000000034c4
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V  [jvm.dll+0xc14ad]
#
Comment 2 Andrew Clement CLA 2018-08-22 16:56:36 EDT
You mentioned this with 1.7.1 and 1.9.1. I didn't have 1.7.1 installed but I had 1.7.4 and it failed with that.  If I don't specify -noverify then the real problem with the classfile surfaces:


Exception in thread "main" java.lang.ClassFormatError: Illegal local variable table length 76 in method Foo.f()V
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

It works fine with 1.9.1 for me. Does it definitely still fail for you in the same way on 1.9.1 - can you try without -noverify do you see the same issue?

My suspicion is there is another bug marked fixed for this issue - i suspect it is related to bug 435446. That was fixed AspectJ 1.8.1 - and indeed the problem above happens for me in 1.8.0 but not 1.8.1.  Do you need to be on such an old AspectJ? Given that 1.7.1 doesn't explicitly support Java8 and yet the code you are weaving includes lambdas, i think you ought to upgrade to at least the most recent 1.8 AspectJ.  But if you tell me it still happens on 1.9.1 clearly there is still something to sort out.
Comment 3 Nikolay Tsankov CLA 2018-08-23 05:10:44 EDT
Actually as reported (with the annotation defined inline) the test passes on 1.9.1, moving the annotation to its own file breaks it. Please try that, might need to be in another package. 

Depending on the setup, we get different errors without -noverify option:

Either the one you also saw or one of those:

AspectJ Internal Error: unable to add stackmap attributes. null
Exception in thread "main" java.lang.ClassFormatError: Illegal exception table start_pc 236 in method com.rbsfm.component.test.recording.RecordingTest.start()V
            at java.lang.Class.forName0(Native Method)


AspectJ Internal Error: unable to add stackmap attributes. null
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 229
Exception Details:
  Location:
    com/x/y/test/recording/RecordingTest.start()V @4: if_icmpge
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: 033c 1b05 a200 e12a b400 0e3a 04b2 008d
    0x0000010: 2a19 04b8 0093 3a05 b800 a606 bd00 1f3a
    0x0000020: 0619 0603 2a53 1906 0419 0453 1906 0519
    0x0000030: 0553 bb00 9759 1906 b700 9a11 1010 b600
    0x0000040: a0b6 00aa c000 444d b200 10bb 0011 59b7
    0x0000050: 0012 1213 b600 142c b600 15b6 0016 b600
    0x0000060: 172a b400 053a 07b2 00ad 2a19 07b8 0093
    0x0000070: 3a08 b800 a606 bd00 1f3a 0919 0903 2a53
    0x0000080: 1909 0419 0753 1909 0519 0853 bb00 b059
    0x0000090: 1909 b700 b111 1010 b600 a0b6 00aa c000
    0x00000a0: 444d b200 10bb 0011 59b7 0012 1218 b600
    0x00000b0: 142c b600 15b6 0016 b600 172a b400 0e04
    0x00000c0: b800 19b9 001a 0200 2ab4 0005 04b8 0019
    0x00000d0: b900 1a02 0014 001b b800 1da7 0004 4e84
    0x00000e0: 0101 a7ff 20b1                         
  Exception Handler Table:
    bci [213, 219] => handler: 222

            at java.lang.Class.forName0(Native Method)
Comment 4 Nikolay Tsankov CLA 2018-08-23 05:33:45 EDT
Forgot to add: changing the forEach to a plain "for" loop or having the "if" condition evaluate to true results in no error
Comment 5 Lachezar Stoev CLA 2018-08-24 07:55:13 EDT
We still get the same exception with 1.9.1 version with the code from the first comment. 
You wrote: "It works fine with 1.9.1 for me", but I don't know why you can not reproduce the issue, there may be some configuration mismatch.
Environment:
OS: Windows 7 , 64 bit Build 7601 (6.1.7601.24168)
JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode windows-amd64 compressed oops)

Please tell us if you need more information.
Comment 6 Andrew Clement CLA 2018-08-24 14:30:42 EDT
I wasn't running totally identically because I separated it out into files I also had to adjust the annotation reference in the pointcut because there are no package statements in those sources. 

The illegal exception table thing you included is interesting and is what might mean it is different to bug 435446.

Let me play around with some more combinations and I'll include exactly what I am running if that doesn't show it.
Comment 7 Andrew Clement CLA 2018-08-24 15:32:48 EDT
Ok I have 3 files in a directory. Here i moved the annotation into a separate package - it made no difference, I can't see the issue:

--- Foo.java ---
package com.rbsfm.component.test.recording;

import com.rbsfm.component.test.recording.x.*;
import java.util.*;

public class Foo {

       private Bar bar = new Bar();

       public static void main(String[] args) {
               Foo foo = new Foo();
               foo.f();
       }

       public void f() {
               boolean bool = false;
               if (bool) {
                       new ArrayList<>().forEach(x -> {
                       });
               }
               bar.f();
       }

       static class Bar {
               @RecordingMethodOutput(id = "Shit")
               public String f() {
                       return "";
               }
       }
}
---

--- RecordingMethodOutput.java ---
package com.rbsfm.component.test.recording.x;
import java.lang.annotation.*;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RecordingMethodOutput {
       public String id();
}


---

--- MyAspect.java ---
package com.rbsfm.component.test.recording;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.*;

@Aspect
class MyAspect {


@Around("@annotation(com.rbsfm.component.test.recording.x.RecordingMethodOutput)")
       public Object aroundProducer(ProceedingJoinPoint joinPoint) throws
Throwable {
               return joinPoint.proceed();
       }
}
---

Compile them:

mkdir out
javac -d out Foo.java RecordingMethodOutput.java

ajc -1.8 -classpath $CLASSPATH:out -d out2 -outxml MyAspect.java

I then slightly tweak the outxml to include debug:

--- out2/META-INF/aop-ajc.xml ---
<aspectj>
	<weaver options="-verbose -showWeaveInfo">
	</weaver>
<aspects>
<aspect name="com.rbsfm.component.test.recording.MyAspect"/>
</aspects>
</aspectj>
---

Run it without:
java -classpath $CLASSPATH:out com.rbsfm.component.test.recording.Foo

Run it with:
java -javaagent:/Users/aclement/installs/aspectj191/lib/aspectjweaver.jar -classpath $CLASSPATH:out:out2 com.rbsfm.component.test.recording.Foo
...

[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(java.lang.String com.rbsfm.component.test.recording.Foo$Bar.f())' in Type 'com.rbsfm.component.test.recording.Foo' (Foo.java:21) advised by around advice from 'com.rbsfm.component.test.recording.MyAspect' (MyAspect.java)
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-execution(java.lang.String com.rbsfm.component.test.recording.Foo$Bar.f())' in Type 'com.rbsfm.component.test.recording.Foo$Bar' (Foo.java:27) advised by around advice from 'com.rbsfm.component.test.recording.MyAspect' (MyAspect.java)
...

Runs fine (and runs fine with noverify).

Can you tell me which of those steps I am doing differently to you so we can work out the issue? I do notice your stack trace includes com.rbsfm.component.test.recording.RecordingTest which obviously isn't a type I'm using. I assume Foo is derived from it.
Comment 8 Lachezar Stoev CLA 2018-08-27 11:59:01 EDT
We reproduce the issue with this code..
Can you tell us what version of java you are using as well as OS(Windows,Linux) info and all related environment specifications.
Comment 9 Andrew Clement CLA 2018-08-27 14:20:34 EDT
That was on Mac with 1.8.1_131. Let me try windows.
Comment 10 Andrew Clement CLA 2018-08-27 15:41:47 EDT
Windows 10 - Java 1.8.0_171 - works ok. I don't have a Windows 7 to try it on unfortunately. Let me try linux.
Comment 11 Andrew Clement CLA 2018-08-27 15:59:05 EDT
Linux Ubuntu 18.04.1  Java 1.8.0_171 - works ok

Do you see the same problem if you skip loadtime weaving and just do compile time weaving?

ajc -1.8 -showWeaveInfo RecordingMethodOutput.java Foo.java MyAspect.java

and run the result.

If you do, can you attach the classfile with the problem so I can compare it to mine (presumably the Foo class)
Comment 12 Nikolay Tsankov CLA 2018-08-28 05:18:08 EDT
Even though we specify 1.9.1 with -javaagent, we still had the 1.7.1 jar in the classpath (as a transitive dependency from another library). Removing the 1.7.1 jar from the classpath resolves the issue.
Thanks a lot for the help and I think you can resolve/close the issue
Comment 13 Andrew Clement CLA 2018-08-28 12:26:19 EDT
thanks for confirming.