Search code examples
javabytecodebytecode-manipulation

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 people use to make their code fly with the help of bytecode manipulation.

Something like aspect oriented programming that was already mentioned or building proxy objects on the fly and similar techniques.


Solution

  • Bytecode manipulation lets you implement arbitrarily complex (and interesting) program transformations, such as:

    • entry/exit logging code for selected functions
    • security transformations that stub out access to certain API's
    • API substitution for, e.g., running code in a test harness.

    The scope is endless; this is just a small sampling.

    As for how this is typically done, start here.