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