Questions tagged [java-bytecode-asm]

ASM is a Java library used for JVM bytecode manipulation and creation.

ASM is a Java bytecode manipulation and analysis framework. It provides a library to read, write, transform, and analyze compiled Java classes, directly in the binary form of byte arrays. Its API allows easy access to class items such as annotations, fields, and methods. Instructions in methods can be analyzed, removed, or inserted as necessary. Output classes can be saved into files, or loaded dynamically by a ClassLoader.

Website: http://asm.ow2.org/

Document: ASM 4.0 A Java bytecode engineering library

798 questions
8
votes
1 answer

Remapper variables during bytecode method inlining by ASM

I am doing an online bytecode method inlining optimization using ASM. My changes are based on the example 3.2.6 Inline Method (http://asm.ow2.org/current/asm-transformations.pdf). The test example (inline callee's calculate(int,int) at Caller::test)…
shijie xu
  • 1,975
  • 21
  • 52
8
votes
2 answers

How to read lambda expression bytecode using ASM

How can I read the bytecode instructions from the body of a lambda expression using ASM?
Josh Stone
  • 4,328
  • 7
  • 29
  • 37
8
votes
4 answers

Android and java bytecode manipulation

I am new to java and I need to manipulate java bytecode for some purposes (see this). Java bytecode manipulation need following imports: org.objectweb.asm java.lang.instrument I resolved org.objectweb.asm by downloading ASM package from asm…
mh taqia
  • 3,506
  • 1
  • 24
  • 35
8
votes
2 answers

Compile Error: JSR/RET are not supported with computeFrames option

Getting this error on an IntelliJ project when I compile java files. There is no specific source file listed, but it fails with this error. Removing the following compiler flags fixes the error: -source 1.5 -target 1.5 However, these need to be in…
Sam Barnum
  • 10,559
  • 3
  • 54
  • 60
8
votes
1 answer

Method code too large! exception using ASM

I am iterating over one class using ASM code without manipulating any byte code. But when I am converting classwriter to bytearray(cw.toByteArray()), I am getting Method code too large! exception. Can anybody tell me when does this happen .. My…
Ashiq Sayyad
  • 111
  • 2
  • 5
8
votes
2 answers

unboxing using the ASM Java library

I'm using the ASM Java library to replace some reflection. I generate the body of this method: void set(Object object, int fieldIndex, Object value); With this generated method, I can set fields on an object at runtime without using reflection. It…
NateS
  • 5,751
  • 4
  • 49
  • 59
8
votes
2 answers

Is it possible to inherit a final class modifying bytecode somehow?

Is it possible to inherit a final class using bytecode manipulations?
yegor256
  • 102,010
  • 123
  • 446
  • 597
7
votes
3 answers

Implementing abstract methods at runtime?

Let's say I have an abstract class: abstract class Foo extends Bar { public abstract int foo(); } that I want to extend at runtime to create a Class object. The hope would be that I could have a dynamically generated class: class FooImpl…
mburke13
  • 350
  • 2
  • 6
  • 22
7
votes
3 answers

How do I map ASM's API version in Opcodes to Java version?

ASM's ClassVisitor constructor requires passing one of Opcodes's ASM4, ASM5, ASM6, ASM7, ASM8 or ASM9. How do I know which ASM# to use for each version of Java? What ASM# would I use for Java 8? What ASM# would I use for Java 11?
Nathan
  • 8,093
  • 8
  • 50
  • 76
7
votes
3 answers

Use cases of jvm dup instruction

Java bytecode instruction set provides various forms of dup instruction. I'm having trouble understanding how these instructions and the swap instruction might be useful. What java code would produce bytecode with these instructions when compiled?
saga
  • 1,933
  • 2
  • 17
  • 44
7
votes
1 answer

Debugging ASM-generated bytecode with JDB (or similar)

So I have some malfuctioning code to debug where SOMEthing throws an NPE and I'd like to step through some generated methods in order to try and find out why. Except stepping blindly is not really useful. Thread-4[1] list Source file not found:…
User1291
  • 7,664
  • 8
  • 51
  • 108
7
votes
2 answers

ASM: Stateful Transformation

I want to write a MethodVisitor that transforms LDC instructions that are for multiplication. Example bytecode: ldc #26 imul This basically pushes a constant and then multiplies it. It has to be a stateful transformation because I first have to…
someguy
  • 7,144
  • 12
  • 43
  • 57
7
votes
0 answers

Reading method invocation arguments using ASM

When vising method instruction a.doAnother(account.getId); Using visitMethodInsn() in ASM. I need to get type of account from the method argument account.getId() and the type of account is Account. however I am getting return type of…
Swati Thakare
  • 189
  • 1
  • 8
7
votes
1 answer

How can I control the order of constant pool entries using ASM?

I'm implementing a transformation that removes unused elements from .class files to reduce their size. Because some constant pool entries will become unused, I'm having ASM recompute the constant pool, rather than copying it over from the input. …
Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
7
votes
1 answer

creating object instance without invoking initializer

I'm trying to generate bytecode which will create object instance without code initialization logic. Actually I want to reproduce generateSerializationConstructor behavior. { mv = cw.visitMethod(ACC_PUBLIC, "newObjectInstance",…
dimzon
  • 414
  • 4
  • 13
1 2
3
53 54