Java 类org.objectweb.asm.Handle 实例源码

项目:DirectLeaks-AntiReleak-Remover    文件:AdviceAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }

        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
项目:DirectLeaks-AntiReleak-Remover    文件:ASMifier.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    buf.setLength(0);
    buf.append(this.name).append(".visitInvokeDynamicInsn(");
    appendConstant(name);
    buf.append(", ");
    appendConstant(desc);
    buf.append(", ");
    appendConstant(bsm);
    buf.append(", new Object[]{");
    for (int i = 0; i < bsmArgs.length; ++i) {
        appendConstant(bsmArgs[i]);
        if (i != bsmArgs.length - 1) {
            buf.append(", ");
        }
    }
    buf.append("});\n");
    text.add(buf.toString());
}
项目:DirectLeaks-AntiReleak-Remover    文件:CheckMethodAdapter.java   
@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;
}
项目:r8    文件:JarSourceCode.java   
private void build(InvokeDynamicInsnNode insn, IRBuilder builder) {
  // Bootstrap method
  Handle bsmHandle = insn.bsm;
  if (bsmHandle.getTag() != Opcodes.H_INVOKESTATIC &&
      bsmHandle.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
    throw new Unreachable(
        "Bootstrap handle is not yet supported: tag == " + bsmHandle.getTag());
  }
  // Resolve the bootstrap method.
  DexMethodHandle bootstrapMethod = getMethodHandle(application, bsmHandle);

  // Decode static bootstrap arguments
  List<DexValue> bootstrapArgs = new ArrayList<>();
  for (Object arg : insn.bsmArgs) {
    bootstrapArgs.add(decodeBootstrapArgument(arg));
  }

  // Construct call site
  DexCallSite callSite = application
      .getCallSite(insn.name, insn.desc, bootstrapMethod, bootstrapArgs);

  buildInvoke(insn.desc, null /* Not needed */,
      false /* Receiver is passed explicitly */, builder,
      (types, registers) -> builder.addInvokeCustom(callSite, types, registers));
}
项目:fastAOP    文件:ASMContentHandler.java   
Handle decodeHandle(final String val) throws SAXException {
    try {
        int dotIndex = val.indexOf('.');
        int descIndex = val.indexOf('(', dotIndex + 1);
        int tagIndex = val.lastIndexOf('(');
        int itfIndex = val.indexOf(' ', tagIndex + 1);

        boolean itf = itfIndex != -1;
        int tag = Integer.parseInt(
                      val.substring(tagIndex + 1,
                            itf? val.length() - 1: itfIndex));
        String owner = val.substring(0, dotIndex);
        String name = val.substring(dotIndex + 1, descIndex);
        String desc = val.substring(descIndex, tagIndex - 1);
        return new Handle(tag, owner, name, desc, itf);

    } catch (RuntimeException e) {
        throw new SAXException("Malformed handle " + val, e);
    }
}
项目:fastAOP    文件:ConstantPool.java   
public Constant newInvokeDynamic(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    key5.set(name, desc, bsm, bsmArgs);
    Constant result = get(key5);
    if (result == null) {
        newNameType(name, desc);
        newHandle(bsm.getTag(), bsm.getOwner(), bsm.getName(),
                bsm.getDesc(), bsm.isInterface());
        for (int i = 0; i < bsmArgs.length; i++) {
            newConst(bsmArgs[i]);
        }
        result = new Constant(key5);
        put(result);
    }
    return result;
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method without extra args and
 *  args to the target method.
 */
private void generateMethodTest2(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test2", "()V",
      null, null);
  MethodType mt = MethodType.methodType(
          CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
  Handle bootstrap = new Handle( Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmLookupStatic", mt.toMethodDescriptorString(), false);
  mv.visitLdcInsn(new Boolean(true));
  mv.visitLdcInsn(new Byte((byte) 127));
  mv.visitLdcInsn(new Character('c'));
  mv.visitLdcInsn(new Short((short) 1024));
  mv.visitLdcInsn(new Integer(123456));
  mv.visitLdcInsn(new Float(1.2f));
  mv.visitLdcInsn(new Long(123456789));
  mv.visitLdcInsn(new Double(3.5123456789));
  mv.visitLdcInsn("String");
  mv.visitInvokeDynamicInsn("targetMethodTest2", "(ZBCSIFJDLjava/lang/String;)V", bootstrap);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invokespecial.
 */
private void generateMethodTest4(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test4", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle( Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallSite", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest5", "(Linvokecustom/InvokeCustom;)V", bootstrap,
      new Handle( Opcodes.H_INVOKESPECIAL, Type.getInternalName(Super.class),
          "targetMethodTest5", "()V", false));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a default method into an interface
 *  that shadows another default method from a super interface.
 */
private void generateMethodTest5(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test5", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest6", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest6", "(Linvokecustom/I;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(I.class),
          "targetMethodTest6", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a default method into an interface
 *  that is at the end of a chain of interfaces.
 */
private void generateMethodTest6(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test6", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest7", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest7", "(Linvokecustom/J;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
          "targetMethodTest7", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a method into an interface
 *  that is shadowed by another definition into a sub interfaces.
 */
private void generateMethodTest7(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test7", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest8", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest8", "(Linvokecustom/J;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
          "targetMethodTest8", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:fastAOP    文件:ASMifier.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    buf.setLength(0);
    buf.append(this.name).append(".visitInvokeDynamicInsn(");
    appendConstant(name);
    buf.append(", ");
    appendConstant(desc);
    buf.append(", ");
    appendConstant(bsm);
    buf.append(", new Object[]{");
    for (int i = 0; i < bsmArgs.length; ++i) {
        appendConstant(bsmArgs[i]);
        if (i != bsmArgs.length - 1) {
            buf.append(", ");
        }
    }
    buf.append("});\n");
    text.add(buf.toString());
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind get instance. The method handle read an instance field from a class.
 */
private void generateMethodTest12(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test12", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("instanceField1", "(Linvokecustom/InvokeCustom;)Ljava/lang/String;",
      bootstrap, new Handle(Opcodes.H_GETFIELD, Type.getInternalName(InvokeCustom.class),
          "instanceField1", "Ljava/lang/String;", false));
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:Spigot-Attribute-Remover    文件:AdviceAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }

        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
项目:fastAOP    文件:AdviceAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }

        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
项目:fastAOP    文件:CheckMethodAdapter.java   
@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;
}
项目:Matcher    文件:Util.java   
public static boolean isCallToInterface(Handle handle) {
    assert handle.isInterface() || handle.getTag() != Opcodes.H_INVOKEINTERFACE;

    return handle.isInterface();

    /*return handle.getTag() == Opcodes.H_INVOKEINTERFACE
            || (handle.getTag() == Opcodes.H_INVOKESPECIAL || handle.getTag() == Opcodes.H_NEWINVOKESPECIAL || handle.getTag() == Opcodes.H_INVOKESTATIC) && handle.isInterface();*/
}
项目:Matcher    文件:AsmClassRemapper.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
    checkState();
    insnIndex++;

    if (mv == null) return;

    Handle target = Util.getTargetHandle(bsm, bsmArgs);

    if (target != null) {
        name = remapper.mapMethodName(target.getOwner(), target.getName(), target.getDesc(), target.isInterface());
    } else {
        String owner = Type.getType(desc).getReturnType().getInternalName();

        name = remapper.mapArbitraryInvokeDynamicMethodName(owner, name);
    }

    boolean copied = false;

    for (int i = 0; i < bsmArgs.length; i++) {
        Object oldArg = bsmArgs[i];
        Object newArg = remapper.mapValue(oldArg);

        if (newArg != oldArg) {
            if (!copied) {
                bsmArgs = Arrays.copyOf(bsmArgs, bsmArgs.length);
                copied = true;
            }

            bsmArgs[i] = newArg;
        }
    }

    mv.visitInvokeDynamicInsn(name, remapper.mapMethodDesc(desc), (Handle) remapper.mapValue(bsm), bsmArgs);
}
项目:DirectLeaks-AntiReleak-Remover    文件:RemappingMethodAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    for (int i = 0; i < bsmArgs.length; i++) {
        bsmArgs[i] = remapper.mapValue(bsmArgs[i]);
    }
    super.visitInvokeDynamicInsn(
            remapper.mapInvokeDynamicMethodName(name, desc),
            remapper.mapMethodDesc(desc), (Handle) remapper.mapValue(bsm),
            bsmArgs);
}
项目:DirectLeaks-AntiReleak-Remover    文件:Remapper.java   
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;
}
项目:DirectLeaks-AntiReleak-Remover    文件:CodeSizeEvaluator.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    minSize += 5;
    maxSize += 5;
    if (mv != null) {
        mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    }
}
项目:DirectLeaks-AntiReleak-Remover    文件:MethodRemapper.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    for (int i = 0; i < bsmArgs.length; i++) {
        bsmArgs[i] = remapper.mapValue(bsmArgs[i]);
    }
    super.visitInvokeDynamicInsn(
            remapper.mapInvokeDynamicMethodName(name, desc),
            remapper.mapMethodDesc(desc), (Handle) remapper.mapValue(bsm),
            bsmArgs);
}
项目:DirectLeaks-AntiReleak-Remover    文件:AnalyzerAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    if (mv != null) {
        mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    }
    if (this.locals == null) {
        labels = null;
        return;
    }
    pop(desc);
    pushDesc(desc);
    labels = null;
}
项目:DirectLeaks-AntiReleak-Remover    文件:AnalyzerAdapter.java   
@Override
public void visitLdcInsn(final Object cst) {
    if (mv != null) {
        mv.visitLdcInsn(cst);
    }
    if (this.locals == null) {
        labels = null;
        return;
    }
    if (cst instanceof Integer) {
        push(Opcodes.INTEGER);
    } else if (cst instanceof Long) {
        push(Opcodes.LONG);
        push(Opcodes.TOP);
    } else if (cst instanceof Float) {
        push(Opcodes.FLOAT);
    } else if (cst instanceof Double) {
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
    } else if (cst instanceof String) {
        push("java/lang/String");
    } else if (cst instanceof Type) {
        int sort = ((Type) cst).getSort();
        if (sort == Type.OBJECT || sort == Type.ARRAY) {
            push("java/lang/Class");
        } else if (sort == Type.METHOD) {
            push("java/lang/invoke/MethodType");
        } else {
            throw new IllegalArgumentException();
        }
    } else if (cst instanceof Handle) {
        push("java/lang/invoke/MethodHandle");
    } else {
        throw new IllegalArgumentException();
    }
    labels = null;
}
项目:DirectLeaks-AntiReleak-Remover    文件:ASMContentHandler.java   
@Override
public final void end(final String element) {
    ArrayList<?> bsmArgs = (ArrayList<?>) pop();
    Handle bsm = (Handle) pop();
    String desc = (String) pop();
    String name = (String) pop();
    getCodeVisitor().visitInvokeDynamicInsn(name, desc, bsm,
            bsmArgs.toArray());
}
项目:DirectLeaks-AntiReleak-Remover    文件:SAXCodeAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "name", "name", "", name);
    attrs.addAttribute("", "desc", "desc", "", desc);
    attrs.addAttribute("", "bsm", "bsm", "",
            SAXClassAdapter.encode(bsm.toString()));
    sa.addStart("INVOKEDYNAMIC", attrs);
    for (int i = 0; i < bsmArgs.length; i++) {
        sa.addElement("bsmArg", getConstantAttribute(bsmArgs[i]));
    }
    sa.addEnd("INVOKEDYNAMIC");
}
项目:DirectLeaks-AntiReleak-Remover    文件:CheckMethodAdapter.java   
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);
    }
}
项目:r8    文件:JarRegisterEffectsVisitor.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
  registerMethodHandleType(bsm);

  // Register bootstrap method arguments, only Type and MethodHandle need to be register.
  for (Object arg : bsmArgs) {
    if (arg instanceof Type && ((Type) arg).getSort() == Type.OBJECT) {
      registry.registerTypeReference(application.getType((Type) arg));
    } else if (arg instanceof Handle) {
      registerMethodHandleType((Handle) arg);
    }
  }
}
项目:r8    文件:JarRegisterEffectsVisitor.java   
private void registerMethodHandleType(Handle handle) {
  switch (handle.getTag()) {
    case Opcodes.H_GETFIELD:
      visitFieldInsn(Opcodes.GETFIELD, handle.getOwner(), handle.getName(), handle.getDesc());
      break;
    case Opcodes.H_GETSTATIC:
      visitFieldInsn(Opcodes.GETSTATIC, handle.getOwner(), handle.getName(), handle.getDesc());
      break;
    case Opcodes.H_PUTFIELD:
      visitFieldInsn(Opcodes.PUTFIELD, handle.getOwner(), handle.getName(), handle.getDesc());
      break;
    case Opcodes.H_PUTSTATIC:
      visitFieldInsn(Opcodes.PUTSTATIC, handle.getOwner(), handle.getName(), handle.getDesc());
      break;
    case Opcodes.H_INVOKEVIRTUAL:
      visitMethodInsn(
          Opcodes.INVOKEVIRTUAL, handle.getOwner(), handle.getName(), handle.getDesc(), false);
      break;
    case Opcodes.H_INVOKEINTERFACE:
      visitMethodInsn(
          Opcodes.INVOKEINTERFACE, handle.getOwner(), handle.getName(), handle.getDesc(), true);
      break;
    case Opcodes.H_INVOKESPECIAL:
      visitMethodInsn(
          Opcodes.INVOKESPECIAL, handle.getOwner(), handle.getName(), handle.getDesc(), false);
      break;
    case Opcodes.H_INVOKESTATIC:
      visitMethodInsn(
          Opcodes.INVOKESTATIC, handle.getOwner(), handle.getName(), handle.getDesc(), false);
      break;
    case Opcodes.H_NEWINVOKESPECIAL:
      visitMethodInsn(
          Opcodes.INVOKESPECIAL, handle.getOwner(), handle.getName(), handle.getDesc(), false);
      break;
    default:
      throw new Unreachable("MethodHandle tag is not supported: " + handle.getTag());
  }
}
项目:r8    文件:JarSourceCode.java   
private DexValue decodeBootstrapArgument(Object value) {
  if (value instanceof Integer) {
    return DexValue.DexValueInt.create((Integer) value);
  } else if (value instanceof Long) {
    return DexValue.DexValueLong.create((Long) value);
  } else if (value instanceof Float) {
    return DexValue.DexValueFloat.create((Float) value);
  } else if (value instanceof Double) {
    return DexValue.DexValueDouble.create((Double) value);
  } else if (value instanceof String) {
    return new DexValue.DexValueString(application.getString((String) value));

  } else if (value instanceof Type) {
    Type type = (Type) value;
    switch (type.getSort()) {
      case Type.OBJECT:
        return new DexValue.DexValueType(
            application.getTypeFromDescriptor(((Type) value).getDescriptor()));
      case Type.METHOD:
        return new DexValue.DexValueMethodType(
            application.getProto(((Type) value).getDescriptor()));
    }
    throw new Unreachable("Type sort is not supported: " + type.getSort());

  } else if (value instanceof Handle) {
    return new DexValue.DexValueMethodHandle(getMethodHandle(application, (Handle) value));
  } else {
    throw new Unreachable(
        "Unsupported bootstrap static argument of type " + value.getClass().getSimpleName());
  }
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method without extra args and no arg
 *  to the target method.
 */
private void generateMethodTest1(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test1", "()V",
          null, null);
  MethodType mt =
      MethodType.methodType(
          CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
  Handle bootstrap = new Handle( Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmLookupStatic", mt.toMethodDescriptorString(), false);
  mv.visitInvokeDynamicInsn("targetMethodTest1", "()V", bootstrap);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:r8    文件:TestGenerator.java   
/**
 * Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 * MethodHandle of kind put static. The method handle write a static field in a class and then
 * print its value.
 */
private void generateMethodTest11(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test11", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
          MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitLdcInsn("Write static field");
  mv.visitInvokeDynamicInsn("staticField1", "(Ljava/lang/String;)V", bootstrap,
      new Handle(Opcodes.H_PUTSTATIC, Type.getInternalName(InvokeCustom.class),
          "staticField1", "Ljava/lang/String;", false));
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      Type.getInternalName(InvokeCustom.class),
      "staticField1",
      "Ljava/lang/String;");
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:r8    文件:TestGenerator.java   
/**
 * Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 * MethodHandle of kind put instance. The method handle write an instance field in a class and
 * then print its value.
 */
private void generateMethodTest13(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test13", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitVarInsn(Opcodes.ASTORE, 0);
  mv.visitVarInsn(Opcodes.ALOAD, 0);
  mv.visitLdcInsn("Write instance field");
  mv.visitInvokeDynamicInsn("instanceField1", "(Linvokecustom/InvokeCustom;Ljava/lang/String;)V",
      bootstrap, new Handle(Opcodes.H_PUTFIELD, Type.getInternalName(InvokeCustom.class),
          "instanceField1", "Ljava/lang/String;", false));
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitVarInsn(Opcodes.ALOAD, 0);
  mv.visitFieldInsn(Opcodes.GETFIELD,
      Type.getInternalName(InvokeCustom.class),
      "instanceField1",
      "Ljava/lang/String;");
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:elasticsearch_my    文件:SFunction.java   
private void initializeConstant(MethodWriter writer) {
    final Handle handle = new Handle(Opcodes.H_INVOKESTATIC,
            CLASS_TYPE.getInternalName(),
            name,
            method.method.getDescriptor(),
            false);
    writer.push(handle);
}
项目:fastAOP    文件:CheckMethodAdapter.java   
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);
    }
}
项目:FastMustache    文件:BytecodeGenerator.java   
protected void insertDefaultSectionStart(String key, boolean inverted) throws CompilerException {
    if(!builderLoaded && needLocal) {
        mv.visitVarInsn(ALOAD, varBuilder);
        builderLoaded = true;
    }

    if(data.getDataType() != DATA) {
        throw new CompilerException("The default section generator can't be used within a custom data type");
    }

    String methodName = "lambda$render$" + compiler.getNextLambdaId();

    mv.visitVarInsn(ALOAD, varData);
    mv.visitLdcInsn(key);

    Type methodType = Type.getMethodType(STRING, DATA);

    Handle lambda = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
            "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;"
                    + "Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;", false);
    Handle method = new Handle(H_INVOKESTATIC, className, methodName, methodType.getDescriptor(), false);

    mv.visitInvokeDynamicInsn("render", Type.getMethodDescriptor(SIMPLE_TEMPLATE), lambda, methodType, method, methodType);

    mv.visitInsn(inverted ? ICONST_1 : ICONST_0);

    mv.visitMethodInsn(INVOKESTATIC, UTILS.getInternalName(), "renderSection", "(" + BUILDER.getDescriptor() +
            DATA.getDescriptor() + STRING.getDescriptor() + SIMPLE_TEMPLATE.getDescriptor() +"Z)" + BUILDER.getDescriptor(), false);

    BytecodeGenerator gen = new BytecodeGenerator(compiler, this, key, cw, data, className, classDesc);
    compiler.setGenerator(gen);

    gen.insertMethodStart(methodName);
}
项目:Recaf    文件:TagTypeSwitchPanel.java   
public TagTypeSwitchPanel(JList<AbstractInsnNode> list, Handle handle) {
    this.list = list;
    this.handle = handle;
    //setMaximumSize(new Dimension(300, 300));
    // content.setMaximumSize(new Dimension(300, 300));
    // scroll.setMaximumSize(new Dimension(300, 300));
    content.setLayout(new GridLayout(0, 2));
    populate(OpcodeUtil.OPS_TAG, s -> OpcodeUtil.nameToTag(s));
    setLayout(new BorderLayout());
    JScrollPane scroll = new JScrollPane(content);
    add(scroll, BorderLayout.CENTER);
}
项目:Spigot-Attribute-Remover    文件:RemappingMethodAdapter.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    for (int i = 0; i < bsmArgs.length; i++) {
        bsmArgs[i] = remapper.mapValue(bsmArgs[i]);
    }
    super.visitInvokeDynamicInsn(
            remapper.mapInvokeDynamicMethodName(name, desc),
            remapper.mapMethodDesc(desc), (Handle) remapper.mapValue(bsm),
            bsmArgs);
}
项目:Spigot-Attribute-Remover    文件:Remapper.java   
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;
}
项目:Spigot-Attribute-Remover    文件:CodeSizeEvaluator.java   
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    minSize += 5;
    maxSize += 5;
    if (mv != null) {
        mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    }
}