jdk.internal.org.objectweb.asm.Handle Java Examples

The following examples show how to use jdk.internal.org.objectweb.asm.Handle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdviceAdapter.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example #2
Source File: CheckMethodAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: ASMifier.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: MethodGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void memberInfoArray(final String className, final List<MemberInfo> mis) {
    if (mis.isEmpty()) {
        pushNull();
        return;
    }

    int pos = 0;
    push(mis.size());
    newObjectArray(SPECIALIZATION_TYPE);
    for (final MemberInfo mi : mis) {
        dup();
        push(pos++);
        visitTypeInsn(NEW, SPECIALIZATION_TYPE);
        dup();
        visitLdcInsn(new Handle(H_INVOKESTATIC, className, mi.getJavaName(), mi.getJavaDesc()));
        final Type    linkLogicClass = mi.getLinkLogicClass();
        final boolean linkLogic      = !linkLogicIsEmpty(linkLogicClass);
        final String  ctor           = linkLogic ? SPECIALIZATION_INIT3 : SPECIALIZATION_INIT2;
        if (linkLogic) {
            visitLdcInsn(linkLogicClass);
        }
        visitInsn(mi.isOptimistic() ? ICONST_1 : ICONST_0);
        visitMethodInsn(INVOKESPECIAL, SPECIALIZATION_TYPE, INIT, ctor, false);
        arrayStore(TYPE_SPECIALIZATION);
    }
}
 
Example #5
Source File: MethodGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void memberInfoArray(final String className, final List<MemberInfo> mis) {
    if (mis.isEmpty()) {
        pushNull();
        return;
    }

    int pos = 0;
    push(mis.size());
    newObjectArray(METHODHANDLE_TYPE);
    for (final MemberInfo mi : mis) {
        dup();
        push(pos++);
        visitLdcInsn(new Handle(H_INVOKESTATIC, className, mi.getJavaName(), mi.getJavaDesc()));
        arrayStore(TYPE_METHODHANDLE);
    }
}
 
Example #6
Source File: ASMifier.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example #7
Source File: Method.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Handle generateBootstrapMethod(Handle h) {
    String bootstrapName = "bootstrapMethod";
    MethodType bootstrapType = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);

    MethodVisitor bmv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, bootstrapName, bootstrapType.toMethodDescriptorString(), null, null);
    bmv.visitCode();

    String constCallSite = "java/lang/invoke/ConstantCallSite";
    bmv.visitTypeInsn(NEW, constCallSite);
    bmv.visitInsn(DUP);

    bmv.visitLdcInsn(h);

    bmv.visitMethodInsn(INVOKESPECIAL, constCallSite, "<init>", "(Ljava/lang/invoke/MethodHandle;)V", false);
    bmv.visitInsn(ARETURN);

    bmv.visitMaxs(0,0);
    bmv.visitEnd();

    return new Handle(H_INVOKESTATIC, ownerClassName, bootstrapName, bootstrapType.toMethodDescriptorString());
}
 
Example #8
Source File: AdviceAdapter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example #9
Source File: ASMifier.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example #10
Source File: ASMifier.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example #11
Source File: TraceMethodVisitor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(
        final String name,
        final String descriptor,
        final Handle bootstrapMethodHandle,
        final Object... bootstrapMethodArguments) {
    p.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
    super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
}
 
Example #12
Source File: RemappingMethodAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: CheckMethodAdapter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #14
Source File: AnalyzerAdapter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #15
Source File: CodeSizeEvaluator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #16
Source File: AnalyzerAdapter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: ClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo getter, final MemberInfo setter) {
    final String propertyName = getter.getName();
    // stack: Collection
    // dup of Collection instance
    mi.dup();

    // Load property name, converting to Symbol if it begins with "@@"
    loadPropertyKey(mi, propertyName);
    // setup flags
    mi.push(getter.getAttributes());
    // setup getter method handle
    mi.visitLdcInsn(new Handle(H_INVOKESTATIC, className,
            getter.getJavaName(), getter.getJavaDesc(), false));
    // setup setter method handle
    if (setter == null) {
        mi.pushNull();
    } else {
        mi.visitLdcInsn(new Handle(H_INVOKESTATIC, className,
                setter.getJavaName(), setter.getJavaDesc(), false));
    }
    // property = AccessorProperty.create(key, flags, getter, setter);
    mi.invokeStatic(ACCESSORPROPERTY_TYPE, ACCESSORPROPERTY_CREATE, ACCESSORPROPERTY_CREATE_DESC);
    // boolean Collection.add(property)
    mi.invokeInterface(COLLECTION_TYPE, COLLECTION_ADD, COLLECTION_ADD_DESC);
    // pop return value of Collection.add
    mi.pop();
    // stack: Collection
}
 
