55,19 €
Oracle JRockit is one of the industry’s highest performing Java Virtual Machines. Java developers are always on the lookout for better ways to analyze application behavior and gain performance. As we all know, this is not as easy as it looks. Welcome to JRockit: The Definitive Guide.This book helps you gain in-depth knowledge of Java from the JVM’s point of view. We will explain how to write code that works well with the JVM to gain performance and scalability. Starting with the inner workings of the JRockit JVM and finishing with a thorough walkthrough of the tools in the JRockit Mission Control suite, this book is for anyone who wants to know more about how the JVM executes your Java application and how to profile for better performance.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 796
Veröffentlichungsjahr: 2010
Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2010
Production Reference: 1260510
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-847198-06-8
www.packtpub.com
Cover Image by Mark Holland (<[email protected]>)
Authors
Marcus Hirt
Marcus Lagergren
Reviewers
Anders Åstrand
Staffan Friberg
Markus Grönlund
Daniel Källander
Bengt Rutisson
Henrik Ståhl
Acquisition Editor
James Lumsden
Development Editor
Rakesh Shejwal
Technical Editor
Sandesh Modhe
Indexer
Rekha Nair
Editorial Team Leader
Gagandeep Singh
Project Team Leader
Priya Mukherji
Project Coordinator
Ashwin Shetty
Proofreader
Andie Scothern
Graphics
Geetanjali Sawant
Production Coordinator
Melwyn D'sa
Cover Work
Melwyn D'sa
I remember quite clearly the first time I met the JRockit team. It was JavaOne 1999 and I was there representing WebLogic. Here were these Swedish college kids in black T-shirts describing how they would build the world's best server VM. I was interested in hearing their story as the 1.2 release of HotSpot had been delayed again and we'd been running into no end of scalability problems with the Classic VM. However I walked away from the booth thinking that, while these guys were smart, they had no idea what they were biting off.
Fast-forward a few years. BEA buys JRockit and I become the technical liaison between the WebLogic and JRockit teams. By now JRockit has developed into an excellent offering—providing great scalability and performance on server-side systems. As we begin working together I have the distinct pleasure of getting to know the authors of this book: Marcus Lagergren and Marcus Hirt.
Lagergren is a remarkably prolific developer, who at the time was working on the compiler. He and I spent several sessions together examining optimizations of WebLogic code and deciphering why this method or that wasn't getting inlined or devirtualized. In the process we, along with the rest of the WebLogic and JRockit teams, were able to produce several SPECjAppServer world records and cement JRockit's reputation for performance.
Hirt, on the other hand, is extremely focused on profiling and diagnostics. It was natural, therefore, that he should lead the nascent tooling effort that would become JRockit Mission Control. This was an extension of an early observation we had, that in order to scale the JRockit engineering team, we would have to invest in tooling to make support and debugging easier.
Fast-forward a few more years. I'm now at Oracle when it acquires BEA. I have the distinct pleasure of again welcoming the JRockit team into a new company as they joined my team at Oracle. The core of the JRockit team is still the same and they now have a place among the small group of the world's experts in virtual machines.
Lagergren is still working on internals—now on JRockit Virtual Edition—and is as productive as ever. Under Hirt's leadership, Mission Control has evolved from an internal developer's tool into one of the JRockit features most appreciated by customers. With this combination of long experience and expertise in all layers of JRockit, it is difficult for me to imagine a better combination of authors to write this book.
Therefore, as has been the case many times before, I'm proud to be associated in some small way with the JRockit team. I trust that you will enjoy reading this book and hope that you will find the topic to be as satisfying as I have found it to be over the years.
Adam Messinger
Vice President of Development, Oracle Fusion Middleware group
February 14, 2010
San Francisco, CA
Marcus Hirt is one of the founders of Appeal Virtual Machines, the company that created the JRockit Java Virtual Machine. He is currently working as Architect, Team Lead, and Engineering Manager for the JRockit Mission Control team. In his spare time he enjoys coding on his many pet projects, composing music, and scuba diving. Marcus has contributed JRockit related articles, whitepapers, tutorials, and webinars to the JRockit community, and has been an appreciated speaker at Oracle Open World, eWorld, BEAWorld, EclipseCon, Nordev, and Expert Zone Developer Summit. He received his M.Sc. education in Computer Science at the Royal Institute of Technology in Stockholm. Marcus Hirt lives in Stockholm with his wife and two children.
Marcus Lagergren has an M.Sc. in Computer Science from the Royal Institute of Technology in Stockholm, Sweden. He majored in theoretical computer science and complexity theory since it was way more manly than, for example, database systems. He has a background in computer security but has worked with runtimes since 1999. Marcus was one of the founding members of Appeal Virtual Machines, the company that developed the JRockit JVM. Marcus has been Team Lead and Architect for the JRockit code generators and has been involved in pretty much every other aspect of the JRockit JVM internals over the years. He has presented at various conferences, such as JavaOne, BEAWorld, and eWorld and holds several patents on runtime technology. Since 2008, he works for Oracle on a fast virtualization platform. Marcus likes power tools, heavy metal, and scuba diving. Marcus Lagergren lives in Stockholm with his wife and two daughters.
We'd like to thank all the people who have been creative with us throughout the years, especially the other Appeal guys who have been a part of our lives for quite some time now. The authors cannot think of a finer and more competent group of people to have shared this journey with.
Furthermore, a great thank you is in order to our families who have been extremely patient with us during the writing of this book.
Anders Åstrand has a Master's degree in Computer Science from the Royal Institute of Technology, Sweden. He has worked at Oracle (formerly BEA Systems) since 2007, in the JRockit performance team.
Staffan Friberg leads the JRockit Performance Team at Oracle, with seven years of experience in QA and Performance Engineering for the JVM.
Markus Grönlund is a Senior Software Engineer with Oracle Corporation and has worked extensively in the Oracle JRockit Virtual Machine development and support arena for the past three years. Markus has been supporting Oracle JRockit VMs the largest mission critical JRockit customers, providing expertise in debugging, configuration, and training.
Prior to joining Oracle Corporation, Markus worked for seven years as a Senior Technical Architect for Intel Corporation, driving early adoption of next-generation Intel Architectures.
I would like to thank the entire Oracle JRockit Virtual Machine team in Stockholm, Sweden. It is a true privilege to be part of such an amazing group of talented people. Thank you all!
Daniel Källander is Development Manager for JRockit and has been with the JRockit team since 2005. Since 1996, he has been a founding member of three IT companies. Before entering the IT industry he completed a Ph.D. in Theoretical Physics, and later also an MBA in International Business.
Bengt Rutisson is Development Manager at Oracle focusing on JRockit garbage collection and memory management. He joined the JRockit team in 2006 and has been working with garbage collection and memory management since then.
Prior to working with JRockit, Bengt has been responsible for several products in Java (for example, the Appear Context Engine) and in Component Pascal (for example, the BlackBox Component Builder).
Henrik Ståhl is Senior Director of Product Management at Oracle, responsible for product strategy for JRockit. In this position, he is constantly looking for new ways to make the Java Virtual Machine more useful. He has been working with the JRockit team since 2004, starting out as Team Lead for the JVM performance team before moving to a product management role. Prior to Oracle, he was Co-Founder and CTO of the Swedish IT consultancy Omegapoint, lead developer for the core part of the Swedish BankID service and Senior Consultant at Icon Medialab. Henrik holds an M.Sc. in Engineering Physics from the Royal Institute of Technology and lives outside of Stockholm, Sweden with his family.
For my family, who endured me being inaccessible for nights and weekends both working on the new major release and writing this book: Malin, Alexander, and little Natalie.
--Marcus HirtFor my family: Klara, Alice, and Ylva. Especially for my lovely wife Klara, who ended up having to singlehandedly juggle two children too often and who, more than once, expressed her desire to purchase a copy of this book and burn it.
--Marcus LagergrenThis book is the result of an amazing series of events.
In high school, back in the pre-Internet era, the authors used to hang out at the same bulletin board systems and found each other in a particularly geeky thread about math problems. Bulletin board friendship led to friendship in real life, as well as several collaborative software projects. Eventually, both authors went on to study at the Royal Institute of Technology (KTH) in Stockholm.
More friends were made at KTH, and a course in database systems in our third year brought enough people with a similar mindset together to achieve critical mass. The decision was made to form a consulting business named Appeal Software Solutions (the acronym A.S.S. seemed like a perfectly valid choice at the time). Several of us started to work alongside our studies and a certain percentage of our earnings was put away so that the business could be bootstrapped into a full-time occupation when everyone was out of university. Our long-term goal was always to work with product development, not consulting. However, at the time we did not know what the products would turn out to be.
In 1997, Joakim Dahlstedt, Fredrik Stridsman and Mattias Joëlson won a trip to one of the first JavaOne conferences by out-coding everyone in a Sun sponsored competition for university students. For fun, they did it again the next year with the same result.
It all started when our three heroes noticed that between the two JavaOne conferences in 1997 and 1998, the presentation of Sun's adaptive virtual machine HotSpot remained virtually unchanged. HotSpot, it seemed at the time, was the answer to the Java performance problem. Java back then was mostly an interpreted language and several static compilers for Java were on the market, producing code that ran faster than bytecode, but that usually violated the language semantics in some fundamental way. As this book will stress again and again, the potential power of an adaptive runtime approach exceeds, by far, that of any ahead-of-time solution, but is harder to achieve.
Since there were no news about HotSpot in 1998, youthful hubris caused us to ask ourselves "How hard can it be? Let's make a better adaptive VM, and faster!" We had the right academic backgrounds and thought we knew in which direction to go. Even though it definitely was more of a challenge than we expected, we would still like to remind the reader that in 1998, Java on the server side was only just beginning to take off, J2EE hardly existed and no one had ever heard of a JSP. The problem domain was indeed a lot smaller in 1998.
The original plan was to have a proof of concept implementation of our own JVM finished in a year, while running the consulting business at the same time to finance the JVM development. The JVM was originally christened "RockIT", being both rock 'n' roll, rock solid and IT. A leading "J" was later added for trademark reasons.
Naturally, after a few false starts, we needed to bring in venture capital. Explaining how to capitalize on an adaptive runtime (that the competitors gave away their own free versions of) provided quite a challenge. Not just because this was 1998, and investors had trouble understanding any venture not ultimately designed to either (1) send text messages with advertisements to cell phones or (2) start up a web-based mail order company.
Eventually, venture capital was secured and in early 2000, the first prototype of JRockit 1.0 went public. JRockit 1.0, besides being, as someone on the Internet put it "very 1.0", made some headlines by being extremely fast at things like multi-threaded server applications. Further venture capital was acquired using this as leverage. The consulting business was broken out into a separate corporation and Appeal Software Solutions was renamed Appeal Virtual Machines. Sales people were hired and we started negotiations with Sun for a Java license.
Thus, JRockit started taking up more and more of our time. In 2001, the remaining engineers working in the consulting business, which had also grown, were all finally absorbed into the full-time JVM project and the consulting company was mothballed. At this time we realized that we both knew exactly how to take JRockit to the next level and that our burn rate was too high. Management started looking for a suitor in the form of a larger company to marry.
In February 2002, BEA Systems acquired Appeal Virtual Machines, letting nervous venture capitalists sleep at night, and finally securing us the resources that we needed for a proper research and development lab. A good-sized server hall for testing was built, requiring reinforced floors and more electricity than was available in our building. For quite a while, there was a huge cable from a junction box on the street outside coming in through the server room window. After some time, we outgrew that lab as well and had to rent another site to host some of our servers.
As part of the BEA platform, JRockit matured considerably. The first two years at BEA, plenty of the value-adds and key differentiators between JRockit and other Java solutions were invented, for example the framework that was later to become JRockit Mission Control. Several press releases, world-beating benchmark scores, and a virtualization platform quickly followed. With JRockit, BEA turned into one of the "big three" JVM vendors on the market, along with Sun and IBM, and a customer base of thousands of users developed. A celebration was in order when JRockit started generating revenue, first from the tools suite and later from the unparalleled GC performance provided by the JRockit Real Time product.
In 2008, BEA was acquired by Oracle, which caused some initial concerns, but JRockit and the JRockit team ended up getting a lot of attention and appreciation.
For many years now, JRockit has been running mission-critical applications all over the world. We are proud to have been part of the making of a piece of software with that kind of market penetration and importance. We are equally proud to have gone from a pre-alpha designed by six guys in a cramped office in the Old Town of Stockholm to a world-class product with a world-class product organization.
The contents of this book stems from more than a decade of our experience with adaptive runtimes in general, and with JRockit in particular. Plenty of the information in this book has, to our knowledge, never been published anywhere before.
We hope you will find it both useful and educational!
Chapter 1: Getting Started. This chapter introduces the JRockit JVM and JRockit Mission Control. Explains how to obtain the software and what the support matrix is for different platforms. We point out things to watch out for when migrating between JVMs from different vendors, and explain the versioning scheme for JRockit and JRockit Mission control. We also give pointers to resources where further information and assistance can be found.
Chapter 2: Adaptive Code Generation. Code generation in an adaptive runtime is introduced. We explain why adaptive code generation is both harder to do in a JVM than in a static environment as well as why it is potentially much more powerful. The concept of "gambling" for performance is introduced. We examine the JRockit code generation and optimization pipeline and walk through it with an example. Adaptive and classic code optimizations are discussed. Finally, we introduce various flags and directive files that can be used to control code generation in JRockit.
Chapter 3: Adaptive Memory Management. Memory management in an adaptive runtime is introduced. We explain how a garbage collector works, both by looking at the concept of automatic memory management as well as at specific algorithms. Object allocation in a JVM is covered in some detail, as well as the meta-info needed for a garbage collector to do its work. The latter part of the chapter is dedicated to the most important Java APIs for controlling memory management. We also introduce the JRockit Real Time product, which can produce deterministic latencies in a Java application. Finally, flags for controlling the JRockit JVM memory management system are introduced.
Chapter 4: Threads and Synchronization. Threads and synchronization are very important building blocks in Java and a JVM. We explain how these concepts work in the Java language and how they are implemented in the JVM. We talk about the need for a Java Memory Model and the intrinsic complexity it brings. Adaptive optimization based on runtime feedback is done here as well as in all other areas of the JVM. A few important anti-patterns such as double-checked locking are introduced, along with common pitfalls in parallel programming. Finally we discuss how to do lock profiling in JRockit and introduce flags that control the thread system.
Chapter 5: Benchmarking and Tuning. The relevance of benchmarking and the importance of performance goals and metrics is discussed. We explain how to create an appropriate benchmark for a particular problem set. Some industrial benchmarks for Java are introduced. Finally, we discuss in detail how to modify application and JVM behavior based on benchmark feedback. Extensive examples of useful command-line flags for the JRockit JVM are given.
Chapter 6: JRockit Mission Control. The JRockit Mission Control tools suite is introduced. Startup and configuration details for different setups are given. We explain how to run JRockit Mission Control in Eclipse, along with tips on how to configure JRockit to run Eclipse itself. The different tools are introduced and common terminology is established. Various ways to enable JRockit Mission Control to access a remotely running JRockit, together with trouble-shooting tips, are provided.
Chapter 7: The Management Console. This chapter is about the Management Console component in JRockit Mission Control. We introduce the concept of diagnostic commands and online monitoring of a JVM instance. We explain how trigger rules can be set, so that notifications can be given upon certain events. Finally, we show how to extend the Management Console with custom components.
Chapter 8: The Runtime Analyzer. The JRockit Runtime Analyzer (JRA) is introduced. The JRockit Runtime Analyzer is an on-demand profiling framework that produces detailed recordings about the JVM and the application it is running. The recorded profile can later be analyzed offline, using the JRA Mission Control plugin. Recorded data includes profiling of methods and locks, as well as garbage collection information, optimization decisions, object statistics, and latency events. You will learn how to detect some common problems in a JRA recording and how the latency analyzer works.
Chapter 9: The Flight Recorder. The JRockit Flight Recorder has superseded JRA in newer versions of the JRockit Mission Control suite. This chapter explains the features that have been added that facilitate even more verbose runtime recordings. Differences in functionality and GUI are covered.
Chapter 10: The Memory Leak Detector. This chapter introduces the JRockit Memory Leak Detector, the final tool in the JRockit Mission Control tools suite. We explain the concept of a memory leak in a garbage collected language and discuss several use cases for the Memory Leak Detector. Not only can it be used to find unintentional object retention in a Java application, but it also works as a generic heap analyzer. Some of the internal implementation details are given, explaining why this tool also runs with a very low overhead.
Chapter 11: JRCMD. The command-line tool JRCMD is introduced. JRCMD enables a user to interact with all JVMs that are running on a particular machine and to issue them diagnostic commands. The chapter has the form of a reference guide and explains the most important available diagnostic commands. A diagnostic command can be used to examine or modify the state of a running JRockit JVM
Chapter 12: Using the JRockit Management APIs. This chapter explains how to programmatically access some of the functionality in the JRockit JVM. This is the way the JRockit Mission Control suite does it. The APIs JMAPI and JMXMAPI are introduced. While they are not fully officially supported, several insights can be gained about the inner mechanisms of the JVM by understanding how they work. We encourage you to experiment with your own setup.
Chapter 13: JRockit Virtual Edition. We explain virtualization in a modern "cloud-based" environment. We introduce the product JRockit Virtual Edition. Removing the OS layer from a virtualized Java setup is less problematic than one might think. It can also help getting rid of some of the runtime overhead that is typically associated with virtualization. We go on to explain how potentially this can even reduce Java virtualization overhead to levels not possible even on physical hardware.
You will need a correctly installed JRockit JVM and runtime environment. To get full benefits from this book, a JRockit version of R28 or later is recommended. However, an R27 version will also work. Also, a correctly installed Eclipse for RCP/Plug-in Developers is useful, especially if trying out the different ways to extend JRockit Mission Control and for working with the programs in the code bundle.
This book is for anyone with a working knowledge of Java, such as developers or administrators with experience from a few years of professional Java development or from managing larger Java installations. The book is divided into three parts.
The first part is focused on what a Java Virtual Machine, and to some extent any adaptive runtime, does and how it works. It will bring up strengths and weaknesses of runtimes in general and of JRockit more specifically, attempting to explain good Java coding practices where appropriate. Peeking inside the "black box" that is the JVM will hopefully provide key insights into what happens when a Java system runs. The information in the first part of the book will help developers and architects understand the consequences of certain design decisions and help them make better ones. This part might also work as study material in a university-level course on adaptive runtimes.
The second part of the book focuses on using the JRockit Mission Control to make Java applications run more optimally. This part of the book is useful for administrators and developers who want to tune JRockit to run their particular applications with maximum performance. It is also useful for developers who want to tune their Java applications for better resource utilization and performance. It should be realized, however, that there is only so much that can be done by tuning the JVM—sometimes there are simple or complex issues in the actual applications, that, if resolved, will lead to massive performance increases. We teach you how the JRockit Mission Control suite suite assists you in finding such bottlenecks and helps you cut hardware and processing costs.
The final part of the book deals with important JRockit-related technologies that have recently, or will soon, be released. This chapter is for anyone interested in how the Java landscape is transforming over the next few years and why. The emphasis is on virtualization.
Finally, there is a bibliography and a glossary of all technical terms used in the book.
This book will, at times, show Java source code and command lines. Java code is formatted with a fixed width font with standard Java formatting. Command-line utilities and parameters are also be printed with a fixed width font. Likewise, references to file names, code fragments, and Java packages in sentences will use a fixed width font.
Short and important information, or anecdotes, relevant to the current section of text is placed in information boxes.
The contents of an information box—this is important!
Technical terms and fundamental concepts are highlighted as keywords. Keywords also often appear in the glossary for quick reference.
Throughout the book, the capitalized tags JROCKIT_HOME and JAVA_HOME should be expanded to the full path of your JRockit JDK/JRE installation. For example, if you have installed JRockit so that your java executable is located in:
C:\jrockits\jrockit-jdk1.5.0_17\bin\java.exe
the JROCKIT_HOME and JAVA_HOME variables should be expanded to:
C:\jrockits\jrockit-jdk1.5.0_17\
The JRockit JVM has its own version number. The latest major version of JRockit is R28. Minor revisions of JRockit are annotated with point release numbers after the major version number. For example R27.1 and R27.2. We will, throughout the book, assume R27.x to mean any R27-based version of the JRockit JVM, and R28.x to mean any R28-based version of the JRockit JVM.
This book assumes that R28 is the JRockit JVM being used, where no other context is supplied. Information relevant only to earlier versions of JRockit is specifically tagged.
JRockit Mission Control clients use more standard revision numbers, for example 4.0. Any reference to 3.x and 4.0 in the context of tools mean the corresponding versions of the JRockit Mission Control clients. At the time of this writing, 4.0 is the latest version of the Mission Control client, and is, unless explicitly stated otherwise, assumed to be the version in use in the examples in this book.
We will sometimes refer to third-party products. No deeper familiarity with them is required to get full benefits from this book. The products mentioned are:
Oracle WebLogic Server—the Oracle J2EE application server.
http://www.oracle.com/weblogicserver
Oracle Coherence—the Oracle in-memory distributed cache technology.
http://www.oracle.com/technology/products/coherence/index.html
Oracle Enterprise Manager—the Oracle application management suite.
http://www.oracle.com/us/products/enterprise-manager/index.htm
Eclipse—the Integrated Development Environment for Java (and other languages).
http://www.eclipse.org
HotSpot™—the HotSpot™ virtual machine.
http://java.sun.com/products/hotspot
See the link associated with each product for further information.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code for the book
Visit http://www.packtpub.com/site/default/files/8068_Code.zip to directly download the example code.
The downloadable files contain instructions on how to use them.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
While parts of this book, mainly the first part, contain generic information on the inner workings of all adaptive runtimes, the examples and in-depth information still assume that the JRockit JVM is used. This chapter briefly explains how to obtain the JRockit JVM and covers porting issues that may arise while deploying your Java application on JRockit.
In this chapter, you will learn:
To get the most out of this book, the latest version of the JRockit JVM is required. For JRockit versions prior to R27.5, a license key was required to access some of the more advanced features in JRockit. As part of the Oracle acquisition of BEA Systems, the license system was removed and it is now possible to access all features in JRockit without any license key at all. This makes it much easier to evaluate JRockit and to use JRockit in development. To use JRockit in production, a license must still be purchased. For Oracle customers, this is rarely an issue, as JRockit is included with most application suites, for example, any suite that includes WebLogic Server will also include JRockit.
At the time of writing, the easiest way to get a JRockit JVM is to download and install JRockit Mission Control—the diagnostics and profiling tools suite for JRockit. The folder layout of the Mission Control distribution is nearly identical to that of any JDK and can readily be used as a JDK. The authors would very much like to be able to provide a self-contained JVM-only JDK for JRockit, but this is currently beyond our control. We anticipate this will change in the near future.
Before JRockit Mission Control is downloaded, ensure that a supported platform is used. The server part of Mission Control is supported on all platforms for which JRockit is supported.
Following is the platform matrix for JRockit Mission Control 3.1.x:
Platform
Java 1.4.2
Java 5.0
Java 6
Linux x86
X
X
X
Linux x86-64
N/A
X
X
Linux Itanium
X (server only)
X (server only)
N/A
Solaris SPARC (64-bit)
X (server only)
X (server only)
X (server only)
Windows x86
X
X
X
Windows x86-64
N/A
X (server only)
X (server only)
Windows Itanium
X (server only)
X (server only)
N/A
Following is the platform matrix for JRockit Mission Control 4.0.0:
Platform
Java 5.0
Java 6
Linux x86
X
X
Linux x86-64
X
X
Solaris SPARC (64-bit)
X (server only)
X (server only)
Windows x86
X
X
Windows x86-64
X
X
Note that the JRockit Mission Control client is not (yet) supported on Solaris, but that 64-bit Windows support has been added in 4.0.0.
When running JRockit Mission Control on Windows, ensure that the system's temporary directory is on a file system that supports per-user file access rights. In other words, make sure it is not on a FAT formatted disk. On a FAT formatted disk, essential features such as automatic discovery of local JVMs will be disabled.
The easiest way to get to the JRockit home page is to go to your favorite search engine and type in "download JRockit". You should end up on a page on the Oracle Technology Network from which the JVM and the Mission Control suite can be downloaded. The installation process varies between platforms, but should be rather self explanatory.
Throughout this book, we will refer to the directory where the JRockit JVM is installed as JROCKIT_HOME. It might simplify things to make JROCKIT_HOME a system variable pointing to that particular path. After the installation has completed, it is a good idea to put the JROCKIT_HOME/bin directory on the path and to update the scripts for any Java applications that should be migrated to JRockit. Setting the JAVA_HOME environment variable to JROCKIT_HOME is also recommended. In most respects JRockit is a direct drop in replacement for other JVMs, but some startup arguments, for example arguments that control specific garbage collection behavior, typically differ between JVMs from different vendors. Common arguments, however, such as arguments for setting a maximum heap size, tend to be standardized between JVMs.
For more information about specific migration details, see the Migrating Applications to the Oracle JRockit JDK Chapter in the online documentation for JRockit.
There are three main types of command-line options to JRockit—system properties, standardized options (-X flags), and non-standard ones (-XX flags).
Startup arguments to a JVM come in many different flavors. Arguments starting with –D are interpreted as a directive to set a system property. Such system properties can provide configuration settings for various parts of the Java class libraries, for example RMI. JRockit Mission Control provides debugging information if started with –Dcom.jrockit.mc.debug=true. In JRockit versions post R28, the use of system properties to provide parameters to the JVM has been mostly deprecated. Instead, most options to the JVM are provided through non-standard options and the new HotSpot style VM flags.
Configuration settings for the JVM typically start with -X for settings that are commonly supported across vendors. For example, the option for setting the maximum heap size, -Xmx, is the same on most JVMs, JRockit included. There are a few exceptions here. The JRockit flag –Xverbose provides logging with optional sub modules. The similar (but more limited) flag in HotSpot is called just –verbose.
Vendor-specific configuration options are usually prefixed with -XX. These options should be treated as potentially unsupported and subject to change without notice. If any JVM setup depends on -XX-prefixed options, those flags should be removed or ported before an application is started on a JVM from a different vendor.
Once the JVM options have been determined, the user application can be started. Typically, moving an existing application to JRockit leads to an increase in runtime performance and a slight increase in memory consumption.
The JVM documentation should always be consulted to determine if non-standard command-line options have the same semantics between different JVMs and JVM versions.
In JRockit versions post R28, there is also a subset of the non-standard options called VM flags. The VM flags use the -XX:<flag>=<value> syntax. These flags can also be read and, depending on the particular flag, written using the command-line utility JRCMD after the JVM has been started. For more information on JRCMD, see Chapter 11.
Sometimes there is a change of runtime behavior when moving from one JVM to another. Usually it boils down to different JVMs interpreting the Java Language Specification or Java Virtual Machine Specification differently, but correctly. In several places there is some leeway in the specification that allows different vendors to implement the functionality in a way that best suits the vendor's architecture. If an application relies too much on a particular implementation of the specification, the application will almost certainly fail when switching to another implementation.
For example, during the milestone testing for an older version of Eclipse, some of the tests started failing when running on JRockit. This was due to the tests having inter-test dependencies, and this particular set of tests were relying on the test harness running the tests in a particular order. The JRockit implementation of the reflective listing of methods (Class#getDeclaredMethods) did not return the methods in the same order as other JVMs, which according to the specification is fine. It was later decided by the Eclipse development team that relying on a particular method ordering was a bug, and the tests were consequently corrected.
If an application has not been written to the specification, but rather to the behavior of the JVM from a certain vendor, it can fail. It can even fail when running with a more recent version of the JVM from the same vendor. When in doubt, consult the Java Language Specification and the documentation for the JDK.
Differences in performance may also be an issue when switching JVMs for an application. Latent bugs that weren't an issue with one JVM may well be an issue with another, if for example, performance differences cause events to trigger earlier or later than before. These things tend to generate support issues but are rarely the fault of the JVM.
For example, a customer reported that JRockit crashed after only a day. Investigation concluded that the application also crashed with a JVM from another vendor, but it took a few more days for the application to crash. It was found that the crashing program ran faster in JRockit, and that the problem; a memory leak, simply came to light much more quickly.
Naturally, any JVM, JRockit included, can have bugs. In order to brand itself "Java", a Java Virtual Machine implementation has to pass an extensive test suite—the Java Compatibility Kit (JCK).
JRockit is continuously subjected to a battery of tests using a distributed test system. Large test suites, of which the JCK is one component, are run to ensure that JRockit can be released as a stable, Java compatible, and certified JVM. Large test suites from various high profile products, such as Eclipse and WebLogic Server, as well as specially designed stress tests, are run on all supported platforms before a release can take place. Continuous testing against performance regressions is also done as a fundamental part of our QA infrastructure. Even so, bugs do happen. If JRockit does crash, it should always be reported to Oracle support engineers.
There are plenty of helpful resources on JRockit and JRockit Mission Control available on the Oracle Technology Network, such as blogs, articles, and forums. JRockit developers and support staff are continuously monitoring the forums, so if an answer to a particular question cannot be found in the forums already, it is usually answered within a few days. Some questions are asked more frequently than others and have been made into "stickies"—forum posts that will stay at the top of the topic listings. There is, for example, a "sticky" available on how to acquire license files for older versions of JRockit.
The JRockit Forum can, at the time of writing, be found here:
http://forums.oracle.com/forums/forum.jspa?forumID=561
Here are the locations of some popular JRockit blogs:
http://blogs.oracle.com/jrockit/
http://blogs.oracle.com/hirt/
http://blogs.oracle.com/staffan/
This chapter provided a short guide for getting started with the JRockit JVM and for migrating existing applications to the JRockit JVM. We covered installing JRockit and provided insights into common pitfalls when migrating a Java application from one JVM to another.
The different categories of command-line flags that JRockit supports were explained, and we showed examples of how to find the version numbers for the different components of the JRockit JDK.
Finally, we provided pointers to additional help.
This chapter covers code generation and code optimization in a JVM runtime environment, both as a general concept as well as taking a closer look at the JRockit code generation internals. We start by discussing the Java bytecode format, and how a JIT compiler works, making a case for the power of adaptive runtimes. After that, we drill down into the JRockit JVM. Finally, the reader learns how to control code generation and optimization in JRockit.
You will learn the following from this chapter:
The main selling point for Java when it first came out, and the main contributor to its success as a mainstream language, was the write once/run everywhere concept. Java programs compile into platform-independent, compact Java bytecode (.class files). There is no need to recompile a Java application for different architectures, since all Java programs run on a platform-specific Java Virtual Machine that takes care of the final transition to native code.
This widely enhanced portability is a good thing. An application, such as a C++ program, that compiles to a platform-dependent format, has a lot less flexibility. The C++ compiler may compile and heavily optimize the program, for example for the x86 architecture. Then x86 will be the only architecture on which the program can run. We can't readily move the program, optimizations and all, to SPARC. It has to be recompiled, perhaps by a weaker compiler that doesn't optimize as well as for x86. Also if the x86 architecture is upgraded with new instructions, the program will not be able to take advantage of these without being recompiled. Portability can of course be achieved by distributing source code, but that may instead be subject to various license restrictions. In Java, the portability problem is moved to the JVM, and thus becomes third-party responsibility for the programmer.
In the Java world, all platforms on which a JVM exists can execute Java. Platform-independent bytecode is not a new concept per se, and has been used in several languages in the past, for example Pascal and Smalltalk. However, Java was the first language where it was a major factor in its widespread adoption.
When Java was new, its applications were mainly in the form of Applets, designed for embedded execution in a web browser. Applets are typical examples of client side programs. However, Java is not only platform-independent, but it also has several other nice intrinsic language properties such as built-in memory management and protection against buffer overruns. The JVM also provides the application with a secure sandboxed platform model. All of these things make Java ideal not only for client applications, but also for complex server side logic.
It took a few years before the benefits of Java as a server-side language were fully acknowledged. Its inherent robustness led to rapidly shorter application development times compared to C++, and to widespread server adoption. Shorter development cycles matter a lot when the application being developed is fairly complex, such as is typically the case for the server side.
While platform-independent bytecode provides complete portability between different hardware platforms, a physical CPU still can't execute it. The CPU only knows to execute its particular flavor of native code.
Throughout this text, we will refer to code that is specific to a certain hardware architecture as native code. For example, x86 assembly language or x86 machine code is native code for the x86 platform. Machine code should be taken to mean code in binary platform-dependent format. Assembly language should be taken to mean machine code in human-readable form.
Thus, the JVM is required to turn the bytecodes into native code for the CPU on which the Java application executes. This can be done in one of the following two ways (or a combination of both):
Naturally, a native code version of a program executes orders of magnitude faster than an interpreted one. The tradeoff is, as we shall see, bookkeeping and compilation time overhead.
The Java Virtual Machine is a stack machine. All bytecode operations, with few exceptions, are computed on an evaluation stack by popping operands from the stack, executing the operation and pushing the result back to the stack. For example, an addition is performed by pushing the two terms to the stack, executing an add instruction that consumes the operands and produces a sum, which is placed on the stack. The party interested in the result of the addition then pops the result.
In addition to the stack, the bytecode format specifies up to 65,536 registers or local variables.
An operation in bytecode is encoded by just one byte, so Java supports up to 256 opcodes, from which most available values are claimed. Each operation has a unique byte value and a human-readable mnemonic.
