]> gcc.gnu.org Git - gcc.git/blame - libjava/jni.cc
All files: Updated copyright information.
[gcc.git] / libjava / jni.cc
CommitLineData
ee9dd372
TT
1// jni.cc - JNI implementation, including the jump table.
2
2ba5f774 3/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
ee9dd372
TT
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11#include <config.h>
12
13#include <stddef.h>
7e648cf9 14#include <string.h>
ee9dd372 15
355dff4c
TT
16// Define this before including jni.h.
17#define __GCJ_JNI_IMPL__
8a922095
TT
18
19#include <gcj/cni.h>
20#include <jvm.h>
21#include <java-assert.h>
ee9dd372 22#include <jni.h>
355dff4c
TT
23
24#include <java/lang/Class.h>
25#include <java/lang/ClassLoader.h>
8a922095
TT
26#include <java/lang/Throwable.h>
27#include <java/lang/ArrayIndexOutOfBoundsException.h>
355dff4c 28#include <java/lang/StringIndexOutOfBoundsException.h>
facc279f 29#include <java/lang/AbstractMethodError.h>
8a922095
TT
30#include <java/lang/InstantiationException.h>
31#include <java/lang/NoSuchFieldError.h>
32#include <java/lang/NoSuchMethodError.h>
33#include <java/lang/reflect/Constructor.h>
355dff4c 34#include <java/lang/reflect/Method.h>
8a922095 35#include <java/lang/reflect/Modifier.h>
7e648cf9
TT
36#include <java/lang/OutOfMemoryError.h>
37#include <java/util/Hashtable.h>
38#include <java/lang/Integer.h>
aaf0766e 39#include <gnu/gcj/jni/NativeThread.h>
8a922095 40
355dff4c
TT
41#include <gcj/method.h>
42#include <gcj/field.h>
43
ee6713e7
TT
44#include <java-interp.h>
45
8a922095
TT
46#define ClassClass _CL_Q34java4lang5Class
47extern java::lang::Class ClassClass;
48#define ObjectClass _CL_Q34java4lang6Object
49extern java::lang::Class ObjectClass;
50
278abd28
TT
51#define ThrowableClass _CL_Q34java4lang9Throwable
52extern java::lang::Class ThrowableClass;
355dff4c
TT
53#define MethodClass _CL_Q44java4lang7reflect6Method
54extern java::lang::Class MethodClass;
aaf0766e
TT
55#define ThreadGroupClass _CL_Q34java4lang11ThreadGroup
56extern java::lang::Class ThreadGroupClass;
57#define NativeThreadClass _CL_Q43gnu3gcj3jni12NativeThread
58extern java::lang::Class ThreadGroupClass;
355dff4c 59
8a922095
TT
60// This enum is used to select different template instantiations in
61// the invocation code.
62enum invocation_type
63{
64 normal,
65 nonvirtual,
66 static_type,
67 constructor
68};
69
aaf0766e 70// Forward declarations.
355dff4c 71extern struct JNINativeInterface _Jv_JNIFunctions;
aaf0766e 72extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
355dff4c 73
7e648cf9
TT
74// Number of slots in the default frame. The VM must allow at least
75// 16.
76#define FRAME_SIZE 32
77
8d00f617
TT
78// Mark value indicating this is an overflow frame.
79#define MARK_NONE 0
80// Mark value indicating this is a user frame.
81#define MARK_USER 1
82// Mark value indicating this is a system frame.
83#define MARK_SYSTEM 2
84
7e648cf9
TT
85// This structure is used to keep track of local references.
86struct _Jv_JNI_LocalFrame
87{
88 // This is true if this frame object represents a pushed frame (eg
89 // from PushLocalFrame).
8d00f617 90 int marker : 2;
7e648cf9
TT
91
92 // Number of elements in frame.
8d00f617 93 int size : 30;
7e648cf9
TT
94
95 // Next frame in chain.
96 _Jv_JNI_LocalFrame *next;
97
98 // The elements. These are allocated using the C "struct hack".
99 jobject vec[0];
100};
101
102// This holds a reference count for all local and global references.
103static java::util::Hashtable *ref_table;
104
aaf0766e
TT
105// The only VM.
106static JavaVM *the_vm;
107
8a922095
TT
108\f
109
7e648cf9
TT
110void
111_Jv_JNI_Init (void)
112{
113 ref_table = new java::util::Hashtable;
114}
115
8a922095
TT
116// Tell the GC that a certain pointer is live.
117static void
7e648cf9 118mark_for_gc (jobject obj)
8a922095 119{
7e648cf9
TT
120 JvSynchronize sync (ref_table);
121
122 using namespace java::lang;
123 Integer *refcount = (Integer *) ref_table->get (obj);
124 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
b099f07d 125 // FIXME: what about out of memory error?
7e648cf9 126 ref_table->put (obj, new Integer (val + 1));
8a922095
TT
127}
128
129// Unmark a pointer.
130static void
7e648cf9 131unmark_for_gc (jobject obj)
8a922095 132{
7e648cf9
TT
133 JvSynchronize sync (ref_table);
134
135 using namespace java::lang;
136 Integer *refcount = (Integer *) ref_table->get (obj);
137 JvAssert (refcount);
138 jint val = refcount->intValue () - 1;
139 if (val == 0)
140 ref_table->remove (obj);
141 else
b099f07d 142 // FIXME: what about out of memory error?
7e648cf9
TT
143 ref_table->put (obj, new Integer (val));
144}
145
146\f
147
148static jobject
149_Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
150{
151 mark_for_gc (obj);
152 return obj;
153}
154
155static void
156_Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
157{
158 unmark_for_gc (obj);
159}
160
161static void
162_Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
163{
164 _Jv_JNI_LocalFrame *frame;
165
166 for (frame = env->locals; frame != NULL; frame = frame->next)
167 {
168 for (int i = 0; i < FRAME_SIZE; ++i)
169 {
170 if (frame->vec[i] == obj)
171 {
172 frame->vec[i] = NULL;
173 unmark_for_gc (obj);
174 return;
175 }
176 }
177
178 // Don't go past a marked frame.
8d00f617 179 JvAssert (frame->marker == MARK_NONE);
7e648cf9
TT
180 }
181
182 JvAssert (0);
183}
184
185static jint
186_Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
187{
188 // It is easier to just always allocate a new frame of the requested
189 // size. This isn't the most efficient thing, but for now we don't
190 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
191
b099f07d
TT
192 _Jv_JNI_LocalFrame *frame;
193 try
7e648cf9 194 {
b099f07d
TT
195 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
196 + size * sizeof (jobject));
197 }
198 catch (jthrowable t)
199 {
200 env->ex = t;
aaf0766e 201 return JNI_ERR;
7e648cf9
TT
202 }
203
8d00f617 204 frame->marker = MARK_NONE;
7e648cf9
TT
205 frame->size = size;
206 memset (&frame->vec[0], 0, size * sizeof (jobject));
207 frame->next = env->locals;
208 env->locals = frame;
209
210 return 0;
211}
212
213static jint
214_Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
215{
216 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
217 if (r < 0)
218 return r;
219
220 // The new frame is on top.
8d00f617 221 env->locals->marker = MARK_USER;
7e648cf9
TT
222
223 return 0;
224}
225
226static jobject
227_Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
228{
229 // Try to find an open slot somewhere in the topmost frame.
230 _Jv_JNI_LocalFrame *frame = env->locals;
231 bool done = false, set = false;
232 while (frame != NULL && ! done)
233 {
234 for (int i = 0; i < frame->size; ++i)
235 if (frame->vec[i] == NULL)
236 {
237 set = true;
238 done = true;
239 frame->vec[i] = obj;
240 break;
241 }
242 }
243
244 if (! set)
245 {
246 // No slots, so we allocate a new frame. According to the spec
247 // we could just die here. FIXME: return value.
248 _Jv_JNI_EnsureLocalCapacity (env, 16);
249 // We know the first element of the new frame will be ok.
250 env->locals->vec[0] = obj;
251 }
252
253 mark_for_gc (obj);
254 return obj;
255}
256
257static jobject
8d00f617 258_Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result, int stop)
7e648cf9
TT
259{
260 _Jv_JNI_LocalFrame *rf = env->locals;
261
262 bool done = false;
263 while (rf != NULL && ! done)
264 {
265 for (int i = 0; i < rf->size; ++i)
266 if (rf->vec[i] != NULL)
267 unmark_for_gc (rf->vec[i]);
268
269 // If the frame we just freed is the marker frame, we are done.
8d00f617 270 done = (rf->marker == stop);
7e648cf9
TT
271
272 _Jv_JNI_LocalFrame *n = rf->next;
273 // When N==NULL, we've reached the stack-allocated frame, and we
274 // must not free it. However, we must be sure to clear all its
275 // elements, since we might conceivably reuse it.
276 if (n == NULL)
ee7f72e4
TT
277 {
278 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
279 break;
280 }
281
282 _Jv_Free (rf);
7e648cf9
TT
283 rf = n;
284 }
285
286 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
8a922095
TT
287}
288
8d00f617
TT
289static jobject
290_Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
291{
292 return _Jv_JNI_PopLocalFrame (env, result, MARK_USER);
293}
294
295// Pop a `system' frame from the stack. This is `extern "C"' as it is
296// used by the compiler.
297extern "C" void
298_Jv_JNI_PopSystemFrame (JNIEnv *env)
299{
300 _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM);
301}
302
ee7f72e4
TT
303// This function is used from other template functions. It wraps the
304// return value appropriately; we specialize it so that object returns
305// are turned into local references.
306template<typename T>
307static T
308wrap_value (JNIEnv *, T value)
309{
310 return value;
311}
312
313template<>
314static jobject
315wrap_value (JNIEnv *env, jobject value)
316{
278abd28 317 return value == NULL ? value : _Jv_JNI_NewLocalRef (env, value);
ee7f72e4
TT
318}
319
8a922095
TT
320\f
321
322static jint
323_Jv_JNI_GetVersion (JNIEnv *)
324{
325 return JNI_VERSION_1_2;
326}
ee9dd372 327
355dff4c 328static jclass
7e648cf9 329_Jv_JNI_DefineClass (JNIEnv *env, jobject loader,
355dff4c
TT
330 const jbyte *buf, jsize bufLen)
331{
b099f07d
TT
332 try
333 {
334 jbyteArray bytes = JvNewByteArray (bufLen);
355dff4c 335
b099f07d
TT
336 jbyte *elts = elements (bytes);
337 memcpy (elts, buf, bufLen * sizeof (jbyte));
355dff4c 338
b099f07d
TT
339 java::lang::ClassLoader *l
340 = reinterpret_cast<java::lang::ClassLoader *> (loader);
341
342 jclass result = l->defineClass (bytes, 0, bufLen);
343 return (jclass) wrap_value (env, result);
344 }
345 catch (jthrowable t)
346 {
347 env->ex = t;
348 return NULL;
349 }
355dff4c
TT
350}
351
352static jclass
353_Jv_JNI_FindClass (JNIEnv *env, const char *name)
354{
355 // FIXME: assume that NAME isn't too long.
356 int len = strlen (name);
357 char s[len + 1];
358 for (int i = 0; i <= len; ++i)
359 s[i] = (name[i] == '/') ? '.' : name[i];
355dff4c 360
b099f07d
TT
361 jclass r = NULL;
362 try
355dff4c 363 {
b099f07d
TT
364 // This might throw an out of memory exception.
365 jstring n = JvNewStringUTF (s);
366
367 java::lang::ClassLoader *loader;
368 if (env->klass == NULL)
369 {
370 // FIXME: should use getBaseClassLoader, but we don't have that
371 // yet.
372 loader = java::lang::ClassLoader::getSystemClassLoader ();
373 }
374 else
375 loader = env->klass->getClassLoader ();
355dff4c 376
b099f07d
TT
377 r = loader->loadClass (n);
378 }
379 catch (jthrowable t)
380 {
381 env->ex = t;
382 }
355dff4c 383
278abd28 384 return (jclass) wrap_value (env, r);
355dff4c
TT
385}
386
ee9dd372 387static jclass
7e648cf9 388_Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
ee9dd372 389{
278abd28 390 return (jclass) wrap_value (env, clazz->getSuperclass ());
ee9dd372
TT
391}
392
393static jboolean
355dff4c 394_Jv_JNI_IsAssignableFrom(JNIEnv *, jclass clazz1, jclass clazz2)
ee9dd372
TT
395{
396 return clazz1->isAssignableFrom (clazz2);
397}
398
8a922095
TT
399static jint
400_Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
401{
278abd28
TT
402 // We check in case the user did some funky cast.
403 JvAssert (obj != NULL && (&ThrowableClass)->isInstance (obj));
355dff4c 404 env->ex = obj;
8a922095
TT
405 return 0;
406}
407
408static jint
409_Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
410{
411 using namespace java::lang::reflect;
412
278abd28
TT
413 JvAssert ((&ThrowableClass)->isAssignableFrom (clazz));
414
b099f07d
TT
415 int r = JNI_OK;
416 try
417 {
418 JArray<jclass> *argtypes
419 = (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL);
8a922095 420
b099f07d
TT
421 jclass *elts = elements (argtypes);
422 elts[0] = &StringClass;
8a922095 423
b099f07d 424 Constructor *cons = clazz->getConstructor (argtypes);
8a922095 425
b099f07d
TT
426 jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
427 jobject *velts = elements (values);
428 velts[0] = JvNewStringUTF (message);
8a922095 429
b099f07d 430 jobject obj = cons->newInstance (values);
8a922095 431
b099f07d
TT
432 env->ex = reinterpret_cast<jthrowable> (obj);
433 }
434 catch (jthrowable t)
435 {
436 env->ex = t;
437 r = JNI_ERR;
438 }
439
440 return r;
8a922095
TT
441}
442
443static jthrowable
444_Jv_JNI_ExceptionOccurred (JNIEnv *env)
445{
278abd28 446 return (jthrowable) wrap_value (env, env->ex);
8a922095
TT
447}
448
449static void
450_Jv_JNI_ExceptionDescribe (JNIEnv *env)
451{
355dff4c
TT
452 if (env->ex != NULL)
453 env->ex->printStackTrace();
8a922095
TT
454}
455
456static void
457_Jv_JNI_ExceptionClear (JNIEnv *env)
458{
355dff4c
TT
459 env->ex = NULL;
460}
461
462static jboolean
463_Jv_JNI_ExceptionCheck (JNIEnv *env)
464{
465 return env->ex != NULL;
8a922095
TT
466}
467
468static void
469_Jv_JNI_FatalError (JNIEnv *, const char *message)
470{
471 JvFail (message);
472}
473
7e648cf9
TT
474\f
475
8a922095
TT
476static jboolean
477_Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
478{
479 return obj1 == obj2;
480}
481
ee9dd372 482static jobject
8a922095 483_Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
ee9dd372 484{
8a922095
TT
485 jobject obj = NULL;
486 using namespace java::lang::reflect;
278abd28 487
b099f07d
TT
488 try
489 {
490 JvAssert (clazz && ! clazz->isArray ());
491 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
492 env->ex = new java::lang::InstantiationException ();
493 else
494 {
495 // FIXME: will this work for String?
496 obj = JvAllocObject (clazz);
497 }
498 }
499 catch (jthrowable t)
8a922095 500 {
b099f07d 501 env->ex = t;
8a922095
TT
502 }
503
278abd28 504 return wrap_value (env, obj);
ee9dd372
TT
505}
506
8a922095 507static jclass
7e648cf9 508_Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
ee9dd372 509{
278abd28
TT
510 JvAssert (obj);
511 return (jclass) wrap_value (env, obj->getClass());
ee9dd372
TT
512}
513
8a922095
TT
514static jboolean
515_Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
ee9dd372 516{
8a922095 517 return clazz->isInstance(obj);
ee9dd372
TT
518}
519
8a922095
TT
520\f
521
522//
523// This section concerns method invocation.
524//
525
526template<jboolean is_static>
527static jmethodID
528_Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
529 const char *name, const char *sig)
ee9dd372 530{
b099f07d
TT
531 try
532 {
533 _Jv_InitClass (clazz);
8a922095 534
b099f07d
TT
535 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
536 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
8a922095 537
b099f07d 538 JvAssert (! clazz->isPrimitive());
8a922095 539
b099f07d 540 using namespace java::lang::reflect;
8a922095 541
b099f07d 542 while (clazz != NULL)
8a922095 543 {
b099f07d
TT
544 jint count = JvNumMethods (clazz);
545 jmethodID meth = JvGetFirstMethod (clazz);
546
547 for (jint i = 0; i < count; ++i)
548 {
549 if (((is_static && Modifier::isStatic (meth->accflags))
550 || (! is_static && ! Modifier::isStatic (meth->accflags)))
551 && _Jv_equalUtf8Consts (meth->name, name_u)
552 && _Jv_equalUtf8Consts (meth->signature, sig_u))
553 return meth;
554
555 meth = meth->getNextMethod();
556 }
8a922095 557
b099f07d 558 clazz = clazz->getSuperclass ();
8a922095
TT
559 }
560
b099f07d
TT
561 env->ex = new java::lang::NoSuchMethodError ();
562 }
563 catch (jthrowable t)
564 {
565 env->ex = t;
8a922095
TT
566 }
567
8a922095
TT
568 return NULL;
569}
570
571// This is a helper function which turns a va_list into an array of
572// `jvalue's. It needs signature information in order to do its work.
573// The array of values must already be allocated.
574static void
575array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
576{
577 jclass *arg_elts = elements (arg_types);
578 for (int i = 0; i < arg_types->length; ++i)
579 {
580 if (arg_elts[i] == JvPrimClass (byte))
581 values[i].b = va_arg (vargs, jbyte);
582 else if (arg_elts[i] == JvPrimClass (short))
583 values[i].s = va_arg (vargs, jshort);
584 else if (arg_elts[i] == JvPrimClass (int))
585 values[i].i = va_arg (vargs, jint);
586 else if (arg_elts[i] == JvPrimClass (long))
587 values[i].j = va_arg (vargs, jlong);
588 else if (arg_elts[i] == JvPrimClass (float))
589 values[i].f = va_arg (vargs, jfloat);
590 else if (arg_elts[i] == JvPrimClass (double))
591 values[i].d = va_arg (vargs, jdouble);
592 else if (arg_elts[i] == JvPrimClass (boolean))
593 values[i].z = va_arg (vargs, jboolean);
594 else if (arg_elts[i] == JvPrimClass (char))
595 values[i].c = va_arg (vargs, jchar);
596 else
597 {
598 // An object.
599 values[i].l = va_arg (vargs, jobject);
600 }
601 }
602}
603
604// This can call any sort of method: virtual, "nonvirtual", static, or
605// constructor.
606template<typename T, invocation_type style>
607static T
608_Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
609 jmethodID id, va_list vargs)
610{
611 if (style == normal)
612 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
613
614 jclass decl_class = klass ? klass : obj->getClass ();
615 JvAssert (decl_class != NULL);
616
617 jclass return_type;
618 JArray<jclass> *arg_types;
8a922095 619
b099f07d
TT
620 try
621 {
622 _Jv_GetTypesFromSignature (id, decl_class,
623 &arg_types, &return_type);
624
625 jvalue args[arg_types->length];
626 array_from_valist (args, arg_types, vargs);
8a922095 627
b099f07d
TT
628 // For constructors we need to pass the Class we are instantiating.
629 if (style == constructor)
630 return_type = klass;
1adbc4d8 631
b099f07d
TT
632 jvalue result;
633 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
634 style == constructor,
635 arg_types, args, &result);
8a922095 636
b099f07d
TT
637 if (ex != NULL)
638 env->ex = ex;
8a922095 639
b099f07d
TT
640 // We cheat a little here. FIXME.
641 return wrap_value (env, * (T *) &result);
642 }
643 catch (jthrowable t)
644 {
645 env->ex = t;
646 }
647
648 return wrap_value (env, (T) 0);
8a922095
TT
649}
650
651template<typename T, invocation_type style>
652static T
653_Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
654 jmethodID method, ...)
655{
656 va_list args;
657 T result;
658
659 va_start (args, method);
660 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
661 va_end (args);
662
663 return result;
664}
665
666template<typename T, invocation_type style>
667static T
668_Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
669 jmethodID id, jvalue *args)
670{
671 if (style == normal)
672 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
673
674 jclass decl_class = klass ? klass : obj->getClass ();
675 JvAssert (decl_class != NULL);
676
677 jclass return_type;
678 JArray<jclass> *arg_types;
b099f07d
TT
679 try
680 {
681 _Jv_GetTypesFromSignature (id, decl_class,
682 &arg_types, &return_type);
8a922095 683
b099f07d
TT
684 // For constructors we need to pass the Class we are instantiating.
685 if (style == constructor)
686 return_type = klass;
1adbc4d8 687
b099f07d
TT
688 jvalue result;
689 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
690 style == constructor,
691 arg_types, args, &result);
8a922095 692
b099f07d
TT
693 if (ex != NULL)
694 env->ex = ex;
8a922095 695
b099f07d
TT
696 // We cheat a little here. FIXME.
697 return wrap_value (env, * (T *) &result);
698 }
699 catch (jthrowable t)
700 {
701 env->ex = t;
702 }
703
704 return wrap_value (env, (T) 0);
8a922095
TT
705}
706
707template<invocation_type style>
708static void
709_Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
710 jmethodID id, va_list vargs)
711{
712 if (style == normal)
713 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
714
715 jclass decl_class = klass ? klass : obj->getClass ();
716 JvAssert (decl_class != NULL);
717
718 jclass return_type;
719 JArray<jclass> *arg_types;
b099f07d
TT
720 try
721 {
722 _Jv_GetTypesFromSignature (id, decl_class,
723 &arg_types, &return_type);
8a922095 724
b099f07d
TT
725 jvalue args[arg_types->length];
726 array_from_valist (args, arg_types, vargs);
8a922095 727
b099f07d
TT
728 // For constructors we need to pass the Class we are instantiating.
729 if (style == constructor)
730 return_type = klass;
1adbc4d8 731
b099f07d
TT
732 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
733 style == constructor,
734 arg_types, args, NULL);
8a922095 735
b099f07d
TT
736 if (ex != NULL)
737 env->ex = ex;
738 }
739 catch (jthrowable t)
740 {
741 env->ex = t;
742 }
8a922095
TT
743}
744
745template<invocation_type style>
746static void
747_Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
748 jmethodID method, ...)
749{
750 va_list args;
751
752 va_start (args, method);
753 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
754 va_end (args);
755}
756
757template<invocation_type style>
758static void
759_Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
760 jmethodID id, jvalue *args)
761{
762 if (style == normal)
763 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
764
765 jclass decl_class = klass ? klass : obj->getClass ();
766 JvAssert (decl_class != NULL);
767
768 jclass return_type;
769 JArray<jclass> *arg_types;
b099f07d
TT
770 try
771 {
772 _Jv_GetTypesFromSignature (id, decl_class,
773 &arg_types, &return_type);
8a922095 774
b099f07d
TT
775 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
776 style == constructor,
777 arg_types, args, NULL);
8a922095 778
b099f07d
TT
779 if (ex != NULL)
780 env->ex = ex;
781 }
782 catch (jthrowable t)
783 {
784 env->ex = t;
785 }
8a922095
TT
786}
787
788// Functions with this signature are used to implement functions in
789// the CallMethod family.
790template<typename T>
791static T
792_Jv_JNI_CallMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
793{
794 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
795}
796
797// Functions with this signature are used to implement functions in
798// the CallMethod family.
799template<typename T>
800static T
801_Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
802{
803 va_list args;
804 T result;
805
806 va_start (args, id);
807 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
808 va_end (args);
809
810 return result;
811}
812
813// Functions with this signature are used to implement functions in
814// the CallMethod family.
815template<typename T>
816static T
817_Jv_JNI_CallMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
818{
819 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
820}
821
822static void
823_Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
824{
825 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
826}
827
828static void
829_Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
830{
831 va_list args;
832
833 va_start (args, id);
834 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
835 va_end (args);
ee9dd372
TT
836}
837
8a922095
TT
838static void
839_Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
ee9dd372 840{
8a922095
TT
841 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
842}
843
844// Functions with this signature are used to implement functions in
845// the CallStaticMethod family.
846template<typename T>
847static T
848_Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
849 jmethodID id, va_list args)
850{
5ef57049
TT
851 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
852 JvAssert ((&ClassClass)->isInstance (klass));
853
8a922095
TT
854 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
855}
856
857// Functions with this signature are used to implement functions in
858// the CallStaticMethod family.
859template<typename T>
860static T
861_Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
862{
863 va_list args;
864 T result;
865
5ef57049
TT
866 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
867 JvAssert ((&ClassClass)->isInstance (klass));
868
8a922095
TT
869 va_start (args, id);
870 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
871 id, args);
872 va_end (args);
873
874 return result;
875}
876
877// Functions with this signature are used to implement functions in
878// the CallStaticMethod family.
879template<typename T>
880static T
881_Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
882 jvalue *args)
883{
5ef57049
TT
884 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
885 JvAssert ((&ClassClass)->isInstance (klass));
886
8a922095
TT
887 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
888}
889
890static void
891_Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass, jmethodID id,
892 va_list args)
893{
894 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
895}
896
897static void
898_Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
899{
900 va_list args;
901
902 va_start (args, id);
903 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
904 va_end (args);
905}
906
907static void
908_Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass, jmethodID id,
909 jvalue *args)
910{
911 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
912}
913
914static jobject
915_Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
916 jmethodID id, va_list args)
917{
278abd28
TT
918 JvAssert (klass && ! klass->isArray ());
919 JvAssert (! strcmp (id->name->data, "<init>")
1adbc4d8
TT
920 && id->signature->length > 2
921 && id->signature->data[0] == '('
922 && ! strcmp (&id->signature->data[id->signature->length - 2],
923 ")V"));
924
8a922095
TT
925 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
926 id, args);
927}
928
929static jobject
930_Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
931{
278abd28
TT
932 JvAssert (klass && ! klass->isArray ());
933 JvAssert (! strcmp (id->name->data, "<init>")
1adbc4d8
TT
934 && id->signature->length > 2
935 && id->signature->data[0] == '('
936 && ! strcmp (&id->signature->data[id->signature->length - 2],
937 ")V"));
278abd28 938
8a922095
TT
939 va_list args;
940 jobject result;
941
942 va_start (args, id);
943 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
944 id, args);
945 va_end (args);
946
947 return result;
948}
949
950static jobject
951_Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
952 jvalue *args)
953{
278abd28
TT
954 JvAssert (klass && ! klass->isArray ());
955 JvAssert (! strcmp (id->name->data, "<init>")
1adbc4d8
TT
956 && id->signature->length > 2
957 && id->signature->data[0] == '('
958 && ! strcmp (&id->signature->data[id->signature->length - 2],
959 ")V"));
960
8a922095
TT
961 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
962 id, args);
963}
964
965\f
966
967template<typename T>
968static T
ee7f72e4 969_Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field)
8a922095 970{
278abd28 971 JvAssert (obj);
8a922095 972 T *ptr = (T *) ((char *) obj + field->getOffset ());
ee7f72e4 973 return wrap_value (env, *ptr);
5dc489c1
TT
974}
975
8a922095
TT
976template<typename T>
977static void
978_Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
979{
278abd28 980 JvAssert (obj);
8a922095
TT
981 T *ptr = (T *) ((char *) obj + field->getOffset ());
982 *ptr = value;
983}
984
985template<jboolean is_static>
986static jfieldID
987_Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
988 const char *name, const char *sig)
989{
b099f07d
TT
990 try
991 {
992 _Jv_InitClass (clazz);
8a922095 993
b099f07d 994 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
8a922095 995
b099f07d
TT
996 jclass field_class = NULL;
997 if (sig[0] == '[')
998 field_class = _Jv_FindClassFromSignature ((char *) sig, NULL);
999 else
1000 {
1001 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
1002 field_class = _Jv_FindClass (sig_u, NULL);
1003 }
8a922095 1004
b099f07d 1005 // FIXME: what if field_class == NULL?
8a922095 1006
b099f07d 1007 while (clazz != NULL)
8a922095 1008 {
b099f07d
TT
1009 jint count = (is_static
1010 ? JvNumStaticFields (clazz)
1011 : JvNumInstanceFields (clazz));
1012 jfieldID field = (is_static
1013 ? JvGetFirstStaticField (clazz)
1014 : JvGetFirstInstanceField (clazz));
1015 for (jint i = 0; i < count; ++i)
1016 {
1017 // The field is resolved as a side effect of class
1018 // initialization.
1019 JvAssert (field->isResolved ());
8a922095 1020
b099f07d 1021 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
8a922095 1022
b099f07d
TT
1023 if (_Jv_equalUtf8Consts (f_name, a_name)
1024 && field->getClass() == field_class)
1025 return field;
8a922095 1026
b099f07d
TT
1027 field = field->getNextField ();
1028 }
1029
1030 clazz = clazz->getSuperclass ();
8a922095
TT
1031 }
1032
b099f07d
TT
1033 env->ex = new java::lang::NoSuchFieldError ();
1034 }
1035 catch (jthrowable t)
1036 {
1037 env->ex = t;
8a922095 1038 }
8a922095
TT
1039 return NULL;
1040}
1041
1042template<typename T>
1043static T
ee7f72e4 1044_Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field)
8a922095
TT
1045{
1046 T *ptr = (T *) field->u.addr;
ee7f72e4 1047 return wrap_value (env, *ptr);
5dc489c1
TT
1048}
1049
8a922095
TT
1050template<typename T>
1051static void
1052_Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
1053{
1054 T *ptr = (T *) field->u.addr;
1055 *ptr = value;
1056}
1057
1058static jstring
7e648cf9 1059_Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
8a922095 1060{
b099f07d
TT
1061 try
1062 {
1063 jstring r = _Jv_NewString (unichars, len);
1064 return (jstring) wrap_value (env, r);
1065 }
1066 catch (jthrowable t)
1067 {
1068 env->ex = t;
1069 return NULL;
1070 }
ee9dd372
TT
1071}
1072
1073static jsize
1074_Jv_JNI_GetStringLength (JNIEnv *, jstring string)
1075{
1076 return string->length();
1077}
1078
8a922095
TT
1079static const jchar *
1080_Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
1081{
1082 jchar *result = _Jv_GetStringChars (string);
7e648cf9 1083 mark_for_gc (string);
8a922095
TT
1084 if (isCopy)
1085 *isCopy = false;
1086 return (const jchar *) result;
1087}
1088
1089static void
7e648cf9 1090_Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
8a922095 1091{
7e648cf9 1092 unmark_for_gc (string);
8a922095
TT
1093}
1094
1095static jstring
7e648cf9 1096_Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
8a922095 1097{
b099f07d
TT
1098 try
1099 {
1100 jstring result = JvNewStringUTF (bytes);
1101 return (jstring) wrap_value (env, result);
1102 }
1103 catch (jthrowable t)
1104 {
1105 env->ex = t;
1106 return NULL;
1107 }
8a922095
TT
1108}
1109
1110static jsize
1111_Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
1112{
1113 return JvGetStringUTFLength (string);
1114}
1115
1116static const char *
b099f07d 1117_Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
8a922095
TT
1118{
1119 jsize len = JvGetStringUTFLength (string);
b099f07d
TT
1120 try
1121 {
1122 char *r = (char *) _Jv_Malloc (len + 1);
1123 JvGetStringUTFRegion (string, 0, len, r);
1124 r[len] = '\0';
8a922095 1125
b099f07d
TT
1126 if (isCopy)
1127 *isCopy = true;
8a922095 1128
b099f07d
TT
1129 return (const char *) r;
1130 }
1131 catch (jthrowable t)
1132 {
1133 env->ex = t;
1134 return NULL;
1135 }
8a922095
TT
1136}
1137
1138static void
1139_Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
1140{
1141 _Jv_Free ((void *) utf);
1142}
1143
355dff4c
TT
1144static void
1145_Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len,
1146 jchar *buf)
1147{
1148 jchar *result = _Jv_GetStringChars (string);
1149 if (start < 0 || start > string->length ()
1150 || len < 0 || start + len > string->length ())
b099f07d
TT
1151 {
1152 try
1153 {
1154 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1155 }
1156 catch (jthrowable t)
1157 {
1158 env->ex = t;
1159 }
1160 }
355dff4c
TT
1161 else
1162 memcpy (buf, &result[start], len * sizeof (jchar));
1163}
1164
1165static void
1166_Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
1167 jsize len, char *buf)
1168{
1169 if (start < 0 || start > str->length ()
1170 || len < 0 || start + len > str->length ())
b099f07d
TT
1171 {
1172 try
1173 {
1174 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1175 }
1176 catch (jthrowable t)
1177 {
1178 env->ex = t;
1179 }
1180 }
355dff4c
TT
1181 else
1182 _Jv_GetStringUTFRegion (str, start, len, buf);
1183}
1184
1185static const jchar *
1186_Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
1187{
1188 jchar *result = _Jv_GetStringChars (str);
1189 if (isCopy)
1190 *isCopy = false;
1191 return result;
1192}
1193
1194static void
1195_Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
1196{
1197 // Nothing.
1198}
1199
8a922095
TT
1200static jsize
1201_Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
1202{
1203 return array->length;
1204}
1205
1206static jarray
7e648cf9 1207_Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass,
8a922095
TT
1208 jobject init)
1209{
b099f07d
TT
1210 try
1211 {
1212 jarray result = JvNewObjectArray (length, elementClass, init);
1213 return (jarray) wrap_value (env, result);
1214 }
1215 catch (jthrowable t)
1216 {
1217 env->ex = t;
1218 return NULL;
1219 }
8a922095
TT
1220}
1221
1222static jobject
7e648cf9 1223_Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
8a922095
TT
1224{
1225 jobject *elts = elements (array);
278abd28 1226 return wrap_value (env, elts[index]);
8a922095
TT
1227}
1228
1229static void
b099f07d 1230_Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index,
8a922095
TT
1231 jobject value)
1232{
b099f07d
TT
1233 try
1234 {
1235 _Jv_CheckArrayStore (array, value);
1236 jobject *elts = elements (array);
1237 elts[index] = value;
1238 }
1239 catch (jthrowable t)
1240 {
1241 env->ex = t;
1242 }
8a922095
TT
1243}
1244
1245template<typename T, jclass K>
1246static JArray<T> *
7e648cf9 1247_Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
8a922095 1248{
b099f07d
TT
1249 try
1250 {
1251 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1252 }
1253 catch (jthrowable t)
1254 {
1255 env->ex = t;
1256 return NULL;
1257 }
8a922095
TT
1258}
1259
1260template<typename T>
1261static T *
1262_Jv_JNI_GetPrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1263 jboolean *isCopy)
1264{
1265 T *elts = elements (array);
1266 if (isCopy)
1267 {
1268 // We elect never to copy.
1269 *isCopy = false;
1270 }
7e648cf9 1271 mark_for_gc (array);
8a922095
TT
1272 return elts;
1273}
1274
1275template<typename T>
1276static void
7e648cf9
TT
1277_Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1278 T *, jint /* mode */)
8a922095
TT
1279{
1280 // Note that we ignore MODE. We can do this because we never copy
1281 // the array elements. My reading of the JNI documentation is that
1282 // this is an option for the implementor.
7e648cf9 1283 unmark_for_gc (array);
8a922095
TT
1284}
1285
1286template<typename T>
1287static void
1288_Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1289 jsize start, jsize len,
1290 T *buf)
1291{
1292 if (start < 0 || len >= array->length || start + len >= array->length)
1293 {
b099f07d
TT
1294 try
1295 {
1296 // FIXME: index.
1297 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1298 }
1299 catch (jthrowable t)
1300 {
1301 // Could have thown out of memory error.
1302 env->ex = t;
1303 }
8a922095
TT
1304 }
1305 else
1306 {
1307 T *elts = elements (array) + start;
1308 memcpy (buf, elts, len * sizeof (T));
1309 }
1310}
1311
1312template<typename T>
1313static void
1314_Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1315 jsize start, jsize len, T *buf)
1316{
1317 if (start < 0 || len >= array->length || start + len >= array->length)
1318 {
b099f07d
TT
1319 try
1320 {
1321 // FIXME: index.
1322 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1323 }
1324 catch (jthrowable t)
1325 {
1326 env->ex = t;
1327 }
8a922095
TT
1328 }
1329 else
1330 {
1331 T *elts = elements (array) + start;
1332 memcpy (elts, buf, len * sizeof (T));
1333 }
1334}
1335
355dff4c
TT
1336static void *
1337_Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
1338 jboolean *isCopy)
1339{
1340 // FIXME: does this work?
1341 jclass klass = array->getClass()->getComponentType();
1342 JvAssert (klass->isPrimitive ());
1343 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1344 if (isCopy)
1345 *isCopy = false;
1346 return r;
1347}
1348
1349static void
1350_Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
1351{
1352 // Nothing.
1353}
1354
8a922095 1355static jint
b099f07d 1356_Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
8a922095 1357{
b099f07d
TT
1358 try
1359 {
1360 return _Jv_MonitorEnter (obj);
1361 }
1362 catch (jthrowable t)
1363 {
1364 env->ex = t;
1365 }
1366 return JNI_ERR;
8a922095
TT
1367}
1368
1369static jint
b099f07d 1370_Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
8a922095 1371{
b099f07d
TT
1372 try
1373 {
1374 return _Jv_MonitorExit (obj);
1375 }
1376 catch (jthrowable t)
1377 {
1378 env->ex = t;
1379 }
1380 return JNI_ERR;
8a922095
TT
1381}
1382
ee9dd372
TT
1383// JDK 1.2
1384jobject
7e648cf9 1385_Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
355dff4c 1386 jboolean)
ee9dd372 1387{
b099f07d
TT
1388 try
1389 {
1390 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1391 field->declaringClass = cls;
1392 field->offset = (char*) fieldID - (char *) cls->fields;
1393 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1394 return wrap_value (env, field);
1395 }
1396 catch (jthrowable t)
1397 {
1398 env->ex = t;
1399 }
1400 return NULL;
ee9dd372
TT
1401}
1402
1403// JDK 1.2
355dff4c
TT
1404static jfieldID
1405_Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
ee9dd372 1406{
355dff4c
TT
1407 using namespace java::lang::reflect;
1408
1409 Field *field = reinterpret_cast<Field *> (f);
ee9dd372
TT
1410 return _Jv_FromReflectedField (field);
1411}
1412
355dff4c 1413jobject
7e648cf9 1414_Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
355dff4c
TT
1415 jboolean)
1416{
1417 using namespace java::lang::reflect;
1418
1419 // FIXME.
1420 static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
1421
b099f07d
TT
1422 jobject result = NULL;
1423
1424 try
355dff4c 1425 {
b099f07d
TT
1426 if (_Jv_equalUtf8Consts (id->name, init_name))
1427 {
1428 // A constructor.
1429 Constructor *cons = new Constructor ();
1430 cons->offset = (char *) id - (char *) &klass->methods;
1431 cons->declaringClass = klass;
1432 result = cons;
1433 }
1434 else
1435 {
1436 Method *meth = new Method ();
1437 meth->offset = (char *) id - (char *) &klass->methods;
1438 meth->declaringClass = klass;
1439 result = meth;
1440 }
355dff4c 1441 }
b099f07d 1442 catch (jthrowable t)
355dff4c 1443 {
b099f07d 1444 env->ex = t;
355dff4c
TT
1445 }
1446
278abd28 1447 return wrap_value (env, result);
355dff4c
TT
1448}
1449
1450static jmethodID
1451_Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
1452{
1453 using namespace java::lang::reflect;
1454 if ((&MethodClass)->isInstance (method))
1455 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1456 return
1457 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1458}
1459
8ade4771
TT
1460static jint
1461_Jv_JNI_RegisterNatives (JNIEnv *env, jclass k,
1462 const JNINativeMethod *methods,
1463 jint nMethods)
1464{
ac52f669 1465#ifdef INTERPRETER
8ade4771
TT
1466 // For now, this only matters for interpreted methods. FIXME.
1467 if (! _Jv_IsInterpretedClass (k))
1468 {
1469 // FIXME: throw exception.
1470 return JNI_ERR;
1471 }
1472 _Jv_InterpClass *klass = reinterpret_cast<_Jv_InterpClass *> (k);
1473
1474 // Look at each descriptor given us, and find the corresponding
1475 // method in the class.
1476 for (int j = 0; j < nMethods; ++j)
1477 {
1478 bool found = false;
1479
1480 _Jv_MethodBase **imeths = _Jv_GetFirstMethod (klass);
1481 for (int i = 0; i < JvNumMethods (klass); ++i)
1482 {
1483 _Jv_MethodBase *meth = imeths[i];
1484 _Jv_Method *self = meth->get_method ();
1485
1486 if (! strcmp (self->name->data, methods[j].name)
1487 && ! strcmp (self->signature->data, methods[j].signature))
1488 {
1489 if (! (self->accflags
1490 & java::lang::reflect::Modifier::NATIVE))
1491 break;
1492
1493 // Found a match that is native.
1494 _Jv_JNIMethod *jmeth = reinterpret_cast<_Jv_JNIMethod *> (meth);
1495 jmeth->set_function (methods[i].fnPtr);
1496 found = true;
1497 break;
1498 }
1499 }
1500
1501 if (! found)
1502 {
1503 jstring m = JvNewStringUTF (methods[j].name);
b099f07d
TT
1504 try
1505 {
1506 env->ex =new java::lang::NoSuchMethodError (m);
1507 }
1508 catch (jthrowable t)
1509 {
1510 env->ex = t;
1511 }
8ade4771
TT
1512 return JNI_ERR;
1513 }
1514 }
1515
1516 return JNI_OK;
ac52f669
TT
1517#else /* INTERPRETER */
1518 return JNI_ERR;
1519#endif /* INTERPRETER */
8ade4771
TT
1520}
1521
1522static jint
1523_Jv_JNI_UnregisterNatives (JNIEnv *, jclass)
1524{
1525 return JNI_ERR;
1526}
1527
355dff4c
TT
1528\f
1529
f39b788a
TT
1530#ifdef INTERPRETER
1531
facc279f
TT
1532// Add a character to the buffer, encoding properly.
1533static void
1534add_char (char *buf, jchar c, int *here)
1535{
1536 if (c == '_')
1537 {
1538 buf[(*here)++] = '_';
1539 buf[(*here)++] = '1';
1540 }
1541 else if (c == ';')
1542 {
1543 buf[(*here)++] = '_';
1544 buf[(*here)++] = '2';
1545 }
1546 else if (c == '[')
1547 {
1548 buf[(*here)++] = '_';
1549 buf[(*here)++] = '3';
1550 }
1551 else if (c == '/')
1552 buf[(*here)++] = '_';
abfb7844 1553 else if ((c >= '0' && c <= '9')
facc279f
TT
1554 || (c >= 'a' && c <= 'z')
1555 || (c >= 'A' && c <= 'Z'))
1556 buf[(*here)++] = (char) c;
1557 else
1558 {
1559 // "Unicode" character.
1560 buf[(*here)++] = '_';
1561 buf[(*here)++] = '0';
1562 for (int i = 0; i < 4; ++i)
1563 {
1564 int val = c & 0x0f;
1565 buf[(*here) + 4 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
1566 c >>= 4;
1567 }
1568 *here += 4;
1569 }
1570}
1571
1572// Compute a mangled name for a native function. This computes the
1573// long name, and also returns an index which indicates where a NUL
1574// can be placed to create the short name. This function assumes that
1575// the buffer is large enough for its results.
1576static void
1577mangled_name (jclass klass, _Jv_Utf8Const *func_name,
1578 _Jv_Utf8Const *signature, char *buf, int *long_start)
1579{
1580 strcpy (buf, "Java_");
1581 int here = 5;
1582
1583 // Add fully qualified class name.
1584 jchar *chars = _Jv_GetStringChars (klass->getName ());
1585 jint len = klass->getName ()->length ();
1586 for (int i = 0; i < len; ++i)
1587 add_char (buf, chars[i], &here);
1588
1589 // Don't use add_char because we need a literal `_'.
1590 buf[here++] = '_';
1591
1592 const unsigned char *fn = (const unsigned char *) func_name->data;
1593 const unsigned char *limit = fn + func_name->length;
1594 for (int i = 0; ; ++i)
1595 {
1596 int ch = UTF8_GET (fn, limit);
1597 if (ch < 0)
1598 break;
1599 add_char (buf, ch, &here);
1600 }
1601
1602 // This is where the long signature begins.
1603 *long_start = here;
1604 buf[here++] = '_';
1605 buf[here++] = '_';
1606
1607 const unsigned char *sig = (const unsigned char *) signature->data;
1608 limit = sig + signature->length;
1609 JvAssert (signature[0] == '(');
cdd59e7b
TT
1610 ++sig;
1611 while (1)
facc279f
TT
1612 {
1613 int ch = UTF8_GET (sig, limit);
1614 if (ch == ')' || ch < 0)
1615 break;
1616 add_char (buf, ch, &here);
1617 }
1618
1619 buf[here] = '\0';
1620}
1621
8d00f617
TT
1622// Return the current thread's JNIEnv; if one does not exist, create
1623// it. Also create a new system frame for use. This is `extern "C"'
1624// because the compiler calls it.
1625extern "C" JNIEnv *
1626_Jv_GetJNIEnvNewFrame (jclass klass)
355dff4c 1627{
8d00f617
TT
1628 JNIEnv *env = _Jv_GetCurrentJNIEnv ();
1629 if (env == NULL)
1630 {
1631 env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
1632 env->p = &_Jv_JNIFunctions;
1633 env->ex = NULL;
1634 env->klass = klass;
1635 env->locals = NULL;
ee6713e7 1636
8d00f617
TT
1637 _Jv_SetCurrentJNIEnv (env);
1638 }
355dff4c 1639
8d00f617
TT
1640 _Jv_JNI_LocalFrame *frame
1641 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1642 + (FRAME_SIZE
1643 * sizeof (jobject)));
7e648cf9 1644
8d00f617 1645 frame->marker = MARK_SYSTEM;
7e648cf9 1646 frame->size = FRAME_SIZE;
8d00f617
TT
1647 frame->next = env->locals;
1648 env->locals = frame;
1649
7e648cf9
TT
1650 for (int i = 0; i < frame->size; ++i)
1651 frame->vec[i] = NULL;
355dff4c 1652
8d00f617
TT
1653 return env;
1654}
1655
1656// Return the function which implements a particular JNI method. If
1657// we can't find the function, we throw the appropriate exception.
1658// This is `extern "C"' because the compiler uses it.
1659extern "C" void *
1660_Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
1661 _Jv_Utf8Const *signature)
1662{
1663 char buf[10 + 6 * (name->length + signature->length)];
1664 int long_start;
1665 void *function;
1666
1667 mangled_name (klass, name, signature, buf, &long_start);
1668 char c = buf[long_start];
1669 buf[long_start] = '\0';
1670 function = _Jv_FindSymbolInExecutable (buf);
1671 if (function == NULL)
1672 {
1673 buf[long_start] = c;
1674 function = _Jv_FindSymbolInExecutable (buf);
1675 if (function == NULL)
1676 {
1677 jstring str = JvNewStringUTF (name->data);
1678 JvThrow (new java::lang::AbstractMethodError (str));
1679 }
1680 }
1681
1682 return function;
1683}
1684
1685// This function is the stub which is used to turn an ordinary (CNI)
1686// method call into a JNI call.
1687void
1688_Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
1689{
1690 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
1691
1692 JNIEnv *env = _Jv_GetJNIEnvNewFrame (_this->defining_class);
1693
ee6713e7
TT
1694 // FIXME: we should mark every reference parameter as a local. For
1695 // now we assume a conservative GC, and we assume that the
1696 // references are on the stack somewhere.
1697
facc279f
TT
1698 // We cache the value that we find, of course, but if we don't find
1699 // a value we don't cache that fact -- we might subsequently load a
1700 // library which finds the function in question.
1701 if (_this->function == NULL)
8d00f617
TT
1702 _this->function = _Jv_LookupJNIMethod (_this->defining_class,
1703 _this->self->name,
1704 _this->self->signature);
facc279f 1705
d348bda4
TT
1706 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
1707 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
1708 int offset = 0;
1709
1710 // First argument is always the environment pointer.
8d00f617 1711 real_args[offset++].ptr = env;
d348bda4
TT
1712
1713 // For a static method, we pass in the Class. For non-static
1714 // methods, the `this' argument is already handled.
1715 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
1716 real_args[offset++].ptr = _this->defining_class;
1717
1718 // Copy over passed-in arguments.
1719 memcpy (&real_args[offset], args, _this->args_raw_size);
1720
facc279f 1721 // The actual call to the JNI function.
d348bda4
TT
1722 ffi_raw_call (&_this->jni_cif, (void (*) (...)) _this->function,
1723 ret, real_args);
355dff4c 1724
8d00f617 1725 _Jv_JNI_PopSystemFrame (env);
7e648cf9 1726
8d00f617
TT
1727 if (env->ex)
1728 JvThrow (env->ex);
355dff4c 1729}
355dff4c 1730
f39b788a
TT
1731#endif /* INTERPRETER */
1732
355dff4c
TT
1733\f
1734
aaf0766e
TT
1735//
1736// Invocation API.
1737//
1738
1739// An internal helper function.
1740static jint
1741_Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
1742{
1743 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
1744 java::lang::ThreadGroup *group = NULL;
1745
1746 if (attach)
1747 {
1748 // FIXME: do we really want to support 1.1?
1749 if (attach->version != JNI_VERSION_1_2
1750 && attach->version != JNI_VERSION_1_1)
1751 return JNI_EVERSION;
1752
1753 JvAssert ((&ThreadGroupClass)->isInstance (attach->group));
1754 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
1755 }
1756
1757 // Attaching an already-attached thread is a no-op.
8ade4771 1758 if (_Jv_GetCurrentJNIEnv () != NULL)
aaf0766e
TT
1759 return 0;
1760
aaf0766e 1761 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2d759f71
TT
1762 if (env == NULL)
1763 return JNI_ERR;
aaf0766e
TT
1764 env->p = &_Jv_JNIFunctions;
1765 env->ex = NULL;
1766 env->klass = NULL;
aaf0766e
TT
1767 env->locals
1768 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1769 + (FRAME_SIZE
1770 * sizeof (jobject)));
2d759f71
TT
1771 if (env->locals == NULL)
1772 {
1773 _Jv_Free (env);
1774 return JNI_ERR;
1775 }
aaf0766e
TT
1776 *penv = reinterpret_cast<void *> (env);
1777
8ade4771
TT
1778 // This thread might already be a Java thread -- this function might
1779 // have been called simply to set the new JNIEnv.
1780 if (_Jv_ThreadCurrent () == NULL)
1781 {
b099f07d
TT
1782 try
1783 {
1784 (void) new gnu::gcj::jni::NativeThread (group, name);
1785 }
1786 catch (jthrowable t)
1787 {
1788 return JNI_ERR;
1789 }
8ade4771 1790 }
aaf0766e
TT
1791 _Jv_SetCurrentJNIEnv (env);
1792
1793 return 0;
1794}
1795
1796// This is the one actually used by JNI.
1797static jint
1798_Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
1799{
1800 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args);
1801}
1802
1803static jint
1804_Jv_JNI_DestroyJavaVM (JavaVM *vm)
1805{
1806 JvAssert (the_vm && vm == the_vm);
1807
1808 JNIEnv *env;
1809 if (_Jv_ThreadCurrent () != NULL)
1810 {
b099f07d
TT
1811 jstring main_name;
1812 // This sucks.
1813 try
1814 {
1815 main_name = JvNewStringLatin1 ("main");
1816 }
1817 catch (jthrowable t)
1818 {
1819 return JNI_ERR;
1820 }
1821
aaf0766e 1822 jint r = _Jv_JNI_AttachCurrentThread (vm,
b099f07d 1823 main_name,
aaf0766e
TT
1824 reinterpret_cast<void **> (&env),
1825 NULL);
1826 if (r < 0)
1827 return r;
1828 }
1829 else
1830 env = _Jv_GetCurrentJNIEnv ();
1831
1832 _Jv_ThreadWait ();
1833
1834 // Docs say that this always returns an error code.
1835 return JNI_ERR;
1836}
1837
1838static jint
1839_Jv_JNI_DetachCurrentThread (JavaVM *)
1840{
1841 java::lang::Thread *t = _Jv_ThreadCurrent ();
1842 if (t == NULL)
1843 return JNI_EDETACHED;
1844
1845 // FIXME: we only allow threads attached via AttachCurrentThread to
1846 // be detached. I have no idea how we could implement detaching
1847 // other threads, given the requirement that we must release all the
1848 // monitors. That just seems evil.
1849 JvAssert ((&NativeThreadClass)->isInstance (t));
1850
1851 // FIXME: release the monitors. We'll take this to mean all
1852 // monitors acquired via the JNI interface. This means we have to
1853 // keep track of them.
1854
1855 gnu::gcj::jni::NativeThread *nt
1856 = reinterpret_cast<gnu::gcj::jni::NativeThread *> (t);
1857 nt->finish ();
1858
1859 return 0;
1860}
1861
1862static jint
1863_Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
1864{
1865 if (_Jv_ThreadCurrent () == NULL)
1866 {
1867 *penv = NULL;
1868 return JNI_EDETACHED;
1869 }
1870
1871 // FIXME: do we really want to support 1.1?
1872 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_1)
1873 {
1874 *penv = NULL;
1875 return JNI_EVERSION;
1876 }
1877
1878 *penv = (void *) _Jv_GetCurrentJNIEnv ();
1879 return 0;
1880}
1881
1882jint
1883JNI_GetDefaultJavaVMInitArgs (void *args)
1884{
1885 jint version = * (jint *) args;
1886 // Here we only support 1.2.
1887 if (version != JNI_VERSION_1_2)
1888 return JNI_EVERSION;
1889
1890 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1891 ia->version = JNI_VERSION_1_2;
1892 ia->nOptions = 0;
1893 ia->options = NULL;
1894 ia->ignoreUnrecognized = true;
1895
1896 return 0;
1897}
1898
1899jint
1900JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
1901{
1902 JvAssert (! the_vm);
1903 // FIXME: synchronize
1904 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
1905 if (nvm == NULL)
1906 return JNI_ERR;
1907 nvm->functions = &_Jv_JNI_InvokeFunctions;
1908
1909 // Parse the arguments.
1910 if (args != NULL)
1911 {
1912 jint version = * (jint *) args;
1913 // We only support 1.2.
1914 if (version != JNI_VERSION_1_2)
1915 return JNI_EVERSION;
1916 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1917 for (int i = 0; i < ia->nOptions; ++i)
1918 {
1919 if (! strcmp (ia->options[i].optionString, "vfprintf")
1920 || ! strcmp (ia->options[i].optionString, "exit")
1921 || ! strcmp (ia->options[i].optionString, "abort"))
1922 {
1923 // We are required to recognize these, but for now we
1924 // don't handle them in any way. FIXME.
1925 continue;
1926 }
1927 else if (! strncmp (ia->options[i].optionString,
1928 "-verbose", sizeof ("-verbose") - 1))
1929 {
1930 // We don't do anything with this option either. We
1931 // might want to make sure the argument is valid, but we
1932 // don't really care all that much for now.
1933 continue;
1934 }
1935 else if (! strncmp (ia->options[i].optionString, "-D", 2))
1936 {
1937 // FIXME.
1938 continue;
1939 }
1940 else if (ia->ignoreUnrecognized)
1941 {
1942 if (ia->options[i].optionString[0] == '_'
1943 || ! strncmp (ia->options[i].optionString, "-X", 2))
1944 continue;
1945 }
1946
1947 return JNI_ERR;
1948 }
1949 }
1950
1951 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
1952 if (r < 0)
1953 return r;
1954
1955 the_vm = nvm;
1956 *vm = the_vm;
1957 return 0;
1958}
1959
1960jint
e1b15113 1961JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize /* buf_len */, jsize *n_vms)
aaf0766e
TT
1962{
1963 JvAssert (buf_len > 0);
1964 // We only support a single VM.
1965 if (the_vm != NULL)
1966 {
1967 vm_buffer[0] = the_vm;
1968 *n_vms = 1;
1969 }
1970 else
1971 *n_vms = 0;
1972 return 0;
1973}
1974
8ade4771
TT
1975JavaVM *
1976_Jv_GetJavaVM ()
aaf0766e
TT
1977{
1978 // FIXME: synchronize
1979 if (! the_vm)
1980 {
1981 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
8ade4771
TT
1982 if (nvm != NULL)
1983 nvm->functions = &_Jv_JNI_InvokeFunctions;
aaf0766e
TT
1984 the_vm = nvm;
1985 }
1986
8ade4771
TT
1987 // If this is a Java thread, we want to make sure it has an
1988 // associated JNIEnv.
1989 if (_Jv_ThreadCurrent () != NULL)
1990 {
1991 void *ignore;
1992 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
1993 }
1994
1995 return the_vm;
1996}
1997
1998static jint
1999_Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm)
2000{
2001 *vm = _Jv_GetJavaVM ();
2002 return *vm == NULL ? JNI_ERR : JNI_OK;
aaf0766e
TT
2003}
2004
2005\f
2006
ee9dd372 2007#define NOT_IMPL NULL
8a922095 2008#define RESERVED NULL
ee9dd372
TT
2009
2010struct JNINativeInterface _Jv_JNIFunctions =
2011{
8a922095
TT
2012 RESERVED,
2013 RESERVED,
2014 RESERVED,
2015 RESERVED,
2016 _Jv_JNI_GetVersion,
355dff4c
TT
2017 _Jv_JNI_DefineClass,
2018 _Jv_JNI_FindClass,
2019 _Jv_JNI_FromReflectedMethod,
2020 _Jv_JNI_FromReflectedField,
2021 _Jv_JNI_ToReflectedMethod,
ee9dd372 2022 _Jv_JNI_GetSuperclass,
355dff4c
TT
2023 _Jv_JNI_IsAssignableFrom,
2024 _Jv_JNI_ToReflectedField,
8a922095
TT
2025 _Jv_JNI_Throw,
2026 _Jv_JNI_ThrowNew,
2027 _Jv_JNI_ExceptionOccurred,
2028 _Jv_JNI_ExceptionDescribe,
2029 _Jv_JNI_ExceptionClear,
2030 _Jv_JNI_FatalError,
7e648cf9
TT
2031
2032 _Jv_JNI_PushLocalFrame,
2033 _Jv_JNI_PopLocalFrame,
2034 _Jv_JNI_NewGlobalRef,
2035 _Jv_JNI_DeleteGlobalRef,
2036 _Jv_JNI_DeleteLocalRef,
2037
8a922095 2038 _Jv_JNI_IsSameObject,
7e648cf9
TT
2039
2040 _Jv_JNI_NewLocalRef,
2041 _Jv_JNI_EnsureLocalCapacity,
2042
8a922095
TT
2043 _Jv_JNI_AllocObject,
2044 _Jv_JNI_NewObject,
2045 _Jv_JNI_NewObjectV,
2046 _Jv_JNI_NewObjectA,
2047 _Jv_JNI_GetObjectClass,
2048 _Jv_JNI_IsInstanceOf,
2049 _Jv_JNI_GetAnyMethodID<false>,
2050
2051 _Jv_JNI_CallMethod<jobject>,
2052 _Jv_JNI_CallMethodV<jobject>,
2053 _Jv_JNI_CallMethodA<jobject>,
2054 _Jv_JNI_CallMethod<jboolean>,
2055 _Jv_JNI_CallMethodV<jboolean>,
2056 _Jv_JNI_CallMethodA<jboolean>,
2057 _Jv_JNI_CallMethod<jbyte>,
2058 _Jv_JNI_CallMethodV<jbyte>,
2059 _Jv_JNI_CallMethodA<jbyte>,
2060 _Jv_JNI_CallMethod<jchar>,
2061 _Jv_JNI_CallMethodV<jchar>,
2062 _Jv_JNI_CallMethodA<jchar>,
2063 _Jv_JNI_CallMethod<jshort>,
2064 _Jv_JNI_CallMethodV<jshort>,
2065 _Jv_JNI_CallMethodA<jshort>,
2066 _Jv_JNI_CallMethod<jint>,
2067 _Jv_JNI_CallMethodV<jint>,
2068 _Jv_JNI_CallMethodA<jint>,
2069 _Jv_JNI_CallMethod<jlong>,
2070 _Jv_JNI_CallMethodV<jlong>,
2071 _Jv_JNI_CallMethodA<jlong>,
2072 _Jv_JNI_CallMethod<jfloat>,
2073 _Jv_JNI_CallMethodV<jfloat>,
2074 _Jv_JNI_CallMethodA<jfloat>,
2075 _Jv_JNI_CallMethod<jdouble>,
2076 _Jv_JNI_CallMethodV<jdouble>,
2077 _Jv_JNI_CallMethodA<jdouble>,
2078 _Jv_JNI_CallVoidMethod,
2079 _Jv_JNI_CallVoidMethodV,
2080 _Jv_JNI_CallVoidMethodA,
2081
2082 // Nonvirtual method invocation functions follow.
2083 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>,
2084 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>,
2085 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>,
2086 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>,
2087 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>,
2088 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>,
2089 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>,
2090 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>,
2091 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>,
2092 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>,
2093 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>,
2094 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>,
2095 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>,
2096 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>,
2097 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>,
2098 _Jv_JNI_CallAnyMethod<jint, nonvirtual>,
2099 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>,
2100 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>,
2101 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>,
2102 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>,
2103 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>,
2104 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>,
2105 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>,
2106 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>,
2107 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>,
2108 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>,
2109 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>,
2110 _Jv_JNI_CallAnyVoidMethod<nonvirtual>,
2111 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>,
2112 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>,
2113
2114 _Jv_JNI_GetAnyFieldID<false>,
2115 _Jv_JNI_GetField<jobject>,
2116 _Jv_JNI_GetField<jboolean>,
2117 _Jv_JNI_GetField<jbyte>,
2118 _Jv_JNI_GetField<jchar>,
2119 _Jv_JNI_GetField<jshort>,
2120 _Jv_JNI_GetField<jint>,
2121 _Jv_JNI_GetField<jlong>,
2122 _Jv_JNI_GetField<jfloat>,
2123 _Jv_JNI_GetField<jdouble>,
2124 _Jv_JNI_SetField,
2125 _Jv_JNI_SetField,
2126 _Jv_JNI_SetField,
2127 _Jv_JNI_SetField,
2128 _Jv_JNI_SetField,
2129 _Jv_JNI_SetField,
2130 _Jv_JNI_SetField,
2131 _Jv_JNI_SetField,
2132 _Jv_JNI_SetField,
2133 _Jv_JNI_GetAnyMethodID<true>,
2134
2135 _Jv_JNI_CallStaticMethod<jobject>,
2136 _Jv_JNI_CallStaticMethodV<jobject>,
2137 _Jv_JNI_CallStaticMethodA<jobject>,
2138 _Jv_JNI_CallStaticMethod<jboolean>,
2139 _Jv_JNI_CallStaticMethodV<jboolean>,
2140 _Jv_JNI_CallStaticMethodA<jboolean>,
2141 _Jv_JNI_CallStaticMethod<jbyte>,
2142 _Jv_JNI_CallStaticMethodV<jbyte>,
2143 _Jv_JNI_CallStaticMethodA<jbyte>,
2144 _Jv_JNI_CallStaticMethod<jchar>,
2145 _Jv_JNI_CallStaticMethodV<jchar>,
2146 _Jv_JNI_CallStaticMethodA<jchar>,
2147 _Jv_JNI_CallStaticMethod<jshort>,
2148 _Jv_JNI_CallStaticMethodV<jshort>,
2149 _Jv_JNI_CallStaticMethodA<jshort>,
2150 _Jv_JNI_CallStaticMethod<jint>,
2151 _Jv_JNI_CallStaticMethodV<jint>,
2152 _Jv_JNI_CallStaticMethodA<jint>,
2153 _Jv_JNI_CallStaticMethod<jlong>,
2154 _Jv_JNI_CallStaticMethodV<jlong>,
2155 _Jv_JNI_CallStaticMethodA<jlong>,
2156 _Jv_JNI_CallStaticMethod<jfloat>,
2157 _Jv_JNI_CallStaticMethodV<jfloat>,
2158 _Jv_JNI_CallStaticMethodA<jfloat>,
2159 _Jv_JNI_CallStaticMethod<jdouble>,
2160 _Jv_JNI_CallStaticMethodV<jdouble>,
2161 _Jv_JNI_CallStaticMethodA<jdouble>,
2162 _Jv_JNI_CallStaticVoidMethod,
2163 _Jv_JNI_CallStaticVoidMethodV,
2164 _Jv_JNI_CallStaticVoidMethodA,
2165
2166 _Jv_JNI_GetAnyFieldID<true>,
2167 _Jv_JNI_GetStaticField<jobject>,
2168 _Jv_JNI_GetStaticField<jboolean>,
2169 _Jv_JNI_GetStaticField<jbyte>,
2170 _Jv_JNI_GetStaticField<jchar>,
2171 _Jv_JNI_GetStaticField<jshort>,
2172 _Jv_JNI_GetStaticField<jint>,
2173 _Jv_JNI_GetStaticField<jlong>,
2174 _Jv_JNI_GetStaticField<jfloat>,
2175 _Jv_JNI_GetStaticField<jdouble>,
2176 _Jv_JNI_SetStaticField,
2177 _Jv_JNI_SetStaticField,
2178 _Jv_JNI_SetStaticField,
2179 _Jv_JNI_SetStaticField,
2180 _Jv_JNI_SetStaticField,
2181 _Jv_JNI_SetStaticField,
2182 _Jv_JNI_SetStaticField,
2183 _Jv_JNI_SetStaticField,
2184 _Jv_JNI_SetStaticField,
2185 _Jv_JNI_NewString,
ee9dd372 2186 _Jv_JNI_GetStringLength,
8a922095
TT
2187 _Jv_JNI_GetStringChars,
2188 _Jv_JNI_ReleaseStringChars,
2189 _Jv_JNI_NewStringUTF,
2190 _Jv_JNI_GetStringUTFLength,
2191 _Jv_JNI_GetStringUTFChars,
2192 _Jv_JNI_ReleaseStringUTFChars,
2193 _Jv_JNI_GetArrayLength,
2194 _Jv_JNI_NewObjectArray,
2195 _Jv_JNI_GetObjectArrayElement,
2196 _Jv_JNI_SetObjectArrayElement,
2197 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2198 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>,
2199 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>,
2200 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>,
2201 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>,
2202 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>,
2203 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>,
2204 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>,
2205 _Jv_JNI_GetPrimitiveArrayElements,
2206 _Jv_JNI_GetPrimitiveArrayElements,
2207 _Jv_JNI_GetPrimitiveArrayElements,
2208 _Jv_JNI_GetPrimitiveArrayElements,
2209 _Jv_JNI_GetPrimitiveArrayElements,
2210 _Jv_JNI_GetPrimitiveArrayElements,
2211 _Jv_JNI_GetPrimitiveArrayElements,
2212 _Jv_JNI_GetPrimitiveArrayElements,
2213 _Jv_JNI_ReleasePrimitiveArrayElements,
2214 _Jv_JNI_ReleasePrimitiveArrayElements,
2215 _Jv_JNI_ReleasePrimitiveArrayElements,
2216 _Jv_JNI_ReleasePrimitiveArrayElements,
2217 _Jv_JNI_ReleasePrimitiveArrayElements,
2218 _Jv_JNI_ReleasePrimitiveArrayElements,
2219 _Jv_JNI_ReleasePrimitiveArrayElements,
2220 _Jv_JNI_ReleasePrimitiveArrayElements,
2221 _Jv_JNI_GetPrimitiveArrayRegion,
2222 _Jv_JNI_GetPrimitiveArrayRegion,
2223 _Jv_JNI_GetPrimitiveArrayRegion,
2224 _Jv_JNI_GetPrimitiveArrayRegion,
2225 _Jv_JNI_GetPrimitiveArrayRegion,
2226 _Jv_JNI_GetPrimitiveArrayRegion,
2227 _Jv_JNI_GetPrimitiveArrayRegion,
2228 _Jv_JNI_GetPrimitiveArrayRegion,
2229 _Jv_JNI_SetPrimitiveArrayRegion,
2230 _Jv_JNI_SetPrimitiveArrayRegion,
2231 _Jv_JNI_SetPrimitiveArrayRegion,
2232 _Jv_JNI_SetPrimitiveArrayRegion,
2233 _Jv_JNI_SetPrimitiveArrayRegion,
2234 _Jv_JNI_SetPrimitiveArrayRegion,
2235 _Jv_JNI_SetPrimitiveArrayRegion,
2236 _Jv_JNI_SetPrimitiveArrayRegion,
8ade4771
TT
2237 _Jv_JNI_RegisterNatives,
2238 _Jv_JNI_UnregisterNatives,
8a922095
TT
2239 _Jv_JNI_MonitorEnter,
2240 _Jv_JNI_MonitorExit,
aaf0766e 2241 _Jv_JNI_GetJavaVM,
355dff4c
TT
2242
2243 _Jv_JNI_GetStringRegion,
2244 _Jv_JNI_GetStringUTFRegion,
2245 _Jv_JNI_GetPrimitiveArrayCritical,
2246 _Jv_JNI_ReleasePrimitiveArrayCritical,
2247 _Jv_JNI_GetStringCritical,
2248 _Jv_JNI_ReleaseStringCritical,
2249
2250 NOT_IMPL /* newweakglobalref */,
2251 NOT_IMPL /* deleteweakglobalref */,
2252
2253 _Jv_JNI_ExceptionCheck
ee9dd372 2254};
aaf0766e
TT
2255
2256struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2257{
2258 RESERVED,
2259 RESERVED,
2260 RESERVED,
2261
2262 _Jv_JNI_DestroyJavaVM,
2263 _Jv_JNI_AttachCurrentThread,
2264 _Jv_JNI_DetachCurrentThread,
2265 _Jv_JNI_GetEnv
2266};
This page took 0.325588 seconds and 5 git commands to generate.