
Résumé
The core of Java technology, the Java virtual machine is
an abstract computing machine that enables the Java
platform to host applications on any computer or operating
system without rewriting or recompiling. Anyone interested
in designing a language or writing a compiler for the Java
virtual machine must have an in-depth understanding of its
binary class format and instruction set. If you are
programming with the Java programming language, knowledge
of the Java virtual machine will give you valuable insight
into the Java platform's security capabilities and
cross-platform portability. It will increase your
understanding of the Java programming language, enabling
you to improve the security and performance of your
programs.
The author employs a tutorial approach that provides a
detailed look into the central workings of the technology
and teaches the reader how to write real programs for the
Java virtual machine. He describes methods for becoming a
better programmer through an advanced understanding of the
Java virtual machine and Java technology. Programming for
the Java Virtual Machine offers comprehensive coverage of
all the major elements of the Java virtual machine--classes
and objects, control instructions, debugging, class
loaders, compiling the Java programming language,
performance issues, security, and threads and
synchronization. The book provides an introduction to the
Java Virtual Machine Specification (JVMS), with a
collection of topics that help programmers understand the
Java virtual machine and the JVMS better. In addition, the
book features implementations of Prolog and Scheme, a
language that runs on top of the Java virtual machine,
generating Java virtual machine code as it runs and using a
Java virtual machine class loader to load the generated
code into the system.
You will find detailed information on such topics as:
- The Java virtual machine verification algorithm
- How Java virtual machine security works, and what it
can and can't do
- Using class loaders to incorporate code and dynamically
generated code from the Internet, the Java Foundation
Classes, database queries, and other languages
- The mechanics of compiling the Java programming
language for the Java virtual machine
- Implementing other languages using the Java virtual
machine, including Scheme, Prolog, Sather, Eiffel, and
regular expressions
Numerous examples illustrate techniques and concepts, and
exercises with solutions help you gain practical
experience.
Contents
Preface xvii
1 Introduction to the Java Virtual Machine 1
1.1 Java Virtual Machine and Java 2
1.2 What Is the Java Virtual Machine? 3
1.2.1 Instruction Set 3
1.2.2 class File Format 5
1.2.3 Verification 5
1.3 Java Platform 6
1.4 Organization of the Java Virtual Machine 7
1.4.1 Class Area 7
1.4.2 Java Stack 9
1.4.3 Heap 9
1.4.4 Native Method Stacks 11
1.4.5 Example 11
1.5 Garbage Collection 15
1.5.1 Finalization 17
1.5.2 Timing of Garbage Collection 19
1.6 JVM Implementations 19
1.7 Versions of the Virtual Machine 20
1.8 Future of the Java Virtual Machine 21
2 Oolong 25
2.1 Hello, World 25
2.1.1 .class and .super Directives 26
2.1.2 main Method 27
2.1.3 Instructions 28
2.2 Structure of an Oolong Program 29
2.3 Defining the Class 30
2.4 Superclasses 31
2.5 Declaring Fields 31
2.6 Declaring Methods 34
2.7 Interfaces 38
3 Writing Methods 41
3.1 Some Definitions 41
3.2 Types 42
3.2.1 Numeric Types 43
3.2.2 Object Types 43
3.2.3 Type returnAddress 44
3.3 Mnemonic Naming Conventions 44
3.4 Testing Code Examples 45
3.5 Returns 47
3.6 Constants 48
3.6.1 General Constants 48
3.6.2 Small Constants and null 48
3.7 Local Variables 50
3.7.1 Initializing Variables 52
3.7.2 Local Variables as Method Arguments 55
3.8 Math 56
3.8.1 Arithmetic Operations 56
3.8.2 Nonnumbers and Infinity 58
3.8.3 Bitwise Operations 58
3.8.4 Floating-Point Arithmetic and strictfp 61
3.9 Type Conversions 62
3.9.1 Conversion Example 63
3.9.2 Widening and Narrowing 64
3.10 Stack Manipulations 65
3.11 Arrays of Numbers 68
3.12 Just Biding Your Time 70
4 Classes and Objects 73
4.1 What Is an Object? 73
4.1.1 Objects and References 74
4.1.2 Class Names 76
4.1.3 Packages 76
4.2 Creating Objects 77
4.3 Constructors 78
4.4 Using Fields 79
4.4.1 Types and getfield 81
4.4.2 Inheriting Fields 82
4.4.3 Changing Field Values 82
4.5 Invoking Methods on Objects 83
4.5.1 Virtual Invocation 86
4.5.2 Method Inheritance and Overriding 87
4.5.3 Overloading and Method Matching 90
4.5.4 Invoking a Method Directly 92
4.5.5 invokespecial and super 93
4.6 Casting 95
4.7 Casting, Fields, Methods, and Java 97
4.8 Returning Objects 100
4.9 Interfaces 101
4.10 Static Fields and Methods 105
4.11 Class Initialization 106
4.12 Arrays 107
4.12.1 Arrays of Reference 108
4.12.2 Multidimensional Arrays 110
4.12.3 Length of Arrays 112
5 Control Instructions 115
5.1 Comparing Integers 115
5.2 Comparing References 118
5.3 Other Comparisons 120
5.4 Switches 122
5.5 Subroutines 123
5.6 Exceptions 124
5.6.1 Multiple Exception Handlers 129
5.6.2 .throws Directive 131
5.6.3 Other Ways to Throw Exceptions 132
5.7 A Gentler Way of Checking Type 132
6 Verification Process 135
6.1 How the Verification Algorithm Works 136
6.2 Is It a Structurally Valid class File? 136
6.3 Are All Constant References Correct? 138
6.5 Will Each Instruction Always Find a Correctly Formed Stack
and Local Variable Array? 144
6.5.1 Example 1: Hello, World 146
6.5.2 Example 2: gotos and ifs 148
6.5.3 Example 3: Code That Doesn't Verify 152
6.5.4 Example 4: Dealing with Subclasses 154
6.5.5 Algorithm 158
6.6 Do External References Check Out? 160
6.7 Java Language and Verification Algorithm 161
6.7.1 Fooling the Virtual Machine with a Java Compiler 163
6.7.2 Other Languages and the Verification Algorithm 164
6.8 Other Safety Requirements 164
6.9 Checking Verification 165
7 Debugging 167
7.1 Debugging Directives in Oolong 167
7.1.1 .source Directive and .line Directives 168
7.1.2 .var Directive 170
7.2 Debugging Oolong Programs 172
7.3 Runtime Tracing 173
8 Class Loaders 177
8.1 How Classes Are Loaded 177
8.1.1 Loading 178
8.1.2 Linking 179
8.2 Loading Classes without a Class Loader 180
8.3 Making Your Own Class Loader 180
8.3.1 Caching Classes 182
8.3.2 Examples 183
8.4 Working with Class Objects 184
8.5 Reflection 186
9 Inside a Java class File 189
9.1 class File Header 190
9.2 Constant Pool 190
9.2.1 UTF8 Entries 193
9.2.2 Constant Entries 193
9.2.3 Field, Method, and Class Entries 195
9.3 Class Information 195
9.4 Fields and Methods 197
9.5 Class Attributes 202
9.6 Other Attributes 203
9.6.1 ConstantValue Attribute 203
9.6.2 Exceptions Attribute 204
9.6.3 InnerClasses Attribute 205
10 Compiling Java 207
10.1 Expressions and Statements 208
10.2 Expression Types 210
10.2.1 Numeric Types 210
10.2.2 Object Types 212
10.2.3 Expression Result Types 212
10.2.4 Compile-Time Types and Type Restrictions 213
10.2.5 Type Safety and Verifiability 215
10.3 Compiling Statements and Expressions 215
10.4 Local Variable Declarations 217
10.5 Fields and Variables 219
10.5.1 Abbreviations 222
10.5.2 Other Assignments 223
10.5.3 Assignments as Expressions 224
10.5.4 Type-Checking in Assignments 225
10.6 Creating New Objects 226
10.7 Class Name Abbreviations 227
10.8 Arithmetic Expressions 228
10.8.1 Numeric Coercions 229
10.8.2 Casting Numeric Values 232
10.8.3 ~ Operator 234
10.9 Method Calls 235
10.9.1 Virtual Method Calls 235
10.9.2 Static Method Calls 236
10.9.3 Example of Method Calls 236
10.9.4 Overriding 238
10.9.5 Overloading 239
10.9.6 Interfaces 241
10.10 Expressions as Statements 242
10.11 Ifs and Booleans 243
10.11.1 Boolean Values 243
10.11.2 if Statements 245
10.11.3 Comparisons 245
10.11.4 Floating-Point Comparisons and NaN 247
10.11.5 Integer Comparisons 249
10.11.6 References and Object Equality 249
10.11.7 Boolean Operators 254
10.12 Other Control Structures 255
10.12.1 Loops 256
10.12.2 Compiling Control Constructs 257
10.12.3 Compound Statements and Verification 259
10.13 Returns 261
10.14 Field Declarations 262
10.15 Method Declarations 263
10.16 Constructors 264
10.16.1 Using Other Constructors in the Same Class 266
10.16.2 Default Constructors 267
10.16.3 Field Initializers and the Constructor 267
10.17 Conclusion 268
11 Compiling Other Languages 269
11.1 Java Version 1.1 270
11.1.1 Class Literals 271
11.1.2 Inner Classes 272
11.1.3 Variable Scoping with Inner Classes 275
11.2 Regular Expressions 277
11.3 Iterators 283
11.3.1 Iterators in Sather 283
11.3.2 Implementing Iterators 285
11.3.3 Iterators with Arguments 288
11.3.4 Using Iterators 290
11.4 Parameterized Types 292
11.4.1 Implementing Parameterized Types with a Generic Class 293
11.4.2 Implementing Parameterized Types as Templates 294
11.5 Multiple Inheritance 295
11.5.1 Interfaces for Multiple Inheritance 296
11.5.2 Implementing the Interfaces 297
11.5.3 Fields 302
11.6 Conclusion 303
12 Implementing Scheme 305
12.1 Scheme Concepts 305
12.2 Compiling Scheme into Bytecodes 309
12.3 Compiling Lambda Expressions 313
12.4 Example 317
12.5 Scheme Library 319
12.6 Optimizing Scheme 320
12.6.1 Static Scoping 321
12.6.2 Using Local Variables 325
12.6.3 Inlining 327
12.6.4 Tail Recursion 327
12.6.5 Using Type Information 328
13 Implementing Prolog 331
13.1 Introduction to Prolog 331
13.1.1 Asking Questions 332
13.1.2 Binding Patterns 333
13.1.3 Implications 333
13.1.4 Binding Patterns and Implications 334
13.1.5 Facts as Rules 335
13.1.6 More About Unification 335
13.2 Implementation Basics 336
13.3 Unification 337
13.3.1 Unification Algorithm 337
13.3.2 Managing Bindings 338
13.4 Rules as Programs 339
13.4.1 inside 340
13.4.2 within 341
13.4.3 yield and Backtracking 341
13.5 Implementing Rules 344
13.5.1 Implementing within 344
13.5.2 Implementing Conjunctions 347
13.5.3 Constructing within 349
13.6 Compiling Facts 349
13.7 Case Study 352
14 Performance 355
14.1 Fast Virtual Machines 355
14.1.1 Garbage Collection Performance 356
14.1.2 Implementing References 358
14.2 Bytecode Optimization Techniques 360
14.2.1 Warning 360
14.2.2 Constant Propagation 360
14.2.3 Strength Reduction 362
14.2.4 Loop Unrolling 363
14.2.5 Peephole Optimization 364
14.3 Inlining 368
14.3.1 Inlining Fields 370
14.3.2 Separate Compilation 372
15 Security and the Virtual Machine 373
15.1 Java platform and Need for Security 373
15.2 Security Promises of the JVM 374
15.3 Security Architecture and Security Policy 375
15.3.1 Example 377
15.3.2 Basic Applet Security Policy 378
15.3.3 More Sophisticated Policies 379
15.4 Some Potential Attacks 380
15.4.1 Implementation Details 380
15.4.2 Protecting the Security Manager 381
15.4.3 Bypassing Java Security 382
15.4.4 Using Unconstructed Objects 383
15.4.5 Invalid Casts 386
15.4.6 Changing the Class of a Reference 388
15.4.7 Reading Uninitialized Fields 388
15.4.8 Array Bounds Checks 390
15.4.9 Catching Exceptions 391
15.4.10 Hidden Code 392
15.5 Conclusion 393
16 Threads and Synchronization 395
16.1 Threads 396
16.1.1 Example: Multithreaded Web Server 398
16.1.2 Exceptions and Threads 401
16.2 Sharing State Between Threads 401
16.2.1 Need for Synchronization 402
16.2.2 Exception: longs and doubles 404
16.3 Monitors and Object Locks 404
16.3.1 Synchronization in Java 407
16.3.2 Synchronized Methods 408
16.4 Scheduling 410
16.4.1 Surrendering Control of the CPU 412
16.4.2 Waiting for Another Thread 413
16.5 Conclusion 414
A Tables 415
A.1 Instructions by Opcode 415
A.2 Instructions Alphabetically 418
A.3 Instructions by Category 421
A.3.1 Arithmetic 421
A.3.2 Array 422
A.3.3 Constant 423
A.3.4 Control 424
A.3.5 Data Type Conversion 425
A.3.6 Object 426
A.3.7 Stack Manipulation 426
A.3.8 Synchronization 426
A.3.9 Variable 427
B Oolong Reference 429
B.1 Using the Oolong Assembler 429
B.2 Gnoloo 430
B.3 DumpClass 431
B.4 Oolong Language 432
B.4.1 Comments 432
B.4.2 .source 432
B.4.3 .class 433
B.4.4 .interface 434
B.4.5 .end class 434
B.4.6 .super 435
B.4.7 .implements 435
B.4.8 .field 436
B.4.9 .method 436
B.4.10 .limit locals 438
B.4.11 .limit stack 438
B.4.12 .line 439
B.4.13 .var 440
B.4.14 .throws 441
B.4.15 .catch 441
B.4.16 .end method 443
B.5 Instructions 443
B.5.1 Instructions with No Arguments 449
B.5.2 Integers 449
B.5.3 Labels 450
B.5.4 Classes 450
B.5.5 Fields and Methods 450
B.5.6 invokeinterface 450
B.5.7 multianewarray 451
B.5.8 ldc, ldc_w, and ldc2_w 451
B.5.9 newarray 452
B.5.10 tableswitch 452
B.5.11 lookupswitch 453
C Answers to Selected Exercises 455
Further Readings 473
Java and the JVM 473
Newsgroup 474
Other Languages 474
Compilers 474
Index 477
Caractéristiques techniques
PAPIER | |
Éditeur(s) | Addison Wesley |
Auteur(s) | Joshua Engel |
Parution | 15/08/1999 |
Nb. de pages | 488 |
Format | 18,5 x 23,3 |
Poids | 900g |
EAN13 | 9780201309720 |
Avantages Eyrolles.com
Consultez aussi
- Les meilleures ventes en Graphisme & Photo
- Les meilleures ventes en Informatique
- Les meilleures ventes en Construction
- Les meilleures ventes en Entreprise & Droit
- Les meilleures ventes en Sciences
- Les meilleures ventes en Littérature
- Les meilleures ventes en Arts & Loisirs
- Les meilleures ventes en Vie pratique
- Les meilleures ventes en Voyage et Tourisme
- Les meilleures ventes en BD et Jeunesse