{"action":"created","issue":{"url":"https://api.github.com/repos/javamelody/javamelody/issues/556","repository_url":"https://api.github.com/repos/javamelody/javamelody","labels_url":"https://api.github.com/repos/javamelody/javamelody/issues/556/labels{/name}","comments_url":"https://api.github.com/repos/javamelody/javamelody/issues/556/comments","events_url":"https://api.github.com/repos/javamelody/javamelody/issues/556/events","html_url":"https://github.com/javamelody/javamelody/issues/556","id":159020136,"number":556,"title":"Java9 Support, remove use of unsupported api:s ","user":{"login":"pethers","id":1726836,"avatar_url":"https://avatars.githubusercontent.com/u/1726836?v=3","gravatar_id":"","url":"https://api.github.com/users/pethers","html_url":"https://github.com/pethers","followers_url":"https://api.github.com/users/pethers/followers","following_url":"https://api.github.com/users/pethers/following{/other_user}","gists_url":"https://api.github.com/users/pethers/gists{/gist_id}","starred_url":"https://api.github.com/users/pethers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pethers/subscriptions","organizations_url":"https://api.github.com/users/pethers/orgs","repos_url":"https://api.github.com/users/pethers/repos","events_url":"https://api.github.com/users/pethers/events{/privacy}","received_events_url":"https://api.github.com/users/pethers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-06-07T20:44:33Z","updated_at":"2017-02-10T01:09:12Z","closed_at":null,"body":"jdeps -jdkinternals javamelody-core-1.59.0.jar\njavamelody-core-1.59.0.jar -> JDK removed internal API\njavamelody-core-1.59.0.jar -> java.base\n\n   net.bull.javamelody.RrdNioBackend                  -> sun.misc.Cleaner                                   JDK internal API (JDK removed internal API)\n   net.bull.javamelody.RrdNioBackend                  -> sun.nio.ch.DirectBuffer                            JDK internal API (java.base)\n\nTested with jdk9-b121, \n\n---\n\n  [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\n     [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\n     [exec]     at net.bull.javamelody.RrdNioBackend.unmapFile(RrdNioBackend.java:101)\n     [exec]     at net.bull.javamelody.RrdNioBackend.close(RrdNioBackend.java:167)\n     [exec]     at org.jrobin.core.RrdDb.close(RrdDb.java:450)\n     [exec]     at org.jrobin.core.RrdDbPool.release(RrdDbPool.java:192)\n     [exec]     at net.bull.javamelody.JRobin.addValue(JRobin.java:354)\n##      [exec]     at net.bull.javamelody.Collector.collectJRobinValues(Collector.java:511)\n\nCan force export of sun.nio.ch.DirectBuffer with arg \"-XaddExports:java.base/sun.nio.ch=ALL-UNNAMED\"\n\nAccording 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 .\n\nLast exception\n\n---\n\n2016-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;\n     [exec] java.lang.NoSuchMethodError: sun.nio.ch.DirectBuffer.cleaner()Lsun/misc/Cleaner;\n     [exec]     at net.bull.javamelody.RrdNioBackend.unmapFile(RrdNioBackend.java:102)\n     [exec]     at net.bull.javamelody.RrdNioBackend.close(RrdNioBackend.java:167)\n     [exec]     at org.jrobin.core.RrdDb.close(RrdDb.java:450)\n     [exec]     at org.jrobin.core.RrdDbPool.release(RrdDbPool.java:192)\n     [exec]     at net.bull.javamelody.JRobin.addValue(JRobin.java:354)\n     [exec]     at net.bull.javamelody.Collector.collectJRobinValues(Collector.java:511)\n\n---\n\nWill try to provide a pull request later this week.\n"},"comment":{"url":"https://api.github.com/repos/javamelody/javamelody/issues/comments/278828153","html_url":"https://github.com/javamelody/javamelody/issues/556#issuecomment-278828153","issue_url":"https://api.github.com/repos/javamelody/javamelody/issues/556","id":278828153,"user":{"login":"evernat","id":498950,"avatar_url":"https://avatars.githubusercontent.com/u/498950?v=3","gravatar_id":"","url":"https://api.github.com/users/evernat","html_url":"https://github.com/evernat","followers_url":"https://api.github.com/users/evernat/followers","following_url":"https://api.github.com/users/evernat/following{/other_user}","gists_url":"https://api.github.com/users/evernat/gists{/gist_id}","starred_url":"https://api.github.com/users/evernat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evernat/subscriptions","organizations_url":"https://api.github.com/users/evernat/orgs","repos_url":"https://api.github.com/users/evernat/repos","events_url":"https://api.github.com/users/evernat/events{/privacy}","received_events_url":"https://api.github.com/users/evernat/received_events","type":"User","site_admin":false},"created_at":"2017-02-10T01:09:12Z","updated_at":"2017-02-10T01:09:12Z","body":"I have made some research and jdk state has changed since last year.\r\n\r\nThere is [JDK-4724038](https://bugs.openjdk.java.net/browse/JDK-4724038) which is not yet resolved, but [JDK-8171377](https://bugs.openjdk.java.net/browse/JDK-8171377) is resolved and available in JDK9 build 150.\r\nIt seems that sun.misc.Unsafe.theUnsafe.invokeCleaner(buffer) and reflection is now the way to go for JDK 9.\r\n\r\nSo when java 9 is detected, we could use some code like this in RrdNioBackedn.unmapFile():\r\n```java\r\nfinal Class<?> unsafeClass = Class.forName(\"sun.misc.Unsafe\");\r\nfinal Field theUnsafeField = unsafeClass.getDeclaredField(\"theUnsafe\");\r\ntheUnsafeField.setAccessible(true);\r\nfinal Object theUnsafe = theUnsafeField.get(null);\r\nfinal Method invokeCleanerMethod = unsafeClass.getMethod(\"invokeCleaner\", ByteBuffer.class);\r\ninvokeCleanerMethod.invoke(theUnsafe, byteBuffer);\r\n```\r\n(This may fail on non-Hotspot/OpenJDK JVMs and the class or method may not be available.)\r\n\r\nThe trick is that the sun.misc.Unsafe is in the [critical internal API list](http://openjdk.java.net/jeps/260) 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."}}
{"actor":{"display_login":"evernat"}}