a few finalizer testcases, old thread implementation uses now VMThread, no mor contex...
[cacao.git] / headers.c
1 /* headers.c - main for header generation (cacaoh)
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    Changes: Mark Probst
30             Philipp Tomsich
31
32    $Id: headers.c 1173 2004-06-16 14:56:18Z jowenn $
33
34 */
35
36
37 #include <stdlib.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include "config.h"
41 #include "global.h"
42 #include "tables.h"
43 #include "loader.h"
44 #include "builtin.h"
45 #include "mm/boehm.h"
46 #include "toolbox/chain.h"
47 #include "toolbox/memory.h"
48 #include "toolbox/logging.h"
49 #include "nat/java_lang_String.h"
50
51
52 /* replace command line options */
53
54 bool verbose =  false;
55 bool verboseexception =  false;
56 bool compileall = false;
57 bool runverbose = false;
58 bool collectverbose = false;
59
60 bool loadverbose = false;
61 bool linkverbose = false;
62 bool initverbose = false;
63
64 bool opt_rt = false;            /* true if RTA parse should be used     RT-CO */
65 bool opt_xta = false;           /* true if XTA parse should be used    XTA-CO */
66 bool opt_vta = false;           /* true if VTA parse should be used    VTA-CO */
67 bool opt_verify = true;        /* true if classfiles should be verified      */
68 bool opt_liberalutf = false;   /* Don't check overlong UTF-8 sequences       */
69
70 bool opt_stat = false;
71 bool opt_eager = false;
72
73 bool showmethods = false;
74 bool showconstantpool = false;
75 bool showutf = false;
76
77 bool makeinitializations = true;
78
79 bool getloadingtime = false;
80 s8 loadingtime = 0;
81
82
83 /******* replace some external functions  *********/
84  
85 functionptr native_findfunction(utf *cname, utf *mname, utf *desc, bool isstatic)
86 { return NULL; }
87
88 java_objectheader *javastring_new(utf *text)
89 { return NULL; }
90
91 utf *javastring_toutf(java_lang_String *string, bool isclassname)
92 { return NULL; }
93
94
95 /* some exception stuff */
96
97 char *string_java_lang_IllegalMonitorStateException =
98     "java/lang/IllegalMonitorStateException";
99
100 char *string_java_lang_NegativeArraySizeException =
101     "java/lang/NegativeArraySizeException";
102
103
104 char *string_java_lang_AbstractMethodError =
105     "java/lang/AbstractMethodError";
106
107 char *string_java_lang_ClassCircularityError =
108     "java/lang/ClassCircularityError";
109
110 char *string_java_lang_ClassFormatError =
111     "java/lang/ClassFormatError";
112
113 char *string_java_lang_ExceptionInInitializerError =
114     "java/lang/ExceptionInInitializerError";
115
116 char *string_java_lang_IncompatibleClassChangeError =
117     "java/lang/IncompatibleClassChangeError";
118
119 char *string_java_lang_InternalError =
120     "java/lang/InternalError";
121
122 char *string_java_lang_LinkageError =
123     "java/lang/LinkageError";
124
125 char *string_java_lang_NoClassDefFoundError =
126     "java/lang/NoClassDefFoundError";
127
128 char *string_java_lang_NoSuchFieldError =
129     "java/lang/NoSuchFieldError";
130
131 char *string_java_lang_NoSuchMethodError =
132         "java/lang/NoSuchMethodError";
133
134 char *string_java_lang_OutOfMemoryError =
135     "java/lang/OutOfMemoryError";
136
137
138 void throw_exception_exit() {}
139
140 void throw_cacao_exception_exit(char *exception, char *message)
141 {
142         fprintf(stderr,
143                         "Exception in thread \"main\" %s: %s\n", exception, message);
144         fflush(stderr);
145
146         /* good bye! */
147         exit(1);
148 }
149
150
151 void new_exception(char *classname) {}
152 void new_exception_message(char *classname, char *message) {}
153 void new_exception_throwable(char *classname, java_objectheader *t) {}
154 void new_exception_utfmessage(char *classname, utf *message)
155 {
156         printf("%s: ", classname);
157         utf_display(message);
158         printf("\n");
159         exit(1);
160 }
161
162 java_objectheader *literalstring_new(utf *u) { return NULL; }  
163
164
165 void literalstring_free(java_objectheader *o) { }
166 void stringtable_update() { }
167 void synchronize_caches() { }
168 void asm_call_jit_compiler() { }
169 void asm_calljavafunction() { }
170 s4 asm_builtin_checkcast(java_objectheader *obj, classinfo *class) { return 0; }
171
172 s4 asm_builtin_idiv(s4 a, s4 b) {return 0;}
173 s4 asm_builtin_irem(s4 a, s4 b) {return 0;}
174 s8 asm_builtin_ldiv(s8 a, s8 b) {return 0;}
175 s8 asm_builtin_lrem(s8 a, s8 b) {return 0;}
176
177 s4 asm_builtin_f2i(float a) { return 0; }
178 s8 asm_builtin_f2l(float a) { return 0; }
179 s4 asm_builtin_d2i(double a) { return 0; }
180 s8 asm_builtin_d2l(double a) { return 0; }
181
182 void asm_builtin_monitorenter(java_objectheader *o) {}
183 void asm_builtin_monitorexit(java_objectheader *o) {}
184
185 s4 asm_builtin_checkarraycast(java_objectheader *obj, vftbl *target) {return 0;}
186
187 #if defined(__MIPS__)
188 void atomic_swap() {}
189 void compare_and_swap() {}
190 #endif
191
192
193 #if defined(__I386__)
194 s4 asm_builtin_arrayinstanceof(java_objectheader *obj, classinfo *class) { return 0; }
195 void asm_builtin_newarray(s4 size, vftbl *arrayvftbl) {}
196 #endif
197
198 void asm_builtin_aastore(java_objectarray *a, s4 index, java_objectheader *o) {}
199
200 u1 *createcompilerstub(methodinfo *m) {return NULL;}
201 u1 *createnativestub(functionptr f, methodinfo *m) {return NULL;}
202 u1 *oldcreatenativestub(functionptr f, methodinfo *m) {return NULL;}
203
204 void removecompilerstub(u1 *stub) {}
205 void removenativestub(u1 *stub) {}
206
207 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop) {}
208 u1* asm_initialize_thread_stack(void *func, u1 *stack) { return NULL; }
209 void thread_restartcriticalsection() {}
210 void asm_switchstackandcall() {}
211 void asm_handle_builtin_exception(classinfo *c) {}
212 void asm_getclassvalues_atomic() {}
213
214 #if defined(__DARWIN__)
215 int cacao_catch_Handler() {}
216 #endif
217
218 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
219 threadcritnode asm_criticalsections;
220 #endif
221
222 java_objectheader *native_new_and_init(void *p) { return NULL; }
223
224
225 /************************ global variables **********************/
226
227 THREADSPECIFIC java_objectheader *_exceptionptr;
228
229 static chain *nativemethod_chain;    /* chain with native methods     */
230 static chain *nativeclass_chain;                               /* chain with processed classes  */      
231 static chain *ident_chain;        /* chain with method and field names in current class */
232 static FILE *file = NULL;
233 static u4 outputsize;
234 static bool dopadding;
235
236
237 static void printIDpart(int c) 
238 {
239         if ((c >= 'a' && c <= 'z')
240                 || (c >= 'A' && c <= 'Z')
241                 || (c >= '0' && c <= '9')
242                 || (c == '_'))
243                 putc(c, file);
244         else
245                 putc('_', file);
246 }
247
248
249 static void printID(utf *u)
250 {
251         char *utf_ptr = u->text;
252         int i;
253
254         for (i = 0; i < utf_strlen(u); i++) 
255                 printIDpart(utf_nextu2(&utf_ptr));
256 }
257
258
259 static void addoutputsize (int len)
260 {
261         u4 newsize,i;
262         if (!dopadding) return;
263
264         newsize = ALIGN(outputsize, len);
265         
266         for (i = outputsize; i < newsize; i++) fprintf(file, "   u1 pad%d\n", (int) i);
267         outputsize = newsize;
268 }
269
270 static void printOverloadPart(utf *desc)
271 {
272         char *utf_ptr=desc->text;
273         u2 c;
274
275         fprintf(file,"__");
276         while ((c=utf_nextu2(&utf_ptr))!=')') {
277                 switch (c) {
278                         case 'I':
279                         case 'S':
280                         case 'B':
281                         case 'C':
282                         case 'Z':
283                         case 'J':
284                         case 'F':
285                         case 'D': 
286                                 fprintf (file, "%c",(char)c);
287                                 break;
288                         case '[':
289                                 fprintf(file,"_3");
290                                 break;
291                         case 'L':
292                                 putc('L',file);
293                                 while ( (c=utf_nextu2(&utf_ptr)) != ';')
294                                         printIDpart (c);
295                                 fprintf(file,"_2");
296                                 break;
297                         case '(':
298                                 break;
299                         default: panic ("invalid method descriptor");
300                 }
301         }
302 }
303
304 static char *printtype(char *utf_ptr)
305 {
306         u2 c;
307
308         switch (utf_nextu2(&utf_ptr)) {
309         case 'V': fprintf (file, "void");
310                 break;
311         case 'I':
312         case 'S':
313         case 'B':
314         case 'C':
315         case 'Z': addoutputsize (4);
316                 fprintf (file, "s4");
317                 break;
318         case 'J': addoutputsize (8);
319                 fprintf (file, "s8");
320                 break;
321         case 'F': addoutputsize (4);
322                 fprintf (file, "float");
323                 break;
324         case 'D': addoutputsize (8);
325                 fprintf (file, "double");
326                 break;
327         case '[':
328                 addoutputsize ( sizeof(java_arrayheader*) ); 
329                 switch (utf_nextu2(&utf_ptr)) {
330                 case 'I':  fprintf (file, "java_intarray*"); break;
331                 case 'J':  fprintf (file, "java_longarray*"); break;
332                 case 'Z':  fprintf (file, "java_booleanarray*"); break;
333                 case 'B':  fprintf (file, "java_bytearray*"); break;
334                 case 'S':  fprintf (file, "java_shortarray*"); break;
335                 case 'C':  fprintf (file, "java_chararray*"); break;
336                 case 'F':  fprintf (file, "java_floatarray*"); break;
337                 case 'D':  fprintf (file, "java_doublearray*"); break;
338                                 
339                 case '[':  fprintf (file, "java_objectarray*");                                        
340                         while ((c = utf_nextu2(&utf_ptr)) == '[') ;
341                         if (c=='L') 
342                                 while (utf_nextu2(&utf_ptr) != ';');
343                         break;
344                            
345                 case 'L':  fprintf (file, "java_objectarray*");
346                         while ( utf_nextu2(&utf_ptr) != ';');
347                         break;
348                 default: panic ("invalid type descriptor");
349                 }
350                 break;
351                 
352         case 'L': 
353                 addoutputsize ( sizeof(java_objectheader*));
354                 fprintf (file, "struct ");
355                 while ( (c = utf_nextu2(&utf_ptr)) != ';' ) printIDpart (c);     
356                 fprintf (file, "*");
357                 break;
358                                         
359         default:  panic ("Unknown type in field descriptor");
360         }
361         
362         return utf_ptr;
363 }
364
365
366 /***** determine the number of entries of a utf string in the ident chain *****/
367
368 static int searchidentchain_utf(utf *ident) 
369 {
370         utf *u = chain_first(ident_chain);     /* first element of list */
371         int count = 0;
372
373         while (u) {
374                 if (u==ident) count++;         /* string found */
375                 u = chain_next(ident_chain);   /* next element in list */ 
376         }
377
378         return count;
379 }
380
381
382 /************** print structure for direct access to objects ******************/
383
384 static void printfields(classinfo *c)
385 {
386         u4 i;
387         fieldinfo *f;
388         int ident_count;
389         
390         if (!c) {
391                 addoutputsize(sizeof(java_objectheader));
392                 fprintf(file, "   java_objectheader header;\n");
393                 return;
394         }
395                 
396         printfields(c->super);
397         
398         for (i = 0; i < c->fieldscount; i++) {
399                 f = &(c->fields[i]);
400                 
401                 if (!(f->flags & ACC_STATIC)) {
402                         fprintf(file, "   ");
403                         printtype(f->descriptor->text);
404                         fprintf(file, " ");
405                         utf_fprint(file, f->name);
406
407                         /* rename multiple fieldnames */
408                         if ((ident_count = searchidentchain_utf(f->name)))
409                                 fprintf(file, "%d", ident_count - 1);
410                         chain_addlast(ident_chain, f->name);    
411
412                         fprintf(file, ";\n");
413                 }
414         }
415 }
416
417
418 /***************** store prototype for native method in file ******************/
419
420 static void printmethod(methodinfo *m)
421 {
422         char *utf_ptr;
423         u2 paramnum = 1;
424         u2 ident_count;
425
426         /* search for return-type in descriptor */      
427         utf_ptr = m->descriptor->text;
428         while (utf_nextu2(&utf_ptr) != ')');
429
430         /* create remarks */
431         fprintf(file, "\n/*\n * Class:     ");
432         utf_fprint(file, m->class->name);
433         fprintf(file, "\n * Method:    ");
434         utf_fprint(file, m->name);
435         fprintf(file, "\n * Signature: ");
436         utf_fprint(file, m->descriptor);
437         fprintf(file, "\n */\n");       
438
439         /* create prototype */                  
440         fprintf(file, "JNIEXPORT ");                            
441         printtype(utf_ptr);
442         fprintf(file, " JNICALL Java_");
443         printID(m->class->name);           
444
445         chain_addlast(ident_chain, m->name);    
446
447         fprintf(file, "_");
448         printID(m->name);
449         if (m->nativelyoverloaded) printOverloadPart(m->descriptor);
450         fprintf(file, "(JNIEnv *env");
451         
452         utf_ptr = m->descriptor->text + 1;
453                         
454         if (!(m->flags & ACC_STATIC)) {
455                 fprintf(file, ", struct ");
456                 printID(m->class->name);
457                 fprintf(file, "* this");
458
459         } else {
460                 fprintf(file, ", jclass clazz");
461         }
462
463         if ((*utf_ptr) != ')') fprintf(file, ", ");
464                         
465         while ((*utf_ptr) != ')') {
466                 utf_ptr = printtype(utf_ptr);
467                 fprintf(file, " par%d", paramnum++);
468                 if ((*utf_ptr)!=')') fprintf(file, ", ");
469         }
470                         
471         fprintf(file, ");\n\n");
472 }
473
474
475 /******* remove package-name in fully-qualified classname *********************/
476
477 static void gen_header_filename(char *buffer, utf *u)
478 {
479         int i;
480   
481         for (i = 0;i < utf_strlen(u); i++) {
482                 if ((u->text[i] == '/') || (u->text[i] == '$')) buffer[i] = '_';  /* convert '$' and '/' to '_' */
483                 else buffer[i] = u->text[i];
484         }
485         buffer[utf_strlen(u)] = '\0';
486 }
487
488
489 /* create headerfile for classes and store native methods in chain ************/
490
491 static void headerfile_generate(classinfo *c)
492 {
493         char header_filename[1024] = "";
494         char classname[1024]; 
495         char uclassname[1024];
496         u2 i;
497         methodinfo *m;                  
498         u2 i2;
499         methodinfo *m2;
500         u2 nativelyoverloaded;                  
501                       
502         /* store class in chain */                    
503         chain_addlast(nativeclass_chain, c);
504                                 
505         /* open headerfile for class */
506         gen_header_filename(classname, c->name);
507
508         /* create chain for renaming fields */
509         ident_chain = chain_new();
510         
511         sprintf(header_filename, "nat/%s.h", classname);
512         file = fopen(header_filename, "w");
513         if (!file) panic("Can not open file to store header information");
514
515         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
516
517         /* convert to uppercase */
518         for (i = 0; classname[i]; i++) {
519                 uclassname[i] = toupper(classname[i]);
520         }
521         uclassname[i] = '\0';
522
523         fprintf(file, "#ifndef _%s_H\n#define _%s_H\n\n", uclassname, uclassname);
524
525         /* create structure for direct access to objects */     
526         fprintf(file, "/* Structure information for class: ");
527         utf_fprint(file, c->name);
528         fprintf(file, " */\n\n");
529         fprintf(file, "typedef struct ");
530         printID(c->name);                                                       
531         fprintf(file, " {\n");
532         outputsize = 0;
533         dopadding = true;
534
535         printfields(c);
536
537         fprintf(file, "} ");
538         printID(c->name);
539         fprintf(file, ";\n\n");
540
541         /* create chain for renaming overloaded methods */
542         chain_free(ident_chain);
543         ident_chain = chain_new();
544
545         /* create method-prototypes */
546                                 
547         /* find overloaded methods */
548         for (i = 0; i < c->methodscount; i++) {
549
550                 m = &(c->methods[i]);
551
552                 if (!(m->flags & ACC_NATIVE)) continue;
553                 if (!m->nativelyoverloaded) {
554                         nativelyoverloaded=false;
555                         for (i2=i+1;i2<c->methodscount; i2++) {
556                                 m2 = &(c->methods[i2]);
557                                 if (!(m2->flags & ACC_NATIVE)) continue;
558                                 if (m->name==m2->name) {
559                                         m2->nativelyoverloaded=true;
560                                         nativelyoverloaded=true;
561                                 }
562                         }
563                         m->nativelyoverloaded=nativelyoverloaded;
564                 }
565
566         }
567
568         for (i = 0; i < c->methodscount; i++) {
569
570                 m = &(c->methods[i]);
571
572                 if (m->flags & ACC_NATIVE) {
573                         chain_addlast(nativemethod_chain, m);
574                         printmethod(m);
575                 }
576         }
577
578         chain_free(ident_chain);
579
580         fprintf(file, "#endif\n\n");
581
582         fclose(file);
583 }
584
585
586 /******** print classname, '$' used to seperate inner-class name ***********/
587
588 void print_classname(classinfo *clazz)
589 {
590         utf *u = clazz->name;
591     char *endpos  = u->text + u->blength;
592     char *utf_ptr = u->text; 
593         u2 c;
594
595     while (utf_ptr < endpos) {
596                 if ((c = utf_nextu2(&utf_ptr)) == '_') {
597                         putc('$', file);
598
599                 } else {
600                         putc(c, file);
601                 }
602         }
603
604
605
606 /*************** create table for locating native functions ****************/
607
608 static void printnativetableentry(methodinfo *m)
609 {
610         fprintf(file, "   { \"");
611         print_classname(m->class);
612         fprintf(file, "\",\n     \"");
613         utf_fprint(file, m->name);
614         fprintf(file, "\",\n     \"");
615         utf_fprint(file, m->descriptor);
616         fprintf(file, "\",\n     ");
617
618         if ((m->flags & ACC_STATIC) != 0)
619                 fprintf(file, "true");
620         else
621                 fprintf(file, "false");
622
623         fprintf(file, ",\n     ");
624         fprintf(file, "(functionptr) Java_");
625         printID(m->class->name);
626         fprintf(file,"_");
627         printID(m->name);
628         if (m->nativelyoverloaded) printOverloadPart(m->descriptor);
629         fprintf(file,"\n   },\n");
630 }
631
632
633 /***************************************************************************
634
635         create the nativetypes-headerfile which includes 
636         the headerfiles of the classes stored in the classes-chain 
637
638 ****************************************************************************/
639
640 static void headers_finish()
641 {
642         methodinfo *m;
643         classinfo *c;
644         char classname[1024];
645         
646         file = fopen("nativetypes.hh", "w");
647
648         if (!file)
649                 panic("Can not open file 'native.h' to store header information");
650         
651         fprintf(file, "/* Headerfile for native methods: nativetypes.hh */\n");
652         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");      
653         fprintf(file, "\n/* include native-Headerfiles */\n\n");
654                         
655         c = chain_first(nativeclass_chain);
656         while (c) {
657                 dopadding = false;
658                 gen_header_filename(classname, c->name);                                                                                                                                                                                        
659                 fprintf(file, "#include \"nat/%s.h\"\n", classname);            
660                 c = chain_next(nativeclass_chain);              
661         }
662
663     fclose(file);
664         chain_free(nativeclass_chain);
665         
666         /* create table of native-methods */
667
668         file = fopen("nativetable.hh", "w");
669
670         if (!file)
671                 panic("Can not open file 'nativetable' to store native-link-table");
672
673         fprintf(file, "/* Table of native methods: nativetables.hh */\n");
674         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n"); 
675
676         while ((m = chain_first(nativemethod_chain)) != NULL) {
677                 chain_remove(nativemethod_chain);               
678                 printnativetableentry(m);
679         }
680                 
681         chain_free(nativemethod_chain);
682         fclose(file);
683 }
684
685
686 /******************** internal function: print_usage ************************
687
688 Prints usage information for the JAVA header generator to stdout.
689
690 ***************************************************************************/
691
692 static void print_usage()
693 {
694         printf("Usage: cacaoh class [class..]\n");
695 }   
696
697
698
699 /************************** Function: main *******************************
700
701    Main program.
702    
703 **************************************************************************/
704
705 int main(int argc, char **argv)
706 {
707         s4 i,a;
708         char *cp;
709         classinfo *topclass;
710                 
711
712         /********** internal (only used by main) *****************************/
713    
714         char classpath[500] = "";
715         char offsets_filename[1024] = ""; /* phil */
716         u4 heapmaxsize = 1000000;
717         u4 heapstartsize = 100000;
718
719         /*********** options so only headers are generated *******************/
720    
721         makeinitializations = false;
722    
723
724         /************ Collect some info from the environment *****************/
725
726         cp = getenv("CLASSPATH");
727         if (cp) {
728                 strcpy(classpath + strlen(classpath), ":");
729                 strcpy(classpath + strlen(classpath), cp);
730         }
731
732         if (argc < 2) {
733                 print_usage();
734                 exit(10);
735         }
736
737
738         /**************************** Program start **************************/
739
740         log_init(NULL);
741         log_text("Java - header-generator started"); 
742         
743         sprintf(offsets_filename, "jit/%s/offsets.h", ARCH_DIR);
744         file = fopen(offsets_filename, "w");
745         if (file == NULL) {
746                 fprintf(stderr, "Can not open file '%s' for write", offsets_filename);
747                 exit(-1);
748         }
749         
750         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n"); 
751
752         fprintf(file, "#define offobjvftbl    %3d\n", (int) OFFSET(java_objectheader, vftbl));
753         fprintf(file, "#define offarraysize   %3d\n", (int) OFFSET(java_arrayheader, size));
754         fprintf(file, "#define offobjarrdata  %3d\n\n", (int) OFFSET(java_objectarray, data[0]));
755         fprintf(file, "#define offbaseval     %3d\n", (int) OFFSET(vftbl, baseval));
756         fprintf(file, "#define offdiffval     %3d\n\n", (int) OFFSET(vftbl, diffval));
757         fprintf(file, "#define offclass     %3d\n\n", (int) OFFSET(vftbl, class));
758
759         fprintf(file, "#define offclassvftbl  %3d\n", (int) OFFSET(classinfo, vftbl));
760         fprintf(file, "#define offclassinit   %3d\n", (int) OFFSET(classinfo, initialized));
761         fprintf(file, "#define offclassloaded %3d\n", (int) OFFSET(classinfo, loaded));
762         fprintf(file, "#define offclasslinked %3d\n\n", (int) OFFSET(classinfo, linked));
763
764         fprintf(file, "#define offjniitemtype %3d\n", (int) OFFSET(jni_callblock, itemtype));
765         fprintf(file, "#define offjniitem     %3d\n", (int) OFFSET(jni_callblock, item));
766         fprintf(file, "#define sizejniblock   %3d\n\n", (int) sizeof(jni_callblock));
767
768         fprintf(file, "#define offclassmethodinfo   %3d\n\n", (int) OFFSET(methodinfo,class));
769
770         fprintf(file, "#define offmethodnative %3d\n", (int) OFFSET(native_stackframeinfo,method));
771 /*      fprintf(file, "#define offreturnfromnative %3d\n", (int) OFFSET(native_stackframeinfo,returnFromNative));
772         fprintf(file, "#define offaddrreturnfromnative %3d\n", (int) OFFSET(native_stackframeinfo,addrReturnFromNative));
773         fprintf(file, "#define offprevnative %3d\n", (int) OFFSET(native_stackframeinfo,prev));
774         fprintf(file, "#define offnextnative %3d\n", (int) OFFSET(native_stackframeinfo,next));*/
775
776         fprintf(file, "\n");
777         fprintf(file, "#define offcast_super_baseval  %3d\n", (int) OFFSET(castinfo, super_baseval));
778         fprintf(file, "#define offcast_super_diffval  %3d\n", (int) OFFSET(castinfo, super_diffval));
779         fprintf(file, "#define offcast_sub_baseval    %3d\n", (int) OFFSET(castinfo, sub_baseval));
780
781         fclose(file);
782
783         /* initialize the garbage collector */
784         gc_init(heapmaxsize, heapstartsize);
785
786         suck_init(classpath);
787    
788         tables_init();
789
790 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
791         initThreadsEarly();
792 #endif
793         loader_init();
794
795
796         /*********************** Load JAVA classes  **************************/
797         
798         nativemethod_chain = chain_new();
799         nativeclass_chain = chain_new();
800         
801         for (a = 1; a < argc; a++) {
802                 cp = argv[a];
803
804                 /* convert classname */
805                 for (i = strlen(cp) - 1; i >= 0; i--) {
806                         switch (cp[i]) {
807                         case '.': cp[i]='/';
808                                 break;
809                         case '_': cp[i]='$';    
810                         }
811                 }
812         
813 /*              topclass = loader_load(utf_new_char(cp)); */
814                 topclass = class_load(class_new(utf_new_char(cp)));
815                 class_link(topclass);
816
817         headerfile_generate(topclass);
818         }
819
820         headers_finish();
821
822         /************************ Release all resources **********************/
823
824         loader_close();
825         tables_close(literalstring_free);
826
827         /* Print "finished" message */
828
829         log_text("Java - header-generator stopped");
830         log_cputime();
831         mem_usagelog(1);
832         
833         return 0;
834 }
835
836
837 void setVMClassField(classinfo *c)
838 {
839 }
840
841
842 void *Java_java_lang_VMObject_clone(void *env, void *clazz, void * this) {
843         return 0;
844 }
845
846
847 /*
848  * These are local overrides for various environment variables in Emacs.
849  * Please do not remove this and leave it at the end of the file, where
850  * Emacs will automagically detect them.
851  * ---------------------------------------------------------------------
852  * Local variables:
853  * mode: c
854  * indent-tabs-mode: t
855  * c-basic-offset: 4
856  * tab-width: 4
857  * End:
858  */