OSDN Git Service

2001-05-18 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / natClass.cc
1 // natClass.cc - Implementation of java.lang.Class native methods.
2
3 /* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #include <config.h>
12
13 #include <limits.h>
14 #include <string.h>
15
16 #pragma implementation "Class.h"
17
18 #include <gcj/cni.h>
19 #include <jvm.h>
20 #include <java-threads.h>
21
22 #include <java/lang/Class.h>
23 #include <java/lang/ClassLoader.h>
24 #include <java/lang/String.h>
25 #include <java/lang/reflect/Modifier.h>
26 #include <java/lang/reflect/Member.h>
27 #include <java/lang/reflect/Method.h>
28 #include <java/lang/reflect/Field.h>
29 #include <java/lang/reflect/Constructor.h>
30 #include <java/lang/AbstractMethodError.h>
31 #include <java/lang/ArrayStoreException.h>
32 #include <java/lang/ClassCastException.h>
33 #include <java/lang/ClassNotFoundException.h>
34 #include <java/lang/ExceptionInInitializerError.h>
35 #include <java/lang/IllegalAccessException.h>
36 #include <java/lang/IllegalAccessError.h>
37 #include <java/lang/IncompatibleClassChangeError.h>
38 #include <java/lang/InstantiationException.h>
39 #include <java/lang/NoClassDefFoundError.h>
40 #include <java/lang/NoSuchFieldException.h>
41 #include <java/lang/NoSuchMethodError.h>
42 #include <java/lang/NoSuchMethodException.h>
43 #include <java/lang/Thread.h>
44 #include <java/lang/NullPointerException.h>
45 #include <java/lang/System.h>
46 #include <java/lang/SecurityManager.h>
47 #include <java/lang/StringBuffer.h>
48 #include <gcj/method.h>
49
50 #include <java-cpool.h>
51
52 \f
53
54 // FIXME: remove these.
55 #define CloneableClass java::lang::Cloneable::class$
56 #define ObjectClass java::lang::Object::class$
57 #define ErrorClass java::lang::Error::class$
58 #define ClassClass java::lang::Class::class$
59 #define MethodClass java::lang::reflect::Method::class$
60 #define FieldClass java::lang::reflect::Field::class$
61 #define ConstructorClass java::lang::reflect::Constructor::class$
62
63 // Some constants we use to look up the class initializer.
64 static _Jv_Utf8Const *void_signature = _Jv_makeUtf8Const ("()V", 3);
65 static _Jv_Utf8Const *clinit_name = _Jv_makeUtf8Const ("<clinit>", 8);
66 static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
67 static _Jv_Utf8Const *finit_name = _Jv_makeUtf8Const ("finit$", 6);
68 // The legacy `$finit$' method name, which still needs to be
69 // recognized as equivalent to the now prefered `finit$' name.
70 static _Jv_Utf8Const *finit_leg_name = _Jv_makeUtf8Const ("$finit$", 7);
71
72 \f
73
74 jclass
75 java::lang::Class::forName (jstring className, jboolean initialize,
76                             java::lang::ClassLoader *loader)
77 {
78   if (! className)
79     throw new java::lang::NullPointerException;
80
81   jsize length = _Jv_GetStringUTFLength (className);
82   char buffer[length];
83   _Jv_GetStringUTFRegion (className, 0, length, buffer);
84
85   // FIXME: should check syntax of CLASSNAME and throw
86   // IllegalArgumentException on failure.
87   _Jv_Utf8Const *name = _Jv_makeUtf8Const (buffer, length);
88
89   // FIXME: should use bootstrap class loader if loader is null.
90   jclass klass = (buffer[0] == '[' 
91                   ? _Jv_FindClassFromSignature (name->data, loader)
92                   : _Jv_FindClass (name, loader));
93
94   if (klass == NULL)
95     throw new java::lang::ClassNotFoundException (className);
96
97   if (initialize)
98     _Jv_InitClass (klass);
99
100   return klass;
101 }
102
103 jclass
104 java::lang::Class::forName (jstring className)
105 {
106   // FIXME: should use class loader from calling method.
107   return forName (className, true, NULL);
108 }
109
110 java::lang::reflect::Constructor *
111 java::lang::Class::getConstructor (JArray<jclass> *param_types)
112 {
113   jstring partial_sig = getSignature (param_types, true);
114   jint hash = partial_sig->hashCode ();
115
116   int i = isPrimitive () ? 0 : method_count;
117   while (--i >= 0)
118     {
119       // FIXME: access checks.
120       if (_Jv_equalUtf8Consts (methods[i].name, init_name)
121           && _Jv_equal (methods[i].signature, partial_sig, hash))
122         {
123           // Found it.  For getConstructor, the constructor must be
124           // public.
125           using namespace java::lang::reflect;
126           if (! Modifier::isPublic(methods[i].accflags))
127             break;
128           Constructor *cons = new Constructor ();
129           cons->offset = (char *) (&methods[i]) - (char *) methods;
130           cons->declaringClass = this;
131           return cons;
132         }
133     }
134   throw new java::lang::NoSuchMethodException;
135 }
136
137 JArray<java::lang::reflect::Constructor *> *
138 java::lang::Class::_getConstructors (jboolean declared)
139 {
140   // FIXME: this method needs access checks.
141
142   int numConstructors = 0;
143   int max = isPrimitive () ? 0 : method_count;
144   int i;
145   for (i = max; --i >= 0; )
146     {
147       _Jv_Method *method = &methods[i];
148       if (method->name == NULL
149           || ! _Jv_equalUtf8Consts (method->name, init_name))
150         continue;
151       if (! declared
152           && ! java::lang::reflect::Modifier::isPublic(method->accflags))
153         continue;
154       numConstructors++;
155     }
156   JArray<java::lang::reflect::Constructor *> *result
157     = (JArray<java::lang::reflect::Constructor *> *)
158     JvNewObjectArray (numConstructors, &ConstructorClass, NULL);
159   java::lang::reflect::Constructor** cptr = elements (result);
160   for (i = 0;  i < max;  i++)
161     {
162       _Jv_Method *method = &methods[i];
163       if (method->name == NULL
164           || ! _Jv_equalUtf8Consts (method->name, init_name))
165         continue;
166       if (! declared
167           && ! java::lang::reflect::Modifier::isPublic(method->accflags))
168         continue;
169       java::lang::reflect::Constructor *cons
170         = new java::lang::reflect::Constructor ();
171       cons->offset = (char *) method - (char *) methods;
172       cons->declaringClass = this;
173       *cptr++ = cons;
174     }
175   return result;
176 }
177
178 java::lang::reflect::Constructor *
179 java::lang::Class::getDeclaredConstructor (JArray<jclass> *param_types)
180 {
181   jstring partial_sig = getSignature (param_types, true);
182   jint hash = partial_sig->hashCode ();
183
184   int i = isPrimitive () ? 0 : method_count;
185   while (--i >= 0)
186     {
187       // FIXME: access checks.
188       if (_Jv_equalUtf8Consts (methods[i].name, init_name)
189           && _Jv_equal (methods[i].signature, partial_sig, hash))
190         {
191           // Found it.
192           using namespace java::lang::reflect;
193           Constructor *cons = new Constructor ();
194           cons->offset = (char *) (&methods[i]) - (char *) methods;
195           cons->declaringClass = this;
196           return cons;
197         }
198     }
199   throw new java::lang::NoSuchMethodException;
200 }
201
202 java::lang::reflect::Field *
203 java::lang::Class::getField (jstring name, jint hash)
204 {
205   java::lang::reflect::Field* rfield;
206   for (int i = 0;  i < field_count;  i++)
207     {
208       _Jv_Field *field = &fields[i];
209       if (! _Jv_equal (field->name, name, hash))
210         continue;
211       if (! (field->getModifiers() & java::lang::reflect::Modifier::PUBLIC))
212         continue;
213       rfield = new java::lang::reflect::Field ();
214       rfield->offset = (char*) field - (char*) fields;
215       rfield->declaringClass = this;
216       rfield->name = name;
217       return rfield;
218     }
219   jclass superclass = getSuperclass();
220   if (superclass == NULL)
221     return NULL;
222   rfield = superclass->getField(name, hash);
223   for (int i = 0; i < interface_count && rfield == NULL; ++i)
224     rfield = interfaces[i]->getField (name, hash);
225   return rfield;
226 }
227
228 java::lang::reflect::Field *
229 java::lang::Class::getDeclaredField (jstring name)
230 {
231   java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
232   if (s != NULL)
233     s->checkMemberAccess (this, java::lang::reflect::Member::DECLARED);
234   int hash = name->hashCode();
235   for (int i = 0;  i < field_count;  i++)
236     {
237       _Jv_Field *field = &fields[i];
238       if (! _Jv_equal (field->name, name, hash))
239         continue;
240       java::lang::reflect::Field* rfield = new java::lang::reflect::Field ();
241       rfield->offset = (char*) field - (char*) fields;
242       rfield->declaringClass = this;
243       rfield->name = name;
244       return rfield;
245     }
246   throw new java::lang::NoSuchFieldException (name);
247 }
248
249 JArray<java::lang::reflect::Field *> *
250 java::lang::Class::getDeclaredFields (void)
251 {
252   java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
253   if (s != NULL)
254     s->checkMemberAccess (this, java::lang::reflect::Member::DECLARED);
255   JArray<java::lang::reflect::Field *> *result
256     = (JArray<java::lang::reflect::Field *> *)
257     JvNewObjectArray (field_count, &FieldClass, NULL);
258   java::lang::reflect::Field** fptr = elements (result);
259   for (int i = 0;  i < field_count;  i++)
260     {
261       _Jv_Field *field = &fields[i];
262       java::lang::reflect::Field* rfield = new java::lang::reflect::Field ();
263       rfield->offset = (char*) field - (char*) fields;
264       rfield->declaringClass = this;
265       *fptr++ = rfield;
266     }
267   return result;
268 }
269
270 void
271 java::lang::Class::getSignature (java::lang::StringBuffer *buffer)
272 {
273   if (isPrimitive())
274     buffer->append((jchar) method_count);
275   else
276     {
277       jstring name = getName();
278       if (name->charAt(0) != '[')
279         buffer->append((jchar) 'L');
280       buffer->append(name);
281       if (name->charAt(0) != '[')
282         buffer->append((jchar) ';');
283     }
284 }
285
286 // This doesn't have to be native.  It is an implementation detail
287 // only called from the C++ code, though, so maybe this is clearer.
288 jstring
289 java::lang::Class::getSignature (JArray<jclass> *param_types,
290                                  jboolean is_constructor)
291 {
292   java::lang::StringBuffer *buf = new java::lang::StringBuffer ();
293   buf->append((jchar) '(');
294   jclass *v = elements (param_types);
295   // A NULL param_types means "no parameters".
296   if (param_types != NULL)
297     {
298       for (int i = 0; i < param_types->length; ++i)
299         v[i]->getSignature(buf);
300     }
301   buf->append((jchar) ')');
302   if (is_constructor)
303     buf->append((jchar) 'V');
304   return buf->toString();
305 }
306
307 java::lang::reflect::Method *
308 java::lang::Class::getDeclaredMethod (jstring name,
309                                       JArray<jclass> *param_types)
310 {
311   jstring partial_sig = getSignature (param_types, false);
312   jint p_len = partial_sig->length();
313   _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
314   int i = isPrimitive () ? 0 : method_count;
315   while (--i >= 0)
316     {
317       // FIXME: access checks.
318       if (_Jv_equalUtf8Consts (methods[i].name, utf_name)
319           && _Jv_equaln (methods[i].signature, partial_sig, p_len))
320         {
321           // Found it.
322           using namespace java::lang::reflect;
323           Method *rmethod = new Method ();
324           rmethod->offset = (char*) (&methods[i]) - (char*) methods;
325           rmethod->declaringClass = this;
326           return rmethod;
327         }
328     }
329   throw new java::lang::NoSuchMethodException;
330 }
331
332 JArray<java::lang::reflect::Method *> *
333 java::lang::Class::getDeclaredMethods (void)
334 {
335   int numMethods = 0;
336   int max = isPrimitive () ? 0 : method_count;
337   int i;
338   for (i = max; --i >= 0; )
339     {
340       _Jv_Method *method = &methods[i];
341       if (method->name == NULL
342           || _Jv_equalUtf8Consts (method->name, clinit_name)
343           || _Jv_equalUtf8Consts (method->name, init_name)
344           || _Jv_equalUtf8Consts (method->name, finit_name)
345           // Backward compatibility hack: match the legacy `$finit$' name
346           || _Jv_equalUtf8Consts (method->name, finit_leg_name))
347         continue;
348       numMethods++;
349     }
350   JArray<java::lang::reflect::Method *> *result
351     = (JArray<java::lang::reflect::Method *> *)
352     JvNewObjectArray (numMethods, &MethodClass, NULL);
353   java::lang::reflect::Method** mptr = elements (result);
354   for (i = 0;  i < max;  i++)
355     {
356       _Jv_Method *method = &methods[i];
357       if (method->name == NULL
358           || _Jv_equalUtf8Consts (method->name, clinit_name)
359           || _Jv_equalUtf8Consts (method->name, init_name)
360           || _Jv_equalUtf8Consts (method->name, finit_name)
361           // Backward compatibility hack: match the legacy `$finit$' name
362           || _Jv_equalUtf8Consts (method->name, finit_leg_name))
363         continue;
364       java::lang::reflect::Method* rmethod
365         = new java::lang::reflect::Method ();
366       rmethod->offset = (char*) method - (char*) methods;
367       rmethod->declaringClass = this;
368       *mptr++ = rmethod;
369     }
370   return result;
371 }
372
373 jstring
374 java::lang::Class::getName (void)
375 {
376   char buffer[name->length + 1];  
377   memcpy (buffer, name->data, name->length); 
378   buffer[name->length] = '\0';
379   return _Jv_NewStringUTF (buffer);
380 }
381
382 JArray<jclass> *
383 java::lang::Class::getClasses (void)
384 {
385   // Until we have inner classes, it always makes sense to return an
386   // empty array.
387   JArray<jclass> *result
388     = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
389   return result;
390 }
391
392 JArray<jclass> *
393 java::lang::Class::getDeclaredClasses (void)
394 {
395   checkMemberAccess (java::lang::reflect::Member::DECLARED);
396   // Until we have inner classes, it always makes sense to return an
397   // empty array.
398   JArray<jclass> *result
399     = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
400   return result;
401 }
402
403 jclass
404 java::lang::Class::getDeclaringClass (void)
405 {
406   // Until we have inner classes, it makes sense to always return
407   // NULL.
408   return NULL;
409 }
410
411 jint
412 java::lang::Class::_getFields (JArray<java::lang::reflect::Field *> *result,
413                                jint offset)
414 {
415   int count = 0;
416   for (int i = 0;  i < field_count;  i++)
417     {
418       _Jv_Field *field = &fields[i];
419       if (! (field->getModifiers() & java::lang::reflect::Modifier::PUBLIC))
420         continue;
421       ++count;
422
423       if (result != NULL)
424         {
425           java::lang::reflect::Field *rfield
426             = new java::lang::reflect::Field ();
427           rfield->offset = (char *) field - (char *) fields;
428           rfield->declaringClass = this;
429           rfield->name = _Jv_NewStringUtf8Const (field->name);
430           (elements (result))[offset++] = rfield;
431         }
432     }
433   jclass superclass = getSuperclass();
434   if (superclass != NULL)
435     {
436       int s_count = superclass->_getFields (result, offset);
437       count += s_count;
438       offset += s_count;
439     }
440   for (int i = 0; i < interface_count; ++i)
441     {
442       int f_count = interfaces[i]->_getFields (result, offset);
443       count += f_count;
444       offset += f_count;
445     }
446   return count;
447 }
448
449 JArray<java::lang::reflect::Field *> *
450 java::lang::Class::getFields (void)
451 {
452   using namespace java::lang::reflect;
453
454   int count = _getFields (NULL, 0);
455
456   JArray<java::lang::reflect::Field *> *result
457     = ((JArray<java::lang::reflect::Field *> *)
458        JvNewObjectArray (count, &FieldClass, NULL));
459
460   _getFields (result, 0);
461
462   return result;
463 }
464
465 JArray<jclass> *
466 java::lang::Class::getInterfaces (void)
467 {
468   jobjectArray r = JvNewObjectArray (interface_count, getClass (), NULL);
469   jobject *data = elements (r);
470   for (int i = 0; i < interface_count; ++i)
471     data[i] = interfaces[i];
472   return reinterpret_cast<JArray<jclass> *> (r);
473 }
474
475 java::lang::reflect::Method *
476 java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
477 {
478   jstring partial_sig = getSignature (param_types, false);
479   jint p_len = partial_sig->length();
480   _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
481   for (Class *klass = this; klass; klass = klass->getSuperclass())
482     {
483       int i = klass->isPrimitive () ? 0 : klass->method_count;
484       while (--i >= 0)
485         {
486           // FIXME: access checks.
487           if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
488               && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len))
489             {
490               // Found it.
491               using namespace java::lang::reflect;
492
493               // Method must be public.
494               if (! Modifier::isPublic (klass->methods[i].accflags))
495                 break;
496
497               Method *rmethod = new Method ();
498               rmethod->offset = ((char *) (&klass->methods[i])
499                                  - (char *) klass->methods);
500               rmethod->declaringClass = klass;
501               return rmethod;
502             }
503         }
504     }
505   throw new java::lang::NoSuchMethodException;
506 }
507
508 // This is a very slow implementation, since it re-scans all the
509 // methods we've already listed to make sure we haven't duplicated a
510 // method.  It also over-estimates the required size, so we have to
511 // shrink the result array later.
512 jint
513 java::lang::Class::_getMethods (JArray<java::lang::reflect::Method *> *result,
514                                 jint offset)
515 {
516   jint count = 0;
517
518   // First examine all local methods
519   for (int i = isPrimitive () ? 0 : method_count; --i >= 0; )
520     {
521       _Jv_Method *method = &methods[i];
522       if (method->name == NULL
523           || _Jv_equalUtf8Consts (method->name, clinit_name)
524           || _Jv_equalUtf8Consts (method->name, init_name)
525           || _Jv_equalUtf8Consts (method->name, finit_name)
526           // Backward compatibility hack: match the legacy `$finit$' name
527           || _Jv_equalUtf8Consts (method->name, finit_leg_name))
528         continue;
529       // Only want public methods.
530       if (! java::lang::reflect::Modifier::isPublic (method->accflags))
531         continue;
532
533       // This is where we over-count the slots required if we aren't
534       // filling the result for real.
535       if (result != NULL)
536         {
537           jboolean add = true;
538           java::lang::reflect::Method **mp = elements (result);
539           // If we already have a method with this name and signature,
540           // then ignore this one.  This can happen with virtual
541           // methods.
542           for (int j = 0; j < offset; ++j)
543             {
544               _Jv_Method *meth_2 = _Jv_FromReflectedMethod (mp[j]);
545               if (_Jv_equalUtf8Consts (method->name, meth_2->name)
546                   && _Jv_equalUtf8Consts (method->signature,
547                                           meth_2->signature))
548                 {
549                   add = false;
550                   break;
551                 }
552             }
553           if (! add)
554             continue;
555         }
556
557       if (result != NULL)
558         {
559           using namespace java::lang::reflect;
560           Method *rmethod = new Method ();
561           rmethod->offset = (char *) method - (char *) methods;
562           rmethod->declaringClass = this;
563           Method **mp = elements (result);
564           mp[offset + count] = rmethod;
565         }
566       ++count;
567     }
568   offset += count;
569
570   // Now examine superclasses.
571   if (getSuperclass () != NULL)
572     {
573       jint s_count = getSuperclass()->_getMethods (result, offset);
574       offset += s_count;
575       count += s_count;
576     }
577
578   // Finally, examine interfaces.
579   for (int i = 0; i < interface_count; ++i)
580     {
581       int f_count = interfaces[i]->_getMethods (result, offset);
582       count += f_count;
583       offset += f_count;
584     }
585
586   return count;
587 }
588
589 JArray<java::lang::reflect::Method *> *
590 java::lang::Class::getMethods (void)
591 {
592   using namespace java::lang::reflect;
593
594   // FIXME: security checks.
595
596   // This will overestimate the size we need.
597   jint count = _getMethods (NULL, 0);
598
599   JArray<Method *> *result
600     = ((JArray<Method *> *) JvNewObjectArray (count, &MethodClass, NULL));
601
602   // When filling the array for real, we get the actual count.  Then
603   // we resize the array.
604   jint real_count = _getMethods (result, 0);
605
606   if (real_count != count)
607     {
608       JArray<Method *> *r2
609         = ((JArray<Method *> *) JvNewObjectArray (real_count, &MethodClass,
610                                                   NULL));
611       
612       Method **destp = elements (r2);
613       Method **srcp = elements (result);
614
615       for (int i = 0; i < real_count; ++i)
616         *destp++ = *srcp++;
617
618       result = r2;
619     }
620
621   return result;
622 }
623
624 jboolean
625 java::lang::Class::isAssignableFrom (jclass klass)
626 {
627   // Arguments may not have been initialized, given ".class" syntax.
628   _Jv_InitClass (this);
629   _Jv_InitClass (klass);
630   return _Jv_IsAssignableFrom (this, klass);
631 }
632
633 jboolean
634 java::lang::Class::isInstance (jobject obj)
635 {
636   if (__builtin_expect (! obj || isPrimitive (), false))
637     return false;
638   _Jv_InitClass (this);
639   return _Jv_IsAssignableFrom (this, JV_CLASS (obj));
640 }
641
642 jobject
643 java::lang::Class::newInstance (void)
644 {
645   // FIXME: do accessibility checks here.  There currently doesn't
646   // seem to be any way to do these.
647   // FIXME: we special-case one check here just to pass a Plum Hall
648   // test.  Once access checking is implemented, remove this.
649   if (this == &ClassClass)
650     throw new java::lang::IllegalAccessException;
651
652   if (isPrimitive ()
653       || isInterface ()
654       || isArray ()
655       || java::lang::reflect::Modifier::isAbstract(accflags))
656     throw new java::lang::InstantiationException;
657
658   _Jv_InitClass (this);
659
660   _Jv_Method *meth = _Jv_GetMethodLocal (this, init_name, void_signature);
661   if (! meth)
662     throw new java::lang::NoSuchMethodException;
663
664   jobject r = JvAllocObject (this);
665   ((void (*) (jobject)) meth->ncode) (r);
666   return r;
667 }
668
669 void
670 java::lang::Class::finalize (void)
671 {
672 #ifdef INTERPRETER
673   JvAssert (_Jv_IsInterpretedClass (this));
674   _Jv_UnregisterClass (this);
675 #endif
676 }
677
678 // This implements the initialization process for a class.  From Spec
679 // section 12.4.2.
680 void
681 java::lang::Class::initializeClass (void)
682 {
683   // short-circuit to avoid needless locking.
684   if (state == JV_STATE_DONE)
685     return;
686
687   // Step 1.
688   _Jv_MonitorEnter (this);
689
690   if (state < JV_STATE_LINKED)
691     {    
692 #ifdef INTERPRETER
693       if (_Jv_IsInterpretedClass (this))
694         {
695           // this can throw exceptions, so exit the monitor as a precaution.
696           _Jv_MonitorExit (this);
697           java::lang::ClassLoader::resolveClass0 (this);
698           _Jv_MonitorEnter (this);
699         }
700       else
701 #endif
702         {
703           _Jv_PrepareCompiledClass (this);
704         }
705     }
706   
707   if (state <= JV_STATE_LINKED)
708     _Jv_PrepareConstantTimeTables (this);
709
710   // Step 2.
711   java::lang::Thread *self = java::lang::Thread::currentThread();
712   // FIXME: `self' can be null at startup.  Hence this nasty trick.
713   self = (java::lang::Thread *) ((long) self | 1);
714   while (state == JV_STATE_IN_PROGRESS && thread && thread != self)
715     wait ();
716
717   // Steps 3 &  4.
718   if (state == JV_STATE_DONE
719       || state == JV_STATE_IN_PROGRESS
720       || thread == self)
721     {
722       _Jv_MonitorExit (this);
723       return;
724     }
725
726   // Step 5.
727   if (state == JV_STATE_ERROR)
728     {
729       _Jv_MonitorExit (this);
730       throw new java::lang::NoClassDefFoundError;
731     }
732
733   // Step 6.
734   thread = self;
735   state = JV_STATE_IN_PROGRESS;
736   _Jv_MonitorExit (this);
737
738   // Step 7.
739   if (! isInterface () && superclass)
740     {
741       try
742         {
743           _Jv_InitClass (superclass);
744         }
745       catch (java::lang::Throwable *except)
746         {
747           // Caught an exception.
748           _Jv_MonitorEnter (this);
749           state = JV_STATE_ERROR;
750           notifyAll ();
751           _Jv_MonitorExit (this);
752           throw except;
753         }
754     }
755
756   // Steps 8, 9, 10, 11.
757   try
758     {
759       _Jv_Method *meth = _Jv_GetMethodLocal (this, clinit_name,
760                                              void_signature);
761       if (meth)
762         ((void (*) (void)) meth->ncode) ();
763     }
764   catch (java::lang::Throwable *except)
765     {
766       if (! ErrorClass.isInstance(except))
767         {
768           try
769             {
770               except = new ExceptionInInitializerError (except);
771             }
772           catch (java::lang::Throwable *t)
773             {
774               except = t;
775             }
776         }
777       _Jv_MonitorEnter (this);
778       state = JV_STATE_ERROR;
779       notifyAll ();
780       _Jv_MonitorExit (this);
781       throw except;
782     }
783
784   _Jv_MonitorEnter (this);
785   state = JV_STATE_DONE;
786   notifyAll ();
787   _Jv_MonitorExit (this);
788 }
789
790 \f
791
792 //
793 // Some class-related convenience functions.
794 //
795
796 // Find a method declared in the class.  If it is not declared locally
797 // (or if it is inherited), return NULL.
798 _Jv_Method *
799 _Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
800                     _Jv_Utf8Const *signature)
801 {
802   for (int i = 0; i < klass->method_count; ++i)
803     {
804       if (_Jv_equalUtf8Consts (name, klass->methods[i].name)
805           && _Jv_equalUtf8Consts (signature, klass->methods[i].signature))
806         return &klass->methods[i];
807     }
808   return NULL;
809 }
810
811 _Jv_Method *
812 _Jv_LookupDeclaredMethod (jclass klass, _Jv_Utf8Const *name,
813                           _Jv_Utf8Const *signature)
814 {
815   for (; klass; klass = klass->getSuperclass())
816     {
817       _Jv_Method *meth = _Jv_GetMethodLocal (klass, name, signature);
818
819       if (meth)
820         return meth;
821     }
822
823   return NULL;
824 }
825
826 // NOTE: MCACHE_SIZE should be a power of 2 minus one.
827 #define MCACHE_SIZE 1023
828
829 struct _Jv_mcache
830 {
831   jclass klass;
832   _Jv_Method *method;
833 };
834
835 static _Jv_mcache method_cache[MCACHE_SIZE + 1];
836
837 static void *
838 _Jv_FindMethodInCache (jclass klass,
839                        _Jv_Utf8Const *name,
840                        _Jv_Utf8Const *signature)
841 {
842   int index = name->hash & MCACHE_SIZE;
843   _Jv_mcache *mc = method_cache + index;
844   _Jv_Method *m = mc->method;
845
846   if (mc->klass == klass
847       && m != NULL             // thread safe check
848       && _Jv_equalUtf8Consts (m->name, name)
849       && _Jv_equalUtf8Consts (m->signature, signature))
850     return mc->method->ncode;
851   return NULL;
852 }
853
854 static void
855 _Jv_AddMethodToCache (jclass klass,
856                        _Jv_Method *method)
857 {
858   _Jv_MonitorEnter (&ClassClass); 
859
860   int index = method->name->hash & MCACHE_SIZE;
861
862   method_cache[index].method = method;
863   method_cache[index].klass = klass;
864
865   _Jv_MonitorExit (&ClassClass);
866 }
867
868 void *
869 _Jv_LookupInterfaceMethod (jclass klass, _Jv_Utf8Const *name,
870                            _Jv_Utf8Const *signature)
871 {
872   using namespace java::lang::reflect;
873
874   void *ncode = _Jv_FindMethodInCache (klass, name, signature);
875   if (ncode != 0)
876     return ncode;
877
878   for (; klass; klass = klass->getSuperclass())
879     {
880       _Jv_Method *meth = _Jv_GetMethodLocal (klass, name, signature);
881       if (! meth)
882         continue;
883
884       if (Modifier::isStatic(meth->accflags))
885         throw new java::lang::IncompatibleClassChangeError
886           (_Jv_GetMethodString (klass, meth->name));
887       if (Modifier::isAbstract(meth->accflags))
888         throw new java::lang::AbstractMethodError
889           (_Jv_GetMethodString (klass, meth->name));
890       if (! Modifier::isPublic(meth->accflags))
891         throw new java::lang::IllegalAccessError
892           (_Jv_GetMethodString (klass, meth->name));
893
894       _Jv_AddMethodToCache (klass, meth);
895
896       return meth->ncode;
897     }
898   throw new java::lang::IncompatibleClassChangeError;
899 }
900
901 // Fast interface method lookup by index.
902 void *
903 _Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, int method_idx)
904 {
905   _Jv_IDispatchTable *cldt = klass->idt;
906   int idx = iface->idt->iface.ioffsets[cldt->cls.iindex] + method_idx;
907   return cldt->cls.itable[idx];
908 }
909
910 jboolean
911 _Jv_IsAssignableFrom (jclass target, jclass source)
912 {
913   if (source == target)
914     return true;
915      
916   // If target is array, so must source be.  
917   if (target->isArray ())
918     {
919       if (! source->isArray())
920         return false;
921       return _Jv_IsAssignableFrom(target->getComponentType(), 
922                                   source->getComponentType());
923     }
924
925   if (target->isInterface())
926     {
927       // Abstract classes have no IDT, and IDTs provide no way to check
928       // two interfaces for assignability.
929       if (__builtin_expect 
930           (source->idt == NULL || source->isInterface(), false))
931         return _Jv_InterfaceAssignableFrom (target, source);
932         
933       _Jv_IDispatchTable *cl_idt = source->idt;
934       _Jv_IDispatchTable *if_idt = target->idt;
935
936       if (__builtin_expect ((if_idt == NULL), false))
937         return false; // No class implementing TARGET has been loaded.    
938       jshort cl_iindex = cl_idt->cls.iindex;
939       if (cl_iindex < if_idt->iface.ioffsets[0])
940         {
941           jshort offset = if_idt->iface.ioffsets[cl_iindex];
942           if (offset < cl_idt->cls.itable_length
943               && cl_idt->cls.itable[offset] == target)
944             return true;
945         }
946       return false;
947     }
948      
949   if ((target == &ObjectClass && !source->isPrimitive())
950       || (source->ancestors != NULL 
951           && source->ancestors[source->depth - target->depth] == target))
952     return true;
953       
954  return false;
955 }
956
957 // Interface type checking, the slow way. Returns TRUE if IFACE is a 
958 // superinterface of SOURCE. This is used when SOURCE is also an interface,
959 // or a class with no interface dispatch table.
960 jboolean
961 _Jv_InterfaceAssignableFrom (jclass iface, jclass source)
962 {
963   for (int i = 0; i < source->interface_count; i++)
964     {
965       jclass interface = source->interfaces[i];
966       if (iface == interface
967           || _Jv_InterfaceAssignableFrom (iface, interface))
968         return true;      
969     }
970     
971   if (!source->isInterface()
972       && source->superclass 
973       && _Jv_InterfaceAssignableFrom (iface, source->superclass))
974     return true;
975         
976   return false;
977 }
978
979 jboolean
980 _Jv_IsInstanceOf(jobject obj, jclass cl)
981 {
982   if (__builtin_expect (!obj, false))
983     return false;
984   return (_Jv_IsAssignableFrom (cl, JV_CLASS (obj)));
985 }
986
987 void *
988 _Jv_CheckCast (jclass c, jobject obj)
989 {
990   if (__builtin_expect 
991        (obj != NULL && ! _Jv_IsAssignableFrom(c, JV_CLASS (obj)), false))
992     throw new java::lang::ClassCastException
993       ((new java::lang::StringBuffer
994         (obj->getClass()->getName()))->append
995        (JvNewStringUTF(" cannot be cast to "))->append
996        (c->getName())->toString());
997
998   return obj;
999 }
1000
1001 void
1002 _Jv_CheckArrayStore (jobject arr, jobject obj)
1003 {
1004   if (obj)
1005     {
1006       JvAssert (arr != NULL);
1007       jclass elt_class = (JV_CLASS (arr))->getComponentType();
1008       jclass obj_class = JV_CLASS (obj);
1009       if (__builtin_expect 
1010           (! _Jv_IsAssignableFrom (elt_class, obj_class), false))
1011         throw new java::lang::ArrayStoreException;
1012     }
1013 }
1014
1015 #define INITIAL_IOFFSETS_LEN 4
1016 #define INITIAL_IFACES_LEN 4
1017
1018 static _Jv_IDispatchTable null_idt = { {SHRT_MAX, 0, NULL} };
1019
1020 // Generate tables for constant-time assignment testing and interface
1021 // method lookup. This implements the technique described by Per Bothner
1022 // <per@bothner.com> on the java-discuss mailing list on 1999-09-02:
1023 // http://gcc.gnu.org/ml/java/1999-q3/msg00377.html
1024 void 
1025 _Jv_PrepareConstantTimeTables (jclass klass)
1026 {  
1027   if (klass->isPrimitive () || klass->isInterface ())
1028     return;
1029   
1030   // Short-circuit in case we've been called already.
1031   if ((klass->idt != NULL) || klass->depth != 0)
1032     return;
1033
1034   // Calculate the class depth and ancestor table. The depth of a class 
1035   // is how many "extends" it is removed from Object. Thus the depth of 
1036   // java.lang.Object is 0, but the depth of java.io.FilterOutputStream 
1037   // is 2. Depth is defined for all regular and array classes, but not 
1038   // interfaces or primitive types.
1039    
1040   jclass klass0 = klass;
1041   jboolean has_interfaces = 0;
1042   while (klass0 != &ObjectClass)
1043     {
1044       has_interfaces += klass0->interface_count;
1045       klass0 = klass0->superclass;
1046       klass->depth++;
1047     }
1048
1049   // We do class member testing in constant time by using a small table 
1050   // of all the ancestor classes within each class. The first element is 
1051   // a pointer to the current class, and the rest are pointers to the 
1052   // classes ancestors, ordered from the current class down by decreasing 
1053   // depth. We do not include java.lang.Object in the table of ancestors, 
1054   // since it is redundant.
1055         
1056   klass->ancestors = (jclass *) _Jv_Malloc (klass->depth * sizeof (jclass));
1057   klass0 = klass;
1058   for (int index = 0; index < klass->depth; index++)
1059     {
1060       klass->ancestors[index] = klass0;
1061       klass0 = klass0->superclass;
1062     }
1063     
1064   if (java::lang::reflect::Modifier::isAbstract (klass->accflags))
1065     return;
1066   
1067   // Optimization: If class implements no interfaces, use a common
1068   // predefined interface table.
1069   if (!has_interfaces)
1070     {
1071       klass->idt = &null_idt;
1072       return;
1073     }
1074
1075   klass->idt = 
1076     (_Jv_IDispatchTable *) _Jv_Malloc (sizeof (_Jv_IDispatchTable));
1077     
1078   _Jv_ifaces ifaces;
1079
1080   ifaces.count = 0;
1081   ifaces.len = INITIAL_IFACES_LEN;
1082   ifaces.list = (jclass *) _Jv_Malloc (ifaces.len * sizeof (jclass *));
1083
1084   int itable_size = _Jv_GetInterfaces (klass, &ifaces);
1085
1086   if (ifaces.count > 0)
1087     {
1088       klass->idt->cls.itable = 
1089         (void **) _Jv_Malloc (itable_size * sizeof (void *));
1090       klass->idt->cls.itable_length = itable_size;
1091           
1092       jshort *itable_offsets = 
1093         (jshort *) _Jv_Malloc (ifaces.count * sizeof (jshort));
1094
1095       _Jv_GenerateITable (klass, &ifaces, itable_offsets);
1096
1097       jshort cls_iindex = 
1098         _Jv_FindIIndex (ifaces.list, itable_offsets, ifaces.count);
1099
1100       for (int i=0; i < ifaces.count; i++)
1101         {
1102           ifaces.list[i]->idt->iface.ioffsets[cls_iindex] =
1103             itable_offsets[i];
1104         }
1105
1106       klass->idt->cls.iindex = cls_iindex;          
1107
1108       _Jv_Free (ifaces.list);
1109       _Jv_Free (itable_offsets);
1110     }
1111   else 
1112     {
1113       klass->idt->cls.iindex = SHRT_MAX;
1114     }
1115 }
1116
1117 // Return index of item in list, or -1 if item is not present.
1118 inline jshort
1119 _Jv_IndexOf (void *item, void **list, jshort list_len)
1120 {
1121   for (int i=0; i < list_len; i++)
1122     {
1123       if (list[i] == item)
1124         return i;
1125     }
1126   return -1;
1127 }
1128
1129 // Find all unique interfaces directly or indirectly implemented by klass.
1130 // Returns the size of the interface dispatch table (itable) for klass, which 
1131 // is the number of unique interfaces plus the total number of methods that 
1132 // those interfaces declare. May extend ifaces if required.
1133 jshort
1134 _Jv_GetInterfaces (jclass klass, _Jv_ifaces *ifaces)
1135 {
1136   jshort result = 0;
1137   
1138   for (int i=0; i < klass->interface_count; i++)
1139     {
1140       jclass iface = klass->interfaces[i];
1141       if (_Jv_IndexOf (iface, (void **) ifaces->list, ifaces->count) == -1)
1142         {
1143           if (ifaces->count + 1 >= ifaces->len)
1144             {
1145               /* Resize ifaces list */
1146               ifaces->len = ifaces->len * 2;
1147               ifaces->list = (jclass *) _Jv_Realloc (ifaces->list, 
1148                              ifaces->len * sizeof(jclass));
1149             }
1150           ifaces->list[ifaces->count] = iface;
1151           ifaces->count++;
1152
1153           result += _Jv_GetInterfaces (klass->interfaces[i], ifaces);
1154         }
1155     }
1156     
1157   if (klass->isInterface())
1158     {
1159       result += klass->method_count + 1;
1160     }
1161   else
1162     {
1163       if (klass->superclass)
1164         {
1165           result += _Jv_GetInterfaces (klass->superclass, ifaces);
1166         }
1167     }
1168   return result;
1169 }
1170
1171 // Fill out itable in klass, resolving method declarations in each ifaces.
1172 // itable_offsets is filled out with the position of each iface in itable,
1173 // such that itable[itable_offsets[n]] == ifaces.list[n].
1174 void
1175 _Jv_GenerateITable (jclass klass, _Jv_ifaces *ifaces, jshort *itable_offsets)
1176 {
1177   void **itable = klass->idt->cls.itable;
1178   jshort itable_pos = 0;
1179
1180   for (int i=0; i < ifaces->count; i++)
1181     { 
1182       jclass iface = ifaces->list[i];
1183       itable_offsets[i] = itable_pos;
1184       itable_pos = _Jv_AppendPartialITable (klass, iface, itable, itable_pos);
1185       
1186       /* Create interface dispatch table for iface */
1187       if (iface->idt == NULL)
1188         {
1189           iface->idt = 
1190             (_Jv_IDispatchTable *) _Jv_Malloc (sizeof (_Jv_IDispatchTable));
1191
1192           // The first element of ioffsets is its length (itself included).
1193           jshort *ioffsets = 
1194             (jshort *) _Jv_Malloc (INITIAL_IOFFSETS_LEN * sizeof (jshort));
1195           ioffsets[0] = INITIAL_IOFFSETS_LEN;
1196           for (int i=1; i < INITIAL_IOFFSETS_LEN; i++)
1197             ioffsets[i] = -1;
1198
1199           iface->idt->iface.ioffsets = ioffsets;            
1200         }
1201     }
1202 }
1203
1204 // Format method name for use in error messages.
1205 jstring
1206 _Jv_GetMethodString (jclass klass, _Jv_Utf8Const *name)
1207 {
1208   jstring r = JvNewStringUTF (klass->name->data);
1209   r = r->concat (JvNewStringUTF ("."));
1210   r = r->concat (JvNewStringUTF (name->data));
1211   return r;
1212 }
1213
1214 void 
1215 _Jv_ThrowNoSuchMethodError ()
1216 {
1217   throw new java::lang::NoSuchMethodError;
1218 }
1219
1220 // Each superinterface of a class (i.e. each interface that the class
1221 // directly or indirectly implements) has a corresponding "Partial
1222 // Interface Dispatch Table" whose size is (number of methods + 1) words.
1223 // The first word is a pointer to the interface (i.e. the java.lang.Class
1224 // instance for that interface).  The remaining words are pointers to the
1225 // actual methods that implement the methods declared in the interface,
1226 // in order of declaration.
1227 //
1228 // Append partial interface dispatch table for "iface" to "itable", at
1229 // position itable_pos.
1230 // Returns the offset at which the next partial ITable should be appended.
1231 jshort
1232 _Jv_AppendPartialITable (jclass klass, jclass iface, void **itable, 
1233                          jshort pos)
1234 {
1235   using namespace java::lang::reflect;
1236
1237   itable[pos++] = (void *) iface;
1238   _Jv_Method *meth;
1239   
1240   for (int j=0; j < iface->method_count; j++)
1241     {
1242       meth = NULL;
1243       for (jclass cl = klass; cl; cl = cl->getSuperclass())
1244         {
1245           meth = _Jv_GetMethodLocal (cl, iface->methods[j].name,
1246                                      iface->methods[j].signature);
1247                  
1248           if (meth)
1249             break;
1250         }
1251
1252       if (meth && (meth->name->data[0] == '<'))
1253         {
1254           // leave a placeholder in the itable for hidden init methods.
1255           itable[pos] = NULL;   
1256         }
1257       else if (meth)
1258         {
1259           if (Modifier::isStatic(meth->accflags))
1260             throw new java::lang::IncompatibleClassChangeError
1261               (_Jv_GetMethodString (klass, meth->name));
1262           if (Modifier::isAbstract(meth->accflags))
1263             throw new java::lang::AbstractMethodError
1264               (_Jv_GetMethodString (klass, meth->name));
1265           if (! Modifier::isPublic(meth->accflags))
1266             throw new java::lang::IllegalAccessError
1267               (_Jv_GetMethodString (klass, meth->name));
1268
1269           itable[pos] = meth->ncode;
1270         }
1271       else
1272         {
1273           // The method doesn't exist in klass. Binary compatibility rules
1274           // permit this, so we delay the error until runtime using a pointer
1275           // to a method which throws an exception.
1276           itable[pos] = (void *) _Jv_ThrowNoSuchMethodError;
1277         }
1278       pos++;
1279     }
1280     
1281   return pos;
1282 }
1283
1284 static _Jv_Mutex_t iindex_mutex;
1285 bool iindex_mutex_initialized = false;
1286
1287 // We need to find the correct offset in the Class Interface Dispatch 
1288 // Table for a given interface. Once we have that, invoking an interface 
1289 // method just requires combining the Method's index in the interface 
1290 // (known at compile time) to get the correct method.  Doing a type test 
1291 // (cast or instanceof) is the same problem: Once we have a possible Partial 
1292 // Interface Dispatch Table, we just compare the first element to see if it 
1293 // matches the desired interface. So how can we find the correct offset?  
1294 // Our solution is to keep a vector of candiate offsets in each interface 
1295 // (idt->iface.ioffsets), and in each class we have an index 
1296 // (idt->cls.iindex) used to select the correct offset from ioffsets.
1297 //
1298 // Calculate and return iindex for a new class. 
1299 // ifaces is a vector of num interfaces that the class implements.
1300 // offsets[j] is the offset in the interface dispatch table for the
1301 // interface corresponding to ifaces[j].
1302 // May extend the interface ioffsets if required.
1303 jshort
1304 _Jv_FindIIndex (jclass *ifaces, jshort *offsets, jshort num)
1305 {
1306   int i;
1307   int j;
1308   
1309   // Acquire a global lock to prevent itable corruption in case of multiple 
1310   // classes that implement an intersecting set of interfaces being linked
1311   // simultaneously. We can assume that the mutex will be initialized
1312   // single-threaded.
1313   if (! iindex_mutex_initialized)
1314     {
1315       _Jv_MutexInit (&iindex_mutex);
1316       iindex_mutex_initialized = true;
1317     }
1318   
1319   _Jv_MutexLock (&iindex_mutex);
1320   
1321   for (i=1;; i++)  /* each potential position in ioffsets */
1322     {
1323       for (j=0;; j++)  /* each iface */
1324         {
1325           if (j >= num)
1326             goto found;
1327           if (i >= ifaces[j]->idt->iface.ioffsets[0])
1328             continue;
1329           int ioffset = ifaces[j]->idt->iface.ioffsets[i];
1330           /* We can potentially share this position with another class. */
1331           if (ioffset >= 0 && ioffset != offsets[j])
1332             break; /* Nope. Try next i. */        
1333         }
1334     }
1335   found:
1336   for (j = 0; j < num; j++)
1337     {
1338       int len = ifaces[j]->idt->iface.ioffsets[0];
1339       if (i >= len) 
1340         {
1341           /* Resize ioffsets. */
1342           int newlen = 2 * len;
1343           if (i >= newlen)
1344             newlen = i + 3;
1345           jshort *old_ioffsets = ifaces[j]->idt->iface.ioffsets;
1346           jshort *new_ioffsets = (jshort *) _Jv_Realloc (old_ioffsets, 
1347                                           newlen * sizeof(jshort));       
1348           new_ioffsets[0] = newlen;
1349
1350           while (len < newlen)
1351             new_ioffsets[len++] = -1;
1352           
1353           ifaces[j]->idt->iface.ioffsets = new_ioffsets;
1354         }
1355       ifaces[j]->idt->iface.ioffsets[i] = offsets[j];
1356     }
1357
1358   _Jv_MutexUnlock (&iindex_mutex);
1359
1360   return i;
1361 }
1362
1363 // Only used by serialization
1364 java::lang::reflect::Field *
1365 java::lang::Class::getPrivateField (jstring name)
1366 {
1367   int hash = name->hashCode ();
1368
1369   java::lang::reflect::Field* rfield;
1370   for (int i = 0;  i < field_count;  i++)
1371     {
1372       _Jv_Field *field = &fields[i];
1373       if (! _Jv_equal (field->name, name, hash))
1374         continue;
1375       rfield = new java::lang::reflect::Field ();
1376       rfield->offset = (char*) field - (char*) fields;
1377       rfield->declaringClass = this;
1378       rfield->name = name;
1379       return rfield;
1380     }
1381   jclass superclass = getSuperclass();
1382   if (superclass == NULL)
1383     return NULL;
1384   rfield = superclass->getPrivateField(name);
1385   for (int i = 0; i < interface_count && rfield == NULL; ++i)
1386     rfield = interfaces[i]->getPrivateField (name);
1387   return rfield;
1388 }
1389
1390 // Only used by serialization
1391 java::lang::reflect::Method *
1392 java::lang::Class::getPrivateMethod (jstring name, JArray<jclass> *param_types)
1393 {
1394   jstring partial_sig = getSignature (param_types, false);
1395   jint p_len = partial_sig->length();
1396   _Jv_Utf8Const *utf_name = _Jv_makeUtf8Const (name);
1397   for (Class *klass = this; klass; klass = klass->getSuperclass())
1398     {
1399       int i = klass->isPrimitive () ? 0 : klass->method_count;
1400       while (--i >= 0)
1401         {
1402           // FIXME: access checks.
1403           if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
1404               && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len))
1405             {
1406               // Found it.
1407               using namespace java::lang::reflect;
1408
1409               Method *rmethod = new Method ();
1410               rmethod->offset = ((char *) (&klass->methods[i])
1411                                  - (char *) klass->methods);
1412               rmethod->declaringClass = klass;
1413               return rmethod;
1414             }
1415         }
1416     }
1417   throw new java::lang::NoSuchMethodException;
1418 }
1419
1420 // Private accessor method for Java code to retrieve the protection domain.
1421 java::security::ProtectionDomain *
1422 java::lang::Class::getProtectionDomain0 ()
1423 {
1424   return protectionDomain;
1425 }