Recently, cloud + community technology salon “Tencent open Source technology” successfully closed. The salon invited a number of Tencent technical experts, in-depth revealed Tencent open source projects TencentOS Tiny, TubeMQ, Kona JDK, TARS and MedicalNet. This article is Mr. Yang Xiaofeng’s detailed introduction of Tencent’s self-developed Kona JDK open source project based on OpenJDK.
1. Tencent Kona origin
1. OpenJDK
You hear a lot about OpenJDK, but what exactly is it? I’m sure you’ve all heard of the Java SE, ME, EE, etc. The Open JDK is usually defined as a free and Open source reference implementation of the Java SE specification.
As early as 2006, Sun committed to gradually open source the core Java Platform, including hotspot, Complier and class libraries. The following year, Redhat came in and released IcedTea, a version built entirely on GNU free software.
There was a big change in 2010 when Oracle took over Stewardship from Sun, IBM came in and gave up Apache Harmony, and Apple joined the OpenJDK.
In 2014, JDK 8 was released, the fastest and most widely adopted version to date, and it remains a workforce in production environments today. Industry surveys this year show that JDK8 remains the leading production JDK release for almost every vendor.
In 2017, JAVA 9 was released after three years of development and a dizzying number of changes took place.
First, from the technical level, JDK introduced the native modular System, also known as Jigsaw project — JPMS (Java Platform Module System). JPMS removed some obstacles for the rapid development of Java language and JDK in the future, but also brought some compatibility problems. JDK 9 has not been the widely anticipated replacement for JDK 8.
Second, Java moved from a feature-driven to a time-driven publishing model. This is due to the rapid development of areas such as cloud computing, which poses a very big challenge to Java.
The traditional release cycle would ideally be about two years, but we were a year or so behind in actual JDK 9 development, and even then we still had some planned work to do.
Long development cycles result in a large number of technologies that are already in place that are delayed from entering production, which greatly slows down Java development and iteration. To accommodate this change, the JDK switched to a new release mode with a six-month cycle.
Third, the Oracle JDK open source commercial features, and changes to the Oracle JDK charging strategy, greatly shorten the JDK free support cycle.
The good news is that despite Java’s “charging” debacle, the OpenJDK community is much more active and engaged today. Vendors like Tencent and Microsoft have joined the community and are actively contributing to OpenJDK.
2. Oracle JDK
What is the relationship between the Oracle JDK and OpenJDK? As a simple comparison, Oracle JDK 8 can be thought of as a superset of OpenJDK that includes its own commercial features.
However, after the development of JDK11, the whole JDK product form has undergone a great change, from a large single application, made a certain degree of decoupling, JMC, OpenJFX and other forms of software package independent of JDK, Oracle also open source their commercial features. So the only difference between Oracle JDK 11 and OpenJDK 11 is the License.
3. Tencent Kona JDK
Tencent Kona JDK is a JDK release based on the main branch of OpenJDK and adheres to the following basic principles.
First, it’s free and everyone can use it.
Second, we will provide long-term and reliable support for LTS versions like JDK8 and JDK11.
Third, the Kona JDK’s ability to ensure production environment readiness through Tencent’s massive load verification.
So what is the relationship between Tencent Kona and the Open JDK? What are the advantages and development ideas?
First, we promise that Kona is a “friend-fork” and will maximize Kona compatibility. The Kona team communicates extensively with a large number of internal JDK users and partner teams to provide high standards of compatibility and stability, reliability, and performance.
The Kona JDK will not innovate for the sake of innovation, because harming JDK compatibility is an irresponsible investment in technology for the enterprise, and will result in future production migration and maintenance costs for users.
In addition, based on Tencent’s massive load of Java/JVM such as big data and cloud, we will share our practical experience and technical precipitation in such a large-scale scenario, and gradually open source them to everyone in the form of Bugfix, Enhancement or Feature.
From the perspective of community participation, we have communicated with the Open JDK community and Oracle Java Product team, and made clear the above principles in the email of the whole community communication. We strictly follow the governance standards of the community and do not be rentier.
Second, OpenJDK technology trends
Going back to OpenJDK itself, what are the major trends to watch right now?
I quote John Rose (Oracle JVM Architect) ‘s summary here.
1. Java-on-Java
Java-on-java refers to the development of JVM virtual machines in the Java language.
For example, the current C1/C2 JIT (just-in-time) compiler, mainly developed In C++, has been very difficult to improve the code, and Oracle has gradually implemented java-based JVM virtual machines In projects such as GraalVM, whose technology will gradually become the core of future JVMS.
At present, it is still in the experimental stage, but it has shown considerable results. For example, with its native machine and SubstrateVM, it can achieve a very breakthrough improvement in boot speed and memory Footprint, and even simple programs can see a 30-fold improvement.
Although this is based on close-world-assumption, the dynamic characteristics of Java have a trade-off, widespread practice is still far away, but the future can be expected.
2. Pay off some debt for the Java language or JVM design implementation
In Java design, everything except primitive data types are objects. Object headers, polymorphic support, and other overhead, which is often overhead for Data, rather than the Data itself.
At the same time, complex reference relationships lead to complexity in memory layout, which makes it difficult to take full advantage of the cache structure of modern cpus. The Java language is also difficult to efficiently and elegantly express some complex data structures and paradigms, which will be addressed in projects such as Valhalla.
3. Java syntax changes
Java syntax has evolved in projects such as Amber/Valhalla to improve the efficiency and quality of code development. For example, local variable type inference is provided in JAVA 10 to simplify code writing and improve code readability through context inference. The following Switch Expression, which is in the preview stage, replaces statements with Expression, greatly improving language Expression ability, development efficiency and good practice.
4. Improved hardware level ability
OpenJDK allows for faster and more direct manipulation of the hardware layer, mainly used in project development such as Panama. For example, it provides computing power support for big data, machine learning, better native code interaction, vector computing and so on.
Of course, there is Project Loom, which improves concurrent programming and execution efficiency, introducing Fiber/Continuation to address current Java concurrent development/execution efficiency issues. As well as the much anticipated Pauseless GC and so on, JVMS in general are becoming smarter and more efficient.
Practice and development in the field of big data
As you know, the mainstream big data stack is either Java based or runs on the JVM. Java and THE JVM provide easy-to-use syntax, cross-platform capabilities, a wide range of tools, libraries, and so on, making the JVM the uncrowned king of big data, with few rivals at present.
However, when it comes to developing and maintaining very large clusters and processing large amounts of data, the JVM becomes increasingly limited.
For example, in the mainstream Hadoop stack, the heap size of nodes such as NM directly affects the cluster and data size, and GC stability is closely related to SLA. At present, THE JVM is far from perfect in heap GC, which needs further improvement.
From the big data load characteristics, the classical GC algorithm has a certain degree of acclimation. We know that the design of the current era is based on a practical experience that “most objects are small and short-lived”. However, in big data loads such as Spark SQL, it is common to see a large number of large objects with long life cycle and even large objects allocated.
Large object allocation and initialization costs are high, and in region-based designs such as the G1 GC, objects 50% or more of the size of a Region occupy one or more partitions, wasting the remaining space, which limits the efficiency of valuable memory resources.
From the perspective of the business characteristics of big data, the JVM mechanism also needs to be tailored and improved. Big data business, for example, the equivalent of step is timing of offline calculation, at different times of the day, the application of behavior change is bigger, and at present the JVM adaptive features because it is not uncommon, G1 continuous prediction GC forecast engine failure caused by GC pause long, sometimes hurt the SLA, targeted improvement is necessary.
Because of the above limitations, many big data frameworks have to work hard to operate out of the heap, bringing efficiency problems in research and development and operation and maintenance.
In production practice, we have noticed that JNI enters critical zone in big data application, GC Locker triggers frequent meaningless Young GC and large object allocation force, which will lead to JVM OOM accident. This problem is more frequent in big data scenario, please refer to the following figure for details.
In addition, both big data and machine learning are inseparable from one core, namely computing power.
Big data relies on parallel computing of data at machine (cluster), thread (multi-core) and instruction (SIMD) levels. Since 2002, the frequency of CPU Core has basically not increased significantly, and even decreased, and the scalability of production load is increasingly dependent on heap CPU and heap machine. Distributed cluster and multithreading are essential, but instruction level optimization at JVM level has not been fully paid attention to, making full use of instruction parallelism is one of the guarantees of computing power.
JVM vectorization /SIMD typically has three approaches:
First, JNI uses native code directly, but is very difficult to develop and maintain due to CPU variability and other reasons.
Second, develop your own JVM intrinsics, which is not unrealistic for the average developer
Third, it is feasible to take advantage of the auto-Vectorization capabilities provided by the JVM.
However, auto-vectorization has many limitations. Currently, SupperWord Optimization is only provided in C2, and Loop Unrolling relying on Counted Loop is difficult and fragile to develop.
At present, the Vector API in the OpenJDK incubation can greatly improve development efficiency and thus performance, and we will actively promote its growth and maturity in the future.
For diagnosing and tuning big data scenarios, Kona’s integrated Java Flight Recorder (Oracle Open Source) provides full-stack JVM Profiling capabilities available in production environments, and provides the possibility to diagnose Memory leaks without Heap Dump. This is very helpful for big data scenarios with massive distributed clusters and frequent heaps/super-large heaps.
It also helps to further understand the general overhead of big data loads, such as serialization/deserialization, memory (object) allocation, and so on.
We will work with the community to enhance SVC tools such as JMap, optimize common overhead, and give back and share our experience with the community.
Fourth, the Q&A
Q: Mr. Yang, what is the difference between the Open JDK and Kona JDK in Tencent Cloud? What are the advantages of doing this?
A: Kona JDK is based on the main branch of Open JDK. It is improved based on the needs and pain points of massive micro-services, Serverless, big data and other practical application scenarios, aiming at providing the best Java running environment and solutions in corresponding scenarios.
The Kona JDK will try to maximize the benefits of the Java ecosystem by using upstream features. In the selection of features, compatibility, maturity and production value are taken into full consideration to bring real efficiency and productivity to users. If there is a specific feature or bug fix that does not meet the general criteria of upstreams to main branches, working ideas, etc., Kona may still choose to provide it as long as it is productive.
In my opinion, from the perspective of Java ecological health, the significance and purpose of Kona JDK is not difference, but long-term and reliable support to accelerate the production of new features of OpenJDK, and enhance the basic strength of Java in data science, cloud computing and other fields.
introduction
Xiaofeng Yang is a senior technical expert at Tencent and a member of the System Software Committee of China Computer Association (CCF). He is currently in charge of the TEG JDK team and OpenJDK Committer. He has led Oracle Java Platform Beijing Core Class Library team and JINGdong Data Foundation Platform Intelligent System RESEARCH and development team, etc., and produced the column “Lecture 36 Java Core Technology”, focusing on the evolution and practice of Java/JVM and other basic software in big data, cloud computing and other frontier fields.