Microsoft SDK for Java

Microsoft Virtual Machine

The Microsoft® virtual machine (Microsoft VM) is a platform-independent software engine that runs Java applets, applications, and COM objects. The Microsoft VM is an interpreter and a runtime system: As an interpreter, the Microsoft VM interprets architecture-neutral instructions, or bytecode. It is machine-independent code generated by Java compilers such as jvc.exe, the Microsoft compiler, and executed by the Java interpreter or compiled at the last minute by a JIT compiler.

Bytecode resembles machine code but is not specific to any one processor. Bytecode is executable on any operating system that supports the Java runtime system. The bytecode (compiled code) is stored in a binary, platform-independent class file, which is a stream of bytes. As a runtime system, the Microsoft VM loads, links, initializes, and executes Java classes.

The Microsoft VM automatically performs garbage collection. The Microsoft VM supports debugging and profiling of running Java code. The following figure and descriptions outline the Microsoft VM's execution of Java software.

The Microsoft virtual machine

Java Software

The Microsoft VM works with many forms of Java software, including the following:

Java APIs

The Microsoft VM includes support for several Java application programming interface (API) sets, including the following:

Note   AFC and its documentation has moved to the Microsoft® SDK for Application Foundation Classes, which can be downloaded from http://www.microsoft.com/java/download.htm This link takes you to a site on microsoft.com.

Microsoft VM Components

Class Loader

A class loader retrieves the class file data that describes Java classes. Common class loaders can read class files from a uniform resource locator (URL), a file, a compressed .zip file, a class file database, or a Win32 resource.

Class Resolver

Class resolution is part of the linking process. After the class loader obtains the class file data, it calls a Microsoft VM method to resolve the class file data into a an internal representation of the class. The class resolver creates this internal representation by extracting constant pool entries, methods, fields, and other attributes, and laying them out in memory. From this internal class structure, the Microsoft VM creates and manipulates instances of the Java class.

Bytecode Verifier

The bytecode verifier of the Microsoft VM scrutinizes Java class methods for correctness. The set of required checks includes the following:

Garbage Collector

If the Microsoft VM can verify that a given Java object will not be accessed again during the execution of the Java program, the garbage collector can free the memory consumed by that object for reuse. This contrasts with other languages that require the programmer to explicitly track runtime memory usage and deallocate memory that is no longer in use.

JIT Compiler

To improve performance, the bytecodes that define a Java method can be translated into machine code that is specific to the host computer. When such translation occurs immediately before a Java method is first executed, it is referred to as a Just-In-Time (JIT) compilation.

The Compilers topic describes the Microsoft VM Java compiler (jvc), the Microsoft® Visual J++® compiler, and the Microsoft VM JIT compiler.

Execution Engine

Most generally, execution includes all the Microsoft VM's actions from startup through exit. More specifically, the execution engine's tasks could be thought of as beginning when the Microsoft VM has finished loading and linking. These tasks are as follows:

Debugging

The Microsoft VM's debugging support provides hooks into the Microsoft VM that enable a debugger to step through executing Java code and examine object data, threads, methods, classes, and method call stacks. Debuggers aid in detecting and investigating logical errors in Java applications. The debugging support is exposed by COM interfaces on COM objects implemented by the Microsoft VM.

The Debugger Interfaces Overview describes the debugging interfaces provided by the Microsoft VM. Use these to implement your debugger.

Profiling

The Microsoft VM's profiling support provides data about the runtime behavior of Java programs, including execution time and memory usage. The profiling support is exposed by COM interfaces on COM objects implemented by the Microsoft VM.

The Profiler Interfaces Overview describes the profiling interfaces provided by the Microsoft VM. Use these to implement your profiler.

Native Code Interfaces

JNI

The Java Native Interface (JNI) is an interface for writing Java methods in native code. JNI exposes all Java objects from the Microsoft VM to the native code, and allows manipulation of these objects through handles rather than direct object references. JNI automatically takes care of reference tracking for garbage collection. See the following table for a comparison of native code interfaces.

RNI

The Raw Native Interface (RNI) is also an interface for writing Java methods in native code. RNI is more efficient than JNI. In contrast with JNI, RNI requires explicit starting and stopping of the garbage collector as appropriate. RNI also requires you to ensure that any references to Java objects are correctly handled while garbage collection is enabled. Also, unlike JNI, RNI exposes direct references to Java objects. See the following table for a comparison of native code interfaces.

J/Direct

J/Direct allows you to directly call any function exported by a dynamic-link library (DLL) without having to write an RNI or COM wrapper DLL. The Microsoft VM automatically maps data types for you. This mapping of data types is called marshaling. See the following table for a comparison of native code interfaces.

COM

The Microsoft VM can automatically treat COM objects as Java objects. The Java developer, therefore, is already in effect a COM developer, because the Microsoft VM allows the Java developer to manipulate Java objects and COM objects the same way. Java/COM integration allows Java software to take advantage of COM applications and services written in any language, and provides Java access to distributed COM (DCOM) functionality. For details, see the white papers Using COM Objects from Java and Integrating Java and COM. See the following table for a comparison of native code interfaces.

Note   The Microsoft VM implements COM classes. Instances of the Microsoft VM's COM classes, like other COM classes, can be created through a CoCreateInstance call. JView is a C++ application that invokes the Microsoft VM in this way to run Java applications.

Native Code Interfaces and the Microsoft VM

Native code interface Mechanism for calling Java native methods? Garbage collection implicitly disabled during call? Java objects manipulated using handles? Marshaling of method parameters and return value?
JNI yes no yes no
RNI yes yes no no
J/Direct no no no yes
COM no no no yes

There are several APIs that give independent software vendors (ISVs) access to the Microsoft VM's underlying features. This information is especially useful if you are creating Java development tools for use with the Microsoft VM.

Determining the VM Version Number describes how to determine which version of the Microsoft VM is running on your machine.

Microsoft VM Object Model describes the object model as it applies to object decomposition and performance.

Compilers describes Microsoft's Java compilers.

Exegen Format describes the data format that must be used for Java resources stored within a portable executable (PE) image so that the Microsoft VM can locate those resources.

Debugger Interfaces Overview provides an overview of the debugger interfaces, including enabling debugging in the Microsoft VM, registering with the debugger manager, implementing callback notification interfaces, and so on.

Profiler Interfaces Overview provides an overview of the profiler interfaces, including enabling profiling in the Microsoft VM, registering for event notification, implementing event monitor information interfaces, and so on.

Invocation Interfaces Reference describes the invocation APIs provided by the Microsoft VM.

Compiler Directives Reference examines the optional special comments inserted in source code to aid in Java/COM integration and development when using the Microsoft compiler, jvc.exe.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.