< prev index next >

src/java.base/share/classes/java/lang/invoke/MemberName.java

Print this page
rev 49420 : 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
Reviewed-by: lfoltan, acorn

*** 1045,1055 **** * Super types are searched (for inherited members) if {@code searchSupers} is true. * Access checking is performed on behalf of the given {@code lookupClass}. * If lookup fails or access is not permitted, null is returned. * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. */ ! private MemberName resolve(byte refKind, MemberName ref, Class<?> lookupClass) { MemberName m = ref.clone(); // JVM will side-effect the ref assert(refKind == m.getReferenceKind()); try { // There are 4 entities in play here: // * LC: lookupClass --- 1045,1056 ---- * Super types are searched (for inherited members) if {@code searchSupers} is true. * Access checking is performed on behalf of the given {@code lookupClass}. * If lookup fails or access is not permitted, null is returned. * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. */ ! private MemberName resolve(byte refKind, MemberName ref, Class<?> lookupClass, ! boolean speculativeResolve) { MemberName m = ref.clone(); // JVM will side-effect the ref assert(refKind == m.getReferenceKind()); try { // There are 4 entities in play here: // * LC: lookupClass
*** 1064,1074 **** // All parameters passed by a caller are checked against MH type (PTYPES) on every invocation, // so it is safe to call a MH from any context. // // REFC view on PTYPES doesn't matter, since it is used only as a starting point for resolution and doesn't // participate in method selection. ! m = MethodHandleNatives.resolve(m, lookupClass); m.checkForTypeAlias(m.getDeclaringClass()); m.resolution = null; } catch (ClassNotFoundException | LinkageError ex) { // JVM reports that the "bytecode behavior" would get an error assert(!m.isResolved()); --- 1065,1078 ---- // All parameters passed by a caller are checked against MH type (PTYPES) on every invocation, // so it is safe to call a MH from any context. // // REFC view on PTYPES doesn't matter, since it is used only as a starting point for resolution and doesn't // participate in method selection. ! m = MethodHandleNatives.resolve(m, lookupClass, speculativeResolve); ! if (m == null && speculativeResolve) { ! return null; ! } m.checkForTypeAlias(m.getDeclaringClass()); m.resolution = null; } catch (ClassNotFoundException | LinkageError ex) { // JVM reports that the "bytecode behavior" would get an error assert(!m.isResolved());
*** 1089,1099 **** public <NoSuchMemberException extends ReflectiveOperationException> MemberName resolveOrFail(byte refKind, MemberName m, Class<?> lookupClass, Class<NoSuchMemberException> nsmClass) throws IllegalAccessException, NoSuchMemberException { ! MemberName result = resolve(refKind, m, lookupClass); if (result.isResolved()) return result; ReflectiveOperationException ex = result.makeAccessException(); if (ex instanceof IllegalAccessException) throw (IllegalAccessException) ex; throw nsmClass.cast(ex); --- 1093,1103 ---- public <NoSuchMemberException extends ReflectiveOperationException> MemberName resolveOrFail(byte refKind, MemberName m, Class<?> lookupClass, Class<NoSuchMemberException> nsmClass) throws IllegalAccessException, NoSuchMemberException { ! MemberName result = resolve(refKind, m, lookupClass, false); if (result.isResolved()) return result; ReflectiveOperationException ex = result.makeAccessException(); if (ex instanceof IllegalAccessException) throw (IllegalAccessException) ex; throw nsmClass.cast(ex);
*** 1104,1115 **** * If lookup fails or access is not permitted, return null. * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. */ public MemberName resolveOrNull(byte refKind, MemberName m, Class<?> lookupClass) { ! MemberName result = resolve(refKind, m, lookupClass); ! if (result.isResolved()) return result; return null; } /** Return a list of all methods defined by the given class. * Super types are searched (for inherited members) if {@code searchSupers} is true. --- 1108,1119 ---- * If lookup fails or access is not permitted, return null. * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. */ public MemberName resolveOrNull(byte refKind, MemberName m, Class<?> lookupClass) { ! MemberName result = resolve(refKind, m, lookupClass, true); ! if (result != null && result.isResolved()) return result; return null; } /** Return a list of all methods defined by the given class. * Super types are searched (for inherited members) if {@code searchSupers} is true.
< prev index next >