summaryrefslogtreecommitdiff
path: root/libjava/jni.cc
blob: ff8f9a23fb2372eb1a7033eea9fde6e4550b867f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
// jni.cc - JNI implementation, including the jump table.

/* Copyright (C) 1998, 1999, 2000  Red Hat, Inc.

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

// Note: currently we take the approach of not checking most
// arguments.  Instead we could do more checking conditionally (e.g.,
// if DEBUG is defined).  That might be beneficial in some cases,
// though to me it seems that one could just as easily use the
// debugger.

#include <config.h>

#include <stddef.h>
#include <string.h>

// Define this before including jni.h.
#define __GCJ_JNI_IMPL__

#include <gcj/cni.h>
#include <jvm.h>
#include <java-assert.h>
#include <jni.h>

#include <java/lang/Class.h>
#include <java/lang/ClassLoader.h>
#include <java/lang/Throwable.h>
#include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/StringIndexOutOfBoundsException.h>
#include <java/lang/InstantiationException.h>
#include <java/lang/NoSuchFieldError.h>
#include <java/lang/NoSuchMethodError.h>
#include <java/lang/reflect/Constructor.h>
#include <java/lang/reflect/Method.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/OutOfMemoryError.h>
#include <java/util/Hashtable.h>
#include <java/lang/Integer.h>

#include <gcj/method.h>
#include <gcj/field.h>

#define ClassClass _CL_Q34java4lang5Class
extern java::lang::Class ClassClass;
#define ObjectClass _CL_Q34java4lang6Object
extern java::lang::Class ObjectClass;

#define MethodClass _CL_Q44java4lang7reflect6Method
extern java::lang::Class MethodClass;

// This enum is used to select different template instantiations in
// the invocation code.
enum invocation_type
{
  normal,
  nonvirtual,
  static_type,
  constructor
};

// Forward declaration.
extern struct JNINativeInterface _Jv_JNIFunctions;

// Number of slots in the default frame.  The VM must allow at least
// 16.
#define FRAME_SIZE 32

// This structure is used to keep track of local references.
struct _Jv_JNI_LocalFrame
{
  // This is true if this frame object represents a pushed frame (eg
  // from PushLocalFrame).
  int marker :  1;

  // Number of elements in frame.
  int size   : 31;

  // Next frame in chain.
  _Jv_JNI_LocalFrame *next;

  // The elements.  These are allocated using the C "struct hack".
  jobject vec[0];
};

// This holds a reference count for all local and global references.
static java::util::Hashtable *ref_table;



void
_Jv_JNI_Init (void)
{
  ref_table = new java::util::Hashtable;
}

// Tell the GC that a certain pointer is live.
static void
mark_for_gc (jobject obj)
{
  JvSynchronize sync (ref_table);

  using namespace java::lang;
  Integer *refcount = (Integer *) ref_table->get (obj);
  jint val = (refcount == NULL) ? 0 : refcount->intValue ();
  ref_table->put (obj, new Integer (val + 1));
}

// Unmark a pointer.
static void
unmark_for_gc (jobject obj)
{
  JvSynchronize sync (ref_table);

  using namespace java::lang;
  Integer *refcount = (Integer *) ref_table->get (obj);
  JvAssert (refcount);
  jint val = refcount->intValue () - 1;
  if (val == 0)
    ref_table->remove (obj);
  else
    ref_table->put (obj, new Integer (val));
}



static jobject
_Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
{
  mark_for_gc (obj);
  return obj;
}

static void
_Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
{
  unmark_for_gc (obj);
}

static void
_Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
{
  _Jv_JNI_LocalFrame *frame;

  for (frame = env->locals; frame != NULL; frame = frame->next)
    {
      for (int i = 0; i < FRAME_SIZE; ++i)
	{
	  if (frame->vec[i] == obj)
	    {
	      frame->vec[i] = NULL;
	      unmark_for_gc (obj);
	      return;
	    }
	}

      // Don't go past a marked frame.
      JvAssert (! frame->marker);
    }

  JvAssert (0);
}

static jint
_Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
{
  // It is easier to just always allocate a new frame of the requested
  // size.  This isn't the most efficient thing, but for now we don't
  // care.  Note that _Jv_JNI_PushLocalFrame relies on this right now.

  _Jv_JNI_LocalFrame *frame
    = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
						  + size * sizeof (jobject));
  if (frame == NULL)
    {
      // FIXME: exception processing.
      env->ex = new java::lang::OutOfMemoryError;
      return -1;
    }

  frame->marker = true;
  frame->size = size;
  memset (&frame->vec[0], 0, size * sizeof (jobject));
  frame->next = env->locals;
  env->locals = frame;

  return 0;
}

static jint
_Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
{
  jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
  if (r < 0)
    return r;

  // The new frame is on top.
  env->locals->marker = true;

  return 0;
}

static jobject
_Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
{
  // Try to find an open slot somewhere in the topmost frame.
  _Jv_JNI_LocalFrame *frame = env->locals;
  bool done = false, set = false;
  while (frame != NULL && ! done)
    {
      for (int i = 0; i < frame->size; ++i)
	if (frame->vec[i] == NULL)
	  {
	    set = true;
	    done = true;
	    frame->vec[i] = obj;
	    break;
	  }
    }

  if (! set)
    {
      // No slots, so we allocate a new frame.  According to the spec
      // we could just die here.  FIXME: return value.
      _Jv_JNI_EnsureLocalCapacity (env, 16);
      // We know the first element of the new frame will be ok.
      env->locals->vec[0] = obj;
    }

  mark_for_gc (obj);
  return obj;
}

static jobject
_Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
{
  _Jv_JNI_LocalFrame *rf = env->locals;

  bool done = false;
  while (rf != NULL && ! done)
    {  
      for (int i = 0; i < rf->size; ++i)
	if (rf->vec[i] != NULL)
	  unmark_for_gc (rf->vec[i]);

      // If the frame we just freed is the marker frame, we are done.
      done = rf->marker;

      _Jv_JNI_LocalFrame *n = rf->next;
      // When N==NULL, we've reached the stack-allocated frame, and we
      // must not free it.  However, we must be sure to clear all its
      // elements, since we might conceivably reuse it.
      if (n == NULL)
	memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
      else
	_Jv_Free (rf);
      rf = n;
    }

  return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
}



static jint
_Jv_JNI_GetVersion (JNIEnv *)
{
  return JNI_VERSION_1_2;
}

static jclass
_Jv_JNI_DefineClass (JNIEnv *env, jobject loader, 
		     const jbyte *buf, jsize bufLen)
{
  jbyteArray bytes = JvNewByteArray (bufLen);
  jbyte *elts = elements (bytes);
  memcpy (elts, buf, bufLen * sizeof (jbyte));

  java::lang::ClassLoader *l
    = reinterpret_cast<java::lang::ClassLoader *> (loader);

  // FIXME: exception processing.
  jclass result = l->defineClass (bytes, 0, bufLen);
  return (jclass) _Jv_JNI_NewLocalRef (env, result);
}

static jclass
_Jv_JNI_FindClass (JNIEnv *env, const char *name)
{
  // FIXME: assume that NAME isn't too long.
  int len = strlen (name);
  char s[len + 1];
  for (int i = 0; i <= len; ++i)
    s[i] = (name[i] == '/') ? '.' : name[i];
  jstring n = JvNewStringUTF (s);

  java::lang::ClassLoader *loader;
  if (env->klass == NULL)
    {
      // FIXME: should use getBaseClassLoader, but we don't have that
      // yet.
      loader = java::lang::ClassLoader::getSystemClassLoader ();
    }
  else
    loader = env->klass->getClassLoader ();

  // FIXME: exception processing.
  jclass r = loader->findClass (n);

  return (jclass) _Jv_JNI_NewLocalRef (env, r);
}

static jclass
_Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
{
  return (jclass) _Jv_JNI_NewLocalRef (env, clazz->getSuperclass ());
}

static jboolean
_Jv_JNI_IsAssignableFrom(JNIEnv *, jclass clazz1, jclass clazz2)
{
  return clazz1->isAssignableFrom (clazz2);
}

static jint
_Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
{
  env->ex = obj;
  return 0;
}

static jint
_Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
{
  using namespace java::lang::reflect;

  JArray<jclass> *argtypes
    = (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL);

  jclass *elts = elements (argtypes);
  elts[0] = &StringClass;

  // FIXME: exception processing.
  Constructor *cons = clazz->getConstructor (argtypes);

  jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
  jobject *velts = elements (values);
  velts[0] = JvNewStringUTF (message);

  // FIXME: exception processing.
  jobject obj = cons->newInstance (values);

  env->ex = reinterpret_cast<jthrowable> (obj);
  return 0;
}

static jthrowable
_Jv_JNI_ExceptionOccurred (JNIEnv *env)
{
  return (jthrowable) _Jv_JNI_NewLocalRef (env, env->ex);
}

static void
_Jv_JNI_ExceptionDescribe (JNIEnv *env)
{
  if (env->ex != NULL)
    env->ex->printStackTrace();
}

static void
_Jv_JNI_ExceptionClear (JNIEnv *env)
{
  env->ex = NULL;
}

static jboolean
_Jv_JNI_ExceptionCheck (JNIEnv *env)
{
  return env->ex != NULL;
}

static void
_Jv_JNI_FatalError (JNIEnv *, const char *message)
{
  JvFail (message);
}



static jboolean
_Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
{
  return obj1 == obj2;
}

static jobject
_Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
{
  jobject obj = NULL;
  using namespace java::lang::reflect;
  if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
    env->ex = new java::lang::InstantiationException ();
  else
    {
      // FIXME: exception processing.
      // FIXME: will this work for String?
      obj = JvAllocObject (clazz);
    }

  return _Jv_JNI_NewLocalRef (env, obj);
}

static jclass
_Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
{
  return (jclass) _Jv_JNI_NewLocalRef (env, obj->getClass());
}

static jboolean
_Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
{
  return clazz->isInstance(obj);
}



//
// This section concerns method invocation.
//

template<jboolean is_static>
static jmethodID
_Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
			const char *name, const char *sig)
{
  // FIXME: exception processing.
  _Jv_InitClass (clazz);

  _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
  _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);

  JvAssert (! clazz->isPrimitive());

  using namespace java::lang::reflect;

  while (clazz != NULL)
    {
      jint count = JvNumMethods (clazz);
      jmethodID meth = JvGetFirstMethod (clazz);

      for (jint i = 0; i < count; ++i)
	{
	  if (((is_static && Modifier::isStatic (meth->accflags))
	       || (! is_static && ! Modifier::isStatic (meth->accflags)))
	      && _Jv_equalUtf8Consts (meth->name, name_u)
	      && _Jv_equalUtf8Consts (meth->signature, sig_u))
	    return meth;

	  meth = meth->getNextMethod();
	}

      clazz = clazz->getSuperclass ();
    }

  env->ex = new java::lang::NoSuchMethodError ();
  return NULL;
}

// This is a helper function which turns a va_list into an array of
// `jvalue's.  It needs signature information in order to do its work.
// The array of values must already be allocated.
static void
array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
{
  jclass *arg_elts = elements (arg_types);
  for (int i = 0; i < arg_types->length; ++i)
    {
      if (arg_elts[i] == JvPrimClass (byte))
	values[i].b = va_arg (vargs, jbyte);
      else if (arg_elts[i] == JvPrimClass (short))
	values[i].s = va_arg (vargs, jshort);
      else if (arg_elts[i] == JvPrimClass (int))
	values[i].i = va_arg (vargs, jint);
      else if (arg_elts[i] == JvPrimClass (long))
	values[i].j = va_arg (vargs, jlong);
      else if (arg_elts[i] == JvPrimClass (float))
	values[i].f = va_arg (vargs, jfloat);
      else if (arg_elts[i] == JvPrimClass (double))
	values[i].d = va_arg (vargs, jdouble);
      else if (arg_elts[i] == JvPrimClass (boolean))
	values[i].z = va_arg (vargs, jboolean);
      else if (arg_elts[i] == JvPrimClass (char))
	values[i].c = va_arg (vargs, jchar);
      else
	{
	  // An object.
	  values[i].l = va_arg (vargs, jobject);
	}
    }
}

// This can call any sort of method: virtual, "nonvirtual", static, or
// constructor.
template<typename T, invocation_type style>
static T
_Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
			jmethodID id, va_list vargs)
{
  if (style == normal)
    id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);

  jclass decl_class = klass ? klass : obj->getClass ();
  JvAssert (decl_class != NULL);

  jclass return_type;
  JArray<jclass> *arg_types;
  // FIXME: exception processing.
  _Jv_GetTypesFromSignature (id, decl_class,
			     &arg_types, &return_type);

  jvalue args[arg_types->length];
  array_from_valist (args, arg_types, vargs);

  jvalue result;
  jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
				      style == constructor,
				      arg_types, args, &result);

  if (ex != NULL)
    env->ex = ex;

  if (! return_type->isPrimitive ())
    {
      // Make sure we create a local reference.  The cast hackery is
      // to avoid problems for template instantations we know won't be
      // used.
      return (T) (long long) _Jv_JNI_NewLocalRef (env, result.l);
    }

  // We cheat a little here.  FIXME.
  return * (T *) &result;
}

template<typename T, invocation_type style>
static T
_Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
		       jmethodID method, ...)
{
  va_list args;
  T result;

  va_start (args, method);
  result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
  va_end (args);

  return result;
}

template<typename T, invocation_type style>
static T
_Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
			jmethodID id, jvalue *args)
{
  if (style == normal)
    id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);

  jclass decl_class = klass ? klass : obj->getClass ();
  JvAssert (decl_class != NULL);

  jclass return_type;
  JArray<jclass> *arg_types;
  // FIXME: exception processing.
  _Jv_GetTypesFromSignature (id, decl_class,
			     &arg_types, &return_type);

  jvalue result;
  jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
				      style == constructor,
				      arg_types, args, &result);

  if (ex != NULL)
    env->ex = ex;

  if (! return_type->isPrimitive ())
    {
      // Make sure we create a local reference.  The cast hackery is
      // to avoid problems for template instantations we know won't be
      // used.
      return (T) (long long) _Jv_JNI_NewLocalRef (env, result.l);
    }

  // We cheat a little here.  FIXME.
  return * (T *) &result;
}

template<invocation_type style>
static void
_Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
			    jmethodID id, va_list vargs)
{
  if (style == normal)
    id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);

  jclass decl_class = klass ? klass : obj->getClass ();
  JvAssert (decl_class != NULL);

  jclass return_type;
  JArray<jclass> *arg_types;
  // FIXME: exception processing.
  _Jv_GetTypesFromSignature (id, decl_class,
			     &arg_types, &return_type);

  jvalue args[arg_types->length];
  array_from_valist (args, arg_types, vargs);

  jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
				      style == constructor,
				      arg_types, args, NULL);

  if (ex != NULL)
    env->ex = ex;
}

template<invocation_type style>
static void
_Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
			   jmethodID method, ...)
{
  va_list args;

  va_start (args, method);
  _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
  va_end (args);
}

template<invocation_type style>
static void
_Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
			    jmethodID id, jvalue *args)
{
  if (style == normal)
    id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);

  jclass decl_class = klass ? klass : obj->getClass ();
  JvAssert (decl_class != NULL);

  jclass return_type;
  JArray<jclass> *arg_types;
  // FIXME: exception processing.
  _Jv_GetTypesFromSignature (id, decl_class,
			     &arg_types, &return_type);

  jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
				      style == constructor,
				      arg_types, args, NULL);

  if (ex != NULL)
    env->ex = ex;
}

// Functions with this signature are used to implement functions in
// the CallMethod family.
template<typename T>
static T
_Jv_JNI_CallMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
{
  return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
}

// Functions with this signature are used to implement functions in
// the CallMethod family.
template<typename T>
static T
_Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
{
  va_list args;
  T result;

  va_start (args, id);
  result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
  va_end (args);

  return result;
}

// Functions with this signature are used to implement functions in
// the CallMethod family.
template<typename T>
static T
_Jv_JNI_CallMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
{
  return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
}

static void
_Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
{
  _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
}

static void
_Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
{
  va_list args;

  va_start (args, id);
  _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
  va_end (args);
}

static void
_Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
{
  _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
}

// Functions with this signature are used to implement functions in
// the CallStaticMethod family.
template<typename T>
static T
_Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
			   jmethodID id, va_list args)
{
  return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
}

// Functions with this signature are used to implement functions in
// the CallStaticMethod family.
template<typename T>
static T
_Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
{
  va_list args;
  T result;

  va_start (args, id);
  result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
						   id, args);
  va_end (args);

  return result;
}

// Functions with this signature are used to implement functions in
// the CallStaticMethod family.
template<typename T>
static T
_Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
			   jvalue *args)
{
  return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
}

static void
_Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass, jmethodID id,
			       va_list args)
{
  _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
}

static void
_Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
{
  va_list args;

  va_start (args, id);
  _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
  va_end (args);
}

static void
_Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass, jmethodID id,
			       jvalue *args)
{
  _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
}

static jobject
_Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
		    jmethodID id, va_list args)
{
  return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
						       id, args);
}

static jobject
_Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
{
  va_list args;
  jobject result;

  va_start (args, id);
  result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
							 id, args);
  va_end (args);

  return result;
}

static jobject
_Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
		    jvalue *args)
{
  return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
						       id, args);
}



template<typename T>
static T
_Jv_JNI_GetField (JNIEnv *, jobject obj, jfieldID field) 
{
  T *ptr = (T *) ((char *) obj + field->getOffset ());
  return *ptr;
}

template<>
static jobject
_Jv_JNI_GetField<jobject> (JNIEnv *env, jobject obj, jfieldID field)
{
  jobject *ptr = (jobject *) ((char *) obj + field->getOffset ());
  return _Jv_JNI_NewLocalRef (env, *ptr);
}

template<typename T>
static void
_Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
{
  T *ptr = (T *) ((char *) obj + field->getOffset ());
  *ptr = value;
}

template<jboolean is_static>
static jfieldID
_Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
		       const char *name, const char *sig)
{
  // FIXME: exception processing.
  _Jv_InitClass (clazz);

  _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);

  jclass field_class = NULL;
  if (sig[0] == '[')
    field_class = _Jv_FindClassFromSignature ((char *) sig, NULL);
  else
    {
      _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
      field_class = _Jv_FindClass (sig_u, NULL);
    }

  // FIXME: what if field_class == NULL?

  while (clazz != NULL)
    {
      jint count = (is_static
		    ? JvNumStaticFields (clazz)
		    : JvNumInstanceFields (clazz));
      jfieldID field = (is_static
			? JvGetFirstStaticField (clazz)
			: JvGetFirstInstanceField (clazz));
      for (jint i = 0; i < count; ++i)
	{
	  // The field is resolved as a side effect of class
	  // initialization.
	  JvAssert (field->isResolved ());

	  _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);

	  if (_Jv_equalUtf8Consts (f_name, a_name)
	      && field->getClass() == field_class)
	    return field;

	  field = field->getNextField ();
	}

      clazz = clazz->getSuperclass ();
    }

  env->ex = new java::lang::NoSuchFieldError ();
  return NULL;
}

// FIXME: local reference
template<typename T>
static T
_Jv_JNI_GetStaticField (JNIEnv *, jclass, jfieldID field)
{
  T *ptr = (T *) field->u.addr;
  return *ptr;
}

template<>
static jobject
_Jv_JNI_GetStaticField<jobject> (JNIEnv *env, jclass, jfieldID field)
{
  jobject *ptr = (jobject *) field->u.addr;
  return _Jv_JNI_NewLocalRef (env, *ptr);
}

template<typename T>
static void
_Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
{
  T *ptr = (T *) field->u.addr;
  *ptr = value;
}

static jstring
_Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
{
  // FIXME: exception processing.
  jstring r = _Jv_NewString (unichars, len);
  return (jstring) _Jv_JNI_NewLocalRef (env, r);
}

static jsize
_Jv_JNI_GetStringLength (JNIEnv *, jstring string)
{
  return string->length();
}

static const jchar *
_Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
{
  jchar *result = _Jv_GetStringChars (string);
  mark_for_gc (string);
  if (isCopy)
    *isCopy = false;
  return (const jchar *) result;
}

static void
_Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
{
  unmark_for_gc (string);
}

static jstring
_Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
{
  // FIXME: exception processing.
  jstring result = JvNewStringUTF (bytes);
  return (jstring) _Jv_JNI_NewLocalRef (env, result);
}

static jsize
_Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
{
  return JvGetStringUTFLength (string);
}

static const char *
_Jv_JNI_GetStringUTFChars (JNIEnv *, jstring string, jboolean *isCopy)
{
  jsize len = JvGetStringUTFLength (string);
  // FIXME: exception processing.
  char *r = (char *) _Jv_Malloc (len + 1);
  JvGetStringUTFRegion (string, 0, len, r);
  r[len] = '\0';

  if (isCopy)
    *isCopy = true;

  return (const char *) r;
}

static void
_Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
{
  _Jv_Free ((void *) utf);
}

static void
_Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len,
			 jchar *buf)
{
  jchar *result = _Jv_GetStringChars (string);
  if (start < 0 || start > string->length ()
      || len < 0 || start + len > string->length ())
    env->ex = new java::lang::StringIndexOutOfBoundsException ();
  else
    memcpy (buf, &result[start], len * sizeof (jchar));
}

static void
_Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
			    jsize len, char *buf)
{
  if (start < 0 || start > str->length ()
      || len < 0 || start + len > str->length ())
    env->ex = new java::lang::StringIndexOutOfBoundsException ();
  else
    _Jv_GetStringUTFRegion (str, start, len, buf);
}

static const jchar *
_Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
{
  jchar *result = _Jv_GetStringChars (str);
  if (isCopy)
    *isCopy = false;
  return result;
}

static void
_Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
{
  // Nothing.
}

static jsize
_Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
{
  return array->length;
}

static jarray
_Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass,
			jobject init)
{
  // FIXME: exception processing.
  jarray result = JvNewObjectArray (length, elementClass, init);
  return (jarray) _Jv_JNI_NewLocalRef (env, result);
}

static jobject
_Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
{
  jobject *elts = elements (array);
  return _Jv_JNI_NewLocalRef (env, elts[index]);
}

static void
_Jv_JNI_SetObjectArrayElement (JNIEnv *, jobjectArray array, jsize index,
			       jobject value)
{
  // FIXME: exception processing.
  _Jv_CheckArrayStore (array, value);
  jobject *elts = elements (array);
  elts[index] = value;
}

template<typename T, jclass K>
static JArray<T> *
_Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
{
  // FIXME: exception processing.
  return (JArray<T> *) _Jv_JNI_NewLocalRef (env,
					    _Jv_NewPrimArray (K, length));
}

template<typename T>
static T *
_Jv_JNI_GetPrimitiveArrayElements (JNIEnv *, JArray<T> *array,
				   jboolean *isCopy)
{
  T *elts = elements (array);
  if (isCopy)
    {
      // We elect never to copy.
      *isCopy = false;
    }
  mark_for_gc (array);
  return elts;
}

template<typename T>
static void
_Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *, JArray<T> *array,
				       T *, jint /* mode */)
{
  // Note that we ignore MODE.  We can do this because we never copy
  // the array elements.  My reading of the JNI documentation is that
  // this is an option for the implementor.
  unmark_for_gc (array);
}

template<typename T>
static void
_Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
				 jsize start, jsize len,
				 T *buf)
{
  if (start < 0 || len >= array->length || start + len >= array->length)
    {
      // FIXME: index.
      env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
    }
  else
    {
      T *elts = elements (array) + start;
      memcpy (buf, elts, len * sizeof (T));
    }
}

template<typename T>
static void
_Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array, 
				 jsize start, jsize len, T *buf)
{
  if (start < 0 || len >= array->length || start + len >= array->length)
    {
      // FIXME: index.
      env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
    }
  else
    {
      T *elts = elements (array) + start;
      memcpy (elts, buf, len * sizeof (T));
    }
}

static void *
_Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
				   jboolean *isCopy)
{
  // FIXME: does this work?
  jclass klass = array->getClass()->getComponentType();
  JvAssert (klass->isPrimitive ());
  char *r = _Jv_GetArrayElementFromElementType (array, klass);
  if (isCopy)
    *isCopy = false;
  return r;
}

static void
_Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
{
  // Nothing.
}

static jint
_Jv_JNI_MonitorEnter (JNIEnv *, jobject obj)
{
  // FIXME: exception processing.
  jint r = _Jv_MonitorEnter (obj);
  return r;
}

static jint
_Jv_JNI_MonitorExit (JNIEnv *, jobject obj)
{
  // FIXME: exception processing.
  jint r = _Jv_MonitorExit (obj);
  return r;
}

