Skip to content

Instantly share code, notes, and snippets.

@khotyn
Created March 4, 2012 14:24
Show Gist options
  • Save khotyn/1973207 to your computer and use it in GitHub Desktop.
Save khotyn/1973207 to your computer and use it in GitHub Desktop.
ASM Notes

ASM Notes

Core API

  • The ASM library is designed to work on compiled Java classes. It was also designed to be as fast and small as possible.
  • ASM provides tools to read, write and transfrom such byte arrays by using higher level concepts then bytes such as numeric constants, strings, Java identifiers, Java types, Java class structure elements.
  • The ASM is just a reference to the __asm__ keyword in C.
  • The core API provides an event based representation of classes, while the tree API provides an object based representation.
  • The CheckClassAdapter class could be used to check if the bytecode generated by ASM is valid.
  • The ASMifier class could be usedd to generate the source code of ASM for generating a specific class.
  • Argument values are statically known and are stored in the compiled code, while operand values come from the operand stack and are known only an runtime?
  • LocalVarialbeSorter is useful to insert new local variables in a method. Without this adapter it would be nassessary to add new local variables after all the existing ones, but unfortunatelly their number is not known until the end of the method, in visitMaxs.

Tree API

  • The tree API is generally used for transformations that cannot be implemented in one pass with the core API. But, there are of course exceptions. For example an obfuscator.
  • It is possible to use the tree API only for methods, and the core API for classes. In practice this strategy is often used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment