FAQ Database Discussion Community


asm version compatible with hibernate 4.3.1

java,spring,hibernate,configuration,java-bytecode-asm
I've been working on a project and using hibernate 4.3.1. an error popped up and after searching for what it means, i found out that its caused by incompatible versions between hibernate and asm. what version of asm is compatible with hibernate 4.3.1?

COMPUTE_FRAMES issue with ASM and stackframe maps in generated code

java-bytecode-asm
I'm writing a code generator for a compiler that I'm using as an example in the compiler class I'm teaching. We're using ASM 5.0.3 to generate JVM code. I'm able to evaluate most straight forward expressions and statements, some that call runtime methods, just fine. For the example reference language,...

How to reuse original frame information from a methodNode in asm to create `org.objectweb.asm.tree.analysis.Frame`

java,bytecode,java-bytecode-asm
How can I construct a org.objectweb.asm.tree.analysis.Frame for each instruction in a method using only FrameNodes and LocalVariableNodes from the MethodNode? Context While instrumenting some code I need all the locals and stack types for some of the original instructions. Currently I get this by doing: Analyzer analyzer = new Analyzer(new...

JMockit: Mocked apis are getting reverted after somtime

java,bytecode,jit,jmockit,java-bytecode-asm
I am using JMockit to mock System.currentMillis(). Few invocations returning mocked time but after sometime, it starts returning original time. When i run the same after disabling the JIT, it runs perfectly fine.

Java Bytecode Signatures

java,generics,jvm,java-bytecode-asm,method-signature
As part of the compiler for the programming language I am working on, I came across generic signatures in the bytecode, which I am trying to parse and convert to an AST. The parsing algorithm mostly works, but there seems to be a special case in which the format of...

Java ASM Generate Catch Block

java,jvm,java-bytecode-asm,verifyerror
I am trying to compile a Try/Catch block using the ASM framework from my compiler (meaning that the try block, the handler blocks and the variables are dynamic). This is what my code currently looks like: org.objectweb.asm.Label tryStart = new org.objectweb.asm.Label(); org.objectweb.asm.Label tryEnd = new org.objectweb.asm.Label(); org.objectweb.asm.Label endLabel = new...

Embed the existing code of a method in a try-finally block (2)

java,bytecode,instrumentation,java-bytecode-asm,bytecode-manipulation
Some time ago, I asked in Embed the existing code of a method in a try-finally block how to wrap the body of a method in a try-finally block using ASM. The solution was to visit a label for the try block at the beginning of the method body in...

In JVM Instructions, some are of different prefixes but their functions are quite similar. Do we really need them all? If Yes, why?

java,jvm,java-bytecode-asm
For add : iadd/ladd/fadd/dadd, For sub : isub/lsub/fsub/dsub, For mul : imul/lmul/fmul/dmul For div : idiv/ldiv/fdiv/ddiv For rem : irem/lrem/frem/drem Fro neg : ineg/lneg/fneg/dneg... Can we only use only one instruction, e.g. add, to replace all the add instructions? If the answer of Q1 is true, will this get...

Fail to load a dynamically generated bytecodes

java,classloader,java-bytecode-asm,bytecode-manipulation
I have succeeded in dumping dynamically generated bytecodes to a file using ASM, but fail to load it. The error message is: java.lang.ClassFormatError: JVMCFRE102 field signature invalid; class=TGWD, offset=0 at java.lang.ClassLoader.defineClass(ClassLoader.java:364) at java.lang.ClassLoader.defineClass(ClassLoader.java:284) at java.lang.invoke.ByteCodeClassLoader.run(ByteCodeClassLoader.java:20) The BytecodeClassLoader is a Class I wrote here. The javap -v result is also shown...

Construct FrameNode with ASM api

java-7,bytecode,java-bytecode-asm,bytecode-manipulation,stackframe
I succeeded in implementing bytecode method inline optimization and the generated code seems OK for me. Yet, the verification fails with message: java.lang.VerifyError: Expecting a stackmap frame at branch target 47 Exception Details: Location: code/sxu/asm/example/Caller.test(II)V @44: goto Reason: Expected stackmap frame at this location. And the corresponding bytecode is: public...

How do I change the package name of classes inside a JAR? [duplicate]

java,jar,java-bytecode-asm
This question already has an answer here: Hand Edit A Jar to Change Package Names 6 answers Typical problem - I have x-1.0.jar, x-2.0.jar and y-1.0.jar. I want to use x-2.0.jar and y-1.0.jar but y-1.0.jar depends on x-1.0.jar. There is a tool out there which allows you to bundle...

To get the hashCode() of the object that calls a specific method in Java

java,java-bytecode-asm,javassist,bytecode-manipulation
What I'm trying to is to get 'hashCode()' value of the object that calls a specific method in Java. For example, public class Caller { public void aMethod() { Callee calleeObj = new Callee(); calleeObj.aSpecificMethod(); //do something } } What I want to know is Caller's hashCode() value which calls...

super class not assignable to class implemented during runtime by asm

java,runtime,java-bytecode-asm,dynamic-class-creation
I have a java class that consist of an inner interface, and plan to implement the implementation class during runtime with asm bytecode injection. package my.example; public class X{ public static interface XInt{ public void getX(); } //the following class that implement the interface will be defined during runtime. //I...

ASM COMPUTE_FRAMES Error with If + Assignment

java,java-bytecode-asm
I once again have a problem with ASM and it's COMPUTE_FRAMES. Whenever I compile this code with my custom compiler (Bytecode below): Code: Random random = Random() int i = 10 Object i1 = i if (i == 10) i1 = "a"; println "test" Bytecode: public static void main(java.lang.String[]); descriptor:...

Inlining tryCatchBlock results in Current frame's stack size doesn't match stackmap exception

java,bytecode,java-bytecode-asm,bytecode-manipulation
I am using ASM to inline body of Callee::calcualte(int,int)int, which contains a try-catch block, to the Caller::test method. The generated bytecode seems OK but verification fails due to Exception: Exception in thread "main" java.lang.VerifyError: Instruction type does not match stack map Exception Details: Location: CallerI.test(II)V @50: iload Reason: Current frame's...

Java bytecode instrumentation using ASM, MethodVisitor is null

java,java-bytecode-asm
So, with the code written below, my output is: Starting application with the Agent Visiting class: HelloWorld Class Major Version: 51 Super class: java/lang/Object Source: HelloWorld.java Method: <init> desc = ()V cv = [email protected] and mv = null Method: main desc = ([Ljava/lang/String;)V cv = [email protected] and mv = null...

Java Byte Code manipulation: Adding a method to a jdk abstract class

java,java-bytecode-asm,bytecode-manipulation
Using Java bytecode library like javaassist/cglib, it is possible to add method/variable to java classes, and popular frameworks like hibernate/spring and so forth use this capability. I need to add a method to the java.util.prefs.Preferences abstract class, the reasons are as follows: I have implemented a clusterable preferences implementation and...

JVM: Invalid index 1 in LocalVariableTable

java,jvm,java-bytecode-asm
I am trying to compile the following code using a custom compiler: public static void main([String] args) { long i = 2L i *= 2L System out println i } The result of the compilation is, when using javap, this Bytecode: public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC...

Different Java bytecode decompile to exactly the same p-code and java code

java,classloader,bytecode,java-bytecode-asm
I have generated two java bytecode files 1.class and 2.class, they are different if using hex file viewer inspect them: However the decompiled p-code are all the same: 1.class -> 1.java 2.class -> 2.java I can also use jd-gui to decompile them into Java source code and again the two...

Replacing a java method invocation from a field with a method call

java,bytecode,instrumentation,java-bytecode-asm,javaassist
I am trying to build a mocking framework in java which fits to a specific requirement of a project. The scenario is, I have a method public String returnRandom(){ String randomString = this.randomGenerator.returnRandom() } The randomGenerator is a dependency of this class and is injected to the object only in...

JVM Verify Error 'Illegal type at constant pool'

java,jvm,java-bytecode-asm
I am currently writing my own compiler and I am trying to compile the following code: List[String] list = List("a", "b", "c", "d") list stream map((String s) => s.toUpperCase()) System out println list The compiler has no problem parsing, linking or compiling the code, but when it comes to executing...

What do 'start' and 'length' attribute in LocalVariableTable mean

java,jvm,bytecode,java-bytecode-asm,bytecode-manipulation
So here is the example: LocalVariableTable: Start Length Slot Name Signature 0 133 0 this Lcom/my/class/Test; 2 131 1 a I 4 129 2 b I 7 126 3 i I 10 123 4 i2 I 16 117 5 o1 Ljava/lang/Integer; 31 102 6 o2 Ljava/lang/Integer; What does start and...

Wrong Stack Size calculated by ASM library

java,bytecode,java-bytecode-asm,bytecode-manipulation
I generate bytecodes using ASM library and 'Max stack size' for a method is left to be calculated automatically. During runtime,i found this value (max stack size) is not correct. My source code is: ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); .... MethodType initType = MethodType.methodType(void.class, clsList); mv = cw.visitMethod(ACC_PUBLIC, "<init>", initType.toMethodDescriptorString(),...

What does the visitLocalVariable() method of the MethodVisitor class in the ASM bytecode engineering library do?

java,jvm,bytecode,java-bytecode-asm,.class-file
I am using ASM (for the first time) in an application to create Java class files. This is for the backend of a compiler I am writing. I read the relevant parts of the ASM documentation and have a question about stack map frames. ASM says it can automatically compute...

ASM Skip Code for some Methods

java,java-bytecode-asm
Is there a way to tell ASM that I don't want to use the SKIP_CODE option for a particular method? For example, if I have a very large class like this: public class Large { public void doManyThings() { /* ... */ } public void methodWithLongBytecode() { /* ... */...