// JDK 1.2
jobject
_Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
			  jboolean)
{
  // FIXME: exception processing.
  java::lang::reflect::Field *field = new java::lang::reflect::Field();
  field->declaringClass = cls;
  field->offset = (char*) fieldID - (char *) cls->fields;
  field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
  return _Jv_JNI_NewLocalRef (env, field);
}

// JDK 1.2
static jfieldID
_Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
{
  using namespace java::lang::reflect;

  Field *field = reinterpret_cast<Field *> (f);
  return _Jv_FromReflectedField (field);
}

jobject
_Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
			   jboolean)
{
  using namespace java::lang::reflect;

  // FIXME.
  static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);

  jobject result;
  if (_Jv_equalUtf8Consts (id->name, init_name))
    {
      // A constructor.
      Constructor *cons = new Constructor ();
      cons->offset = (char *) id - (char *) &klass->methods;
      cons->declaringClass = klass;
      result = cons;
    }
  else
    {
      Method *meth = new Method ();
      meth->offset = (char *) id - (char *) &klass->methods;
      meth->declaringClass = klass;
      result = meth;
    }

  return _Jv_JNI_NewLocalRef (env, result);
}

static jmethodID
_Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
{
  using namespace java::lang::reflect;
  if ((&MethodClass)->isInstance (method))
    return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
  return
    _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
}



