|
|
|
|
Java Virtual MachineBy Jon Meyer & Troy Downing1st Edition March 1997 1-56592-194-1, Order Number: 1941 452 pages, $32.95, Includes diskette |
Java Virtual Machine: Preface
This book describes the Java Virtual Machine, the platform-independent engine used to run Java applets and applications. The book is designed for programmers who are familiar with the Java language and know a little C or C++. It includes introductory and tutorial material, as well as a reference section. The book serves as a "how-to" book--it includes lots of practical information, as well as code examples written for the Java Virtual Machine (or the JVM, as it is often referred to in this book). The material presented here is expected to complement the official JVM specifications released by Sun Microsystems.
Readers should be sure to check the "How to Use this Book" section towards the end of this Preface; it describes the structure of the book and explains how to get the most out of it.
Java Books and Resources
O'Reilly & Associates is developing a series of Java books. The series already includes an introductory volume, a quick reference, several tutorial volumes, several reference volumes, and now the Java Virtual Machine book you are holding. The series will be expanded to include a complete set of Java API reference manuals. In addition, the Java series will include additional volumes covering advanced topics in Java programming, such as Java Beans distributed computing. Refer to http://www.ora.com/publishing/java for a complete list of current and upcoming titles in the O'Reilly & Associates Java series.
Sun Microsystems has online reference documentation for the Java API and the Java Virtual Machine that you may find useful in conjunction with this book. You may want to visit http://www.javasoft.com/ to view or download this API documentation and other useful documents.
The author's own list of documentation related to the Java Virtual Machine can be found at http://cat.nyu.edu/meyer/jasmin.
Also, the comp.lang.java newsgroup is a central location for discussion of Java. The newsgroup has recently been split into several smaller subgroups, for specialized discussion, so be sure to read the FAQ list to find out which group is most appropriate for your needs.
About This Book
We believe that the Java Virtual Machine is one of the most exciting and important features of the Java technology. It is also one of the least accessible. Writing programs that work on the JVM level is painstaking and complicated, and there is little information available on the subject.
Sun has published a book about the Java Virtual Machine: the Java Virtual Machine Specification, by Tim Lindholm and Frank Yellin, available from Addison Wesley, ISBN 0-201-63452-X. The specification is an excellent reference work, and goes a long way to redress the shortfall of information available on the JVM, but it provides little overview material, only has very concise descriptions for many of the JVM instructions, and contains no concrete examples that you can type in and try out. All this is as it should be: the specification is intended as a detailed account of the semantics of the machine, a role it serves well.
This book is written to complement the JVM specification. Where the specification concentrates on giving detailed rules and semantics, in this book we aim to provide more introductory and accessible description, along with lots of actual examples that you can try. For instance, in this book we show how to write a ClassLoader; give pseudo-code showing how instance of works; present a Web applet as a JVM program; and much more.
In taking this approach, we had to give up something. Our book contains less detail in areas such as the rules of IEEE floating point arithmetic, the checks performed by the class verifier, or the semantics required by threads.
This doesn't mean the book is short on useful information. You will find dozens of examples that illustrate how the JVM actually works; the first part of the book contains a substantial overview of the machine; we've also included lots of notes based on our experiences working with the machine.
We believe the book covers all you need to know in order understand and write programs for the Java Virtual Machine. It also provides implementation notes and performance hints. Of course, some readers (especially systems implementors and language specialists) will want more detail. We encourage those readers to consult the official specification.
Target Audience
This book (and the software accompanying it) is designed for programmers, students, hobbyists, professionals, and anyone else who is interested in Java technology and who wants to learn what goes on under the hood of the Java Virtual Machine. Here are some reader profiles:
Teachers
If you are teaching a compilers course, you might consider using the Java Virtual Machine as a target platform for your student coursework. One advantage of this approach is that students can carry out homework on a large variety of machines (in fact, any machine that runs Netscape with Java enabled). Another advantage is that you can then integrate investigation of some of the features of the Virtual Machine (portability, the verifier, object model, type system) into your coursework.Hobbyists
This book gives you the tools you need to poke around in Java at the virtual machine level. If you are interested in gaining a real understanding of how Java works and what the Virtual Machine is like, this book is for you.System Implementors
If you are implementing a Java runtime system, or porting Java to a new platform, this book is a great starting point for learning how everything in the runtime system fits together.Advanced Programmers
Using this book, and the Jasmin software that comes with it, you can disassemble classes, see how they work, and even implement a critical class or method using the hand-coded Java assembler. Alternatively, you might use this book to gain a better understanding of efficiency issues in Java or to create an application that uses the JVM directly.Language Implementors
If you want to create an implementation of your favorite programming language that runs on the Java Virtual Machine, this books gives you all the details you need.Security Wizards
Sun's claim that Java protects you from hostile programs is a pretty strong one. This book helps you assess that claim yourself.Example Programs
In this book you will find many examples that show you how the Java Virtual Machine works.
We wanted to present these examples in an easy-to-read text format, so that you could quickly type in the examples on your system and try them out. However the Java specification does not include a text format for Java class files (it only describes the underlying binary byte format of Java class files).
For the purposes of writing a book, we created our own Java Virtual Machine assembler, called Jasmin. Jasmin takes text-based descriptions of Java class files, written in a simple easy-to-read syntax, and converts them into the appropriate binary class files. Using Jasmin, it's very easy to poke around, trying things out in the Virtual Machine. All of the VM examples in this book are written using the Jasmin syntax, and the reference section includes notes that describe in more detail the Jasmin syntax and the underlying bytecode format that Jasmin files are converted into.
Jasmin is available for free. If you did not receive Jasmin with this book, you can download it from the Web. Check http://www.ora.com/catalog/books/javavm or http://www.cat.nyu.edu/meyer/jasmin for details on how to obtain the latest release of Jasmin.
Request for Comments
We started this book in 1996. At that time, Sun had not released official documentation on the JVM, so much of our early work was based on guesswork and sleuthing. To write the book, we spent a lot of time poking at the internals of the JVM, reading the online material (at http://java.sun.com), and writing test programs using Jasmin. This research has enabled us to give you hard-earned insights into the workings of the Virtual Machine.
When Sun released the JVM specification this year, it contained a number of refinements and improvements not present in the earlier software (pre-JDK 1.0.2). We ended up rewriting much of the book to reflect these changes.
During this process, we made every effort to describe the technology fully and accurately, but it is possible we missed something--this is simply one of the drawbacks of working on the cutting edge of new technology.
We invite you to help us find problems and improve this book. If you have an idea that could make this a more useful reference for people working with the JVM, or if you find a bug or an error in the text, please let us know by sending email to bookquestions@ora.com.
If we find it necessary to issue an errata for this book, or release updated examples or reference information, you'll find the updated information at http://www.ora.com/catalog/books/javavm.
Java Versions
This book was based on Java version 1.02. As the book goes to press, Sun is in the process of releasing JDK 1.1 in beta form. From our preliminary look at this release, there appear to be no major changes to the bytecode format or instruction set of the JVM.
On the other hand, there are new classes in the java.* packages in 1.1, and some new attributes have been added to class files to support new features such as RMI and inner classes. Specifically, an InnerClasses attribute has been added to the top-level class file attributes, as well as a Synthetic attribute for class members.
We will maintain notes about these and other changes on the Web pages http://www.ora.com/catalog/books/javavm and http://www.cat.nyu.edu/meyer/jasmin.
How to Use This Book
This book is structured into three parts. The first part contains an overview of the machine; the second part is a guide to the instruction set; and the third part is the reference section.
If you are unfamiliar with the Java Virtual Machine, you will probably want to take this book off to a peaceful place and spend some time reading the first three chapters. Later, you can come back and study the rest of the chapters in the first part.
If you are trying to familiarize yourself with the instruction set of the JVM, take a look at the second part. It contains a quick tour of all of the instructions in the JVM, along with lots of examples.
If, on the other hand, you are trying to find out a specific detail on the operation of the Java Virtual Machine instruction, you will probably find it in the third part.
To help you locate what you are looking for, below is a brief summary of the contents of each of the chapters in this book.
Section One: Overview of Machine
- Chapter 1: Introduces the Java Virtual Machine, explaining where it came from, why it is interesting, and what its main characteristics are. After reading this chapter, you will be all set for Chapter 2.
- Chapter 2: Dives in and shows you the Java Virtual Machine in action. This chapter takes four example programs and explains how those programs are run by the Virtual Machine. It introduces you to Jasmin, a low-level assembler used to write programs that run on the Java Virtual Machine. After reading this chapter, you will have practical knowledge of topics such as the operand stack, local variables, class files, and method invocation,
- Chapter 3: This chapter takes a step back and describes each of the components of the Java Virtual Machine. It shows how the components fit together, and what they are used for. You will learn about concepts such as the constant pool, local variables, registers, data types, signatures, and garbage collection.
- Chapter 4: Contains an overview of how Java manages classes, and introduces the Java class file format. Since many of the Java VM instructions refer to data entities retrieved from a class file, understanding the contents of a Java class file is essential.
- Chapter 5: Java is designed as a secure language. Read this chapter to learn more about this claim and to learn about security features in the Java Virtual Machine such as the class verifier. Chapter 6: Outlines some of the things you will need to consider if you are implementing your own Java Virtual Machine.
Section Two: Instruction Guide
- Chapter 7: This chapter tells you how to create and manipulate objects and arrays using the Java Virtual Machine. You will learn more about the instructions provided for creating new arrays and objects, accessing fields, and storing and retrieving values from arrays.
- Chapter 8: Provides an overview of the set of instructions in the JVM for manipulating numeric values. In this chapter you will learn what instructions are provided, how they are organized, and other useful facts about numerical computation using Java.
- Chapter 9: Describes all of the instructions for branching, jumping, invoking methods, and performing boolean tests. You will learn how to use subroutines, dispatch methods, and implement switch statements.
- Chapter 10: Covers the Java exception mechanism. You will learn how to throw, catch and declare exceptions. You will see how the Java interpreter handles exceptions.
- Chapter 11: Describes instructions not covered elsewhere in the guide section of the book, including thread monitors and debugging instructions.
Section Three: Reference
- Chapter 12: Describes the Java class file format in detail.
- Chapter 13: Contains an alphabetical reference for of each of the nearly 200 instructions in the Java Virtual Machine.
- Chapter 14: Lists the instructions by function group.
- Chapter 15: Lists the instructions by their opcode.
- Appendix A: Lists the instructions by function group.
- Appendix B: Lists the instructions by their opcode.
- Appendix C: Contains the Jasmin User Guide, which gives notes on the syntax of the Jasmin assembler.
- Appendix D: A quick tour of JAS--a Java API for creating class files.
© 2001, O'Reilly & Associates, Inc.
webmaster@oreilly.com