src/share/classes/java/lang/reflect/Method.java

Print this page
rev 3746 : [mq]: cr6565585.ao

*** 81,95 **** // For sharing of MethodAccessors. This branching structure is // currently only two levels deep (i.e., one root Method and // potentially many Method objects pointing to it.) private Method root; - // More complicated security check cache needed here than for - // Class.newInstance() and Constructor.newInstance() - private Class<?> securityCheckCache; - private Class<?> securityCheckTargetClassCache; - // Generics infrastructure private String getGenericSignature() {return signature;} // Accessor for factory --- 81,90 ----
*** 400,431 **** * {@code abstract}, {@code static}, {@code final}, * {@code synchronized}, {@code native}, {@code strictfp}. */ public String toString() { try { ! StringBuffer sb = new StringBuffer(); int mod = getModifiers() & Modifier.methodModifiers(); if (mod != 0) { ! sb.append(Modifier.toString(mod) + " "); } ! sb.append(Field.getTypeName(getReturnType()) + " "); ! sb.append(Field.getTypeName(getDeclaringClass()) + "."); ! sb.append(getName() + "("); Class<?>[] params = parameterTypes; // avoid clone for (int j = 0; j < params.length; j++) { sb.append(Field.getTypeName(params[j])); if (j < (params.length - 1)) ! sb.append(","); } ! sb.append(")"); Class<?>[] exceptions = exceptionTypes; // avoid clone if (exceptions.length > 0) { sb.append(" throws "); for (int k = 0; k < exceptions.length; k++) { sb.append(exceptions[k].getName()); if (k < (exceptions.length - 1)) ! sb.append(","); } } return sb.toString(); } catch (Exception e) { return "<" + e + ">"; --- 395,426 ---- * {@code abstract}, {@code static}, {@code final}, * {@code synchronized}, {@code native}, {@code strictfp}. */ public String toString() { try { ! StringBuilder sb = new StringBuilder(); int mod = getModifiers() & Modifier.methodModifiers(); if (mod != 0) { ! sb.append(Modifier.toString(mod)).append(' '); } ! sb.append(Field.getTypeName(getReturnType())).append(' '); ! sb.append(Field.getTypeName(getDeclaringClass())).append('.'); ! sb.append(getName()).append('('); Class<?>[] params = parameterTypes; // avoid clone for (int j = 0; j < params.length; j++) { sb.append(Field.getTypeName(params[j])); if (j < (params.length - 1)) ! sb.append(','); } ! sb.append(')'); Class<?>[] exceptions = exceptionTypes; // avoid clone if (exceptions.length > 0) { sb.append(" throws "); for (int k = 0; k < exceptions.length; k++) { sb.append(exceptions[k].getName()); if (k < (exceptions.length - 1)) ! sb.append(','); } } return sb.toString(); } catch (Exception e) { return "<" + e + ">";
*** 473,526 **** public String toGenericString() { try { StringBuilder sb = new StringBuilder(); int mod = getModifiers() & Modifier.methodModifiers(); if (mod != 0) { ! sb.append(Modifier.toString(mod) + " "); } TypeVariable<?>[] typeparms = getTypeParameters(); if (typeparms.length > 0) { boolean first = true; ! sb.append("<"); for(TypeVariable<?> typeparm: typeparms) { if (!first) ! sb.append(","); // Class objects can't occur here; no need to test // and call Class.getName(). sb.append(typeparm.toString()); first = false; } sb.append("> "); } Type genRetType = getGenericReturnType(); sb.append( ((genRetType instanceof Class<?>)? ! Field.getTypeName((Class<?>)genRetType):genRetType.toString()) + " "); ! sb.append(Field.getTypeName(getDeclaringClass()) + "."); ! sb.append(getName() + "("); Type[] params = getGenericParameterTypes(); for (int j = 0; j < params.length; j++) { String param = (params[j] instanceof Class)? Field.getTypeName((Class)params[j]): (params[j].toString()); if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... param = param.replaceFirst("\\[\\]$", "..."); sb.append(param); if (j < (params.length - 1)) ! sb.append(","); } ! sb.append(")"); Type[] exceptions = getGenericExceptionTypes(); if (exceptions.length > 0) { sb.append(" throws "); for (int k = 0; k < exceptions.length; k++) { sb.append((exceptions[k] instanceof Class)? ((Class)exceptions[k]).getName(): exceptions[k].toString()); if (k < (exceptions.length - 1)) ! sb.append(","); } } return sb.toString(); } catch (Exception e) { return "<" + e + ">"; --- 468,522 ---- public String toGenericString() { try { StringBuilder sb = new StringBuilder(); int mod = getModifiers() & Modifier.methodModifiers(); if (mod != 0) { ! sb.append(Modifier.toString(mod)).append(' '); } TypeVariable<?>[] typeparms = getTypeParameters(); if (typeparms.length > 0) { boolean first = true; ! sb.append('<'); for(TypeVariable<?> typeparm: typeparms) { if (!first) ! sb.append(','); // Class objects can't occur here; no need to test // and call Class.getName(). sb.append(typeparm.toString()); first = false; } sb.append("> "); } Type genRetType = getGenericReturnType(); sb.append( ((genRetType instanceof Class<?>)? ! Field.getTypeName((Class<?>)genRetType):genRetType.toString())) ! .append(' '); ! sb.append(Field.getTypeName(getDeclaringClass())).append('.'); ! sb.append(getName()).append('('); Type[] params = getGenericParameterTypes(); for (int j = 0; j < params.length; j++) { String param = (params[j] instanceof Class)? Field.getTypeName((Class)params[j]): (params[j].toString()); if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... param = param.replaceFirst("\\[\\]$", "..."); sb.append(param); if (j < (params.length - 1)) ! sb.append(','); } ! sb.append(')'); Type[] exceptions = getGenericExceptionTypes(); if (exceptions.length > 0) { sb.append(" throws "); for (int k = 0; k < exceptions.length; k++) { sb.append((exceptions[k] instanceof Class)? ((Class)exceptions[k]).getName(): exceptions[k].toString()); if (k < (exceptions.length - 1)) ! sb.append(','); } } return sb.toString(); } catch (Exception e) { return "<" + e + ">";
*** 589,618 **** InvocationTargetException { if (!override) { if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) { Class<?> caller = Reflection.getCallerClass(1); - Class<?> targetClass = ((obj == null || !Modifier.isProtected(modifiers)) - ? clazz - : obj.getClass()); ! boolean cached; ! synchronized (this) { ! cached = (securityCheckCache == caller) ! && (securityCheckTargetClassCache == targetClass); ! } ! if (!cached) { ! Reflection.ensureMemberAccess(caller, clazz, obj, modifiers); ! synchronized (this) { ! securityCheckCache = caller; ! securityCheckTargetClassCache = targetClass; ! } } } } ! if (methodAccessor == null) acquireMethodAccessor(); ! return methodAccessor.invoke(obj, args); } /** * Returns {@code true} if this method is a bridge * method; returns {@code false} otherwise. --- 585,603 ---- InvocationTargetException { if (!override) { if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) { Class<?> caller = Reflection.getCallerClass(1); ! checkAccess(caller, clazz, obj, modifiers); } } + MethodAccessor ma = methodAccessor; // read volatile + if (ma == null) { + ma = acquireMethodAccessor(); } ! return ma.invoke(obj, args); } /** * Returns {@code true} if this method is a bridge * method; returns {@code false} otherwise.
*** 652,675 **** // NOTE that there is no synchronization used here. It is correct // (though not efficient) to generate more than one MethodAccessor // for a given Method. However, avoiding synchronization will // probably make the implementation more scalable. ! private void acquireMethodAccessor() { // First check to see if one has been created yet, and take it // if so MethodAccessor tmp = null; if (root != null) tmp = root.getMethodAccessor(); if (tmp != null) { methodAccessor = tmp; ! return; ! } // Otherwise fabricate one and propagate it up to the root tmp = reflectionFactory.newMethodAccessor(this); setMethodAccessor(tmp); } // Returns MethodAccessor for this Method object, not looking up // the chain to the root MethodAccessor getMethodAccessor() { return methodAccessor; } --- 637,662 ---- // NOTE that there is no synchronization used here. It is correct // (though not efficient) to generate more than one MethodAccessor // for a given Method. However, avoiding synchronization will // probably make the implementation more scalable. ! private MethodAccessor acquireMethodAccessor() { // First check to see if one has been created yet, and take it // if so MethodAccessor tmp = null; if (root != null) tmp = root.getMethodAccessor(); if (tmp != null) { methodAccessor = tmp; ! } else { // Otherwise fabricate one and propagate it up to the root tmp = reflectionFactory.newMethodAccessor(this); setMethodAccessor(tmp); } + return tmp; + } + // Returns MethodAccessor for this Method object, not looking up // the chain to the root MethodAccessor getMethodAccessor() { return methodAccessor; }