// This function is the stub which is used to turn an ordinary (CNI)
// method call into a JNI call.
#if 0
template<typename T>
static T
_Jv_JNI_conversion_call (fixme)
{
  JNIEnv env;
  _Jv_JNI_LocalFrame *frame
    = (_Jv_JNI_LocalFrame *) alloca (sizeof (_Jv_JNI_LocalFrame)
				     + FRAME_SIZE * sizeof (jobject));

  env.p = &_Jv_JNIFunctions;
  env.ex = NULL;
  env.klass = FIXME;
  env.locals = frame;

  frame->marker = true;
  frame->next = NULL;
  frame->size = FRAME_SIZE;
  for (int i = 0; i < frame->size; ++i)
    frame->vec[i] = NULL;

  T result = FIXME_ffi_call (args);

  while (env.locals != NULL)
    _Jv_JNI_PopLocalFrame (&env, result);

  if (env.ex)
    JvThrow (env.ex);

  return T;
}
#endif



#define NOT_IMPL NULL
#define RESERVED NULL

struct JNINativeInterface _Jv_JNIFunctions =
{
  RESERVED,
  RESERVED,
  RESERVED,
  RESERVED,
  _Jv_JNI_GetVersion,
  _Jv_JNI_DefineClass,
  _Jv_JNI_FindClass,
  _Jv_JNI_FromReflectedMethod,
  _Jv_JNI_FromReflectedField,
  _Jv_JNI_ToReflectedMethod,
  _Jv_JNI_GetSuperclass,
  _Jv_JNI_IsAssignableFrom,
  _Jv_JNI_ToReflectedField,
  _Jv_JNI_Throw,
  _Jv_JNI_ThrowNew,
  _Jv_JNI_ExceptionOccurred,
  _Jv_JNI_ExceptionDescribe,
  _Jv_JNI_ExceptionClear,
  _Jv_JNI_FatalError,

