List of usage examples for org.objectweb.asm Opcodes H_INVOKESTATIC
int H_INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes H_INVOKESTATIC.
Click Source Link
From source file:com.devexperts.usages.ClassUsagesAnalyzer.java
License:Open Source License
private void markHandleUse(Handle handle, Member usedFrom, UseKind useKind) { markTypeUse(Type.getType(handle.getDesc()), usedFrom, useKind); String className = Type.getType(handle.getOwner()).getClassName(); switch (handle.getTag()) { case Opcodes.H_GETFIELD: case Opcodes.H_GETSTATIC: case Opcodes.H_PUTFIELD: case Opcodes.H_PUTSTATIC: markMemberUse(className, handle.getName(), usedFrom, useKind); break;//from ww w. java2s .c o m case Opcodes.H_INVOKEVIRTUAL: case Opcodes.H_INVOKESTATIC: case Opcodes.H_INVOKESPECIAL: case Opcodes.H_NEWINVOKESPECIAL: case Opcodes.H_INVOKEINTERFACE: markMemberUse(className, Member.methodMemberName(handle.getName(), Type.getType(handle.getDesc())), usedFrom, useKind); } }
From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java
License:Open Source License
private static void appendHandle(final StringBuilder sb, final Handle h) { switch (h.getTag()) { case Opcodes.H_GETFIELD: sb.append("getfield"); break;// w w w .j av a 2s . c o m 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("'"); }
From source file:com.gargoylesoftware.js.nashorn.internal.runtime.linker.JavaAdapterBytecodeGenerator.java
License:Open Source License
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);// w ww . j av a 2 s . co m // ...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); }
From source file:com.github.anba.es6draft.compiler.assembler.Handle.java
License:Open Source License
private static int toTag(MethodName method) { switch (method.invoke) { case Interface: return Opcodes.H_INVOKEINTERFACE; case Special: case SpecialInterface: return Opcodes.H_INVOKESPECIAL; case Static:// w w w.j av a 2 s .c o m case StaticInterface: return Opcodes.H_INVOKESTATIC; case Virtual: case VirtualInterface: return Opcodes.H_INVOKEVIRTUAL; default: throw new AssertionError(); } }
From source file:com.github.wolf480pl.mias4j.java8.rewrite.AbstractDynamicRewritePolicy.java
License:Open Source License
@Override public Handle interceptDynamic(Type caller, String name, Type desc, Handle bootstrapMethod, Object[] bootstrapArgs, List<Object> newBootstrapArgs) throws RewriteAbortException { InvocationType invType = InvocationType.fromHandleOpcode(bootstrapMethod.getTag()); Type bsmOwner = Type.getObjectType(bootstrapMethod.getOwner()); Type bsmType = Type.getMethodType(bootstrapMethod.getDesc()); boolean should = shouldIntercept(caller, invType, bsmOwner, bootstrapMethod.getName(), bsmType); if (!should) { return null; }//from www. jav a 2 s. c o m newBootstrapArgs.add(invType.id()); newBootstrapArgs.add(bsmOwner.getClassName()); newBootstrapArgs.add(bootstrapMethod.getName()); newBootstrapArgs.add(bsmType); // NOTE: Varags collection for bootstrap methods works only since Java 8 newBootstrapArgs.addAll(Arrays.asList(bootstrapArgs)); return new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(Bootstraps.class), WRAPDYNAMIC_NAME, WRAPDYNAMIC_DESC); }
From source file:com.google.devtools.build.android.desugar.Bug62060793TestDataGenerator.java
License:Open Source License
private static byte[] createClass() { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); MethodVisitor mv;/* w w w.jav a2s . co m*/ cw.visit(V1_8, ACC_PUBLIC | ACC_SUPER, CLASS_NAME, null, "java/lang/Object", null); cw.visitInnerClass(INTERFACE_TYPE_NAME, CLASS_NAME, "Interface", ACC_PUBLIC | ACC_STATIC | ACC_ABSTRACT | ACC_INTERFACE); cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup", ACC_PUBLIC | ACC_FINAL | ACC_STATIC); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "method", "(Ljava/lang/String;)Ljava/lang/String;", null, null); mv.visitParameter("str", 0); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ARETURN); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "method", "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", null, null); mv.visitParameter("bool", 0); mv.visitParameter("c", 0); mv.visitParameter("b", 0); mv.visitParameter("f", 0); mv.visitParameter("d", 0); mv.visitParameter("l", 0); mv.visitParameter("i", 0); mv.visitParameter("s", 0); mv.visitParameter("o", 0); mv.visitParameter("array", 0); mv.visitParameter("str", 0); mv.visitCode(); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false); mv.visitVarInsn(ASTORE, 13); mv.visitVarInsn(ALOAD, 11); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitInsn(ICONST_1); Label l1 = new Label(); mv.visitJumpInsn(GOTO, l1); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/String" }, 0, null); mv.visitInsn(ICONST_0); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER }); mv.visitVarInsn(ISTORE, 14); mv.visitIntInsn(BIPUSH, 91); mv.visitVarInsn(ALOAD, 12); mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false); mv.visitInsn(IADD); mv.visitVarInsn(ALOAD, 13); mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false); mv.visitInsn(IADD); mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); mv.visitInsn(DUP_X1); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(I)V", false); mv.visitVarInsn(ALOAD, 12); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(FLOAD, 3); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(F)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(DLOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(D)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(LLOAD, 6); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(J)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 8); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 9); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ALOAD, 13); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 14); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitInsn(ARETURN); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "lambdaWithConstantArguments", "()L" + INTERFACE_TYPE_NAME + ";", null, null); mv.visitCode(); mv.visitInsn(ICONST_0); mv.visitInsn(ICONST_1); mv.visitInsn(ICONST_2); mv.visitInsn(FCONST_0); mv.visitInsn(DCONST_0); mv.visitInsn(LCONST_0); mv.visitInsn(ICONST_4); mv.visitIntInsn(SIPUSH, 9); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); mv.visitInvokeDynamicInsn("call", "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;)L" + INTERFACE_TYPE_NAME + ";", new Handle(Opcodes.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), new Object[] { Type.getType("(Ljava/lang/String;)Ljava/lang/String;"), new Handle(Opcodes.H_INVOKESTATIC, CLASS_NAME, "method", "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;Ljava/lang/String;" + ")Ljava/lang/String;", false), Type.getType("(Ljava/lang/String;)Ljava/lang/String;") }); mv.visitInsn(ARETURN); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:com.google.devtools.build.android.desugar.LambdaDesugaring.java
License:Open Source License
@Override public void visitEnd() { for (Map.Entry<Handle, MethodReferenceBridgeInfo> bridge : bridgeMethods.entrySet()) { Handle original = bridge.getKey(); Handle neededMethod = bridge.getValue().bridgeMethod(); checkState(// ww w . ja v a 2 s. c om neededMethod.getTag() == Opcodes.H_INVOKESTATIC || neededMethod.getTag() == Opcodes.H_INVOKEVIRTUAL, "Cannot generate bridge method %s to reach %s", neededMethod, original); checkState(bridge.getValue().referenced() != null, "Need referenced method %s to generate bridge %s", original, neededMethod); int access = Opcodes.ACC_BRIDGE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL; if (neededMethod.getTag() == Opcodes.H_INVOKESTATIC) { access |= Opcodes.ACC_STATIC; } MethodVisitor bridgeMethod = super.visitMethod(access, neededMethod.getName(), neededMethod.getDesc(), (String) null, toInternalNames(bridge.getValue().referenced().getExceptionTypes())); // Bridge is a factory method calling a constructor if (original.getTag() == Opcodes.H_NEWINVOKESPECIAL) { bridgeMethod.visitTypeInsn(Opcodes.NEW, original.getOwner()); bridgeMethod.visitInsn(Opcodes.DUP); } int slot = 0; if (neededMethod.getTag() != Opcodes.H_INVOKESTATIC) { bridgeMethod.visitVarInsn(Opcodes.ALOAD, slot++); } Type neededType = Type.getMethodType(neededMethod.getDesc()); for (Type arg : neededType.getArgumentTypes()) { bridgeMethod.visitVarInsn(arg.getOpcode(Opcodes.ILOAD), slot); slot += arg.getSize(); } bridgeMethod.visitMethodInsn(invokeOpcode(original), original.getOwner(), original.getName(), original.getDesc(), original.isInterface()); bridgeMethod.visitInsn(neededType.getReturnType().getOpcode(Opcodes.IRETURN)); bridgeMethod.visitMaxs(0, 0); // rely on class writer to compute these bridgeMethod.visitEnd(); } super.visitEnd(); }
From source file:com.google.devtools.build.android.desugar.LambdaDesugaring.java
License:Open Source License
/** * Makes {@link #visitEnd} generate a bridge method for the given method handle if the * referenced method will be invisible to the generated lambda class. * * @return struct containing either {@code invokedMethod} or {@code invokedMethod} and a handle * representing the bridge method that will be generated for {@code invokedMethod}. *//*from w w w. j a va 2 s . co m*/ private MethodReferenceBridgeInfo queueUpBridgeMethodIfNeeded(Handle invokedMethod) throws ClassNotFoundException { if (invokedMethod.getName().startsWith("lambda$")) { // We adjust lambda bodies to be visible return MethodReferenceBridgeInfo.noBridge(invokedMethod); } // invokedMethod is a method reference if we get here Executable invoked = findTargetMethod(invokedMethod); if (isVisibleToLambdaClass(invoked, invokedMethod.getOwner())) { // Referenced method is visible to the generated class, so nothing to do return MethodReferenceBridgeInfo.noBridge(invokedMethod); } // We need a bridge method if we get here checkState(!isInterface, "%s is an interface and shouldn't need bridge to %s", internalName, invokedMethod); checkState(!invokedMethod.isInterface(), "%s's lambda classes can't see interface method: %s", internalName, invokedMethod); MethodReferenceBridgeInfo result = bridgeMethods.get(invokedMethod); if (result != null) { return result; // we're already queued up a bridge method for this method reference } String name = uniqueInPackage(internalName, "bridge$lambda$" + bridgeMethods.size()); Handle bridgeMethod; switch (invokedMethod.getTag()) { case Opcodes.H_INVOKESTATIC: bridgeMethod = new Handle(invokedMethod.getTag(), internalName, name, invokedMethod.getDesc(), /*itf*/ false); break; case Opcodes.H_INVOKEVIRTUAL: case Opcodes.H_INVOKESPECIAL: // we end up calling these using invokevirtual bridgeMethod = new Handle(Opcodes.H_INVOKEVIRTUAL, internalName, name, invokedMethod.getDesc(), /*itf*/ false); break; case Opcodes.H_NEWINVOKESPECIAL: { // Call invisible constructor through generated bridge "factory" method, so we need to // compute the descriptor for the bridge method from the constructor's descriptor String desc = Type.getMethodDescriptor(Type.getObjectType(invokedMethod.getOwner()), Type.getArgumentTypes(invokedMethod.getDesc())); bridgeMethod = new Handle(Opcodes.H_INVOKESTATIC, internalName, name, desc, /*itf*/ false); break; } case Opcodes.H_INVOKEINTERFACE: // Shouldn't get here default: throw new UnsupportedOperationException("Cannot bridge " + invokedMethod); } result = MethodReferenceBridgeInfo.bridge(invokedMethod, invoked, bridgeMethod); MethodReferenceBridgeInfo old = bridgeMethods.put(invokedMethod, result); checkState(old == null, "Already had bridge %s so we don't also want %s", old, result); return result; }
From source file:com.google.devtools.build.android.desugar.LambdaDesugaring.java
License:Open Source License
static int invokeOpcode(Handle invokedMethod) { switch (invokedMethod.getTag()) { case Opcodes.H_INVOKESTATIC: return Opcodes.INVOKESTATIC; case Opcodes.H_INVOKEVIRTUAL: return Opcodes.INVOKEVIRTUAL; case Opcodes.H_INVOKESPECIAL: case Opcodes.H_NEWINVOKESPECIAL: // Must be preceded by NEW return Opcodes.INVOKESPECIAL; case Opcodes.H_INVOKEINTERFACE: return Opcodes.INVOKEINTERFACE; default:/*from ww w . jav a 2 s . co m*/ throw new UnsupportedOperationException("Don't know how to call " + invokedMethod); } }
From source file:com.heliosdecompiler.appifier.SystemHookDump.java
License:Apache License
public static byte[] dump() { ClassWriter cw = new ClassWriter(0); FieldVisitor fv;/* w w w . j a v a 2 s. c o m*/ MethodVisitor mv; AnnotationVisitor av0; cw.visit(52, ACC_PUBLIC + ACC_SUPER, "com/heliosdecompiler/appifier/SystemHook", null, "java/lang/Object", null); cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup", ACC_PUBLIC + ACC_FINAL + ACC_STATIC); { fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, "out", "Ljava/lang/ThreadLocal;", "Ljava/lang/ThreadLocal<Ljava/io/PrintStream;>;", null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, "err", "Ljava/lang/ThreadLocal;", "Ljava/lang/ThreadLocal<Ljava/io/PrintStream;>;", null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "lambda$static$1", "()Ljava/io/PrintStream;", null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); mv.visitInsn(ARETURN); mv.visitMaxs(1, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "lambda$static$0", "()Ljava/io/PrintStream;", null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitInsn(ARETURN); mv.visitMaxs(1, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); mv.visitInvokeDynamicInsn("get", "()Ljava/util/function/Supplier;", new Handle(Opcodes.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;"), new Object[] { Type.getType("()Ljava/lang/Object;"), new Handle(Opcodes.H_INVOKESTATIC, "com/heliosdecompiler/appifier/SystemHook", "lambda$static$0", "()Ljava/io/PrintStream;"), Type.getType("()Ljava/io/PrintStream;") }); mv.visitMethodInsn(INVOKESTATIC, "java/lang/ThreadLocal", "withInitial", "(Ljava/util/function/Supplier;)Ljava/lang/ThreadLocal;", false); mv.visitFieldInsn(PUTSTATIC, "com/heliosdecompiler/appifier/SystemHook", "out", "Ljava/lang/ThreadLocal;"); mv.visitInvokeDynamicInsn("get", "()Ljava/util/function/Supplier;", new Handle(Opcodes.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;"), new Object[] { Type.getType("()Ljava/lang/Object;"), new Handle(Opcodes.H_INVOKESTATIC, "com/heliosdecompiler/appifier/SystemHook", "lambda$static$1", "()Ljava/io/PrintStream;"), Type.getType("()Ljava/io/PrintStream;") }); mv.visitMethodInsn(INVOKESTATIC, "java/lang/ThreadLocal", "withInitial", "(Ljava/util/function/Supplier;)Ljava/lang/ThreadLocal;", false); mv.visitFieldInsn(PUTSTATIC, "com/heliosdecompiler/appifier/SystemHook", "err", "Ljava/lang/ThreadLocal;"); mv.visitInsn(RETURN); mv.visitMaxs(1, 0); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }