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