  _Jv_JNI_PushLocalFrame,
  _Jv_JNI_PopLocalFrame,
  _Jv_JNI_NewGlobalRef,
  _Jv_JNI_DeleteGlobalRef,
  _Jv_JNI_DeleteLocalRef,

  _Jv_JNI_IsSameObject,

  _Jv_JNI_NewLocalRef,
  _Jv_JNI_EnsureLocalCapacity,

  _Jv_JNI_AllocObject,
  _Jv_JNI_NewObject,
  _Jv_JNI_NewObjectV,
  _Jv_JNI_NewObjectA,
  _Jv_JNI_GetObjectClass,
  _Jv_JNI_IsInstanceOf,
  _Jv_JNI_GetAnyMethodID<false>,

  _Jv_JNI_CallMethod<jobject>,
  _Jv_JNI_CallMethodV<jobject>,
  _Jv_JNI_CallMethodA<jobject>,
  _Jv_JNI_CallMethod<jboolean>,
  _Jv_JNI_CallMethodV<jboolean>,
  _Jv_JNI_CallMethodA<jboolean>,
  _Jv_JNI_CallMethod<jbyte>,
  _Jv_JNI_CallMethodV<jbyte>,
  _Jv_JNI_CallMethodA<jbyte>,
  _Jv_JNI_CallMethod<jchar>,
  _Jv_JNI_CallMethodV<jchar>,
  _Jv_JNI_CallMethodA<jchar>,
  _Jv_JNI_CallMethod<jshort>,
  _Jv_JNI_CallMethodV<jshort>,
  _Jv_JNI_CallMethodA<jshort>,
  _Jv_JNI_CallMethod<jint>,
  _Jv_JNI_CallMethodV<jint>,
  _Jv_JNI_CallMethodA<jint>,
  _Jv_JNI_CallMethod<jlong>,
  _Jv_JNI_CallMethodV<jlong>,
  _Jv_JNI_CallMethodA<jlong>,
  _Jv_JNI_CallMethod<jfloat>,
  _Jv_JNI_CallMethodV<jfloat>,
  _Jv_JNI_CallMethodA<jfloat>,
  _Jv_JNI_CallMethod<jdouble>,
  _Jv_JNI_CallMethodV<jdouble>,
  _Jv_JNI_CallMethodA<jdouble>,
  _Jv_JNI_CallVoidMethod,
  _Jv_JNI_CallVoidMethodV,
  _Jv_JNI_CallVoidMethodA,

