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
2 answers

How do I convert between big-endian and little-endian values in C++?

How do I convert between big-endian and little-endian values in C++? I'm using VC++ 6.0.when I used _byteswap_ulong() function it requires the header file intrin.h. When I include the header it reports an error saying incompatible compiler and that…
Harish
2
votes
0 answers

How to ignore instrumenting getters/setters when using ASM?

I am using ASM library to instrument some classes. I create my own instance of MethodVisitor and override some of its methods e.g. visitCode() which is called when the MethodVisitor is at the start of the method. Here, I insert my own code if the…
2
votes
1 answer

NoClassDefFoundError after instrumenting code

I'm attaching my Java agent dynamically to a java process which instruments the code. Basically it adds a static call to every start of method: //method start AgentClass.staticMethod(); //method body AgentClass lies in the agent's .jar. But…
2
votes
1 answer

get CtClass using specific ClassLoader

I have a class structure like this: package com.mydomain.myproject; public class Outer{ public class Inner{ //some code } } Now, I can get a CtClass of the inner class using: ClassPool pool=ClassPool.getDefault(); CtClass…
2
votes
1 answer

How to reliably set up post-compilation bytecode enhancement builder in Eclipse?

I need to set up an Eclipse project with an additional builder that enhances the Java bytecode produced by an earlier builder (ideally Eclipse's own). I managed to get this builder to run and enhance the Eclipse Java builder output properly but…
2
votes
1 answer

Is there a way to swap long (or double) and reference values on JVM stack?

Let's say I have following bytecode sequence aload 0 // this lload 1 aload 3 For the sake of the question, let's assume that these instructions are generated by other code and I don't have control over it. I need to swap last two items on a stack,…
uaraven
  • 1,097
  • 10
  • 16
2
votes
2 answers

Asm bytecode queries

Hey all, I am trying to use the ASM bytecode Tree Api to do static analysis for a class. I guess I have a pretty basic question. In a method say foobar(), I have a list of instructions within foobar (InsnList which has a List). Now I want to check…
2
votes
1 answer

How to manipulate a class' bytecode just before it is loaded?

I am trying to find a way to manipulate the bytecode of a class (at runtime) just before it is loaded. I need to do this because the manipulation depends on something that is not present before main (and potentially before the subject class is…
Johnny
  • 67
  • 5
2
votes
1 answer

How to make Byte Buddy load many types into the same wrapper class loader

I'm using Byte Buddy in a scenario in which I could potentially need to create several dozen thousand classes with it. These are independent classes implementing interfaces, not proxies. Right now I'm loading my DynamicType.Unloaded instances…
2
votes
1 answer

ASM: visitLabel generates too many labels and nop instructions

ASM documentation says a label represent a basic block, and it is a node in the control graph. So I test the visitLabel method on this simple example: public static void main(String[] args) { int x = 3, y = 4; if (x < y) { x++; …
sean
  • 1,632
  • 2
  • 15
  • 34
2
votes
2 answers

How can I load a reference from a local variable at an index which is unknown at compile time?

As far as I understood the JVM bytecode specification, aload index pushes a reference found at index onto the current stackframe. In my case, I need to aload a reference found at an index which is stored in a local variable - something like this:…
NyxCode
  • 584
  • 1
  • 4
  • 13
2
votes
1 answer

Recompile Python bytecode instructions

Suppose I have a speak function: def speak(): print("moo") I can disassemble it as one usually does, with dis.dis: >>> dis.dis(speak) 2 0 LOAD_GLOBAL 0 (print) 3 LOAD_CONST 1 ('moo') …
Right leg
  • 16,080
  • 7
  • 48
  • 81
2
votes
1 answer

Why do popular frameworks use bytecode manipulation internally?

I heard that many frameworks (Struts, Spring, Hibernate, AspectJ) use bytecode manipulation internally. What are the compelling reasons to use bytecode manipulation? I'm expecting a answer with at least a use-case for each particular framework.
Nuwan Arambage
  • 683
  • 2
  • 7
  • 13
2
votes
1 answer

How to check bytecode length of java method

At this moment I participate in big legacy project with many huge classes and generated code. I wish to find all methods that have bytecode length bigger than 8000 bytes (because OOTB java will not optimize it). I found manual way like this: How…
2
votes
1 answer

problem with classes not found during PlayPlugin.enhance

I'm experimenting with a basic bytecode enhancement in a Play plugin, but when it tries to operate on the ApplicationClasses.ApplicationClass that it's given, the class can't be found. public void enhance(ApplicationClasses.ApplicationClass…
Brad Mace
  • 27,194
  • 17
  • 102
  • 148