Code

JVM: What it is and how it differs from .NET — a Java programmer explains

JVM: What it is and how it differs from .NET — a Java programmer explains

Learn: Java Developer Profession

Learn More

Ivan Uglyansky is a well-known figure in his field, possessing extensive experience and knowledge. His professional activity covers many aspects, including expertise in specific areas, which makes him a valuable specialist. Uglyansky actively shares his knowledge and practical experience, which helps others develop and achieve success. His work and achievements serve as an inspiration for many striving for professional growth. Ivan Uglyansky continues to contribute to his field, remaining a relevant and sought-after expert.

This expert possesses deep knowledge and experience, enabling him to effectively solve problems and deliver high-quality solutions. His professional activities span multiple aspects, including analysis, strategic planning, and the implementation of innovative approaches. He constantly monitors the latest trends and new technologies, allowing him to remain at the forefront of his profession. Thanks to his high level of competence and determination, he is able to offer his clients optimal paths to success and increased efficiency.

He is a JVM engineer with experience at Excelsior@Huawei, specializing in the development of Java virtual machines, compilers, and new programming languages. He is a founding member and active leader of the Java User Group Nsk (JUGNsk), and a member of the SnowOne conference program committee.

Links play a key role in the structure of web content and SEO. They provide site navigation, help users find the information they need, and improve the indexing of pages by search engines. Internal links connect different pages on your site, helping distribute page weight and improve their visibility in search results. External links pointing to authoritative resources can increase the trustworthiness of your content and improve its ranking. Link optimization includes using keywords in anchor text, creating clear URLs, and regularly monitoring for broken links. Proper use of links not only improves the user experience but also helps your site rank better in search results.

I've been developing on the JVM for over 10 years. My career began at Excelsior, a Novosibirsk company, where I worked on developing my own implementation of the Java Virtual Machine, Excelsior JET. Our team subsequently joined Huawei, but the composition remained unchanged. We continue to develop and improve Java and JVM technologies, providing high-performance and reliable solutions for our customers.

What is the JVM and how it saved programmers from professional "burnout"

About 25 years ago, before the advent of Java, many applications were developed in C and C++. However, these languages ​​have a significant drawback: developers need to consider which operating system and processor architecture their code will run on. For example, a program written for Linux will most likely not work on Windows or MacOS. This forced programmers to use conditional compilation directives or create separate versions of programs for each operating system. Java, unlike C and C++, offers platform independence, which significantly simplifies development and increases application compatibility on various devices.

The greatest difficulties arose when working with applications using a graphical user interface (GUI). The code for graphics components varied significantly across different operating systems. This is due to the low-level nature of C and C++, requiring developers to consider the processor architecture and operating system specifics. As a result, cross-platform support is out of the question in this context.

In the 1960s, engineers conceived of the concept of creating programs that weren't tied to specific hardware but were designed for an abstract "executor." Java programs are designed for precisely this purpose—they are developed for a virtual machine known as the Java Virtual Machine (JVM). Java developers don't have to worry about the platform their code will run on, as the JVM accepts and interprets the bytecode without realizing it's executing Java instructions. This ensures a high degree of application compatibility and portability, making Java a popular choice for software development across a variety of fields.

Java's unique selling proposition was that developers could create Windows programs that ran on macOS with minimal modifications. This seemed like a miracle 25 years ago, but today it's accepted as a natural process. Java provided cross-platform support, which significantly simplified development and expanded the software audience.

Still: documentary series "Ancient Aliens"

Java's cross-platform support is ensured by a clear separation between the language levels and its implementation. This allows developers to create applications that can run on various operating systems without having to modify the source code. Thanks to this architecture, Java has become a popular choice for creating multi-functional and versatile software solutions that can function effectively in different environments.

Language level. Developers write code in the Java language, whose syntax and semantics are described in detail in the Java Language Specification. After writing the source code, it is compiled into Java bytecode using a special tool called javac. During the compilation process, syntax is checked. If syntax errors are detected, the developer receives an appropriate error message from javac.

Important aspects to pay attention to include keywords, meta tags, content structure, and its uniqueness. Optimizing text for SEO requires careful work with headings to ensure they are informative and contain the main keywords. You should also consider the length of the text - it should be long enough to cover the topic, but at the same time not lose readability.

