hg: valhalla/valhalla/jdk: Enhancement: improve MH access checks w.r.t. classes defined with Unsafe.dAC

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jun 16 09:56:36 UTC 2015



On 16/06/15 09:33, Remi Forax wrote:
> I should have add that downgrading lambdas to inner classes is that 
> now all the inner classes are stored on disk and loaded and 
> initialized when the class is initialized (unlike lambdas that are 
> lazy constructed).
Not sure I get this point? I know inner class add static footprint - the 
problem that I was trying to avoid is a SSO caused by the fact that the 
very code that is checking MH accessibility needs itself to refer to MH 
(if you are using lambdas).

Regarding the refactoring, of course, when the code is stable enough and 
we are convinced this is the path we should follow, the enum refactoring 
seems a sensible one.

Maurizio
>
> Rémi
>
> On 06/16/2015 10:27 AM, Remi Forax wrote:
>> Hi Maurizio,
>> using 7 classes here is in my opinion overkill
>>
>> what about something like this ?
>>
>> // you can add documentation here, more readable IMO
>> interface VisibilityCheck {
>>   boolean test(Class<?> c1, Class<?> c2);
>> }
>>
>> enum VisibiltyChecks implements VisibilityCheck {
>>   CLASS_EQUALS,
>>   ASSIGNABLE,
>>   SAME_PACKAGE,
>>   SAME_PACKAGE_MEMBER,
>>   RELATED_CLASS,
>>   SUBCLASS
>>   ;
>>
>>   @Overrides
>>   public boolean test(Class<?> c1, Class<?> c2) {
>>     switch(this) {
>>       case CLASS_EQUALS:
>>         return c1 == c2;
>>       case ASSIGNABLE:
>>         return c1.isAssignable(c2);
>>       ...
>>       default:
>>         throw new AssertionError();
>>     }
>>   }
>> }
>>
>> private static final VisibilityCheck classAccessible(int allowedModes) {
>>        return new VisibilityCheck() {
>>            @Override
>>            public boolean test(Class<?> c1, Class<?> c2) {
>>                return isClassAccessible(c1, c2, allowedModes);
>>            }
>>        };
>>    }
>>
>> public static boolean walkHostClass(Class<?> c, Class<?> lookupClass, 
>> VisibilityCheck p) {
>>        for(;lookupClass != null; lookupClass = 
>> UNSAFE.getHostClass(lookupClass)) {
>>            if (p.test(c, lookupClass)) {
>>                return true;
>>            }
>>        }
>>        return false;
>>    }
>>
>> regards,
>> Rémi
>>
>> On 06/15/2015 08:00 PM, maurizio.cimadamore at oracle.com wrote:
>>> Changeset: c28ea949f8cc
>>> Author:    mcimadamore
>>> Date:      2015-06-15 19:00 +0100
>>> URL: http://hg.openjdk.java.net/valhalla/valhalla/jdk/rev/c28ea949f8cc
>>>
>>> Enhancement: improve MH access checks w.r.t. classes defined with 
>>> Unsafe.dAC
>>> * Add new Unsafe.getHostClass() method (see related VM patch)
>>> * Added recursive access check logic that walks through the 
>>> hostclass chain
>>>
>>> ! src/java.base/share/classes/java/lang/invoke/MethodHandles.java
>>> ! src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
>>> ! src/java.base/share/classes/sun/misc/Unsafe.java
>>>
>>
>



More information about the valhalla-dev mailing list