The Java HotSpotTM Server VM

来源:互联网 发布:模拟位置什么软件 编辑:程序博客网 时间:2024/05/18 05:56

来源:

http://java.sun.com/products/hotspot/docs/general/hs2.html

 

 

 

The Java HotSpotTMServer VM

The Solution for Reliable, Secure Performance forthe Enterprise

Documentation Contents

 

The Java HotSpotTM Server VM is Sun Microsystem's solutionfor providing fast, reliable JavaTM technology in the enterprise server environment. Mostreviews and analyses of Java HotSpot technology have focused on itsworld-class speed. This is understandable; the Java HotSpot Server VMwas the world's fastest virtual machine implementation when it was launched (with the product name "Java HotSpot Performance Engine") inApril 1999, and performance tuning has increased its speed by well over 30%since then. However, this document highlights a different, though equallyimportant, aspect of Java HotSpot technology -- its reliability, robustness, and security.

Security

The Java HotSpot Server VM isthe most secure solution for Java technology on the server. In fact, the JavaHotSpot Server VM is fully as secure as a straight interpreter, evenwhile adaptively compiling and de-compiling code on the fly. The Java HotSpotServer VM also supports the entire suite of security enhancementsthat are part of the new Java 2 Platform.

Secure as an Interpreter

Security on the Java platform is basedon protection domains. When the Java platform calls a method to perform asecurity-sensitive operation, it typically happens that the method invocationsets off a series of calls to methods in different classes before the desiredoperation is actually performed. In such cases, the security mechanism mustensure that each class on the call stack meets the security requirements ofthe operation that is finally performed.


The Java HotSpot Server VM is as fully secure as a straight interpreter, even while adaptively compiling and decompiling code on the fly.

Checking the protection domains on thecall stack presents no problem for interpreted code. For interpreted code, thestack is a true source-level call stack that exactly represents the structureof the bytecodes being executed. When compiling and inlining code, however,the information in the stack can become scrambled. Once compiled code from onemethod has been inlined into another method's code in a second class, thefirst class no longer appears on the call stack, and its protection domaincannot be checked by the platform's security mechanism. This presents a realobstacle for JIT and static compilers, and forces them to be very conservativein their inlining so they don't compromise security.

The Java HotSpot Server VMsurmounts this problem by using, in effect, two call stacks. One stackreflects the fully optimized state of the dynamically compiled code, andHotSpot uses this stack for running the program. HotSpot also constructs ondemand a second, ``virtual'' stack that retains the source-level callstructure of the original bytecode. By referring to the virtual stack asnecessary, the Java HotSpot Server VM can achieve the security of aninterpreter while retaining the full performance benefits of its optimizing compiler.

Support for Java 2 Platform Security Enhancements

The Java HotSpot Server VMsupports the Java 2 Platform, including the Java 2 Platform's securityenhancements. The new security features include:

Policy-based, easily-configurable,fine-grained access control

When code is loaded, it is assigned permissionsbased on the security policy currently in effect. Each permission specifies apermitted access to a particular resource (such as "read" and "write" access to a specified file or directory, "connect" access to a given host and port, etc.). The policy, specifying whichpermissions are available for code from various signers/locations, can beinitialized from an external configurable policy file. Unless a permission isexplicitly granted to code, it cannot access the resource that is guarded bythat permission.

The permissions and policy-basedsecurity of the Java 2 Platform is fully supported by the Java HotSpotServer VM.

Certificate interfaces and electronic signing

The Java HotSpot Server VM alsosupports the new certificate interfaces for parsing and managingelectronically signed certificates.

Robustness

The Java HotSpot Server VM hasmany features that make it a more robust solution for enterprise computingthan either JIT compilers or static compilation solutions.

Debugging

The Java HotSpot Server VM'svirtual call stack gives it a big advantage in debugging as well as security.HotSpot can generate a debugging stack trace from the virtual stack when aprogram bug is encountered. Because the source-level virtual stack representsthe true structure of a program, the stack traces produced from it yieldunambiguous information about the location of potential problem spots in the code.

