Microsoft SDK for Java

Raw Native Interface Enhancements

RNI has been extended as a result of feedback and performance enhancements that have been made to the following primary areas:

Reflection APIs
Future Garbage Collection Performance Enhancements
RNIGetCompatibleVersion Requirement
RNI Invocation APIs

Reflection APIs

A number of native reflection APIs have been added to improve accessibility to an object's methods and fields. Using these APIs insulates DLLs from changes to the underlying object model or changes in the class hierarchy.

Users of RNI should use the new write barrier support functions to set an object field inside another object. These APIs are GCSetObjectReferenceForObject and GCSetObjectReferenceForHandle. Also, Field_SetValue, already in Microsoft® Internet Explorer 3.x (the virtual machine version in the Microsoft SDK for Java version 1.5.1), will support the write barrier. RNI developers are encouraged to use the Field_ reflection APIs added in Internet Explorer 3.x because these APIs abstract the object layout. Because these APIs are available on Internet Explorer 3.x, it should be possible to make a single DLL that will work on Internet Explorer 3.x and Internet Explorer 4.0.

Future Garbage Collection Performance Enhancements

To support future garbage collection enhancements, the internal object model was changed to enable more effective garbage collection, and enable future write-barrier support in the garbage collector. To insulate code from these or future changes to the object model, developers are encouraged to use the reflection APIs previously described. A Java object may still be accessed as a C structure, but code must be recompiled using the updated msjavah tool provided in this SDK.

Value layout order in objects has changed. Previously, if class A with a string, an int, and a string, followed by class B with an int and a string, the object layout in memory was as follows:

From A string (can be garbage collected)
    int (atomic non-collectable)
    string
From B int
    String

In the previous example, there are three garbage collection roots. The new object layout coalesces collectable objects within a class, thus reducing the number of garbage collection roots shown as follows:

From A int (atomic non-collectable)
    string (can be garbage collected)
    string
From B string
    Int

Because of this model change, all code that uses RNI must be rebuilt and recompiled with the new msjavah tool. Existing code that hasn't been recompiled will not run on existing virtual machines. Also, existing code that relies on accessing strings directly, rather than using a provided API, will not function.

RNIGetCompatibleVersion Requirement

Due to the object model changes previously described, many RNI DLLs designed for earlier versions of the Microsoft VM need to be recompiled. To identify whether an RNI DLL is compatible with the current version of the virtual machine, it will call the RNI DLL's RNIGetCompatibleVersion export. RNI DLLs that do not export this API will not be loaded by the current virtual machine.

RNI Invocation APIs

The Microsoft VM supports two new invocation APIs, PrepareThreadForJava and UnprepareThreadForJava, which can be used to execute RNI APIs on any Microsoft® Win32® thread. The Microsoft SDK for Java has an invocation sample provided in %SDKDIR%\Samples\Native\Invocation. For more information, see the Native Code Samples Overview. For information about other samples in this SDK, see the Samples Overview.

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