nashorn

16:39:15.082 INFO  jd.cli.Main - Decompiling nashorn.jar
package jdk.internal.dynalink.beans;

class AbstractJavaLinker$1 {}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.AbstractJavaLinker.1
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles.Lookup;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.LinkerServices;

final class AbstractJavaLinker$AnnotatedDynamicMethod
{
  private final SingleDynamicMethod method;
  final GuardedInvocationComponent.ValidationType validationType;
  
  AbstractJavaLinker$AnnotatedDynamicMethod(SingleDynamicMethod method, GuardedInvocationComponent.ValidationType validationType)
  {
    this.method = method;
    this.validationType = validationType;
  }
  
  MethodHandle getInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices)
  {
    return method.getInvocation(callSiteDescriptor, linkerServices);
  }
  
  MethodHandle getTarget(MethodHandles.Lookup lookup)
  {
    MethodHandle inv = method.getTarget(lookup);
    assert (inv != null);
    return inv;
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.AbstractJavaLinker.AnnotatedDynamicMethod
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

class AbstractJavaLinker$MethodPair
{
  final MethodHandle method1;
  final MethodHandle method2;
  
  AbstractJavaLinker$MethodPair(MethodHandle method1, MethodHandle method2)
  {
    this.method1 = method1;
    this.method2 = method2;
  }
  
  MethodHandle guardWithTest(MethodHandle test)
  {
    return MethodHandles.guardWithTest(test, method1, method2);
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.AbstractJavaLinker.MethodPair
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.GuardingDynamicLinker;
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Guards;
import jdk.internal.dynalink.support.Lookup;
import jdk.internal.dynalink.support.TypeUtilities;

abstract class AbstractJavaLinker
  implements GuardingDynamicLinker
{
  final Class<?> clazz;
  private final MethodHandle classGuard;
  private final MethodHandle assignableGuard;
  private final Map<String, AnnotatedDynamicMethod> propertyGetters = new HashMap();
  private final Map<String, DynamicMethod> propertySetters = new HashMap();
  private final Map<String, DynamicMethod> methods = new HashMap();
  
  AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard)
  {
    this(clazz, classGuard, classGuard);
  }
  
  AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard, MethodHandle assignableGuard)
  {
    this.clazz = clazz;
    this.classGuard = classGuard;
    this.assignableGuard = assignableGuard;
    
    FacetIntrospector introspector = createFacetIntrospector();
    for (Method method : introspector.getMethods())
    {
      String name = method.getName();
      
      addMember(name, method, methods);
      if ((name.startsWith("get")) && (name.length() > 3) && (method.getParameterTypes().length == 0)) {
        setPropertyGetter(method, 3);
      } else if ((name.startsWith("is")) && (name.length() > 2) && (method.getParameterTypes().length == 0) && 
        (method.getReturnType() == Boolean.TYPE)) {
        setPropertyGetter(method, 2);
      } else if ((name.startsWith("set")) && (name.length() > 3) && (method.getParameterTypes().length == 1)) {
        addMember(decapitalize(name.substring(3)), method, propertySetters);
      }
    }
    for (Field field : introspector.getFields())
    {
      String name = field.getName();
      if (!propertyGetters.containsKey(name)) {
        setPropertyGetter(name, introspector.unreflectGetter(field), GuardedInvocationComponent.ValidationType.EXACT_CLASS);
      }
      if ((!Modifier.isFinal(field.getModifiers())) && (!propertySetters.containsKey(name))) {
        addMember(name, new SimpleDynamicMethod(introspector.unreflectSetter(field), clazz, name), propertySetters);
      }
    }
    for (Map.Entry<String, MethodHandle> innerClassSpec : introspector.getInnerClassGetters().entrySet())
    {
      String name = (String)innerClassSpec.getKey();
      if (!propertyGetters.containsKey(name)) {
        setPropertyGetter(name, (MethodHandle)innerClassSpec.getValue(), GuardedInvocationComponent.ValidationType.EXACT_CLASS);
      }
    }
  }
  
  private static String decapitalize(String str)
  {
    assert (str != null);
    if (str.isEmpty()) {
      return str;
    }
    char c0 = str.charAt(0);
    if (Character.isLowerCase(c0)) {
      return str;
    }
    if ((str.length() > 1) && (Character.isUpperCase(str.charAt(1)))) {
      return str;
    }
    char[] c = str.toCharArray();
    c[0] = Character.toLowerCase(c0);
    return new String(c);
  }
  
  abstract FacetIntrospector createFacetIntrospector();
  
  Collection<String> getReadablePropertyNames()
  {
    return getUnmodifiableKeys(propertyGetters);
  }
  
  Collection<String> getWritablePropertyNames()
  {
    return getUnmodifiableKeys(propertySetters);
  }
  
  Collection<String> getMethodNames()
  {
    return getUnmodifiableKeys(methods);
  }
  
  private static Collection<String> getUnmodifiableKeys(Map<String, ?> m)
  {
    return Collections.unmodifiableCollection(m.keySet());
  }
  
  private void setPropertyGetter(String name, SingleDynamicMethod handle, GuardedInvocationComponent.ValidationType validationType)
  {
    propertyGetters.put(name, new AnnotatedDynamicMethod(handle, validationType));
  }
  
  private void setPropertyGetter(Method getter, int prefixLen)
  {
    setPropertyGetter(decapitalize(getter.getName().substring(prefixLen)), createDynamicMethod(
      getMostGenericGetter(getter)), GuardedInvocationComponent.ValidationType.INSTANCE_OF);
  }
  
  void setPropertyGetter(String name, MethodHandle handle, GuardedInvocationComponent.ValidationType validationType)
  {
    setPropertyGetter(name, new SimpleDynamicMethod(handle, clazz, name), validationType);
  }
  
  private void addMember(String name, AccessibleObject ao, Map<String, DynamicMethod> methodMap)
  {
    addMember(name, createDynamicMethod(ao), methodMap);
  }
  
  private void addMember(String name, SingleDynamicMethod method, Map<String, DynamicMethod> methodMap)
  {
    DynamicMethod existingMethod = (DynamicMethod)methodMap.get(name);
    DynamicMethod newMethod = mergeMethods(method, existingMethod, clazz, name);
    if (newMethod != existingMethod) {
      methodMap.put(name, newMethod);
    }
  }
  
  static DynamicMethod createDynamicMethod(Iterable<? extends AccessibleObject> members, Class<?> clazz, String name)
  {
    DynamicMethod dynMethod = null;
    for (AccessibleObject method : members) {
      dynMethod = mergeMethods(createDynamicMethod(method), dynMethod, clazz, name);
    }
    return dynMethod;
  }
  
  private static SingleDynamicMethod createDynamicMethod(AccessibleObject m)
  {
    if (CallerSensitiveDetector.isCallerSensitive(m)) {
      return new CallerSensitiveDynamicMethod(m);
    }
    try
    {
      mh = unreflectSafely(m);
    }
    catch (IllegalAccessError e)
    {
      MethodHandle mh;
      return new CallerSensitiveDynamicMethod(m);
    }
    MethodHandle mh;
    Member member = (Member)m;
    return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
  }
  
  private static MethodHandle unreflectSafely(AccessibleObject m)
  {
    if ((m instanceof Method))
    {
      Method reflMethod = (Method)m;
      MethodHandle handle = Lookup.PUBLIC.unreflect(reflMethod);
      if (Modifier.isStatic(reflMethod.getModifiers())) {
        return StaticClassIntrospector.editStaticMethodHandle(handle);
      }
      return handle;
    }
    return StaticClassIntrospector.editConstructorMethodHandle(Lookup.PUBLIC.unreflectConstructor((Constructor)m));
  }
  
  private static DynamicMethod mergeMethods(SingleDynamicMethod method, DynamicMethod existing, Class<?> clazz, String name)
  {
    if (existing == null) {
      return method;
    }
    if (existing.contains(method)) {
      return existing;
    }
    if ((existing instanceof SingleDynamicMethod))
    {
      OverloadedDynamicMethod odm = new OverloadedDynamicMethod(clazz, name);
      odm.addMethod((SingleDynamicMethod)existing);
      odm.addMethod(method);
      return odm;
    }
    if ((existing instanceof OverloadedDynamicMethod))
    {
      ((OverloadedDynamicMethod)existing).addMethod(method);
      return existing;
    }
    throw new AssertionError();
  }
  
  public GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices)
    throws Exception
  {
    LinkRequest ncrequest = request.withoutRuntimeContext();
    
    CallSiteDescriptor callSiteDescriptor = ncrequest.getCallSiteDescriptor();
    String op = callSiteDescriptor.getNameToken(1);
    if ("callMethod" == op) {
      return getCallPropWithThis(callSiteDescriptor, linkerServices);
    }
    List<String> operations = CallSiteDescriptorFactory.tokenizeOperators(callSiteDescriptor);
    while (!operations.isEmpty())
    {
      GuardedInvocationComponent gic = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, operations);
      if (gic != null) {
        return gic.getGuardedInvocation();
      }
      operations = pop(operations);
    }
    return null;
  }
  
  protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices, List<String> operations)
    throws Exception
  {
    if (operations.isEmpty()) {
      return null;
    }
    String op = (String)operations.get(0);
    if ("getProp".equals(op)) {
      return getPropertyGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    if ("setProp".equals(op)) {
      return getPropertySetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    if ("getMethod".equals(op)) {
      return getMethodGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    return null;
  }
  
  static final <T> List<T> pop(List<T> l)
  {
    return l.subList(1, l.size());
  }
  
  MethodHandle getClassGuard(CallSiteDescriptor desc)
  {
    return getClassGuard(desc.getMethodType());
  }
  
  MethodHandle getClassGuard(MethodType type)
  {
    return Guards.asType(classGuard, type);
  }
  
  GuardedInvocationComponent getClassGuardedInvocationComponent(MethodHandle invocation, MethodType type)
  {
    return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, GuardedInvocationComponent.ValidationType.EXACT_CLASS);
  }
  
  SingleDynamicMethod getConstructorMethod(String signature)
  {
    return null;
  }
  
  private MethodHandle getAssignableGuard(MethodType type)
  {
    return Guards.asType(assignableGuard, type);
  }
  
  private GuardedInvocation getCallPropWithThis(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices)
  {
    switch (callSiteDescriptor.getNameTokenCount())
    {
    case 3: 
      return createGuardedDynamicMethodInvocation(callSiteDescriptor, linkerServices, callSiteDescriptor
        .getNameToken(2), methods);
    }
    return null;
  }
  
  private GuardedInvocation createGuardedDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap)
  {
    MethodHandle inv = getDynamicMethodInvocation(callSiteDescriptor, linkerServices, methodName, methodMap);
    return inv == null ? null : new GuardedInvocation(inv, getClassGuard(callSiteDescriptor.getMethodType()));
  }
  
  private MethodHandle getDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap)
  {
    DynamicMethod dynaMethod = getDynamicMethod(methodName, methodMap);
    return dynaMethod != null ? dynaMethod.getInvocation(callSiteDescriptor, linkerServices) : null;
  }
  
  private DynamicMethod getDynamicMethod(String methodName, Map<String, DynamicMethod> methodMap)
  {
    DynamicMethod dynaMethod = (DynamicMethod)methodMap.get(methodName);
    return dynaMethod != null ? dynaMethod : getExplicitSignatureDynamicMethod(methodName, methodMap);
  }
  
  private SingleDynamicMethod getExplicitSignatureDynamicMethod(String fullName, Map<String, DynamicMethod> methodsMap)
  {
    int lastChar = fullName.length() - 1;
    if (fullName.charAt(lastChar) != ')') {
      return null;
    }
    int openBrace = fullName.indexOf('(');
    if (openBrace == -1) {
      return null;
    }
    String name = fullName.substring(0, openBrace);
    String signature = fullName.substring(openBrace + 1, lastChar);
    
    DynamicMethod simpleNamedMethod = (DynamicMethod)methodsMap.get(name);
    if (simpleNamedMethod == null)
    {
      if (name.isEmpty()) {
        return getConstructorMethod(signature);
      }
      return null;
    }
    return simpleNamedMethod.getMethodForExactParamTypes(signature);
  }
  
  private static final MethodHandle IS_METHOD_HANDLE_NOT_NULL = Guards.isNotNull().asType(MethodType.methodType(Boolean.TYPE, MethodHandle.class));
  private static final MethodHandle CONSTANT_NULL_DROP_METHOD_HANDLE = MethodHandles.dropArguments(
    MethodHandles.constant(Object.class, null), 0, new Class[] { MethodHandle.class });
  
  private GuardedInvocationComponent getPropertySetter(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices, List<String> operations)
    throws Exception
  {
    switch (callSiteDescriptor.getNameTokenCount())
    {
    case 2: 
      assertParameterCount(callSiteDescriptor, 3);
      
      MethodType origType = callSiteDescriptor.getMethodType();
      MethodType type = origType.returnType() == Void.TYPE ? origType : origType.changeReturnType(Object.class);
      
      MethodType setterType = type.dropParameterTypes(1, 2);
      
      MethodHandle boundGetter = MethodHandles.insertArguments(getPropertySetterHandle, 0, new Object[] {callSiteDescriptor
        .changeMethodType(setterType), linkerServices });
      
      MethodHandle typedGetter = linkerServices.asType(boundGetter, type.changeReturnType(MethodHandle.class));
      
      MethodHandle invokeHandle = MethodHandles.exactInvoker(setterType);
      
      MethodHandle invokeHandleFolded = MethodHandles.dropArguments(invokeHandle, 2, new Class[] { type.parameterType(1) });
      
      GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, operations);
      MethodHandle fallbackFolded;
      MethodHandle fallbackFolded;
      if (nextComponent == null) {
        fallbackFolded = MethodHandles.dropArguments(CONSTANT_NULL_DROP_METHOD_HANDLE, 1, type.parameterList()).asType(type.insertParameterTypes(0, new Class[] { MethodHandle.class }));
      } else {
        fallbackFolded = MethodHandles.dropArguments(nextComponent.getGuardedInvocation().getInvocation(), 0, new Class[] { MethodHandle.class });
      }
      MethodHandle compositeSetter = MethodHandles.foldArguments(MethodHandles.guardWithTest(IS_METHOD_HANDLE_NOT_NULL, invokeHandleFolded, fallbackFolded), typedGetter);
      if (nextComponent == null) {
        return getClassGuardedInvocationComponent(compositeSetter, type);
      }
      return nextComponent.compose(compositeSetter, getClassGuard(type), clazz, GuardedInvocationComponent.ValidationType.EXACT_CLASS);
    case 3: 
      assertParameterCount(callSiteDescriptor, 2);
      GuardedInvocation gi = createGuardedDynamicMethodInvocation(callSiteDescriptor, linkerServices, callSiteDescriptor
        .getNameToken(2), propertySetters);
      if (gi != null) {
        return new GuardedInvocationComponent(gi, clazz, GuardedInvocationComponent.ValidationType.EXACT_CLASS);
      }
      return getGuardedInvocationComponent(callSiteDescriptor, linkerServices, operations);
    }
    return null;
  }
  
  private static final Lookup privateLookup = new Lookup(MethodHandles.lookup());
  private static final MethodHandle IS_ANNOTATED_METHOD_NOT_NULL = Guards.isNotNull().asType(MethodType.methodType(Boolean.TYPE, AnnotatedDynamicMethod.class));
  private static final MethodHandle CONSTANT_NULL_DROP_ANNOTATED_METHOD = MethodHandles.dropArguments(
    MethodHandles.constant(Object.class, null), 0, new Class[] { AnnotatedDynamicMethod.class });
  private static final MethodHandle GET_ANNOTATED_METHOD = privateLookup.findVirtual(AnnotatedDynamicMethod.class, "getTarget", 
    MethodType.methodType(MethodHandle.class, MethodHandles.Lookup.class));
  private static final MethodHandle GETTER_INVOKER = MethodHandles.invoker(MethodType.methodType(Object.class, Object.class));
  
  private GuardedInvocationComponent getPropertyGetter(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices, List<String> ops)
    throws Exception
  {
    switch (callSiteDescriptor.getNameTokenCount())
    {
    case 2: 
      MethodType type = callSiteDescriptor.getMethodType().changeReturnType(Object.class);
      
      assertParameterCount(callSiteDescriptor, 2);
      
      MethodHandle typedGetter = linkerServices.asType(getPropertyGetterHandle, type.changeReturnType(AnnotatedDynamicMethod.class));
      
      MethodHandle callSiteBoundMethodGetter = MethodHandles.insertArguments(GET_ANNOTATED_METHOD, 1, new Object[] {callSiteDescriptor
        .getLookup() });
      MethodHandle callSiteBoundInvoker = MethodHandles.filterArguments(GETTER_INVOKER, 0, new MethodHandle[] { callSiteBoundMethodGetter });
      
      MethodHandle invokeHandleTyped = linkerServices.asType(callSiteBoundInvoker, 
        MethodType.methodType(type.returnType(), AnnotatedDynamicMethod.class, new Class[] { type.parameterType(0) }));
      
      MethodHandle invokeHandleFolded = MethodHandles.dropArguments(invokeHandleTyped, 2, new Class[] {type
        .parameterType(1) });
      GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, ops);
      MethodHandle fallbackFolded;
      MethodHandle fallbackFolded;
      if (nextComponent == null)
      {
        fallbackFolded = MethodHandles.dropArguments(CONSTANT_NULL_DROP_ANNOTATED_METHOD, 1, type.parameterList()).asType(type.insertParameterTypes(0, new Class[] { AnnotatedDynamicMethod.class }));
      }
      else
      {
        MethodHandle nextInvocation = nextComponent.getGuardedInvocation().getInvocation();
        MethodType nextType = nextInvocation.type();
        fallbackFolded = MethodHandles.dropArguments(nextInvocation.asType(nextType
          .changeReturnType(Object.class)), 0, new Class[] { AnnotatedDynamicMethod.class });
      }
      MethodHandle compositeGetter = MethodHandles.foldArguments(MethodHandles.guardWithTest(IS_ANNOTATED_METHOD_NOT_NULL, invokeHandleFolded, fallbackFolded), typedGetter);
      if (nextComponent == null) {
        return getClassGuardedInvocationComponent(compositeGetter, type);
      }
      return nextComponent.compose(compositeGetter, getClassGuard(type), clazz, GuardedInvocationComponent.ValidationType.EXACT_CLASS);
    case 3: 
      assertParameterCount(callSiteDescriptor, 1);
      
      AnnotatedDynamicMethod annGetter = (AnnotatedDynamicMethod)propertyGetters.get(callSiteDescriptor.getNameToken(2));
      if (annGetter == null) {
        return getGuardedInvocationComponent(callSiteDescriptor, linkerServices, ops);
      }
      MethodHandle getter = annGetter.getInvocation(callSiteDescriptor, linkerServices);
      
      GuardedInvocationComponent.ValidationType validationType = validationType;
      
      return new GuardedInvocationComponent(getter, getGuard(validationType, callSiteDescriptor
        .getMethodType()), clazz, validationType);
    }
    return null;
  }
  
  private MethodHandle getGuard(GuardedInvocationComponent.ValidationType validationType, MethodType methodType)
  {
    switch (validationType)
    {
    case EXACT_CLASS: 
      return getClassGuard(methodType);
    case INSTANCE_OF: 
      return getAssignableGuard(methodType);
    case IS_ARRAY: 
      return Guards.isArray(0, methodType);
    case NONE: 
      return null;
    }
    throw new AssertionError();
  }
  
  private static final MethodHandle IS_DYNAMIC_METHOD = Guards.isInstance(DynamicMethod.class, 
    MethodType.methodType(Boolean.TYPE, Object.class));
  private static final MethodHandle OBJECT_IDENTITY = MethodHandles.identity(Object.class);
  
  private GuardedInvocationComponent getMethodGetter(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices, List<String> ops)
    throws Exception
  {
    MethodType type = callSiteDescriptor.getMethodType().changeReturnType(Object.class);
    switch (callSiteDescriptor.getNameTokenCount())
    {
    case 2: 
      assertParameterCount(callSiteDescriptor, 2);
      GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, ops);
      if ((nextComponent == null) || (!TypeUtilities.areAssignable(DynamicMethod.class, nextComponent
        .getGuardedInvocation().getInvocation().type().returnType()))) {
        return getClassGuardedInvocationComponent(linkerServices.asType(getDynamicMethod, type), type);
      }
      MethodHandle typedGetter = linkerServices.asType(getDynamicMethod, type);
      
      MethodHandle returnMethodHandle = linkerServices.asType(MethodHandles.dropArguments(OBJECT_IDENTITY, 1, type
        .parameterList()), type.insertParameterTypes(0, new Class[] { Object.class }));
      MethodHandle nextComponentInvocation = nextComponent.getGuardedInvocation().getInvocation();
      
      assert (nextComponentInvocation.type().changeReturnType(type.returnType()).equals(type));
      
      MethodHandle nextCombinedInvocation = MethodHandles.dropArguments(nextComponentInvocation, 0, new Class[] { Object.class });
      
      MethodHandle compositeGetter = MethodHandles.foldArguments(MethodHandles.guardWithTest(IS_DYNAMIC_METHOD, returnMethodHandle, nextCombinedInvocation), typedGetter);
      
      return nextComponent.compose(compositeGetter, getClassGuard(type), clazz, GuardedInvocationComponent.ValidationType.EXACT_CLASS);
    case 3: 
      assertParameterCount(callSiteDescriptor, 1);
      DynamicMethod method = getDynamicMethod(callSiteDescriptor.getNameToken(2));
      if (method == null) {
        return getGuardedInvocationComponent(callSiteDescriptor, linkerServices, ops);
      }
      return getClassGuardedInvocationComponent(linkerServices.asType(MethodHandles.dropArguments(
        MethodHandles.constant(Object.class, method), 0, new Class[] { type.parameterType(0) }), type), type);
    }
    return null;
  }
  
  static class MethodPair
  {
    final MethodHandle method1;
    final MethodHandle method2;
    
    MethodPair(MethodHandle method1, MethodHandle method2)
    {
      this.method1 = method1;
      this.method2 = method2;
    }
    
    MethodHandle guardWithTest(MethodHandle test)
    {
      return MethodHandles.guardWithTest(test, method1, method2);
    }
  }
  
  static MethodPair matchReturnTypes(MethodHandle m1, MethodHandle m2)
  {
    MethodType type1 = m1.type();
    MethodType type2 = m2.type();
    Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(), type2
      .returnType());
    
    return new MethodPair(m1.asType(type1.changeReturnType(commonRetType)), m2.asType(type2.changeReturnType(commonRetType)));
  }
  
  private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount)
  {
    if (descriptor.getMethodType().parameterCount() != paramCount) {
      throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters.");
    }
  }
  
  private static MethodHandle GET_PROPERTY_GETTER_HANDLE = MethodHandles.dropArguments(privateLookup.findOwnSpecial("getPropertyGetterHandle", Object.class, new Class[] { Object.class }), 1, new Class[] { Object.class });
  private final MethodHandle getPropertyGetterHandle = GET_PROPERTY_GETTER_HANDLE.bindTo(this);
  
  private Object getPropertyGetterHandle(Object id)
  {
    return propertyGetters.get(id);
  }
  
  private static final MethodHandle GET_PROPERTY_SETTER_HANDLE = MethodHandles.dropArguments(MethodHandles.dropArguments(privateLookup
    .findOwnSpecial("getPropertySetterHandle", MethodHandle.class, new Class[] { CallSiteDescriptor.class, LinkerServices.class, Object.class }), 3, new Class[] { Object.class }), 5, new Class[] { Object.class });
  private final MethodHandle getPropertySetterHandle = GET_PROPERTY_SETTER_HANDLE.bindTo(this);
  
  private MethodHandle getPropertySetterHandle(CallSiteDescriptor setterDescriptor, LinkerServices linkerServices, Object id)
  {
    return getDynamicMethodInvocation(setterDescriptor, linkerServices, String.valueOf(id), propertySetters);
  }
  
  private static MethodHandle GET_DYNAMIC_METHOD = MethodHandles.dropArguments(privateLookup.findOwnSpecial("getDynamicMethod", Object.class, new Class[] { Object.class }), 1, new Class[] { Object.class });
  private final MethodHandle getDynamicMethod = GET_DYNAMIC_METHOD.bindTo(this);
  
  private Object getDynamicMethod(Object name)
  {
    return getDynamicMethod(String.valueOf(name), methods);
  }
  
  DynamicMethod getDynamicMethod(String name)
  {
    return getDynamicMethod(name, methods);
  }
  
  private static Method getMostGenericGetter(Method getter)
  {
    return getMostGenericGetter(getter.getName(), getter.getReturnType(), getter.getDeclaringClass());
  }
  
  private static Method getMostGenericGetter(String name, Class<?> returnType, Class<?> declaringClass)
  {
    if (declaringClass == null) {
      return null;
    }
    for (Class<?> itf : declaringClass.getInterfaces())
    {
      Method itfGetter = getMostGenericGetter(name, returnType, itf);
      if (itfGetter != null) {
        return itfGetter;
      }
    }
    Method superGetter = getMostGenericGetter(name, returnType, declaringClass.getSuperclass());
    if (superGetter != null) {
      return superGetter;
    }
    if (!CheckRestrictedPackage.isRestrictedClass(declaringClass)) {
      try
      {
        return declaringClass.getMethod(name, new Class[0]);
      }
      catch (NoSuchMethodException localNoSuchMethodException1) {}
    }
    return null;
  }
  
  private static final class AnnotatedDynamicMethod
  {
    private final SingleDynamicMethod method;
    final GuardedInvocationComponent.ValidationType validationType;
    
    AnnotatedDynamicMethod(SingleDynamicMethod method, GuardedInvocationComponent.ValidationType validationType)
    {
      this.method = method;
      this.validationType = validationType;
    }
    
    MethodHandle getInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices)
    {
      return method.getInvocation(callSiteDescriptor, linkerServices);
    }
    
    MethodHandle getTarget(MethodHandles.Lookup lookup)
    {
      MethodHandle inv = method.getTarget(lookup);
      assert (inv != null);
      return inv;
    }
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.AbstractJavaLinker
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.reflect.Method;
import java.util.Arrays;

