* Development versions of development, to be continued *
Title: Talking about the development of Java VM
Author: Jim Huang (Huang Jing group)
Copyright announcement: Allows the premise of retaining authors, sources, and this announcement, in any human readable form
Free spread
Last updated: APR 16, 2004
Talking about the development of Java VM
Jim Huang
Slightly organizing the author's experience in Java VM, sharing with you, after this article will focus on several
Open Source Java VM Project, the author itself is KaffEvm [1] developer, I hope this article
Can help you see, more expecting your letter, let KaffEvm have better hair by technical exchanges
exhibition.
[1] http://www.kaffe.org/
■ JVM (Java Virtual Machine) with Java firmware
Java VM is a virtual platform, putting this platform hard work, that is, after Materialized, it is
Java chip. Simply, it is a genuine CPU. If we don't need full CPU complex
Design, you can make it Co-Processor, so you don't need to X86 or Sun SPARC
Use Java VM to simulate, but directly on Java Bytecode "Feeding" Java CHIP. This
It is the technology of early Sun called Picojava. Of course, with the input of soft hardware vendors, introduce more
Miscellaneous techniques, but in principle it is still consistent.
"Simulation" is not true, of course, it is more than a loss, so often gives people Java to perform super slow, super consumption
The impression of resources, in fact, it refers to the performance of Virtual Machine. In order to improve the efficiency of JVM, use a lot
Technical acceleration, which is the most important of Just (Just In Time) Compiler (timely compiler, note:
Don't mix with "instant" [realTIME] to mix) Dynamic, such as HotSpot, etc.
CompiLation technology.
Java Chip is OPTimized for Java OOP, EXPTION-HANDLING, MEMORY / GARBAGE
Collection's special Chip, while x86 (ie traditional CPU) does not compile with C Machine
New / Exception-Handling / Memory Allocation / Late-binding for hardware support
Optimization action.
Worship VLSI, Memory Allocation, and Garabage Collection's movements can be delivered to hardware
Come on. In MODEM or TV, the DSP (digital signal processing) CHIP is used in the digital ratio conversion
Have a so-called Bit-Reverse (for FFT [Fast Fourier Conversion]), if it is made in general X86
This action, at which it is 10 times slower. Another example, the past floating point operation, more than 20 ~ 30 times more than the integer operation
However, because there is a floating point accelerator, the speed of floating point operations can be 1.3 times the integer operation!
The foregoing mentioned that JVM can be implemented in the form of Co-Processor, and you can refer to Nazomi Communica-Tions [2] company products, and they launch a Java accelerator wafer, this code is JA108 product
Specially for 2G / 2.5G or 3G mobile phones. You don't need to install additional memory, just need this JA 208
IC is implanted into the original system design, and the Java application efficiency is 15 to 60 times.
[2] http://www.nazomi.com/
Then, the author operates the MS-Windows 2000 on the Pentium III to perform the following experiments: (original code and
Comparison of Machine Code)
C Virtaul Method Calling:
┌───────────────────────
│21: TestX -> SetX (20); // TestX is an indicator object │
│ --────────────────││
│00401091 PUSH 00000014 │
│00401093 MOV EAX, DWORD PTR [TestX] │
│00401096 MOV EAX, DWORD PTR [EAX] │
│00401098 MOV ECX, DWORD PTR [TESTX] │
│0040109B Call DWORD PTR [EAX] │
└───────────────────────
Not Argument 4 instructions
General CALL:
┌──────────────────────────
│ good () │
│ --───────────────────││
│0040109F CALL @ ilt 0 (? Good @@ yaxh @ z) (00401000) │
│004010A4 Add ESP, 00000004 │
└──────────────────────────
Not an argument 2 instructions
Java's Virtual Call:
┌──────────────────────────
│MY.GetData (33); │
│ --───────────────────││
│ ALOAD_2 │
│ BIPUSH 33 │
│ INVOKEVIRTUAL # 9
└──────────────────────────
Not an argument 2 instructions.
C constructor:
┌─────────────────────
│test * Testx = new test (); │
│ --─────────────────────│
│00401056 Push 00000008 ││00401058 CALL ?? 2 @ YAPAXI @ z (00401184) │
│0040105D ADD ESP, 00000004 │
│00401060 MOV DWORD PTR [EBP-0C], EAX │
│00401063 CMP DWORD PTR [EBP-0C], 00000000 │
│00401067 JE main 00000030 (0040107D) │
│0040106D MOV ECX, DWORD PTR [EBP-0C] │
│00401070 CALL @ ilt 15 (?? 0test @@ qae @ xz) (0040100F) │
│00401075 MOV DWORD PTR [TESTX], EAX │
│00401078 JMP main 00000037 (00401084) │
│0040107D MOV DWORD PTR [TESTX], 00000000 │
└─────────────────────
11 instructions
C Destructor:
┌──────────────────────────
│DELETE TESTX; │
│ --───────────────────││
│004010A7 MOV EAX, DWORD PTR [TestX] │
│004010AA MOV DWORD PTR [EBP-10], EAX │
│004010AD MOV EAX, DWORD PTR [EBP-10] │
│004010B0 MOV DWORD PTR [EBP-14], EAX │
│004010B3 MOV EAX, DWORD PTR [EBP-14] │
│004010B6 PUSH EAX │
│004010B7 CALL ?? 3 @ Yaxpax @ z (00401194) │
│004010BC ADD ESP, 00000004 │
└──────────────────────────
8 instructions
Java's constructor:
┌──────────────────────────
│my my1 = new my (); │
│ --───────────────────││
│NEW # 2
│INVOKENONVIRTUAL # 11
└──────────────────────────
2 instructions
This can be found that the operation of the dynamically configurable object, Java is a Method Call as long as a Machine Code, but is relatively related to X86, which is that Java is directly supported in the instruction set level.
We obviously see a advantage of Java-a small destination code, easy to put it in a resource-embarrassing home appliance
In addition, plus many ready-made APIs can make calls, inherited, and simple programming codes can play strong
the power of.
■ Execute Engine
The core of Java VM is the execution engine, its behavioral mode is defined by the instruction set, JLS (Java Language)
Specification) Detailed specification When the execution of the Bytecode instruction, it is not standardized.
Practical, because this is the actor's responsibility. Perform the period, the execution engine exists in the form of thread.
, Such execution can directly translate bytecode or indirectly generate Native Code through JIT Compiler
. The execution engine will take out OPCode and Operant in Bytecode, and perform phase according to JLS specification
Off, then remove an OPCode until the Method returns or throws an Exception. This part
The author is not intended to mention too much, because the market has already had a lot of books for reference, and a book is a reference:
Explore the general Java VM operation mechanism:
1. "Java Virtual Machine" O'Reilly Publishing
Author: Jon Meyer & Troy Dwning
There is a translation: "Java Virtual Machine", translated by domestic Java authoritative Cai Xuezhen
2. "INSIDE The Java 2 Virtual Machine" McGraw-Hill Publishing
Author: Bill Venners
If you think that the last is too abstract, the book written by Venners should be very appetite, please
With books, there is a JVM concept in the interactive Java Applet, the author's website [3]
Pretty extensive information. Although this book has a Chinese translation, it is strongly recommended not to spend money, because of fallacy
Hundreds of.
[3] http://www.Artima.com/insidejvm/Resources/
Focus on embedded JVM design:
"In-depth Java Virtual Machine - ISIDE KVM"
Author: Huyue Wei (Mango Hu)
Almost the only books in the world discussing the books of Java KVM, it is indeed a valuable reference. but
It is necessary to pay attention to whether the author directly digs from the original code of KVM, is it fully authorized, worth
Discuss.
■ Discussion on Java VM Efficiency
At present, the most prominent product of commercial Java VM is BEA's JROCKIT [4]. JROCKIT is mainly
Server-Side app has made a lot of improvements, and Intel assists the IA32 and IA64 platform optimization,
Thus, on a number of Benchmark (Specjbb and Specjapp Server), JROCKIT is far ahead
Group of groups. BEA is a heavyweight manufacturer that leads J2EE technology, in addition to superior skill in Enterprise
Of course, of course, there must be a strong and high-efficiency Java VM, so BEA bought JROCKIT, in many high orders.
Applications can be seen from the trace of JROCKIT VM. There is a text of Joakim dahlstedt on the BEA website.
Chapter, elaborating the performance of Java VM can actually break the many people: [Java - A SlowLanguage? It depends on what you're talking about] [5].
[4] http://www.jrockit.com/
[5] http://dev2dev.bea.com/products/wljrockit81/articles/dahlstedt.jsp
Joakim dahlstedt is not small, is the main designer of JROCKIT VM, currently bea system
The technology of Java Runtime Group, this article is not the old king selling melons, the opposite, JOAKIM
We are clear, the way Java VM "Benchmark" needs to be adjusted, mainly based on
Next:
1. General Benchmark is just Micro-Benchmark Level, which cannot be promoted to System-SYSTEM-
Level.
2. Software industry development has changed a lot, using Class Library, Framework, and
Application Server, or even Web Services. Combine the old Benchmark can only be for them
Individual Software Stack, can not perform comprehensive analysis of System-Level, such a measure of this
There is a problem.
3. Java VM itself's Dynamic Optimization can be adjusted according to the most authentic profile data
Components make it reorganized against efficacy.
4. Finally, the new CPU architecture, like Intel EPICs may be more suitable for Dynamic Optimization
, Not traditional STATIC Compiler. Under EPIC's architecture, Compiler's impact of performance
When large, Compiler is responsible for choosing a parallel handled instruction set, not an automatic introduction of traditional Pentium
Out-of-ORDER's dilating support, which means that the software dominated the EPIC performance, this
Static Compiler is unfavorable because only a fixed statistical and symbol from Bytecode,
Failed to plan a real profile.
JOAKIM's conclusion gives us very good inspiration:
"In conclusion, ..., but i hope 的 i 'convinced you today using runtime
Systems Like Sun Microsystems' Hotspot Or Bea WebLogic JROCKIT JAVA
Is Not Slow or inefficient, and that the performance of a large-scale
System Built with Java May Be Superior To That of the Same System
Built using C. "
IBM's JDK once once a best performance Java VM, but Sun JDK 1. 4 performance has been with IBM JDK
1.3 is equivalent, its Server version uses more active JIT and GARBAG (Garbage Collection) technology, especially
It is a GC that is optimally suitable for the hardware architecture and multi-execution processing for applications for SMP.
On the other hand, IBM will have the results of the internal JALAPENO JVM research [6] with Open Source.
JIKESRVM Planner [7], is provided, providing a reference ongoing platform for testing many JIT and GC and other technologies. IBM Rearch treats JIKESRVM as a Research InfraStru in JIT.
CTURE, ranging a considerable paper on the website. The author refers to the research direction of Jikesrvm.
, It is considered that the JIT Compiler's trend can list the following:
1. Similar to Hotspot [8] Integrated Base Interpreter, Profiling, and Adaptive
The route of three technologies in Compiler.
2. Dynamic Profiling technology, evolution from simple counter-based algorithm to
Performance Monitoring Event.
3. Apply compilation technology in static Compiler (for Jit Compiler,
Compiling time is a secondary issue), producing an optimization code.
4. Apply inter-procedural analysis, such as Escape Analysis can remove synchro-
Nization and Implement Stack Allocation.
5. Refer to the information obtained by Runtime (mainly Metadata and Dynamic Allocation),
Best for the original code.
[6] http://www.research.ibm.com/jalapeno/
[7] http://www-124.ibm.com/developerWorks/oss/jikesrvm/
[8] http://java.sun.com/products/Hotspot/
Then let's take a look at the sun's HotSpot technology. Recommend HOTSPOT can't mention Henry Massalin
The pioneer, the Ph.D. in Henry is known in the explanation of Java Glossary's HotSpot [9]
"The Mother of All self-modifying code", and hotspot is also "Builds Heavily
ON Work Done in a phdhet by henry massalin.
[9] http://mindprod.com/jgloss/Hotspot.html
Java's initial work is through the direct transpreter, but this does not mean that Java must be interpreted.
Line. Early Java VM is indeed an interpretation of the command one by one, so the effectiveness is extremely unsatisfactory, so it is introduced.
JIT and other key technologies, and Hotspot can tell the next generation JIT. According to Sun's official literature, use
Hotspot's Java VM is difficult to distinguish when Java Bytecode is solved by JVM during Runtime.
Release is performed, because HotSpot actually compiles Java's Bytecode to the original code execution.
In fact, two technologies are quite important in HotSpot, that is, the so-called Dynamic
Compilation and profile. Hotspot compiles Bytecode, not before the program is executed
Compiled (this traditional way is called Static Compilation), the opposite is
During the line, the compiler built by HotSpot is dynamically compiled, and the early Just in time.
It is also the same concept, but there is no Hotspot to be comprehensive.
So, how is HotSpot dynamically compile Java Bytecode? HotSpot uses a highly elastic design, which maintains Profile Monitor, specifically monitored, used in judging program segments.
The frequency is high, and the extent to which the performance impact is delivered to several ranking algorithms. Hotspot For those pairs
The program code fragment of the program is highly affected by the program, which is recommended as Hot SPOT (especially lowercase writing, avoiding
Confused with Hotspot), HOTSPOT will dynamically compile the original boss, at the same time, will be based on
The result of Profiling is optimized to these native codes, thereby increasing execution efficiency. Converse, if
The program code fragment of the row frequency, and HotSpot does not have to spend time doing dynamic compilation, only need to be implemented
Come on.
Overall, in Hotspot, Java Bytecode is loaded into JavaVM in an interpreated manner.
But HotSpot immediately performs status executed in some program segments, knowing the maximum impact on performance
Part of the dynamic compilation and optimization process, establish a original code, so, the next execution process can be obtained.
A considerable degree of performance improvement. We can learn that hotspot has the following three of the execution of Bytecode
Mathematical manner:
- Dynamic translation (not dynamic compilation)
- Some dynamic compilation
- Dynamic compilation and optimization process based on profiling results
As part of the program only do direct translation, some dynamic compilation, and what part of the best treatment, the whole process
Profile Monitor is determined.
What is the advantage of using Dynamic Compilation than the traditional Static Compilation? Throw
Entry cross-platform demand, in any case, Dynamic Compilation is superior to traditional ways, especially
PROFILING's ability. Where is the pre-predecessor implementation of the past Static Compilation?
Only the most important part of the best time, can only construct Micro-Level through the built-in Template
Best chemical code. Conversely, Dynamic Compilation can get the most authentic profile performance.
According to the dynamic adjustment of demand, this is more important in the development trend of gradually softization in the future, because
The work of the past hardware is gradually transferred to the soft body, and the responsibility of Compiler Optimization is extravagant.
It is like the aforementioned Intel EPIC architecture.
Another typical example called Method Inline. Whether in C or Java, call
(Invoke) Method is consuming system resources, the system must maintain stacking operations to meet the expected
Calling convention. So, some people put forward the processing of the original INVOCATION,
Change the way in Inline, "Embed" to the original call, this is just a simple step-by-step
There is no stacking operation. However, Method Inline is a class of C and Java
Piece-oriented language, the compiler is difficult to have a good work, because it takes to take into account the characteristics of the object orientation, especially
It maintains Dynamic Binding properties. Static Compiler can actually put C / Java properties
Method Inlinng for Private and Static's Method, but once there is Overridden or Dynamic Binding, Static Compiler cannot know the actual execution status, will be conservative
Implement INLINING. This problem, it is better to be available by Hotspot. Dynamic CompiLation
The plan is solved, because Profiling Monitor can master the situation of Method Invocation,
However, it can be accurately learned in Runtime, Run-Time Type Identification can assist
Hotspot Processing Method Inline, therefore, in Server-Side apps to repeat a project
When executed, there is a lot of effective performance.
Sun's literature also pointed out that in some cases, Java's application can even be faster than traditional C programs.
In terms of development, JIT Compiler's cost is mainly Profiling and Dynamic Compila-
TION two. Ideally, these two costs should be considered constant dame, so many research papers should be
As success, it is proposed as an improvement. Specially made for Jit Compiler, accuracy does not require high Java