
Facilitates dynamic Java class generation and manipulation at runtime through a byte code writer. Features include customizable JVM bytecode instructions, dynamic class loading, and a DSL-like interface for class construction.
Kasmine is a Kotlin Multiplatform library for writing JVM bytecode dynamically at runtime. It provides a DSL for defining classes, methods, fields, and bytecode instructions directly in Kotlin, enabling advanced use cases like runtime class generation, dynamic proxies, and bytecode manipulation.
version propertyDynamicClassLoader
val myClass = classBuilder {
access = 33u // public final
name = "MyDynamicClass"
version = 52 // Java 8 (default: 51 — Java 7)
method {
access = 9u // public static
name = "main"
signature = "([Ljava/lang/String;)V"
instructionBlock {
getstatic("java/lang/System", "out", "Ljava/io/PrintStream;")
ldc("Hello from Kasmine!")
invokevirtual("java/io/PrintStream", "println", "(Ljava/lang/String;)V")
return_()
}
}
}
val bytecode = myClass.write()
val clazz = DynamicClassLoader(null).define("MyDynamicClass", bytecode)
val mainMethod = clazz.getMethod("main", Array<String>::class.java)
mainMethod.invoke(null, arrayOf<String>())Add to your build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("nl.w8mr.kasmine:core")
}| Area | Status |
|---|---|
| Compact StackMapTable frames (SAME, APPEND, CHOP) | Planned — currently always emits full_frame (tag 255) |
| Full type tracking (Float, Double, Long) in dataflow | Planned — currently only Integer and Object references are tracked |
| Arithmetic / comparison opcodes (iadd, isub, ixor, if_icmpeq, etc.) | Planned |
| invokedynamic support | Planned |
| Exception handlers | Planned |
| Interfaces (implements) | Planned |
| Bootstrap methods | Planned |
| Instruction-level maxStack tracking on InstructionBlock | Planned — fields exist but aren't updated |
areturn with null and Object tracking |
Planned — currently treated as top-of-stack pop |
MIT License — see LICENSE.
Kasmine is a Kotlin Multiplatform library for writing JVM bytecode dynamically at runtime. It provides a DSL for defining classes, methods, fields, and bytecode instructions directly in Kotlin, enabling advanced use cases like runtime class generation, dynamic proxies, and bytecode manipulation.
version propertyDynamicClassLoader
val myClass = classBuilder {
access = 33u // public final
name = "MyDynamicClass"
version = 52 // Java 8 (default: 51 — Java 7)
method {
access = 9u // public static
name = "main"
signature = "([Ljava/lang/String;)V"
instructionBlock {
getstatic("java/lang/System", "out", "Ljava/io/PrintStream;")
ldc("Hello from Kasmine!")
invokevirtual("java/io/PrintStream", "println", "(Ljava/lang/String;)V")
return_()
}
}
}
val bytecode = myClass.write()
val clazz = DynamicClassLoader(null).define("MyDynamicClass", bytecode)
val mainMethod = clazz.getMethod("main", Array<String>::class.java)
mainMethod.invoke(null, arrayOf<String>())Add to your build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("nl.w8mr.kasmine:core")
}| Area | Status |
|---|---|
| Compact StackMapTable frames (SAME, APPEND, CHOP) | Planned — currently always emits full_frame (tag 255) |
| Full type tracking (Float, Double, Long) in dataflow | Planned — currently only Integer and Object references are tracked |
| Arithmetic / comparison opcodes (iadd, isub, ixor, if_icmpeq, etc.) | Planned |
| invokedynamic support | Planned |
| Exception handlers | Planned |
| Interfaces (implements) | Planned |
| Bootstrap methods | Planned |
| Instruction-level maxStack tracking on InstructionBlock | Planned — fields exist but aren't updated |
areturn with null and Object tracking |
Planned — currently treated as top-of-stack pop |
MIT License — see LICENSE.