summaryrefslogtreecommitdiff
path: root/libjava/java/lang/natClass.cc
blob: d6969d49b36f1997c473f12613eaa1b83ce2cb76 (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
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
// natClass.cc - Implementation of java.lang.Class native methods.

/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
   2010 Free Software Foundation

   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.  */

#include <config.h>

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

#pragma implementation "Class.h"

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

#include <java/lang/Class.h>
#include <java/lang/ClassLoader.h>
#include <java/lang/String.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/reflect/Member.h>
#include <java/lang/reflect/Method.h>
#include <java/lang/reflect/Field.h>
#include <java/lang/reflect/Proxy.h>
#include <java/lang/reflect/Constructor.h>
#include <java/lang/AbstractMethodError.h>
#include <java/lang/ArrayStoreException.h>
#include <java/lang/ClassCastException.h>
#include <java/lang/ClassNotFoundException.h>
#include <java/lang/ExceptionInInitializerError.h>
#include <java/lang/IllegalAccessException.h>
#include <java/lang/IllegalAccessError.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/NoSuchFieldError.h>
#include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/InstantiationException.h>
#include <java/lang/NoClassDefFoundError.h>
#include <java/lang/NoSuchFieldException.h>
#include <java/lang/NoSuchMethodError.h>
#include <java/lang/NoSuchMethodException.h>
#include <java/lang/Thread.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/RuntimePermission.h>
#include <java/lang/System.h>
#include <java/lang/SecurityException.h>
#include <java/lang/SecurityManager.h>
#include <java/lang/StringBuffer.h>
#include <java/lang/VMClassLoader.h>
#include <gcj/method.h>
#include <gnu/gcj/RawData.h>
#include <java/lang/VerifyError.h>
#include <java/lang/InternalError.h>
#include <java/lang/TypeNotPresentException.h>
#include <java/lang/Byte.h>
#include <java/lang/Short.h>
#include <java/lang/Integer.h>
#include <java/lang/Float.h>
#include <java/lang/Double.h>
#include <java/lang/Long.h>
#include <java/lang/Character.h>
#include <java/lang/Boolean.h>
#include <java/lang/annotation/Annotation.h>
#include <java/util/HashMap.h>
#include <java/util/Map.h>
#include <sun/reflect/annotation/AnnotationInvocationHandler.h>
#include <java/lang/Enum.h>

#include <java-cpool.h>
#include <java-interp.h>
#include <java-assert.h>
#include <java-stack.h>
#include <execution.h>



using namespace gcj;

jclass
java::lang::Class::forName (jstring className, jboolean initialize,
                            java::lang::ClassLoader *loader)
{
  if (! className)
    throw new java::lang::NullPointerException;

  jsize length = _Jv_GetStringUTFLength (className);
  char buffer[length];
  _Jv_GetStringUTFRegion (className, 0, className->length(), buffer);

  _Jv_Utf8Const *name = _Jv_makeUtf8Const (buffer, length);

  if (! _Jv_VerifyClassName (name))
    throw new java::lang::ClassNotFoundException (className);

  jclass klass = (buffer[0] == '[' 
		  ? _Jv_FindClassFromSignature (name->chars(), loader)
		  : _Jv_FindClass (name, loader));

  if (klass == NULL)
    throw new java::lang::ClassNotFoundException (className);

  if (initialize)
    _Jv_InitClass (klass);

  return klass;
}

jclass
java::lang::Class::forName (jstring className)
{
  java::lang::ClassLoader *loader = NULL;

  jclass caller = _Jv_StackTrace::GetCallingClass (&Class::class$);
  if (caller)
    loader = caller->getClassLoaderInternal();

  return forName (className, true, loader);
}

java::lang::ClassLoader *
java::lang::Class::getClassLoader (void)
{
  java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
  if (s != NULL)
    {
      jclass caller = _Jv_StackTrace::GetCallingClass (&Class::class$);
      return getClassLoader (caller);
   }

  return loader;
}

java::lang::ClassLoader *
java::lang::Class::getClassLoader (jclass caller)
{
  java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
  if (s != NULL)
    {
      ClassLoader *caller_loader = caller->getClassLoaderInternal();

      // If the caller has a non-null class loader, and that loader
      // is not this class' loader or an ancestor thereof, then do a
      // security check.
      if (caller_loader != NULL && ! caller_loader->isAncestorOf(loader))
	s->checkPermission (new RuntimePermission (JvNewStringLatin1 ("getClassLoader")));
    }

  return loader;
}

java::lang::reflect::Constructor *
java::lang::Class::getConstructor (JArray<jclass> *param_types)
{
  memberAccessCheck(java::lang::reflect::Member::PUBLIC);

  jstring partial_sig = getSignature (param_types, true);
  jint hash = partial_sig->hashCode ();

  int i = isPrimitive () ? 0 : method_count;
  while (--i >= 0)
    {
      if (_Jv_equalUtf8Consts (methods[i].name, init_name)
	  && _Jv_equal (methods[i].signature, partial_sig, hash))
	{
	  // Found it.  For getConstructor, the constructor must be
	  // public.
	  using namespace java::lang::reflect;
	  if (! Modifier::isPublic(methods[i].accflags))
	    break;
	  Constructor *cons = new Constructor ();
	  cons->offset = (char *) (&methods[i]) - (char *) methods;
	  cons->declaringClass = this;
	  return cons;
	}
    }
  throw new java::lang::NoSuchMethodException (_Jv_NewStringUtf8Const (init_name));
}

JArray<java::lang::reflect::Constructor *> *
java::lang::Class::getDeclaredConstructors (jboolean publicOnly)
{
  int numConstructors = 0;
  int max = isPrimitive () ? 0 : method_count;
  int i;
  for (i = max; --i >= 0; )
    {
      _Jv_Method *method = &methods[i];
      if (method->name == NULL
	  || ! _Jv_equalUtf8Consts (method->name, init_name))
	continue;
      if (publicOnly
	  && ! java::lang::reflect::Modifier::isPublic(method->accflags))
	continue;
      numConstructors++;
    }
  JArray<java::lang::reflect::Constructor *> *result
    = (JArray<java::lang::reflect::Constructor *> *)
    JvNewObjectArray (numConstructors,
		      &java::lang::reflect::Constructor::class$,
		      NULL);
  java::lang::reflect::Constructor** cptr = elements (result);
  for (i = 0;  i < max;  i++)
    {
      _Jv_Method *method = &methods[i];
      if (method->name == NULL
	  || ! _Jv_equalUtf8Consts (method->name, init_name))
	continue;
      if (publicOnly
	  && ! java::lang::reflect::Modifier::isPublic(method->accflags))
	continue;
      java::lang::reflect::Constructor *cons
	= new java::lang::reflect::Constructor ();
      cons->offset = (char *) method - (char *) methods;
      cons->declaringClass = this;
      *cptr++ = cons;
    }
  return result;
}

java::lang::reflect::Constructor *
java::lang::Class::getDeclaredConstructor (JArray<jclass> *param_types)
{
  memberAccessCheck(java::lang::reflect::Member::DECLARED);

  jstring partial_sig = getSignature (param_types, true);
  jint hash = partial_sig->hashCode ();

  int i = isPrimitive () ? 0 : method_count;
  while (--i >= 0)
    {
      if (_Jv_equalUtf8Consts (methods[i].name, init_name)
	  && _Jv_equal (methods[i].signature, partial_sig, hash))
	{
	  // Found it.
	  using namespace java::lang::reflect;
	  Constructor *cons = new Constructor ();
	  cons->offset = (char *) (&methods[i]) - (char *) methods;
	  cons->declaringClass = this;
	  return cons;
	}
    }
  throw new java::lang::NoSuchMethodException (_Jv_NewStringUtf8Const (init_name));
}

java::lang::reflect::Field *
java::lang::Class::getField (jstring name, jint hash)
{
  java::lang::reflect::Field* rfield;
  for (int i = 0;  i < field_count;  i++)
    {
      _Jv_Field *field = &fields[i];
      if (! _Jv_equal (field->name, name, hash))
	continue;
      if (! (field->getModifiers() & java::lang::reflect::Modifier::PUBLIC))
	continue;
      rfield = new java::lang::reflect::Field ();
      rfield->offset = (char*) field - (char*) fields;
      rfield->declaringClass = this;
      rfield->name = name;
      return rfield;
    }
  jclass superclass = getSuperclass();
  if (superclass == NULL)
    return NULL;
  rfield = superclass->getField(name, hash);
  for (int i = 0; i < interface_count && rfield == NULL; ++i)
    rfield = interfaces[i]->getField (name, hash);
  return rfield;
}

java::lang::reflect::Field *
java::lang::Class::getDeclaredField (jstring name)
{
  memberAccessCheck(java::lang::reflect::Member::DECLARED);
  int hash = name->hashCode();
  for (int i = 0;  i < field_count;  i++)
    {
      _Jv_Field *field = &fields[i];
      if (! _Jv_equal (field->name, name, hash))
	continue;
      java::lang::reflect::Field* rfield = new java::lang::reflect::Field ();
      rfield->offset = (char*) field - (char*) fields;
      rfield->declaringClass = this;
      rfield->name = name;
      return rfield;
    }
  throw new java::lang::NoSuchFieldException (name);
}

JArray<java::lang::reflect::Field *> *
java::lang::Class::getDeclaredFields (jboolean public_only)
{
  int size;
  if (public_only)
    {
      size = 0;
      for (int i = 0; i < field_count; ++i)
	{
	  _Jv_Field *field = &fields[i];
	  if ((field->flags & java::lang::reflect::Modifier::PUBLIC))
	    ++size;
	}
    }
  else
    size = field_count;

  JArray<java::lang::reflect::Field *> *result
    = (JArray<java::lang::reflect::Field *> *)
    JvNewObjectArray (size, &java::lang::reflect::Field::class$, NULL);
  java::lang::reflect::Field** fptr = elements (result);
  for (int i = 0;  i < field_count;  i++)
    {
      _Jv_Field *field = &fields[i];
      if (public_only
	  && ! (field->flags & java::lang::reflect::Modifier::PUBLIC))
	continue;
      java::lang::reflect::Field* rfield = new java::lang::reflect::Field ();
      rfield->offset = (char*) field - (char*) fields;
      rfield->declaringClass = this;
      *fptr++ = rfield;
    }
  return result;
}

void
java::lang::Class::getSignature (java::lang::StringBuffer *buffer)
{
  if (isPrimitive())
    buffer->append((jchar) method_count);
  else
    {
      jstring name = getName();
      if (name->charAt(0) != '[')
	buffer->append((jchar) 'L');
      buffer->append(name);
      if (name->charAt(0) != '[')
	buffer->append((jchar) ';');
    }
}

// This doesn't have to be native.  It is an implementation detail
// only called from the C++ code, though, so maybe this is clearer.
jstring
java::lang::Class::getSignature (JArray<jclass> *param_types,
				 jboolean is_constructor)
{
  java::lang::StringBuffer *buf = new java::lang::StringBuffer ();
  buf->append((jchar) '(');
  // A NULL param_types means "no parameters".
  if (param_types != NULL)
    {
      jclass *v = elements (param_types);
      for (int i = 0; i < param_types->length; ++i)
	v[i]->getSignature(buf);
    }
  buf->append((jchar) ')');
  if (is_constructor)
    buf->append((jchar) 'V');
  return buf->toString();
}

java::lang::reflect::Method *
java::lang::Class::_getDeclaredMethod (jstring name,
				       JArray<jclass> *param_types)
{
  jstring partial_sig = getSignature (param_types, false);
  jint p_len = partial_sig->length();
  _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
  int i = isPrimitive () ? 0 : method_count;
  while (--i >= 0)
    {
      if (_Jv_equalUtf8Consts (methods[i].name, utf_name)
	  && _Jv_equaln (methods[i].signature, partial_sig, p_len)
	  && (methods[i].accflags
	      & java::lang::reflect::Modifier::INVISIBLE) == 0)
	{
	  // Found it.
	  using namespace java::lang::reflect;
	  Method *rmethod = new Method ();
	  rmethod->offset = (char*) (&methods[i]) - (char*) methods;
	  rmethod->declaringClass = this;
	  return rmethod;
	}
    }
  return NULL;
}

JArray<java::lang::reflect::Method *> *
java::lang::Class::getDeclaredMethods (void)
{
  memberAccessCheck(java::lang::reflect::Member::DECLARED);

  int numMethods = 0;
  int max = isPrimitive () ? 0 : method_count;
  int i;
  for (i = max; --i >= 0; )
    {
      _Jv_Method *method = &methods[i];
      if (method->name == NULL
	  || _Jv_equalUtf8Consts (method->name, clinit_name)
	  || _Jv_equalUtf8Consts (method->name, init_name)
	  || _Jv_equalUtf8Consts (method->name, finit_name)
	  || (methods[i].accflags
	      & java::lang::reflect::Modifier::INVISIBLE) != 0)
	continue;
      numMethods++;
    }
  JArray<java::lang::reflect::Method *> *result
    = (JArray<java::lang::reflect::Method *> *)
    JvNewObjectArray (numMethods, &java::lang::reflect::Method::class$, NULL);
  java::lang::reflect::Method** mptr = elements (result);
  for (i = 0;  i < max;  i++)
    {
      _Jv_Method *method = &methods[i];
      if (method->name == NULL
	  || _Jv_equalUtf8Consts (method->name, clinit_name)
	  || _Jv_equalUtf8Consts (method->name, init_name)
	  || _Jv_equalUtf8Consts (method->name, finit_name)
	  || (methods[i].accflags
	      & java::lang::reflect::Modifier::INVISIBLE) != 0)
	continue;
      java::lang::reflect::Method* rmethod
	= new java::lang::reflect::Method ();
      rmethod->offset = (char*) method - (char*) methods;
      rmethod->declaringClass = this;
      *mptr++ = rmethod;
    }
  return result;
}

jstring
java::lang::Class::getName (void)
{
  return name->toString();
}

JArray<jclass> *
java::lang::Class::getInterfaces (void)
{
  jobjectArray r = JvNewObjectArray (interface_count, getClass (), NULL);
  jobject *data = elements (r);
  for (int i = 0; i < interface_count; ++i)
    {
      typedef unsigned int uaddr __attribute__ ((mode (pointer)));
      data[i] = interfaces[i];
      if ((uaddr)data[i] < (uaddr)constants.size)
	fprintf (stderr, "ERROR !!!\n");
    }
  return reinterpret_cast<JArray<jclass> *> (r);
}

java::lang::reflect::Method *
java::lang::Class::_getMethod (jstring name, JArray<jclass> *param_types)
{
  jstring partial_sig = getSignature (param_types, false);
  jint p_len = partial_sig->length();
  _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);

   for (Class *klass = this; klass; klass = klass->getSuperclass())
    {
      int i = klass->isPrimitive () ? 0 : klass->method_count;
      while (--i >= 0)
	{
	  if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
	      && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len)
	      && (klass->methods[i].accflags
		  & java::lang::reflect::Modifier::INVISIBLE) == 0)
	    {
	      // Found it.
	      using namespace java::lang::reflect;

	      // Method must be public.
	      if (! Modifier::isPublic (klass->methods[i].accflags))
		break;

	      Method *rmethod = new Method ();
	      rmethod->offset = ((char *) (&klass->methods[i])
				 - (char *) klass->methods);
	      rmethod->declaringClass = klass;
	      return rmethod;
	    }
	}
    }

  // If we haven't found a match, and this class is an interface, then
  // check all the superinterfaces.
  if (isInterface())
    {
      for (int i = 0; i < interface_count; ++i)
	{
	  using namespace java::lang::reflect;
	  Method *rmethod = interfaces[i]->_getMethod (name, param_types);
	  if (rmethod != NULL)
	    return rmethod;
	}
    }

  return NULL;
}