Be sure to use internal and external links to increase the authority of the page and improve navigation. Images should have appropriate alt attributes, which improves SEO and makes the content accessible to people with disabilities. Don't forget about mobile optimization, as more and more users use mobile devices to access the Internet.

The key is to create high-quality content that is useful to users and answers their queries. Regularly updating information can also improve search engine rankings.

  • At this stage, there is nothing platform-specific; all Java code (like Java bytecode) is universal.
  • Java bytecode is a language intended for machines, not people. The average developer does not need to read it.

The implementation level of Java bytecode begins with its transfer to the Java Virtual Machine (JVM). The virtual machine is responsible for executing this bytecode, which is detailed in the Java Virtual Machine Specification. The JVM handles all aspects related to a specific operating system or processor architecture without touching the Java source code. This frees developers from the complexities associated with OS or hardware differences. They simply select the appropriate JVM version, for example, for Linux x64. All OS- and architecture-specific nuances are handled by the JVM development team, simplifying the process of developing Java software.

The Java programming language and the Java Virtual Machine (JVM) evolve concurrently, allowing them to support each other. New language features often require updates and improvements within the JVM. At the same time, different JVM implementations also evolve independently, introducing more efficient garbage collection algorithms and code optimizations. This interaction between the language and the virtual machine ensures the stability and performance of Java applications, allowing developers to use modern technologies and approaches in their projects.

The separation of the Java programming language and its implementation on the virtual machine is important for developers. It allows them to not be limited to just the Java language, since the virtual machine does not distinguish whether the bytecode came from Java or another language. Thus, developers can use any language that compiles to bytecode, which opens up a wide range of choices. There are many languages ​​that are supported, including Kotlin, Clojure, Groovy, and others. For example, Kotlin code is compiled using the kotlinc tool into class files, which are then executed on the Java Virtual Machine (JVM). This approach provides flexibility and extensibility in software development, allowing developers to choose the most appropriate language for solving specific problems.

In the 1960s, engineers put forward the concept of developing software that targets not specific hardware, but an abstract "executor." Java programs are written for just such a runner—a virtual machine known as the Java Virtual Machine (JVM). This allows Java developers to be confident in the platform on which their code will run. At the same time, the virtual machine has no idea that it is processing Java instructions, since it works with bytecode. This approach ensures a high degree of software portability and compatibility, which makes Java one of the most popular programming languages ​​in the world.

How the JDK and Open JDK are related

The Java Development Kit (JDK) is a set of tools designed for developing applications in the Java language. The JDK includes key components that enable the development, compilation, and execution of Java programs. The main elements of the JDK include the Java compiler, debugging tools, and the class libraries necessary for creating functional applications. Using the JDK is a mandatory step for developers looking to create efficient and productive Java applications.

  • Javac. This is the compiler that converts Java source code into class files or jar format.
  • JVM. The virtual machine that executes bytecode.
  • Standard Library. The set of modules, classes, objects, and functions that are available in the language.
  • Documentation. It contains reference information about the tools in a given JDK version.

When a new version of the programming language is released, all related components receive updates.

When using a standard JVM, such as HotSpot, the process of running a Java application begins with compiling the source code using javac. This step converts the code into class files or jar files, which can then be distributed and used as an application. Thus, the main step in developing Java applications is creating compilable code, which allows for efficient management and deployment of the software.

To successfully run the application, the host must have a Java virtual machine installed. The user must enter the command java -jar at the command line. The program will then run. Ensure that the host has the latest version of Java installed to avoid potential compatibility issues and ensure stable operation of the application.

Our virtual machine changed the application launch process. We precompiled class files into a single executable file, allowing the application to run on the user's computer without requiring a JVM. However, the JVM itself did not disappear; all its components were integrated into a single executable file. This solution simplifies the application's use, ensuring its operation in environments where Java is not installed.

The Java Virtual Machine (JVM) specification contains minimum implementation requirements, leaving developers considerable freedom in their approach. It describes the desired result, but does not specify how exactly to implement it. One of the key functions of the JVM is memory management, which is accomplished using the garbage collector mechanism. However, the specification does not disclose the details of how it works. This creates opportunities for different garbage collector implementations, which allows for performance optimization depending on specific conditions and tasks.

