`
`GOOGLEEXHIBIT 1032
`
`Page 1 of 280
`
`GOOGLE EXHIBIT 1032
`
`
`
`haw
`
`Venners
`
`Page 2 of 280
`
`Page 2 of 280
`
`
`
`INSIDE THE JAVA
`VIRTUAL MACHINE
`SECOND EDITION
`
`Page 3 of 280
`
`
`
`Inside the
`Java
`Virtual
`Machine
`
`Bill Venners
`
`Second Edition
`
`McGraw-Hill
`New York San Francisco Washington, D.C.
`Auckland Bogota Caracas Lisbon London Madrid
`Mexico City Milan Montreal New Delhi San Juan
`Singapore Sydney Tokyo Toronto
`
`Page 4 of 280
`
`
`
`McGraw-Hill
`A Division ofTheMcGmw·HillCompanies iZ
`
`Copyright© 1999 by The McGraw-Hill Companies, Inc. All Rights Reserved.
`Printed in the United States of America. Except as permitted under the United
`States Copyright Act of 1976, no part of this publication may be reproduced or
`distributed in any form or by any means, or stored in a database or retrieval
`system, without the prior written permission of the publisher.
`
`Portions of this book were derived from articles written by Bill Venners and
`first published in the column "Under the Hood" of Java World, a division of Web
`Publishing, Inc., June, 1996 through October, 1997.
`
`1 2 3 4 5 6 7 8 9 0 AGM/AGM 9 0 4 3 2 1 0 9
`
`PIN 135094-2
`Part of ISBN 0-07-135093-4
`
`The sponsoring editor for this book was Simon Yates and the production
`supervisor was Clare Stanley. It was set in Century Schoolbook by Douglas &
`Gayle, Limited.
`Printed and bound by Quebecor I Martinsburg.
`
`Throughout this book, trademarked names are used. Rather than put a trade(cid:173)
`mark symbol after every occurrence of a trademarked name, we used the names
`in an editorial fashion only, and to the benefit of the trademark owner, with no
`intention of infringement of the trademark. Where such designations appear in
`this book, they have been printed with initial .caps.
`
`Information contained in this work has been obtained by The McGraw-Hill
`Companies, Inc. (''McGraw-Hill") from sources believed to be reliable. However,
`neither McGraw-Hill nor its authors guarantees the accuracy or completeness
`of any information published herein and neither McGraw-Hill nor its authors
`shall be responsible for any errors, omissions, or damages arising out of use of
`this information. This work is published with the understanding that
`McGraw-Hill and its authors are supplying information but are not attempt(cid:173)
`ing to render engineering or other professional services. If such servi,ces are
`required, the assistance of an appropriate professional should be sought.
`
`0
`
`This book is printed on recycled, acid-free paper containing a minimum of 50
`percent recycled de-inked fiber.
`
`Page 5 of 280
`
`
`
`To my parents
`To my parents
`
`Page 6 of 280
`
`Page 6 of 280
`
`
`
`CONTENTS
`
`Preface
`Introduction
`Acknowledgments
`
`Chapter 1
`
`Introduction to Javas Architecture
`
`Why Java?
`The Challenges and Opportunities of Networks
`The Architecture
`The Java Virtual Machine
`The Class Loader Architecture
`The Java Class File
`The Java API
`The Java Programming Language
`Architectural Tradeoffs
`Conclusion
`The Resources Page
`
`Chapter 2
`
`Platform Independence
`
`Why Platform Independence?
`Javas Architectural Support for Platform Independence
`The Java Platform
`The Java Language
`The Java Class File
`Scaleability
`Factors that Influence Platform Independence
`Java Platform Deployment
`The Java Platform Version and Edition
`Native Methods
`Non-Standard Run-Time Libraries
`Virtual Machine Dependencies
`User Interface Dependencies
`Bugs in Java Platform Implementations
`Testing
`Seven Steps to Platform Independence
`The Politics of Platform Independence
`Platform Independence and Network-Mobile Objects
`The ~esources Page
`
`XN
`XNii
`xxxii
`
`2
`2
`4
`5
`8
`11
`12
`14
`16
`21
`21
`
`23
`
`24
`25
`25
`26
`26
`26
`29
`29
`30
`31
`32
`33
`34
`34
`34
`35
`36
`39
`40
`
`vii
`
`Page 7 of 280
`
`
`
`viii
`
`Contents
`
`Chapter 3
`
`Security
`
`Why Security?
`The Basic Sandbox
`The Class Loader Architecture
`The Class File Verifier
`Pass One: Structural Checks on the Class File
`Pass Two: Semantic Checks on the Type Data
`Pass Three: Bytecode Verification
`Pass Four: Venfication of Symbolic References
`Binary Compatibility
`Safety Features Built Into the Java Virtual Machine
`The Security Manager and the Java API
`Code Signing and Authentication
`A Code-Signing Example
`Policy
`Policy File
`Protection Domains
`The Access Controller
`The implies{ ) Method
`Stack Inspection Examples
`A Stack Inspection That Says "Yes"
`A Stack Inspection That Says "No"
`The doPrivileged{ ) Method
`A Futile Use of doPrivileged{ )
`Missing Pieces and Future Directions
`Security Beyond the Architecture
`The Resources Page
`
`Chapter 4
`
`Network Mobility
`
`41
`
`42
`43
`45
`52
`53
`54
`54
`56
`58
`59
`62
`68
`75
`79
`82
`84
`86
`87
`90
`93
`97
`100
`105
`109
`110
`Ill
`
`113
`
`114
`Why Network Mobility?
`116
`A New Software Paradigm
`Javas Architectural Support for Network Mobility
`120
`122
`The Applet: An Example of Network-Mobile Code
`The Jini Service Object: An Example of Network-Mobile Objects 125
`126
`What is Jini?
`126
`How Jini Works
`129
`The Benefits of the Service Object
`Network Mobility: The Design Center of Java
`131
`132
`The Resources Page
`
`Page 8 of 280
`
`
`
`Chapter 5
`
`The Java Vrrtual Machine
`
`What Is a Java Virtual Machine?
`The Lifetime of a Java Virtual Machine
`The Architecture of the Java Virtual Machine
`Data Types
`Won] Size
`The Class Loader Subsystem
`The Method Area
`The Heap
`The Program Counter
`The Java Stack
`The Stack Frame
`Native Method Stacks
`Execution Engine
`Native Method Interface
`The Real Machine
`Eternal Math: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 6
`
`The Java Class File
`
`What Is a Java Class File?
`What Is in a Class File?
`Special Strings
`Fully Qualified Names
`Simple Names
`Descriptors
`The Constant Pool
`The CONSTANT_Utf8_info Table
`The CONSTANT _Integer _info Table
`The CONSTANT _Fioat_info Table
`The CONSTANT _Long_info Table
`The CONSTANT _Double_info Table
`The CONSTANT_Ciass_info Table
`The CONSTANT _String_info Table
`The CONSTANT _Fieldref_info Table
`The CONSTANT_Methodref_info Table
`The CONSTANT _lnterfaceMethodref_info Table
`The CONSTANT_NameAndType_info Table
`
`LJ
`
`133
`
`134
`134
`136
`139
`142
`142
`146
`154
`161
`162
`163
`172
`173
`186
`187
`188
`189
`190
`
`191
`
`192
`193
`201
`202
`202
`202
`205
`205
`207
`208
`208
`209
`209
`210
`211
`212
`212
`213
`
`Page 9 of 280
`
`
`
`Contents
`
`Fields
`Methods
`Attributes
`Attribute Format
`The Code Attribute
`The ConstantValue Attribute
`The Deprecated Attribute
`The Exceptions Attribute
`The lnnerCiasses Attribute
`The UneNumberTable Attribute
`The LocaiVariableTable Attribute
`The SourceFile Attribute
`The Synthetic Attribute
`Gett1ng Loaded: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 7
`
`The Lifetime of a Type
`
`Type Loading, Linking, and Initialization
`Load1ng
`Verification
`Preparation
`Resolution
`Initialization
`The Lifetime of an Object
`Class Instantiation
`Garbage Collection and Finalization of Objects
`Unloading of Types
`On the CD-ROM
`The Resources Page
`
`Chapter 8
`
`The Linking Model
`
`Dynamic Linking and Resolution
`Resolution and Dynamic Extension
`Class Loaders and the Parent-Delegation Model
`Constant Pool Resolution
`Resolution of CONSTANT_Ciass_info Entries
`Resolution of CONSTANT_Fieldref_info Entries
`Resolution of CONSTANT_Methodref_info Entries
`Resolution of CONSTANT _lnterfaceMethodref_info Entries
`Resolution of CONSTANT _String_info Entries
`
`214
`216
`218
`219
`220
`223
`224
`225
`225
`229
`231
`233
`234
`234
`236
`236
`
`237
`
`238
`240
`241
`244
`245
`245
`253
`254
`264
`265
`268
`268
`
`269
`
`270
`272
`276
`277
`278
`287
`288
`289
`290
`
`L
`
`Page 10 of 280
`
`
`
`Contents
`
`Resolution of Other Types of Entries
`Loading Constraints
`Compile-Time Resolution of Constants
`Direct References
`_quick Instructions
`Example: The Linking of the Salutation Application
`Example: The Dynamic Extension of the Greet Application
`Using a 1. 1 User-Defined Class Loader
`Using a Version 1 .2 User-Defined Class Loader
`Example: Dynamic Extension with forName{ )
`Example: Unloading Unreachable Greeters
`Example: Type Safety and Loading Constraints
`On the CD-ROM
`The Resources Page
`
`Chapter 9
`
`Garbage Collection
`
`Why Garbage Collection?
`Garbage Collection Algorithms
`Reference Counting Collectors
`Tracing Collectors
`Compacting Collectors
`Copying Collectors
`Generational Collectors
`Adaptive Collectors
`The Train Algorithm
`Cars, Trains, and a Railway Station
`Collecting Cars
`Remembered Sets and Popular Objects
`Finalization
`The Reachability Life Cycle of Objects
`Reference Objects
`Reachability State Changes
`Caches, Canonicalizing Mappings, and Pre-Mortem Cleanup
`Heap of Fish: A Simulation
`Allocate Fish
`Assign References
`Garbage Collect
`Compact Heap
`On the CD-ROM
`The Resources Page
`
`292
`292
`294
`296
`305
`306
`3 1 8
`323
`329
`333
`336
`343
`353
`353
`
`355
`
`356
`357
`358
`359
`359
`360
`362
`362
`363
`364
`366
`367
`368
`370
`37 1
`373
`376
`378
`379
`38 1
`382
`383
`384
`384
`
`Page 11 of 280
`
`
`
`LJ
`
`;
`
`Contents
`
`Chapter 10 Stack and Local Variable Operations
`
`Pushing Constants onto the Stack
`Generic Stack Operations
`Pushing Local Variables onto the Stack
`Popping to Local Variables
`The wide Instruction
`Fibonacci Forever: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 11
`
`Type Conversion
`
`The Conversion Opcodes
`Conversion Diversion: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 12
`
`Integer Arithmetic
`
`Twos-Complement Arithmetic
`Inner lnt: A Java int Reveals Its Inner Nature
`Arithmetic Opcodes
`Prime Time: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 13 Logic
`
`The Logic Opcodes
`Logical Results: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 14 Floating-Point Arithmetic
`
`Floating-Point Numbers
`Inner Float: A Java float Reveals its Inner Nature
`Floating Point Modes
`Floating-Point Value Sets
`Floating-Point Value Set Conversion
`Implications of the Relaxed Rules
`The Floating Point Opcodes
`Circle of Squares: A Simulation
`
`385
`
`386
`389
`389
`390
`392
`394
`397
`397
`
`399
`
`400
`402
`405
`405
`
`407
`
`408
`409
`409
`412
`416
`416
`
`417
`
`418
`419
`421
`422
`
`423
`
`424
`427
`428
`429
`430
`431
`431
`434
`
`·--
`
`Page 12 of 280
`
`
`
`Contents
`
`On the CD-ROM
`The Resources Page
`
`Chapter 15 Objects and Arrays
`
`A Refresher on Objects and Arrays
`Opcodes for Objects
`Opcodes for Arrays
`Three-Dimensional Array: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 16 Control Flow
`
`Conditional Branching
`Unconditional Branching
`Conditional Branching with Tables
`Saying Tomato: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 17 Exceptions
`
`Throwing and Catching Exceptions
`The Exception Table
`Play Ball!: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 18 Finally Clauses
`
`Miniature Subroutines
`Asymmetrical Invocation and Return
`Hop Around: A Simulation
`On the CD-ROM
`The Resources Page
`
`Chapter 19 Method Invocation and Return
`
`Method Invocation
`Invoking a Java Method
`Invoking a Native Method
`Other Forms of Method Invocation
`The invokespecial Instruction
`invokespecial and <init>()
`
`LJ
`
`436
`436
`
`437
`
`438
`438
`440
`443
`447
`447
`
`449
`
`450
`453
`453
`455
`457
`458
`
`459
`
`460
`464
`465
`468
`468
`
`469
`
`470
`471
`474
`477
`478
`
`479
`
`480
`481
`482
`482
`483
`483
`
`Page 13 of 280
`
`
`
`I
`l.__ __ xiv
`
`r
`
`!
`
`Contents
`
`invokespecial and Private Methods
`invokespeCial and super
`The invokeinterface Instruction
`Invocation Instructions and Speed
`Examples of Method Invocation
`Returning from Methods
`On the CD-ROM
`The Resources Page
`
`Chapter 20 Thread Synchronization
`
`Monitors
`Object Locking
`Synchronization Support 1n the Instruction Set
`Synchronized Statements
`Synchronized Methods
`Coordination Support 1n Class Object
`On the CD-ROM
`The Resources Page
`
`Appendix A
`Appendix B
`Appendix C
`Appendix D
`
`Index
`
`486
`487
`490
`490
`491
`495
`496
`496
`
`497
`
`498
`503
`505
`505
`508
`51 I
`51 I
`512
`
`513
`649
`659
`667
`
`677
`
`i
`I
`
`_L
`
`Page 14 of 280
`
`
`
`-
`
`PREFACE
`
`My primary goal in writing this book was to explain the Java virtual
`machine-and several core Java APis closely related to the virtual
`machine-to Java programmers. Although the Java virtual machine
`incorporates technologies that have been tried and proven in other pro(cid:173)
`gramming languages, prior to Java, many of these technologies had not
`yet entered into common use. As a consequence, many programmers will
`encounter these technologies for the first time as they begin to program
`in Java. Garbage collection, multi-threading, exception handling, dynamic
`extension-even the use of a virtual machine itself-might be new to
`many programmers. The aim of this book is to help programmers under(cid:173)
`stand how all these things work, and in the process we hope to help them
`become more adept at Java programming.
`Another goal I had in mind as I wrote this book was to experiment a
`bit with the changing nature of text. Web pages have three interesting
`characteristics that differentiate them from paper-based text: they are
`dynamic (can evolve over time), they are interactive (especially if you
`embed Java applets in them), and they are interconnected (you can eas(cid:173)
`ily navigate from one to another). Besides the traditional text and figures,
`this book includes several Java applets (in a mini-Web site on the
`CD-ROM) that serve as interactive illustrations of the concepts presented
`in the text. In addition, I maintain a Web site at artima. com on the
`Internet that serves as a launching point for readers to find more (and
`more current) information about the topics covered in the book. This book
`is composed of all of these components: text, figures, interactive illustra(cid:173)
`tions, and constantly evolving links to further reading.
`
`Bill Venners
`
`XV
`
`Page 15 of 280
`
`
`
`-
`
`-
`
`INTRODUCTJON
`This book describes the Java virtual machine, the abstract computer on
`which all Java programs run, and several core Java APis that have an inti(cid:173)
`mate relationship with the virtual machine. Through a combination of tuto(cid:173)
`rial explanations, working examples, reference material, and applets that
`interactively illustrate the concepts presented in the text, this book pro(cid:173)
`vides an in-depth, technical survey of Java as a technology.
`The Java programming language seems poised to be the next popular lan(cid:173)
`guage for mainstream commercial software development-the next step after
`C and C++. One of the fundamental reasons why Java is a likely candidate for
`this role is that Java's architecture helps programmers deal with emerging
`hardware realities. Java has features that the shifting hardware environment
`is demanding-features that are made possible by the Java virtual machine.
`The evolution of programming languages has (to a great extent) been
`driven by changes in the hardware being programmed. As hardware has
`grown faster, cheaper, and more powerful, software has become larger and
`more complex. The migration from assembly languages to procedural lan(cid:173)
`guages, such as C, and to object oriented languages, such as C++, was
`largely driven by a need to manage ever greater complexity-complexity
`made possible by increasingly powerful hardware.
`Today, the progression towards cheaper, faster, and more powerful hardwEJTe
`continues, as does the need for managing increasing software complexity.
`Building on C and C++, Java helps programmers deal with complexity by ren(cid:173)
`dering impossible certain kinds ofbugs that frequently plague C and C++ pro(cid:173)
`grammers. Java's inherent memory safety-garbage collection, lack of pointer
`arithmetic, and run-time checks on the use of references-prevents most mem(cid:173)
`ory bugs from ever occurring in Java programs. Java's memory safety makes
`programmers more productive and helps them manage complexity.
`In addition, besides the ongoing increase in the capabilities of hard(cid:173)
`ware, there is another fundamental shift taking place in the hardware
`environment: the network. As networks interconnect more and more com(cid:173)
`puters and devices, new demands are being made on software. With the
`rise of the network, platform independence and security have become
`more important than they were in the past.
`The Java virtual machine is responsible for the memory safety, platform
`independence, and security features of the Java programming language.
`Although virtual machines have been around for a long time, prior to
`Java, they had not quite entered the mainstream. Given today's emerging
`
`xvii
`
`Page 16 of 280
`
`
`
`Introduction
`
`hardware realities, however, software developers needed a programming
`language with a virtual machine, and Sun hit the market window with Java.
`Thus, the Java virtual machine embodies the right software features
`for the coming years of computing. This book will help you get to know
`this virtual machine and some closely related Java APis. Armed with this
`knowledge, you will be better able to take maximum advantage of Java's
`unique architecture in your own endeavors.
`
`Who Should Read the Book?
`
`This book is aimed primarily at professional software developers and stu(cid:173)
`dents who want to understand Java technology. I assume that you are
`familiar, although not necessarily proficient, with the Java language.
`Reading this book should help you add a depth to your knowledge of Java
`programming. If you are one of the elite few who are actually writing Java
`compilers or creating implementations of the Java virtual machine, this
`book can serve as a companion to the Java virtual machine specification.
`Where the specification specifies, this book explains.
`
`How to Use the Book
`
`This book has five basic parts:
`
`1. An introduction to Java's architecture (Chapters 1 through 4)
`2. An in-depth, technical tutorial of Java internals (Chapters 5
`through 20)
`3. A class file and instruction set reference (Chapter 6 and Appen(cid:173)
`dixes A through C)
`4. Interactive illustrations and example source code (on the
`CD-ROM)
`5. The Java Virtual Machine Resources Page (http : I I www. art i rna .
`comlinsidejvmlresourcesl)
`
`An Introduction to Java's Architecture
`
`Chapters 1 through 4 (Part I of this book) give an overview of Java's archi(cid:173)
`tecture, including the motivations behind (and the implications of) Java's
`
`Page 17 of 280
`
`
`
`Introduction
`
`xix
`
`architectural design. These chapters show how the Java virtual machine
`relates to the other components of Java's architecture: the class file, API,
`and language. If you want a basic understanding of Java as a technology,
`consult these chapters. Here are some specific points of interest from this
`portion of the book:
`
`81 For an overview of Java's architecture and a discussion of its inher(cid:173)
`ent tradeoff's, see Chapter 1, "Introduction to Java's Architecture."
`81 For a discussion of what platform independence really means, how
`Java's architecture supports this feature, and seven steps to create
`a platform-independent Java program, see Chapter 2, "Platform
`Independence."
`II For a description of the security model built into Java's core archi(cid:173)
`tecture, including an elaborate working example that demon(cid:173)
`strates the fine-grained access control made possible by the
`Version 1.2 security framework, see Chapter 3, "Security."
`81 For a discussion of the new paradigm of network-mobile software,
`see Chapter 4, "Network Mobility."
`
`A Tutorial of Java Internals
`
`Chapters 5 through 20 (Part II of this book) give an in-depth technical
`description of the inner workings of the Java virtual machine and related
`core Java APis. These chapters will help you understand how Java pro(cid:173)
`grams actually work. All of the material in Part II is presented in a tuto(cid:173)
`ria1 manner with many examples. Here are some specific points of interest
`from this portion of the book:
`
`81 For a comprehensive overview of the inner workings of the Java
`virtual machine, see Chapter 5, "The Java Virtual Machine."
`81 If you are parsing, generating, or simply peering into Java class
`files, see Chapter 6, "The Java Class File," for a complete tutorial
`and reference on the class file format.
`81 For a discussion of the lifetime of a class inside the Java virtual
`machine, including the circumstances in which classes can be
`unloaded, see Chapter 7, "The Lifetime of a Type."
`81 For a thorough explanation of Java's linking model, including a
`tutorial and examples on using forName () and class loaders to
`dynamically extend Java applications with new types at run time,
`see Chapter 8, "The Linking Model."
`
`Page 18 of 280
`
`
`
`lxxJ
`
`t
`
`.
`
`Introduction
`
`Ill For a discussion of garbage collection and finalization, an explana(cid:173)
`tion of soft, weak, and phantom references, and suggestions on
`how to use finalizers, see Chapter 9, "Garbage Collection."
`Ill For a tutorial on the Java virtual machine's instruction set, read
`Chapters 10 through 20.
`Ill For an explanation of monitors and how you can use them to write
`thread-safe Java code, see Chapter 20, "Thread Synchronization."
`
`A Class File and Instruction Set Reference
`
`In addition to being a tutorial on the Java class file, Chapter 6, "The Java
`Class File," serves as a complete reference of the class file format. Simi(cid:173)
`larly, Chapters 10 through 20 form a tutorial of the Java virtual machine's
`instruction set, and Appendixes A through C serve as a complete refer(cid:173)
`ence of the instruction set. If you need to look up something, check out
`these chapters and the appendixes.
`
`Interactive Illustrations and
`Example Source Code
`
`For most of this book's chapters, material associated with the chapter(cid:173)
`such as example code or simulation applets-appears on the CD-ROM.
`The applets directory of the CD-ROM contains a mini-Web site called
`the "Interactive Illustrations Web Site," which includes 15 Java applets
`that illustrate the concepts presented in the text. These interactive illus(cid:173)
`trations form an integral part of this book. Eleven of the applets simulate
`the Java virtual machine by executing bytecodes. The other applets illus(cid:173)
`trate garbage collection, twos-complement and IEEE 754 floating-point
`numbers, and the process of loading of class files. The applets can be
`viewed on any platform by any Java-capable browser. The source code for
`the simulation applets is also included on the CD-ROM.
`The copyright notice accompanying the HTML, . java, and . class
`files for the Interactive Illustrations Web Site enables you to post the Web
`site on any network, including the Internet-providing that you adhere
`to a few simple rules. For example, you must post the Web site in its
`entirety (you cannot make any changes to it), and you cannot charge peo-
`
`Page 19 of 280
`
`
`
`Introduction
`
`-
`
`ple to look at the site. The full text of the copyright notice is given in the
`introduction to this book.
`All of the example source code shown in this book appears on the
`CD-ROM in both source and compiled (class files) form. If some example
`code in the text strikes you as interesting (or dubious), you can try it for
`yourself.
`Most of the example code is for illustrative purposes and is not likely
`to be of much practical use besides helping you understand Java. Never(cid:173)
`theless, you are free to cut and paste from the example code, use it in your
`own programs, and distribute it in binary (such as Java class file) format.
`The full text of the copyright notice for the example source code is shown
`in the introduction.
`
`The Java Virtual Machine Resources Page
`
`To help you find more information and keep abreast of changes, I main(cid:173)
`tain several pages at artima.com with links to further reading about the
`material presented in this book. The main URL for these pages of links
`is the Java Virtual Machine Resources Page at http: I /www. artima.
`com/insidejvm/resources/.
`
`Chapter-by-Chapter Summary
`
`Part 1: Java's Architecture
`
`Chapter 1: Introduction to Java's Architecture This chapter gives
`an introduction to Java as a technology and gives an overview of Java's
`architecture, discusses why Java is important, and examines Java's pros
`and cons.
`
`Chapter 2: Platform Independence This chapter shows how Java's
`architecture enables programs to run on any platform, discusses the fac(cid:173)
`tors that determine the true portability of Java programs, and examines
`the relevant tradeoffs.
`
`Chapter 3: Security This chapter gives an in-depth overview of the secu(cid:173)
`rity model built into Java's core architecture and traces the evolution of
`
`Page 20 of 280
`
`
`
`l~ii
`
`Introduction
`
`Java's security model, from the basic sandbox ofVersion 1.0 through the code
`signing and authentication ofVersion 1.1, to the fine-grained access control
`ofVersion 1.2.
`
`Chapter 4: Network Mobility This chapter examines the new para(cid:173)
`digm of network-mobile software heralded by the arrival of Java and
`shows how Java's architecture makes this functionality possible.
`
`Part II: Java Internals
`
`Chapter 5: The Java Virtual Machine This chapter gives a detailed
`overview of the Java virtual machine's internal architecture. Accompa(cid:173)
`nying the chapter on the CD-ROM is an applet called Eternal Math, which
`simulates the Java virtual machine by executing a short sequence of byte(cid:173)
`codes.
`
`Chapter 6: The Java Class File This chapter describes the contents
`of the class file, including the structure and format of the constant pool,
`and serves as both a tutorial and a complete reference for the Java class
`file format. Accompanying the chapter on the CD-ROM is an applet called
`Getting Loaded, which simulates the process of the Java virtual machine
`loading a Java class file.
`
`Chapter 7: The Lifetime of a Class This chapter follows the lifetime
`of a type (class or interface) from the type's initial entrance into the vir(cid:173)
`tual machine to its ultimate exit. The chapter discusses the processes of
`loading, linking, and initialization; object instantiation, garbage collec(cid:173)
`tion, and finalization; and type unloading.
`
`Chapter 8: The Linking Model This chapter takes an in-depth look
`at Java's linking model and describes the parent-delegation model of class
`loaders, constant pool resolution, name spaces, and loading constraints.
`The chapter also shows how to use forName () and class loaders to enable
`a Java application to dynamically extend itself at run time.
`
`Chapter 9: Garbage Collection This chapter describes various
`garbage-collection techniques and explains how garbage collection works
`in Java virtual machines, including a discussion of the train algorithm
`and soft, weak, and phantom references. Accompanying this chapter on
`
`Page 21 of 280
`
`
`
`Introduction
`
`xxiii
`
`the CD-ROM is an applet called Heap of Fish, which simulates a com(cid:173)
`pacting, mark-and-sweep, garbage-collected heap.
`
`Chapter 10: Stack and Local Variable Operations This chapter
`describes the Java virtual machine instructions that focus most exclu(cid:173)
`sively on the operand stack-those that push constants onto the operand
`stack, perform generic stack operations, and transfer values back and
`forth between the operand stack and local variables. Accompanying this
`chapter on the CD-ROM is an applet called Fibonacci Forever, which sim(cid:173)
`ulates the Java virtual machine executing a method that generates the
`Fibonacci sequence.
`
`Chapter 11: Type Conversion This chapter describes the instructions
`that convert values from one primitive type to another. Accompanying the
`chapter on the CD-ROM is an applet called Conversion Diversion, which
`simulates the Java virtual machine's execution of a method that performs
`type conversion.
`
`Chapter 12: Integer Arithmetic This chapter describes integer arith(cid:173)
`metic in the Java virtual machine, explains twos-complement arithmetic,
`and describes the instructions that perform integer arithmetic. Accompa(cid:173)
`nying this chapter on the CD-ROM are two applets that interactively
`illustrate the material presented in the chapter. One applet, called Inner
`Int, enables you to view and manipulate a twos-complement number. The
`other applet, called Prime Time, simulates the Java virtual machine exe(cid:173)
`cuting a method that generates prime numbers.
`
`Chapter 13: Logic This chapter describes the instructions that per(cid:173)
`form bitwise, logical operations inside the Java virtual machine. These
`instructions include opcodes to perform shifting and Boolean operations
`on integers. Accompanying this chapter on the CD-ROM is an applet
`called Logical Results, which simulates the Java virtual machine's exe(cid:173)
`cution of a method that uses several of the logic opcodes.
`
`Chapter 14: Floating-Point Arithmetic This chapter describes the
`floating-point numbers and the instructions that perform floating-point
`arithmetic inside the Java virtual machine specification. Accompanying
`this chapter on the CD-ROM are two applets that interactively illustrate
`the material presented in the chapter. One applet, called Inner Float,
`enables you to view and manipulate the individual components that make
`up a floating-point number. The other applet, called Circle of Squares,
`
`Page 22 of 280
`
`
`
`xxiv
`
`IntrodJ.Iction
`
`simulates the Java virtual machine's execution of a method that uses sev(cid:173)
`eral floating-point opcodes.
`
`Chapter 15: Objects and Arrays This chapter describes the Java vir(cid:173)
`tual machine instructions that create and manipulate objects and arrays.
`Accompanying this chapter on the CD-ROM is an applet called Three(cid:173)
`DimensionalArray, which simulates the Java virtual machine's execution
`of a method that allocates and initializes a three-dimensional array.
`
`Chapter 16: Control Flow This chapter describes the instructions
`that cause the Java virtual machine to conditionally or unconditionally
`branch to a different location within the same method. Accompanying this
`chapter on the CD-ROM is an applet called Saying Tomato, which simu(cid:173)
`lates the Java virtual machine's execution of a method that includes byte(cid:173)
`codes that perform table jumps (the compiled version of a Java switch
`statement).
`
`Chapter 17: Exceptions This chapter shows how exceptions are imple(cid:173)
`mented in bytecodes and describes the instruction for throwing an excep(cid:173)
`tion explicitly, explains exception tables, and shows how catch clauses
`work. Accompanying this chapter on the CD-ROM is an applet called Play
`Ball!, which simulates the Java virtual machine executing a method that
`throws and catches exceptions.
`
`Chapter 18: Finally Clauses This chapter shows how finally clauses
`are implemented in bytecodes and describes the relevant instructions
`with examples of their use. The chapter also describes some surprising
`behavior exhibited by finally clauses in Java source code and explains this
`behavior at the bytecode level. Accompanying this chapter on the
`CD-ROM is an applet called Hop Around, which simulates the Java vir(cid:173)
`tual machine executing a method that includes finally clauses.
`
`Chapter 19: Method Invocation and Return This chapter describes
`the four instructions that the Java virtual machine uses to invoke meth(cid:173)
`ods and the situations in which each instruction is used.
`
`Chapter 20: Thread Synchronization This chapter describes moni(cid:173)
`tors-the mechanism that Java uses to support synchronization-and
`shows how they are used by the Java virtual machine. The chapter also
`shows how one aspect of monitors, the locking and unlocking of data, is sup(cid:173)
`ported in the instruction set.
`
`Page 23 of 280
`
`
`
`Introduction
`
`-
`
`LJ
`
`Appendix A: Instruction Set by Opcode Mnemonic This appendix
`lists the opcodes alphabetically by mnemonic. For each opcode, you are
`given the mnemonic, opcode byte value, instruction format (the operands,
`if any), a snapshot image of the stack before and after the instruction is
`executed, and a description of the instruction's execution. Appendix A
`serves as the primary instruction -set reference of the book.
`
`Appendix B: Opcode Mnemonic by Functional Group This appen(cid:173)
`dix organizes the instructions by functional group. The organization used
`in this appendix corresponds to the order in which the instructions are
`described in Chapters 10 through 20.
`
`Appendix C: Opcode Mnemonic by Opcode This appendix orga(cid:173)
`nizes the opcodes in numerical order. For each numerical value, you are
`given the mnemonic.
`
`Appendix D: Slices of Pi: A Sim