
Java Virtual Machine
by Troy Downing, Jon MeyerThe Java Virtual Machine is the software implementation of a "CPU" designed to run compiled Java code. This includes stand-alone Java applications, as well as "applets" that are downloaded and run in Web browsers such as the NetScape Navigator. This book is a comprehensive programming guide for the Java Virtual Machine (JVM). The book is divided into two
Overview
The Java Virtual Machine is the software implementation of a "CPU" designed to run compiled Java code. This includes stand-alone Java applications, as well as "applets" that are downloaded and run in Web browsers such as the NetScape Navigator. This book is a comprehensive programming guide for the Java Virtual Machine (JVM). The book is divided into two sections: the first section includes information on the semantics and structure of the JVM; the second section is a reference of the JVM instructions, or "opcodes." This book is intended to give readers a strong overview and reference of the JVM so that they may create their own implementations of the JVM or write their own compilers that create Java object code. The programming guide includes numerous examples written in Java assembly language. A Java assembler is provided with the book, so the examples can all be compiled and executed. The reference section offers a complete description of the instruction set of the VM and the class file format, including a description of the byte-code verifier.Perhaps the most important reason for learning about the Java Virtual Machine is that it gives you additional tools for solving programming problems in Java. The Java architecture is very open it's easy to add programatic extensions to Java, once you have learned the basic rules of the Java Virtual Machine. And the Java Virtual Machine is portable, so you only have to write the extension once.So if you don't like how a particular feature of the Java language works, why not create an extension library that operates in the way you need it to? It's not as hard as you might think, and this book gives you all the details you need.For example, if your application has a lot of matrix manipulation code in it, you probably want to write the matrix equations using operators like *, +, / and -. But Java doesn't let you override these operators. The solution? Create a simple parser that compiles the matrix expressions into efficient JVM code directly. You can then call the resulting methods from any Java program, in any interpreter.Alternatively, you might be writing a rule-based application and want to express the rules using easy-to-read syntax. Create a JVM interface that lets you do this quickly, elegantly, and efficiently.Using JVM unleashes the true power of Java making it possible to develop additional syntaxes for expressing the problems you want to solve, and giving you the ultimate control over the performance of your application.So if you want to be ahead of the competition, get started on the JVM. Create applications that include operator overloading, user-extensible syntax words, dynamic generation of classes and methods, and much more. You can overcome design features of the Java language, or even create your own languages. And because of the architecture of the Java Virtual machine, you can do this simply, portably, and efficiently: your work will be accessible from any Java application, in any Java interpreter on nearly any computer.
Editorial Reviews
Under the Hood
By now, the mere mention of the word "Java" is enough to make most of us either swoon with delight or suffer hype-induced apoplexy. Aside from describing the latest version of the newest Java API/framework/IDE du jour, what else is left to say? Quite a lot, in fact, especially if you want to understand your tools from the inside out.
In Java Virtual Machine, which is based on Java 1.0.2, Jon Meyer and Troy Downing have written an interesting and useful book about the virtual machine that's at the core of every Java implementation. More so than most computer books, this book serves well as both tutorial and reference.
The tutorial material is in the first 11chapters ("Overview," "Quick Tour," "Components of the Machine," "Classes," "Security," "Implementation Notes," "Data Operations," "Arithmetic," "Flow Control," "Exceptions," and "Threads"), while the reference material is in the last two chapters ("Class File Reference" and "Instruction Reference") and four appendices.
In the opening chapters, Meyer and Downing provide a good overview of Java. One teaching tool they use is Jasmin, their Java assembler, which is included on a diskette -- with complete Java source, no less. I'm normally skeptical about the value of author-invented languages, even assembly variations, but the numerous Jasmin examples they present are a terrific aid. And best of all, you can use Jasmin for real work or experimentally to find new and creative ways to crash a JVM.
The 196-page "Instruction Reference" chapter is the heart of the reference material, and is exactly what most of us want --a detailed,instruction-by-instruction treatment of all opcodes required to implement a JVM, including example code, bytecodes, exceptions thrown, and cross references to related instructions.
For me, the most interesting parts of Java Virtual Machine discuss the code verifier and exceptions. The code verifier is the part of the JVM that attempts to ensure that a class file is robust and secure before running it, a very difficult task, and the source of at least one widely publicized Java bug. Support for exceptions turns out to be both more intricate and more elegant than I expected, thanks to the presence of finally blocks and the need to traverse the call chain to find a handler for the exception in question. The authors also show how simply JVMs handle virtual method invocation, and they provide a nice, brief discussion of garbage collection, something many programmers may not have considered in detail before working with Java.
I did have a few minor quibbles with Java Virtual Machine. The chapter on threads, far from being the meaty treatment I had hoped for, is a scant three pages in length. There are also several places where I suspect the authors' great familiarity with the material induced myopia. For example, they explain that the JVM will accept a 32-bit integer for some data types, and truncate the value as needed. One of the target types treated this way is boolean, which is defined as a single bit. This left me wondering if the high-order 31 bits really are ignored, or if JVMs use the common C convention of treating zero as False and any nonzero value as True. (In another place they say that only the integers 0 or 1 should be stored into a Boolean, which implies strict truncation really is used, and that Jasmin coders should be very careful about converting integers to Booleans.) In presenting the instructions that compare object references, Meyer and Downing say that equality means both references point to the same object, which is clear enough, but they skate over the issue of deep comparisons, something that should probably be mentioned at that point, however briefly.
As I wrote this review, CNN broadcast a tribute to Jacques Cousteau which quoted him as saying, "We must go and see for ourselves." The famous oceanographer spoke about a realm very different from the microcosm of Java's inner workings, but I believe the spirit still applies. After all, Meyer and Downing say that their book is for anyone "who is interested in Java technology and who wants to learn what goes on under the hood of the Java Virtual Machine." I agree; Java Virtual Machine is an excellent guide for programmers who are willing to delve beneath Java's surface and see for themselves.--Dr.Dobb's Electronic Review of computer Books
Product Details
- ISBN-13:
- 9781565921948
- Publisher:
- O'Reilly Media, Incorporated
- Publication date:
- 04/08/1997
- Series:
- Java Series
- Edition description:
- BK&DISK
- Pages:
- 450
- Product dimensions:
- 7.08(w) x 9.18(h) x 1.15(d)
Meet the Author
Customer Reviews
Average Review: