GitHub project: mikenakis-bytecode

A lightweight framework for manipulating JVM bytecode.

The mikenakis-bytecode Logo, an old-fashioned coffee grinder.
by Mike Nakis, based on original work by Gregory Sujkowski from the Noun Project.
Used under CC BY License.

What are the benefits of mikenakis-bytecode over javassist, ASM, and the like?

There are no benefits other than that the interface seems more simple, elegant and intuitive to me; of course, my opinion is biased, because I wrote it. So, let's just say that `mikenakis-bytecode` exists simply because I wanted to write it. For fun. That's how I roll.

What does mikenakis-bytecode have to offer?

`mikenakis-bytecode` was built with a simple philosophy: the framework should contain the bare minimum of features that are necessary in order to manipulate bytecode in an easy and error-free way, and these features should be simple, intuitive, and elegant, so that if you already know JVM bytecode and you just want a framework to work with it, all features of the framework should be self-explanatory so that you do not have learn the framework before you can begin using it.

For example, `mikenakis-bytecode` enables you to work with the contents of an individual class-file, but it is not concerned with relationships between class files. So, types referenced by the type being examined (like supertype, implemented interfaces, etc.) are simply identified by strings containing fully qualified type names. The framework does not offer any kind of abstraction for groups or hierarchies of classes, because that would have greatly increased not only the complexity of the implementation of the framework, but also the complexity of its interface: there would be a lot that you would have to learn before you could start using it.

As another example, `mikenakis-bytecode` facilitates easy generation of valid class files by completely shielding the programmer from having to deal with bytecode offsets. To achieve this, mikenakis-bytecode makes exclusive use of instruction references instead. This means that you can simply code a jump to a certain instruction, and `mikenakis-bytecode` will determine whether a 'short' or a 'long' form of a jump instruction should be used, and if necessary it will replace a short conditional jump with an inverted conditional short jump around an unconditional long jump.

Similarly, when it comes to coding stack frames, `mikenakis-bytecode` will not automatically generate stack frame entries for you, (because that's quite difficult,) but it will allow you to specify stack frames that simply reference target instructions, and it will pick the right subtype based on how long the actual offset to the target instruction turns out to be.

How does working with mikenakis-bytecode look like?

If you want to get an idea of how it looks like to be working with mikenakis-bytecode, you can see how it is used in these projects:
  1. For dumping the contents of class files in my mikenakis-classdump project
  2. For dependency analysis in my mikenakis-testana project
  3. For simple bytecode manipulation in my mikenakis-rumination project


Source code is hosted on GitHub: https://github.com/mikenakis/mikenakis-bytecode

Continuous Integration is hosted on CircleCI. (But they do not allow viewing unless you are logged in.)

The Artifact Repository is on Repsy: https://repo.repsy.io/mvn/mikenakis/mikenakis-public/mikenakis/


This creative work is explicitly published under No License. This means that I remain the exclusive copyright holder of this creative work, and you may not do anything with it other than view its source code and admire it. More information here: michael.gr - Open Source but No License.

If you would like to do anything more with this creative work, please contact me.

1 comment: