did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780201709698

Java¿ Platform Performance Strategies and Tactics

by ;
  • ISBN13:

    9780201709698

  • ISBN10:

    0201709694

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2000-05-31
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $39.99

Summary

Author's Note

In 1997, I was hired as a contractor to work on the Java(TM) Foundation Classes (JFC) Swing toolkit (Swing). This was an ambitious endeavor--Swing was slated to become the new standard for developing Graphical User Interfaces (GUIs) with the Java programming language. Prior to the release of Swing, the only GUI toolkit available with the Java platform was the Abstract Window Toolkit (AWT), a fairly primitive GUI toolkit by 1990s standards. While AWT was hobbled by a "lowest common denominator" design, Swing was designed to be a state-of-the-art toolkit. Written entirely in the Java programming language, it offered a powerful Model-View architecture, an advanced widget set, and a revolutionary pluggable look-and-feel (PLAF) system. When JFC was released in mid-1998, it was quickly adopted by thousands of eager developers.

As with any successful new product, along with stories of success came some bitter complaints. Some developers complained about architectural and philosophical issues. Others complained about bugs or the lack of a particular feature. However, the complaints I personally found most troubling were that programs written with Swing were slow.

I convinced my manager to let me spend a week looking into Swing's performance issues, downloaded a trial copy of a profiling package, and started poking at different parts of the toolkit.

It turned out that there were several areas where performance improvements could be made relatively easily. At the end of the week, I wrote a report on my findings and sent it to the rest of the Swing engineering team. Other members of the team got caught up in the spirit of performance tuning and began doing their own analyses. Over the next few months, I spent more and more of my time working on analysis and tuning and the Swing team made numerous performance enhancements. Many of the techniques described in this book are based on the knowledge gained while we were tuning Swing.

In late 1998, we shipped a new version of Swing that was more than twice as fast for typical tasks than the previous release. However, while many developers were pleased with the improvements, we were troubled to see that we still received numerous complaints about performance. Clearly the problem was more complex than we first thought.

I joined the performance team in Sun's Java Software unit in late 1998 and worrying about performance issues became my full-time job. In an effort to better understand the performance issues we and our developers face, I spend a lot of time talking with developers who are working on serious, real-world Java technology-based systems. Developers sometimes point out areas where changes in the libraries or VM could improve the performance of their programs. Part of my group's charter is to help make sure those changes, when appropriate, make their way into the runtime environment.

When working with developers, we also often find areas where changes to their program code can improve performance. We've found that there are a number of common mistakes and misconceptions about the performance characteristics of Java technologies and even about performance tuning in general.

The goal of this book is to share what we've learned about performance tuning Java technology-based systems with a wide audience. We hope that it will prove to be a valuable reference for you.

Steve Wilson
Sun Microsystems

About This Book

The information in this book will help you write high-performance software for the Java platform. It presents both high-level strategies for incorporating performance tuning into your software development process and code-level performance tuning tactics.

The two parts of the book approach performance tuning from different perspectives, providing a holistic view of the performance tuning process.

  • Part I: Strategies provides a high-level overview of the performance tuning process. It focuses on general strategies that you can incorporate into the development process to improve the performance of Java technology-based systems.
  • Part II: Tactics focuses on specific techniques for improving performance once you've figured out where the hot spots and bottlenecks are.
The higher-level information in the Strategies part is intended for a broad audience, including software engineers, engineering managers, technical leads, and quality assurance specialists involved in the development of Java technology-based solutions. The information in the Tactics part is geared toward intermediate to advanced developers familiar with the Java programming language who are looking for concrete coding techniques they can use to speed up their software.

The Strategies chapters are best read as a single piece, but the Tactics part does not need to be read linearly--you can go directly to whatever topic interests you most.

The two appendices at the end of the book provide information about garbage collection and the HotSpot(TM) virtual machine (VM) and how they can impact performance.

Performance Measurements

Unless otherwise noted, all performance measurements described in this book were run on a pre-release build of the Java 2 Standard Edition (J2SE) v. 1.3 using the HotSpot Client VM on the Microsoft Windows operating system.

Specific performance results are only representative of the configuration on which they are run. Factors such as the CPU, hard disk, operating system, and Java runtime environment (JRE) can all impact performance--keep in mind that the same benchmarks run under different configurations might yield substantially different results.

Code Samples

Complete code for the snippets, sample programs, utilities, and benchmarks used in this book is available online at http://java.sun.com/docs/books/performance/

Acknowledgments

We would like to thank the many people who contributed to the success of this book.

Jon Kannegaard, Larry Abrahams, and Graham Hamilton provided the initial push that started this project. We especially need to thank Larry, who provided much needed management support throughout the project. Lisa Friendly and Tim Lindholm, editors of the Java Series, patiently guided two first-time authors through the process of making this book a reality. Mike Hendrickson and Julie DiNicola from Addison-Wesley were immensely helpful throughout the entire process.

Deborah Adair of The Design Cage served as part editor, part graphic designer, and part writing coach. We couldn't have finished the project without her help.

Hans Muller, the technical lead for Project Swing and the foremost expert on Swing's threading model, provided the material for Chapter 11, Writing Responsive User Interfaces with Swing. He spent many nights and weekends working on this chapter so the rest of us could better understand how to use threads in Swing programs.

Alan Sommerer contributed to the outline and organization of early drafts, ensuring that key concepts were not missed.

David Wilson and Doris Chen began writing a two-day training course on performance tuning about the same time we started working on this book. We exchanged many ideas with them and believe both the course and the book benefited.

Over the past year, Agnes Jacob introduced us to many developers who had performance-related issues. These experiences were invaluable in deciding what information to include in this book.

Many people provided a tremendous amount of input to the book by reviewing early drafts or providing important technical tidbits: Eric Armstrong, Tom Ball, Clifford Crick, Mark Davidson, Joshua Engel, Peter Hag

Author Biography

Steve Wilson is the Engineering Manager of the Java Performance Team at Sun Microsystems's Java Software unit. There he leads the team that is responsible for performance tuning of the Java™ 2 Standard Edition internals and helps third-party developers improve program code performance. Mr. Wilson previously worked as a member of the Swing team, which developed the Java Foundation Classes toolkit. Prior to joining Sun, he spent several years as an independent consultant specializing in object-oriented technologies.

Jeff Kesselman is an engineer on the Java Performance Team at Sun Microsystems's Java Software unit where he works with various groups to improve Java code performance. Prior to joining Sun, he developed cutting-edge games for several PC and console platforms in the computer game industry.



0201709694AB04062001

Table of Contents