The Java Virtual Machine (JVM) specification was designed to enable the creation of different implementations that may differ in their characteristics, but still fully comply with the specification. This opens up opportunities for diversity and innovation in the world of virtual machines. Differences in JVM implementations create competitive advantages: some virtual machines boast more efficient garbage collection algorithms, others provide fast application startup, and some offer powerful optimizations at the compile level. Thus, the diversity of JVM implementations contributes to the development of technology and improved software performance.

The first Java Virtual Machine (JVM), like the Java programming language, was developed by Sun Microsystems. After the publication of the Java specification, Oracle began developing its own version of the JVM called JRockit, and IBM created OpenJ9. In 2000, our Excelsior JET virtual machine (VM) was launched, offering unique capabilities for Java developers.

Initially, all Java Virtual Machines (JVMs) were closed source. However, in 2006, Sun Microsystems open-sourced its HotSpot JVM, javac compiler, and Java standard library. This became the basis for the OpenJDK project, a completely open-source implementation of the Java Development Kit (JDK). Sun was later acquired by Oracle, but the OpenJDK project continued to exist and remains a key open-source platform for Java and JVM development. OpenJDK provides access to the latest updates and improvements, making it an essential tool for developers looking to leverage modern Java technologies.

OpenJDK is the reference implementation of Java, the benchmark for JDK developers. This project is licensed under the GPL 2 with Classpath Exception, allowing any company or developer with the necessary skills to create their own JVM implementations based on OpenJDK. It is important to note that, according to the license terms, such implementations will also be open source, which promotes development and innovation in the Java ecosystem.

There are JVM implementations that are not related to OpenJDK. Sun Microsystems and Oracle were not the only companies developing JVMs. An example is IBM's J9, which also opened the source code and is now called OpenJ9. This platform offers alternative solutions for running Java applications and gives developers the opportunity to use various tools and technologies. OpenJ9's open source nature fosters community growth and improves JVM performance for various use cases.

Some companies offer virtual machines for sale. For example, Azul provides a free build of Zulu and a commercial version of Azul Zing. Azul Zing includes the unique C4 garbage collector, which ensures minimal downtime, ahead of trends in this area. Azul Zing also implements ReadyNow! technology, which remembers all code optimizations and applies them at JVM startup, helping to achieve maximum performance. Excelsior JET was a commercial, closed-source solution that provided fast application startup times, low memory consumption, and high peak performance in various scenarios. These benefits were achieved through static compilation, as opposed to dynamic compilation in HotSpot. Static compilation allowed for the creation of optimized executables, which is especially important for applications requiring high efficiency and performance. Today, many users prefer free builds based on OpenJDK. There are both standard OpenJDK builds from Oracle and alternative versions developed by other companies and developers associated with OpenJDK. Often, these builds are published by contributors outside of Oracle. This diversity allows developers to choose the most suitable solutions for their projects, taking into account performance and compatibility requirements. Alternative builds may include additional features not found in standard Oracle versions. Some of these builds may undergo additional certification, for example, for integration with CryptoPro. All third-party builds undergo standard tests, ensuring the stable operation of your programs. Using these builds is completely safe and free, making them an attractive choice for developers and users. Some companies not only publish their builds but also offer paid support to users. For example, if you experience a problem with a virtual machine and your application starts running slowly or even throws errors, this may be due to bugs in the JVM. In such cases, the company's engineers are ready to quickly resolve the issue and offer a solution. This allows users to minimize downtime and improve application performance, while providing reliable technical support to keep things running efficiently.

There are many options for virtual machines and their builds, and it is impossible to cover them all in this article. Major companies such as Oracle, Red Hat, Azul, IBM, BellSoft, Amazon, and Microsoft offer their own builds of virtual machines. The Java expert community has prepared a useful document that examines the various options in detail and explains the situation with the diversity of JVMs and their builds. This document is called "Java Is Still Free" and is highly recommended reading for anyone interested.

How and Why Other Languages ​​Are Moving to the JVM

Java is not only a programming language, but also an entire development philosophy. This philosophy has proven so attractive that other programming languages ​​have begun to adapt to run on the JVM platform. A prime example of this is Jython and JRuby, which allow developers to leverage the power of Java with the syntax and features of other languages. This expands the functionality and capabilities of programming, making Java one of the most versatile platforms in the development world.

The primary reason for developing such solutions is to improve performance. Over the past 25 years, highly efficient Java Virtual Machines (JVMs) have been created. Using these advances, the performance of applications written in Python and Ruby can be significantly improved. Optimizing code execution in these programming languages ​​opens up new opportunities for creating faster and more efficient software solutions.

Using the Java Virtual Machine (JVM) ensures reliable interaction with the Java ecosystem. Running code on the JVM provides better integration with other modules running in this environment. This opens up opportunities to use various Java libraries, which significantly expands functionality and simplifies application development. Thus, developers can effectively take advantage of the advantages offered by the Java ecosystem to create high-performance and scalable solutions.

Kotlin has its own unique history. When it was created, the decision was made to compile the language to Java bytecode and run it on the Java Virtual Machine (JVM). This meant that the main task was to develop a high-quality translator, known as kotlinc, which converts .kt source code into class files. Low-level components, such as garbage collectors and operating system interaction, were delegated to the existing JVM environment, which significantly simplified the language implementation and allowed the focus to be on its high-level features.

Kotlin's creators recently introduced Kotlin Native, a technology that allows Kotlin code to be compiled to native code without using a JVM. This technology includes its own low-level components, such as a memory manager, which provides more efficient resource management. Kotlin Native opens up new possibilities for developers, allowing them to create applications that run on multiple platforms, including iOS and Android, without having to adapt the code for each. Using Kotlin Native simplifies cross-platform application development and improves performance through direct interaction with system APIs.

While porting any programming language to the Java Virtual Machine (JVM) seems straightforward at first glance, it is much more complex in practice. Creating a translator that converts code into class files requires a deep understanding of the language and its functionality. It is important not only to correctly reflect the language features in Java bytecode but also to ensure high performance, which is a significant challenge. JRuby is an example that illustrates the challenges of implementing this approach.

Charles Nutter regularly shares his experience supporting various Ruby features in the JRuby project, discussing the challenges that arise. As the differences between the original Ruby language and the Java platform increase, the translation process becomes increasingly complex. However, as practice shows, everything is possible, and JRuby is a clear confirmation of this idea.

What competitors does the JVM have?

The .NET platform is one of the most well-known competitors to the Java Virtual Machine, offering a virtual machine for executing C# programs. It provides high performance and cross-platform support, making it an attractive choice for developers. Comparing the capabilities of the Java Virtual Machine and the .NET platform helps highlight the advantages and disadvantages of each technology, which can be useful for choosing the optimal solution for software development.

In the early 2000s, Microsoft developed its Java Virtual Machine, known as Microsoft J++. However, the company did not comply with the language specifications, which led to a lawsuit from Sun Microsystems. As a result, Microsoft lost all lawsuits and lost the right to create a virtual machine for Java. This event is considered one of the reasons for the emergence of the C# programming language, which was developed as an alternative to Java and has become an important tool in the Microsoft ecosystem.

Java and C# are designed to solve similar problems and share a number of common advantages. Both languages ​​offer strong typing, automatic garbage collection, and high security, which makes them attractive to developers. These managed languages ​​are widely used in various areas of programming, providing reliability and efficiency in software development.

Previously, there was a significant difference between the platforms: Java provided cross-platform support, while .NET and C# functioned exclusively on Windows. However, with the advent of .NET Core, C# acquired the ability to run on various operating systems, making it multiplatform. This transformation opened new horizons for developers, allowing C# to be used to create applications on Windows, Linux, and macOS, significantly expanding the audience and possibilities of using the language.

Java and C# are two popular programming languages, each with its own features and advantages. However, C# is developing more dynamically, offering developers new features and capabilities that sometimes appear in Java significantly late or are absent altogether. As a result, C# appears to be a more attractive option for modern development. This makes it the choice for many projects, especially those that require innovative solutions and modern programming approaches.

Java has a powerful implementation and highly optimized virtual machines. This is the result of long-standing competition between virtual machine developers, which has been going on for over 20 years. Vendors constantly compete to create better optimizations, more efficient garbage collection algorithms, and faster application startup. As a result of many of these improvements, the Java implementation surpasses C# in a number of respects. Some features that have been present in the JVM for a long time are just beginning to be implemented in the .NET platform.

There are other programming languages ​​that can compete with Java, but they are significantly different in nature. For example, Python, which recently took first place in the TIOBE ranking, is actively used in areas such as data science, artificial intelligence, machine learning, and task automation. However, it's worth noting that Python's dynamic typing can create difficulties when managing large codebases, limiting its use in large-scale projects.

JavaScript remains one of the most popular programming languages, but its relationship with Java is not as significant, as Java is not currently used in front-end development. In the past, there were plans to use Java in this area, for example, through legacy Java applet technologies, but they did not find widespread adoption. JavaScript, in turn, has become the main tool for creating interactive web applications, which makes it indispensable in modern web development.

Where Java is good and where it is not

Java is actively used in back-end development, serving a variety of server-side applications. Java's main competitor is C#, but Java maintains a significant advantage due to its cross-platform nature. Although this statement is becoming less relevant, as C# is also evolving in this direction. It is important to note that Java has a temporal priority, as it was released ten years before C#. This has allowed it to gain the trust of developers and form extensive code bases.

Java is preferable to the "Swiss knife" C++ because it offers greater convenience and security. This means that developers can avoid common pitfalls, such as improper memory management and segmentation faults, which can arise unexpectedly. For everyday server-side tasks, the development speed in Java and C# significantly exceeds that of C++. Java allows you to focus on problem solving rather than technical details, making it an ideal choice for many projects in modern programming.

Java is not an optimal choice for applications that require high performance and strictly fixed response times. However, some developers use Java to create such programs if they are willing to accept small delays measured in microseconds. In such cases, the advantages associated with development speed and reliability may outweigh the disadvantages. However, using Java for developing software for pacemakers, where accuracy and stability are critical, is not recommended.

Still: the film "Spider-Man 2"

Trading applications are increasingly being developed in Java. In trading, fast response is especially important to avoid losses due to sharp fluctuations in stock prices, for example, Tesla. However, in practice, reliability turns out to be more important than speed. It is better to have a slow but stable trading platform than to create a high-speed application in C++ that may freeze after a few minutes of operation. Java provides a high level of security, which makes it an attractive choice for developing trading applications.

What's wrong with the JVM

As any programming language, including Java, evolves, controversial issues and questionable decisions arise. This applies both to the specifications of the language itself and to the operation of the Java Virtual Machine (JVM). Analyzing such subtleties can help developers better understand the limitations and capabilities of Java, which in turn leads to the creation of more efficient and optimized code. Understanding these aspects also helps avoid common mistakes and improve the quality of software.

One of the hot topics in the Java world is Project Jigsaw and the implementation of the module system, introduced in the ninth version of the language. The creators of Java worked long and hard to develop a system that allows Java programs to be divided into separate logical components called modules. This creates a new level of abstraction that complements the existing packages in Java. The module system simplifies dependency management and improves code organization, which contributes to more efficient development and maintenance of Java applications. The module system also provides greater security by allowing access to internal components to be restricted and improving encapsulation. The introduction of Project Jigsaw was an important step in the evolution of Java, opening up new opportunities for developers.

A significant amount of time was spent on its development, as it was necessary to provide support at the level of the language, the virtual machine, and other JDK components. For a long time, the system was not included in the release version, and when it was finally released, it turned out to be not so popular among users.

The process of introducing new features and specifications to the Java language is carried out through the Java Community Process (JCP). This special council analyzes proposals, known as Java Specification Requests (JSRs), and makes decisions by voting. The JCP represents the interests of various stakeholders in the Java community: large companies, user group representatives, and individual developers. Thus, the process of developing and improving the Java language ensures that the views of all stakeholders are taken into account, which promotes its evolution and adaptation to modern requirements.

The idea of ​​introducing a new module system into Java was rejected by the JCP several times, which is a rare occurrence. However, after significant revisions and softening, this system was finally integrated into the language. Nevertheless, several years after its introduction, it can be noted that most Java developers are not happy with the new module system, and the use of modules remains rare.

Generics in Java, unlike many other programming languages, are erased. This means that type parameters are converted to Object during compilation, and at runtime it is impossible to determine which type was passed. This approach has its advantages and disadvantages, and the debate about which generics are better – erased or non-erased – continues to this day. However, the choice of erased generics in Java is driven by several factors. A more detailed explanation of the choice and features of generics in Java can be found in Brian Goetz's article "Background: How We Got the Generics We Have," which covers the historical aspects and technical details of the implementation of generics in the language.

Despite the various opinions about the implementation of generics in Java, there is an important problem: primitive types cannot be used as type parameters, as they are incompatible with the Object object. This limits the expressiveness of the language and forces developers to resort to using wrapped types, which can negatively impact performance. In contrast, some functions must be manually specialized for primitive types. To address this problem, Project Valhalla plans to implement specialized generics, which will significantly improve work with primitives and increase code efficiency.

Backward compatibility is a key tenet of the Java language, which the JCP board does not intend to violate even for the sake of implementing the most modern features. While there may be changes in some cases, legacy code must continue to function without interruption. This important requirement allows developers to confidently update their applications, knowing that existing functionality will remain functional. Backward compatibility ensures software reliability and stability, making Java a popular choice for development in a variety of fields.

In legacy bytecode, you might find exceptions implemented through the JSR and RET instructions, but in the new bytecode, these instructions are absent. However, all tools must support legacy bytecode, as it is still relevant for libraries developed 20 years ago. These libraries continue to be used in modern projects in the .jar format, highlighting the importance of compatibility with legacy standards.

This principle ensures the creation of a stable ecosystem, allowing businesses to avoid the fear of a new version breaking the existing infrastructure and blocking upgrades. However, such stability can hinder innovation. Java may evolve more slowly than C# due to strict backward compatibility, which is viewed as something immutable and unacceptable for change. This creates certain limitations and hinders the rapid adoption of new technologies and features, which can negatively impact the platform's competitiveness.

In the Java programming language, new features and specifications emerge through the Java Community Process (JCP). This process involves reviewing proposals, known as Java Specification Requests (JSRs), which are then voted on. Representatives from large companies, user group members, and individual experts participate in the JCP, ensuring a diversity of opinions and interests within the Java community. Thus, new features and improvements are developed with the needs of various participants in mind, which promotes the evolution of the language and its adaptation to the needs of modern developers.

How much knowledge of the JVM does a developer need?

This question is a matter of great debate. The answer largely depends on the goals of the Java developer.

About 30% of programmers can successfully complete their tasks without delving into the internal mechanisms of the virtual machine. For 50% of developers, a basic understanding of the Java Virtual Machine (JVM) is sufficient to reach the mid- to senior-level positions. While their primary task isn't to delve into the intricacies of the virtual machine, understanding its structure allows them to write more efficient code and prevent errors. However, 20% of tasks require a deep understanding of the JVM's workings. Thus, the better you understand the virtual machine, the wider the range of tasks that you can successfully solve.

Frame: the animated series "Futurama"

If performance is critical in the project, and improve it with If it's impossible to use a more efficient algorithm, it's necessary to pay attention to the garbage collector. It's important to understand how it functions and how to improve its efficiency. You should consider the available settings that can be changed to optimize the garbage collector. It's also worth understanding the concept of deoptimization: what it is, the reasons for its occurrence, and ways to minimize its impact on project performance.

A Java developer who systematically delves into their field has the opportunity to become a Performance Engineer. These professionals identify performance issues and analyze the internal processes of the Java Virtual Machine (JVM). Instead of making changes to the virtual machine code, they tune it like watchmakers, ensuring optimal application performance. Becoming a Performance Engineer requires a deep understanding of the JVM, as well as skills in performance analysis and optimization, which can significantly improve the efficiency of Java applications.

For managed language developers, it's important to understand what happens "under the hood" when running programs in integrated development environments. While it's not necessary to memorize every detail of the JVM, a basic understanding of concepts such as the interpreter, the Just-In-Time Compiler, and the object lifecycle, including the concept of "dead object," is helpful. This knowledge helps develop a deeper understanding of application performance and optimization, as well as improves debugging and problem-solving skills. Understanding these aspects allows developers to write more efficient and optimized code.

A developer without knowledge of certain key aspects can successfully complete many tasks. However, sooner or later, they will encounter errors whose causes are unclear. For example, without considering how memory works and how it is returned to the operating system, you might receive an "Out of Memory" error message from the IDE. This occurs because the program is consuming excessive memory. A developer who understands the principles of memory management will strive to optimize their code and minimize the creation of unnecessary objects. Knowing these fundamentals helps you avoid problems, improves your productivity, and leads to better software.

A Java developer who continually delves into their profession may eventually become a Performance Engineer. These experts identify and fix performance issues by analyzing the internal workings of the Java Virtual Machine (JVM). Instead of simply adding code, they focus on fine-tuning the virtual machine, like watchmakers, to optimize application performance and improve overall system efficiency. Developing in this direction requires a developer with deep knowledge of how the JVM works and an understanding of various optimization techniques.

Where the JVM is heading

