Hi Mandy,
Yes, either way will avoid double canRead/isExported calls against the
same module. Although perhaps, an API with null prevModule would be more
consistent with other API methods that use null prevLookupClass etc...
Regards, Peter
On 7/5/19 8:19 PM, Mandy Chung wrote:
On 7/5/19 8:24 AM, Peter Levart wrote:
Hi Mandy,
On 7/2/19 7:20 PM, Mandy Chung wrote:
Webrev updated:
http://cr.openjdk.java.net/~mchung/jdk14/8173978/webrev.01/
I just skimmed across code and I think there's a little optimization
possible in VerifyAccess:
:
...instead of seting prevLookupModule to lookupModule in case
prevLookupClass is null (common case) causing double canRead and
isExported checks against the same module in isModuleAccessible()
(for positive outcome - the case where we want the check to be quick):
alternatively, keep prevLookupModule = lookupModule if prevLookupClass
is null
:
...and then check against null in isModuleAccessible():
and skip for the case where m1 == m2 like:
public static boolean isModuleAccessible(Class<?> refc, Module m1,
Module m2) {
Module refModule = refc.getModule();
assert refModule != m1 || refModule != m2;
int mods = getClassModifiers(refc);
if (isPublic(mods)) {
if (m1.canRead(refModule) && (m1 == m2 ||
m2.canRead(refModule))) {
String pn = refc.getPackageName();
// refc is exported package to at least both m1 and m2
if (refModule.isExported(pn, m1) && (m1 == m2 ||
refModule.isExported(pn, m2)))
return true;
}
}
return false;
}
Mandy