Preface xiii
Part I: Strategies 1(36)
What Is Performance?
3(6)
Computational Performance
4(1)
RAM Footprint
4(1)
Startup Time
5(1)
Scalability
6(1)
Perceived Performance
7(2)
The Performance Process
9(8)
Developing a Performance Process
9(6)
Analysis
10(2)
Object-Oriented Design
12(2)
Coding
14(1)
Testing
14(1)
Profiling
15(1)
References on Object-Oriented Design
15(2)
Measurement Is Everything
17(20)
Benchmarking
17(10)
Why Build Benchmarks?
21(1)
Micro-Benchmarks
22(1)
Macro-Benchmarks
23(2)
Analyzing Benchmarks
25(2)
Profiling
27(5)
Profiling Execution Times
28(2)
Profiling Memory Usage
30(1)
Profiling to Locate Memory Leaks
31(1)
Dealing with Flat Profiles
32(5)
A Flat Profile Example
35(2)
Part II: Tactics 37(154)
I/O Performance
41(12)
Basic I/O
41(6)
Buffered Streams
41(3)
Custom Buffering
44(3)
Further Improvements
47(1)
Serialization
47(6)
Serialization Example
48(1)
Improved Serialization Example
49(2)
Analyzing Persistent State
51(2)
RAM Footprint
53(14)
Computing RAM Footprint
53(2)
Assessing Memory Usage
53(1)
Measuring a Program's True Footprint
54(1)
What Contributes to Footprint?
55(9)
Objects
57(5)
Classes
62(1)
Threads
63(1)
Native Data Structures
63(1)
Native Libraries
64(1)
Class Loading
64(3)
Measuring Class Loads
64(3)
Controlling Class Loading
67(18)
Eager Class Loading
67(3)
Controlling Eager Loading
69(1)
Reducing the Number of Classes
70(7)
Simple Inner Classes
71(1)
Collapsing the Listeners
72(1)
Using Reflection
73(1)
Using a Proxy
74(3)
Who Really Uses These Tactics?
77(1)
Running Multiple Programs
77(8)
The Office Suite
77(2)
Running in the Same Virtual Machine
79(3)
A Better Launcher
82(3)
Object Mutability: Strings and Other Things
85(18)
Losts of Little Objects
86(1)
Handling String Objects
86(2)
Mutable Objects in AWT and Swing
88(3)
Eliminating Temporary Objects
90(1)
Other Mutable Object Tactics
91(6)
Simulating const
91(6)
Mutable Object Case Study
97(1)
Small Objects and the Modern JVM
97(2)
Object Pooling
98(1)
Array Mutability
99(4)
Algorithms and Data Structures
103(26)
Selecting Algorithms
103(9)
Comparing Algorithms
105(1)
Achieving Elegance
106(1)
Considering the Problem Space
107(5)
Using Recursive Algorithms
112(3)
Beyond Simple Algorithms
115(1)
Selecting Data Structures
116(7)
Java 2 Collections
116(1)
The Collection Interfaces
117(1)
Collection Interface
118(1)
List Objects
119(1)
Set Objects
119(1)
Map Objects
120(1)
Synchronized Collections
120(2)
Collections Framework Algorithms
122(1)
Plain Arrays
122(1)
Immutable Collections
123(1)
Collections Example
123(4)
Collection Benchmark Results
125(2)
References on Algorithms and Data Structures
127(2)
Using Native Code
129(16)
Native Graphics Example
129(4)
Native Code Comparison
132(1)
Examining JNI Costs
133(9)
Java Language Copy
136(1)
JNI Patterns
136(1)
Pattern 1: Call
136(1)
Pattern 2: Call-Pull
137(1)
Pattern 3: Call-Pull-Push
138(1)
Pattern 3 (Variant): Call-Pull-Push with Critical
139(2)
Pattern 4: Call-Invoke
141(1)
Native Code Case Studies
142(3)
Java Media Framework
142(1)
The java.math Package
143(1)
Java 3D
143(2)
Swing Models and Renderers
145(16)
Swing's Component Architecture
145(2)
Scalable Components
147(14)
Renderers
147(2)
Models
149(2)
Example: Simple Spreadsheet
151(1)
Using Custom Models
152(2)
Using Custom Renderers
154(3)
Using Custom Models and Renderers Together
157(4)
Writing Responsive User Interfaces with Swing
161(22)
Guidelines for Responsive GUIs
161(3)
Design, Then Build (Repeat)
162(1)
Put the User in Charge
162(2)
Using Threads in Swing Programs
164(4)
The Single-Thread Rule
165(1)
Using invokeLater and invokeAndWait for Event Dispatching
166(2)
Using Timers in Swing Applications
168(8)
How Timers Work
168(2)
Code Without Timers
170(1)
The Swing Timer Class
171(1)
The Utility Timer and Timer Task Classes
172(1)
How to Choose a Timer Class
173(1)
Timer Example
174(2)
Responsive Applications Use Threads
176(2)
Example: Searching the Web
178(5)
Worker Thread Priority
179(1)
Interrupting a Worker Thread
180(3)
Deployment
183(8)
Compiler Options
183(1)
JAR Files
184(2)
Reducing Program Size
184(1)
Download Time Reduction
184(2)
JAR Files and Resources
186(1)
Packaging Utilities
186(1)
Dynamic Downloading
187(4)
Applet Caching
188(3)
Appendices 191(28)
A The Truth About Garbage Collection
193(12)
A.1 Why Should You Care About Garbage Collection?
193(1)
A.2 The Guarantees of GC
193(1)
A.3 The Object Lifecycle
194(1)
A.3.1 Created
195(1)
A.3.2 In Use
195(1)
A.3.3 Invisible
196(1)
A.3.4 Unreachable
197(1)
A.3.5 Collected
198(1)
A.3.6 Finalized
198(1)
A.3.7 Deallocated
199(1)
A.4 Reference Objects
199(1)
A.4.1 Types of Reference Objects
200(1)
A.4.2 Example GC with WeakReference
201(2)
A.5 References on Garbage Collection
203(2)
B The Java HotSpot Virtual Machine
205(14)
B.1 HotSpot Architecture
205(1)
B.1.1 Two Versions of HotSpot
206(2)
B.2 Runtime Features
208(1)
B.2.1 Memory Allocation and Garbage Collection
208(3)
B.2.2 Thread Synchronization
211(1)
B.3 HotSpot Server Compiler
211(1)
B.3.1 Aggressive Inlining
211(2)
B.3.2 Other Optimizations
213(1)
B.3.3 Array Bounds Checks
213(1)
B.4 -X Flags
213(1)
B.4.1 -Xnoc Iassgc
214(1)
B.4.2 -Xincgc
214(1)
B.4.3 -Xbatch
214(1)
B.4.4 -Xms
214(1)
B.4.5 -Xmx
215(1)
B.4.6 -Xprof
215(1)
B.5 -XX Flags
216(1)
B.5.1 Kinds of -XX Flags
217(1)
B.5.2 PrintBytecodeHistogram
217(1)
B.5.3 CompileThreshold
217(1)
B.5.4 NewSize
218(1)
References 219(2)
Index 221

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

