* src/cacaoh/headers.c (typeinfo_print_short): Stub added.
[cacao.git] / src / cacaoh / headers.c
1 /* src/cacaoh/headers.c - functions for header generation
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Reinhard Grafl
28
29    Changes: Mark Probst
30             Philipp Tomsich
31             Christian Thalinger
32                         Edwin Steiner
33
34    $Id: headers.c 5739 2006-10-11 19:43:12Z edwin $
35
36 */
37
38
39 #include "config.h"
40
41 #include <assert.h>
42 #include <ctype.h>
43 #include <stdarg.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 #include "vm/types.h"
48
49 #if defined(ENABLE_THREADS)
50 # if defined(__DARWIN__)
51 #  include <signal.h>
52 # endif
53 # include <ucontext.h>
54 #endif
55
56 #include "mm/boehm.h"
57 #include "mm/memory.h"
58 #include "native/include/java_lang_String.h"
59 #include "native/include/java_lang_Throwable.h"
60 #include "toolbox/chain.h"
61 #include "toolbox/logging.h"
62 #include "vm/builtin.h"
63 #include "vm/class.h"
64 #include "vm/global.h"
65 #include "vm/method.h"
66 #include "vm/loader.h"
67 #include "vm/options.h"
68 #include "vm/stringlocal.h"
69 #include "vm/jit/asmpart.h"
70
71
72 /* Invocation API variables ***************************************************/
73
74 _Jv_JavaVM *_Jv_jvm;                    /* denotes a Java VM                  */
75
76
77 #if defined(ENABLE_INTRP)
78 /* dummy interpreter stack to keep the compiler happy */
79
80 u1 *intrp_main_stack;
81 #endif
82
83
84 /* for raising exceptions from native methods *********************************/
85
86 #if !defined(ENABLE_THREADS)
87 java_objectheader *_no_threads_exceptionptr = NULL;
88 #endif
89
90
91 /* replace some non-vmcore functions ******************************************/
92
93 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
94                                                                 bool isstatic)
95 {
96         /* return something different than NULL, otherwise we get an exception */
97
98         return (functionptr) 1;
99 }
100
101 java_objectheader *native_new_and_init(classinfo *c) { return NULL; }
102 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s) { return NULL; }
103 java_objectheader *native_new_and_init_int(classinfo *c, s4 i) { return NULL; }
104 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t) { return NULL; }
105
106
107 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
108 { return NULL; }
109
110 void vm_abort(const char *text, ...)
111 {
112         abort();
113 }
114
115 /* code patching functions */
116 void patcher_builtin_arraycheckcast(u1 *sp) {}
117
118 #if defined(__MIPS__)
119 long compare_and_swap(long *p, long oldval, long newval)
120 {
121         if (*p == oldval) {
122                 *p = newval;
123                 return oldval;
124         } else
125                 return *p;
126 }
127 #endif
128
129
130 u1 *createcompilerstub(methodinfo *m) { return NULL; }
131 #if defined(ENABLE_INTRP)
132 u1 *intrp_createcompilerstub(methodinfo *m) { return NULL; }
133 #endif
134
135 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m) { return NULL; }
136
137 void removecompilerstub(u1 *stub) {}
138 void removenativestub(u1 *stub) {}
139
140 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop) {}
141 u1* asm_initialize_thread_stack(void *func, u1 *stack) { return NULL; }
142
143 void *asm_switchstackandcall(void *stack, void *func, void **stacktopsave, void * p) { return NULL; }
144
145 void asm_handle_builtin_exception(classinfo *c) {}
146 void asm_abstractmethoderror(void) {}
147
148 #if defined(ENABLE_JIT)
149 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out) {}
150 #endif
151
152 #if defined(ENABLE_INTRP)
153 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out) {}
154 #endif
155
156 u8 asm_get_cycle_count(void)
157 {
158         return 0;
159 }
160
161
162 void *Java_java_lang_VMObject_clone(void *env, void *clazz, void * this)
163 {
164         return NULL;
165 }
166
167 typecheck_result typeinfo_is_assignable_to_class(typeinfo *value,classref_or_classinfo dest)
168 {
169         return typecheck_TRUE;
170 }
171
172 void typeinfo_init_classinfo(typeinfo *info,classinfo *c)
173 {
174 }
175
176 bool typeinfo_init_class(typeinfo *info,classref_or_classinfo c)
177 {
178         return true;
179 }
180
181 void typeinfo_print(FILE *file,typeinfo *info,int indent) {}
182 void typeinfo_print_short(FILE *file,typeinfo *info) {}
183
184 void exceptions_print_exception(java_objectheader *xptr) {}
185 void stacktrace_print_trace(java_objectheader *xptr) {}
186 java_objectarray *stacktrace_getClassContext() { return NULL; }
187 void code_free_code_of_method(methodinfo *m) {}
188
189
190 /* exception functions ********************************************************/
191
192 /* these should not be called */
193
194 void throw_main_exception_exit(void) { assert(0); }
195 void throw_exception(void) { assert(0); }
196 void throw_exception_exit(void) { assert(0); }
197
198 void exceptions_throw_verifyerror(methodinfo *m, const char *message)
199 {
200         assert(0);
201 }
202
203 java_objectheader *new_exception_throwable(const char *classname, java_lang_Throwable *throwable)
204 {
205         assert(0);
206
207         /* keep compiler happy */
208
209         return NULL;
210 }
211
212
213 void throw_cacao_exception_exit(const char *exception, const char *message, ...)
214 {
215         va_list ap;
216
217         fprintf(stderr, "%s: ", exception);
218
219         va_start(ap, message);
220         vfprintf(stderr, message, ap);
221         va_end(ap);
222
223         fputc('\n', stderr);
224
225         exit(1);
226 }
227
228
229 void exceptions_throw_outofmemory_exit(void)
230 {
231         fprintf(stderr, "java.lang.InternalError: Out of memory\n");
232         exit(1);
233 }
234
235
236 java_objectheader *new_exception(const char *classname)
237 {
238         fprintf(stderr, "%s\n", classname);
239         exit(1);
240
241         /* keep compiler happy */
242
243         return NULL;
244 }
245
246
247 java_objectheader *new_exception_message(const char *classname, const char *message)
248 {
249         fprintf(stderr, "%s: %s\n", classname, message);
250         exit(1);
251
252         /* keep compiler happy */
253
254         return NULL;
255 }
256
257
258 java_objectheader *new_exception_utfmessage(const char *classname, utf *message)
259 {
260         fprintf(stderr, "%s: ", classname);
261         utf_display_printable_ascii(message);
262         fputc('\n', stderr);
263
264         exit(1);
265
266         /* keep compiler happy */
267
268         return NULL;
269 }
270
271
272 java_objectheader *new_exception_javastring(const char *classname,
273                                                                                         java_lang_String *message)
274 {
275         fprintf(stderr, "%s: ", classname);
276         /* TODO print message */
277         fputc('\n', stderr);
278
279         exit(1);
280
281         /* keep compiler happy */
282
283         return NULL;
284 }
285
286
287 void exceptions_throw_abstractmethoderror(void)
288 {
289         fprintf(stderr, "java.lang.AbstractMethodError\n");
290
291         exit(1);
292 }
293
294
295 java_objectheader *new_classformaterror(classinfo *c, const char *message, ...)
296 {
297         va_list ap;
298
299         utf_display_printable_ascii(c->name);
300         fprintf(stderr, ": ");
301
302         va_start(ap, message);
303         vfprintf(stderr, message, ap);
304         va_end(ap);
305
306         fputc('\n', stderr);
307
308         exit(1);
309
310         /* keep compiler happy */
311
312         return NULL;
313 }
314
315
316 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
317 {
318         va_list ap;
319
320         va_start(ap, message);
321         (void) new_classformaterror(c, message, ap);
322         va_end(ap);
323 }
324
325
326 java_objectheader *new_classnotfoundexception(utf *name)
327 {
328         fprintf(stderr, "java.lang.ClassNotFoundException: ");
329         utf_fprint_printable_ascii(stderr, name);
330         fputc('\n', stderr);
331
332         exit(1);
333
334         /* keep compiler happy */
335
336         return NULL;
337 }
338
339
340 java_objectheader *new_noclassdeffounderror(utf *name)
341 {
342         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
343         utf_fprint_printable_ascii(stderr, name);
344         fputc('\n', stderr);
345
346         exit(1);
347
348         /* keep compiler happy */
349
350         return NULL;
351 }
352
353
354 java_objectheader *exceptions_new_linkageerror(const char *message,
355                                                                                            classinfo *c)
356 {
357         fprintf(stderr, "java.lang.LinkageError: %s",message);
358         if (c) {
359                 utf_fprint_printable_ascii_classname(stderr, c->name);
360         }
361         fputc('\n', stderr);
362
363         exit(1);
364
365         /* keep compiler happy */
366
367         return NULL;
368 }
369
370 java_objectheader *exceptions_new_nosuchmethoderror(classinfo *c,
371                                                                                                         utf *name, utf *desc)
372 {
373         fprintf(stderr, "java.lang.NoSuchMethodError: ");
374         utf_fprint_printable_ascii(stderr, c->name);
375         fprintf(stderr, ".");
376         utf_fprint_printable_ascii(stderr, name);
377         utf_fprint_printable_ascii(stderr, desc);
378         fputc('\n', stderr);
379
380         exit(1);
381
382         /* keep compiler happy */
383
384         return NULL;
385 }
386
387
388 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
389 {
390         (void) exceptions_new_nosuchmethoderror(c, name, desc);
391 }
392
393
394 java_objectheader *new_internalerror(const char *message, ...)
395 {
396         va_list ap;
397
398         fprintf(stderr, "%s: ", string_java_lang_InternalError);
399
400         va_start(ap, message);
401         vfprintf(stderr, message, ap);
402         va_end(ap);
403
404         exit(1);
405
406         /* keep compiler happy */
407
408         return NULL;
409 }
410
411
412 java_objectheader *new_unsupportedclassversionerror(classinfo *c, const char *message, ...)
413 {
414         va_list ap;
415
416         fprintf(stderr, "%s: ", string_java_lang_UnsupportedClassVersionError);
417
418         utf_display_printable_ascii(c->name);
419         fprintf(stderr, ": ");
420
421         va_start(ap, message);
422         vfprintf(stderr, message, ap);
423         va_end(ap);
424
425         exit(1);
426
427         /* keep compiler happy */
428
429         return NULL;
430 }
431
432
433 void exceptions_throw_arrayindexoutofboundsexception(void)
434 {
435         fprintf(stderr, "%s", string_java_lang_ArrayIndexOutOfBoundsException);
436         exit(1);
437 }
438
439
440 java_objectheader *exceptions_new_arraystoreexception(void)
441 {
442         fprintf(stderr, "%s", string_java_lang_ArrayStoreException);
443         exit(1);
444
445         /* keep compiler happy */
446
447         return NULL;
448 }
449
450
451 void exceptions_throw_arraystoreexception(void)
452 {
453         (void) exceptions_new_arraystoreexception();
454 }
455
456
457 java_objectheader *exceptions_throw_illegalmonitorstateexception(void)
458 {
459         fprintf(stderr, "%s", string_java_lang_IllegalMonitorStateException);
460         exit(1);
461
462         /* keep compiler happy */
463
464         return NULL;
465 }
466
467
468 java_objectheader *new_negativearraysizeexception(void)
469 {
470         fprintf(stderr, "%s", string_java_lang_NegativeArraySizeException);
471         exit(1);
472
473         /* keep compiler happy */
474
475         return NULL;
476 }
477
478
479 void exceptions_throw_negativearraysizeexception(void)
480 {
481         (void) new_negativearraysizeexception();
482 }
483
484
485 java_objectheader *new_nullpointerexception(void)
486 {
487         fprintf(stderr, "%s", string_java_lang_NullPointerException);
488         exit(1);
489
490         /* keep compiler happy */
491
492         return NULL;
493 }
494
495
496 void exceptions_throw_nullpointerexception(void)
497 {
498         (void) new_nullpointerexception();
499 }
500
501
502 void classnotfoundexception_to_noclassdeffounderror(void)
503 {
504 }
505
506 /* machine dependent stuff ****************************************************/
507
508 #if defined(ENABLE_THREADS)
509 critical_section_node_t asm_criticalsections;
510 void thread_restartcriticalsection(ucontext_t *uc) {}
511 #endif
512
513 void md_param_alloc(methoddesc *md) {}
514
515
516 #if defined(ENABLE_INTRP)
517 void print_dynamic_super_statistics(void) {}
518 #endif
519
520
521 /************************ global variables **********************/
522
523 #define ACC_NATIVELY_OVERLOADED    0x10000000
524
525 chain *ident_chain;     /* chain with method and field names in current class */
526 FILE *file = NULL;
527 static u4 outputsize;
528 static bool dopadding;
529
530
531 static void printIDpart(int c)
532 {
533         if ((c >= 'a' && c <= 'z') ||
534                 (c >= 'A' && c <= 'Z') ||
535                 (c >= '0' && c <= '9') ||
536                 (c == '_'))
537                 putc(c, file);
538         else
539                 putc('_', file);
540 }
541
542
543 void printID(utf *u)
544 {
545         char *utf_ptr = u->text;
546         int i;
547
548         for (i = 0; i < utf_get_number_of_u2s(u); i++) 
549                 printIDpart(utf_nextu2(&utf_ptr));
550 }
551
552
553 static void addoutputsize (int len)
554 {
555         u4 newsize,i;
556         if (!dopadding) return;
557
558         newsize = ALIGN(outputsize, len);
559         
560         for (i = outputsize; i < newsize; i++) fprintf(file, "   u1 pad%d\n", (int) i);
561         outputsize = newsize;
562 }
563
564
565 void printOverloadPart(utf *desc)
566 {
567         char *utf_ptr=desc->text;
568         u2 c;
569
570         fprintf(file, "__");
571
572         while ((c = utf_nextu2(&utf_ptr)) != ')') {
573                 switch (c) {
574                 case 'I':
575                 case 'S':
576                 case 'B':
577                 case 'C':
578                 case 'Z':
579                 case 'J':
580                 case 'F':
581                 case 'D': 
582                         fprintf(file, "%c", (char) c);
583                         break;
584                 case '[':
585                         fprintf(file, "_3");
586                         break;
587                 case 'L':
588                         putc('L', file);
589                         while ((c = utf_nextu2(&utf_ptr)) != ';')
590                                 printIDpart(c);
591                         fprintf(file, "_2");
592                         break;
593                 case '(':
594                         break;
595                 default: 
596                         log_text("invalid method descriptor");
597                         assert(0);
598                 }
599         }
600 }
601
602 static char *printtype(char *utf_ptr)
603 {
604         u2 c;
605
606         switch (utf_nextu2(&utf_ptr)) {
607         case 'V': fprintf (file, "void");
608                 break;
609         case 'I':
610         case 'S':
611         case 'B':
612         case 'C':
613         case 'Z': addoutputsize (4);
614                 fprintf (file, "s4");
615                 break;
616         case 'J': addoutputsize (8);
617                 fprintf (file, "s8");
618                 break;
619         case 'F': addoutputsize (4);
620                 fprintf (file, "float");
621                 break;
622         case 'D': addoutputsize (8);
623                 fprintf (file, "double");
624                 break;
625         case '[':
626                 addoutputsize ( sizeof(java_arrayheader*) ); 
627                 switch (utf_nextu2(&utf_ptr)) {
628                 case 'I':  fprintf (file, "java_intarray*"); break;
629                 case 'J':  fprintf (file, "java_longarray*"); break;
630                 case 'Z':  fprintf (file, "java_booleanarray*"); break;
631                 case 'B':  fprintf (file, "java_bytearray*"); break;
632                 case 'S':  fprintf (file, "java_shortarray*"); break;
633                 case 'C':  fprintf (file, "java_chararray*"); break;
634                 case 'F':  fprintf (file, "java_floatarray*"); break;
635                 case 'D':  fprintf (file, "java_doublearray*"); break;
636                                 
637                 case '[': fprintf(file, "java_objectarray*");
638                         while ((c = utf_nextu2(&utf_ptr)) == '[');
639                         if (c == 'L')
640                                 while (utf_nextu2(&utf_ptr) != ';');
641                         break;
642                            
643                 case 'L':  fprintf(file, "java_objectarray*");
644                         while (utf_nextu2(&utf_ptr) != ';');
645                         break;
646                 default:
647                         log_text("invalid type descriptor");
648                         assert(0);
649                 }
650                 break;
651                 
652         case 'L': 
653                 addoutputsize ( sizeof(java_objectheader*));
654                 fprintf (file, "struct ");
655                 while ( (c = utf_nextu2(&utf_ptr)) != ';' ) printIDpart (c);     
656                 fprintf (file, "*");
657                 break;
658                                         
659         default:
660                 log_text("Unknown type in field descriptor");
661                 assert(0);
662         }
663         
664         return utf_ptr;
665 }
666
667
668 /***** determine the number of entries of a utf string in the ident chain *****/
669
670 static int searchidentchain_utf(utf *ident) 
671 {
672         utf *u = chain_first(ident_chain);     /* first element of list */
673         int count = 0;
674
675         while (u) {
676                 if (u==ident) count++;         /* string found */
677                 u = chain_next(ident_chain);   /* next element in list */ 
678         }
679
680         return count;
681 }
682
683
684 /************** print structure for direct access to objects ******************/
685
686 static void printfields(classinfo *c)
687 {
688         u4 i;
689         fieldinfo *f;
690         int ident_count;
691         
692         if (!c) {
693                 addoutputsize(sizeof(java_objectheader));
694                 fprintf(file, "   java_objectheader header;\n");
695                 return;
696         }
697                 
698         printfields(c->super.cls);
699         
700         for (i = 0; i < c->fieldscount; i++) {
701                 f = &(c->fields[i]);
702                 
703                 if (!(f->flags & ACC_STATIC)) {
704                         fprintf(file, "   ");
705                         printtype(f->descriptor->text);
706                         fprintf(file, " ");
707                         utf_fprint_printable_ascii(file, f->name);
708
709                         /* rename multiple fieldnames */
710                         if ((ident_count = searchidentchain_utf(f->name)))
711                                 fprintf(file, "%d", ident_count - 1);
712                         chain_addlast(ident_chain, f->name);    
713
714                         fprintf(file, ";\n");
715                 }
716         }
717 }
718
719
720 /***************** store prototype for native method in file ******************/
721
722 void printmethod(methodinfo *m)
723 {
724         char *utf_ptr;
725         u2 paramnum = 1;
726
727         /* search for return-type in descriptor */      
728         utf_ptr = m->descriptor->text;
729         while (utf_nextu2(&utf_ptr) != ')');
730
731         /* create remarks */
732         fprintf(file, "\n/*\n * Class:     ");
733         utf_fprint_printable_ascii(file, m->class->name);
734         fprintf(file, "\n * Method:    ");
735         utf_fprint_printable_ascii(file, m->name);
736         fprintf(file, "\n * Signature: ");
737         utf_fprint_printable_ascii(file, m->descriptor);
738         fprintf(file, "\n */\n");
739
740         /* create prototype */                  
741         fprintf(file, "JNIEXPORT ");
742         printtype(utf_ptr);
743         fprintf(file, " JNICALL Java_");
744         printID(m->class->name);
745
746         chain_addlast(ident_chain, m->name);
747
748         fprintf(file, "_");
749         printID(m->name);
750
751         /* ATTENTION: We use a dummy flag here. */
752
753         if (m->flags & ACC_NATIVELY_OVERLOADED)
754                 printOverloadPart(m->descriptor);
755
756         fprintf(file, "(JNIEnv *env");
757         
758         utf_ptr = m->descriptor->text + 1;
759                         
760         if (!(m->flags & ACC_STATIC)) {
761                 fprintf(file, ", struct ");
762                 printID(m->class->name);
763                 fprintf(file, "* this");
764
765         } else {
766                 fprintf(file, ", jclass clazz");
767         }
768
769         if ((*utf_ptr) != ')') fprintf(file, ", ");
770                         
771         while ((*utf_ptr) != ')') {
772                 utf_ptr = printtype(utf_ptr);
773                 fprintf(file, " par%d", paramnum++);
774                 if ((*utf_ptr)!=')') fprintf(file, ", ");
775         }
776                         
777         fprintf(file, ");\n\n");
778 }
779
780
781 /******* remove package-name in fully-qualified classname *********************/
782
783 void gen_header_filename(char *buffer, utf *u)
784 {
785         s4 i;
786   
787         for (i = 0; i < utf_get_number_of_u2s(u); i++) {
788                 if ((u->text[i] == '/') || (u->text[i] == '$')) {
789                         buffer[i] = '_';  /* convert '$' and '/' to '_' */
790
791                 } else {
792                         buffer[i] = u->text[i];
793                 }
794         }
795         buffer[utf_get_number_of_u2s(u)] = '\0';
796 }
797
798
799 /* create headerfile for classes and store native methods in chain ************/
800
801 void headerfile_generate(classinfo *c, char *opt_directory)
802 {
803         char header_filename[1024] = "";
804         char classname[1024]; 
805         char uclassname[1024];
806         u2 i;
807         methodinfo *m;                  
808         u2 j;
809         methodinfo *m2;
810         bool nativelyoverloaded;
811
812         /* prevent compiler warnings */
813
814         nativelyoverloaded = false;
815
816         /* open headerfile for class */
817         gen_header_filename(classname, c->name);
818
819         /* create chain for renaming fields */
820         ident_chain = chain_new();
821         
822         if (opt_directory) {
823                 sprintf(header_filename, "%s/%s.h", opt_directory, classname);
824
825         } else {
826                 sprintf(header_filename, "%s.h", classname);
827         }
828
829         file = fopen(header_filename, "w");
830         if (!file) {
831                 log_text("Can not open file to store header information");
832                 assert(0);
833         }
834
835         fprintf(file, "/* This file is machine generated, don't edit it! */\n\n");
836
837         /* convert to uppercase */
838         for (i = 0; classname[i]; i++) {
839                 uclassname[i] = toupper(classname[i]);
840         }
841         uclassname[i] = '\0';
842
843         fprintf(file, "#ifndef _%s_H\n#define _%s_H\n\n", uclassname, uclassname);
844
845         /* create structure for direct access to objects */     
846         fprintf(file, "/* Structure information for class: ");
847         utf_fprint_printable_ascii(file, c->name);
848         fprintf(file, " */\n\n");
849         fprintf(file, "typedef struct ");
850         printID(c->name);                                                       
851         fprintf(file, " {\n");
852         outputsize = 0;
853         dopadding = true;
854
855         printfields(c);
856
857         fprintf(file, "} ");
858         printID(c->name);
859         fprintf(file, ";\n\n");
860
861         /* create chain for renaming overloaded methods */
862         chain_free(ident_chain);
863         ident_chain = chain_new();
864
865         /* create method-prototypes */
866                                 
867         /* find overloaded methods */
868
869         for (i = 0; i < c->methodscount; i++) {
870                 m = &(c->methods[i]);
871
872                 if (!(m->flags & ACC_NATIVE))
873                         continue;
874
875                 /* We use a dummy flag here. */
876
877                 if (!(m->flags & ACC_NATIVELY_OVERLOADED)) {
878                         nativelyoverloaded = false;
879
880                         for (j = i + 1; j < c->methodscount; j++) {
881                                 m2 = &(c->methods[j]);
882
883                                 if (!(m2->flags & ACC_NATIVE))
884                                         continue;
885
886                                 if (m->name == m2->name) {
887                                         m2->flags          |= ACC_NATIVELY_OVERLOADED;
888                                         nativelyoverloaded  = true;
889                                 }
890                         }
891                 }
892
893                 if (nativelyoverloaded == true)
894                         m->flags |= ACC_NATIVELY_OVERLOADED;
895         }
896
897         for (i = 0; i < c->methodscount; i++) {
898                 m = &(c->methods[i]);
899
900                 if (m->flags & ACC_NATIVE)
901                         printmethod(m);
902         }
903
904         chain_free(ident_chain);
905
906         fprintf(file, "#endif\n\n");
907
908         fclose(file);
909 }
910
911
912 /******** print classname, '$' used to seperate inner-class name ***********/
913
914 void print_classname(classinfo *clazz)
915 {
916         utf *u = clazz->name;
917     char *endpos  = u->text + u->blength;
918     char *utf_ptr = u->text; 
919         u2 c;
920
921     while (utf_ptr < endpos) {
922                 if ((c = utf_nextu2(&utf_ptr)) == '_')
923                         putc('$', file);
924                 else
925                         putc(c, file);
926         }
927
928
929 /* jvmti releated functions ************************************************/
930
931 #if defined(ENABLE_JVMTI)
932 void jvmti_ThreadStartEnd(int ev) {;}
933 void jvmti_ClassLoadPrepare(bool prepared, classinfo *c) {;}
934 void jvmti_MonitorContendedEntering(bool entered, jobject obj) {;}
935 #endif
936
937
938
939 /*
940  * These are local overrides for various environment variables in Emacs.
941  * Please do not remove this and leave it at the end of the file, where
942  * Emacs will automagically detect them.
943  * ---------------------------------------------------------------------
944  * Local variables:
945  * mode: c
946  * indent-tabs-mode: t
947  * c-basic-offset: 4
948  * tab-width: 4
949  * End:
950  * vim:noexpandtab:sw=4:ts=4:
951  */