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