Example #18
Source File: ClassGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo memInfo) {
    final String propertyName = memInfo.getName();
    // stack: Collection
    // dup of Collection instance
    mi.dup();

    // property = AccessorProperty.create(key, flags, getter, setter);
    mi.loadLiteral(propertyName);
    // setup flags
    mi.push(memInfo.getAttributes());
    // setup getter method handle
    String javaName = GETTER_PREFIX + memInfo.getJavaName();
    mi.visitLdcInsn(new Handle(H_INVOKEVIRTUAL, className, javaName, getterDesc(memInfo)));
    // setup setter method handle
    if (memInfo.isFinal()) {
        mi.pushNull();
    } else {
        javaName = SETTER_PREFIX + memInfo.getJavaName();
        mi.visitLdcInsn(new Handle(H_INVOKEVIRTUAL, className, javaName, setterDesc(memInfo)));
    }
    mi.invokeStatic(ACCESSORPROPERTY_TYPE, ACCESSORPROPERTY_CREATE, ACCESSORPROPERTY_CREATE_DESC);
    // boolean Collection.add(property)
    mi.invokeInterface(COLLECTION_TYPE, COLLECTION_ADD, COLLECTION_ADD_DESC);
    // pop return value of Collection.add
    mi.pop();
    // stack: Collection
}
 
Example #19
Source File: ClassGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo getter, final MemberInfo setter) {
    final String propertyName = getter.getName();
    // stack: Collection
    // dup of Collection instance
    mi.dup();

    // property = AccessorProperty.create(key, flags, getter, setter);
    mi.loadLiteral(propertyName);
    // setup flags
    mi.push(getter.getAttributes());
    // setup getter method handle
    mi.visitLdcInsn(new Handle(H_INVOKESTATIC, className,
            getter.getJavaName(), getter.getJavaDesc()));
    // setup setter method handle
    if (setter == null) {
        mi.pushNull();
    } else {
        mi.visitLdcInsn(new Handle(H_INVOKESTATIC, className,
                setter.getJavaName(), setter.getJavaDesc()));
    }
    mi.invokeStatic(ACCESSORPROPERTY_TYPE, ACCESSORPROPERTY_CREATE, ACCESSORPROPERTY_CREATE_DESC);
    // boolean Collection.add(property)
    mi.invokeInterface(COLLECTION_TYPE, COLLECTION_ADD, COLLECTION_ADD_DESC);
    // pop return value of Collection.add
    mi.pop();
    // stack: Collection
}
 
Example #20
Source File: AnalyzerAdapter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #21
Source File: CheckMethodAdapter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #22
Source File: AnalyzerAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #23
Source File: AnalyzerAdapter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #24
Source File: NashornTextifier.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static void appendHandle(final StringBuilder sb, final Handle h) {
    switch (h.getTag()) {
    case Opcodes.H_GETFIELD:
        sb.append("getfield");
        break;
    case Opcodes.H_GETSTATIC:
        sb.append("getstatic");
        break;
    case Opcodes.H_PUTFIELD:
        sb.append("putfield");
        break;
    case Opcodes.H_PUTSTATIC:
        sb.append("putstatic");
        break;
    case Opcodes.H_INVOKEINTERFACE:
        sb.append("interface");
        break;
    case Opcodes.H_INVOKESPECIAL:
        sb.append("special");
        break;
    case Opcodes.H_INVOKESTATIC:
        sb.append("static");
        break;
    case Opcodes.H_INVOKEVIRTUAL:
        sb.append("virtual");
        break;
    case Opcodes.H_NEWINVOKESPECIAL:
        sb.append("new_special");
        break;
    default:
        assert false;
        break;
    }
    sb.append(" '");
    sb.append(h.getName());
    sb.append("'");
}
 
