List of usage examples for org.objectweb.asm Handle isInterface
boolean isInterface
To view the source code for org.objectweb.asm Handle isInterface.
Click Source Link
From source file:com.geeksaga.light.profiler.util.ConstantPoolWrapper.java
License:Apache License
public Constant newConst(final Object cst, boolean isExtend) { if (cst instanceof Integer) { int val = (Integer) cst; return newInteger(val, isExtend); } else if (cst instanceof Float) { float val = (Float) cst; return newFloat(val, isExtend); } else if (cst instanceof Long) { long val = (Long) cst; return newLong(val, isExtend); } else if (cst instanceof Double) { double val = (Double) cst; return newDouble(val, isExtend); } else if (cst instanceof String) { return newString((String) cst); } else if (cst instanceof Type) { Type t = (Type) cst; int s = t.getSort(); if (s == Type.OBJECT) { return newClass(t.getInternalName(), isExtend); } else if (s == Type.METHOD) { return newMethodType(t.getDescriptor(), isExtend); } else {//from w w w. jav a 2 s. c om return newClass(t.getDescriptor(), isExtend); } } else if (cst instanceof Handle) { Handle h = (Handle) cst; return newHandle(h.getTag(), h.getOwner(), h.getName(), h.getDesc(), h.isInterface(), isExtend); } else { throw new IllegalArgumentException("value " + cst); } }
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(// w w w . java2s .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 v a 2 s .c o 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:cuchaz.enigma.mapping.Translator.java
License:Open Source License
default Handle getTranslatedHandle(Handle handle) { MethodEntry entry = new MethodEntry(new ClassEntry(handle.getOwner()), handle.getName(), new MethodDescriptor(handle.getDesc())); MethodEntry translatedMethod = getTranslatedMethod(entry); ClassEntry ownerClass = translatedMethod.getOwnerClassEntry(); return new Handle(handle.getTag(), ownerClass.getName(), translatedMethod.getName(), translatedMethod.getDesc().toString(), handle.isInterface()); }
From source file:org.jacoco.core.internal.instr.CondyProbeArrayStrategyTest.java
License:Open Source License
@Test public void should_store_instance_using_condy_and_checkcast() { final MethodNode m = new MethodNode(); final int maxStack = strategy.storeInstance(m, false, 1); assertEquals(1, maxStack);// w w w . j a va 2 s . com final ConstantDynamic constantDynamic = (ConstantDynamic) ((LdcInsnNode) m.instructions.get(0)).cst; assertEquals("$jacocoData", constantDynamic.getName()); assertEquals("Ljava/lang/Object;", constantDynamic.getDescriptor()); final Handle bootstrapMethod = constantDynamic.getBootstrapMethod(); assertEquals(Opcodes.H_INVOKESTATIC, bootstrapMethod.getTag()); assertEquals("ClassName", bootstrapMethod.getOwner()); assertEquals("$jacocoInit", bootstrapMethod.getName()); assertEquals("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)[Z", bootstrapMethod.getDesc()); assertTrue(bootstrapMethod.isInterface()); final TypeInsnNode castInstruction = (TypeInsnNode) m.instructions.get(1); assertEquals(Opcodes.CHECKCAST, castInstruction.getOpcode()); assertEquals("[Z", castInstruction.desc); final VarInsnNode storeInstruction = (VarInsnNode) m.instructions.get(2); assertEquals(Opcodes.ASTORE, storeInstruction.getOpcode()); assertEquals(1, storeInstruction.var); assertEquals(3, m.instructions.size()); }