java-bytecode-asm

ASM - java.lang.VerifyError: Operand stack overflow Exception

强颜欢笑 提交于 2020-01-23 11:13:31
问题 I am using ASM 5.0.3 byte code library with Tomcat 8 and JDK 8. Also I am using ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES); and classReader.accept(myClassVisitor, ClassReader.SKIP_FRAMES); Below exception is thrown by ASM Caused by: java.lang.VerifyError: Operand stack overflow Exception Details: Location: org/apache/tomcat/websocket/server/WsServerContainer.addEndpoint(Ljavax/websocket/server/ServerEndpointConfig;)V @0: aload_0 Reason: Exceeded max

ASM - java.lang.VerifyError: Operand stack overflow Exception

久未见 提交于 2020-01-23 11:12:13
问题 I am using ASM 5.0.3 byte code library with Tomcat 8 and JDK 8. Also I am using ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES); and classReader.accept(myClassVisitor, ClassReader.SKIP_FRAMES); Below exception is thrown by ASM Caused by: java.lang.VerifyError: Operand stack overflow Exception Details: Location: org/apache/tomcat/websocket/server/WsServerContainer.addEndpoint(Ljavax/websocket/server/ServerEndpointConfig;)V @0: aload_0 Reason: Exceeded max

creating object instance without invoking initializer

笑着哭i 提交于 2020-01-14 08:13:51
问题 I'm trying to generate bytecode wich will create object instance without code initialization logic. Actually I want to reproduce generateSerializationConstructor behavior. { mv = cw.visitMethod(ACC_PUBLIC, "newObjectInstance", "()Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, classNameInternal); mv.visitInsn(DUP); classNameInternal = "java/lang/Object"; mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "()V"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv

unexpected instructions and parameters for invokevirtual in the inlined method body

两盒软妹~` 提交于 2020-01-11 11:07:59
问题 I followed the sample code in the "3.2.6 Inline Method“ in the http://asm.ow2.org/current/asm-transformations.pdf, to inline a MethodNode to a call site. My problem is that there are some unexpected instructions shown in the generated bytecode after inlining (these bytecodes are inconsistent to my code), and the problem only exists when an ifeq is after inlineed method body and the variable on the stack is loaded by xLoad. I still have not found the root cause for the issue. Now i am start to

ASM: outputting java bytecode and opcode

丶灬走出姿态 提交于 2020-01-11 07:07:26
问题 I am trying to write a program that takes a .class file and collects all the methods of the .class file as well as the contents of each method. Here is my code public class ClassReaderTest1 { public static void main(String[] args) throws Exception{ InputStream in = new FileInputStream("*.class"); ClassReader reader = new ClassReader(in); ClassNode classNode = new ClassNode(); reader.accept(classNode,0); @SuppressWarnings("unchecked") final List<MethodNode> methods = classNode.methods; for

How do I apply the AdviceAdapter I have written?

懵懂的女人 提交于 2020-01-06 20:40:01
问题 I have the following class: import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.commons.AdviceAdapter; public class NotEmptyAdvice extends AdviceAdapter { protected NotEmptyAdvice(final MethodVisitor visitor, final int i, final String s, final String s2) { super(visitor, i, s, s2); } @Override protected void onMethodEnter() { super.mv.visitVarInsn(ALOAD, 1); super.mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "isEmpty", "()Z" ); super.mv.visitVarInsn(IFEQ, 1); super.mv

How do I apply the AdviceAdapter I have written?

陌路散爱 提交于 2020-01-06 20:39:29
问题 I have the following class: import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.commons.AdviceAdapter; public class NotEmptyAdvice extends AdviceAdapter { protected NotEmptyAdvice(final MethodVisitor visitor, final int i, final String s, final String s2) { super(visitor, i, s, s2); } @Override protected void onMethodEnter() { super.mv.visitVarInsn(ALOAD, 1); super.mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "isEmpty", "()Z" ); super.mv.visitVarInsn(IFEQ, 1); super.mv

Is there an analogue of visitLdcInsn for loading objects (not constant)?

三世轮回 提交于 2020-01-06 02:50:30
问题 We wrote a simple PostScript interpreter in Java and want to optimize it by generating bytecode directly for specific parts of source code. For this we need to load the object from the context of the Java bytecode context. Specify such object in the signature of the generated bytecode method is not good, because they may be in a large amount in our case. In Java Asm we have method public void visitLdcInsn(Object cst) It visits a LDC instruction. Parameter cst - the constant to be loaded on

getting the number of local variables in a method

微笑、不失礼 提交于 2020-01-05 09:15:37
问题 So I have some classes into which "dummy method calls" have been inserted; i.e. static methods in a dedicated class that have an empty body. The idea is to take the arguments that were pushed to the stack prior to the method invokation, store them in local variables, then replace the method invocation with the actual implementation. To see how locals are handled, I run A.java package asmvisit; public class A { long y; public long doSomething(int x, A a){ if(a == null){ this.y = (long)x;

getting the number of local variables in a method

与世无争的帅哥 提交于 2020-01-05 09:14:42
问题 So I have some classes into which "dummy method calls" have been inserted; i.e. static methods in a dedicated class that have an empty body. The idea is to take the arguments that were pushed to the stack prior to the method invokation, store them in local variables, then replace the method invocation with the actual implementation. To see how locals are handled, I run A.java package asmvisit; public class A { long y; public long doSomething(int x, A a){ if(a == null){ this.y = (long)x;