register2.java: New file.
* testsuite/libjava.jni/register2.java: New file. * testsuite/libjava.jni/register2.out: New file. * testsuite/libjava.jni/register2.c: New file. * java/lang/natClass.cc (_Jv_GetClassNameUtf8): New function. * java/lang/Class.h (_Jv_GetClassNameUtf8): Declare. * jni.cc (struct NativeMethodCacheEntry): New struct. (nathash): Changed type. (hash): Updated. (nathash_find_slot): Likewise. (nathash_find): Likewise. (natrehash): Likewise. (nathash_add): Likewise. (_Jv_JNI_RegisterNatives): Likewise. (_Jv_LookupJNIMethod): Likewise. Idea from Juerg Lehni <juerg@scratchdisk.com> Co-Authored-By: Bryce McKinlay <mckinlay@redhat.com> From-SVN: r117867
This commit is contained in:
parent
9e7fc6b946
commit
e7f7d23387
7 changed files with 140 additions and 19 deletions
48
libjava/testsuite/libjava.jni/register2.c
Normal file
48
libjava/testsuite/libjava.jni/register2.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <register2.h>
|
||||
|
||||
static int
|
||||
twentythree (JNIEnv *env, jclass k)
|
||||
{
|
||||
return 23;
|
||||
}
|
||||
|
||||
static int
|
||||
oneninetyseven (JNIEnv *env, jclass k)
|
||||
{
|
||||
return 197;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JNI_OnLoad (JavaVM *vm, void *nothing)
|
||||
{
|
||||
JNIEnv *env;
|
||||
JNINativeMethod meth;
|
||||
jclass k;
|
||||
jint r;
|
||||
|
||||
r = (*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_2);
|
||||
assert (r == JNI_OK);
|
||||
k = (*env)->FindClass (env, "register2$I1");
|
||||
assert (k != NULL);
|
||||
|
||||
meth.name = "doit";
|
||||
meth.signature = "()I";
|
||||
meth.fnPtr = twentythree;
|
||||
|
||||
r = (*env)->RegisterNatives (env, k, &meth, 1);
|
||||
assert (r == JNI_OK);
|
||||
|
||||
k = (*env)->FindClass (env, "register2$I2");
|
||||
assert (k != NULL);
|
||||
|
||||
meth.name = "doit";
|
||||
meth.signature = "()I";
|
||||
meth.fnPtr = oneninetyseven;
|
||||
|
||||
r = (*env)->RegisterNatives (env, k, &meth, 1);
|
||||
assert (r == JNI_OK);
|
||||
|
||||
return JNI_VERSION_1_2;
|
||||
}
|
27
libjava/testsuite/libjava.jni/register2.java
Normal file
27
libjava/testsuite/libjava.jni/register2.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Another test of RegisterNatives.
|
||||
// We neglected to track the class name in our internal hash table.
|
||||
// This is a regression test for the fix.
|
||||
|
||||
public class register2
|
||||
{
|
||||
static
|
||||
{
|
||||
System.loadLibrary ("register2");
|
||||
}
|
||||
|
||||
static class I1
|
||||
{
|
||||
public static native int doit ();
|
||||
}
|
||||
|
||||
static class I2
|
||||
{
|
||||
public static native int doit ();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println (new I1().doit());
|
||||
System.out.println (new I2().doit());
|
||||
}
|
||||
}
|
2
libjava/testsuite/libjava.jni/register2.out
Normal file
2
libjava/testsuite/libjava.jni/register2.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
23
|
||||
197
|
Loading…
Add table
Add a link
Reference in a new issue