  // Nonvirtual method invocation functions follow.
  _Jv_JNI_CallAnyMethod<jobject, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jchar, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jshort, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jint, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jint, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jint, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jlong, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>,
  _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>,
  _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>,
  _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>,
  _Jv_JNI_CallAnyVoidMethod<nonvirtual>,
  _Jv_JNI_CallAnyVoidMethodV<nonvirtual>,
  _Jv_JNI_CallAnyVoidMethodA<nonvirtual>,

  _Jv_JNI_GetAnyFieldID<false>,
  _Jv_JNI_GetField<jobject>,
  _Jv_JNI_GetField<jboolean>,
  _Jv_JNI_GetField<jbyte>,
  _Jv_JNI_GetField<jchar>,
  _Jv_JNI_GetField<jshort>,
  _Jv_JNI_GetField<jint>,
  _Jv_JNI_GetField<jlong>,
  _Jv_JNI_GetField<jfloat>,
  _Jv_JNI_GetField<jdouble>,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_SetField,
  _Jv_JNI_GetAnyMethodID<true>,

  _Jv_JNI_CallStaticMethod<jobject>,
  _Jv_JNI_CallStaticMethodV<jobject>,
  _Jv_JNI_CallStaticMethodA<jobject>,
  _Jv_JNI_CallStaticMethod<jboolean>,
  _Jv_JNI_CallStaticMethodV<jboolean>,
  _Jv_JNI_CallStaticMethodA<jboolean>,
  _Jv_JNI_CallStaticMethod<jbyte>,
  _Jv_JNI_CallStaticMethodV<jbyte>,
  _Jv_JNI_CallStaticMethodA<jbyte>,
  _Jv_JNI_CallStaticMethod<jchar>,
  _Jv_JNI_CallStaticMethodV<jchar>,
  _Jv_JNI_CallStaticMethodA<jchar>,
  _Jv_JNI_CallStaticMethod<jshort>,
  _Jv_JNI_CallStaticMethodV<jshort>,
  _Jv_JNI_CallStaticMethodA<jshort>,
  _Jv_JNI_CallStaticMethod<jint>,
  _Jv_JNI_CallStaticMethodV<jint>,
  _Jv_JNI_CallStaticMethodA<jint>,
  _Jv_JNI_CallStaticMethod<jlong>,
  _Jv_JNI_CallStaticMethodV<jlong>,
  _Jv_JNI_CallStaticMethodA<jlong>,
  _Jv_JNI_CallStaticMethod<jfloat>,
  _Jv_JNI_CallStaticMethodV<jfloat>,
  _Jv_JNI_CallStaticMethodA<jfloat>,
  _Jv_JNI_CallStaticMethod<jdouble>,
  _Jv_JNI_CallStaticMethodV<jdouble>,
  _Jv_JNI_CallStaticMethodA<jdouble>,
  _Jv_JNI_CallStaticVoidMethod,
  _Jv_JNI_CallStaticVoidMethodV,
  _Jv_JNI_CallStaticVoidMethodA,

