Java Code Examples for jdk.internal.org.objectweb.asm.MethodVisitor#visitLabel()
The following examples show how to use
jdk.internal.org.objectweb.asm.MethodVisitor#visitLabel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedefineRunningMethodsWithResolutionErrors.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void createMethodBody(MethodVisitor mv) { Label classExists = new Label(); // Cache resolution errors createLoadNonExistentClassCode(mv, classExists); // Redefine our own class and method mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V"); // Provoke the same error again to make sure the resolution error cache works createLoadNonExistentClassCode(mv, classExists); // Test passed mv.visitInsn(RETURN); mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]); mv.visitLabel(classExists); createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")"); }
Example 2
Source File: RedefineRunningMethodsWithResolutionErrors.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) { Label tryLoadBegin = new Label(); Label tryLoadEnd = new Label(); Label catchLoadBlock = new Label(); mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError"); // Try to load a class that does not exist to provoke resolution errors mv.visitLabel(tryLoadBegin); mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V"); mv.visitLabel(tryLoadEnd); // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen mv.visitJumpInsn(GOTO, classExists); mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" }); mv.visitLabel(catchLoadBlock); // Ignore the expected NoClassDefFoundError mv.visitInsn(POP); }
Example 3
Source File: TinyInstrumentor.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Create a {@link ClassNode} with empty constructor. */ private static ClassNode emptyClass(String name) { ClassNode classNode = new ClassNode(); classNode.visit(52, ACC_SUPER | ACC_PUBLIC, name.replace('.', '/'), null, "java/lang/Object", new String[]{}); MethodVisitor mv = classNode.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitMaxs(1, 1); mv.visitEnd(); return classNode; }
Example 4
Source File: RedefineRunningMethodsWithResolutionErrors.java From hottub with GNU General Public License v2.0 | 6 votes |
private static void createMethodBody(MethodVisitor mv) { Label classExists = new Label(); // Cache resolution errors createLoadNonExistentClassCode(mv, classExists); // Redefine our own class and method mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V"); // Provoke the same error again to make sure the resolution error cache works createLoadNonExistentClassCode(mv, classExists); // Test passed mv.visitInsn(RETURN); mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]); mv.visitLabel(classExists); createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")"); }
Example 5
Source File: RedefineRunningMethodsWithResolutionErrors.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) { Label tryLoadBegin = new Label(); Label tryLoadEnd = new Label(); Label catchLoadBlock = new Label(); mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError"); // Try to load a class that does not exist to provoke resolution errors mv.visitLabel(tryLoadBegin); mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V"); mv.visitLabel(tryLoadEnd); // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen mv.visitJumpInsn(GOTO, classExists); mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" }); mv.visitLabel(catchLoadBlock); // Ignore the expected NoClassDefFoundError mv.visitInsn(POP); }
Example 6
Source File: RedefineRunningMethodsWithResolutionErrors.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void createMethodBody(MethodVisitor mv) { Label classExists = new Label(); // Cache resolution errors createLoadNonExistentClassCode(mv, classExists); // Redefine our own class and method mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V"); // Provoke the same error again to make sure the resolution error cache works createLoadNonExistentClassCode(mv, classExists); // Test passed mv.visitInsn(RETURN); mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]); mv.visitLabel(classExists); createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")"); }
Example 7
Source File: RedefineRunningMethodsWithResolutionErrors.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) { Label tryLoadBegin = new Label(); Label tryLoadEnd = new Label(); Label catchLoadBlock = new Label(); mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError"); // Try to load a class that does not exist to provoke resolution errors mv.visitLabel(tryLoadBegin); mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V"); mv.visitLabel(tryLoadEnd); // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen mv.visitJumpInsn(GOTO, classExists); mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" }); mv.visitLabel(catchLoadBlock); // Ignore the expected NoClassDefFoundError mv.visitInsn(POP); }
Example 8
Source File: TestOSRWithNonEmptyStack.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void generateTestMethod(ClassWriter classWriter) { MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC, TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null); Label osrEntryPoint = new Label(); mv.visitCode(); // Push 'this' into stack before OSR entry point to bail out compilation mv.visitVarInsn(ALOAD, 0); // Setup loop counter mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); // Begin loop mv.visitLabel(osrEntryPoint); // Increment loop counter mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_1); mv.visitInsn(IADD); // Duplicate it for loop condition check mv.visitInsn(DUP); mv.visitVarInsn(ISTORE, 1); // Check loop condition mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS); mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint); // Pop 'this'. mv.visitInsn(POP); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
Example 9
Source File: TestOSRWithNonEmptyStack.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void generateTestMethod(ClassWriter classWriter) { MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC, TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null); Label osrEntryPoint = new Label(); mv.visitCode(); // Push 'this' into stack before OSR entry point to bail out compilation mv.visitVarInsn(ALOAD, 0); // Setup loop counter mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); // Begin loop mv.visitLabel(osrEntryPoint); // Increment loop counter mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_1); mv.visitInsn(IADD); // Duplicate it for loop condition check mv.visitInsn(DUP); mv.visitVarInsn(ISTORE, 1); // Check loop condition mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS); mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint); // Pop 'this'. mv.visitInsn(POP); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
Example 10
Source File: TestOSRWithNonEmptyStack.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void generateTestMethod(ClassWriter classWriter) { MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC, TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null); Label osrEntryPoint = new Label(); mv.visitCode(); // Push 'this' into stack before OSR entry point to bail out compilation mv.visitVarInsn(ALOAD, 0); // Setup loop counter mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); // Begin loop mv.visitLabel(osrEntryPoint); // Increment loop counter mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_1); mv.visitInsn(IADD); // Duplicate it for loop condition check mv.visitInsn(DUP); mv.visitVarInsn(ISTORE, 1); // Check loop condition mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS); mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint); // Pop 'this'. mv.visitInsn(POP); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
Example 11
Source File: TestUnstableIfTrap.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 12
Source File: LabelNode.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 13
Source File: LabelNode.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 14
Source File: LabelNode.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 15
Source File: LabelNode.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 16
Source File: LabelNode.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 17
Source File: InvokeDynamicPatcher.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@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); }
Example 18
Source File: LabelNode.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 19
Source File: LabelNode.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }
Example 20
Source File: LabelNode.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitLabel(getLabel()); }