Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

native.h File Reference


Detailed Description

Local native method interface between JNI and JVM.

Native methods that are implemented within the JVM may circumvent the full-blown JNI interface by calling these functions.

Control

$URL: https://svn.apache.org/path/name/native.h $ $Id: native.h 0 09/28/2005 dlydick $

Copyright 2005 The Apache Software Foundation or its licensors, as applicable.

Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Version:
$LastChangedRevision: 0 $
Date:
$LastChangedDate: 09/28/2005 $
Author:
$LastChangedBy: dlydick $ Original code contributed by Daniel Lydick on 09/28/2005.

Reference

Definition in file native.h.

Go to the source code of this file.

Functions

 ARCH_COPYRIGHT_APACHE (native, h,"$URL: https://svn.apache.org/path/name/native.h $ $Id: native.h 0 09/28/2005 dlydick $")
jvm_native_method_ordinal native_locate_local_method (ClassFile *pcfs, jvm_constant_pool_index clsnameidx, jvm_constant_pool_index mthnameidx, jvm_constant_pool_index mthdescidx, rboolean find_registerNatives)
 Associate class name string with its local native method interface connection.
rvoid native_run_method (jvm_thread_index thridx, jvm_native_method_ordinal nmord, jvm_class_index clsidx, jvm_constant_pool_index mthnameidx, jvm_constant_pool_index mthdescidx)
 Invoke a native method, either local or full JNI.


Function Documentation

ARCH_COPYRIGHT_APACHE native  ,
,
"$URL: https://svn.apache.org/path/name/native.h $ $Id: native.h 0 09/28/2005 dlydick $" 
 

rvoid native_run_method jvm_thread_index  thridx,
jvm_native_method_ordinal  nmord,
jvm_class_index  clsidx,
jvm_constant_pool_index  mthnameidx,
jvm_constant_pool_index  mthdescidx
 

Invoke a native method, either local or full JNI.

Local native methods are normally called through this interface using their ordinal number assignment. Normal JNI native methods are invoked with the JLOBJECT_NMO_NULL ordinal and with normal class and method information.

Attention:
A necessary restriction of this local native method interface is that the real machine functions that are called as Java native methods MAY NOT attempt to call Java virtual functions. Code that needs to do this should use the full JNI instead. The same is true about Java-domain access to data. As a practical matter, this should never be an issue because the suite of local native methods is concerned with JVM core internals, that is, in the real machine domain, and will probably never care about Java-domain functionality.

All local native methods must throw Errors through exit_throw_exception() so as to avoid crossing from real- to Java-domain functionality. Each and every possible subclass of java.lang.Error and every possible subclass of java.lang.Exception is available through this interface. It will be loaded and an instance created in the usual manner after being thrown by the native code through this function. The result, of course, is a normal state of the JVM, which will be shut down in the normal fashion for Errors, but will only stop the thread for Exceptions.

Parameters:
thridx JVM thread where request came from.
nmord Ordinal number definition of local native method.
clsidx Class table index of native method to invoke.
mthnameidx Class file constant_pool index of name of native method to invoke. This entry must be a CONSTANT_Utf8_info string containing an unqualified method name.
mthdescidx Class file constant_pool index of descriptor of method to invoke. This entry must be a CONSTANT_Utf8_info string containing the descriptor of an unqualified method name.
Returns:
rvoid. May throw an error or exception of any kind from with the native code.
Verify that this local native method ordinal is both unique and complete.

Invoke JNI methods, not local native methods

Todo:
Invoke the full JNI interface for this method at this place. Additional parameters will be needed.
Currently, the JNI interface is stubbed out here. The implementation goes something like this:

env = make_JNIEnv_pointer_from_pjvm(); (to be done during jvm_init() at startup)

System.LoadLibrary("SomeJniMethodLib.so"); (to be done in Java class initialization, requires dlopen(3), dlsym(3), etc. Recommend adding function method_load_jni_lib() in this source file for this purpose.)

registerNatives(); (to be done in Java class initialization)

void *pjni = method_resolve_jni(clsidx, mthnameidx, mthdescidx); (Recommend adding this function in this source file for this purpose.)

