public String getSignature(Class<?> caller, String name, MethodType type, boolean isStatic) { String className = caller.getName().replace('.', '/'); // Remove implicit first argument if (!isStatic) type = type.dropParameterTypes(0, 1); return className + "/" + name + type.toMethodDescriptorString(); }
@SuppressWarnings("ReferenceEquality") @Override public MethodHandle findShadowMethodHandle(Class<?> definingClass, String name, MethodType methodType, boolean isStatic) throws IllegalAccessException { return PerfStatsCollector.getInstance().measure("find shadow method handle", () -> { MethodType actualType = isStatic ? methodType : methodType.dropParameterTypes(0, 1); Class<?>[] paramTypes = actualType.parameterArray(); Method shadowMethod = pickShadowMethod(definingClass, name, paramTypes); if (shadowMethod == CALL_REAL_CODE) { return null; } else if (shadowMethod == DO_NOTHING_METHOD) { return DO_NOTHING; } shadowMethod.setAccessible(true); MethodHandle mh = LOOKUP.unreflect(shadowMethod); // Robolectric doesn't actually look for static, this for example happens // in MessageQueue.nativeInit() which used to be void non-static in 4.2. if (!isStatic && Modifier.isStatic(shadowMethod.getModifiers())) { return dropArguments(mh, 0, Object.class); } else { return mh; } }); }
MethodType typeVTU = f.type().dropParameterTypes(0, 1).appendParameterTypes(h.type().parameterList()).appendParameterTypes(f.type().parameterType(0)); MethodType typeUST = f.type().dropParameterTypes(1, 2).appendParameterTypes(g.type().parameterList()).appendParameterTypes(h.type().parameterList());
MethodType typeVTU = f.type().dropParameterTypes(0, 1).appendParameterTypes(h.type().parameterList()).appendParameterTypes(f.type().parameterType(0)); MethodType typeUST = f.type().dropParameterTypes(1, 2).appendParameterTypes(g.type().parameterList()).appendParameterTypes(h.type().parameterList());
private static MethodHandle buildGetter(Class arrayClass) { MethodHandle get = MethodHandles.arrayElementGetter(arrayClass); MethodHandle fallback = MethodHandles.explicitCastArguments(get, get.type().changeParameterType(0, Object.class)); fallback = MethodHandles.dropArguments(fallback, 2, int.class); MethodType reorderType = fallback.type(). insertParameterTypes(0, int.class). dropParameterTypes(2,3); fallback = MethodHandles.permuteArguments(fallback, reorderType, 1, 0, 0); fallback = MethodHandles.foldArguments(fallback, normalizeIndex); fallback = MethodHandles.explicitCastArguments(fallback, get.type()); MethodHandle guard = MethodHandles.dropArguments(notNegative, 0, arrayClass); MethodHandle handle = MethodHandles.guardWithTest(guard, get, fallback); return handle; }
private static MethodHandle buildSetter(Class arrayClass){ MethodHandle set = MethodHandles.arrayElementSetter(arrayClass); MethodHandle fallback = MethodHandles.explicitCastArguments(set, set.type().changeParameterType(0, Object.class)); fallback = MethodHandles.dropArguments(fallback, 3, int.class); MethodType reorderType = fallback.type(). insertParameterTypes(0, int.class). dropParameterTypes(4,5); fallback = MethodHandles.permuteArguments(fallback, reorderType, 1, 0, 3, 0); fallback = MethodHandles.foldArguments(fallback, normalizeIndex); fallback = MethodHandles.explicitCastArguments(fallback, set.type()); MethodHandle guard = MethodHandles.dropArguments(notNegative, 0, arrayClass); MethodHandle handle = MethodHandles.guardWithTest(guard, set, fallback); return handle; }
/** * Drop the specified number of first arguments from this signature. * * @param n number of arguments to drop * @return a new signature */ public Signature dropFirst(int n) { return new Signature( methodType.dropParameterTypes(0, n), Arrays.copyOfRange(argNames, n, argNames.length)); }
/** * Returns a new call site descriptor that is identical to the passed one, except that it has some parameter types * removed from its method type. * @param desc the original call site descriptor * @param start index of the first parameter to remove * @param end index of the first parameter to not remove * @return a new call site descriptor with modified method type */ public static CallSiteDescriptor dropParameterTypes(final CallSiteDescriptor desc, final int start, final int end) { return desc.changeMethodType(desc.getMethodType().dropParameterTypes(start, end)); }
public MethodType down(MethodType type) { assertTypesAreCompatible(); return type .dropParameterTypes(index, index + count) .insertParameterTypes(index, arrayType); }
/** * Returns a new call site descriptor that is identical to the passed one, except that it has some parameter types * removed from its method type. * @param desc the original call site descriptor * @param start index of the first parameter to remove * @param end index of the first parameter to not remove * @return a new call site descriptor with modified method type */ public static CallSiteDescriptor dropParameterTypes(CallSiteDescriptor desc, int start, int end) { return desc.changeMethodType(desc.getMethodType().dropParameterTypes(start, end)); }
/** * Drop the specified number of last arguments from this signature. * * @param n number of arguments to drop * @return a new signature */ public Signature dropLast(int n) { return new Signature( methodType.dropParameterTypes(methodType.parameterCount() - n, methodType.parameterCount()), Arrays.copyOfRange(argNames, 0, argNames.length - n)); }
public static CallSite invokeVirtual(Lookup caller, String methodName, MethodType signature, String owner) throws ReflectiveOperationException { Class<?> o = resolve(caller, owner); signature = signature.dropParameterTypes(0,1); // drop 'this' for (Linker linker : Linker.LINKERS) { CallSite c = linker.invokeVirtual(caller, methodName, signature, o); if (c!=null) return c; } throw new LinkageError("Unable to link invokeVirtual "+owner+"."+methodName+signature); }
public static CallSite invokeInterface(Lookup caller, String methodName, MethodType signature, String owner) throws ReflectiveOperationException { Class<?> o = resolve(caller, owner); signature = signature.dropParameterTypes(0,1); // drop 'this' for (Linker linker : Linker.LINKERS) { CallSite c = linker.invokeInterface(caller, methodName, signature, o); if (c!=null) return c; } throw new LinkageError("Unable to link invokeInterface "+owner+"."+methodName+signature); }
public MethodType down(MethodType type) { assertTypesAreCompatible(); return type .dropParameterTypes(index, source.parameterCount()) .appendParameterTypes(arrayType); }
public static CallSite invokeSpecial(Lookup caller, String methodName, MethodType signature, String owner) throws ReflectiveOperationException { Class<?> o = resolve(caller, owner); signature = signature.dropParameterTypes(0,1); // drop 'this' for (Linker linker : Linker.LINKERS) { CallSite c = linker.invokeSpecial(caller, methodName, signature, o); if (c!=null) return c; } throw new LinkageError("Unable to link invokeSpecial "+owner+"."+methodName+signature); }
public MethodType down(MethodType type) { int last = source.parameterCount() - 1; if (!source.parameterArray()[last].isArray()) { throw new InvalidTransformException("trailing argument is not []: " + source); } type = type.dropParameterTypes(last, last + 1); return type.appendParameterTypes(spreadTypes); }
private Object[] a(Object[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { if (targetParameterTypes == null || targetParameterTypes.length == 0) { return args; } return convertArguments(targetParameterTypes, method.type().dropParameterTypes(0, 1).parameterArray(), args); }
private static MethodType getTestType(final MethodHandle test, final MethodType type) { return type.dropParameterTypes(test.type().parameterCount(), type.parameterCount()).changeReturnType(boolean.class); }
private static MethodHandle invalidCallArgumentsHandle(String name, MethodType type, WrongMethodTypeException e) { // Add native call name? MethodHandle mh = MethodHandles.insertArguments(invalidNativeCallArgumentsMH, 0, e.getMessage()); return MethodHandles.dropArguments(mh, 1, type.dropParameterTypes(0, 1).parameterArray()); }
private static MethodType getTestType(MethodHandle test, MethodType type) { return type.dropParameterTypes(test.type().parameterCount(), type.parameterCount()).changeReturnType(boolean.class); }