Java Reference
In-Depth Information
10.5.2 Crossing the JNI Layer
The JNI layer acts as a trampoline to the Symbian C++ code which
performs the actual operations. When the execution reaches the JNI
function, as defined in MyClass.readBytes() , the first obvious thing
to do is to locate the native peer by casting the passed handle:
CMyClassPeer* peer = JavaUnhand<CMyClassPeer>(aHandle);
Afterwards, there are typically some preparatory operations that require
invoking code in the VM itself (e.g., to access the aBytes parameter):
jbyte* javaBuffer = aJni->GetByteArrayElements(aBytes, NULL);
GetByteArrayElements() invokes operations directly in the VM
itself. However, if you search for such a method in the reference CLDC-HI
HotSpot, you will not find it. Let's see why. As we said previously, one of
the areas in which the Java ME subsystem can reuse code is the VM imple-
mentation. Since there are no standard interfaces to VMs through which
the Profile libraries can interact, a few VM-agnostic mechanisms were
developed. The KVM Java Native Interface (KJNI) was defined to hide the
native interfaces of different VMs. For example, GetByteArrayEle-
ments() is implemented by using CLDC-HI HotSpot interface functions,
such as KNI_GetArrayLength() , KNI_GetRawArrayRegion() ,
and so on.
This VM-agnostic KJNI insulates the Profile libraries from differences
between underlying VM implementations. The result is that Symbian OS
licensees can replace only the VM engine, by providing an implementa-
tion of the KJNI.
After the native peer is located, the operation is delegated to the
Symbian C++ layer. When the operation returns from the Symbian C++
layer, the KJNI can be used again to assign the return values into Java
objects and primitives.
10.5.3 Symbian C++ Layer
The Java and JNI layers both sit on top of a native Symbian C++
layer which performs most of the functionality. The common func-
tionality is built into the MIDP run-time executable and the variant
functionality is built into various DLLs, which are loaded from the main
Search WWH ::

Custom Search