Project Valhalla (Java language)

Last updated

Project Valhalla is an experimental OpenJDK project to develop major new language features for Java 10 and beyond. The project was announced in July 2014 and is an experimental effort by Oracle, led by engineer Brian Goetz. [1]

Contents

Planned features

Valhalla is incubating Java language features and enhancements in these areas: [2]

These features will require both syntax and VM-level changes.

Project activity

The project is organized on the OpenJDK 'Project Valhalla' mailing list. Project Valhalla has begun in the experimental stages, with an inaugural announcement & early draft initial proposals.

Published as of January 2022:

Experimental OpenJDK prototypes can also be built from the Mercurial repositories. These are starting to incorporate many specialization features. Note that these are Gnu Make/ C++ sources, and building the OpenJDK requires technical expertise. See OpenJDK build instructions for details.

Project Components

The project is organized into several JEPs (JDK Enhancement Proposals):

Value Classes

Value classes are reference types, in the same way as all existing Java classes. However, they give up the ability to have identity. This means that the <nowiki>==</nowiki> operator compares instance of the value class by equality of their components, instead of by identity. Additionally, synchronizing on instances of value classes will fail.

Value classes still support null, since they are reference types. The Java Virtual Machine is expected to be able to take advantage of the additional constraints of value classes to eliminate heap allocation of value types in the vast majority of cases. However, storing instances of value classes into a field or upcasting them to an interface will still require an allocation.

Existing types in the Java API such as java.util.Optional are known as value-based classes, and are candidates for being made into value classes in a future JDK release.

Primitive Classes

Primitive Classes are subject to all the constraints of value classes, but are not reference types. This means they give up the ability to support null. Instead, their default values are the zero value for each of the component types (0 for numerical types, false for booleans, null for reference types, and the zero value for nested primitive classes.

All primitive classes are stored "inline", that is, without requiring a heap allocation. Arrays of primitive classes will not require a pointer indirection from the array to the heap. Where needed, conversions will be inserted to "box" the primitive class into a value class version of itself and vice versa.

Classes for the Basic Primitives

This JEP is meant to express the classical primitive types of the Java Virtual Machine (byte, char, short, int, long, boolean, float, double) as Primitive Classes.

Traditionally, the eight primitive types are treated separately from all other types. Providing primitive class declarations from them removes much of this special-casing, leading to a more elegant and easy to understand type system.

Technical benefits and implications

Memory access performance and the efficiency of 'boxed' value access are a major area to be addressed by these features. 'Value Type' features and 'Generic specialization' (when applied to lists or collections) reduce memory usage, but more importantly avoid pointer indirection which typically causes a cache miss. [3] [4]

Instead of a list or array of object references, pointing to data values scattered throughout memory, Project Valhalla enhancements will enable list or array values to potentially be laid out linearly—without indirection—as a consecutive block of memory.

Value Types are envisaged as "Codes like a class, works like an int!" [5] Synchronization and inheritance would be excluded for Value Types. These would no longer require object identity and associated memory/ pointer overheads, though would be able to assume a 'boxed' form for compatibility. [4]

See also

Related Research Articles

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, protocol stacks, though decreasingly for application software. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

<span class="mw-page-title-main">Java (programming language)</span> Object-oriented programming language

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need to recompile. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities that are typically not available in traditional compiled languages. As of 2019, Java was one of the most popular programming languages in use according to GitHub, particularly for client–server web applications, with a reported 9 million developers.

<span class="mw-page-title-main">Java virtual machine</span> Java Virtual machine

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

Java Platform, Standard Edition is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE).

Java and C++ are two prominent object-oriented programming languages. By many language popularity metrics, the two languages have dominated object-oriented and high-performance software development for much of the 21st century, and are often directly compared and contrasted. Java appeared about 10 years later and its syntax was based on C/C++.

<span class="mw-page-title-main">D (programming language)</span> Multi-paradigm system programming language