final class AccessibleMembersLookup$MethodSignature
{
  private final String name;
  private final Class<?>[] args;
  
  AccessibleMembersLookup$MethodSignature(String name, Class<?>[] args)
  {
    this.name = name;
    this.args = args;
  }
  
  AccessibleMembersLookup$MethodSignature(Method method)
  {
    this(method.getName(), method.getParameterTypes());
  }
  
  public boolean equals(Object o)
  {
    if ((o instanceof MethodSignature))
    {
      MethodSignature ms = (MethodSignature)o;
      return (name.equals(name)) && (Arrays.equals(args, args));
    }
    return false;
  }
  
  public int hashCode()
  {
    return name.hashCode() ^ Arrays.hashCode(args);
  }
  
  public String toString()
  {
    StringBuilder b = new StringBuilder();
    b.append("[MethodSignature ").append(name).append('(');
    if (args.length > 0)
    {
      b.append(args[0].getCanonicalName());
      for (int i = 1; i < args.length; i++) {
        b.append(", ").append(args[i].getCanonicalName());
      }
    }
    return ")]";
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.AccessibleMembersLookup.MethodSignature
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

class AccessibleMembersLookup
{
  private final Map<MethodSignature, Method> methods;
  private final Set<Class<?>> innerClasses;
  private final boolean instance;
  
  AccessibleMembersLookup(Class<?> clazz, boolean instance)
  {
    methods = new HashMap();
    innerClasses = new LinkedHashSet();
    this.instance = instance;
    lookupAccessibleMembers(clazz);
  }
  
  Method getAccessibleMethod(Method m)
  {
    return m == null ? null : (Method)methods.get(new MethodSignature(m));
  }
  
  Collection<Method> getMethods()
  {
    return methods.values();
  }
  
  Class<?>[] getInnerClasses()
  {
    return (Class[])innerClasses.toArray(new Class[innerClasses.size()]);
  }
  
  static final class MethodSignature
  {
    private final String name;
    private final Class<?>[] args;
    
    MethodSignature(String name, Class<?>[] args)
    {
      this.name = name;
      this.args = args;
    }
    
    MethodSignature(Method method)
    {
      this(method.getName(), method.getParameterTypes());
    }
    
    public boolean equals(Object o)
    {
      if ((o instanceof MethodSignature))
      {
        MethodSignature ms = (MethodSignature)o;
        return (name.equals(name)) && (Arrays.equals(args, args));
      }
      return false;
    }
    
    public int hashCode()
    {
      return name.hashCode() ^ Arrays.hashCode(args);
    }
    
    public String toString()
    {
      StringBuilder b = new StringBuilder();
      b.append("[MethodSignature ").append(name).append('(');
      if (args.length > 0)
      {
        b.append(args[0].getCanonicalName());
        for (int i = 1; i < args.length; i++) {
          b.append(", ").append(args[i].getCanonicalName());
        }
      }
      return ")]";
    }
  }
  
  private void lookupAccessibleMembers(Class<?> clazz)
  {
    boolean searchSuperTypes;
    if (!CheckRestrictedPackage.isRestrictedClass(clazz))
    {
      boolean searchSuperTypes = false;
      for (Method method : clazz.getMethods())
      {
        boolean isStatic = Modifier.isStatic(method.getModifiers());
        if (instance != isStatic)
        {
          MethodSignature sig = new MethodSignature(method);
          if (!methods.containsKey(sig))
          {
            Class<?> declaringClass = method.getDeclaringClass();
            if ((declaringClass != clazz) && (CheckRestrictedPackage.isRestrictedClass(declaringClass))) {
              searchSuperTypes = true;
            } else if ((!isStatic) || (clazz == declaringClass)) {
              methods.put(sig, method);
            }
          }
        }
      }
      for (Class<?> innerClass : clazz.getClasses()) {
        innerClasses.add(innerClass);
      }
    }
    else
    {
      searchSuperTypes = true;
    }
    if ((instance) && (searchSuperTypes))
    {
      Object interfaces = clazz.getInterfaces();
      for (int i = 0; i < interfaces.length; i++) {
        lookupAccessibleMembers(interfaces[i]);
      }
      Object superclass = clazz.getSuperclass();
      if (superclass != null) {
        lookupAccessibleMembers((Class)superclass);
      }
    }
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.AccessibleMembersLookup
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodType;
import jdk.internal.dynalink.support.TypeUtilities;

final class ApplicableOverloadedMethods$1
  extends ApplicableOverloadedMethods.ApplicabilityTest
{
  boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method)
  {
    MethodType methodType = method.getMethodType();
    int methodArity = methodType.parameterCount();
    if (methodArity != callSiteType.parameterCount()) {
      return false;
    }
    for (int i = 1; i < methodArity; i++) {
      if (!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.ApplicableOverloadedMethods.1
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodType;
import jdk.internal.dynalink.support.TypeUtilities;

final class ApplicableOverloadedMethods$2
  extends ApplicableOverloadedMethods.ApplicabilityTest
{
  boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method)
  {
    MethodType methodType = method.getMethodType();
    int methodArity = methodType.parameterCount();
    if (methodArity != callSiteType.parameterCount()) {
      return false;
    }
    for (int i = 1; i < methodArity; i++) {
      if (!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), methodType
        .parameterType(i))) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.ApplicableOverloadedMethods.2
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodType;
import jdk.internal.dynalink.support.TypeUtilities;

final class ApplicableOverloadedMethods$3
  extends ApplicableOverloadedMethods.ApplicabilityTest
{
  boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method)
  {
    if (!method.isVarArgs()) {
      return false;
    }
    MethodType methodType = method.getMethodType();
    int methodArity = methodType.parameterCount();
    int fixArity = methodArity - 1;
    int callSiteArity = callSiteType.parameterCount();
    if (fixArity > callSiteArity) {
      return false;
    }
    for (int i = 1; i < fixArity; i++) {
      if (!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), methodType
        .parameterType(i))) {
        return false;
      }
    }
    Class<?> varArgType = methodType.parameterType(fixArity).getComponentType();
    for (int i = fixArity; i < callSiteArity; i++) {
      if (!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), varArgType)) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.ApplicableOverloadedMethods.3
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodType;

abstract class ApplicableOverloadedMethods$ApplicabilityTest
{
  abstract boolean isApplicable(MethodType paramMethodType, SingleDynamicMethod paramSingleDynamicMethod);
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.ApplicableOverloadedMethods.ApplicabilityTest
 * Java Class Version: 7 (51.0)
 * JD-Core Version:    0.7.1
 */
package jdk.internal.dynalink.beans;

import java.lang.invoke.MethodType;
import java.util.LinkedList;
import java.util.List;
import jdk.internal.dynalink.support.TypeUtilities;

class ApplicableOverloadedMethods
{
  private final List<SingleDynamicMethod> methods;
  private final boolean varArgs;
  
  ApplicableOverloadedMethods(List<SingleDynamicMethod> methods, MethodType callSiteType, ApplicabilityTest test)
  {
    this.methods = new LinkedList();
    for (SingleDynamicMethod m : methods) {
      if (test.isApplicable(callSiteType, m)) {
        this.methods.add(m);
      }
    }
    varArgs = (test == APPLICABLE_BY_VARIABLE_ARITY);
  }
  
  List<SingleDynamicMethod> getMethods()
  {
    return methods;
  }
  
  List<SingleDynamicMethod> findMaximallySpecificMethods()
  {
    return MaximallySpecific.getMaximallySpecificMethods(methods, varArgs);
  }
  
  static final ApplicabilityTest APPLICABLE_BY_SUBTYPING = new ApplicabilityTest()
  {
    boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method)
    {
      MethodType methodType = method.getMethodType();
      int methodArity = methodType.parameterCount();
      if (methodArity != callSiteType.parameterCount()) {
        return false;
      }
      for (int i = 1; i < methodArity; i++) {
        if (!TypeUtilities.isSubtype(callSiteType.parameterType(i), methodType.parameterType(i))) {
          return false;
        }
      }
      return true;
    }
  };
  static final ApplicabilityTest APPLICABLE_BY_METHOD_INVOCATION_CONVERSION = new ApplicabilityTest()
  {
    boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method)
    {
      MethodType methodType = method.getMethodType();
      int methodArity = methodType.parameterCount();
      if (methodArity != callSiteType.parameterCount()) {
        return false;
      }
      for (int i = 1; i < methodArity; i++) {
        if (!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), methodType
          .parameterType(i))) {
          return false;
        }
      }
      return true;
    }
  };
  static final ApplicabilityTest APPLICABLE_BY_VARIABLE_ARITY = new ApplicabilityTest()
  {
    boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method)
    {
      if (!method.isVarArgs()) {
        return false;
      }
      MethodType methodType = method.getMethodType();
      int methodArity = methodType.parameterCount();
      int fixArity = methodArity - 1;
      int callSiteArity = callSiteType.parameterCount();
      if (fixArity > callSiteArity) {
        return false;
      }
      for (int i = 1; i < fixArity; i++) {
        if (!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), methodType
          .parameterType(i))) {
          return false;
        }
      }
      Class<?> varArgType = methodType.parameterType(fixArity).getComponentType();
      for (int i = fixArity; i < callSiteArity; i++) {
        if (!TypeUtilities.isMethodInvocationConvertible(callSiteType.parameterType(i), varArgType)) {
          return false;
        }
      }
      return true;
    }
  };
  
  static abstract class ApplicabilityTest
  {
    abstract boolean isApplicable(MethodType paramMethodType, SingleDynamicMethod paramSingleDynamicMethod);
  }
}

/* Location:
 * Qualified Name:     jdk.internal.dynalink.beans.ApplicableOverloadedMethods
 * Java Class Version: 7 (51.0)
 * JD-Co
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd