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