本文整理汇总了Java中jdk.internal.org.objectweb.asm.MethodVisitor.visitLdcInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitLdcInsn方法的具体用法?Java MethodVisitor.visitLdcInsn怎么用?Java MethodVisitor.visitLdcInsn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.internal.org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitLdcInsn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ldc
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type ldc(final MethodVisitor method, final Object c) {
if (c == null) {
method.visitInsn(ACONST_NULL);
} else if (c instanceof Undefined) {
return loadUndefined(method);
} else if (c instanceof String) {
method.visitLdcInsn(c);
return STRING;
} else if (c instanceof Handle) {
method.visitLdcInsn(c);
return Type.typeFor(MethodHandle.class);
} else {
throw new UnsupportedOperationException("implementation missing for class " + c.getClass() + " value=" + c);
}
return Type.OBJECT;
}
示例2: generateBootstrapMethod
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
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());
}
示例3: getClassFile
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Generates a class of the following shape:
* static class T {
* @DontInline public static int f() { return $r; }
* }
*/
static byte[] getClassFile(int r) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
MethodVisitor mv;
cw.visit(52, ACC_PUBLIC | ACC_SUPER, NAME, null, "java/lang/Object", null);
{
mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f", "()I", null, null);
mv.visitAnnotation("Ljdk/internal/vm/annotation/DontInline;", true);
mv.visitCode();
mv.visitLdcInsn(r);
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例4: loadClassData
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private byte[] loadClassData(String name) throws Exception {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
switch (name) {
case INTERFACE_NAME:
cw.visit(V1_8, ACC_ABSTRACT | ACC_INTERFACE | ACC_PUBLIC, INTERFACE_NAME, null, "java/lang/Object", null);
{
mv = cw.visitMethod(ACC_PRIVATE, "privInstance", "()I", null, null);
mv.visitCode();
mv.visitLdcInsn(EXPECTED);
mv.visitInsn(IRETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
break;
case CLASS_NAME:
cw.visit(52, ACC_SUPER | ACC_PUBLIC, CLASS_NAME, null, "java/lang/Object", new String[]{INTERFACE_NAME});
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
break;
default:
break;
}
cw.visitEnd();
return cw.toByteArray();
}
示例5: dumpT1
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpT1() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(52, ACC_PUBLIC | ACC_SUPER, "p1/T1", null, "java/lang/Object", null);
{
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_PUBLIC, "m", "()I", null, null);
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("p1/T1.m()");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false);
mv.visitIntInsn(BIPUSH, 3);
mv.visitInsn(IRETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例6: createThrowRuntimeExceptionCode
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createThrowRuntimeExceptionCode(MethodVisitor mv, String msg) {
mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
mv.visitInsn(DUP);
mv.visitLdcInsn(msg);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V");
mv.visitInsn(ATHROW);
}
示例7: initField
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
void initField(MethodVisitor mv) {
if (hasDefaultValue) {
return; // Nothing to do
}
if (!isStatic()) {
mv.visitVarInsn(ALOAD, 0);
}
mv.visitLdcInsn(type.value);
mv.visitFieldInsn((isStatic() ? PUTSTATIC : PUTFIELD), className, FIELD_NAME, fieldDesc);
}
示例8: dumpP1B
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpP1B() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "P1/B", null, "P1/A", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "P1/A", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(0, "m", "()I", null, null);
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("B.m");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
mv.visitIntInsn(BIPUSH, 2);
mv.visitInsn(IRETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例9: accept
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
mv.visitLdcInsn(cst);
acceptAnnotations(mv);
}
示例10: loadUndefined
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type loadUndefined(final MethodVisitor method) {
method.visitLdcInsn(UNDEFINED_INT);
return INT;
}
示例11: loadUndefined
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type loadUndefined(final MethodVisitor method) {
method.visitLdcInsn(UNDEFINED_INT);
return BOOLEAN;
}
示例12: dumpP2C
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpP2C() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "P2/C", null, "P1/B", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "P1/B", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "m", "()I", null, null);
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("P2/C.m");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
mv.visitIntInsn(BIPUSH, 3);
mv.visitInsn(IRETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "()I", null, null);
mv.visitCode();
mv.visitTypeInsn(NEW, "P2/C");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "P2/C", "<init>", "()V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "P1/A", "m", "()I", false);
mv.visitInsn(IRETURN);
mv.visitMaxs(3, 2);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例13: ClassWriter
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Returns the bytes for a class with name d_name (presumably "D" in some
* package), extending some class with name sub_what, implementing p.I,
* and defining two methods m() and m(11args) with access method_acc.
*
* @param d_name Name of class that is defined
* @param sub_what Name of class that it extends
* @param method_acc Accessibility of method(s) m in defined class.
* @return
* @throws Exception
*/
public static byte[] bytesForSomeDsubSomethingSomeAccess
(String d_name, String sub_what, int method_acc)
throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES
| ClassWriter.COMPUTE_MAXS);
MethodVisitor mv;
String[] interfaces = {"p/I"};
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, d_name, null, sub_what, interfaces);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, sub_what, "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
// int m() {return 3;}
{
mv = cw.visitMethod(method_acc, "m", "()I", null, null);
mv.visitCode();
mv.visitLdcInsn(new Integer(3));
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
// int m(11args) {return 3;}
{
mv = cw.visitMethod(method_acc, "m", "(BCSIJ"
+ "Ljava/lang/Object;"
+ "Ljava/lang/Object;"
+ "Ljava/lang/Object;"
+ "Ljava/lang/Object;"
+ "Ljava/lang/Object;"
+ "Ljava/lang/Object;"
+ ")I", null, null);
mv.visitCode();
mv.visitLdcInsn(new Integer(3));
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例14: bytesForT
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* The bytecodes for a class p/T defining a methods test() and test(11args)
* that contain an invokeExact of a particular methodHandle, I.m.
*
* Test will be passed values that may imperfectly implement I,
* and thus may in turn throw exceptions.
*
* @return
* @throws Exception
*/
public static byte[] bytesForT() throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES
| ClassWriter.COMPUTE_MAXS);
MethodVisitor mv;
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "p/T", null, "java/lang/Object", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
// static int test(I)
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;)I", null, null);
mv.visitCode();
mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "()I"));
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle",
"invokeExact", "(Lp/I;)I");
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
// static int test(I,11args)
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I", null, null);
mv.visitCode();
mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "(BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I"));
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ILOAD, 1);
mv.visitVarInsn(ILOAD, 2);
mv.visitVarInsn(ILOAD, 3);
mv.visitVarInsn(ILOAD, 4);
mv.visitVarInsn(LLOAD, 5);
mv.visitVarInsn(ALOAD, 7);
mv.visitVarInsn(ALOAD, 8);
mv.visitVarInsn(ALOAD, 9);
mv.visitVarInsn(ALOAD, 10);
mv.visitVarInsn(ALOAD, 11);
mv.visitVarInsn(ALOAD, 12);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle",
"invokeExact", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I");
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例15: getField
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
void getField(MethodVisitor mv) {
mv.visitLdcInsn(Type.getType(classDesc));
mv.visitLdcInsn(FIELD_NAME);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;", false);
}