// This is a very slow implementation, since it re-scans all the
// methods we've already listed to make sure we haven't duplicated a
// method.  It also over-estimates the required size, so we have to
// shrink the result array later.
jint
java::lang::Class::_getMethods (JArray<java::lang::reflect::Method *> *result,
				jint offset)
{
  jint count = 0;

  // First examine all local methods
  for (int i = isPrimitive () ? 0 : method_count; --i >= 0; )
    {
      _Jv_Method *method = &methods[i];
      if (method->name == NULL
	  || _Jv_equalUtf8Consts (method->name, clinit_name)
	  || _Jv_equalUtf8Consts (method->name, init_name)
	  || _Jv_equalUtf8Consts (method->name, finit_name)
	  || (method->accflags
	      & java::lang::reflect::Modifier::INVISIBLE) != 0)
	continue;
      // Only want public methods.
      if (! java::lang::reflect::Modifier::isPublic (method->accflags))
	continue;

      // This is where we over-count the slots required if we aren't
      // filling the result for real.
      if (result != NULL)
	{
	  jboolean add = true;
	  java::lang::reflect::Method **mp = elements (result);
	  // If we already have a method with this name and signature,
	  // then ignore this one.  This can happen with virtual
	  // methods.
	  for (int j = 0; j < offset; ++j)
	    {
	      _Jv_Method *meth_2 = _Jv_FromReflectedMethod (mp[j]);
	      if (_Jv_equalUtf8Consts (method->name, meth_2->name)
		  && _Jv_equalUtf8Consts (method->signature,
					  meth_2->signature))
		{
		  add = false;
		  break;
		}
	    }
	  if (! add)
	    continue;
	}

      if (result != NULL)
	{
	  using namespace java::lang::reflect;
	  Method *rmethod = new Method ();
	  rmethod->offset = (char *) method - (char *) methods;
	  rmethod->declaringClass = this;
	  Method **mp = elements (result);
	  mp[offset + count] = rmethod;
	}
      ++count;
    }
  offset += count;

  // Now examine superclasses.
  if (getSuperclass () != NULL)
    {
      jint s_count = getSuperclass()->_getMethods (result, offset);
      offset += s_count;
      count += s_count;
    }

  // Finally, examine interfaces.
  for (int i = 0; i < interface_count; ++i)
    {
      int f_count = interfaces[i]->_getMethods (result, offset);
      count += f_count;
      offset += f_count;
    }

  return count;
}

JArray<java::lang::reflect::Method *> *
java::lang::Class::getMethods (void)
{
  using namespace java::lang::reflect;

  memberAccessCheck(Member::PUBLIC);

  // This will overestimate the size we need.
  jint count = _getMethods (NULL, 0);

  JArray<Method *> *result
    = ((JArray<Method *> *) JvNewObjectArray (count,
					      &Method::class$,
					      NULL));

  // When filling the array for real, we get the actual count.  Then
  // we resize the array.
  jint real_count = _getMethods (result, 0);

  if (real_count != count)
    {
      JArray<Method *> *r2
	= ((JArray<Method *> *) JvNewObjectArray (real_count,
						  &Method::class$,
						  NULL));
      
      Method **destp = elements (r2);
      Method **srcp = elements (result);

      for (int i = 0; i < real_count; ++i)
	*destp++ = *srcp++;

      result = r2;
    }

  return result;
}

jboolean
java::lang::Class::isAssignableFrom (jclass klass)
{
  // Arguments may not have been initialized, given ".class" syntax.
  // This ensures we can at least look at their superclasses.
  _Jv_Linker::wait_for_state (this, JV_STATE_LOADING);
  _Jv_Linker::wait_for_state (klass, JV_STATE_LOADING);
  return _Jv_IsAssignableFrom (klass, this);
}

jboolean
java::lang::Class::isInstance (jobject obj)
{
  if (! obj)
    return false;
  return _Jv_IsAssignableFrom (JV_CLASS (obj), this);
}

jobject
java::lang::Class::newInstance (void)
{
  memberAccessCheck(java::lang::reflect::Member::PUBLIC);

  if (isPrimitive ()
      || isInterface ()
      || isArray ()
      || java::lang::reflect::Modifier::isAbstract(accflags))
    throw new java::lang::InstantiationException (getName ());

  _Jv_InitClass (this);

  _Jv_Method *meth = _Jv_GetMethodLocal (this, init_name, void_signature);
  if (! meth)
    throw new java::lang::InstantiationException (getName());

  jobject r = _Jv_AllocObject (this);
  ((void (*) (jobject)) meth->ncode) (r);
  return r;
}

void
java::lang::Class::finalize (void)
{
  // Array classes don't have an engine, and don't need to be finalized.
  if (engine)
    engine->unregister(this);
}

#ifdef INTERPRETER
void
_Jv_ClosureList::releaseClosures (_Jv_ClosureList **closures)
{
  if (!closures)
    return;

  while (_Jv_ClosureList *current = *closures)
    {
      *closures = current->next;
      ffi_closure_free (current->ptr);
    }
}

void
_Jv_ClosureList::registerClosure (jclass klass, void *ptr)
{
  _Jv_ClosureList **closures = klass->engine->get_closure_list (klass);
  if (closures)
    {
      this->ptr = ptr;
      this->next = *closures;
      *closures = this;
    }
}
#endif

// This implements the initialization process for a class.  From Spec
// section 12.4.2.
void
java::lang::Class::initializeClass (void)
{
  // Short-circuit to avoid needless locking (expression includes
  // JV_STATE_PHANTOM and JV_STATE_DONE).
  if (state >= JV_STATE_PHANTOM)
    return;

  // Step 1.  We introduce a new scope so we can synchronize more
  // easily.
  {
    JvSynchronize sync (this);

    if (state < JV_STATE_LINKED)
      {
	try
	  {
	    _Jv_Linker::wait_for_state(this, JV_STATE_LINKED);
	  }
	catch (java::lang::SecurityException *x)
	  {
	    throw x;
	  }
	catch (java::lang::Throwable *x)
	  {
	    // Turn into a NoClassDefFoundError.
	    java::lang::NoClassDefFoundError *result
	      = new java::lang::NoClassDefFoundError(getName());
	    result->initCause(x);
	    throw result;
	  }
      }

    // Step 2.
    java::lang::Thread *self = java::lang::Thread::currentThread();
    self = (java::lang::Thread *) ((long) self | 1);
    while (state == JV_STATE_IN_PROGRESS && thread && thread != self)
      wait ();

    // Steps 3 &  4.
    if (state == JV_STATE_DONE || state == JV_STATE_IN_PROGRESS)
      return;

    // Step 5.
    if (state == JV_STATE_ERROR)
      throw new java::lang::NoClassDefFoundError (getName());

    // Step 6.
    thread = self;
    _Jv_Linker::wait_for_state (this, JV_STATE_LINKED);
    state = JV_STATE_IN_PROGRESS;
  }

  // Step 7.
  if (! isInterface () && superclass)
    {
      try
	{
	  _Jv_InitClass (superclass);
	}
      catch (java::lang::SecurityException *x)
	{
	  throw x;
	}
      catch (java::lang::Throwable *except)
	{
	  // Caught an exception.
	  JvSynchronize sync (this);
	  state = JV_STATE_ERROR;
	  notifyAll ();
	  throw except;
	}
    }

  // Steps 8, 9, 10, 11.
  try
    {
      _Jv_Method *meth = _Jv_GetMethodLocal (this, clinit_name,
					     void_signature);
      if (meth)
	((void (*) (void)) meth->ncode) ();
    }
  catch (java::lang::SecurityException *x)
    {
      throw x;
    }
  catch (java::lang::Throwable *except)
    {
      if (! java::lang::Error::class$.isInstance(except))
	{
	  try
	    {
	      except = new ExceptionInInitializerError (except);
	    }
	  catch (java::lang::Throwable *t)
	    {
	      except = t;
	    }
	}

      JvSynchronize sync (this);
      state = JV_STATE_ERROR;
      notifyAll ();
      throw except;
    }

  JvSynchronize sync (this);
  state = JV_STATE_DONE;
  notifyAll ();
}

