merge from gnuclasspath branch. I hope I didn't miss or revert any modifications...
[cacao.git] / src / native / vm / VMClass.c
1 /* class: java/lang/Class */
2
3
4 /* for selecting public members */
5 #define MEMBER_PUBLIC  0
6
7
8 /******************************************************************************************                                                                                                             
9
10         creates method signature (excluding return type) from array of 
11         class-objects representing the parameters of the method 
12
13 *******************************************************************************************/
14
15
16 utf *create_methodsig(java_objectarray* types, char *retType)
17 {
18     char *buffer;       /* buffer for building the desciptor */
19     char *pos;          /* current position in buffer */
20     utf *result;        /* the method signature */
21     u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
22     u4 len = 0;         /* current length of the descriptor */
23     u4 i,j,n;
24  
25     if (!types) return NULL;
26
27     /* determine required buffer-size */    
28     for (i=0;i<types->header.size;i++) {
29       classinfo *c = (classinfo *) types->data[i];
30       buffer_size  = buffer_size + c->name->blength+2;
31     }
32
33     if (retType) buffer_size+=strlen(retType);
34
35     /* allocate buffer */
36     buffer = MNEW(u1, buffer_size);
37     pos    = buffer;
38     
39     /* method-desciptor starts with parenthesis */
40     *pos++ = '(';
41
42     for (i=0;i<types->header.size;i++) {
43
44             char ch;       
45             /* current argument */
46             classinfo *c = (classinfo *) types->data[i];
47             /* current position in utf-text */
48             char *utf_ptr = c->name->text; 
49             
50             /* determine type of argument */
51             if ( (ch = utf_nextu2(&utf_ptr)) == '[' ) {
52         
53                 /* arrayclass */
54                 for ( utf_ptr--; utf_ptr<utf_end(c->name); utf_ptr++)
55                    *pos++ = *utf_ptr; /* copy text */
56
57             } else
58             {           
59                 /* check for primitive types */
60                 for (j=0; j<PRIMITIVETYPE_COUNT; j++) {
61
62                         char *utf_pos   = utf_ptr-1;
63                         char *primitive = primitivetype_table[j].wrapname;
64
65                         /* compare text */
66                         while (utf_pos<utf_end(c->name))
67                                 if (*utf_pos++ != *primitive++) goto nomatch;
68
69                         /* primitive type found */
70                         *pos++ = primitivetype_table[j].typesig;
71                         goto next_type;
72
73                 nomatch:
74                 }
75
76                 /* no primitive type and no arrayclass, so must be object */
77                 *pos++ = 'L';
78                 /* copy text */
79                 for ( utf_ptr--; utf_ptr<utf_end(c->name); utf_ptr++)
80                         *pos++ = *utf_ptr;
81                 *pos++ = ';';
82
83                 next_type:
84             }  
85     }       
86
87     *pos++ = ')';
88
89     if (retType) {
90         for (i=0;i<strlen(retType);i++) {
91                 *pos++=retType[i];
92         }
93     }
94     /* create utf-string */
95     result = utf_new(buffer,(pos-buffer));
96     MFREE(buffer, u1, buffer_size);
97
98     return result;
99 }
100
101 /******************************************************************************************
102
103         retrieve the next argument or returntype from a descriptor
104         and return the corresponding class 
105
106 *******************************************************************************************/
107
108
109 classinfo *get_type(char **utf_ptr,char *desc_end, bool skip)
110 {
111     classinfo *c = class_from_descriptor(*utf_ptr,desc_end,utf_ptr,
112                                          (skip) ? CLASSLOAD_SKIP : CLASSLOAD_LOAD);
113     if (!c)
114         /* unknown type */
115         panic("illegal descriptor");
116
117     if (skip) return NULL;
118
119     use_class_as_object(c);
120     return c;
121 }
122
123 /******************************************************************************************
124
125         use the descriptor of a method to generate a java/lang/Class array
126         which contains the classes of the parametertypes of the method
127
128 *******************************************************************************************/
129
130 java_objectarray* get_parametertypes(methodinfo *m) 
131 {
132     utf  *descr    =  m->descriptor;    /* method-descriptor */ 
133     char *utf_ptr  =  descr->text;      /* current position in utf-text */
134     char *desc_end =  utf_end(descr);   /* points behind utf string     */
135     java_objectarray* result;
136     int parametercount = 0;
137     int i;
138
139     /* skip '(' */
140     utf_nextu2(&utf_ptr);
141   
142     /* determine number of parameters */
143     while ( *utf_ptr != ')' ) {
144         get_type(&utf_ptr,desc_end,true);
145         parametercount++;
146     }
147
148     /* create class-array */
149     result = builtin_anewarray(parametercount, class_java_lang_Class);
150
151     utf_ptr  =  descr->text;
152     utf_nextu2(&utf_ptr);
153
154     /* get returntype classes */
155     for (i = 0; i < parametercount; i++)
156             result->data[i] = (java_objectheader *) get_type(&utf_ptr,desc_end, false);
157
158     return result;
159 }
160
161
162 /******************************************************************************************
163
164         get the returntype class of a method
165
166 *******************************************************************************************/
167
168 classinfo *get_returntype(methodinfo *m) 
169 {
170         char *utf_ptr;   /* current position in utf-text */
171         char *desc_end;  /* points behind utf string     */
172         utf *desc = m->descriptor; /* method-descriptor  */
173
174         utf_ptr  = desc->text;
175         desc_end = utf_end(desc);
176
177         /* ignore parametertypes */
178         while ((utf_ptr<desc_end) && utf_nextu2(&utf_ptr)!=')')
179                 /* skip */ ;
180
181         return get_type(&utf_ptr,desc_end, false);
182 }
183
184
185 /*
186  * Class:     java_lang_VMClass
187  * Method:    forName
188  * Signature: (Ljava/lang/String;)Ljava/lang/Class;
189  */
190 JNIEXPORT struct java_lang_Class* JNICALL Java_java_lang_VMClass_forName (JNIEnv *env , jclass clazz,struct java_lang_String* s)
191 {
192         classinfo *c;
193         utf *u;
194         u4 i;
195
196         if (runverbose)
197         {
198             log_text("Java_java_lang_VMClass_forName0 called");
199             log_text(javastring_tochar((java_objectheader*)s));
200         }
201
202         /* illegal argument */
203         if (!s) return NULL;
204         
205         /* create utf string in which '.' is replaced by '/' */
206         u = javastring_toutf(s, true);
207         
208         if ( !(c = class_get(u)) ) {
209             methodinfo *method;
210             java_lang_Class *class;
211             
212             log_text("forName: would need classloader");
213             /*utf_display(u);*/
214             
215             c = loader_load(u);
216             if (c == NULL)
217             {
218                 /* class was not loaded. raise exception */
219                 exceptionptr = 
220                     native_new_and_init (class_java_lang_ClassNotFoundException);
221                 return NULL;
222             }
223         }
224
225         use_class_as_object (c);
226         return (java_lang_Class*) c;
227 }
228
229 /*
230  * Class:     java_lang_VMClass
231  * Method:    getClassLoader
232  * Signature: ()Ljava/lang/ClassLoader;
233  */
234 JNIEXPORT struct java_lang_ClassLoader* JNICALL Java_java_lang_VMClass_getClassLoader (JNIEnv *env ,  struct java_lang_VMClass* this )
235 {  
236   init_systemclassloader();
237   return SystemClassLoader;
238 }
239
240 /*
241  * Class:     java_lang_VMClass
242  * Method:    getModifiers
243  * Signature: ()I
244  */
245 /* XXX delete */
246 #if 0
247 JNIEXPORT struct java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType (JNIEnv *env ,  struct java_lang_VMClass* this )
248 {
249   classinfo *c = NULL; 
250
251   if ((classinfo*) (this->vmData) == class_array) {
252         java_arrayheader *a = (java_arrayheader*) (this->vmData);
253
254         /* determine componenttype */
255         switch (a->arraytype) {
256            case ARRAYTYPE_BYTE:    c = class_java_lang_Byte; break;  
257            case ARRAYTYPE_BOOLEAN: c = class_java_lang_Boolean; break;   
258            case ARRAYTYPE_CHAR:    c = class_java_lang_Character; break;   
259            case ARRAYTYPE_SHORT:   c = class_java_lang_Short; break;    
260            case ARRAYTYPE_INT:     c = class_java_lang_Integer; break;   
261            case ARRAYTYPE_LONG:    c = class_java_lang_Long; break;   
262            case ARRAYTYPE_FLOAT:   c = class_java_lang_Float; break;   
263            case ARRAYTYPE_DOUBLE:  c = class_java_lang_Double; break;   
264            case ARRAYTYPE_OBJECT:  c = ((java_objectarray*) a) -> elementtype; break;
265            case ARRAYTYPE_ARRAY:   c = (classinfo *) ((java_arrayarray*) a) -> data[0]; break;
266            default: panic("illegal arraytype");
267         }               
268
269         /* set vftbl */
270         use_class_as_object (c);
271   }
272   
273   return (java_lang_Class*) c;
274 }
275 #endif
276 JNIEXPORT struct java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType (JNIEnv *env ,  struct java_lang_VMClass* this )
277 {
278     classinfo *thisclass = (classinfo*) (this->vmData);
279     classinfo *c = NULL;
280     arraydescriptor *desc;
281     
282     if ((desc = thisclass->vftbl->arraydesc) != NULL) {
283         if (desc->arraytype == ARRAYTYPE_OBJECT)
284             c = desc->componentvftbl->class;
285         else
286             c = primitivetype_table[desc->arraytype].class_primitive;
287         
288         /* set vftbl */
289         use_class_as_object (c);
290     }
291     
292     return (java_lang_Class*) c;
293 }
294
295
296 /*
297  * Class:     java_lang_VMClass
298  * Method:    getDeclaredConstructors
299  * Signature: (Z)[Ljava/lang/reflect/Constructor;
300  */
301 JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredConstructors (JNIEnv *env ,  struct java_lang_VMClass* this , s4 public_only)
302 {
303   
304     classinfo *c = (classinfo *) (this->vmData);    
305     java_objectheader *o;
306     classinfo *class_constructor;
307     java_objectarray *array_constructor;     /* result: array of Method-objects */
308     java_objectarray *exceptiontypes;   /* the exceptions thrown by the method */
309     methodinfo *m;                      /* the current method to be represented */    
310     int public_methods = 0;             /* number of public methods of the class */
311     int pos = 0;
312     int i;
313     utf *utf_constr=utf_new_char("<init>");
314
315
316     /*
317     log_text("Java_java_lang_VMClass_getDeclaredConstructors");
318     utf_display(c->name);
319     printf("\n");
320     */
321
322
323     /* determine number of constructors */
324     for (i = 0; i < c->methodscount; i++) 
325         if ((((c->methods[i].flags & ACC_PUBLIC)) || public_only) && 
326                 (c->methods[i].name==utf_constr)) public_methods++;
327
328     class_constructor = (classinfo*) loader_load(utf_new_char ("java/lang/reflect/Constructor"));
329
330     if (!class_constructor) 
331         return NULL;
332
333     array_constructor = builtin_anewarray(public_methods, class_constructor);
334
335     if (!array_constructor) 
336         return NULL;
337
338     for (i = 0; i < c->methodscount; i++) 
339         if ((c->methods[i].flags & ACC_PUBLIC) || (!public_only)){
340         
341             m = &c->methods[i];     
342             if (m->name!=utf_constr) continue;
343             o = native_new_and_init(class_constructor);     
344             array_constructor->data[pos++] = o;
345
346             /* array of exceptions declared to be thrown, information not available !! */
347             exceptiontypes = builtin_anewarray (0, class_java_lang_Class);
348
349 /*          class_showconstantpool(class_constructor);*/
350             /* initialize instance fields */
351             ((java_lang_reflect_Constructor*)o)->flag=(m->flags & (ACC_PRIVATE | ACC_PUBLIC | ACC_PROTECTED));
352             setfield_critical(class_constructor,o,"clazz",          "Ljava/lang/Class;",  jobject, (jobject) c /*this*/);
353             setfield_critical(class_constructor,o,"slot",           "I",                     jint,    i); 
354             setfield_critical(class_constructor,o,"exceptionTypes", "[Ljava/lang/Class;", jobject, (jobject) exceptiontypes);
355             setfield_critical(class_constructor,o,"parameterTypes", "[Ljava/lang/Class;", jobject, (jobject) get_parametertypes(m));
356         }            
357     
358 log_text("leaving Java_java_lang_VMClass_getDeclaredConstructors");
359 return array_constructor;
360
361
362
363
364 /*  panic("Java_java_lang_Class_getConstructors0 called");
365   return NULL;*/
366 }
367
368
369 /*
370  * Class:     java_lang_VMClass
371  * Method:    getDeclaredClasses
372  * Signature: (Z)[Ljava/lang/Class;
373  */
374 JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredClasses (JNIEnv *env ,  struct java_lang_VMClass* this , s4 publicOnly)
375 {
376 #warning fix the public only case
377   classinfo *c = (classinfo *) (this->vmData);
378   int pos = 0;                /* current declared class */
379   int declaredclasscount = 0; /* number of declared classes */
380   java_objectarray *result;   /* array of declared classes */
381   int i;
382
383   if (!this)
384     return NULL;
385
386   if (!this->vmData)
387     return NULL;
388
389   if (!Java_java_lang_VMClass_isPrimitive(env, this) && (c->name->text[0]!='[')) {
390     /* determine number of declared classes */
391     for (i = 0; i < c->innerclasscount; i++) {
392       if (c->innerclass[i].outer_class == c) 
393         /* outer class is this class */
394         declaredclasscount++;
395     }
396   }
397
398   result = builtin_anewarray(declaredclasscount, class_java_lang_Class);        
399
400   for (i = 0; i < c->innerclasscount; i++) {
401     
402     classinfo *inner =  c->innerclass[i].inner_class;
403     classinfo *outer =  c->innerclass[i].outer_class;
404       
405     if (outer == c) {
406       /* outer class is this class, store innerclass in array */
407       use_class_as_object (inner);
408       result->data[pos++] = (java_objectheader *) inner;
409     }
410   }
411
412   return result;
413 }
414
415 /*
416  * Class:     java/lang/Class
417  * Method:    getDeclaringClass
418  * Signature: ()Ljava/lang/Class;
419  */
420 JNIEXPORT struct java_lang_Class* JNICALL Java_java_lang_VMClass_getDeclaringClass ( JNIEnv *env ,  struct java_lang_VMClass* this)
421 {
422 #warning fixme
423   classinfo *c = (classinfo *) (this->vmData);
424   log_text("Java_java_lang_VMClass_getDeclaringClass");
425
426   if (this && this->vmData && !Java_java_lang_VMClass_isPrimitive(env, this) && (c->name->text[0]!='[')) {    
427     int i, j;
428
429     if (c->innerclasscount == 0)  /* no innerclasses exist */
430         return NULL;
431     
432     for (i = 0; i < c->innerclasscount; i++) {
433
434       classinfo *inner =  c->innerclass[i].inner_class;
435       classinfo *outer =  c->innerclass[i].outer_class;
436       
437       if (inner == c) {
438         /* innerclass is this class */
439         use_class_as_object (outer);
440         return (java_lang_Class*) outer;
441       }
442     }
443   }
444
445   /* return NULL for arrayclasses and primitive classes */
446   return NULL;
447 }
448
449 /*
450  * Class:     java/lang/Class
451  * Method:    getField0
452  * Signature: (Ljava/lang/String;I)Ljava/lang/reflect/Field;
453  */
454 JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_java_lang_VMClass_getField0 ( JNIEnv *env ,  struct java_lang_VMClass* this, struct java_lang_String* name, s4 public_only)
455 {
456     classinfo *c, *fieldtype;   
457     fieldinfo *f;               /* the field to be represented */
458     java_lang_reflect_Field *o; /* result: field-object */
459     utf *desc;                  /* the fielddescriptor */
460     char buffer[MAXSTRINGSIZE];
461     
462     /* create Field object */
463     c = (classinfo*) loader_load(utf_new_char ("java/lang/reflect/Field"));
464     o = (java_lang_reflect_Field*) native_new_and_init(c);
465
466     /* get fieldinfo entry */
467     f = class_findfield_approx((classinfo*) (this->vmData), javastring_toutf(name, false));
468
469     if (f) {
470
471         if ( public_only && !(f->flags & ACC_PUBLIC))
472         {
473             /* field is not public */
474             exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldException);
475             return NULL;
476         }
477
478       desc = f->descriptor;
479       fieldtype = class_from_descriptor(desc->text,utf_end(desc),NULL,true);
480       if (!fieldtype) return NULL;
481          
482       /* initialize instance fields */
483       setfield_critical(c,o,"clazz",          "Ljava/lang/Class;",  jobject, (jobject) (this->vmData) /*this*/);
484       setfield_critical(c,o,"modifiers",      "I",                  jint,    f->flags);
485       /* save type in slot-field for faster processing */
486       setfield_critical(c,o,"slot",           "I",                  jint,    (jint) f->descriptor->text[0]);  
487       setfield_critical(c,o,"name",           "Ljava/lang/String;", jstring, (jstring) name);
488       setfield_critical(c,o,"type",           "Ljava/lang/Class;",  jclass,  fieldtype);
489
490       return o;
491     }
492
493     return NULL;
494 }
495
496
497 /*
498  * Class:     java_lang_VMClass
499  * Method:    getDeclaredFields
500  * Signature: (Z)[Ljava/lang/reflect/Field;
501  */
502 JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredFields (JNIEnv *env ,  struct java_lang_VMClass* this , s4 public_only)
503 {
504     classinfo *c = (classinfo *) (this->vmData);
505     classinfo *class_field;
506     java_objectarray *array_field; /* result: array of field-objects */
507     int public_fields = 0;         /* number of elements in field-array */
508     int pos = 0;
509     int i;
510
511     /* determine number of fields */
512     for (i = 0; i < c->fieldscount; i++) 
513         if ((c->fields[i].flags & ACC_PUBLIC) || (!public_only)) public_fields++;
514
515     class_field = loader_load(utf_new_char("java/lang/reflect/Field"));
516
517     if (!class_field) 
518         return NULL;
519
520     /* create array of fields */
521     array_field = builtin_anewarray(public_fields, class_field);
522
523     /* creation of array failed */
524     if (!array_field) 
525         return NULL;
526
527     /* get the fields and store in the array */    
528     for (i = 0; i < c->fieldscount; i++) 
529         if ( (c->fields[i].flags & ACC_PUBLIC) || (!public_only))
530             array_field->data[pos++] = (java_objectheader*) Java_java_lang_VMClass_getField0
531                                                              (env,
532                                                               this,
533                                                               (java_lang_String*) javastring_new(c->fields[i].name), 
534                                                               public_only);
535     return array_field;
536 }
537
538 /*
539  * Class:     java/lang/Class
540  * Method:    getInterfaces
541  * Signature: ()[Ljava/lang/Class;
542  */
543 JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getInterfaces ( JNIEnv *env ,  struct java_lang_VMClass* this)
544 {
545         classinfo *c = (classinfo*) (this->vmData);
546         u4 i;
547         java_objectarray *a = builtin_anewarray (c->interfacescount, class_java_lang_Class);
548         if (!a) return NULL;
549         for (i=0; i<c->interfacescount; i++) {
550                 use_class_as_object (c->interfaces[i]);
551
552                 a->data[i] = (java_objectheader*) c->interfaces[i];
553                 }
554         return a;
555 }
556
557
558 /*
559  * Class:     java/lang/Class
560  * Method:    getMethod0
561  * Signature: (Ljava/lang/String;[Ljava/lang/Class;I)Ljava/lang/reflect/Method;
562  */
563 JNIEXPORT struct java_lang_reflect_Method* JNICALL Java_java_lang_VMClass_getMethod0 ( JNIEnv *env ,  struct java_lang_Class* 
564         this, struct java_lang_String* name, java_objectarray* types, s4 which)
565 {
566     classinfo *c; 
567     classinfo *clazz = (classinfo *) this;
568     java_lang_reflect_Method* o;         /* result: Method-object */ 
569     java_objectarray *exceptiontypes;    /* the exceptions thrown by the method */
570     methodinfo *m;                       /* the method to be represented */
571
572     c = (classinfo*) loader_load(utf_new_char ("java/lang/reflect/Method"));
573     o = (java_lang_reflect_Method*) native_new_and_init(c);
574
575     /* find the method */
576     m = class_resolvemethod_approx (
577                 clazz, 
578                 javastring_toutf(name, false),
579                 create_methodsig(types,0)
580         );
581
582     if (!m || (which==MEMBER_PUBLIC && !(m->flags & ACC_PUBLIC)))
583     {
584         /* no apropriate method was found */
585         exceptionptr = native_new_and_init (class_java_lang_NoSuchMethodException);
586         return NULL;
587     }
588    
589     /* array of exceptions declared to be thrown, information not available !! */
590     exceptiontypes = builtin_anewarray (0, class_java_lang_Class);
591
592     /* initialize instance fields */
593     setfield_critical(c,o,"clazz",          "Ljava/lang/Class;",  jobject, (jobject) clazz /*this*/);
594     setfield_critical(c,o,"parameterTypes", "[Ljava/lang/Class;", jobject, (jobject) types);
595     setfield_critical(c,o,"exceptionTypes", "[Ljava/lang/Class;", jobject, (jobject) exceptiontypes);
596     setfield_critical(c,o,"name",           "Ljava/lang/String;", jstring, javastring_new(m->name));
597     setfield_critical(c,o,"modifiers",      "I",                  jint,    m->flags);
598     setfield_critical(c,o,"slot",           "I",                  jint,    0); 
599     setfield_critical(c,o,"returnType",     "Ljava/lang/Class;",  jclass,  get_returntype(m));
600
601     return o;
602 }
603
604 /*
605  * Class:     java_lang_VMClass
606  * Method:    getDeclaredMethods
607  * Signature: (Z)[Ljava/lang/reflect/Method;
608  */
609 JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredMethods (JNIEnv *env ,  struct java_lang_VMClass* this , s4 public_only)
610 {
611     classinfo *c = (classinfo *) this->vmData;    
612     java_objectheader *o;
613     classinfo *class_method;
614     java_objectarray *array_method;     /* result: array of Method-objects */
615     java_objectarray *exceptiontypes;   /* the exceptions thrown by the method */
616     methodinfo *m;                      /* the current method to be represented */    
617     int public_methods = 0;             /* number of public methods of the class */
618     int pos = 0;
619     int i;
620
621     /* determine number of methods */
622     for (i = 0; i < c->methodscount; i++) 
623         if (((c->methods[i].flags & ACC_PUBLIC)) || public_only) public_methods++;
624
625     class_method = (classinfo*) loader_load(utf_new_char ("java/lang/reflect/Method"));
626
627     if (!class_method) 
628         return NULL;
629     
630     array_method = builtin_anewarray(public_methods, class_method);
631
632     if (!array_method) 
633         return NULL;
634
635     for (i = 0; i < c->methodscount; i++) 
636         if ((c->methods[i].flags & ACC_PUBLIC) || (!public_only)){
637
638             m = &c->methods[i];     
639             o = native_new_and_init(class_method);     
640             array_method->data[pos++] = o;
641
642             /* array of exceptions declared to be thrown, information not available !! */
643             exceptiontypes = builtin_anewarray (0, class_java_lang_Class);
644
645             /* initialize instance fields */
646             setfield_critical(class_method,o,"clazz",          "Ljava/lang/Class;",  jobject, (jobject) c /*this*/);
647             setfield_critical(class_method,o,"name",           "Ljava/lang/String;", jstring, javastring_new(m->name));
648             setfield_critical(class_method,o,"flag",      "I",               jint,    m->flags);
649             setfield_critical(class_method,o,"slot",           "I",                  jint,    i); 
650             setfield_critical(class_method,o,"returnType",     "Ljava/lang/Class;",  jclass,  get_returntype(m));
651             setfield_critical(class_method,o,"exceptionTypes", "[Ljava/lang/Class;", jobject, (jobject) exceptiontypes);
652             setfield_critical(class_method,o,"parameterTypes", "[Ljava/lang/Class;", jobject, (jobject) get_parametertypes(m));
653         }            
654
655     return array_method;
656 }
657
658 /*
659  * Class:     java/lang/Class
660  * Method:    getModifiers
661  * Signature: ()I
662  */
663 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_getModifiers ( JNIEnv *env ,  struct java_lang_VMClass* this)
664 {
665   classinfo *c = (classinfo *) (this->vmData);
666   return c->flags;
667 }
668
669 /*
670  * Class:     java/lang/Class
671  * Method:    getName
672  * Signature: ()Ljava/lang/String;
673  */
674 JNIEXPORT struct java_lang_String* JNICALL Java_java_lang_VMClass_getName ( JNIEnv *env ,  struct java_lang_VMClass* this)
675 {
676
677         u4 i;
678         classinfo *c = (classinfo*) (this->vmData);
679         java_lang_String *s = (java_lang_String*) javastring_new(c->name);
680
681         if (!s) return NULL;
682
683         /* return string where '/' is replaced by '.' */
684         for (i=0; i<s->value->header.size; i++) {
685                 if (s->value->data[i] == '/') s->value->data[i] = '.';
686                 }
687         
688         return s;
689 }
690
691
692
693 /*
694  * Class:     java/lang/Class
695  * Method:    getProtectionDomain0
696  * Signature: ()Ljava/security/ProtectionDomain;
697  */
698 JNIEXPORT struct java_security_ProtectionDomain* JNICALL Java_java_lang_VMClass_getProtectionDomain0 ( JNIEnv *env ,  struct java_lang_Class* this)
699 {
700   log_text("Java_java_lang_VMClass_getProtectionDomain0  called");
701   return NULL;
702 }
703
704 /*
705  * Class:     java/lang/Class
706  * Method:    getSigners
707  * Signature: ()[Ljava/lang/Object;
708  */
709 JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getSigners ( JNIEnv *env ,  struct java_lang_Class* this)
710 {
711   log_text("Java_java_lang_VMClass_getSigners  called");
712   return NULL;
713 }
714
715 /*
716  * Class:     java/lang/Class
717  * Method:    getSuperclass
718  * Signature: ()Ljava/lang/Class;
719  */
720 JNIEXPORT struct java_lang_Class* JNICALL Java_java_lang_VMClass_getSuperclass ( JNIEnv *env ,  struct java_lang_VMClass* this)
721 {
722         classinfo *c = ((classinfo*) this->vmData) -> super;
723         if (!c) return NULL;
724
725         use_class_as_object (c);
726         return (java_lang_Class*) c;
727 }
728
729 /*
730  * Class:     java/lang/Class
731  * Method:    isArray
732  * Signature: ()Z
733  */
734 /* XXX delete */
735 #if 0
736 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isArray ( JNIEnv *env ,  struct java_lang_VMClass* this)
737 {
738         classinfo *c = (classinfo*) (this->vmData);
739
740         if (c == class_array || c->name->text[0] == '[')  return true;
741         return false;
742 }
743 #endif
744 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isArray ( JNIEnv *env ,  struct java_lang_VMClass* this)
745 {
746     classinfo *c = (classinfo*) (this->vmData);
747     return c->vftbl->arraydesc != NULL;
748 }
749
750 /*
751  * Class:     java/lang/Class
752  * Method:    isAssignableFrom
753  * Signature: (Ljava/lang/Class;)Z
754  */
755 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isAssignableFrom ( JNIEnv *env ,  struct java_lang_VMClass* this, struct java_lang_Class* sup)
756 {
757 #warning fixme
758         log_text("Java_java_lang_VMClass_isAssignableFrom");
759         return (*env)->IsAssignableForm(env, (jclass) this, (jclass) sup->vmClass);
760 }
761
762 /*
763  * Class:     java/lang/Class
764  * Method:    isInstance
765  * Signature: (Ljava/lang/Object;)Z
766  */
767 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInstance ( JNIEnv *env ,  struct java_lang_VMClass* this, struct java_lang_Object* obj)
768 {
769         classinfo *clazz = (classinfo*) this;
770         return (*env)->IsInstanceOf(env,(jobject) obj,clazz);
771 }
772
773 /*
774  * Class:     java/lang/Class
775  * Method:    isInterface
776  * Signature: ()Z
777  */
778 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInterface ( JNIEnv *env ,  struct java_lang_VMClass* this)
779 {
780         classinfo *c = (classinfo*) this->vmData;
781         if (c->flags & ACC_INTERFACE) return true;
782         return false;
783 }
784
785 /*
786  * Class:     java/lang/Class
787  * Method:    isPrimitive
788  * Signature: ()Z
789  */
790 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isPrimitive ( JNIEnv *env ,  struct java_lang_VMClass* this)
791 {
792   int i;
793   classinfo *c = (classinfo *) this->vmData;
794
795   /* search table of primitive classes */
796   for (i=0;i<PRIMITIVETYPE_COUNT;i++)
797     if (primitivetype_table[i].class_primitive == c) return true;
798
799   return false;
800 }
801
802
803 /*
804  * Class:     java/lang/Class
805  * Method:    registerNatives
806  * Signature: ()V
807  */
808 JNIEXPORT void JNICALL Java_java_lang_VMClass_registerNatives ( JNIEnv *env  )
809 {
810     /* empty */
811 }
812
813 /*
814  * Class:     java/lang/Class
815  * Method:    setProtectionDomain0
816  * Signature: (Ljava/security/ProtectionDomain;)V
817  */
818 JNIEXPORT void JNICALL Java_java_lang_VMClass_setProtectionDomain0 ( JNIEnv *env ,  struct java_lang_Class* this, struct java_security_ProtectionDomain* par1)
819 {
820   if (verbose)
821     log_text("Java_java_lang_VMClass_setProtectionDomain0 called");
822 }
823
824 /*
825  * Class:     java/lang/Class
826  * Method:    setSigners
827  * Signature: ([Ljava/lang/Object;)V
828  */
829 JNIEXPORT void JNICALL Java_java_lang_VMClass_setSigners ( JNIEnv *env ,  struct java_lang_Class* this, java_objectarray* par1)
830 {
831   if (verbose)
832     log_text("Java_java_lang_VMClass_setSigners called");
833 }
834
835
836
837
838
839
840 /*
841  * Class:     java_lang_VMClass
842  * Method:    initialize
843  * Signature: ()V
844  */
845 JNIEXPORT void JNICALL Java_java_lang_VMClass_initialize (JNIEnv *env ,  struct java_lang_VMClass* this ){
846         log_text("Java_java_lang_VMClass_initialize");
847 }
848 /*
849  * Class:     java_lang_VMClass
850  * Method:    loadArrayClass
851  * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Class;
852  */
853 JNIEXPORT struct java_lang_Class* JNICALL Java_java_lang_VMClass_loadArrayClass (JNIEnv *env , jclass clazz, struct java_lang_String* par1, struct 
854         java_lang_ClassLoader* par2) {
855                 log_text("Java_java_lang_VMClass_loadArrayClass");
856                 return 0;
857 }
858 /*
859  * Class:     java_lang_VMClass
860  * Method:    throwException
861  * Signature: (Ljava/lang/Throwable;)V
862  */
863 JNIEXPORT void JNICALL Java_java_lang_VMClass_throwException (JNIEnv *env , jclass clazz, struct java_lang_Throwable* par1) {
864         log_text("Java_java_lang_VMClass_throwException");
865 }
866
867 /*
868  * Class:     java_lang_VMClass
869  * Method:    step7
870  * Signature: ()V
871  */
872 JNIEXPORT void JNICALL Java_java_lang_VMClass_step7 (JNIEnv *env ,  struct java_lang_VMClass* this ) {
873         log_text("Java_java_lang_VMClass_step7");
874 }
875 /*
876  * Class:     java_lang_VMClass
877  * Method:    step8
878  * Signature: ()V
879  */
880 JNIEXPORT void JNICALL Java_java_lang_VMClass_step8 (JNIEnv *env ,  struct java_lang_VMClass* this ) {
881         log_text("Java_java_lang_VMClass_step8");
882 }
883
884
885
886 /*
887  * Class:     java_lang_VMClass
888  * Method:    isInitialized
889  * Signature: ()Z
890  */
891 JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isInitialized (JNIEnv *env ,  struct java_lang_VMClass* this ) {
892         log_text("Java_java_lang_VMClass_isInitialized");
893         return 1;
894 }
895 /*
896  * Class:     java_lang_VMClass
897  * Method:    setInitialized
898  * Signature: ()V
899  */
900 JNIEXPORT void JNICALL Java_java_lang_VMClass_setInitialized (JNIEnv *env ,  struct java_lang_VMClass* this ) {
901         log_text("Java_java_lang_VMClass_setInitialized");
902 }