JVM Assembler
A comprehensive Java Virtual Machine (JVM) assembler and class file manipulation library. It supports reading, analyzing, optimizing, and writing .class files.
🏛️ Architecture
graph TB
subgraph "JVM Toolchain Architecture"
A[JASM Source / Class File] --> B[JVM Program Model]
B --> C[Bytecode Analyzer]
C --> D[Bytecode Optimizer]
D --> E[Class File Writer]
E --> F[JVM Class Binary]
subgraph "Internal Components"
G[Constant Pool Manager]
H[Instruction Encoder]
I[Attribute Handler]
end
E --> G
E --> H
E --> I
end
🚀 Features
Core Capabilities
- Class File I/O: High-performance reading and writing of JVM Class files (supporting Java 8 to latest versions).
- Constant Pool Management: Automatic management of constant pool entries, including deduplication and slot allocation for Long/Double types.
- Bytecode Encoding: Full support for all JVM opcodes with automatic stack map frame generation (🚧) and branch offset calculation.
Advanced Features
- JASM Language: A custom assembly-like language (JASM) for human-readable JVM bytecode representation.
- Programmatic Builder: A fluent API for constructing classes, methods, and fields from scratch without writing raw bytecode.
- Analysis & Optimization: Built-in tools for control flow analysis and basic bytecode optimizations.
💻 Usage
Generating a "Hello World" Class
The following example demonstrates how to build a JVM class that prints "Hello Gaia" to the console.
use ;
use ClassWriter;
use fs;
🛠️ Support Status
| Feature | Support Level | Java Version |
|---|---|---|
| Basic Opcodes | ✅ Full | All |
| Constant Pool | ✅ Full | All |
| Annotations | ✅ Full | Java 5+ |
| Generics | ✅ Full | Java 5+ |
| Lambdas | ✅ Full | Java 8+ |
| Stack Map Frames | 🚧 In Progress | Java 6+ |
Legend: ✅ Supported, 🚧 In Progress, ❌ Not Supported
🔗 Relations
- gaia-types: Leverages
BinaryWriterwithBigEndianconfiguration for JVM-standard bytecode serialization. - gaia-assembler: Functions as the primary JVM backend, mapping Gaia IR to high-level JVM bytecode.