Ok, crazy idea.
You can use the same technique in the thread you described, trying a different method. Class ClassLoader has the following method:
private Class<?> findBootstrapClassOrNull(String name)
This method calls a native method:
private native Class<?> findBootstrapClass(String name)
Which you could try to make accessible too.
EDIT: I've tried the following code, running from application class loader, though:
public class MyClassLoader extends ClassLoader {
public static void main(String[] args)
throws NoSuchMethodException,
InvocationTargetException,
IllegalAccessException {
Method method = ClassLoader.class.getDeclaredMethod(
"findBootstrapClass", String.class);
method.setAccessible(true);
MyClassLoader cl = new MyClassLoader();
System.out.println(method.invoke(cl, "java.lang.String"));
System.out.println(method.invoke(cl, "sun.java2d.loops.GraphicsPrimitiveMgr$2"));
}
}
(By the way, this code does not have to extend ClassLoader, I just left that from a previous test where I was invoking a protected method from ClassLoader.)
Whatever classes I provide, at the point my main method is running, it appears pretty much everything is loaded, not sure. From the source code for the "findBootstrapClass" method, I see this:
/**
* Returns a class loaded by the bootstrap class loader;
* or return null if not found.
*/
private Class<?> findBootstrapClassOrNull(String name)
So, unless you get different result running at the time the code is being instrumented, I'm thinking perhaps this is not doable.
NOTE: again, the source code that I looked at is for OpenJDK 1.8
Good luck.