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