RFR: 8153334: Replace BufferedInputStreams use of AtomicReferenceFieldUpdater with Unsafe
Peter Levart
peter.levart at gmail.com
Thu Apr 14 14:25:07 UTC 2016
Hi Paul,
I wanted to try using VarHandles for code internal to JDK but there's a
problem with MethodHandles.lookup(). It doesn't allow the caller class
loaded by the bootstrap class loader and located in either java.* or
sun.* (but not sun.invoke.*) packages:
private static void checkUnprivilegedlookupClass(Class<?>
lookupClass, int allowedModes) {
String name = lookupClass.getName();
if (name.startsWith("java.lang.invoke."))
throw newIllegalArgumentException("illegal lookupClass:
"+lookupClass);
// For caller-sensitive MethodHandles.lookup()
// disallow lookup more restricted packages
if (allowedModes == ALL_MODES &&
lookupClass.getClassLoader() == null) {
if (name.startsWith("java.") ||
(name.startsWith("sun.") &&
!name.startsWith("sun.invoke."))) {
throw newIllegalArgumentException("illegal
lookupClass: " + lookupClass);
}
}
}
...strangely, other bootstrap class loaded callers located in jdk.* are
allowed. Why such distinction? Is there or will there be an official way
to use VarHandles in JDK code and not having to resort to work-arounds
like
MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP").setAccessible(true)?
Regards, Peter
More information about the core-libs-dev
mailing list