Currently, three projects are actively being developed that will certainly be included in future versions of Java. These projects are significant for the further development of the language and its ecosystem, providing performance improvements, new features, and opportunities for developers. Their integration into Java is expected to increase development efficiency and simplify working with modern technologies.

Loom is a project that adds support for virtual threads to the Java programming language. Unlike traditional threads, which directly correspond to operating system threads, virtual threads operate independently. They are activated only when needed, allowing for efficient resource utilization and improved application performance. Virtual threads in Java provide easier and more flexible handling of parallel tasks, simplifying the development of multithreaded programs.

Previously, each instance of the java.lang.Thread class in Java corresponded to a separate operating system thread, enabling multithreading. This solution, although logical, has its limitations: the number of operating system threads is limited, and creating several thousand threads this way becomes difficult. Project Loom offers an innovative solution—virtual threads, which do not have a strict 1:1 correspondence with operating system threads. Instead, virtual threads use OS threads as needed to execute their tasks, significantly increasing the efficiency of multithreading. These changes allow developers to create more scalable and performant applications by optimizing resource usage and simplifying thread management.

The idea of ​​virtual threads is not new. For example, the Go language has implemented this concept from the very beginning. The issue of virtual threads has been discussed for many decades. In the 1990s, Java also had green threads - a concept in which several "green" threads were processed within a single operating system thread. At that time, when processors had only one core, the problem of lightweight multithreading was not so pressing. It can be argued that the Loom project is a kind of reincarnation of green threads, but implemented at a higher level. This new implementation allows developers to create more efficient and scalable applications while providing simple thread management.

This project is highly significant in the context of the modern world of microservices and servers that handle a huge number of concurrent connections. When creating tens or hundreds of thousands of threads, legacy implementation methods using operating system threads become inefficient. However, with Loom, this task becomes entirely achievable. Loom offers an innovative approach to thread management, allowing developers to efficiently create and manage large numbers of lightweight threads, significantly improving application performance and scalability.

Panama is a project aimed at simplifying the interaction between Java and native code, such as C or C++. Although Java has had the ability to interact with native code from the very beginning, the primary tool for this has remained the Java Native Interface (JNI). Despite its power, JNI is often slow and cumbersome to use. Developing with it requires writing complex, cumbersome, and unsafe code. Many Java developers with experience working with JNI can attest to the difficulty and frustration this process causes, leaving a negative impression of working with native code. Project Panama aims to address these issues by providing more efficient and secure ways to interact, making it a significant step in the evolution of Java.

The authors of Project Panama have been working for several years on a solution that could significantly improve the lives of Java developers. Like the Panama Canal, Panama connects two worlds: native and Java. This project offers a new interface and an optimized JVM implementation, allowing for safe and efficient interaction with native code, including off-heap work. With Panama, developers can integrate native libraries into their Java applications, opening up new horizons for performance and functionality.

Project Valhalla aims to introduce new object types to Java, known as value types, inline types, or primitive value types. This name, like the project concept itself, continues to evolve. Valhalla is a complex initiative whose goal is to extend the capabilities of the Java language, improve performance, and simplify working with data. The introduction of value types will allow developers to create more efficient and lightweight data structures, which will significantly improve application performance.

The idea is to define a subclass of objects that lack identity. What does this mean? In Java, you can create two identical objects using the new operator and compare them using the == operator, which will result in false. This happens because they are different objects that are compared not by their contents, but by a unique property assigned to each object at the time of its creation. The ability to compare by some other criterion than their contents is what we call identity.

On the other hand, you can create two variables of type int and assign them the value 42. When compared using the == operator, the result will be true. This happens because the int type lacks identity; Variables of this type are compared solely by value.

The goal of Valhalla is to enable users to create their own identity-free classes, and to prepare the existing type system for this process. This will allow, for example, the embedding of flat fields of such types in other classes, which effectively means the ability to inline their fields inside other objects. In addition, users will be able to work with flat arrays of such objects and obtain specialized generics, which will significantly expand the functionality of programming and code optimization.

This is a significant and fundamental change in the Java ecosystem that is attracting attention and deserves anticipation, as it will open up new opportunities for developers. The innovations promise improved functionality and performance, which will enable the creation of more efficient and modern applications on the Java platform.

