### Java Assembler Tools (AsmTools) User’s Guide
---
### Using the AsmTools
This chapter describes general principles and techniques for using the AsmTools.
If no command-line options are provided, or they are invalid, the tools display
error messages and usage information. To get the help message, launch AsmTools
without parameters:
```bash
java -jar asmtools.jar
```
The help system describes how to use all the AsmTools components and contains
the following topics described in this chapter.
- [Assemblers and Disassemblers](#BADGCIGA)
- [JASM vs JCOD](#BADGCIGB)
- [Tool Usage](#BADCEIIF)
- [ASMTools (Launcher)](BADCEABC)
- [JASM](#BADEFIIJ)
- [JDIS](#BADCBFCE)
- [JCODER](#BADIFAIE)
- [JDEC](#BADHJAHI)
---
### Assemblers and Dissassemblers
Assembly and disassembly are reflexive operations. One tool’s output can be fed
into another to reproduce the same file.
```bash
java -jar asmtools.jar jdec Foo.class # produces Foo.jcod
java -jar asmtools.jar jcoder Foo.jcod # produces Foo.class
java -jar asmtools.jar jdis Foo.class # produces Foo.jasm
java -jar asmtools.jar jasm Foo.jasm # produces Foo.class
```
For a given `foo.class`, the result of disassembly followed by reassembly is the
same `foo.class`.
---
### JASM vs JCOD
Which format to use depends on the task you are trying to do.
We can describe some generalizations of when you might wish to use the `JASM` format versus the `JCOD` format.
#### JASM
The biggest difference between the two formats is that `JASM` specifically focuses on representing byte-code instructions in the VM format
(while providing minimal description of the structure of the rest of the class file).
Generally, `JASM` is more convenient for semantic changes, like change to instruction flow.
Typical JASM use cases:
- Producing invalid classes in which two methods have the same signature
- Producing invalid class references that use illegal types
- Generating invalid classes with missing or removed instructions
- Inserting instrumentation or profiling instructions into methods
- Creating classes in which language keywords are used as identifiers
- Verifying that two classes produced by different compilers are equivalent
#### JCOD
`JCOD` provides good support for describing the structure of a class file
(as well as writing incorrect bytes outside of this structure),
and provides no support for specifying byte-code instructions (simply raw bytes for instructions).
`JCOD` is typically used for VMs to test Well-formedness of class files (e.g. extra or missing bytes),
boundary issues, constant-pool coherence, constant-pool index coherence, attribute well-formedness, etc.
Typical JCOD use cases:
- Examining specific parts of a class file, such as:
- the constant pool (for dependency analysis)
- constant values
- inheritance chains (superclasses)
- interface implementation and resolution
- Producing malformed or structurally invalid class files for JVM testing
- Validating class-file well-formedness rules
- Testing boundary conditions and structural constraints
- Verifying attribute structure and consistency
---
### Tool Usage
AsmTools consists of the following utilities:
- [jasm](#BADEFIIJ) – Generates class files from `JASM`
- [jdis](#BADCBFCE) – Disassembles class files into `JASM`
- [jcoder](#BADIFAIE) – Generates class files from `JCOD`
- [jdec](#BADHJAHI) – Disassembles class files into `JCOD`
Each utility can be invoked as:
```bash
java -jar asmtools.jar UTILITY [options] File1 ...
```
or
```bash
java -cp asmtools.jar com.sun.asmtools.UTILITY.Main [options] File1 ...
```
Each utility supports own set of options.
---
**Note**: See the following sections for the options associated with each tool.
---
### ASMTools (Launcher)
The `asmtools.jar` launcher provides a single entry point to run one of the AsmTools utilities (`jasm`, `jdis`, `jcoder`, or `jdec`)
and to display global help/version information.
**Usage**:
```text
java -jar asmtools.jar run jasm, jdis, jcoder, or jdec tool
or: java -jar asmtools.jar -?|-h|-help print Help (this message) and exit
or: java -jar asmtools.jar -version print version information and exit
use -dls switch to return the ancient dual stream logging
```
---
### JASM
`JASM` assembles a `.jasm` source file, written according to the [JASM Specification](JASM_SPEC), into a `.class` file
for use with a Java Virtual Machine.
**Usage**:
```text
java -jar asmtools.jar jasm [options] |-
```
or
```text
java -cp asmtools.jar org.openjdk.asmtools.jasm.Main [options] |-
```
**Note**: if `-` is provided, `` is used as the input stream.
#### Options:
```text
-d Specify where to place generated class files, otherwise
-w Specify where to place generated class files, without considering the classpath, otherwise
-nowrite Do not write generated class files
-nowarn Do not print warnings
-strict Consider warnings as errors
-cv Set operating class file version if not specified in the source file (by default 45.3)
-fixcv Override class file version in source file(s)
-fixcv Update class file version to major.minor if file's version is below the threshold()
-t Print debug, trace information
-v Print additional information
-version Print the jasm version
```
#### Notes:
1. **Class-file generation behavior**
The `-nowrite` option always suppresses generation of the `.class` file.
Without `-nowrite`, warnings prevent class-file generation only when `-strict` is specified; otherwise, the class file is written.