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