Previously, each instance of the java.lang.Thread class in Java corresponded to one operating system thread, which enabled multithreading. However, this model has its limitations: the number of operating system threads is limited, and creating more than several thousand threads becomes difficult. Project Loom offers a solution in the form of virtual threads, which are not tied to a strict 1:1 relationship with operating system threads. Instead, virtual threads use system threads as needed, allowing for more efficient resource management and increasing the performance of multithreaded applications. This innovation significantly simplifies development and improves the scalability of applications running a large number of parallel tasks.

What languages ​​are JVMs and libraries for Java developed in?

Java virtual machines are typically developed using C++, while their standard library is primarily written in Java itself. However, sometimes there is a need to use native code, which also means turning to C++. Traditionally, systems programming is done in C++, as this language provides the necessary performance and the ability to interact with low-level components such as operating systems and hardware. However, it is becoming clear that not all elements of the virtual machine require writing in C++. For example, using managed languages ​​such as Java or Scala allows for more efficient and convenient compiler development without resorting to C++. This opens up new opportunities for optimization and simplification of development. Oracle Labs is developing the GraalVM project, which includes three main components. GraalVM is a general-purpose virtual machine that provides support for various programming languages ​​and high performance for multithreaded applications. The first component is Graal, a compiler that optimizes code execution and significantly accelerates its execution. The second component is Truffle, a framework for creating language interpreters that provides easy integration with Graal. The third component is Substrate VM, a technology for creating native images, allowing applications to run without the need for a full-fledged virtual machine. Together, these components make GraalVM a powerful tool for developers looking to improve the efficiency and performance of their applications.

  • The Graal Compiler is a powerful optimizing compiler; in the future, it may replace the C2 compiler from HotSpot. It is as good as many optimizations, but is written entirely in Java.
  • The Truffle Framework is a special framework for writing interpreters for other languages, which then run on GraalVM. Essentially, this is a fast way to implement any programming language on top of GraalVM! Again, interpreters are written in managed languages.
  • Graal Native Image is a separate application build mode that is actually an entire virtual machine, but written with some specification violations. However, it allows for fast startup and low memory consumption. The runtime for this virtual machine is also partially written in Java! Of course, not completely and with different language limitations (in fact, a separate dialect is used there - System Java), but nevertheless, it is possible.

Creating virtual machines in managed languages ​​​​is a long-standing goal of many systems developers. For example, the well-known C compiler is written in C. Likewise, developers of virtual machines for managed languages ​​​​aim to use Java or other managed languages ​​​​while avoiding the complexities and risks associated with using C++. This opens up new opportunities for improving security, reducing errors, and simplifying the virtual machine development process. Using managed languages ​​​​can significantly improve the performance and reliability of systems, which makes this area especially relevant for modern IT professionals.

How to contribute to OpenJDK

I have never contributed to OpenJDK and worked on a different, closed and proprietary JVM. Therefore, I only have a general understanding of the OpenJDK commit process. Please take the following with caution.

If I were to contribute to OpenJDK, I would focus on two main areas: performance improvements and feature expansion. Performance improvements involve optimizing existing algorithms and memory management mechanisms, which can significantly improve the efficiency of Java applications. Feature expansion involves adding new functions and libraries that can ease development and improve the user experience. Such initiatives not only contribute to the development of OpenJDK, but also help the developer community find new solutions to pressing problems.

  • Find something small that can be fixed or improved. This could be a simple (and low-priority) bug in the OpenJDK issue tracker or an inefficiency in an algorithm in the platform classes. Fix this issue, build OpenJDK, and check that, for example, the algorithm actually works better on some benchmarks.

After making improvements, send a message to the mailing list outlining the changes and asking for a review. Then go through the review process and complete the remaining commit steps. The commit procedure is fairly standard, since OpenJDK is now hosted on GitHub. Congratulations, you are now an OpenJDK contributor!

According to reviews from people who have already gone through this process, the entire process can take a significant amount of time, especially the first time. However, it is quite doable and realistic for most people.

  • Get a job at a contributor company. In this case, you will develop code that will end up in OpenJDK during work hours. However, the difficulty is that such companies are still very few. However, getting into one of them is really cool. A striking example of such a company is St. Petersburg's BellSoft, which last year took fourth place in the world (!) among external (not from Oracle) contributors to OpenJDK.

Java developer profession

You will learn to program in Java from scratch and create Web applications using the Spring framework. In six months, you'll gain fundamental skills and build a portfolio, and we'll help you find a job.

Find out more