Without access to such a source-levelcall stack, traces produced by JIT compilers and VMs running staticallycompiled code are much more difficult to interpret.

The debugging problems are compounded inthe case of static compilers because the code being executed is actuallycompiled C code rather than compiled bytecode, adding an additional layer ofindirection and translation between the stack trace and the program's originalJava source code.

Code Size

The Java HotSpot Server VMcompiles only those parts of an application that are performance bottlenecks.Typically this will involve only a small part of the program, perhaps aslittle as 10% of the bytecode. Because only a relatively small amount of codeis compiled, the Java HotSpot Server VM keeps runtime code size assmall as possible while delivering the performance of large, fully optimized code.

Portability

The dynamic compiler in the Java HotSpotServer VM is highly portable, relying on a relatively small machinedescription file to describe all aspects of the target hardware. Theportability of the compiler is attested by the fact that both implementationsreleased by Sun (one for Win32 platforms and one for SolarisTM SPARCTM platforms) have posted best SPEC JVM 98 results fortheir respective hardwares.

The Java HotSpot Server VM hasan additional dimension of portability not available to statically compiledcode in that HotSpot takes bytecodes as input. This gives HotSpot theflexibility of an interpreter with the performance benefits of compiled code.The Java HotSpot Server VM can run bytecodes loaded remotely, makeuse of optional packages (formerly known as standard extensions), and can takeadvantage of introspection and reflection, all with fully optimized performance.

Garbage Collection

The Java HotSpot Server VM'sgarbage collector is fully accurate, unlike the conservative garbagecollectors on most other Java runtime systems. Because the Java HotSpotcollector is fully accurate, it can make several strong design guarantees thata conservative collector cannot make:

  • Allinaccessible object memory can be reclaimed reliably.
  • Allobjects can be relocated, allowing object memory compaction, which eliminatesobject memory fragmentation and increases memory locality.

The Java HotSpot garbage collector isalso fully incremental, eliminating user-detectable garbage-collection pauses.The incremental collector scales smoothly, providing non-distruptive,relatively constant pause times even when extremely large object data sets arebeing manipulated. This provides excellent behavior for:

  • Serverapplications, especially high-availability applications
  • Applicationsthat manipulate very large ``live'' object data sets
  • Applications where all user-noticeablepauses are undesirable, such as highly interactive applications.

Systems that run statically compiledcode will be hard pressed to match the benefits of the Java HotSpot garbagecollector for long-running enterprise applications: no memory leaks, no heapfragmentation.


Systems that run statically compiled code will be hard pressed to match the benefits of the Java HotSpot garbage collector for long-running applications: no memory leaks, no heap fragmentation.

Dynamic Compilation

Straight bytecode interpretation is tooslow for most enterprise applications. Any viable solution for performance onthe enterprise needs to include compilation of the bytecodes toplatform-specific native code to achieve reasonable program execution speed.Several strategies have been developed for addressing this need. Thestrategies can be categorized broadly by whether the compilation to nativecode takes place before runtime (static compilation) or during runtime(dynamic compilation) as with the Java HotSpot Server VM. Dynamiccompilation has emerged as the clear winner over static compilation forperformance.


Dynamic compilation has emerged as the clear winner over static compilation for performance.

The Java HotSpot Dynamic Compiler

The Java HotSpot Server VMstarts a program by interpreting the bytecodes. As the program runs, aprofiler monitors the program to determine the most heavily used portions ofthe code.

Nearly all applications spend most oftheir time in only a small portion of their code. The Java HotSpot profileridentifies those parts of an application's code that are most critical forperformance. Java HotSpot then compiles and optimizes the performance-critical``hot spots'' without wasting time compiling seldom-used code. Furthermore,the runtime analyses also enable the compiler to perform native-codeoptimizations not possible with static compilers.

Static Compilers

