In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "detailed explanation of the New Features of JDK12". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. JDK12's Shenandoah low pause time garbage collector (experimental)
Definition:
Add a new garbage collection (GC) algorithm called Shenandoah to reduce GC pause time by evacuating at the same time as running Java threads. The pause time for using Shenandoah is independent of the heap size, which means that whether the heap is 200MB or 200GB, it will have the same consistent pause time.
Non-target:
This is not a GC that rules everyone. There are other garbage collection algorithms that can give priority to throughput or memory usage over responsiveness. Shenandoah is an algorithm for evaluating responsiveness and predictable short pauses in applications. The goal is not to resolve all JVM pause issues. The pause time is beyond the scope of this GC due to reasons other than JEP, such as secure Point in time (TTSP) publishing or monitoring inflation.
Build and invoke:
As an experimental feature, Shenandoah requires-XX:+UnlockExperimentalVMOptions on the command line. The Shenandoah build system automatically disables unsupported configurations. Downstream builders can choose-- with-jvm-features=-shenandoahgc disables building Shenandoah on other supported platforms. To enable / use ShenandoahGC, the following JVM options are required:-XX:+UnlockExperimentalVMOptions-XX:+UseShenandoahGC2, Microbenchmark Suite of JDK12
Definition:
Add a basic set of microbenchmarks to the JDK source code so that developers can easily run existing microbenchmarks and create new ones.
Goal:
1. Based on [Java Microbenchmark harness (JMH)] [1] 2, stable and adjusted benchmark testing, for continuous performance testing 2.1, stable and immobile suite 2.2 after functional release milestones, and after non-functional versions, support applicable test comparison with previous JDK versions 3, simple 3.1 easily add new benchmark 3.2 in API and option changes When not recommended or deleted during development, test 3.3 can be easily updated, easy to build 3.4 easy to find and run benchmark 3.5 support JMH update 3.6 initial set of approximately a hundred benchmarks in the suite 3, Switch expression for JDK12 (preview version)
The preview function, if the switch effect of the jdk12 is not good, will be directly removed by the next version of jdk13, which is not necessary for every later version.
Many break make it unnecessarily verbose, and if you forget to write break, it will produce unexpected results or exceptions, so the jdk12 has been optimized and upgraded here.
Previous versions of JDK12:
Switch (day) {case MONDAY: case FRIDAY: case SUNDAY: System.out.println (6); break; case TUESDAY: System.out.println (7); break; case THURSDAY: case SATURDAY: System.out.println (8); break; case WEDNESDAY: System.out.println (9); break;}
JDK12: we propose to introduce a new form of switch tag, written as "case L->", which means that if the tag matches, only the code on the right side of the tag will be executed.
Switch (day) {case MONDAY, FRIDAY, SUNDAY-> System.out.println (6); case TUESDAY-> System.out.println (7); case THURSDAY, SATURDAY-> System.out.println (8); case WEDNESDAY-> System.out.println (9);}
Many Switch expressions, each case assigns a value to a variable or performs some action, as follows, assigning a specific value to the numLetters variable.
Before JDK12:
Int numLetters;switch (day) {case MONDAY: case FRIDAY: case SUNDAY: numLetters = 6; break; case TUESDAY: numLetters = 7; break; case THURSDAY: case SATURDAY: numLetters = 8; break; case WEDNESDAY: numLetters = 9; break; default: throw new IllegalStateException ("Wat:" + day);}
JDK12: expressing this as a statement is circuitous, repetitive, and error-prone. It means that we should calculate the value of numLetters every day. It should be possible to say directly that using clearer, more secure Switch expressions
Int numLetters = switch (day) {case MONDAY, FRIDAY, SUNDAY-> 6; case TUESDAY-> 7; case THURSDAY, SATURDAY-> 8; case WEDNESDAY-> 9;}
If you use it on a method, you can:
Static void howMany (int k) {switch (k) {case 1-> System.out.println ("one"); case 2-> System.out.println ("two"); case 3-> System.out.println ("many");}}
Or on the class, the switch function that I think of can be used in abstract factory classes.
T result = switch (arg) {case L1-> E1; case L2-> e2; default-> e3;}; 4. JVM constant API of JDK12
Summary:
API is introduced to simulate the nominal descriptions of key class files and runtime artifacts, especially constants that can be loaded from a constant pool.
Motivation:
Each Java class file has a constant pool that stores the operands of bytecode instructions in the class. In a broad sense, entries in a constant pool describe runtime artifacts (such as classes and methods) or simple values (such as strings and integers). All of these entries are called loadable constants because they can be used as operands of the ldc instruction ("load constants"). They may also appear in the static parameter list of the bootstrap method of the invokedynamic instruction. Executing a ldc or invokedynamic instruction causes the load constant to be parsed into a standard Java class, such as the "live" value Class,String or int. Programs that operate class files need to model bytecode instructions and loadable constants in turn. However, it is inappropriate to use standard Java types to simulate loadable constants. Loadable constants that describe strings (CONSTANT_String_info entries) may be acceptable because generating "real-time" String objects is simple, but loadable constants that describe classes (CONSTANT_Class_info entries) are problematic because generating "real-time" ClassObject depends on the correctness and consistency of class loading. Unfortunately, classes are loaded with many environmental dependencies and failure patterns: the required class does not exist or the requester may not be able to access it; the result of class loading varies from context to context; loading the class has side effects; and sometimes class loading may not be possible at all (for example, when the described class does not already exist or cannot be loaded, such as during compilation of similar classes or during jlink transformation). Therefore, if a program that handles loadable constants can manipulate classes and methods in pure nominal form, as well as lesser-known artifacts (such as method handles and dynamically calculated constants), it will be simpler: 1. Bytecode parsing and generation libraries must describe classes and method handles in symbolic form. If there are no standard mechanisms, they must use ad-hoc mechanisms, whether it's ASM's descriptor type Handle, or string tuples (method owner, method name, method descriptor), or the special (and error-prone) nature of these mechanisms to encode a single string. 2. If they could work in the symbol field instead of using "real-time" classes and method handles, invokedynamic would be easier to manipulate by rotating bytecode (such as LambdaMetafactory). 3. Compilers and offline converters (such as jlink plug-ins) need to describe classes and members that cannot be loaded into the running VM. Compiler plug-ins, such as comment processors, also need to use symbolic terms to describe program elements. 5. One AArch74 port of JDK12 instead of two
Summary:
Arm64 removes all port-related sources while retaining 32-bit ARM ports and 64-bit aarch74 ports.
Motivation:
Removing this port will allow all contributors to focus their efforts on a single 64-bit ARM implementation and eliminate the duplication of work required to maintain both ports. 6. Default CDS file of JDK12
Summary:
Use the default class list on the 64-bit platform to enhance the JDK build process to generate class data sharing (CDS) archives.
Goal:
1. Improve out-of-the-box startup time 2. Eliminate the need for users to run-Xshare:dump to benefit from CDS. 7. Mobile mixed collection of JDK12's G1.
Summary:
If the G1 blend set may exceed the pause target, it can be aborted.
Motivation:
One of the goals of G1 is to meet the user-provided pause time target to pause its collection pause. G1 uses the advanced analysis engine to select the amount of work to be done during the collection (this is based in part on application behavior). The result of this selection is a set of areas called collection sets. Once the collection has been determined and the collection has been started, G1 must collect all active objects in all areas of the collection without stopping. If the heuristic chooses too large a collection, this behavior can cause G1 to exceed the pause time target, for example, if the behavior of the application changes so that the heuristic works on "stale" data. This can be observed especially during mixed collections, where collection sets can usually contain too many old regions. A mechanism is needed to detect when the heuristic repeatedly selects the wrong workload for the collection, and if so, let G1 perform the collection incrementally, where the collection can be aborted after each step. This mechanism will allow G1 to meet the pause time target more frequently. 8. JDK12 immediately returns unused committed memory from G1
Summary:
Enhance the G1 garbage collector to automatically return Java heap memory to the operating system when idle.
Success indicators:
If application activity is very low, G1 should release unused Java heap memory within a reasonable period of time.
Motivation:
The current G1 garbage collector may not be able to return committed Java heap memory to the operating system in a timely manner. G1 returns memory from the Java heap only during full GC or concurrent cycles. Because G1 is difficult to completely avoid full GC and only triggers concurrent cycles based on Java heap occupancy and allocation activities, in many cases it does not return Java heap memory unless this operation is enforced externally. This behavior is particularly disadvantageous in a container environment that uses resources to pay. Even when VM uses only a fraction of its allocated memory resources because of inactivity, G1 retains all Java heaps. As a result, customers always pay for all resources, and cloud providers are unable to make full use of their hardware. If VM can detect underutilization of the Java heap (the "idle" phase) and automatically reduce its heap usage during that period, both will benefit. Shenandoah and OpenJ9's GenCon collectors already provide similar functionality. 9. Unicode11 is supported in the core library java.lang
JDK version 12 includes support for Unicode 11.0.0. After the release of JDK 11, which supports Unicode 10.0.0, Unicode 11.0.0 introduced the following new features included in JDK 12:
1,684 new characters 1.1,66 emoji characters 1.2, Copyleft symbol 1.3, half star 1.4of the rating system, additional horoscope 1.5, chess Chinese chess symbol 2, 11 new block 2.1, Georgian extension 2.2, Mayan number 2.3, Indian Siyaq number 2.4, chess symbol 3, Seven new scripts 3.1,3.2,3.3,3.4,3.4,3.5,3.5,3.6,3.7,3.7,3.5,3.6,3.7,3.7,3.5,3.6,3.7,3.7,3.5,3.5,3.5,3.5,3.5,3.5,3.5,3.5,3.6,3.7,3.7,3.5,3.5,3.6,3.7,3.7,3.5,3.5,3.6,3.7,3.7,3.5,3.5,3.5,3.5,3.6,3.7,3.7,3.5,3.5,3.5,3.6,3.7,3.7,3.and Medefaidrin10, the core library java.text support for compressed digital format NumberFormat added support for formatting numbers in a compact format. A compact number format is a number expressed in short or human-readable form. For example, in the en_US locale, 1000 can be formatted as "1K" and 1000000 can be formatted as "1m", depending on the specified style NumberFormat.Style. The compact digital format is defined by LDML's Compact Number format specification. To get an example, use one of the factory methods given in the NumberFormat compact digital format. For example: NumberFormat fmt = NumberFormat.getCompactNumberInstance (Locale.US, NumberFormat.Style.SHORT); String result = fmt.format (1000); the above example leads to "1K". 12. Security library java.security
Disable and allow options for java.security.manager system properties
New "disallow" and "allow" token options have been added to the java.security.manager system properties. In the JDK implementation, if the Java virtual machine starts with the system property java.security.manager set to "disallow", the System.setSecurityManager method cannot be used to set the security manager and will throw a UnsupportedOperationException. The "disallow" option improves run-time performance of applications that have never set the security manager.
Groupname option added to keytool key pair generation
-groupname adds a new option, keytool-genkeypair, so that users can specify named groups when generating key pairs. For example, keytool-genkeypair-keyalg EC-groupname secp384r1 will use the secp384r1 curve to generate EC key pairs. Because there may be multiple curves of the same size, using this-groupname option takes precedence over the-keysize option.
New Java Flight Recorder (JFR) Security event
Skip it.
Custom PKCS12 KeyStore generation
New system and security attributes have been added to enable users to customize the generation of PKCS#12 KeyStore. This includes algorithms and parameters for key protection, certificate protection, and MacData. A detailed description of these properties and a possible value java.security can be found in the PKCS12 KeyStore Properties section of the file. 13. Security library javax.net.ssl
ChaCha20 and Poly1305 TLS password
A new TLS cipher suite using the ChaCha20-Poly1305 algorithm has been added to JSSE. These cipher suites are enabled by default. The TLS_CHACHA20_POLY1305_SHA256 cipher suite applies to TLS 1.3. 14. Security Library / org.ietf.jgss
Support for dns_canonicalize_hostname in krb5.conf
The configuration file for krb5.conf in the dns_canonicalize_hostname flag is now supported by the JDK Kerberos implementation. When set to "true", the short hostname in the service principal name is normalized to a fully qualified domain name, if available. Otherwise, normalization is not performed. The default value is true ". This is also the behavior before JDK 12. 15. Delete items
Delete the finalize method in java.util.ZipFile / Inflator / Deflator in the core library / java.util.jar
The finalize method in java.util.ZipFile,java.util.Inflator and java.util.Deflator is deprecated in JDK9 to remove and perform an update, which is a null operation. The finalize is deleted in the method java.util.ZipFile,java.util.Inflator and java.util.Deflator in this version. Finalize should modify the subclasses overridden to perform cleanup to use the alternate cleanup mechanism and remove the write finalize method. Finalize method to remove the subclasses ZipFile,Deflater and Inflater to which the Object.finalize will be exposed. The finalize changes due to the declared exception, and a compilation error may occur when overwriting. Object.finalize now announces that java.lang.Throwable is being thrown. Previously, only java.io.IOException announced.
Core library / java.io, remove the finalize method from FileInputStream and FileOutputStream
The finalize methods FileInputStream and FileOutputStream are deprecated to remove JDK 9. They have been deleted in this version. The java.lang.ref.Cleaner, the main mechanism since JDK9 has been implemented to close file descriptors no longer from reachable FileInputStream and FileOutputStream. The recommended way to close a file is to explicitly call close or use try-with-resources.
Tool / javac delete javac supports 6 / 1.6 source, destination and release values
The support for the parameter values of javac 6apace 1.6-source,-target and-release flags have been removed. This is the end of the introduction of "detailed explanation of the new features of JDK12". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.