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:org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.BytecodeGenerator.java
License:Open Source License
/********************************************************************************************************************/ Handle bootstrapRascalPrimitive() {//w ww.jav a 2 s . c o m MethodType bmt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class); Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, (RascalPrimitive.class.getName()).replace('.', '/'), "bootstrapRascalPrimitive", bmt.toMethodDescriptorString()); return bootstrap; }
From source file:org.springsource.loaded.support.Java8.java
License:Apache License
public static CallSite callLambdaMetaFactory(Object[] bsmArgs, Object lookup, String indyNameAndDescriptor, Class<?> executorClass) throws Exception { MethodHandles.Lookup caller = (MethodHandles.Lookup) lookup; ClassLoader callerLoader = caller.lookupClass().getClassLoader(); int descriptorStart = indyNameAndDescriptor.indexOf('('); String invokedName = indyNameAndDescriptor.substring(0, descriptorStart); MethodType invokedType = MethodType .fromMethodDescriptorString(indyNameAndDescriptor.substring(descriptorStart), callerLoader); // Use bsmArgs to build the parameters MethodType samMethodType = MethodType.fromMethodDescriptorString((((Type) bsmArgs[0]).getDescriptor()), callerLoader);//from w ww.j a v a 2 s . c o m String execClassName = executorClass.getName(); Handle bsmArgsHandle = (Handle) bsmArgs[1]; Class<?> lookupClass = caller.lookupClass(); String owner = bsmArgsHandle.getOwner(); if (!execClassName.startsWith(owner.replace('/', '.')) && bsmArgsHandle.getTag() != Opcodes.H_INVOKEINTERFACE) { executorClass = null; lookupClass = Class.forName(owner.replace('/', '.')); } String name = bsmArgsHandle.getName(); String descriptor = bsmArgsHandle.getDesc(); MethodType implMethodType = MethodType.fromMethodDescriptorString(descriptor, callerLoader); // Looking up the lambda$run method in the caller class (note the caller class is the executor, which gets us around the // problem of having to hack into LambdaMetafactory to intercept reflection) MethodHandle implMethod = null; switch (bsmArgsHandle.getTag()) { case Opcodes.H_INVOKESTATIC: implMethod = caller.in(lookupClass).findStatic(lookupClass, name, implMethodType); break; case Opcodes.H_INVOKESPECIAL: // If there is an executor, the lambda function is actually modified from 'private instance' to 'public static' so adjust lookup. The method // will be static with a new leading parameter. if (executorClass == null) { // TODO is final parameter here correct? implMethod = caller.in(lookupClass).findSpecial(lookupClass, name, implMethodType, caller.lookupClass()); } else { implMethod = caller.in(lookupClass).findStatic(lookupClass, name, MethodType .fromMethodDescriptorString("(L" + owner + ";" + descriptor.substring(1), callerLoader)); } break; case Opcodes.H_INVOKEVIRTUAL: // If there is an executor, the lambda function is actually modified from 'private instance' to 'public static' so adjust lookup. The method // will be static with a new leading parameter. if (executorClass == null) { // TODO when can this scenario occur? Aren't we only here if reloading has happened? implMethod = caller.in(lookupClass).findVirtual(lookupClass, name, implMethodType); } else { implMethod = caller.in(lookupClass).findStatic(lookupClass, name, MethodType .fromMethodDescriptorString("(L" + owner + ";" + descriptor.substring(1), callerLoader)); } break; case Opcodes.H_INVOKEINTERFACE: Class<?> targetType = Class.forName(bsmArgsHandle.getOwner().replace('/', '.'), true, callerLoader); for (Method m : targetType.getMethods()) { if (org.objectweb.asm.Type.getMethodDescriptor(m).equals(bsmArgsHandle.getDesc())) { implMethod = caller.unreflect(targetType.getMethod(name, m.getParameterTypes())); break; } } break; default: throw new IllegalStateException("nyi " + bsmArgsHandle.getTag()); } MethodType instantiatedMethodType = MethodType .fromMethodDescriptorString((((Type) bsmArgs[2]).getDescriptor()), callerLoader); return LambdaMetafactory.metafactory(caller, invokedName, invokedType, samMethodType, implMethod, instantiatedMethodType); }
From source file:org.teavm.parsing.ProgramParser.java
License:Apache License
private static MethodHandle parseHandle(Handle handle) { switch (handle.getTag()) { case Opcodes.H_GETFIELD: return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_GETSTATIC: return MethodHandle.staticFieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_PUTFIELD: return MethodHandle.fieldSetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_PUTSTATIC: return MethodHandle.staticFieldSetter(handle.getOwner().replace('/', '.'), handle.getName(), ValueType.parse(handle.getDesc())); case Opcodes.H_INVOKEVIRTUAL: return MethodHandle.virtualCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_INVOKESTATIC: return MethodHandle.staticCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_INVOKESPECIAL: return MethodHandle.specialCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_NEWINVOKESPECIAL: return MethodHandle.constructorCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); case Opcodes.H_INVOKEINTERFACE: return MethodHandle.interfaceCaller(handle.getOwner().replace('/', '.'), handle.getName(), MethodDescriptor.parseSignature(handle.getDesc())); default:// w ww . j av a 2 s . c om throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag()); } }
From source file:serianalyzer.SerianalyzerMethodVisitor.java
License:Open Source License
/** * {@inheritDoc}// www . j av a2s . c o m * * @see org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn(java.lang.String, java.lang.String, * org.objectweb.asm.Handle, java.lang.Object[]) */ @Override public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { if (bsm.getTag() == Opcodes.H_INVOKESTATIC && (bsm.getName().equals("metafactory") || //$NON-NLS-1$ bsm.getName().equals("altMetafactory")) //$NON-NLS-1$ && bsm.getOwner().equals("java/lang/invoke/LambdaMetafactory") && bsmArgs.length >= 2) { //$NON-NLS-1$ Handle h = (Handle) bsmArgs[1]; Type[] handleArgs = Type.getArgumentTypes(h.getDesc()); Type[] formalArgs = Type.getArgumentTypes(desc); List<BaseType> args = this.stack.pop(formalArgs.length); boolean tainted = checkTainted(formalArgs, args); String className = Type.getObjectType(h.getOwner()).getClassName(); boolean isStatic = h.getTag() == Opcodes.H_INVOKESTATIC; MethodReference r = new MethodReference(className, false, h.getName(), isStatic, h.getDesc()); this.foundRefs.add(r); if (tainted) { if (!Arrays.equals(handleArgs, formalArgs)) { if (this.log.isDebugEnabled()) { this.log.debug("Mismatch between formal args and handle args in " + this.ref + " " + name); //$NON-NLS-1$ //$NON-NLS-2$ this.log.debug("Handle arguments are " + Arrays.toString(handleArgs)); //$NON-NLS-1$ this.log.debug("Formal arguments are " + Arrays.toString(formalArgs)); //$NON-NLS-1$ this.log.debug("BSM arguments are " + Arrays.toString(bsmArgs)); //$NON-NLS-1$ } this.parent.getAnalyzer().getState().getBench().unhandledLambda(); r.setArgumentTypes( setupTainting(r, Opcodes.INVOKEDYNAMIC, Collections.EMPTY_LIST, null, r, handleArgs)); } else { r.setArgumentTypes(setupTainting(r, Opcodes.INVOKEDYNAMIC, args, null, r, handleArgs)); } this.parent.getAnalyzer().getState().getBench().taintedCall(); if (this.log.isDebugEnabled()) { this.log.debug(String.format("In %s need to check lambda %s %s::%s %s (%s): %s", //$NON-NLS-1$ this.ref, bsm.getTag(), bsm.getOwner(), bsm.getName(), desc, bsm.getDesc(), Arrays.toString(bsmArgs))); this.log.debug(String.format("In %s need to check lambda %s::%s (%s)", this.ref, h.getOwner(), //$NON-NLS-1$ h.getName(), h.getDesc())); this.log.debug("Arguments " + args); //$NON-NLS-1$ } boolean unsafeCall = this.parent.getAnalyzer().checkMethodCall(r, Collections.singleton(this.ref), true, false); if (!unsafeCall) { this.log.debug("Call is safe"); //$NON-NLS-1$ } this.foundCall = true; } else { this.parent.getAnalyzer().getState().traceCalls(r, Collections.singleton(this.ref)); this.parent.getAnalyzer().getState().getBench().untaintedCall(); } Type returnType = Type.getReturnType(desc); if (returnType != Type.VOID_TYPE) { this.stack.push(new BasicVariable(returnType, "return " + r, tainted)); //$NON-NLS-1$ } } else { this.log.warn("Unsupported dynamic call in " + this.ref); //$NON-NLS-1$ this.log.warn(String.format("In %s need to check lambda %s %s::%s %s (%s): %s", //$NON-NLS-1$ this.ref, bsm.getTag(), bsm.getOwner(), bsm.getName(), desc, bsm.getDesc(), Arrays.toString(bsmArgs))); } super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); }
From source file:soot.jimple.internal.JDynamicInvokeExpr.java
License:Open Source License
public JDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List<? extends Value> bootstrapArgs, SootMethodRef methodRef, List<? extends Value> methodArgs) { /*//from ww w. j a va 2 s. c o m * Here the static-handle is chosen as default value, because this works for Java. */ this(bootstrapMethodRef, bootstrapArgs, methodRef, Opcodes.H_INVOKESTATIC, methodArgs); }
From source file:st.redline.compiler.ByteCodeEmitter.java
License:Open Source License
private void emitResolveMethodOrBlock(String type, TerminalNode node, EmitterNode emitterNode) { String blockName = makeBlockName(emitterNode.index()); visitLine(mv, node.getSymbol().getLine()); mv.visitTypeInsn(NEW, type);/*from w w w . j a va 2 s . c o m*/ mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, type, "<init>", "()V", false); mv.visitInvokeDynamicInsn("apply", "()Lst/redline/kernel/TriFunction;", 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;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"), new Handle(Opcodes.H_INVOKESTATIC, source.fullClassName(), blockName, "(Lst/redline/kernel/PrimObject;Lst/redline/kernel/PrimObject;Lst/redline/kernel/PrimContext;)Lst/redline/kernel/PrimObject;"), Type.getType( "(Lst/redline/kernel/PrimObject;Lst/redline/kernel/PrimObject;Lst/redline/kernel/PrimContext;)Lst/redline/kernel/PrimObject;") }); mv.visitMethodInsn(INVOKEVIRTUAL, type, "function", "(Lst/redline/kernel/TriFunction;)Lst/redline/kernel/PrimObject;", false); }
From source file:st.redline.compiler.SmalltalkGeneratingVisitor.java
License:Open Source License
private void pushNewLambda(MethodVisitor mv, String className, String name, String sig, int line) { visitLine(mv, line);/*from w w w . j a v a 2 s .c om*/ pushReceiver(mv); mv.visitInvokeDynamicInsn("apply", "()Lst/redline/core/LambdaBlock;", 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(sig), new Handle(Opcodes.H_INVOKESTATIC, className, name, sig), Type.getType(sig) }); }