// Only used by serialization
java::lang::reflect::Field *
java::lang::Class::getPrivateField (jstring name)
{
  int hash = name->hashCode ();

  java::lang::reflect::Field* rfield;
  for (int i = 0;  i < field_count;  i++)
    {
      _Jv_Field *field = &fields[i];
      if (! _Jv_equal (field->name, name, hash))
	continue;
      rfield = new java::lang::reflect::Field ();
      rfield->offset = (char*) field - (char*) fields;
      rfield->declaringClass = this;
      rfield->name = name;
      return rfield;
    }
  jclass superclass = getSuperclass();
  if (superclass == NULL)
    return NULL;
  rfield = superclass->getPrivateField(name);
  for (int i = 0; i < interface_count && rfield == NULL; ++i)
    rfield = interfaces[i]->getPrivateField (name);
  return rfield;
}

// Only used by serialization
java::lang::reflect::Method *
java::lang::Class::getPrivateMethod (jstring name, JArray<jclass> *param_types)
{
  jstring partial_sig = getSignature (param_types, false);
  jint p_len = partial_sig->length();
  _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
  for (Class *klass = this; klass; klass = klass->getSuperclass())
    {
      int i = klass->isPrimitive () ? 0 : klass->method_count;
      while (--i >= 0)
	{
	  if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
	      && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len))
	    {
	      // Found it.
	      using namespace java::lang::reflect;

	      Method *rmethod = new Method ();
	      rmethod->offset = ((char *) (&klass->methods[i])
				 - (char *) klass->methods);
	      rmethod->declaringClass = klass;
	      return rmethod;
	    }
	}
    }
  throw new java::lang::NoSuchMethodException (name);
}

// Private accessor method for Java code to retrieve the protection domain.
java::security::ProtectionDomain *
java::lang::Class::getProtectionDomain0 ()
{
  return protectionDomain;
}

JArray<jobject> *
java::lang::Class::getSigners()
{
  return hack_signers;
}

void
java::lang::Class::setSigners(JArray<jobject> *s)
{
  hack_signers = s;
}



static unsigned char
read_u1 (unsigned char *&p)
{
  return *p++;
}

static unsigned char
read_u1 (unsigned char *&p, unsigned char *next)
{
  if (next - p < 1)
    throw new java::lang::InternalError();
  return *p++;
}

static unsigned int
read_u2 (unsigned char *&p)
{
  unsigned int b1 = *p++;
  unsigned int b2 = *p++;
  return (b1 << 8) | b2;
}

static unsigned int
read_u2 (unsigned char *&p, unsigned char *next)
{
  if (next - p < 2)
    throw new java::lang::InternalError();
  return read_u2 (p);
}

static int
read_4 (unsigned char *&p)
{
  int b1 = *p++;
  int b2 = *p++;
  int b3 = *p++;
  int b4 = *p++;
  return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
}

jstring
java::lang::Class::getReflectionSignature (jint /*jv_attr_type*/ type,
					   jint obj_index)
{
  // We just re-parse the bytecode for this data each time.  If
  // necessary we can cache results, but I suspect this is not
  // performance sensitive.
  unsigned char *bytes = reflection_data;
  if (bytes == NULL)
    return NULL;
  while (true)
    {
      int kind = read_u1 (bytes);
      if (kind == JV_DONE_ATTR)
	return NULL;
      int len = read_4 (bytes);
      unsigned char *next = bytes + len;
      if (kind != type)
	{
	  bytes = next;
	  continue;
	}
      if (type != JV_CLASS_ATTR)
	{
	  unsigned short index = read_u2 (bytes, next);
	  if (index != obj_index)
	    {
	      bytes = next;
	      continue;
	    }
	}
      int nt = read_u1 (bytes, next);
      if (nt != JV_SIGNATURE_KIND)
	{
	  bytes = next;
	  continue;
	}
      unsigned int cpool_idx = read_u2 (bytes, next);
      if (cpool_idx >= (unsigned int) constants.size
	  || constants.tags[cpool_idx] != JV_CONSTANT_Utf8)
	{
	  // We just ignore errors for now.  It isn't clear what is
	  // best to do here, as an encoding error here means a bug
	  // either in the compiler or in defineclass.cc.
	  return NULL;
	}
      return _Jv_NewStringUtf8Const (constants.data[cpool_idx].utf8);
    }
}

jstring
java::lang::Class::getReflectionSignature (::java::lang::reflect::Constructor *c)
{
  _Jv_Method *meth = _Jv_FromReflectedConstructor (c);
  unsigned short meth_index = meth - methods;
  return getReflectionSignature (JV_METHOD_ATTR, meth_index);
}

jstring
java::lang::Class::getReflectionSignature (::java::lang::reflect::Method *m)
{
  _Jv_Method *meth = _Jv_FromReflectedMethod (m);
  unsigned short meth_index = meth - methods;
  return getReflectionSignature (JV_METHOD_ATTR, meth_index);
}

jstring
java::lang::Class::getReflectionSignature (::java::lang::reflect::Field *f)
{
  _Jv_Field *fld = _Jv_FromReflectedField (f);
  unsigned short fld_index = fld - fields;
  return getReflectionSignature (JV_FIELD_ATTR, fld_index);
}

jstring
java::lang::Class::getClassSignature()
{
  return getReflectionSignature (JV_CLASS_ATTR, 0);
}

jint
java::lang::Class::getEnclosingMethodData()
{
  unsigned char *bytes = reflection_data;
  if (bytes == NULL)
    return 0;
  while (true)
    {
      int kind = read_u1 (bytes);
      if (kind == JV_DONE_ATTR)
	return 0;
      int len = read_4 (bytes);
      unsigned char *next = bytes + len;
      if (kind != JV_CLASS_ATTR)
	{
	  bytes = next;
	  continue;
	}
      int type = read_u1 (bytes, next);
      if (type != JV_ENCLOSING_METHOD_KIND)
	{
	  bytes = next;
	  continue;
	}
      int class_index = read_u2 (bytes, next);
      int method_index = read_u2 (bytes, next);
      _Jv_word result;
      _Jv_storeIndexes (&result, class_index, method_index);
      return result.i;
    }
}

jclass
java::lang::Class::getEnclosingClass()
{
  _Jv_word indexes;
  indexes.i = getEnclosingMethodData();
  if (indexes.i == 0)
    // No enclosing method, but perhaps a member or anonymous class
    return getDeclaringClass();
  _Jv_ushort class_index, method_index;
  _Jv_loadIndexes (&indexes, class_index, method_index);
  return _Jv_Linker::resolve_pool_entry (this, class_index).clazz;
}