D, also known as dlang, is a multi-paradigm system programming language created by Walter Bright at Digital Mars and released in 2001. Andrei Alexandrescu joined the design and development effort in 2007. Though it originated as a re-engineering of C++, D is a profoundly different language —features of D can be considered streamlined and expanded-upon ideas from C++, however D also draws inspiration from other high-level programming languages, notably Java, Python, Ruby, C#, and Eiffel.

C dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely malloc, realloc, calloc, aligned_alloc and free.

<span class="mw-page-title-main">Pointer (computer programming)</span> Object which stores memory addresses in a computer program

In computer science, a pointer is an object in many programming languages that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory-mapped computer hardware. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number and reading the text found on that page. The actual format and content of a pointer variable is dependent on the underlying computer architecture.

This article compares two programming languages: C# with Java. While the focus of this article is mainly the languages and their features, such a comparison will necessarily also consider some features of platforms and libraries. For a more detailed comparison of the platforms, see Comparison of the Java and .NET platforms.

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

java.nio is a collection of Java programming language APIs that offer features for intensive I/O operations. It was introduced with the J2SE 1.4 release of Java by Sun Microsystems to complement an existing standard I/O. NIO was developed under the Java Community Process as JSR 51. An extension to NIO that offers a new file system API, called NIO.2, was released with Java SE 7 ("Dolphin").

In some programming languages, const is a type qualifier that indicates that the data is read-only. While this can be used to declare constants, const in the C family of languages differs from similar constructs in other languages in being part of the type, and thus has complicated behavior when combined with pointers, references, composite data types, and type-checking. In other languages, the data is not in a single memory location, but copied at compile time on each use. Languages which utilize it include C, C++, D, JavaScript, Julia, and Rust.

<span class="mw-page-title-main">C Sharp (programming language)</span> Multi-paradigm (object-oriented) programming language

C# is a general-purpose high-level programming language supporting multiple paradigms. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.

The Java programming language and Java software platform have been criticized for design choices including the implementation of generics, forced object-oriented programming, the handling of unsigned numbers, the implementation of floating-point arithmetic, and a history of security vulnerabilities in the primary Java VM implementation, HotSpot. Software written in Java, especially its early versions, has been criticized for its performance compared to software written in other programming languages. Developers have also remarked that differences in various Java implementations must be taken into account when writing complex Java programs that must work with all of them.

The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community Process (JCP), which uses Java Specification Requests (JSRs) to propose and specify additions and changes to the Java platform. The language is specified by the Java Language Specification (JLS); changes to the JLS are managed under JSR 901. In September 2017, Mark Reinhold, chief Architect of the Java Platform, proposed to change the release train to "one feature release every six months" rather than the then-current two-year schedule. This proposal took effect for all following versions, and is still the current release schedule.

Generics are a facility of generic programming that were added to the Java programming language in 2004 within version J2SE 5.0. They were designed to extend Java's type system to allow "a type or method to operate on objects of various types while providing compile-time type safety". The aspect compile-time type safety was not fully achieved, since it was shown in 2016 that it is not guaranteed in all cases.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

The JDK Enhancement Proposal is a process drafted by Oracle Corporation for collecting proposals for enhancements to the Java Development Kit and OpenJDK.

Whiley is an experimental programming language that combines features from the functional and imperative paradigms, and supports formal specification through function preconditions, postconditions and loop invariants. The language uses flow-sensitive typing also known as "flow typing."

References

  1. Goetz, Brian. "Welcome to Valhalla!". OpenJDK mail archive. OpenJDK. Retrieved 12 August 2014.
  2. Evans, Ben. "Oracle Launches Project Valhalla for Java". InfoQ. InfoWorld. Retrieved 12 August 2014.
  3. Krill, Paul. "Next generation Project Valhalla proposed; Value types, generic specialization, and enhanced volatiles top the wish-list for Project Valhalla". JavaWorld. InfoWorld. Retrieved 12 August 2014.
  4. 1 2 "Value Types & List<int> coming for Java 10 ?". LiterateJava.com. Retrieved 12 August 2014.
  5. Rose, John; Goetz, Brian; Steele, Guy. "State of the Values". OpenJDK. Retrieved 12 August 2014.