&& handle.getTag() != Opcodes.H_INVOKESTATIC)) {
private SootMethodRef toSootMethodRef(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); SootClass bsmCls = Scene.v().getSootClass(bsmClsName); List<Type> bsmSigTypes = AsmUtil.toJimpleDesc(methodHandle.getDesc()); Type returnType = bsmSigTypes.remove(bsmSigTypes.size() - 1); return Scene.v().makeMethodRef(bsmCls, methodHandle.getName(), bsmSigTypes, returnType, methodHandle.getTag() == MethodHandle.Kind.REF_INVOKE_STATIC.getValue()); }
private SootFieldRef toSootFieldRef(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); SootClass bsmCls = Scene.v().getSootClass(bsmClsName); Type t = AsmUtil.toJimpleDesc(methodHandle.getDesc()).get(0); int kind = methodHandle.getTag(); return Scene.v().makeFieldRef(bsmCls, methodHandle.getName(), t, kind == MethodHandle.Kind.REF_GET_FIELD_STATIC.getValue() || kind == MethodHandle.Kind.REF_PUT_FIELD_STATIC.getValue()); }
Handle handle = (Handle) value; return addConstantMethodHandle( handle.getTag(), handle.getOwner(), handle.getName(),
private void transformIndyBootstrap(MethodVisitor mv, AbstractInsnNode ain) { InvokeDynamicInsnNode indy = (InvokeDynamicInsnNode)ain; Object[]bsmArgs = indy.bsmArgs; // Is it a lambda conversion if (indy.bsm.getOwner().equals("java/lang/invoke/LambdaMetafactory")) { Handle lambdaBody = (Handle)bsmArgs[1]; String desc = lambdaBody.getDesc(); if (detector.isPausable(lambdaBody.getOwner(), lambdaBody.getName(), desc)) { bsmArgs[0] = addFiberType((Type)bsmArgs[0]); bsmArgs[1] = new Handle(lambdaBody.getTag(), lambdaBody.getOwner(), lambdaBody.getName(), desc.replace(")", D_FIBER_LAST_ARG), lambdaBody.isInterface()); bsmArgs[2] = addFiberType((Type)bsmArgs[2]); } } ain.accept(mv); }
SootClass enclosingClass = body.getMethod().getDeclaringClass(); bootstrap_model = LambdaMetaFactory.v().makeLambdaHelper(bsmMethodArgs, insn.bsm.getTag(), insn.name, types, enclosingClass); indy = Jimple.v().newDynamicInvokeExpr(bsmMethodRef, bsmMethodArgs, methodRef, insn.bsm.getTag(), methodArgs);
bootstrapMethodsAttribute.putShort( addConstantMethodHandle( bootstrapMethodHandle.getTag(), bootstrapMethodHandle.getOwner(), bootstrapMethodHandle.getName(),
private MethodHandle parseHandle(Handle handle) { String owner = referenceCache.getCached(handle.getOwner().replace('/', '.')); String name = referenceCache.getCached(handle.getName()); switch (handle.getTag()) { case Opcodes.H_GETFIELD: return MethodHandle.fieldGetter(owner, name, referenceCache.getCached(ValueType.parse(handle.getDesc()))); case Opcodes.H_GETSTATIC: return MethodHandle.staticFieldGetter(owner, name, referenceCache.getCached(ValueType.parse(handle.getDesc()))); case Opcodes.H_PUTFIELD: return MethodHandle.fieldSetter(owner, name, referenceCache.getCached(ValueType.parse(handle.getDesc()))); case Opcodes.H_PUTSTATIC: return MethodHandle.staticFieldSetter(owner, name, referenceCache.getCached(ValueType.parse(handle.getDesc()))); case Opcodes.H_INVOKEVIRTUAL: return MethodHandle.virtualCaller(owner, name, parseSignature(handle.getDesc())); case Opcodes.H_INVOKESTATIC: return MethodHandle.staticCaller(owner, name, parseSignature(handle.getDesc())); case Opcodes.H_INVOKESPECIAL: return MethodHandle.specialCaller(owner, name, parseSignature(handle.getDesc())); case Opcodes.H_NEWINVOKESPECIAL: return MethodHandle.constructorCaller(owner, name, parseSignature(handle.getDesc())); case Opcodes.H_INVOKEINTERFACE: return MethodHandle.interfaceCaller(owner, name, parseSignature(handle.getDesc())); default: throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag()); } }
void checkLDCConstant(final Object cst) { if (cst instanceof Type) { int s = ((Type) cst).getSort(); if (s != Type.OBJECT && s != Type.ARRAY && s != Type.METHOD) { throw new IllegalArgumentException("Illegal LDC constant value"); } if (s != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) { throw new IllegalArgumentException( "ldc of a constant class requires at least version 1.5"); } if (s == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) { throw new IllegalArgumentException( "ldc of a method type requires at least version 1.7"); } } else if (cst instanceof Handle) { if ((version & 0xFFFF) < Opcodes.V1_7) { throw new IllegalArgumentException( "ldc of a handle requires at least version 1.7"); } int tag = ((Handle) cst).getTag(); if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) { throw new IllegalArgumentException("invalid handle tag " + tag); } } else { checkConstant(cst); } }
@Override public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { checkStartCode(); checkEndCode(); checkMethodIdentifier(version, name, "name"); checkMethodDesc(desc); if (bsm.getTag() != Opcodes.H_INVOKESTATIC && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL) { throw new IllegalArgumentException("invalid handle tag " + bsm.getTag()); } for (int i = 0; i < bsmArgs.length; i++) { checkLDCConstant(bsmArgs[i]); } super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); ++insnCount; }
@Override public void visitInvokeDynamicInsn( final String name, final String descriptor, final Handle bootstrapMethodHandle, final Object... bootstrapMethodArguments) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkMethodIdentifier(version, name, "name"); checkMethodDescriptor(version, descriptor); if (bootstrapMethodHandle.getTag() != Opcodes.H_INVOKESTATIC && bootstrapMethodHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL) { throw new IllegalArgumentException("invalid handle tag " + bootstrapMethodHandle.getTag()); } for (Object bootstrapMethodArgument : bootstrapMethodArguments) { checkLdcConstant(bootstrapMethodArgument); } super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments); ++insnCount; }
@Override public void visitInvokeDynamicInsn( final String name, final String descriptor, final Handle bootstrapMethodHandle, final Object... bootstrapMethodArguments) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkMethodIdentifier(version, name, "name"); checkMethodDescriptor(version, descriptor); if (bootstrapMethodHandle.getTag() != Opcodes.H_INVOKESTATIC && bootstrapMethodHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL) { throw new IllegalArgumentException("invalid handle tag " + bootstrapMethodHandle.getTag()); } for (Object bootstrapMethodArgument : bootstrapMethodArguments) { checkLdcConstant(bootstrapMethodArgument); } super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments); ++insnCount; }
@Override public void visitLdcInsn(Object cst) { if (cst instanceof Handle) { Handle handle = (Handle) cst; handle = new Handle(handle.getTag(), handle.getOwner(), handle.getName(), getMethodDescriptor(handle.getDesc()), handle.isInterface()); StringBuilder buf = stringBuilder; buf.setLength(0); buf.append(tab2).append("LDC "); buf.append(handle.getOwner()).append('.').append(handle.getName()).append(handle.getDesc()); buf.append('\n'); text.add(buf.toString()); return; } super.visitLdcInsn(cst); }
public static Instruction buildInvokeDynamic(final String className, final String name, final String desc, final Handle handle, final Label label) { final MethodIdentifier actualIdentifier = of(handle.getOwner(), handle.getName(), handle.getDesc(), handle.getTag() == Opcodes.H_INVOKESTATIC); final MethodIdentifier dynamicIdentifier = of(className, name, desc, true); return new InvokeDynamicInstruction(actualIdentifier, dynamicIdentifier, label); }
public static Instruction buildInvokeDynamic(final String className, final String name, final String desc, final Handle handle, final Label label) { final MethodIdentifier actualIdentifier = of(handle.getOwner(), handle.getName(), handle.getDesc(), handle.getTag() == Opcodes.H_INVOKESTATIC); final MethodIdentifier dynamicIdentifier = of(className, name, desc, true); return new InvokeDynamicInstruction(actualIdentifier, dynamicIdentifier, label); }
private void backportLambda(String invokedName, Type invokedType, Handle bsm, Object[] bsmArgs) { Type[] argumentTypes= Type.getArgumentTypes(invokedType.toString()); Type returnType= Type.getReturnType(invokedType.toString()); String returnTypeName= returnType.getClassName(); int length= argumentTypes.length; createArrayWithParameters(length, argumentTypes); this.visitLdcInsn(myClassName); this.visitLdcInsn(invokedName); this.visitLdcInsn(returnTypeName); this.visitLdcInsn(invokedType.toString()); this.visitLdcInsn(bsmArgs[1].toString()); this.visitVarInsn(Opcodes.ALOAD, 20); this.visitLdcInsn(bsm.getTag() == 5 ? "virtual" : "static"); String runnableSignature= "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;"; this.visitMethodInsn(INVOKESTATIC, "com/dragome/utils/DragomeCallsiteFactory", "create", runnableSignature, false); }
private static MethodHandle parseHandle(Handle handle) { switch (handle.getTag()) { case Opcodes.H_GETFIELD: return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); default: throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag());
public Object mapValue(Object value) { if (value instanceof Type) { return mapType((Type) value); } if (value instanceof Handle) { Handle h = (Handle) value; return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName( h.getOwner(), h.getName(), h.getDesc()), mapMethodDesc(h.getDesc()), h.isInterface()); } return value; }
public Object mapValue(Object value) { if (value instanceof Type) { return mapType((Type) value); } if (value instanceof Handle) { Handle h = (Handle) value; return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName( h.getOwner(), h.getName(), h.getDesc()), mapMethodDesc(h.getDesc()), h.isInterface()); } return value; }