  _Jv_JNI_GetAnyFieldID<true>,
  _Jv_JNI_GetStaticField<jobject>,
  _Jv_JNI_GetStaticField<jboolean>,
  _Jv_JNI_GetStaticField<jbyte>,
  _Jv_JNI_GetStaticField<jchar>,
  _Jv_JNI_GetStaticField<jshort>,
  _Jv_JNI_GetStaticField<jint>,
  _Jv_JNI_GetStaticField<jlong>,
  _Jv_JNI_GetStaticField<jfloat>,
  _Jv_JNI_GetStaticField<jdouble>,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_SetStaticField,
  _Jv_JNI_NewString,
  _Jv_JNI_GetStringLength,
  _Jv_JNI_GetStringChars,
  _Jv_JNI_ReleaseStringChars,
  _Jv_JNI_NewStringUTF,
  _Jv_JNI_GetStringUTFLength,
  _Jv_JNI_GetStringUTFChars,
  _Jv_JNI_ReleaseStringUTFChars,
  _Jv_JNI_GetArrayLength,
  _Jv_JNI_NewObjectArray,
  _Jv_JNI_GetObjectArrayElement,
  _Jv_JNI_SetObjectArrayElement,
  _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
  _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>,
  _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>,
  _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>,
  _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>,
  _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>,
  _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>,
  _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_ReleasePrimitiveArrayElements,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_GetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  _Jv_JNI_SetPrimitiveArrayRegion,
  NOT_IMPL /* RegisterNatives */,
  NOT_IMPL /* UnregisterNatives */,
  _Jv_JNI_MonitorEnter,
  _Jv_JNI_MonitorExit,
  NOT_IMPL /* GetJavaVM */,

  _Jv_JNI_GetStringRegion,
  _Jv_JNI_GetStringUTFRegion,
  _Jv_JNI_GetPrimitiveArrayCritical,
  _Jv_JNI_ReleasePrimitiveArrayCritical,
  _Jv_JNI_GetStringCritical,
  _Jv_JNI_ReleaseStringCritical,

  NOT_IMPL /* newweakglobalref */,
  NOT_IMPL /* deleteweakglobalref */,

  _Jv_JNI_ExceptionCheck
};