ArchitectureDiagram
Article contributed by GilbertHerschberger (3 April 2000).
The general architecture of a Java-based operating system requires machine code. What should be implemented in machine code? How much of an operating system should be written in C/C++? This article provides a introduction to these issues.
This diagram illustrates the standard libraries for a traditional operating system. Native interface and bytecode are optional.
Machine Code
|
This diagram illustrates the necessary standard libraries for any Java-based operating system. Unlike a traditional operating system, this operating system always includes a native interface and bytecode layer.
Machine Code
|
|
Native Interface
|
|
Bytecode
|
The machine code and bytecode layers of the general architecture require their own standard libraries. A "standard" library contains functions available to all programs. The library is standardized for a number of very good reasons.
A programming language depends on perfect compatibility for translators that implement the language.
A programming language is independent of the processor that translated it. A programming language might require a standard library. It is also called "run-time support" libraries.
A language like C has adopted a style of standard language interface. This provides source-level compatibility between hardware platforms. Different implementations of the standard library have exactly the same interface. A program compiled on one operating system can be compiled on another.
All programs depend on perfect backward compatibility from each standard library.
Perfect compatibility is required for porting from one operating system to another. When a new version of the operating system is released, programs developed on the old version continue to work properly. When a version of the operating system is ported from one processor to another, programs developed on one processor continue to work properly on another. The standard library is often associated with the operating system. An operating system might have a standard library.
Standard libraries encourage optimization and competition.
A standard library can be optimized for a custom platform. Functions required by the standard can be written with a custom platform in mind.
A standard library encourages competition. Different programmers can attempt to build the smallest, fastest, or most robust version. Competition provices an opportunity to give customers what they want.
A Java-based operating system has two kinds of standard libraries: machine code and bytecode. C programmers have come to expect a standard machine code library. Java programmers have come to expect a standard machine code and bytecode library.
The standard machine code library contains all of the "standard" functions available to all machine code programs. It is also known as the "standard C library" and "standard class library". In addition, there is a "standard template library" for C++ templates.
When optimized, a standard machine code library for JOS is incompatible. It cannot be used on Linux, Windows or any other operating system.
The standard machine code library can be written carefully in C/C++. A function can depend on other functions within the standard machine code library. Functions cannot depend on the standard C library or standard C++ class library.
The standard native interface library contains all of the functions, structures and classes to translate between bytecode and machine code. Like the JavaNativeInterface, additional functions are requires to copy an object in bytecode to a corresponding object in machine code. This library provides methods for interpreting the primative types.
Any kernel module can define a class in bytecode, invoke a static method, create an object in bytecode and invoke a virtual method. Likewise, any bytecode object can invoke "native" methods that are bound to machine code. The native interface is implemented for each hardware platform in a standard native interface library.
This library can be written in C/C++. These functions can depend on other functions within the standard native interface library or standard machine code library.
The standard bytecode library contains all of the classes available to all bytecode programs. It is also called the "standard class libraries", or the java
packages.
Unlike a machine code library, a bytecode library can be compatible. Even when optimized, a standard bytecode library for JOS might be used on another bytecode processor.
java.lang.Runtime
For example, Runtime.getRuntime()
always returns an instance of a custom class that extends java.lang.Runtime
.
public void example() { Runtime r = Runtime.getRuntime(); String cn = r.getClass().getName(); println( "Runtime Class: " + cn ); } public void println( String v ) { System.out.println( v ); }
For example, the decaf.VMRuntime
class might extend java.lang.Runtime
. decaf.VMRuntime.getRuntime()
might return an instance of decaf.VMRuntime()
. On JOS, Runtime.getRuntime()
might return an instance of decaf.VMRuntime
.
On a foreign virtual machine, Runtime.getRuntime()
would not return an instance of decaf.VMRuntime
but an instance of some other class.
Here is a diagram of the kernel interface, from the bottom up:
kernel The kernel is written in machine code. It is loaded before any other kernel module. |
kernel interface Some of the kernel is exposed through a kernel interface. A kernel exposes useful functions through an interface. It provide an interface between the kernel and standard machine code libraries. |
machine code library The standard machine code library provide high-level functions for all kernel modules. A standard C library could be written here. |
kernel module A kernel module provides high-level functions for all bytecode. A virtual machine could be written at this layer. |
There are multiple kernels because there are multiple hardware platforms. A kernel must be ported to different hardware platforms. This means that there must be more than one version of the kernel. With a standard kernel interface, kernels from different hardware platforms can provide similar functionality to a platform-independent virtual machine.