::java::lang::reflect::Method *
java::lang::Class::getEnclosingMethod()
{
  _Jv_word indexes;
  indexes.i = getEnclosingMethodData();
  if (indexes.i == 0)
    return NULL;
  _Jv_ushort class_index, method_index;
  _Jv_loadIndexes (&indexes, class_index, method_index);
  jclass found_class;
  _Jv_Method *method = _Jv_Linker::resolve_method_entry (this, found_class,
							 class_index,
							 method_index,
							 false, false);
  using namespace java::lang::reflect;
  Method *rmethod = new Method ();
  rmethod->offset = (char *) method - (char *) found_class->methods;
  rmethod->declaringClass = found_class;
  return rmethod;
}

::java::lang::reflect::Constructor *
java::lang::Class::getEnclosingConstructor()
{
  _Jv_word indexes;
  indexes.i = getEnclosingMethodData();
  if (indexes.i == 0)
    return NULL;
  _Jv_ushort class_index, method_index;
  _Jv_loadIndexes (&indexes, class_index, method_index);
  jclass found_class;
  _Jv_Method *method = _Jv_Linker::resolve_method_entry (this, found_class,
							 class_index,
							 method_index,
							 false, false);
  using namespace java::lang::reflect;
  Constructor *cons = new Constructor ();
  cons->offset = (char *) method - (char *) found_class->methods;
  cons->declaringClass = this;
  return cons;
}

static void
check_constant (_Jv_Constants *pool, jint cpool_index, jint type)
{
  if (cpool_index <= 0 || cpool_index >= pool->size)
    throw new InternalError(JvNewStringLatin1("invalid constant pool index"));
  if ((pool->tags[cpool_index] & 
	~(JV_CONSTANT_ResolvedFlag|JV_CONSTANT_LazyFlag)) != type)
    {
      ::java::lang::StringBuffer *sb = new ::java::lang::StringBuffer();
      sb->append(JvNewStringLatin1("expected pool constant "));
      sb->append(type);
      sb->append(JvNewStringLatin1(" but got "));
      sb->append(jint (pool->tags[cpool_index]));
      throw new InternalError(sb->toString());
    }
}

// Forward declaration
static ::java::lang::annotation::Annotation *
parseAnnotation(jclass klass, _Jv_Constants *pool,
		unsigned char *&bytes, unsigned char *last);

static jobject
parseAnnotationElement(jclass klass, _Jv_Constants *pool,
		       unsigned char *&bytes, unsigned char *last)
{
  int tag = read_u1 (bytes, last);
  jobject result;
  switch (tag)
    {
    case 'B':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Integer);
	result = Byte::valueOf (pool->data[cindex].i);
      }
      break;
    case 'C':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Integer);
	result = Character::valueOf (pool->data[cindex].i);
      }
      break;
    case 'S':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Integer);
	result = Short::valueOf (pool->data[cindex].i);
      }
      break;
    case 'Z':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Integer);
	result = Boolean::valueOf (jboolean (pool->data[cindex].i));
      }
      break;
    case 'I':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Integer);
	result = Integer::valueOf (pool->data[cindex].i);
      }
      break;
    case 'D':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Double);
	_Jv_word2 word;
	memcpy (&word, &pool->data[cindex], 2 * sizeof (_Jv_word));
	result = Double::valueOf (word.d);
      }
      break;
    case 'F':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Float);
	result = Float::valueOf (pool->data[cindex].f);
      }
      break;
    case 'J':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Long);
	_Jv_word2 word;
	memcpy (&word, &pool->data[cindex], 2 * sizeof (_Jv_word));
	result = Long::valueOf (word.l);
      }
      break;
    case 's':
      {
	int cindex = read_u2 (bytes, last);
	// Despite what the JVM spec says, compilers generate a Utf8
	// constant here, not a String.
	check_constant (pool, cindex, JV_CONSTANT_Utf8);
	result = pool->data[cindex].utf8->toString();
      }
      break;
    case 'e':
      {
	int type_name_index = read_u2 (bytes, last);
	check_constant (pool, type_name_index, JV_CONSTANT_Utf8);
 	int const_name_index = read_u2 (bytes, last);
	check_constant (pool, const_name_index, JV_CONSTANT_Utf8);

	_Jv_Utf8Const *u_name = pool->data[type_name_index].utf8;
	_Jv_Utf8Const *e_name = pool->data[const_name_index].utf8;

	// FIXME: throw correct exceptions at the correct times.
	jclass e_class = _Jv_FindClassFromSignature(u_name->chars(),
						    klass->getClassLoaderInternal());
	result = ::java::lang::Enum::valueOf(e_class, e_name->toString());
      }
      break;
    case 'c':
      {
	int cindex = read_u2 (bytes, last);
	check_constant (pool, cindex, JV_CONSTANT_Utf8);
	_Jv_Utf8Const *u_name = pool->data[cindex].utf8;
	jclass anno_class
	  = _Jv_FindClassFromSignatureNoException(u_name->chars(),
						  klass->getClassLoaderInternal());
	// FIXME: not correct: we should lazily do this when trying to
	// read the element.  This means that
	// AnnotationInvocationHandler needs to have a special case.
	if (! anno_class)
	  // FIXME: original exception...
	  throw new TypeNotPresentException(u_name->toString(), NULL);
	result = anno_class;
      }
      break;
    case '@':
      result = parseAnnotation (klass, pool, bytes, last);
      break;
    case '[':
      {
	int n_array_elts = read_u2 (bytes, last);
	jobjectArray aresult = _Jv_NewObjectArray (n_array_elts,
						   &Object::class$, NULL);
	jobject *elts = elements (aresult);
	for (int i = 0; i < n_array_elts; ++i)
	  elts[i] = parseAnnotationElement(klass, pool, bytes, last);
	result = aresult;
      }
      break;
    default:
      throw new java::lang::InternalError();
    }
  return result;
}

static ::java::lang::annotation::Annotation *
parseAnnotation(jclass klass, _Jv_Constants *pool,
		unsigned char *&bytes, unsigned char *last)
{
  int type_index = read_u2 (bytes, last);
  check_constant (pool, type_index, JV_CONSTANT_Utf8);

  _Jv_Utf8Const *u_name = pool->data[type_index].utf8;
  jclass anno_class = _Jv_FindClassFromSignatureNoException(u_name->chars(),
							    klass->getClassLoaderInternal());
  // FIXME: what to do if anno_class==NULL?

  ::java::util::HashMap *hmap = new ::java::util::HashMap();
  int npairs = read_u2 (bytes, last);
  for (int i = 0; i < npairs; ++i)
    {
      int name_index = read_u2 (bytes, last);
      check_constant (pool, name_index, JV_CONSTANT_Utf8);
      jstring name = _Jv_NewStringUtf8Const (pool->data[name_index].utf8);
      jobject value = parseAnnotationElement (klass, pool, bytes, last);
      // FIXME: any checks needed for name?
      hmap->put(name, value);
    }
  using namespace ::sun::reflect::annotation;
  return AnnotationInvocationHandler::create (anno_class,
					      (::java::util::Map *) hmap);
}

static jobjectArray
parseAnnotations(jclass klass, _Jv_Constants *pool,
		 unsigned char *&bytes, unsigned char *last)
{
  int num = read_u2 (bytes, last);
  jobjectArray result = _Jv_NewObjectArray (num,
					    &::java::lang::annotation::Annotation::class$,
					    NULL);
  jobject *elts = elements (result);
  for (int i = 0; i < num; ++i)
    elts[i] = parseAnnotation(klass, pool, bytes, last);
  return result;
}

