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 internal api:s #3

Open
pethers opened this issue Jun 14, 2016 · 1 comment
Open

Java9 Support, remove use of internal api:s #3

pethers opened this issue Jun 14, 2016 · 1 comment

Comments

@pethers
Copy link

pethers commented Jun 14, 2016

jdeps result

org.jrobin.core.RrdNioBackend -> sun.misc.Cleaner JDK internal API (JDK removed internal API)
org.jrobin.core.RrdNioBackend -> sun.nio.ch.DirectBuffer JDK internal API (java.base)

Support Oracle JDK6-9

fix from
http://stackoverflow.com/questions/1854398/how-to-garbage-collect-a-direct-buffer-java


private void unmapFile() {
destroyBuffer(byteBuffer);
}

private static void destroyBuffer(Buffer buffer) {
    if (buffer != null && buffer.isDirect()) {
        try {
            if (!buffer.getClass().getName().equals("java.nio.DirectByteBuffer")) {
                Field attField = buffer.getClass().getDeclaredField("att");
                attField.setAccessible(true);
                buffer = (Buffer) attField.get(buffer);
            }

            Method cleanerMethod = buffer.getClass().getMethod("cleaner");
            cleanerMethod.setAccessible(true);
            Object cleaner = cleanerMethod.invoke(buffer);
            Method cleanMethod = cleaner.getClass().getMethod("clean");
            cleanMethod.setAccessible(true);
            cleanMethod.invoke(cleaner);
        } catch (Exception e) {
            throw new RuntimeException("Could not destroy direct buffer " + buffer, e);
        }
    }

}

Tested with JDK8, JDK9_b121 require jvm option for JDK9
"-XaddExports:java.base/jdk.internal.ref=ALL-UNNAMED"

Possible solution to support other JDK providers at
https://sourceforge.net/p/tuer/code/HEAD/tree/pre_beta/src/main/java/engine/misc/DeallocationHelper.java

holzingk pushed a commit to i2p/i2p.i2p that referenced this issue Oct 26, 2016
from https://github.com/OpenNMS/jrobin/releases
Replaces 1.5.9.1 from 2008-09-05
Needed for Java 9 to remove dependency on Sun private classes.
No modifications, but includes only core, data, and graph;
cmd, convertor, inspector, and tests are not included.
Using source instead of jar because:
 - Release jar not available
 - Additional change will be needed for Java 9
   to remove dependency on Sun private classes, see:
   OpenNMS/jrobin#3
@fbacchella
Copy link

This is how I solved it in RRD4J: rrd4j/rrd4j@4b791a7.

It was issued in release 3.3.

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

2 participants