Wednesday, February 22, 2023

Embedded Java: Then and now


Oracle Java SE 8 Embedded is the final major release of the Oracle Java SE Embedded product. Starting with JDK 9, Oracle doesn’t plan to offer a separate Java SE Embedded product download.

Embedded Java, Oracle Java, Java Career, Java Prep, Java Tutorial and Materials, Java Certifications, Java JDK

Mainstream Java is heading towards version 20, so what’s going on with Java in the embedded space?

First, here’s some history. Java (then called Oak) was initially developed by engineers at Sun Microsystems more than 30 years ago. Originally, Oak was developed to provide an object-oriented programming and runtime environment for embedded systems—independent of the underlying hardware and operating system.

The idea was to create a uniform and portable programming platform with automatic memory management and robust execution of code in a virtual environment. By using a virtual machine (VM), programmers would automatically avoid otherwise common problems such as crashes caused by buffer overflows and faulty pointer arithmetic.

Object-oriented programming for embedded systems was a relatively new idea in the 1990s, and the embedded community was skeptical. The Java programming language was designed to be interpreted during runtime and as such, it was initially intrinsically slow and resource hungry. And even though the first Java release had only eight packages and about 200 classes, it was considered too “heavy” by many hardcore C/C++ and assembly language programmers.

Given the limited processing power and very limited memory availability back then, it was understandable that the advantages of object-oriented programming, portability, and secure execution did convince many software engineers.

Set-top box manufacturers were among the earliest adopters of Java in the embedded space even before the Java plugin for web browsers opened the door for an entirely new programming model on the desktop.

Applets—which were small, and usually visual, programs written in Java—could be downloaded into a browser and create an interactive user experience that was previously hard to accomplish with HTML and early scripting languages.

Because the Java code was executed in a VM invoked by the browser, applet authors didn’t have to care much about the variety of target operating systems and underlying CPU architectures. Java grew bigger and stronger and conquered the desktop world. Even back then, PCs had serious computing power and memory, and some technology advances such as just-in-time (JIT) compilers helped increase the acceptance of Java as a mainstream programming language for client applications.

Enter J2ME


Even decades ago, programmers and project managers realized the advantages of object-oriented programming and the benefits of the fast-growing class libraries and functionality included in the Java language. But most embedded systems still weren’t strong and big enough to host a full desktop Java runtime environment (JRE). The Java stakeholders (Sun Microsystems, IBM, Nokia, RIM, Philips, Siemens, Motorola, and others) organized in the Java Community Process approved a Java Specification Request, JSR 68, to specify a Java variant specifically designed for embedded use: Java 2 Micro Edition, also known as J2ME.

Subsetted class libraries and small-footprint JVMs opened the door for widespread use of Java in embedded systems. In particular, mobile phones made use of Java with the Mobile Information Device Profile (MIDP) profile, a configuration targeted to handheld phones with elementary graphics capabilities from the Limited Connected Device User Interface (LCDUI).

In 2001 MicroDoc (the company we work for) was one of the first companies in Europe to begin working on embedded Java. Initial work was done on the infamous PowerPC Red Box with UNIX, followed by a JVM port to Sun’s ChorusOS microkernel operating system for credit card payment terminals. Many of those terminals are still in operation today with their original VM infrastructure.

More and more embedded systems were integrated into communication networks, and implementing complex networking protocols in C or even assembly language turned out to be complicated and error prone. Java offered an integrated network stack and an automatic software distribution mechanism locally and over the network. And embedded JVMs became available for many operating systems and CPU architectures such as SH-4, PowerPC, ARM, MIPS, and x86.

The adoption of Java in the embedded space was still limited by frequent complaints about poor runtime performance and high memory requirements. But new technologies such as tiered garbage collectors and ahead-of-time (AOT) compilation made the execution of Java code more predictable and faster than ever. And the advent of stronger 32-bit processors and affordable memory opened the way for many high-tech use cases such as automotive head units and Global System for Mobile Communications (GSM) network stations and controllers.

Java takes the lead


Java surpassed all other programming languages in popularity for the first time in 2001 when it became the most used programming language according to the TIOBE Index, and it stayed on top until 2019. During that period, embedded Java achieved widespread adoption in devices such as telematics units, Blu-ray players, internet routers, and integrated internet edge devices. MicroDoc ported a VM to Windows CE on AMD’s Geode chipset as part of AMD’s 50x15 initiative. The initiative was founded to accelerate access to the internet with very low-cost devices to enable educational and commercial applications online, even in less-developed countries.

That goal was eventually reached with the advent of feature phones and, of course, smartphones. Beyond that, MicroDoc had its first high-volume deployment in the auto industry in 2009. The company’s engineers cooperated closely with a well-known German tier-one supplier, and they created one of the first aftermarket onboard telematics devices for the trucking industry. The platform, based on 32-bit ARM/Linux, was designed to enable track-and-trace services and to enable third-party applications to be deployed.

What followed was a series of automotive engagements with tier-one suppliers and OEMs. MicroDoc provided an advanced runtime platform for automotive head units on a variety of hardware and software architectures. Starting with 32-bit SH-4 on Windows Automotive, the team ported and optimized VMs for Linux on PowerPC, ARM32, and ARM64, which enabled MicroDoc’s customers to deploy their Java-based applications on whatever hardware generation they chose to deploy.

As a kind of niche market supplier for customized Java VMs, MicroDoc was able to work with customers from a variety of industries, including network infrastructure companies, logistics companies, smart-home device manufacturers, and companies in the healthcare sector.

Besides porting JVMs to numerous target devices, MicroDoc also added valuable reusable components to the standard class libraries. These include Java stacks for the use of many variants of OpenGL, libraries for the open standard communication protocol MQTT, device management protocols, and hardened stacks for the Transport Layer Security (TLS) protocol.

Modern embedded Java


As a typed language, Java is still among the most popular languages today, and embedded applications benefit from the integrated security measures in current Java systems. But it looked like the idea of a truly embedded Java came to an end with Java 8.

To maintain the integrity of the Java language and still allow for customizing Java runtimes for embedded systems, Oracle released Oracle Java SE Embedded, which defined three so-called compact profiles that were strict subsets of the desktop class libraries.

This move was needed since Java 8 had become fairly large and contained many features rarely used in embedded systems. The smallest compact profile class libraries have a footprint of less than 14 Mb compared to the desktop version libraries, which go above 50 MB.

A configurable JIT compiler and a choice of garbage collectors complemented the embedded version and made it a suitable embedded platform for many industries; for example, some of the world’s largest automakers rely on Java 8 technology for their infotainment and telematics systems.

Because the current release of the platform is Java 19, and Java 20 will be released in March 2023, it is fair to ask why there isn’t a more recent Java embedded version. There are several reasons.

The embedded systems market is very complex. There are hundreds, if not thousands, of different CPU variants and operating system dialects on the potential target devices, and it is extremely expensive to maintain a complex codebase such as a VM on so many platforms. The few profitable high-volume embedded applications, such as smartphones, have turned to open source offerings or focus on different languages.

Therefore, it is hard to justify big investments in many VM platforms. Oracle has reduced the number of embedded platforms it supports. What remains is a few smaller software vendors (such as MicroDoc) who specialize in the customization and optimization of JVMs for niche markets.

Java has a new module system. Java 9 introduced a new module system (known as Project Jigsaw). Java’s monolithic class library was rearchitected to allow separation into functional components that can be added, as needed, for a runtime system. Unused components can be left out—thus, the footprint is reduced. Whether this technology lives up to its promises remains to be decided by embedded systems engineers. Some claim that the unbundling was not done thoroughly enough and the essential core modules needed for every application are still too big.

Some people complain about performance issues, in particular startup time. When you launch a VM, you load a big piece of software and classes before any user code can be executed. And then the JIT compiler monitors the application and decides when to interrupt the execution of frequently used methods to compile them into machine code. That helps at runtime later, but it also increases the system’s total startup time.

Help comes from the cloud


Cloud computing has become a mainstream business in recent years. Giant server farms host applications for millions of users. Many services offered in the cloud are based on microservice architectures. Microservices are small functional entities that are invoked and immediately suspended after use. The requirements for cloud computing are fairly in line with what’s needed in the embedded space: a small footprint and fast startup.

Even though today’s servers have abundant horsepower and virtually unlimited memory, when millions of users are served at a time, the resources need to be shared among all users, and the fraction available for a single user can become fairly small. Also, users don’t want to wait for many services to start up; they want an immediate response.

Oracle is one of the major cloud providers and has launched a game-changing project to solve these problems: GraalVM.

GraalVM is a portable VM that can be used to execute a variety of programming languages: Java and also Python, R, Ruby, and JavaScript. And GraalVM offers a unique technology called GraalVM Native Image that can be used to compile Java applications directly into a standalone executable file, called a native image, for a target platform.

Using a native image is different from having a JVM execute AOT code. A native image contains only the ready-to-run machine code of the application and a lightweight memory manager for garbage collection. Most of the other heavyweight JVM components are stripped: No interpreter, no JIT compiler, and no class libraries are part of the native image. This leads to a superslim footprint and blindingly fast startup times.

Does that sound like an embedded platform? It does.

GraalVM Native Image is well suited for bringing new and existing Java applications to embedded devices. It offers the full universe of Java advantages and at the same time saves memory and CPU cycles.

Oracle is focusing on server-based cloud computing with GraalVM, but there is a growing community working on implementations for embedded use. MicroDoc has entered into a contract with Oracle to bring a commercial license offering for GraalVM to the embedded market.

MicroDoc has already implemented a cross-compiler for GraalVM Native Image compilation that can create executables for previously unsupported platforms that are commonly used in the embedded space (such as 32-bit Linux running on ARM). With 30 years of experience in the field of embedded VMs, MicroDoc can bring GraalVM-based solutions to legacy systems and future architectures as well.

In other words, the story of embedded Java is not over. In fact, it has only just begun.

Source: oracle.com

Related Posts

0 comments:

Post a Comment