static jobjectArray
parseParameterAnnotations(jclass klass, _Jv_Constants *pool,
			  unsigned char *&bytes, unsigned char *last)
{
  jclass anno = &::java::lang::annotation::Annotation::class$;
  jclass annoary = _Jv_GetArrayClass (anno, anno->getClassLoaderInternal());

  // FIXME: something should check the number of params versus the
  // method
  int n_params = read_u1 (bytes, last);
  jobjectArray result = _Jv_NewObjectArray (n_params, annoary, NULL);
  jobject *elts = elements (result);
  for (int i = 0; i < n_params; ++i)
    elts[i] = parseAnnotations(klass, pool, bytes, last);
  return result;
}

jobject
java::lang::Class::getMethodDefaultValue(::java::lang::reflect::Method *meth)
{
  // FIXME: could cache the value here...

  unsigned char *bytes = reflection_data;
  if (bytes == NULL)
    return 0;

  unsigned short meth_index = _Jv_FromReflectedMethod (meth) - methods;

  while (true)
    {
      int type = read_u1 (bytes);
      if (type == JV_DONE_ATTR)
	return NULL;
      int len = read_4 (bytes);
      unsigned char *next = bytes + len;
      if (type != JV_METHOD_ATTR)
	{
	  bytes = next;
	  continue;
	}
      int kind = read_u1 (bytes, next);
      if (kind != JV_ANNOTATION_DEFAULT_KIND)
	{
	  bytes = next;
	  continue;
	}
      int index = read_u2 (bytes, next);
      if (meth_index != index)
	{
	  bytes = next;
	  continue;
	}

      // FIXME: could cache here.  If we do then we have to clone any
      // array result.
      return parseAnnotationElement(this, &this->constants, bytes, next);
    }
}

jobjectArray
java::lang::Class::getDeclaredAnnotations(jint /* jv_attr_type */ member_type,
					  jint member_index,
					  jint /* jv_attr_kind */ kind_req)
{
  using namespace java::lang::annotation;
  jobjectArray result;

  unsigned char *bytes = reflection_data;
  if (bytes == NULL)
    return 0;

  if (loader == NULL)
    loader = (ClassLoader *)VMClassLoader::bootLoader;

  result = (loader->getDeclaredAnnotations
	    (this, member_type, member_index, kind_req));
  if (result)
    return result;

  for (;;)
    {
      int type = read_u1 (bytes);
      if (type == JV_DONE_ATTR)
	return NULL;
      int len = read_4 (bytes);
      unsigned char *next = bytes + len;
      if (type != member_type)
	{
	  bytes = next;
	  continue;
	}
      int kind = read_u1 (bytes, next);
      if (kind != kind_req)
	{
	  bytes = next;
	  continue;
	}
      if (member_type != JV_CLASS_ATTR)
	{
	  int index = read_u2 (bytes, next);
	  if (member_index != index)
	    {
	      bytes = next;
	      continue;
	    }
	}

      if (kind_req == JV_PARAMETER_ANNOTATIONS_KIND)
	result = ((parseParameterAnnotations 
		   (this, &this->constants, bytes, next)));
      else
	result = ((parseAnnotations (this, &this->constants, bytes, next)));
      break;
    }

  return (loader->putDeclaredAnnotations
	  (this, member_type, member_index, kind_req, result));
}

jobjectArray
java::lang::Class::getDeclaredAnnotations(::java::lang::reflect::Method *meth,
					  jboolean is_param)
{
  unsigned short meth_index = _Jv_FromReflectedMethod (meth) - methods;
  return getDeclaredAnnotations(JV_METHOD_ATTR, meth_index,
				(is_param
				 ? JV_PARAMETER_ANNOTATIONS_KIND
				 : JV_ANNOTATIONS_KIND));
}

jobjectArray
java::lang::Class::getDeclaredAnnotations(::java::lang::reflect::Constructor *cons,
					  jboolean is_param)
{
  unsigned short meth_index = _Jv_FromReflectedConstructor (cons) - methods;
  return getDeclaredAnnotations(JV_METHOD_ATTR, meth_index,
				(is_param
				 ? JV_PARAMETER_ANNOTATIONS_KIND
				 : JV_ANNOTATIONS_KIND));
}

jobjectArray
java::lang::Class::getDeclaredAnnotations(::java::lang::reflect::Field *fld)
{
  unsigned short field_index = _Jv_FromReflectedField (fld) - fields;
  return getDeclaredAnnotations(JV_FIELD_ATTR, field_index,
				JV_ANNOTATIONS_KIND);
}

JArray< ::java::lang::annotation::Annotation *> *
java::lang::Class::getDeclaredAnnotationsInternal()
{
  return (JArray< ::java::lang::annotation::Annotation *> *) getDeclaredAnnotations(JV_CLASS_ATTR, 0, JV_ANNOTATIONS_KIND);
}

static jclass
resolve_class_constant (jclass klass, _Jv_Constants *pool, int cpool_index)
{
  check_constant (pool, cpool_index, JV_CONSTANT_Class);
  // FIXME: what is the correct thing to do with an exception here?
  return _Jv_Linker::resolve_pool_entry (klass, cpool_index, false).clazz;
}

jint
java::lang::Class::findInnerClassAttribute()
{
  unsigned char *bytes = reflection_data;
  if (bytes == NULL)
    return -1;
  while (true)
    {
      int type = read_u1 (bytes);
      if (type == JV_DONE_ATTR)
	break;
      // After the type but before the length.
      unsigned char *save = bytes;
      int len = read_4 (bytes);
      unsigned char *next = bytes + len;
      if (type != JV_CLASS_ATTR)
	{
	  bytes = next;
	  continue;
	}
      int kind = read_u1 (bytes, next);
      if (kind != JV_INNER_CLASSES_KIND)
	{
	  bytes = next;
	  continue;
	}
      return save - reflection_data;
    }
  return -1;
}

jint
java::lang::Class::findDeclaredClasses(JArray<jclass> *result,
				       jboolean publicOnly,
				       jint offset)
{
  unsigned char *bytes = reflection_data + offset;
  int len = read_4 (bytes);
  unsigned char *next = bytes + len;
  // Skip a byte.
  read_u1 (bytes, next);
  int n_classes = read_u2 (bytes, next);
  int count = 0;
  for (int i = 0; i < n_classes; ++i)
    {
      int inner_class_index = read_u2 (bytes, next);
      int outer_class_index = read_u2 (bytes, next);
      /*int inner_name_index = */ read_u2 (bytes, next);
      int inner_flags = read_u2 (bytes, next);

      if (inner_class_index == 0 || outer_class_index == 0)
	continue;
      if (resolve_class_constant (this, &constants, outer_class_index) == this)
	{
	  jclass inner = resolve_class_constant (this, &constants,
						 inner_class_index);
	  if (! publicOnly
	      || ((inner_flags
		   & java::lang::reflect::Modifier::PUBLIC) != 0))
	    {
	      if (result)
		{
		  jclass *elts = elements (result);
		  elts[count] = inner;
		}
	      ++count;
	    }
	}
    }

  return count;
}

JArray<jclass> *
java::lang::Class::getDeclaredClasses (jboolean publicOnly)
{
  int offset = findInnerClassAttribute();
  int count;
  if (offset == -1)
    {
      // No InnerClasses attribute, so no declared classes.
      count = 0;
    }
  else
    count = findDeclaredClasses(NULL, publicOnly, offset);
  JArray<jclass> *result
    = (JArray<jclass> *) JvNewObjectArray (count, &java::lang::Class::class$,
					   NULL);
  if (count > 0)
    findDeclaredClasses(result, publicOnly, offset);
  return result;
}

