* src/vm/options.h (opt_verify): Only declare for ENABLE_VERIFIER.
[cacao.git] / src / vm / vm.c
1 /* src/vm/finalizer.c - finalizer linked list and thread
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: Christian Thalinger
28
29    Changes:
30
31    $Id: finalizer.c 4357 2006-01-22 23:33:38Z twisti $
32
33 */
34
35
36 #include "config.h"
37
38 #include <assert.h>
39 #include <stdlib.h>
40
41 #include "vm/types.h"
42
43 #include "mm/boehm.h"
44 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/native.h"
47
48 #if defined(USE_THREADS)
49 # if defined(NATIVE_THREADS)
50 #  include "threads/native/threads.h"
51 # else
52 #  include "threads/green/threads.h"
53 #  include "threads/green/locks.h"
54 # endif
55 #endif
56
57 #include "vm/classcache.h"
58 #include "vm/exceptions.h"
59 #include "vm/finalizer.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/options.h"
63 #include "vm/properties.h"
64 #include "vm/signallocal.h"
65 #include "vm/stringlocal.h"
66 #include "vm/suck.h"
67 #include "vm/vm.h"
68 #include "vm/jit/jit.h"
69 #include "vm/jit/asmpart.h"
70 #include "vm/jit/profile/profile.h"
71 #include "vm/rt-timing.h"
72
73 #if defined(ENABLE_JVMTI)
74 #include "native/jvmti/cacaodbg.h"
75 #endif
76
77 /* Invocation API variables ***************************************************/
78
79 _Jv_JavaVM *_Jv_jvm;                    /* denotes a Java VM                  */
80 _Jv_JNIEnv *_Jv_env;                    /* pointer to native method interface */
81
82
83 /* global variables ***********************************************************/
84
85 s4 vms = 0;                             /* number of VMs created              */
86
87 bool vm_initializing = false;
88 bool vm_exiting = false;
89
90 #if defined(ENABLE_INTRP)
91 u1 *intrp_main_stack = NULL;
92 #endif
93
94 void **stackbottom = NULL;
95
96 char *mainstring = NULL;
97 classinfo *mainclass = NULL;
98
99 char *specificmethodname = NULL;
100 char *specificsignature = NULL;
101
102 bool startit = true;
103
104
105 /* define heap sizes **********************************************************/
106
107 #define HEAP_MAXSIZE      64 * 1024 * 1024  /* default 64MB                   */
108 #define HEAP_STARTSIZE    2  * 1024 * 1024  /* default 2MB                    */
109 #define STACK_SIZE              128 * 1024  /* default 128kB                  */
110
111
112 /* define command line options ************************************************/
113
114 enum {
115         /* Java options */
116
117         OPT_JAR,
118
119         OPT_D32,
120         OPT_D64,
121
122         OPT_CLASSPATH,
123         OPT_D,
124
125         OPT_VERBOSE,
126
127         OPT_VERSION,
128         OPT_SHOWVERSION,
129         OPT_FULLVERSION,
130
131         OPT_HELP,
132         OPT_X,
133
134         /* Java non-standard options */
135
136         OPT_JIT,
137         OPT_INTRP,
138
139         OPT_BOOTCLASSPATH,
140         OPT_BOOTCLASSPATH_A,
141         OPT_BOOTCLASSPATH_P,
142
143         OPT_PROF,
144         OPT_PROF_OPTION,
145
146         OPT_MS,
147         OPT_MX,
148
149         /* CACAO options */
150
151         OPT_VERBOSE1,
152         OPT_NOIEEE,
153         OPT_SOFTNULL,
154         OPT_TIME,
155
156 #if defined(ENABLE_STATISTICS)
157         OPT_STAT,
158 #endif
159
160         OPT_LOG,
161         OPT_CHECK,
162         OPT_LOAD,
163         OPT_METHOD,
164         OPT_SIGNATURE,
165         OPT_SHOW,
166         OPT_ALL,
167
168         OPT_VERBOSETC,
169 #if defined(ENABLE_VERIFIER)
170         OPT_NOVERIFY,
171 #endif
172         OPT_EAGER,
173
174         /* optimization options */
175
176 #if defined(ENABLE_LOOP)
177         OPT_OLOOP,
178 #endif
179         
180 #if defined(ENABLE_IFCONV)
181         OPT_IFCONV,
182 #endif
183
184 #if defined(ENABLE_LSRA)
185         OPT_LSRA,
186 #endif
187
188 #if defined(ENABLE_INLINING)
189         OPT_INLINING,
190 #endif
191
192 #if defined(ENABLE_INTRP)
193         /* interpreter options */
194
195         OPT_NO_DYNAMIC,
196         OPT_NO_REPLICATION,
197         OPT_NO_QUICKSUPER,
198         OPT_STATIC_SUPERS,
199         OPT_TRACE,
200 #endif
201
202         OPT_SS,
203
204 #ifdef ENABLE_JVMTI
205         OPT_DEBUG,
206         OPT_XRUNJDWP,
207         OPT_NOAGENT,
208         OPT_AGENTLIB,
209         OPT_AGENTPATH,
210 #endif
211
212         DUMMY
213 };
214
215
216 opt_struct opts[] = {
217         /* Java options */
218
219         { "jar",               false, OPT_JAR },
220
221         { "d32",               false, OPT_D32 },
222         { "d64",               false, OPT_D64 },
223         { "client",            false, OPT_IGNORE },
224         { "server",            false, OPT_IGNORE },
225         { "hotspot",           false, OPT_IGNORE },
226
227         { "classpath",         true,  OPT_CLASSPATH },
228         { "cp",                true,  OPT_CLASSPATH },
229         { "D",                 true,  OPT_D },
230         { "version",           false, OPT_VERSION },
231         { "showversion",       false, OPT_SHOWVERSION },
232         { "fullversion",       false, OPT_FULLVERSION },
233         { "help",              false, OPT_HELP },
234         { "?",                 false, OPT_HELP },
235         { "X",                 false, OPT_X },
236
237         { "noasyncgc",         false, OPT_IGNORE },
238 #if defined(ENABLE_VERIFIER)
239         { "noverify",          false, OPT_NOVERIFY },
240 #endif
241         { "v",                 false, OPT_VERBOSE1 },
242         { "verbose:",          true,  OPT_VERBOSE },
243
244 #ifdef TYPECHECK_VERBOSE
245         { "verbosetc",         false, OPT_VERBOSETC },
246 #endif
247 #if defined(__ALPHA__)
248         { "noieee",            false, OPT_NOIEEE },
249 #endif
250         { "softnull",          false, OPT_SOFTNULL },
251         { "time",              false, OPT_TIME },
252 #if defined(ENABLE_STATISTICS)
253         { "stat",              false, OPT_STAT },
254 #endif
255         { "log",               true,  OPT_LOG },
256         { "c",                 true,  OPT_CHECK },
257         { "l",                 false, OPT_LOAD },
258         { "eager",             false, OPT_EAGER },
259         { "sig",               true,  OPT_SIGNATURE },
260         { "all",               false, OPT_ALL },
261 #if defined(ENABLE_LOOP)
262         { "oloop",             false, OPT_OLOOP },
263 #endif
264 #if defined(ENABLE_IFCONV)
265         { "ifconv",            false, OPT_IFCONV },
266 #endif
267 #if defined(ENABLE_LSRA)
268         { "lsra",              false, OPT_LSRA },
269 #endif
270
271 #if defined(ENABLE_INTRP)
272         /* interpreter options */
273
274         { "trace",             false, OPT_TRACE },
275         { "static-supers",     true,  OPT_STATIC_SUPERS },
276         { "no-dynamic",        false, OPT_NO_DYNAMIC },
277         { "no-replication",    false, OPT_NO_REPLICATION },
278         { "no-quicksuper",     false, OPT_NO_QUICKSUPER },
279 #endif
280
281         /* JVMTI Agent Command Line Options */
282 #ifdef ENABLE_JVMTI
283         { "agentlib:",         true,  OPT_AGENTLIB },
284         { "agentpath:",        true,  OPT_AGENTPATH },
285 #endif
286
287         /* Java non-standard options */
288
289         { "Xjit",              false, OPT_JIT },
290         { "Xint",              false, OPT_INTRP },
291         { "Xbootclasspath:",   true,  OPT_BOOTCLASSPATH },
292         { "Xbootclasspath/a:", true,  OPT_BOOTCLASSPATH_A },
293         { "Xbootclasspath/p:", true,  OPT_BOOTCLASSPATH_P },
294 #ifdef ENABLE_JVMTI
295         { "Xdebug",            false, OPT_DEBUG },
296         { "Xnoagent",          false, OPT_NOAGENT },
297         { "Xrunjdwp",          true,  OPT_XRUNJDWP },
298 #endif 
299         { "Xms",               true,  OPT_MS },
300         { "ms",                true,  OPT_MS },
301         { "Xmx",               true,  OPT_MX },
302         { "mx",                true,  OPT_MX },
303         { "Xss",               true,  OPT_SS },
304         { "ss",                true,  OPT_SS },
305         { "Xprof:",            true,  OPT_PROF_OPTION },
306         { "Xprof",             false, OPT_PROF },
307
308         /* keep these at the end of the list */
309
310 #if defined(ENABLE_INLINING)
311         { "i",                 true,  OPT_INLINING },
312 #endif
313         { "m",                 true,  OPT_METHOD },
314         { "s",                 true,  OPT_SHOW },
315
316         { NULL,                false, 0 }
317 };
318
319
320 /* usage ***********************************************************************
321
322    Prints the correct usage syntax to stdout.
323
324 *******************************************************************************/
325
326 void usage(void)
327 {
328         puts("Usage: cacao [-options] classname [arguments]");
329         puts("               (to run a class file)");
330         puts("   or  cacao [-options] -jar jarfile [arguments]");
331         puts("               (to run a standalone jar file)\n");
332
333         puts("Java options:");
334         puts("    -d32                     use 32-bit data model if available");
335         puts("    -d64                     use 64-bit data model if available");
336         puts("    -client                  compatibility (currently ignored)");
337         puts("    -server                  compatibility (currently ignored)");
338         puts("    -hotspot                 compatibility (currently ignored)\n");
339
340         puts("    -cp <path>               specify a path to look for classes");
341         puts("    -classpath <path>        specify a path to look for classes");
342         puts("    -D<name>=<value>         add an entry to the property list");
343         puts("    -verbose[:class|gc|jni]  enable specific verbose output");
344         puts("    -version                 print product version and exit");
345         puts("    -fullversion             print jpackage-compatible product version and exit");
346         puts("    -showversion             print product version and continue");
347         puts("    -help, -?                print this help message");
348         puts("    -X                       print help on non-standard Java options\n");
349
350 #ifdef ENABLE_JVMTI
351         puts("    -agentlib:<agent-lib-name>=<options>  library to load containg JVMTI agent");
352         puts("    -agentpath:<path-to-agent>=<options>  path to library containg JVMTI agent");
353 #endif
354
355         puts("CACAO options:\n");
356         puts("    -v                       write state-information");
357         puts("    -verbose[:call|exception]enable specific verbose output");
358 #ifdef TYPECHECK_VERBOSE
359         puts("    -verbosetc               write debug messages while typechecking");
360 #endif
361 #if defined(__ALPHA__)
362         puts("    -noieee                  don't use ieee compliant arithmetic");
363 #endif
364 #if defined(ENABLE_VERIFIER)
365         puts("    -noverify                don't verify classfiles");
366 #endif
367         puts("    -softnull                use software nullpointer check");
368         puts("    -time                    measure the runtime");
369 #if defined(ENABLE_STATISTICS)
370         puts("    -stat                    detailed compiler statistics");
371 #endif
372         puts("    -log logfile             specify a name for the logfile");
373         puts("    -c(heck)b(ounds)         don't check array bounds");
374         puts("            s(ync)           don't check for synchronization");
375 #if defined(ENABLE_LOOP)
376         puts("    -oloop                   optimize array accesses in loops");
377 #endif
378         puts("    -l                       don't start the class after loading");
379         puts("    -eager                   perform eager class loading and linking");
380         puts("    -all                     compile all methods, no execution");
381         puts("    -m                       compile only a specific method");
382         puts("    -sig                     specify signature for a specific method");
383         puts("    -s(how)a(ssembler)       show disassembled listing");
384         puts("           c(onstants)       show the constant pool");
385         puts("           d(atasegment)     show data segment listing");
386         puts("           e(xceptionstubs)  show disassembled exception stubs (only with -sa)");
387         puts("           i(ntermediate)    show intermediate representation");
388         puts("           m(ethods)         show class fields and methods");
389         puts("           n(ative)          show disassembled native stubs");
390         puts("           u(tf)             show the utf - hash");
391 #if defined(ENABLE_INLINING)
392         puts("    -i     n(line)           activate inlining");
393         puts("           v(irtual)         inline virtual methods (uses/turns rt option on)");
394         puts("           e(exception)      inline methods with exceptions");
395         puts("           p(aramopt)        optimize argument renaming");
396         puts("           o(utsiders)       inline methods of foreign classes");
397 #endif /* defined(ENABLE_INLINING) */
398 #if defined(ENABLE_IFCONV)
399         puts("    -ifconv                  use if-conversion");
400 #endif
401 #if defined(ENABLE_LSRA)
402         puts("    -lsra                    use linear scan register allocation");
403 #endif
404
405         /* exit with error code */
406
407         exit(1);
408 }   
409
410
411 static void Xusage(void)
412 {
413 #if defined(ENABLE_JIT)
414         puts("    -Xjit                    JIT mode execution (default)");
415 #endif
416 #if defined(ENABLE_INTRP)
417         puts("    -Xint                    interpreter mode execution");
418 #endif
419         puts("    -Xbootclasspath:<zip/jar files and directories separated by :>");
420     puts("                             value is set as bootstrap class path");
421         puts("    -Xbootclasspath/a:<zip/jar files and directories separated by :>");
422         puts("                             value is appended to the bootstrap class path");
423         puts("    -Xbootclasspath/p:<zip/jar files and directories separated by :>");
424         puts("                             value is prepended to the bootstrap class path");
425         puts("    -Xms<size>               set the initial size of the heap (default: 2MB)");
426         puts("    -Xmx<size>               set the maximum size of the heap (default: 64MB)");
427         puts("    -Xss<size>               set the thread stack size (default: 128kB)");
428         puts("    -Xprof[:bb]              collect and print profiling data");
429 #if defined(ENABLE_JVMTI)
430     /* -Xdebug option depend on gnu classpath JDWP options. options: 
431          transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
432         puts("    -Xdebug           enable remote debugging\n");
433         puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
434         puts("                      enable remote debugging\n");
435 #endif 
436
437         /* exit with error code */
438
439         exit(1);
440 }   
441
442
443 /* version *********************************************************************
444
445    Only prints cacao version information.
446
447 *******************************************************************************/
448
449 static void version(void)
450 {
451         puts("java version \""JAVA_VERSION"\"");
452         puts("CACAO version "VERSION"");
453
454         puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
455         puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
456         puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
457         puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
458
459         puts("This program is free software; you can redistribute it and/or");
460         puts("modify it under the terms of the GNU General Public License as");
461         puts("published by the Free Software Foundation; either version 2, or (at");
462         puts("your option) any later version.\n");
463
464         puts("This program is distributed in the hope that it will be useful, but");
465         puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
466         puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU");
467         puts("General Public License for more details.\n");
468
469         puts("Configure/Build options:\n");
470         puts("  ./configure: "VERSION_CONFIGURE_ARGS"");
471 #if defined(__VERSION__)
472         puts("  CC         : "VERSION_CC" ("__VERSION__")");
473 #else
474         puts("  CC         : "VERSION_CC"");
475 #endif
476         puts("  CFLAGS     : "VERSION_CFLAGS"");
477 }
478
479
480 /* fullversion *****************************************************************
481
482    Prints a Sun compatible version information (required e.g. by
483    jpackage, www.jpackage.org).
484
485 *******************************************************************************/
486
487 static void fullversion(void)
488 {
489         puts("java full version \"cacao-"JAVA_VERSION"\"");
490
491         /* exit normally */
492
493         exit(0);
494 }
495
496
497 /* vm_create *******************************************************************
498
499    Creates a JVM.  Called by JNI_CreateJavaVM.
500
501 *******************************************************************************/
502
503 bool vm_create(JavaVMInitArgs *vm_args)
504 {
505         char *cp;
506         s4    cplen;
507         u4    heapmaxsize;
508         u4    heapstartsize;
509         s4    opt;
510         s4    i, j, k;
511
512         /* check the JNI version requested */
513
514         switch (vm_args->version) {
515         case JNI_VERSION_1_1:
516                 break;
517         case JNI_VERSION_1_2:
518         case JNI_VERSION_1_4:
519                 break;
520         default:
521                 return false;
522         }
523
524         /* we only support 1 JVM instance */
525
526         if (vms > 0)
527                 return false;
528
529
530         /* get stuff from the environment *****************************************/
531
532 #if defined(DISABLE_GC)
533         nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
534 #endif
535
536
537         /* set the bootclasspath */
538
539         cp = getenv("BOOTCLASSPATH");
540
541         if (cp) {
542                 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
543                 strcpy(bootclasspath, cp);
544
545         } else {
546                 cplen = strlen(CACAO_VM_ZIP_PATH) +
547                         strlen(":") +
548                         strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
549                         strlen("0");
550
551                 bootclasspath = MNEW(char, cplen);
552                 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
553                 strcat(bootclasspath, ":");
554                 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
555         }
556
557
558         /* set the classpath */
559
560         cp = getenv("CLASSPATH");
561
562         if (cp) {
563                 classpath = MNEW(char, strlen(cp) + strlen("0"));
564                 strcat(classpath, cp);
565
566         } else {
567                 classpath = MNEW(char, strlen(".") + strlen("0"));
568                 strcpy(classpath, ".");
569         }
570
571
572         /* interpret the options **************************************************/
573    
574         checknull  = false;
575         opt_noieee = false;
576
577         heapmaxsize   = HEAP_MAXSIZE;
578         heapstartsize = HEAP_STARTSIZE;
579         opt_stacksize = STACK_SIZE;
580
581
582 #if defined(ENABLE_JVMTI)
583         /* initialize JVMTI related  **********************************************/
584         jvmtibrkpt.brk=NULL;
585         jvmtibrkpt.num=0;
586         jvmtibrkpt.size=0;
587         jdwp = jvmti = dbgprocess = false;
588 #endif
589
590         /* initialize properties before commandline handling */
591
592         if (!properties_init())
593                 throw_cacao_exception_exit(string_java_lang_InternalError,
594                                                                    "Unable to init properties");
595
596         /* iterate over all passed options */
597
598         while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
599                 switch (opt) {
600                 case OPT_IGNORE:
601                         break;
602                         
603                 case OPT_JAR:
604                         opt_jar = true;
605                         break;
606
607                 case OPT_D32:
608 #if SIZEOF_VOID_P == 8
609                         puts("Running a 32-bit JVM is not supported on this platform.");
610                         exit(1);
611 #endif
612                         break;
613
614                 case OPT_D64:
615 #if SIZEOF_VOID_P == 4
616                         puts("Running a 64-bit JVM is not supported on this platform.");
617                         exit(1);
618 #endif
619                         break;
620
621                 case OPT_CLASSPATH:
622                         /* forget old classpath and set the argument as new classpath */
623                         MFREE(classpath, char, strlen(classpath));
624
625                         classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
626                         strcpy(classpath, opt_arg);
627                         break;
628
629                 case OPT_D:
630                         for (j = 0; j < strlen(opt_arg); j++) {
631                                 if (opt_arg[j] == '=') {
632                                         opt_arg[j] = '\0';
633                                         properties_add(opt_arg, opt_arg + j + 1);
634                                         goto didit;
635                                 }
636                         }
637
638                         /* if no '=' is given, just create an empty property */
639
640                         properties_add(opt_arg, "");
641                                         
642                 didit:
643                         break;
644
645                 case OPT_BOOTCLASSPATH:
646                         /* Forget default bootclasspath and set the argument as
647                            new boot classpath. */
648                         MFREE(bootclasspath, char, strlen(bootclasspath));
649
650                         bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
651                         strcpy(bootclasspath, opt_arg);
652                         break;
653
654                 case OPT_BOOTCLASSPATH_A:
655                         /* append to end of bootclasspath */
656                         cplen = strlen(bootclasspath);
657
658                         bootclasspath = MREALLOC(bootclasspath,
659                                                                          char,
660                                                                          cplen,
661                                                                          cplen + strlen(":") +
662                                                                          strlen(opt_arg) + strlen("0"));
663
664                         strcat(bootclasspath, ":");
665                         strcat(bootclasspath, opt_arg);
666                         break;
667
668                 case OPT_BOOTCLASSPATH_P:
669                         /* prepend in front of bootclasspath */
670                         cp = bootclasspath;
671                         cplen = strlen(cp);
672
673                         bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
674                                                                  cplen + strlen("0"));
675
676                         strcpy(bootclasspath, opt_arg);
677                         strcat(bootclasspath, ":");
678                         strcat(bootclasspath, cp);
679
680                         MFREE(cp, char, cplen);
681                         break;
682
683 #if defined(ENABLE_JVMTI)
684                 case OPT_DEBUG:
685                         jdwp=true;
686                         break;
687                 case OPT_NOAGENT:
688                         /* I don't know yet what Xnoagent should do. This is only for 
689                            compatiblity with eclipse - motse */
690                         break;
691                 case OPT_XRUNJDWP:
692                         transport = opt_arg;
693                         j=0;
694                         while (transport[j]!='=') j++;
695                         j++;
696                         while (j<strlen(transport)) {
697                                 if (strncmp("suspend=",&transport[j],8)==0) {
698                                         if ((j+8)>=strlen(transport) || 
699                                                 (transport[j+8]!= 'y' && transport[j+8]!= 'n')) {
700                                                 printf("bad Xrunjdwp option: -Xrunjdwp%s\n",transport);
701                                                 usage();
702                                                 break;
703                                         }
704                                         else {
705                                                 suspend = transport[j+8] == 'y';
706                                                 break;
707                                         }
708                                 }
709                                 while (transport[j]!=',') j++;
710                                 j++;
711                         }
712                         
713                         break;
714                 case OPT_AGENTPATH:
715                 case OPT_AGENTLIB:
716                         jvmti=true;
717                         agentarg = opt_arg;
718                         break;
719 #endif
720                         
721                 case OPT_MX:
722                 case OPT_MS:
723                 case OPT_SS:
724                         {
725                                 char c;
726                                 c = opt_arg[strlen(opt_arg) - 1];
727
728                                 if ((c == 'k') || (c == 'K')) {
729                                         j = atoi(opt_arg) * 1024;
730
731                                 } else if ((c == 'm') || (c == 'M')) {
732                                         j = atoi(opt_arg) * 1024 * 1024;
733
734                                 } else
735                                         j = atoi(opt_arg);
736
737                                 if (opt == OPT_MX)
738                                         heapmaxsize = j;
739                                 else if (opt == OPT_MS)
740                                         heapstartsize = j;
741                                 else
742                                         opt_stacksize = j;
743                         }
744                         break;
745
746                 case OPT_VERBOSE1:
747                         opt_verbose = true;
748                         break;
749
750                 case OPT_VERBOSE:
751                         if (strcmp("class", opt_arg) == 0)
752                                 opt_verboseclass = true;
753
754                         else if (strcmp("gc", opt_arg) == 0)
755                                 opt_verbosegc = true;
756
757                         else if (strcmp("jni", opt_arg) == 0)
758                                 opt_verbosejni = true;
759
760                         else if (strcmp("call", opt_arg) == 0)
761                                 opt_verbosecall = true;
762
763                         else if (strcmp("jit", opt_arg) == 0) {
764                                 opt_verbose = true;
765                                 loadverbose = true;
766                                 linkverbose = true;
767                                 initverbose = true;
768                                 compileverbose = true;
769                         }
770                         else if (strcmp("exception", opt_arg) == 0)
771                                 opt_verboseexception = true;
772                         break;
773
774 #ifdef TYPECHECK_VERBOSE
775                 case OPT_VERBOSETC:
776                         typecheckverbose = true;
777                         break;
778 #endif
779                                 
780                 case OPT_VERSION:
781                         version();
782                         exit(0);
783                         break;
784
785                 case OPT_FULLVERSION:
786                         fullversion();
787                         break;
788
789                 case OPT_SHOWVERSION:
790                         version();
791                         break;
792
793                 case OPT_NOIEEE:
794                         opt_noieee = true;
795                         break;
796
797 #if defined(ENABLE_VERIFIER)
798                 case OPT_NOVERIFY:
799                         opt_verify = false;
800                         break;
801 #endif
802
803                 case OPT_SOFTNULL:
804                         checknull = true;
805                         break;
806
807                 case OPT_TIME:
808                         getcompilingtime = true;
809                         getloadingtime = true;
810                         break;
811                                         
812 #if defined(ENABLE_STATISTICS)
813                 case OPT_STAT:
814                         opt_stat = true;
815                         break;
816 #endif
817                                         
818                 case OPT_LOG:
819                         log_init(opt_arg);
820                         break;
821                         
822                 case OPT_CHECK:
823                         for (j = 0; j < strlen(opt_arg); j++) {
824                                 switch (opt_arg[j]) {
825                                 case 'b':
826                                         checkbounds = false;
827                                         break;
828                                 case 's':
829                                         checksync = false;
830                                         break;
831                                 default:
832                                         usage();
833                                 }
834                         }
835                         break;
836                         
837                 case OPT_LOAD:
838                         opt_run = false;
839                         makeinitializations = false;
840                         break;
841
842                 case OPT_EAGER:
843                         opt_eager = true;
844                         break;
845
846                 case OPT_METHOD:
847                         opt_run = false;
848                         opt_method = opt_arg;
849                         makeinitializations = false;
850                         break;
851                         
852                 case OPT_SIGNATURE:
853                         opt_signature = opt_arg;
854                         break;
855                         
856                 case OPT_ALL:
857                         compileall = true;
858                         opt_run = false;
859                         makeinitializations = false;
860                         break;
861                         
862                 case OPT_SHOW:       /* Display options */
863                         for (j = 0; j < strlen(opt_arg); j++) {         
864                                 switch (opt_arg[j]) {
865                                 case 'a':
866                                         opt_showdisassemble = true;
867                                         compileverbose = true;
868                                         break;
869                                 case 'c':
870                                         showconstantpool = true;
871                                         break;
872                                 case 'd':
873                                         opt_showddatasegment = true;
874                                         break;
875                                 case 'e':
876                                         opt_showexceptionstubs = true;
877                                         break;
878                                 case 'i':
879                                         opt_showintermediate = true;
880                                         compileverbose = true;
881                                         break;
882                                 case 'm':
883                                         showmethods = true;
884                                         break;
885                                 case 'n':
886                                         opt_shownativestub = true;
887                                         break;
888                                 case 'u':
889                                         showutf = true;
890                                         break;
891                                 default:
892                                         usage();
893                                 }
894                         }
895                         break;
896                         
897 #if defined(ENABLE_LOOP)
898                 case OPT_OLOOP:
899                         opt_loops = true;
900                         break;
901 #endif
902
903 #if defined(ENABLE_INLINING)
904                 case OPT_INLINING:
905                         for (j = 0; j < strlen(opt_arg); j++) {         
906                                 switch (opt_arg[j]) {
907                                 case 'n':
908                                         /* define in options.h; Used in main.c, jit.c
909                                            & inline.c inlining is currently
910                                            deactivated */
911                                         break;
912                                 case 'v':
913                                         inlinevirtuals = true;
914                                         break;
915                                 case 'e':
916                                         inlineexceptions = true;
917                                         break;
918                                 case 'p':
919                                         inlineparamopt = true;
920                                         break;
921                                 case 'o':
922                                         inlineoutsiders = true;
923                                         break;
924                                 default:
925                                         usage();
926                                 }
927                         }
928                         break;
929 #endif /* defined(ENABLE_INLINING) */
930
931 #if defined(ENABLE_IFCONV)
932                 case OPT_IFCONV:
933                         opt_ifconv = true;
934                         break;
935 #endif
936
937 #if defined(ENABLE_LSRA)
938                 case OPT_LSRA:
939                         opt_lsra = true;
940                         break;
941 #endif
942
943                 case OPT_HELP:
944                         usage();
945                         break;
946
947                 case OPT_X:
948                         Xusage();
949                         break;
950
951                 case OPT_PROF_OPTION:
952                         /* use <= to get the last \0 too */
953
954                         for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
955                                 if (opt_arg[j] == ',')
956                                         opt_arg[j] = '\0';
957
958                                 if (opt_arg[j] == '\0') {
959                                         if (strcmp("bb", opt_arg + k) == 0)
960                                                 opt_prof_bb = true;
961
962                                         else {
963                                                 printf("Unknown option: -Xprof:%s\n", opt_arg + k);
964                                                 usage();
965                                         }
966
967                                         /* set k to next char */
968
969                                         k = j + 1;
970                                 }
971                         }
972                         /* fall through */
973
974                 case OPT_PROF:
975                         opt_prof = true;
976                         break;
977
978                 case OPT_JIT:
979 #if defined(ENABLE_JIT)
980                         opt_jit = true;
981 #else
982                         printf("-Xjit option not enabled.\n");
983                         exit(1);
984 #endif
985                         break;
986
987                 case OPT_INTRP:
988 #if defined(ENABLE_INTRP)
989                         opt_intrp = true;
990 #else
991                         printf("-Xint option not enabled.\n");
992                         exit(1);
993 #endif
994                         break;
995
996 #if defined(ENABLE_INTRP)
997                 case OPT_STATIC_SUPERS:
998                         opt_static_supers = atoi(opt_arg);
999                         break;
1000
1001                 case OPT_NO_DYNAMIC:
1002                         opt_no_dynamic = true;
1003                         break;
1004
1005                 case OPT_NO_REPLICATION:
1006                         opt_no_replication = true;
1007                         break;
1008
1009                 case OPT_NO_QUICKSUPER:
1010                         opt_no_quicksuper = true;
1011                         break;
1012
1013                 case OPT_TRACE:
1014                         vm_debug = true;
1015                         break;
1016 #endif
1017
1018                 default:
1019                         printf("Unknown option: %s\n",
1020                                    vm_args->options[opt_index].optionString);
1021                         usage();
1022                 }
1023         }
1024
1025
1026         /* get the main class *****************************************************/
1027
1028         if (opt_index < vm_args->nOptions) {
1029                 mainstring = vm_args->options[opt_index++].optionString;
1030
1031                 /* Put the jar file into the classpath (if any). */
1032
1033                 if (opt_jar == true) {
1034                         /* free old classpath */
1035
1036                         MFREE(classpath, char, strlen(classpath));
1037
1038                         /* put jarfile into classpath */
1039
1040                         classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1041
1042                         strcpy(classpath, mainstring);
1043                 
1044                 } else {
1045                         /* replace .'s with /'s in classname */
1046
1047                         for (i = strlen(mainstring) - 1; i >= 0; i--)
1048                                 if (mainstring[i] == '.')
1049                                         mainstring[i] = '/';
1050                 }
1051         }
1052
1053 #if defined(ENABLE_JVMTI)
1054         /* The fork has to occure before threads a created because threads  are 
1055            not forked correctly (see man pthread_atfork). Varibale dbgprocess 
1056            stores information whether this is the debugger or debuggee process. */
1057         if (jvmti || jdwp) {
1058                 set_jvmti_phase(JVMTI_PHASE_ONLOAD);
1059                 dbgprocess = cacaodbgfork();
1060         }
1061
1062         if (dbgprocess && jvmti) { /* is this the parent/debugger process ? */
1063                 agentload(agentarg);
1064                 set_jvmti_phase(JVMTI_PHASE_PRIMORDIAL);
1065         }
1066 #endif
1067
1068
1069         /* initialize this JVM ****************************************************/
1070
1071         vm_initializing = true;
1072
1073         /* initialize the garbage collector */
1074
1075         gc_init(heapmaxsize, heapstartsize);
1076
1077 #if defined(ENABLE_INTRP)
1078         /* Allocate main thread stack on the Java heap. */
1079
1080         if (opt_intrp) {
1081                 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1082                 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1083         }
1084 #endif
1085
1086 #if defined(USE_THREADS)
1087 #if defined(NATIVE_THREADS)
1088         threads_preinit();
1089 #endif
1090         initLocks();
1091 #endif
1092
1093         /* initialize the string hashtable stuff: lock (must be done
1094            _after_ threads_preinit) */
1095
1096         if (!string_init())
1097                 throw_main_exception_exit();
1098
1099         /* initialize the utf8 hashtable stuff: lock, often used utf8
1100            strings (must be done _after_ threads_preinit) */
1101
1102         if (!utf8_init())
1103                 throw_main_exception_exit();
1104
1105         /* initialize the classcache hashtable stuff: lock, hashtable
1106            (must be done _after_ threads_preinit) */
1107
1108         if (!classcache_init())
1109                 throw_main_exception_exit();
1110
1111         /* initialize the loader with bootclasspath (must be done _after_
1112            thread_preinit) */
1113
1114         if (!suck_init())
1115                 throw_main_exception_exit();
1116
1117         suck_add_from_property("java.endorsed.dirs");
1118         suck_add(bootclasspath);
1119
1120         /* initialize the memory subsystem (must be done _after_
1121            threads_preinit) */
1122
1123         if (!memory_init())
1124                 throw_main_exception_exit();
1125
1126         /* initialize the finalizer stuff (must be done _after_
1127            threads_preinit) */
1128
1129         if (!finalizer_init())
1130                 throw_main_exception_exit();
1131
1132         /* install architecture dependent signal handler used for exceptions */
1133
1134         signal_init();
1135
1136         /* initialize the codegen subsystems */
1137
1138         codegen_init();
1139
1140         /* initializes jit compiler */
1141
1142         jit_init();
1143
1144         /* machine dependent initialization */
1145
1146 #if defined(ENABLE_JIT)
1147 # if defined(ENABLE_INTRP)
1148         if (opt_intrp)
1149                 intrp_md_init();
1150         else
1151 # endif
1152                 md_init();
1153 #else
1154         intrp_md_init();
1155 #endif
1156
1157         /* initialize the loader subsystems (must be done _after_
1158        classcache_init) */
1159
1160         if (!loader_init((u1 *) stackbottom))
1161                 throw_main_exception_exit();
1162
1163         if (!linker_init())
1164                 throw_main_exception_exit();
1165
1166         if (!native_init())
1167                 throw_main_exception_exit();
1168
1169         if (!exceptions_init())
1170                 throw_main_exception_exit();
1171
1172         if (!builtin_init())
1173                 throw_main_exception_exit();
1174
1175 #if defined(USE_THREADS)
1176         if (!threads_init((u1 *) stackbottom))
1177                 throw_main_exception_exit();
1178 #endif
1179
1180         /* That's important, otherwise we get into trouble, if the Runtime
1181            static initializer is called before (circular dependency. This
1182            is with classpath 0.09. Another important thing is, that this
1183            has to happen after initThreads!!! */
1184
1185         if (!initialize_class(class_java_lang_System))
1186                 throw_main_exception_exit();
1187
1188         /* JNI init creates a Java object (this means running Java code) */
1189
1190         if (!jni_init())
1191                 throw_main_exception_exit();
1192
1193 #if defined(ENABLE_PROFILING)
1194         /* initialize profiling */
1195
1196         if (!profile_init())
1197                 throw_main_exception_exit();
1198 #endif
1199
1200 #if defined(USE_THREADS)
1201         /* finally, start the finalizer thread */
1202
1203         if (!finalizer_start_thread())
1204                 throw_main_exception_exit();
1205
1206         /* start the profile sampling thread */
1207
1208 /*      if (!profile_start_thread()) */
1209 /*              throw_main_exception_exit(); */
1210 #endif
1211
1212         /* increment the number of VMs */
1213
1214         vms++;
1215
1216         /* initialization is done */
1217
1218         vm_initializing = false;
1219
1220         /* everything's ok */
1221
1222         return true;
1223 }
1224
1225
1226 /* vm_destroy ******************************************************************
1227
1228    Unloads a Java VM and reclaims its resources.
1229
1230 *******************************************************************************/
1231
1232 s4 vm_destroy(JavaVM *vm)
1233 {
1234 #if defined(USE_THREADS)
1235 #if defined(NATIVE_THREADS)
1236         joinAllThreads();
1237 #else
1238         killThread(currentThread);
1239 #endif
1240 #endif
1241
1242         /* everything's ok */
1243
1244         return 0;
1245 }
1246
1247
1248 /* vm_exit *********************************************************************
1249
1250    Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1251
1252 *******************************************************************************/
1253
1254 void vm_exit(s4 status)
1255 {
1256         methodinfo *m;
1257
1258         /* signal that we are exiting */
1259
1260         vm_exiting = true;
1261
1262         assert(class_java_lang_System);
1263         assert(class_java_lang_System->state & CLASS_LOADED);
1264
1265 #if defined(ENABLE_JVMTI)
1266         if (dbgprocess) {
1267                 set_jvmti_phase(JVMTI_PHASE_DEAD);
1268                 if (jvmti) agentunload();
1269         }
1270 #endif
1271
1272         if (!link_class(class_java_lang_System))
1273                 throw_main_exception_exit();
1274
1275         /* call java.lang.System.exit(I)V */
1276
1277         m = class_resolveclassmethod(class_java_lang_System,
1278                                                                  utf_new_char("exit"),
1279                                                                  utf_int__void,
1280                                                                  class_java_lang_Object,
1281                                                                  true);
1282         
1283         if (m == NULL)
1284                 throw_main_exception_exit();
1285
1286         /* call the exit function with passed exit status */
1287
1288         (void) vm_call_method(m, NULL, status);
1289
1290         /* If we had an exception, just ignore the exception and exit with
1291            the proper code. */
1292
1293         vm_shutdown(status);
1294 }
1295
1296
1297 /* vm_shutdown *****************************************************************
1298
1299    Terminates the system immediately without freeing memory explicitly
1300    (to be used only for abnormal termination).
1301         
1302 *******************************************************************************/
1303
1304 void vm_shutdown(s4 status)
1305 {
1306 #if defined(ENABLE_JVMTI)
1307         if (dbgprocess) {
1308                 set_jvmti_phase(JVMTI_PHASE_DEAD);
1309                 if (jvmti) agentunload();
1310                 ipcrm();
1311         }
1312 #endif
1313         if (opt_verbose || getcompilingtime || opt_stat) {
1314                 log_text("CACAO terminated by shutdown");
1315                 dolog("Exit status: %d\n", (s4) status);
1316         }
1317
1318         exit(status);
1319 }
1320
1321
1322 /* vm_exit_handler *************************************************************
1323
1324    The exit_handler function is called upon program termination.
1325
1326    ATTENTION: Don't free system resources here! Some threads may still
1327    be running as this is called from VMRuntime.exit(). The OS does the
1328    cleanup for us.
1329
1330 *******************************************************************************/
1331
1332 void vm_exit_handler(void)
1333 {
1334 #if defined(ENABLE_JVMTI)
1335         if (jvmti && jdwp) set_jvmti_phase(JVMTI_PHASE_DEAD);
1336         if (jvmti) agentunload();
1337         ipcrm();
1338 #endif
1339
1340 #if !defined(NDEBUG)
1341         if (showmethods)
1342                 class_showmethods(mainclass);
1343
1344         if (showconstantpool)
1345                 class_showconstantpool(mainclass);
1346
1347         if (showutf)
1348                 utf_show();
1349
1350 # if defined(ENABLE_PROFILING)
1351         if (opt_prof)
1352                 profile_printstats();
1353 # endif
1354 #endif
1355
1356 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
1357         clear_thread_flags();           /* restores standard file descriptor
1358                                        flags */
1359 #endif
1360
1361 #if defined(ENABLE_RT_TIMING)
1362         rt_timing_print_time_stats(stderr);
1363 #endif
1364
1365 #if defined(ENABLE_CYCLES_STATS)
1366         builtin_print_cycles_stats(stderr);
1367         stacktrace_print_cycles_stats(stderr);
1368 #endif
1369
1370         if (opt_verbose || getcompilingtime || opt_stat) {
1371                 log_text("CACAO terminated");
1372
1373 #if defined(ENABLE_STATISTICS)
1374                 if (opt_stat) {
1375                         print_stats();
1376 #ifdef TYPECHECK_STATISTICS
1377                         typecheck_print_statistics(get_logfile());
1378 #endif
1379                 }
1380
1381                 mem_usagelog(1);
1382
1383                 if (getcompilingtime)
1384                         print_times();
1385 #endif
1386         }
1387         /* vm_print_profile(stderr);*/
1388 }
1389
1390
1391 /* vm_vmargs_from_valist *******************************************************
1392
1393    XXX
1394
1395 *******************************************************************************/
1396
1397 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
1398                                                                   vm_arg *vmargs, va_list ap)
1399 {
1400         typedesc *paramtypes;
1401         s4        i;
1402
1403         paramtypes = m->parseddesc->paramtypes;
1404
1405         /* if method is non-static fill first block and skip `this' pointer */
1406
1407         i = 0;
1408
1409         if (o != NULL) {
1410                 /* the `this' pointer */
1411                 vmargs[0].type = TYPE_ADR;
1412                 vmargs[0].data = (u8) (ptrint) o;
1413
1414                 paramtypes++;
1415                 i++;
1416         } 
1417
1418         for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
1419                 switch (paramtypes->decltype) {
1420                 /* primitive types */
1421                 case PRIMITIVETYPE_BOOLEAN: 
1422                 case PRIMITIVETYPE_BYTE:
1423                 case PRIMITIVETYPE_CHAR:
1424                 case PRIMITIVETYPE_SHORT: 
1425                 case PRIMITIVETYPE_INT:
1426                         vmargs[i].type = TYPE_INT;
1427                         vmargs[i].data = (s8) va_arg(ap, s4);
1428                         break;
1429
1430                 case PRIMITIVETYPE_LONG:
1431                         vmargs[i].type = TYPE_LNG;
1432                         vmargs[i].data = (s8) va_arg(ap, s8);
1433                         break;
1434
1435                 case PRIMITIVETYPE_FLOAT:
1436                         vmargs[i].type = TYPE_FLT;
1437 #if defined(__ALPHA__)
1438                         /* this keeps the assembler function much simpler */
1439
1440                         *((jdouble *) (&vmargs[i].data)) = (jdouble) va_arg(ap, jdouble);
1441 #else
1442                         *((jfloat *) (&vmargs[i].data)) = (jfloat) va_arg(ap, jdouble);
1443 #endif
1444                         break;
1445
1446                 case PRIMITIVETYPE_DOUBLE:
1447                         vmargs[i].type = TYPE_DBL;
1448                         *((jdouble *) (&vmargs[i].data)) = (jdouble) va_arg(ap, jdouble);
1449                         break;
1450
1451                 case TYPE_ADR: 
1452                         vmargs[i].type = TYPE_ADR;
1453                         vmargs[i].data = (u8) (ptrint) va_arg(ap, void*);
1454                         break;
1455                 }
1456         }
1457 }
1458
1459
1460 /* vm_vmargs_from_jvalue *******************************************************
1461
1462    XXX
1463
1464 *******************************************************************************/
1465
1466 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
1467                                                                   vm_arg *vmargs, jvalue *args)
1468 {
1469         typedesc *paramtypes;
1470         s4        i;
1471         s4        j;
1472
1473         paramtypes = m->parseddesc->paramtypes;
1474
1475         /* if method is non-static fill first block and skip `this' pointer */
1476
1477         i = 0;
1478
1479         if (o != NULL) {
1480                 /* the `this' pointer */
1481                 vmargs[0].type = TYPE_ADR;
1482                 vmargs[0].data = (u8) (ptrint) o;
1483
1484                 paramtypes++;
1485                 i++;
1486         } 
1487
1488         for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
1489                 switch (paramtypes->decltype) {
1490                 /* primitive types */
1491                 case PRIMITIVETYPE_BOOLEAN: 
1492                 case PRIMITIVETYPE_BYTE:
1493                 case PRIMITIVETYPE_CHAR:
1494                 case PRIMITIVETYPE_SHORT: 
1495                 case PRIMITIVETYPE_INT:
1496                         vmargs[i].type = TYPE_INT;
1497                         vmargs[i].data = (s8) args[j].i;
1498                         break;
1499
1500                 case PRIMITIVETYPE_LONG:
1501                         vmargs[i].type = TYPE_LNG;
1502                         vmargs[i].data = (s8) args[j].j;
1503                         break;
1504
1505                 case PRIMITIVETYPE_FLOAT:
1506                         vmargs[i].type = TYPE_FLT;
1507 #if defined(__ALPHA__)
1508                         /* this keeps the assembler function much simpler */
1509
1510                         *((jdouble *) (&vmargs[i].data)) = (jdouble) args[j].f;
1511 #else
1512                         *((jfloat *) (&vmargs[i].data)) = args[j].f;
1513 #endif
1514                         break;
1515
1516                 case PRIMITIVETYPE_DOUBLE:
1517                         vmargs[i].type = TYPE_DBL;
1518                         *((jdouble *) (&vmargs[i].data)) = args[j].d;
1519                         break;
1520
1521                 case TYPE_ADR: 
1522                         vmargs[i].type = TYPE_ADR;
1523                         vmargs[i].data = (u8) (ptrint) args[j].l;
1524                         break;
1525                 }
1526         }
1527 }
1528
1529
1530 /* vm_call_method **************************************************************
1531
1532    Calls a Java method with a variable number of arguments and returns
1533    an address.
1534
1535 *******************************************************************************/
1536
1537 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
1538 {
1539         va_list            ap;
1540         java_objectheader *ro;
1541
1542         va_start(ap, o);
1543         ro = vm_call_method_valist(m, o, ap);
1544         va_end(ap);
1545
1546         return ro;
1547 }
1548
1549
1550 /* vm_call_method_valist *******************************************************
1551
1552    Calls a Java method with a variable number of arguments, passed via
1553    a va_list, and returns an address.
1554
1555 *******************************************************************************/
1556
1557 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
1558                                                                                  va_list ap)
1559 {
1560         s4                 vmargscount;
1561         vm_arg            *vmargs;
1562         java_objectheader *ro;
1563         s4                 dumpsize;
1564
1565         /* mark start of dump memory area */
1566
1567         dumpsize = dump_size();
1568
1569         /* get number of Java method arguments */
1570
1571         vmargscount = m->parseddesc->paramcount;
1572
1573         /* allocate vm_arg array */
1574
1575         vmargs = DMNEW(vm_arg, vmargscount);
1576
1577         /* fill the vm_arg array from a va_list */
1578
1579         vm_vmargs_from_valist(m, o, vmargs, ap);
1580
1581         /* call the Java method */
1582
1583         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1584
1585         /* release dump area */
1586
1587         dump_release(dumpsize);
1588
1589         return ro;
1590 }
1591
1592
1593 /* vm_call_method_jvalue *******************************************************
1594
1595    Calls a Java method with a variable number of arguments, passed via
1596    a jvalue array, and returns an address.
1597
1598 *******************************************************************************/
1599
1600 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
1601                                                                                  jvalue *args)
1602 {
1603         s4                 vmargscount;
1604         vm_arg            *vmargs;
1605         java_objectheader *ro;
1606         s4                 dumpsize;
1607
1608         /* mark start of dump memory area */
1609
1610         dumpsize = dump_size();
1611
1612         /* get number of Java method arguments */
1613
1614         vmargscount = m->parseddesc->paramcount;
1615
1616         /* allocate vm_arg array */
1617
1618         vmargs = DMNEW(vm_arg, vmargscount);
1619
1620         /* fill the vm_arg array from a va_list */
1621
1622         vm_vmargs_from_jvalue(m, o, vmargs, args);
1623
1624         /* call the Java method */
1625
1626         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1627
1628         /* release dump area */
1629
1630         dump_release(dumpsize);
1631
1632         return ro;
1633 }
1634
1635
1636 /* vm_call_method_vmarg ********************************************************
1637
1638    Calls a Java method with a variable number of arguments, passed via
1639    a vm_arg array, and returns an address.
1640
1641 *******************************************************************************/
1642
1643 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
1644                                                                                 vm_arg *vmargs)
1645 {
1646         java_objectheader *o;
1647
1648 #if defined(ENABLE_JIT)
1649 # if defined(ENABLE_INTRP)
1650         if (opt_intrp)
1651                 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1652         else
1653 # endif
1654                 o = asm_vm_call_method(m, vmargscount, vmargs);
1655 #else
1656         o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1657 #endif
1658
1659         return o;
1660 }
1661
1662
1663 /* vm_call_method_int **********************************************************
1664
1665    Calls a Java method with a variable number of arguments and returns
1666    an integer (s4).
1667
1668 *******************************************************************************/
1669
1670 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
1671 {
1672         va_list ap;
1673         s4      i;
1674
1675         va_start(ap, o);
1676         i = vm_call_method_int_valist(m, o, ap);
1677         va_end(ap);
1678
1679         return i;
1680 }
1681
1682
1683 /* vm_call_method_int_valist ***************************************************
1684
1685    Calls a Java method with a variable number of arguments, passed via
1686    a va_list, and returns an integer (s4).
1687
1688 *******************************************************************************/
1689
1690 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
1691 {
1692         s4      vmargscount;
1693         vm_arg *vmargs;
1694         s4      i;
1695         s4      dumpsize;
1696
1697         /* mark start of dump memory area */
1698
1699         dumpsize = dump_size();
1700
1701         /* get number of Java method arguments */
1702
1703         vmargscount = m->parseddesc->paramcount;
1704
1705         /* allocate vm_arg array */
1706
1707         vmargs = DMNEW(vm_arg, vmargscount);
1708
1709         /* fill the vm_arg array from a va_list */
1710
1711         vm_vmargs_from_valist(m, o, vmargs, ap);
1712
1713         /* call the Java method */
1714
1715         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1716
1717         /* release dump area */
1718
1719         dump_release(dumpsize);
1720
1721         return i;
1722 }
1723
1724
1725 /* vm_call_method_int_jvalue ***************************************************
1726
1727    Calls a Java method with a variable number of arguments, passed via
1728    a jvalue array, and returns an integer (s4).
1729
1730 *******************************************************************************/
1731
1732 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1733 {
1734         s4      vmargscount;
1735         vm_arg *vmargs;
1736         s4      i;
1737         s4      dumpsize;
1738
1739         /* mark start of dump memory area */
1740
1741         dumpsize = dump_size();
1742
1743         /* get number of Java method arguments */
1744
1745         vmargscount = m->parseddesc->paramcount;
1746
1747         /* allocate vm_arg array */
1748
1749         vmargs = DMNEW(vm_arg, vmargscount);
1750
1751         /* fill the vm_arg array from a va_list */
1752
1753         vm_vmargs_from_jvalue(m, o, vmargs, args);
1754
1755         /* call the Java method */
1756
1757         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1758
1759         /* release dump area */
1760
1761         dump_release(dumpsize);
1762
1763         return i;
1764 }
1765
1766
1767 /* vm_call_method_int_vmarg ****************************************************
1768
1769    Calls a Java method with a variable number of arguments, passed via
1770    a vm_arg array, and returns an integer (s4).
1771
1772 *******************************************************************************/
1773
1774 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1775 {
1776         s4 i;
1777
1778 #if defined(ENABLE_JIT)
1779 # if defined(ENABLE_INTRP)
1780         if (opt_intrp)
1781                 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1782         else
1783 # endif
1784                 i = asm_vm_call_method_int(m, vmargscount, vmargs);
1785 #else
1786         i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1787 #endif
1788
1789         return i;
1790 }
1791
1792
1793 /* vm_call_method_long *********************************************************
1794
1795    Calls a Java method with a variable number of arguments and returns
1796    a long (s8).
1797
1798 *******************************************************************************/
1799
1800 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
1801 {
1802         va_list ap;
1803         s8      l;
1804
1805         va_start(ap, o);
1806         l = vm_call_method_long_valist(m, o, ap);
1807         va_end(ap);
1808
1809         return l;
1810 }
1811
1812
1813 /* vm_call_method_long_valist **************************************************
1814
1815    Calls a Java method with a variable number of arguments, passed via
1816    a va_list, and returns a long (s8).
1817
1818 *******************************************************************************/
1819
1820 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
1821 {
1822         s4      vmargscount;
1823         vm_arg *vmargs;
1824         s8      l;
1825         s4      dumpsize;
1826
1827         /* mark start of dump memory area */
1828
1829         dumpsize = dump_size();
1830
1831         /* get number of Java method arguments */
1832
1833         vmargscount = m->parseddesc->paramcount;
1834
1835         /* allocate vm_arg array */
1836
1837         vmargs = DMNEW(vm_arg, vmargscount);
1838
1839         /* fill the vm_arg array from a va_list */
1840
1841         vm_vmargs_from_valist(m, o, vmargs, ap);
1842
1843         /* call the Java method */
1844
1845         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1846
1847         /* release dump area */
1848
1849         dump_release(dumpsize);
1850
1851         return l;
1852 }
1853
1854
1855 /* vm_call_method_long_jvalue **************************************************
1856
1857    Calls a Java method with a variable number of arguments, passed via
1858    a jvalue array, and returns a long (s8).
1859
1860 *******************************************************************************/
1861
1862 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1863 {
1864         s4      vmargscount;
1865         vm_arg *vmargs;
1866         s8      l;
1867         s4      dumpsize;
1868
1869         /* mark start of dump memory area */
1870
1871         dumpsize = dump_size();
1872
1873         /* get number of Java method arguments */
1874
1875         vmargscount = m->parseddesc->paramcount;
1876
1877         /* allocate vm_arg array */
1878
1879         vmargs = DMNEW(vm_arg, vmargscount);
1880
1881         /* fill the vm_arg array from a va_list */
1882
1883         vm_vmargs_from_jvalue(m, o, vmargs, args);
1884
1885         /* call the Java method */
1886
1887         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1888
1889         /* release dump area */
1890
1891         dump_release(dumpsize);
1892
1893         return l;
1894 }
1895
1896
1897 /* vm_call_method_long_vmarg ***************************************************
1898
1899    Calls a Java method with a variable number of arguments, passed via
1900    a vm_arg array, and returns a long (s8).
1901
1902 *******************************************************************************/
1903
1904 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1905 {
1906         s8 l;
1907
1908 #if defined(ENABLE_JIT)
1909 # if defined(ENABLE_INTRP)
1910         if (opt_intrp)
1911                 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1912         else
1913 # endif
1914                 l = asm_vm_call_method_long(m, vmargscount, vmargs);
1915 #else
1916         l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1917 #endif
1918
1919         return l;
1920 }
1921
1922
1923 /* vm_call_method_float ********************************************************
1924
1925    Calls a Java method with a variable number of arguments and returns
1926    an float.
1927
1928 *******************************************************************************/
1929
1930 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
1931 {
1932         va_list ap;
1933         float   f;
1934
1935         va_start(ap, o);
1936         f = vm_call_method_float_valist(m, o, ap);
1937         va_end(ap);
1938
1939         return f;
1940 }
1941
1942
1943 /* vm_call_method_float_valist *************************************************
1944
1945    Calls a Java method with a variable number of arguments, passed via
1946    a va_list, and returns a float.
1947
1948 *******************************************************************************/
1949
1950 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
1951                                                                   va_list ap)
1952 {
1953         s4      vmargscount;
1954         vm_arg *vmargs;
1955         float   f;
1956         s4      dumpsize;
1957
1958         /* mark start of dump memory area */
1959
1960         dumpsize = dump_size();
1961
1962         /* get number of Java method arguments */
1963
1964         vmargscount = m->parseddesc->paramcount;
1965
1966         /* allocate vm_arg array */
1967
1968         vmargs = DMNEW(vm_arg, vmargscount);
1969
1970         /* fill the vm_arg array from a va_list */
1971
1972         vm_vmargs_from_valist(m, o, vmargs, ap);
1973
1974         /* call the Java method */
1975
1976         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
1977
1978         /* release dump area */
1979
1980         dump_release(dumpsize);
1981
1982         return f;
1983 }
1984
1985
1986 /* vm_call_method_float_jvalue *************************************************
1987
1988    Calls a Java method with a variable number of arguments, passed via
1989    a jvalue array, and returns a float.
1990
1991 *******************************************************************************/
1992
1993 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
1994                                                                   jvalue *args)
1995 {
1996         s4      vmargscount;
1997         vm_arg *vmargs;
1998         float   f;
1999         s4      dumpsize;
2000
2001         /* mark start of dump memory area */
2002
2003         dumpsize = dump_size();
2004
2005         /* get number of Java method arguments */
2006
2007         vmargscount = m->parseddesc->paramcount;
2008
2009         /* allocate vm_arg array */
2010
2011         vmargs = DMNEW(vm_arg, vmargscount);
2012
2013         /* fill the vm_arg array from a va_list */
2014
2015         vm_vmargs_from_jvalue(m, o, vmargs, args);
2016
2017         /* call the Java method */
2018
2019         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2020
2021         /* release dump area */
2022
2023         dump_release(dumpsize);
2024
2025         return f;
2026 }
2027
2028
2029 /* vm_call_method_float_vmarg **************************************************
2030
2031    Calls a Java method with a variable number of arguments and returns
2032    an float.
2033
2034 *******************************************************************************/
2035
2036 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2037 {
2038         float f;
2039
2040 #if defined(ENABLE_JIT)
2041 # if defined(ENABLE_INTRP)
2042         if (opt_intrp)
2043                 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2044         else
2045 # endif
2046                 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2047 #else
2048         f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2049 #endif
2050
2051         return f;
2052 }
2053
2054
2055 /* vm_call_method_double *******************************************************
2056
2057    Calls a Java method with a variable number of arguments and returns
2058    a double.
2059
2060 *******************************************************************************/
2061
2062 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2063 {
2064         va_list ap;
2065         double  d;
2066
2067         va_start(ap, o);
2068         d = vm_call_method_double_valist(m, o, ap);
2069         va_end(ap);
2070
2071         return d;
2072 }
2073
2074
2075 /* vm_call_method_double_valist ************************************************
2076
2077    Calls a Java method with a variable number of arguments, passed via
2078    a va_list, and returns a double.
2079
2080 *******************************************************************************/
2081
2082 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2083                                                                         va_list ap)
2084 {
2085         s4      vmargscount;
2086         vm_arg *vmargs;
2087         double  d;
2088         s4      dumpsize;
2089
2090         /* mark start of dump memory area */
2091
2092         dumpsize = dump_size();
2093
2094         /* get number of Java method arguments */
2095
2096         vmargscount = m->parseddesc->paramcount;
2097
2098         /* allocate vm_arg array */
2099
2100         vmargs = DMNEW(vm_arg, vmargscount);
2101
2102         /* fill the vm_arg array from a va_list */
2103
2104         vm_vmargs_from_valist(m, o, vmargs, ap);
2105
2106         /* call the Java method */
2107
2108         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2109
2110         /* release dump area */
2111
2112         dump_release(dumpsize);
2113
2114         return d;
2115 }
2116
2117
2118 /* vm_call_method_double_jvalue ************************************************
2119
2120    Calls a Java method with a variable number of arguments, passed via
2121    a jvalue array, and returns a double.
2122
2123 *******************************************************************************/
2124
2125 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2126                                                                         jvalue *args)
2127 {
2128         s4      vmargscount;
2129         vm_arg *vmargs;
2130         double  d;
2131         s4      dumpsize;
2132
2133         /* mark start of dump memory area */
2134
2135         dumpsize = dump_size();
2136
2137         /* get number of Java method arguments */
2138
2139         vmargscount = m->parseddesc->paramcount;
2140
2141         /* allocate vm_arg array */
2142
2143         vmargs = DMNEW(vm_arg, vmargscount);
2144
2145         /* fill the vm_arg array from a va_list */
2146
2147         vm_vmargs_from_jvalue(m, o, vmargs, args);
2148
2149         /* call the Java method */
2150
2151         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2152
2153         /* release dump area */
2154
2155         dump_release(dumpsize);
2156
2157         return d;
2158 }
2159
2160
2161 /* vm_call_method_double_vmarg *************************************************
2162
2163    Calls a Java method with a variable number of arguments and returns
2164    a double.
2165
2166 *******************************************************************************/
2167
2168 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2169                                                                    vm_arg *vmargs)
2170 {
2171         double d;
2172
2173 #if defined(ENABLE_JIT)
2174 # if defined(ENABLE_INTRP)
2175         if (opt_intrp)
2176                 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2177         else
2178 # endif
2179                 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2180 #else
2181         d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2182 #endif
2183
2184         return d;
2185 }
2186
2187
2188 /*
2189  * These are local overrides for various environment variables in Emacs.
2190  * Please do not remove this and leave it at the end of the file, where
2191  * Emacs will automagically detect them.
2192  * ---------------------------------------------------------------------
2193  * Local variables:
2194  * mode: c
2195  * indent-tabs-mode: t
2196  * c-basic-offset: 4
2197  * tab-width: 4
2198  * End:
2199  */