Finally, invoke JNI method, per return type. The parameters are on the the JVM thread's STACK() now, so simply reference the stack frame for the parameter list. To be decided: How to take the return code and pass it back out. Suggest doing the same thing as the local native methods by capturing its value, POP_FRAME(), then PUSH(rc).

(*pjni)(&GET_SP(thridx)); ... (jvoid) jint rc = (*pjni)(&GET_SP(thridx)); jfloat rc = (*pjni)(&GET_SP(thridx)); jlong rc = (*pjni)(&GET_SP(thridx)); jdouble rc = (*pjni)(&GET_SP(thridx));

POP_FRAME(thridx); PUSH(thridx, rc); ... adjusted for return type

The only problem with this for now is that the STACK() in this implementation is a push-UP stack, which means that the first item pushed has the lowest real machine address. Many stacks are a push-DOWN type, which means that the last item pushed has the lowest real machine address. This will need to be examined to see how it affects the JNI implementation connectivity to the library. It should not be too much of a problem to change the STACK() implementation to be push-DOWN, but if JNI is a highly modular interface, then this implementation of it should be handle either type of STACK() with equal facility.

< Signed byte

< Unicode character

< Integer

< Signed short

< Boolean, true or false

< Long integer

< an instance of class '/class/name'

< Double-precision floating-point value

< Single-precision floating-point value

< Reference to one array dimension

< No return type, instead: (rvoid) fn(p1,p2,...)

Todo:
Which is the better error, VerifyError or NoSuchMethodError ?

Invoke local native methods that return (jvoid)

< No (jvoid) methods

< No (jvoid) methods

Invoke local native methods that return (jobject), known to this implementation as (jvm_object_hash).

< No (jobject) methods

Invoke local native methods that return (jint)

< No (jint) methods

Invoke local native methods that return (jfloat)

< No (jfloat) methods

< No (jfloat) methods

< No (jfloat) methods

< No (jfloat) methods

Invoke local native methods that return (jlong)

< No (jlong) methods

< No (jlong) methods

< No (jlong) methods

< No (jlong) methods

Invoke local native methods that return (jdouble)

< No (jdouble) methods

< No (jdouble) methods

< No (jdouble) methods

< No (jdouble) methods

IGNORE local native method registration.

IGNORE local native method un-registration.

Somebody goofed. There is an incomplete definition somewhere.

Due to the invocation of native_verify_ordinal_definition() above, this condition should not be reached unless one of the NATIVE_TABLE_JLxxxxx_RETURNTYPE macros does not have all of the entries that it needs.

Definition at line 1413 of file native.c.

References EXIT_JVM_METHOD, exit_throw_exception(), and JVMCLASS_JAVA_LANG_NOSUCHMETHODERROR.

Referenced by object_run_method(), and opcode_run().

jvm_native_method_ordinal native_locate_local_method ClassFile pcfs,
jvm_constant_pool_index  clsnameidx,
jvm_constant_pool_index  mthnameidx,
jvm_constant_pool_index  mthdescidx,
rboolean  find_registerNatives
 

Associate class name string with its local native method interface connection.

Parameters:
pcfs ClassFile pointer of a class referencing a native method, local or otherwise. The following constant_pool indices are all relative to this ClassFile.
clsnameidx constant_pool index in pcfs of class name to locate in class table.
mthnameidx constant_pool index in pcfs of method name to locate in clsnameidx.
mthdescidx constant_pool index in pcfs of method description with method name mthnameidx to locate in clsnameidx.
find_registerNatives When rtrue, will return the ordinal for JVMCFG_JLOBJECT_NMO_REGISTER and JVMCFG_JLOBJECT_NMO_UNREGISTER as well as the other ordinals. Once JVM initialization is complete, this should always be rfalse because all future classes should never have local ordinals.
Returns:
ordinal definition for this method, or jvm_native_method_ordinal_null if not found.
< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_VOID

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_VOID

Definition at line 1266 of file native.c.

Referenced by linkage_resolve_class().


Generated on Fri Sep 30 19:00:31 2005 by  doxygen 1.4.4