Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java9 Support, remove use of unsupported api:s #556

Closed
pethers opened this issue Jun 7, 2016 · 13 comments
Closed

Java9 Support, remove use of unsupported api:s #556

pethers opened this issue Jun 7, 2016 · 13 comments

Comments

@pethers
Copy link
Contributor

pethers commented Jun 7, 2016

jdeps -jdkinternals javamelody-core-1.59.0.jar
javamelody-core-1.59.0.jar -> JDK removed internal API
javamelody-core-1.59.0.jar -> java.base

net.bull.javamelody.RrdNioBackend -> sun.misc.Cleaner JDK internal API (JDK removed internal API)
net.bull.javamelody.RrdNioBackend -> sun.nio.ch.DirectBuffer JDK internal API (java.base)

Tested with jdk9-b121,


[exec] 2016-06-07 22:09:00,994 [main] WARN n.b.javamelody - exception while collecting data: java.lang.IllegalAccessError: class net.bull.javamelody.RrdNioBackend (in unnamed module @0x65d6b83b) cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x65d6b83b
[exec] java.lang.IllegalAccessError: class net.bull.javamelody.RrdNioBackend (in unnamed module @0x65d6b83b) cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x65d6b83b
[exec] at net.bull.javamelody.RrdNioBackend.unmapFile(RrdNioBackend.java:101)
[exec] at net.bull.javamelody.RrdNioBackend.close(RrdNioBackend.java:167)
[exec] at org.jrobin.core.RrdDb.close(RrdDb.java:450)
[exec] at org.jrobin.core.RrdDbPool.release(RrdDbPool.java:192)
[exec] at net.bull.javamelody.JRobin.addValue(JRobin.java:354)

[exec] at net.bull.javamelody.Collector.collectJRobinValues(Collector.java:511)

Can force export of sun.nio.ch.DirectBuffer with arg "-XaddExports:java.base/sun.nio.ch=ALL-UNNAMED"

According to https://wiki.openjdk.java.net/display/JDK8/Java+Dependency+Analysis+Tool , sun.misc.Cleaner can be replaced with java.lang.ref.PhantomReference @SInCE 1.2 .

Last exception


2016-06-07 22:25:55,403 [main] WARN n.b.javamelody - exception while collecting data: java.lang.NoSuchMethodError: sun.nio.ch.DirectBuffer.cleaner()Lsun/misc/Cleaner;
[exec] java.lang.NoSuchMethodError: sun.nio.ch.DirectBuffer.cleaner()Lsun/misc/Cleaner;
[exec] at net.bull.javamelody.RrdNioBackend.unmapFile(RrdNioBackend.java:102)
[exec] at net.bull.javamelody.RrdNioBackend.close(RrdNioBackend.java:167)
[exec] at org.jrobin.core.RrdDb.close(RrdDb.java:450)
[exec] at org.jrobin.core.RrdDbPool.release(RrdDbPool.java:192)
[exec] at net.bull.javamelody.JRobin.addValue(JRobin.java:354)
[exec] at net.bull.javamelody.Collector.collectJRobinValues(Collector.java:511)


Will try to provide a pull request later this week.

@pethers
Copy link
Contributor Author

pethers commented Jun 12, 2016

Didn't find any easy solution, one solution to support different jdk provider and 7-9 https://sourceforge.net/p/tuer/code/HEAD/tree/pre_beta/src/main/java/engine/misc/DeallocationHelper.java

@pethers
Copy link
Contributor Author

pethers commented Jun 14, 2016

Found a possible solution at pethers@60916dd , tested with JDK8, JDK9_b121 require jvm option for JDK9
"-XaddExports:java.base/jdk.internal.ref=ALL-UNNAMED" .

@evernat
Copy link
Member

evernat commented Jun 14, 2016

Thanks @pethers
I will need a bit of time to test that.
Does it work with JDK 1.6 like that ? I am not sure according to stackoverflow

@pethers
Copy link
Contributor Author

pethers commented Jun 15, 2016

No hurry, don't expect to run JDK9 any time soon. Just want to make sure all blockers are resolved before the java 9 release. Probably a lots of other people having the same issues, so maybe a better solution shows up later on.

@evernat
Copy link
Member

evernat commented Feb 10, 2017

I have made some research and jdk state has changed since last year.

There is JDK-4724038 which is not yet resolved, but JDK-8171377 is resolved and available in JDK9 build 150.
It seems that sun.misc.Unsafe.theUnsafe.invokeCleaner(buffer) and reflection is now the way to go for JDK 9.

So when java 9 is detected, we could use some code like this in RrdNioBackend.unmapFile():

final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
final Field theUnsafeField = unsafeClass.getDeclaredField("theUnsafe");
theUnsafeField.setAccessible(true);
final Object theUnsafe = theUnsafeField.get(null);
final Method invokeCleanerMethod = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);
invokeCleanerMethod.invoke(theUnsafe, byteBuffer);

(This may fail on non-Hotspot/OpenJDK JVMs and the class or method may not be available.)

The trick is that the sun.misc.Unsafe is in the critical internal API list proposed to remain accessible in JDK 9, whereas sun.misc.Cleaner and sun.nio.ch.DirectBuffer are unfortunately not in that list. That's the cause for the new invokeCleaner method in sun.misc.Unsafe added in JDK 9.

@pethers
Copy link
Contributor Author

pethers commented Feb 10, 2017

Looks good, happy to test if needed ?

@evernat
Copy link
Member

evernat commented Feb 10, 2017

Yes you can. It would be great.

pethers added a commit to Hack23/cia that referenced this issue Feb 10, 2017
@pethers
Copy link
Contributor Author

pethers commented Feb 11, 2017

evernat added a commit that referenced this issue Feb 12, 2017
#556 : Java 9 compatibility
@evernat
Copy link
Member

evernat commented Feb 12, 2017

I clicked on "create pull request" in the comparison.
And #609 is now merged. I will keep the method instance in cache and it will be good to go.
Thanks.

@evernat evernat closed this as completed Feb 12, 2017
@lepirlouit
Copy link

lepirlouit commented Sep 22, 2017

still an issue for me in version 1.69.0 : with jdk 9 in ubuntu 16.04 9-internal+0-2016-04-14-195246.buildd.src

@evernat
Copy link
Member

evernat commented Sep 24, 2017

@lepirlouit
You are using OpenJDK Runtime Environment, 9-internal+0-2016-04-14-195246.buildd.src. That's an old build of openjdk 9.
You need to install a newer version and the GA release of openjdk 9 is now available at: http://jdk.java.net/9/
or of Oracle JDK 9: http://www.oracle.com/technetwork/java/javase/downloads/index.html

pethers added a commit to Hack23/cia that referenced this issue Mar 9, 2018
@hemmanj
Copy link

hemmanj commented Mar 16, 2018

Hello,

I use the jRobin1.5.9.1. I see the exception with java9 runtime. The solutions i.e. adding below additions to jvm arguments does not work . Could you suggested what's the latest fix for this problem?
--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED

Exception seen:
java.lang.NoSuchMethodError: sun.nio.ch.DirectBuffer.cleaner()Lsun/misc/Cleaner;
at org.jrobin.core.RrdNioBackend.unmapFile(Unknown Source)
at org.jrobin.core.RrdNioBackend.setLength(Unknown Source)
at org.jrobin.core.RrdDb.(Unknown Source)
at org.jrobin.core.RrdDb.(Unknown Source)
at org.jrobin.core.RrdDbPool.requestRrdDb(Unknown Source)

thanks

@evernat
Copy link
Member

evernat commented Mar 21, 2018

@hemmanj
You need to use a recent javamelody version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants