本文整理汇总了Java中jdk.internal.org.objectweb.asm.MethodVisitor.visitFieldInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitFieldInsn方法的具体用法?Java MethodVisitor.visitFieldInsn怎么用?Java MethodVisitor.visitFieldInsn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.internal.org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitFieldInsn方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitPushFields
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void emitPushFields(String types, String className, MethodVisitor mv) {
for (int i = 0; i < types.length(); ++i) {
char tc = types.charAt(i);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc));
}
}
示例2: 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();
}
示例3: dumpP1A
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpP1A() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "P1/A", 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("A.m");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
mv.visitIntInsn(BIPUSH, 1);
mv.visitInsn(IRETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例4: 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();
}
示例5: generateTestMethod
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateTestMethod(ClassVisitor cv,
Label unstableIfLocation) {
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, METHOD_NAME,
"(Z)V", null, null);
mv.visitCode();
Label end = new Label();
Label falseBranch = new Label();
// push "field" field's value and 1 to stack
mv.visitFieldInsn(GETSTATIC, CLASS_NAME, FIELD_NAME, "I");
mv.visitInsn(ICONST_1);
// load argument's value
mv.visitVarInsn(ILOAD, 0); // alwaysTrue
// here is our unstable if
mv.visitLabel(unstableIfLocation);
mv.visitJumpInsn(IFEQ, falseBranch);
// increment on "true"
mv.visitInsn(IADD);
mv.visitJumpInsn(GOTO, end);
// decrement on "false"
mv.visitLabel(falseBranch);
mv.visitInsn(ISUB);
mv.visitLabel(end);
// bye bye
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
示例6: getFieldValue
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
void getFieldValue(MethodVisitor mv) {
if (isStatic()) {
mv.visitFieldInsn(GETSTATIC, className, FIELD_NAME, fieldDesc);
} else {
mv.visitFieldInsn(GETSTATIC, className, "t", classDesc);
mv.visitFieldInsn(GETFIELD, className, FIELD_NAME, fieldDesc);
}
}
示例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: accept
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
mv.visitFieldInsn(opcode, owner, name, desc);
acceptAnnotations(mv);
}
示例9: loadUndefined
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type loadUndefined(final MethodVisitor method) {
method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "UNDEFINED", typeDescriptor(Undefined.class));
return UNDEFINED;
}
示例10: loadEmpty
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type loadEmpty(final MethodVisitor method) {
method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "EMPTY", typeDescriptor(Undefined.class));
return UNDEFINED;
}
示例11: 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();
}
示例12: generateTestClass
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static void generateTestClass(int dim, boolean good) throws Exception {
String baseClassName = "MeetIncompatibleInterfaceArrays";
if (good)
baseClassName += "Good";
String createName = "createI2" + (good ? "1" : "") + "Array";
String a = "";
for (int i = 0; i < dim; i++)
a += "[";
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
cw.visit(V1_8, ACC_PUBLIC, baseClassName + dim + "ASM", null, "java/lang/Object", null);
MethodVisitor constr = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
constr.visitCode();
constr.visitVarInsn(ALOAD, 0);
constr.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
constr.visitInsn(RETURN);
constr.visitMaxs(0, 0);
constr.visitEnd();
MethodVisitor run = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "run",
"()" + a + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I1;", null, null);
run.visitCode();
if (dim == 4) {
run.visitMethodInsn(INVOKESTATIC, "compiler/types/TestMeetIncompatibleInterfaceArrays$Helper", createName + 3,
"()" + "[[[" + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I2;", false);
} else {
run.visitMethodInsn(INVOKESTATIC, "compiler/types/TestMeetIncompatibleInterfaceArrays$Helper", createName + dim,
"()" + a + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I2;", false);
}
run.visitInsn(ARETURN);
run.visitMaxs(0, 0);
run.visitEnd();
MethodVisitor test = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "test", "()V", null, null);
test.visitCode();
test.visitMethodInsn(INVOKESTATIC, baseClassName + dim + "ASM", "run",
"()" + a + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I1;", false);
test.visitVarInsn(ASTORE, 0);
if (dim > 0) {
test.visitVarInsn(ALOAD, 0);
for (int i = 1; i <= dim; i++) {
test.visitInsn(ICONST_0);
test.visitInsn(AALOAD);
}
test.visitVarInsn(ASTORE, 1);
}
test.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
test.visitVarInsn(ALOAD, dim > 0 ? 1 : 0);
test.visitMethodInsn(INVOKEINTERFACE, "compiler/types/TestMeetIncompatibleInterfaceArrays$I1", "getName",
"()Ljava/lang/String;", true);
test.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false);
test.visitInsn(RETURN);
test.visitMaxs(0, 0);
test.visitEnd();
// Get the bytes of the class..
byte[] b = cw.toByteArray();
// ..and write them into a class file (for debugging)
FileOutputStream fos = new FileOutputStream(PATH + baseClassName + dim + "ASM.class");
fos.write(b);
fos.close();
}
示例13: visitMethod
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public MethodVisitor visitMethod(final int access, final String name,
final String desc, final String signature,
final String[] exceptions) {
/* a code generate looks like
* 0: aload_0
* 1: ldc #125 // int 1
* 3: ldc2_w #126 // long 2l
* 6: ldc #128 // float 3.0f
* 8: ldc2_w #129 // double 4.0d
* 11: ldc #132 // String 5
* 13: aload_0
* 14: getfield #135 // Field nativeCallee:Z
* 17: ifeq 28
* 20: invokedynamic #181, 0 // InvokeDynamic #1:calleeNative:(Lcompiler/calls/common/InvokeDynamic;IJFDLjava/lang/String;)Z
* 25: goto 33
* 28: invokedynamic #183, 0 // InvokeDynamic #1:callee:(Lcompiler/calls/common/InvokeDynamic;IJFDLjava/lang/String;)Z
* 33: ldc #185 // String Call insuccessfull
* 35: invokestatic #191 // Method jdk/test/lib/Asserts.assertTrue:(ZLjava/lang/String;)V
* 38: return
*
* or, using java-like pseudo-code
* if (this.nativeCallee == false) {
* invokedynamic-call-return-value = invokedynamic-of-callee
* } else {
* invokedynamic-call-return-value = invokedynamic-of-nativeCallee
* }
* Asserts.assertTrue(invokedynamic-call-return-value, error-message);
* return;
*/
if (name.equals(CALLER_METHOD_NAME)) {
MethodVisitor mv = cv.visitMethod(access, name, desc,
signature, exceptions);
Label nonNativeLabel = new Label();
Label checkLabel = new Label();
MethodType mtype = MethodType.methodType(CallSite.class,
MethodHandles.Lookup.class, String.class, MethodType.class);
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, CLASS,
BOOTSTRAP_METHOD_NAME, mtype.toMethodDescriptorString());
mv.visitCode();
// push callee parameters onto stack
mv.visitVarInsn(Opcodes.ALOAD, 0);//push "this"
mv.visitLdcInsn(1);
mv.visitLdcInsn(2L);
mv.visitLdcInsn(3.0f);
mv.visitLdcInsn(4.0d);
mv.visitLdcInsn("5");
// params loaded. let's decide what method to call
mv.visitVarInsn(Opcodes.ALOAD, 0); // push "this"
// get nativeCallee field
mv.visitFieldInsn(Opcodes.GETFIELD, CLASS, CALL_NATIVE_FIELD,
CALL_NATIVE_FIELD_DESC);
// if nativeCallee == false goto nonNativeLabel
mv.visitJumpInsn(Opcodes.IFEQ, nonNativeLabel);
// invokedynamic nativeCalleeMethod using bootstrap method
mv.visitInvokeDynamicInsn(NATIVE_CALLEE_METHOD_NAME,
CALLEE_METHOD_DESC, bootstrap);
// goto checkLabel
mv.visitJumpInsn(Opcodes.GOTO, checkLabel);
// label: nonNativeLabel
mv.visitLabel(nonNativeLabel);
// invokedynamic calleeMethod using bootstrap method
mv.visitInvokeDynamicInsn(CALLEE_METHOD_NAME, CALLEE_METHOD_DESC,
bootstrap);
mv.visitLabel(checkLabel);
mv.visitLdcInsn(CallsBase.CALL_ERR_MSG);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, ASSERTS_CLASS,
ASSERTTRUE_METHOD_NAME, ASSERTTRUE_METHOD_DESC, false);
// label: return
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
return null;
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
示例14: getUnsafe
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
void getUnsafe(MethodVisitor mv) {
mv.visitFieldInsn(GETSTATIC, className, "U", UNSAFE_DESC);
}