本文整理汇总了Java中org.objectweb.asm.Handle类的典型用法代码示例。如果您正苦于以下问题:Java Handle类的具体用法?Java Handle怎么用?Java Handle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Handle类属于org.objectweb.asm包,在下文中一共展示了Handle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitInvokeDynamicInsn
import org.objectweb.asm.Handle; //导入依赖的package包/类
@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);
}
}
}
}
示例2: visitInvokeDynamicInsn
import org.objectweb.asm.Handle; //导入依赖的package包/类
@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());
}
示例3: visitInvokeDynamicInsn
import org.objectweb.asm.Handle; //导入依赖的package包/类
@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;
}
示例4: build
import org.objectweb.asm.Handle; //导入依赖的package包/类
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));
}
示例5: decodeHandle
import org.objectweb.asm.Handle; //导入依赖的package包/类
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);
}
}
示例6: newInvokeDynamic
import org.objectweb.asm.Handle; //导入依赖的package包/类
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;
}
示例7: generateMethodTest2
import org.objectweb.asm.Handle; //导入依赖的package包/类
/**
* 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);
}
示例8: generateMethodTest4
import org.objectweb.asm.Handle; //导入依赖的package包/类
/**
* 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);
}
示例9: generateMethodTest5
import org.objectweb.asm.Handle; //导入依赖的package包/类
/**
* 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);
}
示例10: generateMethodTest6
import org.objectweb.asm.Handle; //导入依赖的package包/类
/**
* 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);
}
示例11: generateMethodTest7
import org.objectweb.asm.Handle; //导入依赖的package包/类
/**
* 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);
}
示例12: generateMethodTest12
import org.objectweb.asm.Handle; //导入依赖的package包/类
/**
* 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);
}
示例13: isCallToInterface
import org.objectweb.asm.Handle; //导入依赖的package包/类
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();*/
}
示例14: visitInvokeDynamicInsn
import org.objectweb.asm.Handle; //导入依赖的package包/类
@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);
}
示例15: visitInvokeDynamicInsn
import org.objectweb.asm.Handle; //导入依赖的package包/类
@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);
}