Java Code Examples for org.objectweb.asm.MethodVisitor#visitLineNumber()
The following examples show how to use
org.objectweb.asm.MethodVisitor#visitLineNumber() .
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: StatementWriter.java From groovy with Apache License 2.0 | 6 votes |
public void writeBlockStatement(final BlockStatement block) { writeStatementLabel(block); int mark = controller.getOperandStack().getStackLength(); CompileStack compileStack = controller.getCompileStack(); compileStack.pushVariableScope(block.getVariableScope()); for (Statement statement : block.getStatements()) { statement.visit(controller.getAcg()); } compileStack.pop(); // GROOVY-7647, GROOVY-9126 if (block.getLastLineNumber() > 0 && !isMethodOrConstructorNonEmptyBlock(block)) { MethodVisitor mv = controller.getMethodVisitor(); Label blockEnd = new Label(); mv.visitLabel(blockEnd); mv.visitLineNumber(block.getLastLineNumber(), blockEnd); } controller.getOperandStack().popDownTo(mark); }
Example 2
Source File: CreateTest.java From AVM with MIT License | 6 votes |
private byte[] getByteCodeForEmptyClass() { ClassWriter classWriter = new ClassWriter(0); MethodVisitor methodVisitor; classWriter.visit(V10, ACC_PUBLIC | ACC_SUPER, "a/Main", null, "java/lang/Object", null); classWriter.visitSource("Main.java", null); { methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); Label label0 = new Label(); methodVisitor.visitLabel(label0); methodVisitor.visitLineNumber(3, label0); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } classWriter.visitEnd(); return classWriter.toByteArray(); }
Example 3
Source File: CreateTest.java From AVM with MIT License | 6 votes |
private byte[] getByteCodeForClassWithoutSuperName() { ClassWriter classWriter = new ClassWriter(0); MethodVisitor methodVisitor; classWriter.visit(V10, ACC_PUBLIC | ACC_SUPER, "b/Main", null, null, null); classWriter.visitSource("Main.java", null); { methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); Label label0 = new Label(); methodVisitor.visitLabel(label0); methodVisitor.visitLineNumber(3, label0); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } classWriter.visitEnd(); return classWriter.toByteArray(); }
Example 4
Source File: UserlibCollisionTest.java From AVM with MIT License | 6 votes |
private static byte[] getJavaLangPackageClassBytes() { ClassWriter classWriter = new ClassWriter(0); MethodVisitor methodVisitor; classWriter.visit(V10, ACC_PUBLIC | ACC_SUPER, "java/lang/MyClass", null, "java/lang/Object", null); classWriter.visitSource("MyClass.java", null); { methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); Label label0 = new Label(); methodVisitor.visitLabel(label0); methodVisitor.visitLineNumber(3, label0); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } classWriter.visitEnd(); return classWriter.toByteArray(); }
Example 5
Source File: UserlibCollisionTest.java From AVM with MIT License | 6 votes |
private static byte[] getAvmPackageClassBytes() { ClassWriter classWriter = new ClassWriter(0); MethodVisitor methodVisitor; classWriter.visit(V10, ACC_PUBLIC | ACC_SUPER, "avm/Main", null, "java/lang/Object", null); classWriter.visitSource("Main.java", null); { methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); Label label0 = new Label(); methodVisitor.visitLabel(label0); methodVisitor.visitLineNumber(3, label0); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } classWriter.visitEnd(); return classWriter.toByteArray(); }
Example 6
Source File: AsmClassGenerator.java From groovy with Apache License 2.0 | 5 votes |
public void onLineNumber(final ASTNode statement, final String message) { if (statement == null || statement instanceof BlockStatement) return; currentASTNode = statement; int line = statement.getLineNumber(); if (line < 0 || (!ASM_DEBUG && line == controller.getLineNumber())) return; controller.setLineNumber(line); MethodVisitor mv = controller.getMethodVisitor(); if (mv != null) { Label l = new Label(); mv.visitLabel(l); mv.visitLineNumber(line, l); } }
Example 7
Source File: DefaultApplicationFactory.java From thorntail with Apache License 2.0 | 5 votes |
static byte[] basicClassBytes() { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(52, ACC_PUBLIC + ACC_SUPER, "org/wildfly/swarm/jaxrs/runtime/DefaultApplication", null, "javax/ws/rs/core/Application", null); cw.visitSource("DefaultApplication.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(23, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/core/Application", "<init>", "()V", false); mv.visitInsn(RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "Lorg/wildfly/swarm/jaxrs/runtime/DefaultApplication;", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
Example 8
Source File: Label.java From OSRS-Deobfuscator with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void accept(MethodVisitor visitor) { visitor.visitLabel(label); if (lineNumber != null) { visitor.visitLineNumber(lineNumber, label); } }
Example 9
Source File: CommonHelpers.java From HttpSessionReplacer with MIT License | 5 votes |
static void addIsServlet3(ClassVisitor cw) { FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, "$$isServlet3", "Z", null, null); fv.visitEnd(); MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "$$isServlet3", "()Z", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException"); mv.visitLabel(l0); mv.visitLineNumber(446, l0); mv.visitLdcInsn(Type.getType("Ljavax/servlet/ServletRequest;")); mv.visitLdcInsn("startAsync"); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false); mv.visitInsn(POP); mv.visitLabel(l1); mv.visitLineNumber(447, l1); mv.visitInsn(ICONST_1); mv.visitInsn(IRETURN); mv.visitLabel(l2); mv.visitLineNumber(448, l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" }); mv.visitVarInsn(ASTORE, 0); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(449, l3); mv.visitInsn(ICONST_0); mv.visitInsn(IRETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("e", "Ljava/lang/NoSuchMethodException;", null, l3, l4, 0); mv.visitMaxs(3, 1); mv.visitEnd(); }
Example 10
Source File: ClientServiceFactory.java From thorntail with Apache License 2.0 | 4 votes |
static void createMethod(ClassWriter cw, String implName, String clientInterfaceName, MethodInfo method, int lineNum, String baseUrl) { MethodVisitor mv; { mv = cw.visitMethod(ACC_PUBLIC, method.name(), buildMethodDef(method), null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(lineNum++, l0); mv.visitLdcInsn(Type.getType(buildTypeDef(clientInterfaceName))); mv.visitTypeInsn(NEW, "org/jboss/resteasy/client/jaxrs/ResteasyClientBuilder"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "org/jboss/resteasy/client/jaxrs/ResteasyClientBuilder", "<init>", "()V", false); mv.visitMethodInsn(INVOKEVIRTUAL, "org/jboss/resteasy/client/jaxrs/ResteasyClientBuilder", "build", "()Lorg/jboss/resteasy/client/jaxrs/ResteasyClient;", false); mv.visitLdcInsn(baseUrl); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(lineNum++, l1); mv.visitMethodInsn(INVOKEVIRTUAL, "org/jboss/resteasy/client/jaxrs/ResteasyClient", "target", "(Ljava/lang/String;)Lorg/jboss/resteasy/client/jaxrs/ResteasyWebTarget;", false); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(lineNum - 2, l2); mv.visitMethodInsn(INVOKESTATIC, "org/wildfly/swarm/cdi/jaxrsapi/deployment/ProxyBuilder", "builder", "(Ljava/lang/Class;Ljavax/ws/rs/client/WebTarget;)Lorg/wildfly/swarm/cdi/jaxrsapi/deployment/ProxyBuilder;", false); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(lineNum++, l3); mv.visitMethodInsn(INVOKEVIRTUAL, "org/wildfly/swarm/cdi/jaxrsapi/deployment/ProxyBuilder", "build", "()Ljava/lang/Object;", false); mv.visitTypeInsn(CHECKCAST, clientInterfaceName.replace('.', '/')); for (int i = 1; i <= method.parameters().size(); i++) { mv.visitVarInsn(ALOAD, i); } Label l4 = new Label(); mv.visitLabel(l4); mv.visitLineNumber(lineNum++, l4); mv.visitMethodInsn(INVOKEINTERFACE, clientInterfaceName.replace('.', '/'), method.name(), buildMethodDef(method), true); Label l5 = new Label(); mv.visitLabel(l5); if (method.returnType().kind().equals(org.jboss.jandex.Type.Kind.VOID)) { mv.visitLineNumber(lineNum++, l5); mv.visitInsn(RETURN); } else { mv.visitLineNumber(lineNum - 4, l5); mv.visitInsn(ARETURN); } Label l6 = new Label(); mv.visitLabel(l6); int methodParams = 0; mv.visitLocalVariable("this", buildTypeDef(implName), null, l0, l6, methodParams++); for (AnnotationInstance anno : method.annotations()) { if (anno.name().toString().contains("QueryParam") || anno.name().toString().contains("PathParam")) { short position = anno.target().asMethodParameter().position(); org.jboss.jandex.Type parameterType = anno.target().asMethodParameter().method().parameters().get(position); mv.visitLocalVariable(String.valueOf(anno.value().value()), buildTypeDef(parameterType.name().toString()), null, l0, l6, methodParams++); } } mv.visitMaxs(3, methodParams); lineNum += 4; mv.visitEnd(); } }
Example 11
Source File: ClientServiceFactory.java From thorntail with Apache License 2.0 | 4 votes |
static byte[] createImpl(String implName, ClassInfo classInfo) { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, implName.replace('.', '/'), null, "java/lang/Object", new String[]{classInfo.name().toString().replace('.', '/')} ); int lastDot = implName.lastIndexOf('.'); String simpleName = implName.substring(lastDot + 1); cw.visitSource(simpleName + ".java", null); { av0 = cw.visitAnnotation("Ljavax/enterprise/context/ApplicationScoped;", true); av0.visitEnd(); } cw.visitInnerClass("javax/ws/rs/client/Invocation$Builder", "javax/ws/rs/client/Invocation", "Builder", ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(14, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(15, l1); mv.visitInsn(RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", buildTypeDef(implName), null, l0, l2, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } List<AnnotationInstance> annotations = classInfo.annotations().get(DotName.createSimple("org.wildfly.swarm.client.jaxrs.Service")); String baseUrl = (String) annotations.get(0).value("baseUrl").value(); int lineNum = 18; classInfo.asClass().methods() .stream() .forEachOrdered(method -> { createMethod(cw, implName, classInfo.name().toString(), method, lineNum, baseUrl); }); cw.visitEnd(); return cw.toByteArray(); }
Example 12
Source File: CommonHelpers.java From HttpSessionReplacer with MIT License | 4 votes |
static void addLogError(ClassVisitor cw) { MethodVisitor mv; mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_VARARGS, "$$error", "(Ljava/lang/String;[Ljava/lang/Object;)V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(433, l0); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); mv.visitLdcInsn("SessionAgent: [ERROR] %s"); mv.visitInsn(ICONST_1); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "format", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "format", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(434, l1); mv.visitVarInsn(ALOAD, 1); Label l2 = new Label(); mv.visitJumpInsn(IFNULL, l2); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ARRAYLENGTH); mv.visitInsn(ICONST_1); mv.visitJumpInsn(IF_ICMPLE, l2); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ARRAYLENGTH); mv.visitInsn(ICONST_1); mv.visitInsn(ISUB); mv.visitInsn(AALOAD); mv.visitTypeInsn(INSTANCEOF, "java/lang/Throwable"); mv.visitJumpInsn(IFEQ, l2); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(435, l3); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ARRAYLENGTH); mv.visitInsn(ICONST_1); mv.visitInsn(ISUB); mv.visitInsn(AALOAD); mv.visitTypeInsn(CHECKCAST, "java/lang/Throwable"); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "(Ljava/io/PrintStream;)V", false); mv.visitLabel(l2); mv.visitLineNumber(437, l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("format", "Ljava/lang/String;", null, l0, l4, 0); mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l0, l4, 1); mv.visitMaxs(7, 2); mv.visitEnd(); }
Example 13
Source File: LineNumberNode.java From JReFrameworker with MIT License | 4 votes |
@Override public void accept(final MethodVisitor methodVisitor) { methodVisitor.visitLineNumber(line, start.getLabel()); }
Example 14
Source File: ApplicationFactory.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
public static byte[] create(String name, String context) { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name.replace('.', '/'), null, "javax/ws/rs/core/Application", null); int lastDot = name.lastIndexOf('.'); String simpleName = name.substring(lastDot + 1); cw.visitSource(simpleName + ".java", null); { av0 = cw.visitAnnotation("Ljavax/ws/rs/ApplicationPath;", true); av0.visit("value", "/"); av0.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(10, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/core/Application", "<init>", "()V", false); mv.visitInsn(RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name.replace('.', '/') + ";", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
Example 15
Source File: LineNumberNode.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor mv) { mv.visitLineNumber(line, start.getLabel()); }
Example 16
Source File: LineNumberNode.java From JReFrameworker with MIT License | 4 votes |
@Override public void accept(final MethodVisitor methodVisitor) { methodVisitor.visitLineNumber(line, start.getLabel()); }
Example 17
Source File: ModifyUtils.java From DataLoader with Apache License 2.0 | 4 votes |
public static File modifyJar(File file, File tempDir) throws IOException { JarFile jarFile = new JarFile(file); System.out.println(TAG + "tempDir: " + tempDir.getAbsolutePath()); File outputFile = new File(tempDir, file.getName()); JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(outputFile)); Enumeration enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { JarEntry jarEntry = (JarEntry) enumeration.nextElement(); InputStream inputStream = jarFile.getInputStream(jarEntry); String entryName = jarEntry.getName(); ZipEntry zipEntry = new ZipEntry(entryName); jarOutputStream.putNextEntry(zipEntry); byte[] modifiedClassBytes = null; byte[] sourceClassBytes = IOUtils.toByteArray(inputStream); if (TARGET_CLASS.equals(jarEntry.getName())) { ClassReader cr = new ClassReader(sourceClassBytes); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cr.accept(cw, 0); { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(18, l0); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); modifiedClassBytes = cw.toByteArray(); } if (modifiedClassBytes == null) { jarOutputStream.write(sourceClassBytes); } else { jarOutputStream.write(modifiedClassBytes); } jarOutputStream.closeEntry(); } jarOutputStream.close(); jarFile.close(); return outputFile; }
Example 18
Source File: FastPathGuardsBench.java From bumblebench with Apache License 2.0 | 4 votes |
static void visitLineNumberInfo(MethodVisitor mv) { Label label = new Label(); mv.visitLabel(label); mv.visitLineNumber(Thread.currentThread().getStackTrace()[3].getLineNumber(), label); }
Example 19
Source File: LineNumberNode.java From Concurnas with MIT License | 4 votes |
@Override public void accept(final MethodVisitor methodVisitor) { methodVisitor.visitLineNumber(line, start.getLabel()); }
Example 20
Source File: LineNumberNode.java From Cafebabe with GNU General Public License v3.0 | 4 votes |
@Override public void accept(final MethodVisitor methodVisitor) { methodVisitor.visitLineNumber(line, start.getLabel()); }