JASM : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

JASM
Introduction Books
Key Byte Op Codes Learning More
Richer Class Files Links

Introduction

JASM (Java Assembler) . Pronounced jazz-em, a generic term for assemblers for the JVM (Java Virtual Machine) 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 (Random Access Memory) 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 Ye-roon Fright-ers) 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 http://weblog.ikvm.net/.

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. Oracle now has some classes for assembling byte code: see sun.reflect.ClassFileAssembler.

Key Byte Op Codes

Some of the more interesting byte codes include:
aastore store a reference in an array, making sure the type of the reference is compatible with the run-time type of the array.
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 implement if/else branching.
iadd adds top two ints on the stack and replaces them with the result.
iload push the value of a local integer variable to the top of the stack.
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 née invokenonvirtual in JDK (Java Development Kit) 1.0. Call a private instance method and final instance methods where you can tell ahead of time which variant of the method you want. Also used to call clinit, the code to initialise a new object prior to the constructor running. Also used to call super. someMethod, where you also know the class of the method to invoke at compile time.
invokestatic call a static method.
invokevirtual call a non-final instance method.
lookupswitch 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.

Richer Class Files

There are several techniques for persuading the compiler to add extra information into the class files:

Books

book cover recommend book⇒Inside The Java Virtual Machineto book home
by Bill Venners 978-0-07-135093-8 paperback
publisher McGraw-Hill
published 2000-01-06
Covers Java 2 JVM internals.
ISBN of first edition was 0-07-913248-0.
See the blurb.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag amazon.es amazon.ca Canadian flag
Spanish flag iberlibro.com Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Nook at Barnes & Noble American flag
India flag junglee.com Kobo American flag
UN flag other stores Google play American flag
O’Reilly Safari American flag
Powells American flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Programming For The Java Virtual Machineto book home
by Joshua Engel 978-0-201-30972-0 paperback
publisher Addison-Wesley
published 1999-07-02
From the reviews it looks like it too gets hung up on a proprietary assembler called Oolong. He does provide a code-generating class and spends one chapter on using it. I think the book would have been more useful if all the examples were in code-generator code, rather than an obscure dialect of assembler.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag amazon.es amazon.ca Canadian flag
Spanish flag iberlibro.com Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Nook at Barnes & Noble American flag
India flag junglee.com Kobo American flag
UN flag other stores Google play American flag
O’Reilly Safari American flag
Powells American flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Java(TM) Virtual Machine Specification, The second editionto book home
by Tim Lindholm and Frank Yellin 978-0-201-43294-7 paperback
publisher Prentice Hall
published 1999-04-24
Make sure you get the second edition. This book has an unusual copyright notice. You might want to read a different book if you plan to write a clean-room JVM. Read the version for Java 7 online.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag amazon.es amazon.ca Canadian flag
Spanish flag iberlibro.com Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Nook at Barnes & Noble American flag
India flag junglee.com Kobo American flag
UN flag other stores Google play American flag
O’Reilly Safari American flag
Powells American flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒The Java Virtual Machineto book home
by Joshua Engel 978-1-56592-194-8 paperback
publisher O’Reilly recommended
published 1997-04
Known known as the goldfish bowl book because of its cover. The book is frustrating because it spends so much time with the irrelevant Jasmin assembler and its syntax. You are interested in generating byte codes directly, not assembler. It leaves out much you must discover by experiment looking at generated class files, such as whether offsets are signed or absolute, where the base is etc. In its next revision, it should set the Jasmin aside in an appendix and include examples and more precise documentation on the binary formats. The book is still valuable because it gives a fair bit of background exposition you will not find in the vmspec itself. You would use this book to understand the VM, then the vmspec to actually write code that generated or modified class files. Out of print. You might want to read 9780201432947 Java(TM) Virtual Machine Specification, The second edition or the version for Java 7 online instead.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag amazon.es amazon.ca Canadian flag
Spanish flag iberlibro.com Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Nook at Barnes & Noble American flag
India flag junglee.com Kobo American flag
UN flag other stores Google play American flag
O’Reilly Safari American flag
Powells American flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.

Learning More



This page is posted
on the web at:

http://mindprod.com/jgloss/jasm.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\jasm.html
logo
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[54.91.243.175]
You are visitor number