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
2
votes
1 answer

Few questions on generator expressions and speed efficient alternatives

Consider the following code, integral to my questions below: import functools N = 3 class Struct: """Create an instance with argument=value slots. This is for making a lightweight object whose class doesn't matter.""" def…
2
votes
2 answers

Bytecode enhancement for fields in a class

Is it possible to add "hooks" to a class via bytecode enhancement that execute code whenever a class field is read or written? For example, I'd like to automatically set a "dirty" flag whenever a new value is assigned to a field. If so, which…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
2
votes
0 answers

AspectJ - How to instruemt methods that are very very big

I have a generic Java agent based on AspectJ that instruments methods with a certain structure. The agent should be able to work with any Java web application. The problem - in case the method the agent tries to instrument is very very big, the…
Lin
  • 2,445
  • 5
  • 27
  • 37
2
votes
1 answer

Dynamic Bytecode Instrumentation fails without any error

Objective I'm doing dynamic bytecode instrumentation using a JVMTI agent. I have to instrument those methods which are "hot", that is, the methods which invoke JIT compiler. To do so I listen to a CompiledLoadEvent and inside its call back function,…
Saqib Ahmed
  • 1,056
  • 14
  • 33
2
votes
1 answer

How to get a class file (in specification format) during runtime using JVMTI?

I am working on a research project which includes Hotspot profiler's feedback. Currently I am working on a JVMTI agent which should have following features: listen any compiled load event. Extract and analyse the complete class file which has…
Saqib Ahmed
  • 1,056
  • 14
  • 33
2
votes
1 answer

How does one create an ASM LdcInsnNode that statically adds the current class to the stack?

I'm using the ASM library to modify bytecode created by others. For an arbitrary method in an arbitrary class, I'd like to create an LdcInsnNode that adds the current class to the stack. For example, let's say I'm transforming a class called…
Finn
  • 652
  • 7
  • 16
2
votes
2 answers

ASM Java bycode muniplation changing a class name

So recently I been trying to simply just change a class name and I just cant . Here is my code…
2
votes
1 answer

Getting verify error when working with asm java

So basicly Im trying to add a simple System.out.println("hey"); at the end of a method. I used the tree API. I do however keep getting this error: java.lang.VerifyError: Expecting a stackmap frame at branch target 38 This is my code: public class…
2
votes
3 answers

How can I get the syntax tree from a coderef in Perl?

I'd like to inspect and manipulate code of arbitrary Perl procedures (got by coderefs) in Perl. Is there a tool/module/library for that? Something similar to B::Concise, except that B::Concise prints the code on output, but I'd like to inspect it…
jpalecek
  • 47,058
  • 7
  • 102
  • 144
2
votes
1 answer

Java Bytecode Manipulation and Java reflection API?

I recently came across the term "Bytecode manipulation" (what made to look into this, by chance I saw bytecode provider while seeing the logs in an application which used Hibernate) . I also know (a bit) about Java Reflection API. Are these two…
CuriousMind
  • 8,301
  • 22
  • 65
  • 134
2
votes
3 answers

Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct?

Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct? It's about translating strings in Lua bytecode. Of course, not every language has the same size for each word...
lesderid
  • 3,388
  • 8
  • 39
  • 65
2
votes
3 answers

How to check that bytecode operation PUTFIELD is reassigning a field belonging to 'this' object using ObjectWeb ASM?

I am using the ASM bytecode manipulation framework to perform static analysis on Java code. I wish to detect when fields of an object are reassigned, i.e. when this kind of code occurs: class MyObject { private int value; void setValue(int…
2
votes
2 answers

When A ClassVisitor's visitMethod will be called in asm?

Let's say I have class like this: public class ClassPrinter extends ClassVisitor { public ClassPrinter(ClassWriter writer) { super(Opcodes.ASM5, writer); } @Override public void visit(int version, int access, String name,…
Ant's
  • 13,545
  • 27
  • 98
  • 148
2
votes
3 answers

Resolve a TypeVariable

Say I have these classes: class Container { private List list; } And I have an instance of Container, say Container instance = new Container(); Is there a way to find out list's actual type parameter at run-time? I.e., that it's…
jqno
  • 15,133
  • 7
  • 57
  • 84
2
votes
2 answers

ASM Tree API: Using LDC to load a Class constant

I'm writing a program in ASM that uses the Tree API to add bytecode to some methods. I've used ASMifier to generate the code required to create a specific method, but I'm having some trouble with the following line: mv.visitLdcInsn(Type.getType('L'…
konsolas
  • 1,041
  • 11
  • 24