RFR: 8153334: Replace BufferedInputStreams use of AtomicReferenceFieldUpdater with Unsafe

Paul Sandoz paul.sandoz at oracle.com
Thu Apr 14 14:40:14 UTC 2016


Hi Peter,

You found that annoying restriction :-) at this point i think this is mostly redundant.

This is something i planned to update and limit the restriction to code within j.l.invoke and sun.invoke packages.

I'll follow up with a patch soon to unblock, but feel free to beat me to it if you wish.

Paul.

> On 14 Apr 2016, at 16:25, Peter Levart <peter.levart at gmail.com> wrote:
> 
> 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