Bug 552951 - aspectjtools.jar & aspectjweaver.jar - internal API usage in Java 11
Summary: aspectjtools.jar & aspectjweaver.jar - internal API usage in Java 11
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Library (show other bugs)
Version: 1.9.4   Edit
Hardware: PC Windows 10
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-12 07:03 EST by Rohit Gaikwad CLA
Modified: 2019-11-26 12:22 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rohit Gaikwad CLA 2019-11-12 07:03:14 EST
The aspectjtools & aspectjweaver jars of version 1.9.4 are making use of jdk.unsupported module’s class sun.misc.UnSafe which makes use of JDK Internal APIs.

http://openjdk.java.net/jeps/260 states that use of non-standard, unstable, and unsupported APIs that are internal implementation details of the JDK were never intended for external use.
This JEP does not commit to preserve the compatibility of any internal APIs across releases; they continue to remain unstable and subject to change without notice.

We are migrating our product to Java 11 & this would lead us into a unstable situation, further there can be a blocker if the internal APIs are removed without notice.
Hence, To avoid the above situation an alternative needs to be find for the usage of sun.misc.UnSafe in those 2 jars(aspectjtools & aspectjweaver).

Jar Name	ClassName	Issue
aspectjtools.jar	org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor	sun.misc.Unsafe (JDK internal API (jdk.unsupported))
aspectjweaver.jar	org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor	sun.misc.Unsafe (JDK internal API (jdk.unsupported))
Comment 1 Rohit Gaikwad CLA 2019-11-12 07:05:34 EST
#Addind a well formatted issue#

Jar Name	   ClassName	                                            Issue
aspectjtools.jar   org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor   sun.misc.Unsafe (JDK internal API (jdk.unsupported))
aspectjweaver.jar  org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor   sun.misc.Unsafe (JDK internal API (jdk.unsupported))
Comment 2 Andrew Clement CLA 2019-11-14 12:50:17 EST
I have planned to review the situation for 1.9.5.
Comment 3 Andrew Clement CLA 2019-11-26 12:22:26 EST
Right, paging this back into my brain.

I've actually already done the work to avoid using Unsafe on Java11.  It looks like you are using a jar scanner rather than running code against the weaver?

Inside CLWA there are different codepaths depending on the JDK level:

if (LangUtil.is11VMOrGreater()) {
  if (!initializedForJava11) {
    initializeForJava11();
  }
  // Do this: clazz = defineClassMethodHandle.bindTo(loader).invokeWithArguments(name, bytes, 0, bytes.length, protectionDomain);
  Object o = bindTo_Method.invoke(defineClassMethodHandle,loader);
  clazz = invokeWithArguments_Method.invoke(o, new Object[] {new Object[] {name, bytes, 0, bytes.length, protectionDomain}});

} else {
  if (defineClassMethod == null) {
    synchronized (lock) {
      getUnsafe();
      defineClassMethod = Unsafe.class.getDeclaredMethod("defineClass", String.class,byte[].class,Integer.TYPE,Integer.TYPE, ClassLoader.class,ProtectionDomain.class);
    }
  }
  defineClassMethod.setAccessible(true);
  clazz = defineClassMethod.invoke(getUnsafe(), name,bytes,0,bytes.length,loader,protectionDomain);
}

So unsafe is only used below Java11. Now on Java11 you do a slight nasty that I want to try and address, and the problem/workaround is covered in bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=546305 - but that is not as bad I would say.

If you are seeing Unsafe related problems when running on AspectJ with Java11, let me know.