jclass
java::lang::Class::getDeclaringClass (void)
{
  int offset = findInnerClassAttribute();
  if (offset == -1)
    return NULL;

  unsigned char *bytes = reflection_data + offset;
  int len = read_4 (bytes);
  unsigned char *next = bytes + len;
  // Skip a byte.
  read_u1 (bytes, next);
  int n_classes = read_u2 (bytes, next);
  for (int i = 0; i < n_classes; ++i)
    {
      int inner_class_index = read_u2 (bytes, next);
      int outer_class_index = read_u2 (bytes, next);
      /*int inner_name_index = */read_u2 (bytes, next);
      /*int inner_flags = */read_u2 (bytes, next);

      if (inner_class_index == 0 || outer_class_index == 0)
	continue;
      if (resolve_class_constant (this, &constants, inner_class_index) == this)
	return resolve_class_constant (this, &constants, outer_class_index);
    }

  return NULL;
}

jboolean
java::lang::Class::isAnonymousClass()
{
  int offset = findInnerClassAttribute();
  if (offset == -1)
    return false;

  unsigned char *bytes = reflection_data + offset;
  int len = read_4 (bytes);
  unsigned char *next = bytes + len;
  // Skip a byte.
  read_u1 (bytes, next);
  int n_classes = read_u2 (bytes, next);
  for (int i = 0; i < n_classes; ++i)
    {
      int inner_class_index = read_u2 (bytes, next);
      /*int outer_class_index = */read_u2 (bytes, next);
      int inner_name_index = read_u2 (bytes, next);
      /*int inner_flags = */read_u2 (bytes, next);

      if (inner_class_index == 0)
	continue;
      if (resolve_class_constant (this, &constants, inner_class_index) == this)
	return inner_name_index == 0;
    }

  return false;
}

jboolean
java::lang::Class::isLocalClass()
{
  _Jv_word indexes;
  indexes.i = getEnclosingMethodData();
  return indexes.i != 0;
}

jboolean
java::lang::Class::isMemberClass()
{
  // FIXME: is this correct?
  return !isLocalClass() && getDeclaringClass() != NULL;
}



//
// Some class-related convenience functions.
//

// Find a method declared in the class.  If it is not declared locally
// (or if it is inherited), return NULL.
_Jv_Method *
_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
		    _Jv_Utf8Const *signature)
{
  for (int i = 0; i < klass->method_count; ++i)
    {
      if (_Jv_equalUtf8Consts (name, klass->methods[i].name)
	  && _Jv_equalUtf8Consts (signature, klass->methods[i].signature))
	return &klass->methods[i];
    }
  return NULL;
}

_Jv_Method *
_Jv_LookupDeclaredMethod (jclass klass, _Jv_Utf8Const *name,
                          _Jv_Utf8Const *signature,
			  jclass *declarer_result)
{
  for (; klass; klass = klass->getSuperclass())
    {
      _Jv_Method *meth = _Jv_GetMethodLocal (klass, name, signature);

      if (meth)
	{
	  if (declarer_result)
	    *declarer_result = klass;
	  return meth;
	}
    }

  return NULL;
}

java::lang::reflect::Method *
_Jv_GetReflectedMethod (jclass klass, _Jv_Utf8Const *name,
		       _Jv_Utf8Const *signature)
{
  for (; klass; klass = klass->getSuperclass())
    {
      _Jv_Method *meth = _Jv_GetMethodLocal (klass, name, signature);
      if (meth)
	{
	  using namespace java::lang::reflect;
	  Method *rmethod = new Method ();
	  rmethod->offset = (char*) meth - (char*) klass->methods;
	  rmethod->declaringClass = klass;
	  return rmethod;
	}
    }
  
  return NULL;
}

#ifdef HAVE_TLS

// NOTE: MCACHE_SIZE should be a power of 2 minus one.
#define MCACHE_SIZE 31

struct _Jv_mcache
{
  jclass klass;
  _Jv_Method *method;
};

static __thread _Jv_mcache *method_cache;
#endif // HAVE_TLS

static void *
_Jv_FindMethodInCache (jclass klass MAYBE_UNUSED,
		       _Jv_Utf8Const *name MAYBE_UNUSED,
		       _Jv_Utf8Const *signature MAYBE_UNUSED)
{
#ifdef HAVE_TLS
  _Jv_mcache *cache = method_cache;
  if (cache)
    {
      int index = name->hash16 () & MCACHE_SIZE;
      _Jv_mcache *mc = &cache[index];
      _Jv_Method *m = mc->method;

      if (mc->klass == klass
	  && _Jv_equalUtf8Consts (m->name, name)
	  && _Jv_equalUtf8Consts (m->signature, signature))
	return mc->method->ncode;
    }
#endif // HAVE_TLS
  return NULL;
}

static void
_Jv_AddMethodToCache (jclass klass MAYBE_UNUSED,
		      _Jv_Method *method MAYBE_UNUSED)
{
#ifdef HAVE_TLS
  if (method_cache == NULL)
    method_cache = (_Jv_mcache *) _Jv_MallocUnchecked((MCACHE_SIZE + 1)
						      * sizeof (_Jv_mcache));
  // If the allocation failed, just keep going.
  if (method_cache != NULL)
    {
      int index = method->name->hash16 () & MCACHE_SIZE;
      method_cache[index].method = method;
      method_cache[index].klass = klass;
    }
#endif // HAVE_TLS
}

// Free this thread's method cache.  We explicitly manage this memory
// as the GC does not yet know how to scan TLS on all platforms.
void
_Jv_FreeMethodCache ()
{
#ifdef HAVE_TLS
  if (method_cache != NULL)
    {
      _Jv_Free(method_cache);
      method_cache = NULL;
    }
#endif // HAVE_TLS
}

void *
_Jv_LookupInterfaceMethod (jclass klass, _Jv_Utf8Const *name,
                           _Jv_Utf8Const *signature)
{
  using namespace java::lang::reflect;

  void *ncode = _Jv_FindMethodInCache (klass, name, signature);
  if (ncode != 0)
    return ncode;

  for (; klass; klass = klass->getSuperclass())
    {
      _Jv_Method *meth = _Jv_GetMethodLocal (klass, name, signature);
      if (! meth)
        continue;

      if (Modifier::isStatic(meth->accflags))
	throw new java::lang::IncompatibleClassChangeError
	  (_Jv_GetMethodString (klass, meth));
      if (Modifier::isAbstract(meth->accflags))
	throw new java::lang::AbstractMethodError
	  (_Jv_GetMethodString (klass, meth));
      if (! Modifier::isPublic(meth->accflags))
	throw new java::lang::IllegalAccessError
	  (_Jv_GetMethodString (klass, meth));

      _Jv_AddMethodToCache (klass, meth);

      return meth->ncode;
    }
  throw new java::lang::IncompatibleClassChangeError;
}

// Fast interface method lookup by index.
void *
_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, int method_idx)
{
  _Jv_IDispatchTable *cldt = klass->idt;
  int idx = iface->ioffsets[cldt->iindex] + method_idx;
  return cldt->itable[idx];
}

