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

Remi Forax forax at univ-mlv.fr
Tue Jun 16 08:33:08 UTC 2015


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).

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