Java Glossary : JASM

CMP home Java glossary home Menu no menu Last updated 2004-07-02 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : J words : JASM.

JASM
Java Assembler. Pronounced "jazz-em", a generic term for assemblers for the JVM bytecodes. It also includes postfix assemblers. There are four ways to create class files of JVM byte codes:
  1. Write a Java program and compile it.
  2. Write a program in some other language such as NetRexx or JPython that support the JVM and compile it.
  3. Write a Jasmin program and assemble it, or use some other similar JASM assembler.
  4. Generate the hex byte codes directly. You might write them to disk and load them in the conventional way with Class.forName , or leave them in RAM and load them with a custom ClassLoader or use java.lang.ClassLoader.defineClass directly.
The easiest way to create class file on the fly is to generate Java source code then invoke the Javac or other compiler. Sometimes it is simpler to generate byte codes directly, such as a spreadsheet engine, a regex parser or a grammar parser since you can use cheating tactics like GOTO, and have precise control of the byte codes generated.

Jeroen Frijters (pronounced Yeroon Frighters) delivered a paper called On the Fly Byte Code Generation at the 1999 Colorado Software Conference. He wrote classes for creating byte codes. His email address is jeroen@sumatra.nl and his website is jeroen.nu.

Probably the easiest way to understand byte codes is to write sample Java code that does what you want, then disassemble it. Then it should become clear what you need to generate. Sun now has some classes for assembling byte code: see sun.reflect.ClassFileAssembler.

Key Byte Op Codes

Some of the more interesting byte codes include:
athrow throw an exception.
checkcast checks that a cast to another reference type is valid.
fadd adds top two floats on the stack and replaces them with the result. The JVM does not have a separate floating point stack.
goto At the byte code level there has to be a goto to implmement if/else branching.
iadd adds top two ints on the stack and replaces them with the result.
iconst push an integer literal to the stack.
instanceof replaces reference on top of stack with a boolean.
invokeinterface call a method when all you have is an interface reference to it.
invokespecial call a private instance method, and final instance methods where you can tell ahead of time which variant of the method you want.
invokestatic call a static method.
invokevirtual call a non-final instance method.
lookupswich used when switch case labels are not dense. Searches for a matching key and jumps.
new allocates RAM for objects.
pop drops the top element of the stack.
swap exchanges the top two elements of the stack.
tableswitch used when switch case labels are dense. Indexes into table for offset.
ASM Java byte code generator ¤ BCEL (Jakarta Byte Code Engineering Library ¤ Class.forName ¤ ClassLoader ¤ cglib: code generation library ¤ disassembler ¤ Jasmin ¤ Java Bytecode Assembler ¤ Javac.exe ¤ Jenesis ¤ JikesBT ¤ Oolong ¤ spreadsheet amanuensis


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 2911.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/jasm.html J:\mindprod\jgloss\jasm.html