jboolean
_Jv_IsAssignableFrom (jclass source, jclass target)
{
  if (source == target)
    return true;

  // If target is array, so must source be.  
  while (target->isArray ())
    {
      if (! source->isArray())
	return false;
      target = target->getComponentType();
      source = source->getComponentType();
    }

  if (target->isInterface())
    {
      // Abstract classes have no IDT, and IDTs provide no way to check
      // two interfaces for assignability.
      if (__builtin_expect 
          (source->idt == NULL || source->isInterface(), false))
        return _Jv_InterfaceAssignableFrom (source, target);

      _Jv_IDispatchTable *cl_idt = source->idt;

      if (__builtin_expect ((target->ioffsets == NULL), false))
	return false; // No class implementing TARGET has been loaded.    
      jshort cl_iindex = cl_idt->iindex;
      if (cl_iindex < target->ioffsets[0])
        {
	  jshort offset = target->ioffsets[cl_iindex];
	  if (offset != -1 && offset < cl_idt->itable_length
	      && cl_idt->itable[offset] == target)
	    return true;
	}
      return false;
    }

  // Primitive TYPE classes are only assignable to themselves.
  if (__builtin_expect (target->isPrimitive() || source->isPrimitive(), false))
    return false;

  if (target == &java::lang::Object::class$)
    return true;
  else if (source->ancestors == NULL || target->ancestors == NULL)
    {
      // We need this case when either SOURCE or TARGET has not has
      // its constant-time tables prepared.

      // At this point we know that TARGET can't be Object, so it is
      // safe to use that as the termination point.
      while (source && source != &java::lang::Object::class$)
	{
	  if (source == target)
	    return true;
	  source = source->getSuperclass();
	}
    }
  else if (source->depth >= target->depth
	   && source->ancestors[source->depth - target->depth] == target)
    return true;

  return false;
}

// Interface type checking, the slow way. Returns TRUE if IFACE is a 
// superinterface of SOURCE. This is used when SOURCE is also an interface,
// or a class with no interface dispatch table.
jboolean
_Jv_InterfaceAssignableFrom (jclass source, jclass iface)
{
  for (int i = 0; i < source->interface_count; i++)
    {
      jclass interface = source->interfaces[i];
      if (iface == interface
          || _Jv_InterfaceAssignableFrom (interface, iface))
        return true;      
    }
    
  if (!source->isInterface()
      && source->superclass 
      && _Jv_InterfaceAssignableFrom (source->superclass, iface))
    return true;
        
  return false;
}

jboolean
_Jv_IsInstanceOf(jobject obj, jclass cl)
{
  if (__builtin_expect (!obj, false))
    return false;
  return _Jv_IsAssignableFrom (JV_CLASS (obj), cl);
}

void *
_Jv_CheckCast (jclass c, jobject obj)
{
  if (__builtin_expect 
      (obj != NULL && ! _Jv_IsAssignableFrom(JV_CLASS (obj), c), false))
    throw new java::lang::ClassCastException
      ((new java::lang::StringBuffer
	(obj->getClass()->getName()))->append
       (JvNewStringUTF(" cannot be cast to "))->append
       (c->getName())->toString());

  return obj;
}

void
_Jv_CheckArrayStore (jobject arr, jobject obj)
{
  if (obj)
    {
      JvAssert (arr != NULL);
      jclass elt_class = (JV_CLASS (arr))->getComponentType();
      if (elt_class == &java::lang::Object::class$)
	return;
      jclass obj_class = JV_CLASS (obj);
      if (__builtin_expect 
          (! _Jv_IsAssignableFrom (obj_class, elt_class), false))
	throw new java::lang::ArrayStoreException
		((new java::lang::StringBuffer
		 (JvNewStringUTF("Cannot store ")))->append
		 (obj_class->getName())->append
		 (JvNewStringUTF(" in array of type "))->append
		 (elt_class->getName())->toString());
    }
}

jboolean
_Jv_IsAssignableFromSlow (jclass source, jclass target)
{
  // First, strip arrays.
  while (target->isArray ())
    {
      // If target is array, source must be as well.
      if (! source->isArray ())
       return false;
      target = target->getComponentType ();
      source = source->getComponentType ();
    }

  // Quick success.
  if (target == &java::lang::Object::class$)
    return true;

  // Ensure that the classes have their supers installed.
  _Jv_Linker::wait_for_state (source, JV_STATE_LOADING);
  _Jv_Linker::wait_for_state (target, JV_STATE_LOADING);

  do
    {
      if (source == target)
       return true;

      if (target->isPrimitive () || source->isPrimitive ())
       return false;

      if (target->isInterface ())
       {
         for (int i = 0; i < source->interface_count; ++i)
           {
             // We use a recursive call because we also need to
             // check superinterfaces.
             if (_Jv_IsAssignableFromSlow (source->getInterface (i), target))
               return true;
           }
       }
      source = source->getSuperclass ();
    }
  while (source != NULL);

  return false;
}

// Lookup an interface method by name.  This is very similar to
// purpose to _getMethod, but the interfaces are quite different.  It
// might be a good idea for _getMethod to call this function.
//
// Return true of the method is found, with the class in FOUND_CLASS
// and the index in INDEX.
bool
_Jv_getInterfaceMethod (jclass search_class, jclass &found_class, int &index,
			const _Jv_Utf8Const *utf_name,  
			const _Jv_Utf8Const *utf_sig)
{
   for (jclass klass = search_class; klass; klass = klass->getSuperclass())
    {
      // FIXME: Throw an exception?
      if (!klass->isInterface ())
	return false;
      
      int max = klass->method_count;
      int offset = 0;
      for (int i = 0; i < max; ++i)
	{
	  // Skip <clinit> here, as it will not be in the IDT.
	  if (klass->methods[i].name->first() == '<')
	    continue;

	  if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
	      && _Jv_equalUtf8Consts (klass->methods[i].signature, utf_sig))
	    {
	      // Found it.
	      using namespace java::lang::reflect;

	      // FIXME: Method must be public.  Throw an exception?
	      if (! Modifier::isPublic (klass->methods[i].accflags))
		break;

	      found_class = klass;
	      // Interface method indexes count from 1.
	      index = offset + 1;
	      return true;
	    }

	  ++offset;
	}
    }

  // If we haven't found a match, and this class is an interface, then
  // check all the superinterfaces.
  if (search_class->isInterface())
    {
      for (int i = 0; i < search_class->interface_count; ++i)
	{
	  using namespace java::lang::reflect;
	  bool found = _Jv_getInterfaceMethod (search_class->interfaces[i], 
					       found_class, index,
					       utf_name, utf_sig);
	  if (found)
	    return true;
	}
    }

  return false;
}

#ifdef INTERPRETER
_Jv_MethodBase *
_Jv_FindInterpreterMethod (jclass klass, jmethodID desired_method)
{
  using namespace java::lang::reflect;

  _Jv_InterpClass *iclass
    = reinterpret_cast<_Jv_InterpClass *> (klass->aux_info);
  _Jv_MethodBase **imethods = _Jv_GetFirstMethod (iclass);

  for (int i = 0; i < JvNumMethods (klass); ++i)
    {
      _Jv_MethodBase *imeth = imethods[i];
      if (imeth->get_method () == desired_method)
	return imeth;
    }

  return NULL;
}
#endif

// Return Utf8 name of a class. This function is here for code that
// can't access klass->name directly.
_Jv_Utf8Const*
_Jv_GetClassNameUtf8 (jclass klass)
{
  return klass->name;
}

jclass
_Jv_GetMethodDeclaringClass (jmethodID method)
{
  _Jv_StackTrace::UpdateNCodeMap ();
  jobject obj = reinterpret_cast<jobject> (method->ncode);
  return reinterpret_cast<jclass> (_Jv_StackTrace::ncodeMap->get (obj));
}

jbyte
_Jv_GetClassState (jclass klass)
{
  return klass->state;
}

#ifdef INTERPRETER
jstring
_Jv_GetInterpClassSourceFile (jclass klass)
{
  if (_Jv_IsInterpretedClass (klass))
    {
      _Jv_InterpClass *iclass =
	reinterpret_cast<_Jv_InterpClass *> (klass->aux_info);
      return iclass->source_file_name;
    }

  return NULL;
}
#endif