Skip to content

Commit

Permalink
Fix Init sun.misc.GC for Java 9
Browse files Browse the repository at this point in the history
Summary:

In java 9, sun.misc.GC is moved to sun.rmi.transport.GC , trying again
if sun.misc.GC is not found else throwing ClassNotFoundException.
  • Loading branch information
Chiranjivee Thakur authored and Chiranjivee Thakur committed May 22, 2018
1 parent 277b99f commit ad701de
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -22,8 +22,9 @@ public class SunGCInitiator implements PreClassLoaderInitiator {
@Override
public void doOutsideClassLoader(ClassLoaderLeakPreventor preventor) {
try {
Class<?> gcClass = Class.forName("sun.misc.GC");
Class<?> gcClass = this.getGCClass();
final Method requestLatency = gcClass.getDeclaredMethod("requestLatency", long.class);
requestLatency.setAccessible(true);
requestLatency.invoke(null, Long.valueOf(Long.MAX_VALUE - 1));
}
catch (ClassNotFoundException cnfex) {
Expand All @@ -39,6 +40,14 @@ public void doOutsideClassLoader(ClassLoaderLeakPreventor preventor) {
catch (InvocationTargetException itex) {
preventor.error(itex);
}

}

private Class<?> getGCClass() throws ClassNotFoundException {
try {
return Class.forName("sun.misc.GC");
} catch (ClassNotFoundException cnfex) {
// Try Jre 9 classpath
return Class.forName("sun.rmi.transport.GC");
}
}
}

0 comments on commit ad701de

Please sign in to comment.