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