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