Questions tagged [bytecode-manipulation]

Low level Virtual Machine bytecode manipulations. Including creating/modifying/optimizing/etc bytecode for various VMs. For example JVM, Python VM, Lua VM, etc.

Why?

Using some VM based programming languages for period of time usually leads to realising that some parts of the code aren't translated into bytecode efficiently, might be optimized for the specific VM even more or we just need some functionality which isn't implemented into standard bytecode compiler/interpreter/etc, like:

  • bytecode encryption
  • bytecode linkage
  • etc.

Links:

More about bytecode:

383 questions
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
7
votes
3 answers

How to make a copy of a Java class in runtime?

I have a class class Foo { int increment(int x) { return x + 1; } } I want to obtain a copy of this class in runtime, e. g. a class like class Foo$Copy1 { int increment(int x) { return x + 1; } } Which has all the…
leventov
  • 14,760
  • 11
  • 69
  • 98
7
votes
2 answers

Is it safe to use bytecode enhancement techniques on classes that might be serialized and why?

I haven't tried this yet, but it seems risky. The case I'm thinking of is instrumenting simple VO classes with JiBX. These VOs are going to be serialized over AMF and possibly other schemes. Can anyone confirm or deny my suspicions that doing…
gtrak
  • 5,598
  • 4
  • 32
  • 41
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
5 answers

Bytecode manipulation patterns

What legitimate uses are there for bytecode manipulation and how people implement those bytecode manipulation based solutions in practice? Update: I should have made it more clear that this question really is about what patterns and techniques…
ahe
  • 2,319
  • 1
  • 19
  • 22
7
votes
3 answers

Stand-alone Bytecode Verifier

In my bytecode instrumentation project, I stumble frequently on VerifyErrors. However, the default java Verifier gives little information on which instruction resulted in the error (it only gives the method and a small message). Is there any…
H-H
  • 4,431
  • 6
  • 33
  • 41
7
votes
3 answers

Attach proxy to an existing object?

My plan is to write a annotation based caching framework which caches the return values of methods. When a method gets called the first time with a specific parameter, then the cache should store the methods return value. When the same method gets…
eztam
  • 3,443
  • 7
  • 36
  • 54
7
votes
5 answers

Adding programmatic annotations to a Java class

Usage example: I want to put on class fields a custom annotation @MyContainer and then add automatically on all such fields relevant Hibernate annotations (depending on field type and properties). In additional I need to add JAXB XmlType annotation…
6
votes
3 answers

Optimizing boolean logic tree evaluation

I've got a lot of true/false results saved as bits in long[] arrays. I do have a huge number of these (millions and millions of longs). For example, say I have only five results, I'd have: +----- condition 5 is true | |+---- condition 4 is…
SyntaxT3rr0r
  • 27,745
  • 21
  • 87
  • 120
6
votes
1 answer

Lombok on Jenkins

I just started using Lombok's ability to auto-generate getters and setters for Java beans in my local Eclipse environment via modifying its boot classpath: -vmargs -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar It works fine locally, however…
6
votes
1 answer

Is bytecode manipulation safe

Performing bytecode manipulation using APIs like javaassist modify class files after compilation. But, if the java code is optimized can't the modifications be performed in the wrong place? Are there ways to avoid this problem? Is the story any…
6
votes
0 answers

Different behaviors between Unsafe defineAnonymousClass and ClassLoader

I used classloader and Unsafe::definedAnonymous() to load generated bytecode byte[]. The usage of Class returned by classLoader.loadClass() succeeds while it fails with c.getMethod() in which c=Unsafe.defineAnonymousClass() API. So is the generated…
6
votes
3 answers

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

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…
6
votes
3 answers

How to validate Python bytecode?

I'm thinking to do some bytecode manipulation (think genetic programming) in Python. I came across a test case in crashers test section of Python source tree that states: Broken bytecode objects can easily crash the interpreter. This is not going…
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
6
votes
1 answer

Integrating javassist byte code manipulation with maven compilation

I have a maven project which compiles with javac / aspectj compiler. I want to run on classes which were compiled a javassist program which manipulate the compiled classes and add stuff to them. I thought using the "process-classes" phase to run my…
1 2
3
25 26