In contrast to dynamic compilers, staticcompilers translate bytecode into native code before runtime. For example, itis possible to first convert bytecodes into C source code, which is thencompiled into platform-specific native code, as illustrated schematically inthe following figure.

Optimization

The Java HotSpot Server VM'sruntime analyses allow it to perform optimizations during compilation that areimpossible with static compilers. For example, the HotSpot profiler candetermine actual runtime sizes of arrays and vectors, identify program hotspots, and provide up-to-date information about what objects the program iscreating and what classes have been loaded. The dynamic compiler can generatecode that is tailor-made for the specific behavior of the program. Oneimportant optimization that dynamic compilation enables is aggresive method inlining.

Method Inlining

Method inlining is an important compileroptimization. However, static compilers are restricted in the amount ofinlining they can do, for a couple of reasons. First, a static compiler caninline a method only if the compiler can determine that method is notoverridden in a subclass. A static compiler can inline static, final, andprivate methods because it knows those methods can't be overridden. However,public and protected methods can be overridden in a subclass, and staticcompilers therefore cannot inline those methods.

Second, even if it were possible todetermine through static analysis which methods are overridden and which arenot, a static compiler still could not inline public methods. The Javalanguage allows for loading of classes during runtime, and such dynamicallyloaded classes can change the structure of a program significantly. Inparticular, such dynamic loading can render invalid any inlining that was donebased on pre-runtime, static analyses.

The Java HotSpot dynamic compiler usesruntime analysis to perform inlining aggressively, yet safely. Once the JavaHotSpot profiler has collected runtime information about program hot spots, itnot only compiles the hot spot into native code, but performs extensive methodinlining on that code. The Java HotSpot compiler can afford to be aggressivein the way it inlines because it can always back out an inlining optimizationif it determines that the method inheritance structure has changed duringruntime due to dynamic class loading.

The Java HotSpot Server VM canrevert to using the interpreter whenever compiler deoptimizations are calledfor because of dynamic class loading. When a class is loaded dynamically,HotSpot checks to ensure that the inter-class dependecies of inlined methodshave not been altered. If any dependencies are affected by dynamically loadedclass, HotSpot can back out affected inlined code, revert to interpreting fora while, and re-optimize later based on the new class dependencies.

When running statically compiled code,on the other hand, a virtual machine does not have access to the originalbytecodes, and cannot fall back on an interpreter when optimizations in thestatically compiled code become unsafe. Therefore, static compilers cannot beas aggressive in their optimization as dynamic compilers, and a performancepenalty is the result.

The extensive inlining enabled by theJava HotSpot dynamic compiler gives it a huge advantage over static compilers.Inlining reduces the number of method invocations and their associatedperformance overhead. This is a significant bonus with the Java programminglanguage in which methods are virtual by default and method invocations arefrequent.


The extensive inlining enabled by the Java HotSpot dynamic compiler gives it a huge advantage over static compilers.

Furthermore, method inlining issynergistic with other optimizations. Inlining produces large blocks of codewhich make additional optimizations easier for the compiler to perform. Theability of the Java HotSpot Server VM to do aggressive inlining is akey factor in making HotSpot faster than current JIT and static compilers.

Summary -- Secure and Robust As Well As Fast

Java HotSpot technology enableshigh-performance, optimized code to be as secure as interpreted code.Moreover, the same technology adds robustness to the runtime environment byreducing runtime code size, eliminating memory leaks, reducing heapfragmentation, and enabling pauseless garbage collection.

The Java HotSpot Server VMtakes bytecodes as input, allowing for easier code debugging, dynamicde-optimization at runtime, and the flexibility to run dynamically loadedbytecodes with optimized performance.

What's more, the Java HotSpotServer VM supports all features of the latest version of the Java 2Platform, including the new security enhancements.

In short, the Java HotSpot Server VM isthe best solution for providing fast, reliable Java technology for the enterprise.


Copyright © 1999 Sun Microsystems, Inc. All Rights Reserved.  Sun Microsystems, Inc
Java Software
原创粉丝点击