Skip to content

Commit

Permalink
[pinpoint-apm#8890] Temporary: forcefully bind Java9ClassLoader in Sy…
Browse files Browse the repository at this point in the history
…stem.bootLayer
  • Loading branch information
youngjin.kim2 committed Jun 2, 2022
1 parent ad1d936 commit ad65f36
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
Expand Down Expand Up @@ -45,6 +47,34 @@ public Java9ClassLoader(String name, URL[] urls, ClassLoader parent, List<String
Objects.requireNonNull(libClass, "libClass");

this.profilerLibClass = new ProfilerLibClass(libClass);

TEMPORARY_bindClassLoaderToBootLayerInOpenJ9(this);
}

/**
* It forcefully executes `System.bootLayer.bindToLoader(classLoader)` in openj9
* @param classLoader classLoader to bind to bootLayer
*/
private void TEMPORARY_bindClassLoaderToBootLayerInOpenJ9(ClassLoader classLoader) {
if (!System.getProperty("java.vm.name").toLowerCase().contains("openj9")) {
return;
}

try {
// Pull System.bootLayer
final Field field = System.class.getDeclaredField("bootLayer");
field.setAccessible(true);
final ModuleLayer bootLayer = (ModuleLayer) field.get(null);
field.setAccessible(false);

// Invoke ModuleLayer::bindToLoader
final Method bindToLoader = ModuleLayer.class.getDeclaredMethod("bindToLoader", ClassLoader.class);
bindToLoader.setAccessible(true);
bindToLoader.invoke(bootLayer, classLoader);
bindToLoader.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
Expand Down

0 comments on commit ad65f36

Please sign in to comment.