Author's Note In 1997, I was hired as a contractor to work on the Java(TM) Foundation Classes (JFC) Swing toolkit (Swing). This was an ambitious endeavor--Swing was slated to become the new standard for developing Graphical User Interfaces (GUIs) with the Java programming language. Prior to the release of Swing, the only GUI toolkit available with the Java platform was the Abstract Window Toolkit (AWT), a fairly primitive GUI toolkit by 1990s standards. While AWT was hobbled by a "lowest common denominator" design, Swing was designed to be a state-of-the-art toolkit. Written entirely in the Java programming language, it offered a powerful Model-View architecture, an advanced widget set, and a revolutionary pluggable look-and-feel (PLAF) system. When JFC was released in mid-1998, it was quickly adopted by thousands of eager developers. As with any successful new product, along with stories of success came some bitter complaints. Some developers complained about architectural and philosophical issues. Others complained about bugs or the lack of a particular feature. However, the complaints I personally found most troubling were that programs written with Swing were slow. I convinced my manager to let me spend a week looking into Swing's performance issues, downloaded a trial copy of a profiling package, and started poking at different parts of the toolkit. It turned out that there were several areas where performance improvements could be made relatively easily. At the end of the week, I wrote a report on my findings and sent it to the rest of the Swing engineering team. Other members of the team got caught up in the spirit of performance tuning and began doing their own analyses. Over the next few months, I spent more and more of my time working on analysis and tuning and the Swing team made numerous performance enhancements. Many of the techniques described in this book are based on the knowledge gained while we were tuning Swing. In late 1998, we shipped a new version of Swing that was more than twice as fast for typical tasks than the previous release. However, while many developers were pleased with the improvements, we were troubled to see that we still received numerous complaints about performance. Clearly the problem was more complex than we first thought. I joined the performance team in Sun's Java Software unit in late 1998 and worrying about performance issues became my full-time job. In an effort to better understand the performance issues we and our developers face, I spend a lot of time talking with developers who are working on serious, real-world Java technology-based systems. Developers sometimes point out areas where changes in the libraries or VM could improve the performance of their programs. Part of my group's charter is to help make sure those changes, when appropriate, make their way into the runtime environment. When working with developers, we also often find areas where changes to their program code can improve performance. We've found that there are a number of common mistakes and misconceptions about the performance characteristics of Java technologies and even about performance tuning in general. The goal of this book is to share what we've learned about performance tuning Java technology-based systems with a wide audience. We hope that it will prove to be a valuable reference for you. Steve Wilson Sun Microsystems About This Book The information in this book will help you write high-performance software for the Java platform. It presents both high-level strategies for incorporating performance tuning into your software development process and code-level performance tuning tactics. The two parts of the book approach performance tuning from different perspectives, providing a holistic view of the performance tuning process. Part I: Strategies provides a

Rewards Program