Example #25
Source File: Remapper.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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()));
    }
    return value;
}
 
Example #26
Source File: ClassGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo memInfo) {
    final String propertyName = memInfo.getName();
    // stack: Collection
    // dup of Collection instance
    mi.dup();

    // property = AccessorProperty.create(key, flags, getter, setter);
    mi.loadLiteral(propertyName);
    // setup flags
    mi.push(memInfo.getAttributes());
    // setup getter method handle
    String javaName = GETTER_PREFIX + memInfo.getJavaName();
    mi.visitLdcInsn(new Handle(H_INVOKEVIRTUAL, className, javaName, getterDesc(memInfo)));
    // setup setter method handle
    if (memInfo.isFinal()) {
        mi.pushNull();
    } else {
        javaName = SETTER_PREFIX + memInfo.getJavaName();
        mi.visitLdcInsn(new Handle(H_INVOKEVIRTUAL, className, javaName, setterDesc(memInfo)));
    }
    mi.invokeStatic(ACCESSORPROPERTY_TYPE, ACCESSORPROPERTY_CREATE, ACCESSORPROPERTY_CREATE_DESC);
    // boolean Collection.add(property)
    mi.invokeInterface(COLLECTION_TYPE, COLLECTION_ADD, COLLECTION_ADD_DESC);
    // pop return value of Collection.add
    mi.pop();
    // stack: Collection
}
 
Example #27
Source File: JavaAdapterBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void generateFinalizerOverride(final String finalizerDelegateName) {
    final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
            VOID_NOARG_METHOD_DESCRIPTOR, null, null));
    // Overridden finalizer will take a MethodHandle to the finalizer delegating method, ...
    mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, finalizerDelegateName,
            Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE)));
    mv.visitVarInsn(ALOAD, 0);
    // ...and invoke it through JavaAdapterServices.invokeNoPermissions
    mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "invokeNoPermissions",
            Type.getMethodDescriptor(METHOD_HANDLE_TYPE, OBJECT_TYPE), false);
    mv.visitInsn(RETURN);
    endMethod(mv);
}
 
Example #28
Source File: RemappingMethodAdapter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #29
Source File: NashornTextifier.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void appendHandle(final StringBuilder sb, final Handle h) {
    switch (h.getTag()) {
    case Opcodes.H_GETFIELD:
        sb.append("getfield");
        break;
    case Opcodes.H_GETSTATIC:
        sb.append("getstatic");
        break;
    case Opcodes.H_PUTFIELD:
        sb.append("putfield");
        break;
    case Opcodes.H_PUTSTATIC:
        sb.append("putstatic");
        break;
    case Opcodes.H_INVOKEINTERFACE:
        sb.append("interface");
        break;
    case Opcodes.H_INVOKESPECIAL:
        sb.append("special");
        break;
    case Opcodes.H_INVOKESTATIC:
        sb.append("static");
        break;
    case Opcodes.H_INVOKEVIRTUAL:
        sb.append("virtual");
        break;
    case Opcodes.H_NEWINVOKESPECIAL:
        sb.append("new_special");
        break;
    default:
        assert false;
        break;
    }
    sb.append(" '");
    sb.append(h.getName());
    sb.append("'");
}
 
Example #30
Source File: BootstrapMethodErrorTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private byte[] loadClassData(String name) throws Exception {
  ClassWriter cw = new ClassWriter(0);
  MethodVisitor mv;

  if (name.equals("C")) {
    cw.visit(52, ACC_SUPER | ACC_PUBLIC, "C", null, "java/lang/Object", null);
    {
      mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "m", "()V", null, null);
      mv.visitCode();
      mv.visitInsn(RETURN);
      mv.visitMaxs(0, 1);
      mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
  } else if (name.equals("Exec")) {
    cw.visit(52, ACC_SUPER | ACC_PUBLIC, "Exec", null, "java/lang/Object", null);
    {
      mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invokeRef", "()V", null, null);
      mv.visitCode();
      Handle h = new Handle(H_INVOKESTATIC, "C", "m", "()V");
      mv.visitInvokeDynamicInsn("C", "()V", h);
      mv.visitInsn(RETURN);
      mv.visitMaxs(0, 0);
      mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
  }
  return null;
}