Ten years of Java virtual machine

xiaoxiao2021-03-13  201

Text / Cao Xiao Gang

Java virtual machine origin and construct When we say "Java" words, you refer to four interrelated concepts: Java language, Java API, Java Class file format, Java virtual machine. The entire Java system is based on Java virtual machine, because of this, Java security and network mobility can be implemented. Java is not the first system that adopts the "virtual machine" concept, but is the first virtual machine platform that is widely used. "Virtual" is a means of isolating physics resources and logical resources. The "virtual" of the Java virtual machine is a means used to isolate the physical machine, the underlying operating system and the Java language specification implementation. Although Java is an object-oriented language, we usually use a large number of polymorphisms, composition, delegation, but when we discuss virtual machines, the basic concept we see is "" Stack (stack "and" heap ". Based on the "Storage Calculation" model of Von Nyman, all code is saved in the code space, and the program is executed as the program counter pointer changes, jumps. The concept of no registers in the Java virtual machine, method call is made using "stack", which is a safe and simple method. The Java virtual machine supports the isolation of classes through class loaders, which is the basis for Java implementation security. Each class has its own namespace, run in a sandbox with different security levels, so there is no low-level code to access high-level code. The appearance of the class-loaded load is a significant difference in the Java virtual machine and most of the virtual machines implemented by C. Another significant feature of the Java virtual machine is to achieve automatic garbage collection. In order to always write the association between the objects, if the object space is applied in each block, it must be released in the export, and the method call is often the boundary of the object. The maximum benefit of automatic garbage collection brings to developers is that it is very convenient to organize the system into an object map as a whole. Just add an object to this picture, and maintain the association between the objects, but do not need to do it. Complex cleaning work. It is support for this simple object map, or mapping (relational database and object mapping) technology is recently wide, design model is also easier to be accepted by Java groups.

Optimization of Virtual Machines In 1995, the virtual machine execution is based on the "Byte Code Interceptor", that is, each instruction is interpreted on the spot by virtual machine. This causes the speed that is slowly slow. What's more, some people have begun to summarize many "speed optimization experience", such as: "Try to put all the code in a larger method" and "less interface", etc., which is completely designed with Java language The purpose of the destination, now what is a ridiculous tansel, but it is the experience of many programmers. No him, Java itself is too slow. Thow in the top of Java life is so slowly. So, Sun's engineer began to think about improving execution speed. The emergence of JIT static compilers was in October 1996, Sun released the first compiler. The JIT compiler is compiled before performing each code, the result is the local static machine code, and the execution speed has improved. Symantec has been enthusiastically sought after by its proud JIT compiler. At the beginning of 1998, Java 1.2 was released, with a JIT compiler, from this Java user can finally leave the strange "speed optimization experience" that said above. Although the JIT static compiler can solve some problems, performance is still very gap between C / C . What is a good programmer improves running speed? First of all, he will not be stupid to optimize all the code. He will observe, which code is the biggest effect on the overall performance? Then focus on optimizing this code. According to experience, 10% -20% of the entire program will occupy 80% -90% of runtime. With this method, after the same time, after paying the same effort, this excellent programmer has greatly optimized the performance of the entire program. The HotSpot engine is an optimization of this method of imitating artificial. At the beginning of the program run, the Java code is still explained, but the HotSpot engine starts samples. According to the result of the sample, decide that a certain program is to occupy more running time, it is considered "HotSpot", which is the bottleneck of the current program, and the engine starts to start a separate thread. Optimization. Because there is no difference in compilation of the original JIT compiler, the HotSpot engine can focus on the HOTSPOT code, so that this part of the code is more prominent. The previous static compiler can only compile optimization according to the predetermined policy, and the HOTSPOT engine optimization is based on the result of the sample, so this method is valid for all applications. On March 27, 1999, Sun released the first HotSpot engine. In JDK 1.3, in May 2000, the HotSopt engine contains the HOTSOPT engine, which also makes 1.3 into a landmark release. Here, Java's ten-year life has passed half. Hotspot represents a dynamic compilation technology. For Java's large number of programs, combination, combined with object-oriented features, dynamic compilation has a significant advantage over static compilation. For example, Method INLINING. The call is a very time consuming operation. If the method can call the method to directly embed the memory to the caller code, it can save a lot of time, which is called "Method Inline". Because of the overloading of the class, it is difficult to know which properties are demonstrated, and the method is overloaded, so it is difficult to merge Method, so if each method is small, the static optimization can start The role is relatively small. Dynamic compilation Because you can master the overloading conditions at all times, you can combine the relevant method to perform depth optimization.

Modern Java programs, especially after designing mode education, a large number of inheritance, delegation, forming a lot of short ways, dynamic compilation advantages are more obvious. Since the HotSpot appears, the entire Java boundary is oscillated. In the past five years, it is five years of continuing optimization. There are several ways to continue the optimization, one is to study the new sampling algorithm. Because sampling is related to different optimization strategies, it will have a relatively large impact on overall performance. The second is to study the method of depth optimization. The third is to study the algorithm of garbage collection. The garbage collection will bring a short pause, which will bring a negative user experience. Thus, how to increase the efficiency of garbage collection, reduce delays, and the algorithm of the five flowers, such as progressive collection, train algorithm, etc. How to use multiprocessor for parallel collection is also a hotspot for parallel collection when multi-processors. In this regard, the BEA's JROCKET walked in front. The virtual machine in real life is finally, let us take some virtual machines that are visible on the market. The first mentioned, there is no doubt that is the virtual machine of Sun. As the "official implementation" in the public's mind, Sun has the largest user base, and has the status of "compatible reference", and other virtual machines must consider compatibility with Sun virtual machines. For example, JROCKET will exhibit different characteristics of SUN in certain special circumstances, which may have an impact on the program. However, Sun also did not let the majority of users disappointed, although in early performance rather than Symantec, the performance was surpassed by IBM at 1.2, but Sun has been striving to innovate, especially after 1.4.2, and performance has a growing progress. . Although the virtual machine of JDK 1.5 has no improvement in performance, it has enhanced stability. It is said that 8,000 bugs have been revised, it is really sweating. It turned out that we have been enjoying so many bugs below 1.4.2. Secondly, the old style IBM. IBM's JDK found the best performance record at 1.3, since then set up a high-end image. Especially in its WebSphere products have been well evaluated. Its JDK is also one of the first JDKs that support 64bit. Now, IBM JDK is still spelled with BEA at high ends. Then it is the show, the bie's Jrocket. When I said that BEA suddenly sprung up in the JVM field, how much is a little, but it takes the strategy to be particularly simple: I have no, the sorry flower bought the JROCKET in this area, plus the sign in front. Yes. JROCKET is aimed at high-end servers market and has a good performance in multiprocessor environments. In addition, there are several JVMs of open source code worth mentioning. The first is the famous Jikesrvm. Speaking of its big name, most people know that Jikes compilers are IBM development, efficiency is much higher than the equivalent Javac compiler, and many developers use Jikes compilers to replace Javac. JIKESRVM is a complete set of virtual machine technology opened by IBM, including JIT, GC's full implementation, and many papers on its website, it is really trying to study the excellent resources of JVM (http: // jikesrvm) . SourceForge.Net. Kaffe is an old name JVM, but now I have already heard it. When the author wrote this article, the www.kaffe.org website has no response, nor does it know how the current situation is. There are two plans for GNU: GCJ and GNU ClassPath. GNU ClassPath is a bottom-up implementation, while GCJ is a pre-encoder that supports Java.

Conclusion time flow, vigorous Java virtual machine performance debate seems to be reconounced in the ear, now new debate is already "whether Java's performance has exceeds C / C ". JOAKIM DAHLSTEDT is one of the main architects of JROCKIT. He insists that Java is by no means a slower, low-efficiency language, JVM is a key component to ensure that the system's deployment is just like running and developing as fast and easy. Especially in the current development trend is when using a large amount of prefabricated frameworks, dynamic compilation may achieve better performance than static optimizations such as C / C . I really want to calm down to find an open source JVM study.

转载请注明原文地址:https://www.9cbs.com/read-129155.html

New Post(0)