search
HomeJavajavaTutorialLet's talk about the Java Valhalla Project

This article brings you relevant knowledge about java, which mainly introduces the introduction of the Java Valhalla Project and a detailed introduction around the theme. Let’s take a look at it together. I hope it will be helpful to everyone. helpful.

Let's talk about the Java Valhalla Project

Recommended study: "java Video Tutorial"

In this article, we will introduce the Valhalla project - its historical reasons , the current state of development, and what it will bring to everyday Java developers after its release.

Motivation and reasons for the Valhalla project

Oracle's Java language architect Brian Goetz said in a speech that one of the main motivations for the Valhalla project is the desire to adapt the Java language and runtime to modern hardware. . When the Java language was born (at the time of writing about 25 years ago), access to memory and arithmetic operations cost about the same.

Today, this situation has changed, and memory fetch operations are 200 to 1000 times more expensive than arithmetic operations. In terms of language design, this means that indirect operations that result in pointer extractions can adversely affect overall performance.

Since most Java data structures in an application are objects, we can think of Java as a Pointer-intensive language (although we usually don't see or manipulate them directly) . This pointer-based object implementation is used to enable object identification, which itself is used for language features such as polymorphism, mutability, and locking. By default, these properties apply to every object regardless of whether they are actually needed.

Following the chain of identifiers leading to pointers and the chain of pointers leading to indirection, indirection has a performance drawback and the logical conclusion is to delete those data structures that do not require them. This is where value types come into play.

Value Types Value Types

The concept of value types is to represent pure data aggregation. This removes functionality from regular objects. So we have pure data, no identity. Of course, this means that we also lose the functionality that can be achieved using object identification. Therefore, equality comparisons can only be made based on status. Therefore, we cannot use representation polymorphism, nor can we use immutable or non-nullable objects.

Since we no longer have object identifiers, we can abandon pointers and change the general memory layout of value types instead of objects. Let's compare the memory layout between class points and corresponding value type points.

The code and corresponding memory layout of the regular Point class are:

final class Point {
  final int x;
  final int y;
}

On the other hand, the value type Point The code and corresponding memory layout would be:

value class Point {
  int x;
  int y
}

This allows the JVM to flatten value types into arrays and objects, as well as other value types.

In the image below, we show the indirect negative effects when using the Point class in an array:

On the other hand, Here we see the corresponding memory structure for the value type Point[]:

It also enables the JVM to pass value types on the stack without having to Allocate them on the heap. In the end, this means that we get data aggregations with runtime behavior similar to Java primitives like int or float.

But unlike primitives, value types can have methods and fields. We can also implement interfaces and use them as generic types.

Therefore, we can look at value types from two different perspectives:

  • Faster objects
  • User-defined primitives

As an extra icing on the cake, we can use value types as generic types without boxing. This leads us directly to another big project Valhalla feature: specialized generics.

Specialized Generics

When we want to generalize a language primitive, we currently use boxed types, such as integer representationIntegeror floating point representation Float. This boxing creates an extra layer of indirection, thereby defeating the purpose of using primitives to improve performance in the first place.

As a result, we see many specializations for primitive types in existing frameworks and libraries, such as IntStream<t></t> or ToIntFunction<t></t> . This is done to maintain the performance improvements of using primitives.

Therefore, specializing generics is to eliminate the need for these "hacks". Instead, the Java language strives to enable generic types for basically everything: object references, primitives, value types, and maybe even void.

Conclusion

We have a preliminary understanding of the changes that the Valhalla project will bring to the Java language. Two of the main goals are to improve performance and reduce leaky abstractions.

Performance enhancements are addressed by flattening the object graph and removing indirection. This results in a more efficient memory layout and fewer allocations and garbage collections.

When used as a generic type, primitives and objects have more similar behavior, which is a better abstraction.

Recommended study: "java video tutorial"

The above is the detailed content of Let's talk about the Java Valhalla Project. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:脚本之家. If there is any infringement, please contact admin@php.cn delete
How does cloud computing impact the importance of Java's platform independence?How does cloud computing impact the importance of Java's platform independence?Apr 22, 2025 pm 07:05 PM

Cloud computing significantly improves Java's platform independence. 1) Java code is compiled into bytecode and executed by the JVM on different operating systems to ensure cross-platform operation. 2) Use Docker and Kubernetes to deploy Java applications to improve portability and scalability.

What role has Java's platform independence played in its widespread adoption?What role has Java's platform independence played in its widespread adoption?Apr 22, 2025 pm 06:53 PM

Java'splatformindependenceallowsdeveloperstowritecodeonceandrunitonanydeviceorOSwithaJVM.Thisisachievedthroughcompilingtobytecode,whichtheJVMinterpretsorcompilesatruntime.ThisfeaturehassignificantlyboostedJava'sadoptionduetocross-platformdeployment,s

How do containerization technologies (like Docker) affect the importance of Java's platform independence?How do containerization technologies (like Docker) affect the importance of Java's platform independence?Apr 22, 2025 pm 06:49 PM

Containerization technologies such as Docker enhance rather than replace Java's platform independence. 1) Ensure consistency across environments, 2) Manage dependencies, including specific JVM versions, 3) Simplify the deployment process to make Java applications more adaptable and manageable.

What are the key components of the Java Runtime Environment (JRE)?What are the key components of the Java Runtime Environment (JRE)?Apr 22, 2025 pm 06:33 PM

JRE is the environment in which Java applications run, and its function is to enable Java programs to run on different operating systems without recompiling. The working principle of JRE includes JVM executing bytecode, class library provides predefined classes and methods, configuration files and resource files to set up the running environment.

Explain how the JVM handles memory management, regardless of the underlying operating system.Explain how the JVM handles memory management, regardless of the underlying operating system.Apr 22, 2025 pm 05:45 PM

JVM ensures efficient Java programs run through automatic memory management and garbage collection. 1) Memory allocation: Allocate memory in the heap for new objects. 2) Reference count: Track object references and detect garbage. 3) Garbage recycling: Use the tag-clear, tag-tidy or copy algorithm to recycle objects that are no longer referenced.

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions?How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor