No description
Find a file
2020-11-18 18:54:40 +01:00
javap fixed a bug with wrong utf-8 length and added uniqueness checks. Improved the design 2020-11-10 12:49:10 +01:00
src added better support for methods, maxLocals and maxStack is now calculated (was dummy constant before). JavaOpcodes contains info about the number of pops/pushes and an indication of wide-ness (1 or 2 bytes for constantpool index) 2020-11-18 18:45:08 +01:00
.gitignore API draft, constant pool creator working in principle. A working test 2020-11-09 09:56:33 +01:00
pom.xml fixed a bug with wrong utf-8 length and added uniqueness checks. Improved the design 2020-11-10 12:49:10 +01:00
README.md minor change in readme 2020-11-18 18:54:40 +01:00

beejava

Beejava is a code creation library, somewhat comparable to javassist or bytebuddy.

  • It let's you compile java 'opcode' to bytecode.
  • It does not inspect or enhance existing bytecode, though it could be part of such functionality.

What is 'opcode'?

The goal of the project is to let developers dynamically create classes, using a simplified version of standard java opcodes. For instance: instead of having to choose between:

  • INVOKE_SPECIAL
  • INVOKE_VIRTUAL
  • INVOKE_DYNAMIC
  • INVOKE_INTERFACE

developers can just write INVOKE and the compiler will figure out the correct instruction to put in the class file.

project status:

early stage

  • At this moment a complete compile cycle is guaranteed (unittested) for a really simple class.

Code example below, but the API will undoubtedly change.

BeeSource createEmptyClass() {
    return BeeSource.builder()
           .withClassFileVersion(Version.V14)
           .withPackage("nl.sander.beejava.test")
           .withAccessFlags(PUBLIC, SUPER)
           .withSimpleName("EmptyBean")
           .withSuperClass(Object.class) // Not mandatory, like in java sourcecode
           .withConstructors(createDefaultConstructor()) // There's no default constructor in beejava. The user must always add them
           .build();
}

BeeConstructor createDefaultConstructor() {
    return BeeConstructor.builder()
            .withAccessFlags(MethodAccessFlags.PUBLIC)
            .withCode(
                    line(0, LD_VAR, Ref.THIS),
                    line(1, INVOKE, Ref.SUPER, "<init>", "()"),
                    line(5, RETURN))
            .build();
 }

Ideas about what's next

  • MORE opcodes
  • invoke dynamic support (also in constant pool)
  • support for exceptions, class attributes
  • figure out a nicer, better api, drop the line numbers
  • or instead drop this idea and let the developer write the raw bytecode. The constant pool would then be the only thing Beejava adds.
  • create a readable file format for opcode files