* src/vm/vm.c: Renamed -Xglibj to -Xbootclasspath/c to match jamvm's
[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 <errno.h>
40 #include <stdlib.h>
41
42 #if defined(WITH_JRE_LAYOUT)
43 # include <libgen.h>
44 # include <unistd.h>
45 #endif
46
47 #include "vm/types.h"
48
49 #include "mm/boehm.h"
50 #include "mm/memory.h"
51 #include "native/jni.h"
52 #include "native/native.h"
53
54 #if defined(ENABLE_THREADS)
55 # include "threads/native/threads.h"
56 #endif
57
58 #include "vm/classcache.h"
59 #include "vm/exceptions.h"
60 #include "vm/finalizer.h"
61 #include "vm/global.h"
62 #include "vm/initialize.h"
63 #include "vm/options.h"
64 #include "vm/properties.h"
65 #include "vm/signallocal.h"
66 #include "vm/stringlocal.h"
67 #include "vm/suck.h"
68 #include "vm/vm.h"
69 #include "vm/jit/jit.h"
70 #include "vm/jit/asmpart.h"
71
72 #include "vm/jit/recompile.h"
73
74 #include "vm/jit/profile/profile.h"
75 #include "vm/rt-timing.h"
76
77 #if defined(ENABLE_JVMTI)
78 #include "native/jvmti/cacaodbg.h"
79 #endif
80
81
82 /* Invocation API variables ***************************************************/
83
84 _Jv_JavaVM *_Jv_jvm;                    /* denotes a Java VM                  */
85 _Jv_JNIEnv *_Jv_env;                    /* pointer to native method interface */
86
87
88 /* global variables ***********************************************************/
89
90 s4 vms = 0;                             /* number of VMs created              */
91
92 bool vm_initializing = false;
93 bool vm_exiting = false;
94
95 char      *cacao_prefix = NULL;
96 char      *cacao_libjvm = NULL;
97 char      *classpath_libdir = NULL;
98
99 char      *_Jv_bootclasspath;           /* contains the boot classpath        */
100 char      *_Jv_classpath;               /* contains the classpath             */
101 char      *_Jv_java_library_path;
102
103 char      *mainstring = NULL;
104 classinfo *mainclass = NULL;
105
106 char *specificmethodname = NULL;
107 char *specificsignature = NULL;
108
109 bool startit = true;
110
111 #if defined(ENABLE_INTRP)
112 u1 *intrp_main_stack = NULL;
113 #endif
114
115
116 /* define heap sizes **********************************************************/
117
118 #define HEAP_MAXSIZE      128 * 1024 * 1024 /* default 128MB                  */
119 #define HEAP_STARTSIZE      2 * 1024 * 1024 /* default 2MB                    */
120 #define STACK_SIZE                64 * 1024 /* default 64kB                   */
121
122
123 /* define command line options ************************************************/
124
125 enum {
126         OPT_FOO,
127
128         /* Java options */
129
130         OPT_JAR,
131
132         OPT_D32,
133         OPT_D64,
134
135         OPT_CLASSPATH,
136         OPT_D,
137
138         OPT_VERBOSE,
139
140         OPT_VERSION,
141         OPT_SHOWVERSION,
142         OPT_FULLVERSION,
143
144         OPT_HELP,
145         OPT_X,
146
147         OPT_ESA,
148         OPT_DSA,
149
150         /* Java non-standard options */
151
152         OPT_JIT,
153         OPT_INTRP,
154
155         OPT_BOOTCLASSPATH,
156         OPT_BOOTCLASSPATH_A,
157         OPT_BOOTCLASSPATH_P,
158
159         OPT_BOOTCLASSPATH_C,
160
161 #if defined(ENABLE_PROFILING)
162         OPT_PROF,
163         OPT_PROF_OPTION,
164 #endif
165
166         OPT_MS,
167         OPT_MX,
168
169         /* CACAO options */
170
171         OPT_VERBOSE1,
172         OPT_NOIEEE,
173         OPT_SOFTNULL,
174
175 #if defined(ENABLE_STATISTICS)
176         OPT_TIME,
177         OPT_STAT,
178 #endif
179
180         OPT_LOG,
181         OPT_CHECK,
182         OPT_LOAD,
183         OPT_SHOW,
184         OPT_DEBUGCOLOR,
185
186 #if !defined(NDEBUG)
187         OPT_ALL,
188         OPT_METHOD,
189         OPT_SIGNATURE,
190 #endif
191
192 #if defined(ENABLE_VERIFIER)
193         OPT_NOVERIFY,
194 #if defined(TYPECHECK_VERBOSE)
195         OPT_VERBOSETC,
196 #endif
197 #endif /* defined(ENABLE_VERIFIER) */
198         OPT_EAGER,
199
200         /* optimization options */
201
202 #if defined(ENABLE_LOOP)
203         OPT_OLOOP,
204 #endif
205         
206 #if defined(ENABLE_IFCONV)
207         OPT_IFCONV,
208 #endif
209
210 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
211         OPT_LSRA,
212 #endif
213
214 #if defined(ENABLE_INLINING)
215         OPT_INLINING,
216 #endif
217
218 #if defined(ENABLE_INTRP)
219         /* interpreter options */
220
221         OPT_NO_DYNAMIC,
222         OPT_NO_REPLICATION,
223         OPT_NO_QUICKSUPER,
224         OPT_STATIC_SUPERS,
225         OPT_TRACE,
226 #endif
227
228         OPT_SS,
229
230 #ifdef ENABLE_JVMTI
231         OPT_DEBUG,
232         OPT_XRUNJDWP,
233         OPT_NOAGENT,
234         OPT_AGENTLIB,
235         OPT_AGENTPATH,
236 #endif
237
238         DUMMY
239 };
240
241
242 opt_struct opts[] = {
243         { "foo",               false, OPT_FOO },
244
245         /* Java options */
246
247         { "jar",               false, OPT_JAR },
248
249         { "d32",               false, OPT_D32 },
250         { "d64",               false, OPT_D64 },
251         { "client",            false, OPT_IGNORE },
252         { "server",            false, OPT_IGNORE },
253         { "jvm",               false, OPT_IGNORE },
254         { "hotspot",           false, OPT_IGNORE },
255
256         { "classpath",         true,  OPT_CLASSPATH },
257         { "cp",                true,  OPT_CLASSPATH },
258         { "D",                 true,  OPT_D },
259         { "version",           false, OPT_VERSION },
260         { "showversion",       false, OPT_SHOWVERSION },
261         { "fullversion",       false, OPT_FULLVERSION },
262         { "help",              false, OPT_HELP },
263         { "?",                 false, OPT_HELP },
264         { "X",                 false, OPT_X },
265
266         { "esa",                     false, OPT_ESA },
267         { "enablesystemassertions",  false, OPT_ESA },
268         { "dsa",                     false, OPT_DSA },
269         { "disablesystemassertions", false, OPT_DSA },
270
271         { "noasyncgc",         false, OPT_IGNORE },
272 #if defined(ENABLE_VERIFIER)
273         { "noverify",          false, OPT_NOVERIFY },
274 #endif
275         { "v",                 false, OPT_VERBOSE1 },
276         { "verbose:",          true,  OPT_VERBOSE },
277
278 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
279         { "verbosetc",         false, OPT_VERBOSETC },
280 #endif
281 #if defined(__ALPHA__)
282         { "noieee",            false, OPT_NOIEEE },
283 #endif
284         { "softnull",          false, OPT_SOFTNULL },
285 #if defined(ENABLE_STATISTICS)
286         { "time",              false, OPT_TIME },
287         { "stat",              false, OPT_STAT },
288 #endif
289         { "log",               true,  OPT_LOG },
290         { "c",                 true,  OPT_CHECK },
291         { "l",                 false, OPT_LOAD },
292         { "eager",             false, OPT_EAGER },
293
294 #if !defined(NDEBUG)
295         { "all",               false, OPT_ALL },
296         { "sig",               true,  OPT_SIGNATURE },
297 #endif
298
299 #if defined(ENABLE_LOOP)
300         { "oloop",             false, OPT_OLOOP },
301 #endif
302 #if defined(ENABLE_IFCONV)
303         { "ifconv",            false, OPT_IFCONV },
304 #endif
305 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
306         { "lsra",              false, OPT_LSRA },
307 #endif
308
309 #if defined(ENABLE_INTRP)
310         /* interpreter options */
311
312         { "trace",             false, OPT_TRACE },
313         { "static-supers",     true,  OPT_STATIC_SUPERS },
314         { "no-dynamic",        false, OPT_NO_DYNAMIC },
315         { "no-replication",    false, OPT_NO_REPLICATION },
316         { "no-quicksuper",     false, OPT_NO_QUICKSUPER },
317 #endif
318
319         /* JVMTI Agent Command Line Options */
320 #ifdef ENABLE_JVMTI
321         { "agentlib:",         true,  OPT_AGENTLIB },
322         { "agentpath:",        true,  OPT_AGENTPATH },
323 #endif
324
325         /* Java non-standard options */
326
327         { "Xjit",              false, OPT_JIT },
328         { "Xint",              false, OPT_INTRP },
329         { "Xbootclasspath:",   true,  OPT_BOOTCLASSPATH },
330         { "Xbootclasspath/a:", true,  OPT_BOOTCLASSPATH_A },
331         { "Xbootclasspath/p:", true,  OPT_BOOTCLASSPATH_P },
332         { "Xbootclasspath/c:", true,  OPT_BOOTCLASSPATH_C },
333
334 #ifdef ENABLE_JVMTI
335         { "Xdebug",            false, OPT_DEBUG },
336         { "Xnoagent",          false, OPT_NOAGENT },
337         { "Xrunjdwp",          true,  OPT_XRUNJDWP },
338 #endif 
339
340         { "Xms",               true,  OPT_MS },
341         { "ms",                true,  OPT_MS },
342         { "Xmx",               true,  OPT_MX },
343         { "mx",                true,  OPT_MX },
344         { "Xss",               true,  OPT_SS },
345         { "ss",                true,  OPT_SS },
346
347 #if defined(ENABLE_PROFILING)
348         { "Xprof:",            true,  OPT_PROF_OPTION },
349         { "Xprof",             false, OPT_PROF },
350 #endif
351
352         /* keep these at the end of the list */
353
354 #if defined(ENABLE_INLINING)
355         { "i",                 true,  OPT_INLINING },
356 #endif
357
358 #if !defined(NDEBUG)
359         { "m",                 true,  OPT_METHOD },
360 #endif
361
362         { "s",                 true,  OPT_SHOW },
363         { "debug-color",      false,  OPT_DEBUGCOLOR },
364
365         { NULL,                false, 0 }
366 };
367
368
369 /* usage ***********************************************************************
370
371    Prints the correct usage syntax to stdout.
372
373 *******************************************************************************/
374
375 void usage(void)
376 {
377         puts("Usage: cacao [-options] classname [arguments]");
378         puts("               (to run a class file)");
379         puts("   or  cacao [-options] -jar jarfile [arguments]");
380         puts("               (to run a standalone jar file)\n");
381
382         puts("Java options:");
383         puts("    -d32                     use 32-bit data model if available");
384         puts("    -d64                     use 64-bit data model if available");
385         puts("    -client                  compatibility (currently ignored)");
386         puts("    -server                  compatibility (currently ignored)");
387         puts("    -jvm                     compatibility (currently ignored)");
388         puts("    -hotspot                 compatibility (currently ignored)\n");
389
390         puts("    -cp <path>               specify a path to look for classes");
391         puts("    -classpath <path>        specify a path to look for classes");
392         puts("    -D<name>=<value>         add an entry to the property list");
393         puts("    -verbose[:class|gc|jni]  enable specific verbose output");
394         puts("    -version                 print product version and exit");
395         puts("    -fullversion             print jpackage-compatible product version and exit");
396         puts("    -showversion             print product version and continue");
397         puts("    -help, -?                print this help message");
398         puts("    -X                       print help on non-standard Java options");
399         puts("    -esa | -enablesystemassertions");
400         puts("                             enable system assertions");
401         puts("    -dsa | -disablesystemassertions");
402         puts("                             disable system assertions");
403         puts("");
404
405 #ifdef ENABLE_JVMTI
406         puts("    -agentlib:<agent-lib-name>=<options>  library to load containg JVMTI agent");
407         puts ("                                         for jdwp help use: -agentlib:jdwp=help");
408         puts("    -agentpath:<path-to-agent>=<options>  path to library containg JVMTI agent");
409 #endif
410
411         puts("CACAO options:");
412         puts("    -v                       write state-information");
413         puts("    -verbose[:call|exception|jit]");
414         puts("                             enable specific verbose output");
415         puts("    -debug-color             colored output for ANSI terms");
416 #ifdef TYPECHECK_VERBOSE
417         puts("    -verbosetc               write debug messages while typechecking");
418 #endif
419 #if defined(__ALPHA__)
420         puts("    -noieee                  don't use ieee compliant arithmetic");
421 #endif
422 #if defined(ENABLE_VERIFIER)
423         puts("    -noverify                don't verify classfiles");
424 #endif
425         puts("    -softnull                use software nullpointer check");
426 #if defined(ENABLE_STATISTICS)
427         puts("    -time                    measure the runtime");
428         puts("    -stat                    detailed compiler statistics");
429 #endif
430         puts("    -log logfile             specify a name for the logfile");
431         puts("    -c(heck)b(ounds)         don't check array bounds");
432         puts("            s(ync)           don't check for synchronization");
433 #if defined(ENABLE_LOOP)
434         puts("    -oloop                   optimize array accesses in loops");
435 #endif
436         puts("    -l                       don't start the class after loading");
437         puts("    -eager                   perform eager class loading and linking");
438 #if !defined(NDEBUG)
439         puts("    -all                     compile all methods, no execution");
440         puts("    -m                       compile only a specific method");
441         puts("    -sig                     specify signature for a specific method");
442 #endif
443
444         puts("    -s(how)...               show...");
445         puts("           c(onstants)       the constant pool");
446         puts("           m(ethods)         class fields and methods");
447         puts("           u(tf)             the utf - hash");
448         puts("           i(ntermediate)    intermediate representation");
449 #if defined(ENABLE_DISASSEMBLER)
450         puts("           a(ssembler)       disassembled listing");
451         puts("           e(xceptionstubs)  disassembled exception stubs (only with -sa)");
452         puts("           n(ative)          disassembled native stubs");
453 #endif
454         puts("           d(atasegment)     data segment listing");
455 #if defined(ENABLE_INLINING)
456         puts("    -i     n(line)           activate inlining");
457         puts("           v(irtual)         inline virtual methods (uses/turns rt option on)");
458         puts("           e(exception)      inline methods with exceptions");
459         puts("           p(aramopt)        optimize argument renaming");
460         puts("           o(utsiders)       inline methods of foreign classes");
461 #endif /* defined(ENABLE_INLINING) */
462 #if defined(ENABLE_IFCONV)
463         puts("    -ifconv                  use if-conversion");
464 #endif
465 #if defined(ENABLE_LSRA)
466         puts("    -lsra                    use linear scan register allocation");
467 #endif
468 #if defined(ENABLE_SSA)
469         puts("    -lsra                    use linear scan register allocation (with SSA)");
470 #endif
471
472         /* exit with error code */
473
474         exit(1);
475 }   
476
477
478 static void Xusage(void)
479 {
480 #if defined(ENABLE_JIT)
481         puts("    -Xjit                    JIT mode execution (default)");
482 #endif
483 #if defined(ENABLE_INTRP)
484         puts("    -Xint                    interpreter mode execution");
485 #endif
486         puts("    -Xbootclasspath:<zip/jar files and directories separated by :>");
487     puts("                             value is set as bootstrap class path");
488         puts("    -Xbootclasspath/a:<zip/jar files and directories separated by :>");
489         puts("                             value is appended to the bootstrap class path");
490         puts("    -Xbootclasspath/p:<zip/jar files and directories separated by :>");
491         puts("                             value is prepended to the bootstrap class path");
492         puts("    -Xbootclasspath/c:<zip/jar files and directories separated by :>");
493         puts("                             value is used as Java core library, but the");
494         puts("                             hardcoded VM interface classes are prepended");
495         printf("    -Xms<size>               set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
496         printf("    -Xmx<size>               set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
497         printf("    -Xss<size>               set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
498
499 #if defined(ENABLE_PROFILING)
500         puts("    -Xprof[:bb]              collect and print profiling data");
501 #endif
502
503 #if defined(ENABLE_JVMTI)
504     /* -Xdebug option depend on gnu classpath JDWP options. options: 
505          transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
506         puts("    -Xdebug                  enable remote debugging\n");
507         puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
508         puts("                             enable remote debugging\n");
509 #endif 
510
511         /* exit with error code */
512
513         exit(1);
514 }   
515
516
517 /* version *********************************************************************
518
519    Only prints cacao version information.
520
521 *******************************************************************************/
522
523 static void version(bool opt_exit)
524 {
525         puts("java version \""JAVA_VERSION"\"");
526         puts("CACAO version "VERSION"");
527
528         puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
529         puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
530         puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
531         puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
532
533         puts("This program is free software; you can redistribute it and/or");
534         puts("modify it under the terms of the GNU General Public License as");
535         puts("published by the Free Software Foundation; either version 2, or (at");
536         puts("your option) any later version.\n");
537
538         puts("This program is distributed in the hope that it will be useful, but");
539         puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
540         puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU");
541         puts("General Public License for more details.\n");
542
543         puts("Configure/Build options:\n");
544         puts("  ./configure: "VERSION_CONFIGURE_ARGS"");
545 #if defined(__VERSION__)
546         puts("  CC         : "VERSION_CC" ("__VERSION__")");
547 #else
548         puts("  CC         : "VERSION_CC"");
549 #endif
550         puts("  CFLAGS     : "VERSION_CFLAGS"\n");
551
552         puts("Default variables:\n");
553         printf("  maximum heap size              : %d\n", HEAP_MAXSIZE);
554         printf("  initial heap size              : %d\n", HEAP_STARTSIZE);
555         printf("  stack size                     : %d\n", STACK_SIZE);
556         puts("  java.boot.class.path           : "CACAO_VM_ZIP":"CLASSPATH_GLIBJ_ZIP"");
557         puts("  gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
558
559         puts("Runtime variables:\n");
560         printf("  maximum heap size              : %d\n", opt_heapmaxsize);
561         printf("  initial heap size              : %d\n", opt_heapstartsize);
562         printf("  stack size                     : %d\n", opt_stacksize);
563         printf("  java.boot.class.path           : %s\n", _Jv_bootclasspath);
564         printf("  gnu.classpath.boot.library.path: %s\n", classpath_libdir);
565
566         /* exit normally, if requested */
567
568         if (opt_exit)
569                 exit(0);
570 }
571
572
573 /* fullversion *****************************************************************
574
575    Prints a Sun compatible version information (required e.g. by
576    jpackage, www.jpackage.org).
577
578 *******************************************************************************/
579
580 static void fullversion(void)
581 {
582         puts("java full version \"cacao-"JAVA_VERSION"\"");
583
584         /* exit normally */
585
586         exit(0);
587 }
588
589
590 /* forward declarations *******************************************************/
591
592 static char *vm_get_mainclass_from_jar(char *mainstring);
593 #if !defined(NDEBUG)
594 static void  vm_compile_all(void);
595 static void  vm_compile_method(void);
596 #endif
597
598
599 /* vm_create *******************************************************************
600
601    Creates a JVM.  Called by JNI_CreateJavaVM.
602
603 *******************************************************************************/
604
605 bool vm_create(JavaVMInitArgs *vm_args)
606 {
607         char *cp;
608         s4    len;
609         s4    opt;
610         s4    i, j;
611         bool  opt_version;
612         bool  opt_exit;
613
614 #if defined(ENABLE_JVMTI)
615         lt_dlhandle  handle;
616         char *libname, *agentarg;
617         bool jdwp,agentbypath;
618         jdwp = agentbypath = false;
619 #endif
620
621         /* check the JNI version requested */
622
623         switch (vm_args->version) {
624         case JNI_VERSION_1_1:
625                 break;
626         case JNI_VERSION_1_2:
627         case JNI_VERSION_1_4:
628                 break;
629         default:
630                 return false;
631         }
632
633         /* we only support 1 JVM instance */
634
635         if (vms > 0)
636                 return false;
637
638         if (atexit(vm_exit_handler))
639                 vm_abort("atexit failed: %s\n", strerror(errno));
640
641         if (opt_verbose)
642                 log_text("CACAO started -------------------------------------------------------");
643
644         /* set the VM starttime */
645
646         _Jv_jvm->starttime = builtin_currenttimemillis();
647
648         /* get stuff from the environment *****************************************/
649
650 #if defined(DISABLE_GC)
651         nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
652 #endif
653
654 #if defined(WITH_JRE_LAYOUT)
655         /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
656
657         cacao_prefix = MNEW(char, 4096);
658
659         if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
660                 vm_abort("readlink failed: %s\n", strerror(errno));
661
662         /* get the path of the current executable */
663
664         cacao_prefix = dirname(cacao_prefix);
665
666         if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
667                 vm_abort("libjvm name to long for buffer\n");
668
669         /* concatenate the library name */
670
671         strcat(cacao_prefix, "/..");
672
673         /* now set path to libjvm.so */
674
675         len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
676
677         cacao_libjvm = MNEW(char, len);
678         strcpy(cacao_libjvm, cacao_prefix);
679         strcat(cacao_libjvm, "/lib/libjvm");
680
681         /* and finally set the path to GNU Classpath libraries */
682
683         len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
684
685         classpath_libdir = MNEW(char, len);
686         strcpy(classpath_libdir, cacao_prefix);
687         strcat(classpath_libdir, "/lib/classpath");
688 #else
689         cacao_prefix     = CACAO_PREFIX;
690         cacao_libjvm     = CACAO_LIBDIR"/libjvm";
691         classpath_libdir = CLASSPATH_LIBDIR"/classpath";
692 #endif
693
694         /* set the bootclasspath */
695
696         cp = getenv("BOOTCLASSPATH");
697
698         if (cp != NULL) {
699                 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
700                 strcpy(_Jv_bootclasspath, cp);
701         }
702         else {
703 #if defined(WITH_JRE_LAYOUT)
704                 len =
705                         strlen(cacao_prefix) +
706                         strlen("/share/cacao/vm.zip") +
707                         strlen(":") +
708                         strlen(cacao_prefix) +
709                         strlen("/share/classpath/glibj.zip") +
710                         strlen("0");
711
712                 _Jv_bootclasspath = MNEW(char, len);
713                 strcat(_Jv_bootclasspath, cacao_prefix);
714                 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
715                 strcat(_Jv_bootclasspath, ":");
716                 strcat(_Jv_bootclasspath, cacao_prefix);
717                 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
718 #else
719                 len =
720                         strlen(CACAO_VM_ZIP) +
721                         strlen(":") +
722                         strlen(CLASSPATH_GLIBJ_ZIP) +
723                         strlen("0");
724
725                 _Jv_bootclasspath = MNEW(char, len);
726                 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
727                 strcat(_Jv_bootclasspath, ":");
728                 strcat(_Jv_bootclasspath, CLASSPATH_GLIBJ_ZIP);
729 #endif
730         }
731
732         /* set the classpath */
733
734         cp = getenv("CLASSPATH");
735
736         if (cp != NULL) {
737                 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
738                 strcat(_Jv_classpath, cp);
739         }
740         else {
741                 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
742                 strcpy(_Jv_classpath, ".");
743         }
744
745         /* get and set java.library.path */
746
747         _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
748
749         if (_Jv_java_library_path == NULL)
750                 _Jv_java_library_path = "";
751
752         /* interpret the options **************************************************/
753
754         opt_version       = false;
755         opt_exit          = false;
756
757         checknull         = false;
758         opt_noieee        = false;
759
760         opt_heapmaxsize   = HEAP_MAXSIZE;
761         opt_heapstartsize = HEAP_STARTSIZE;
762         opt_stacksize     = STACK_SIZE;
763
764
765 #if defined(ENABLE_JVMTI)
766         /* initialize JVMTI related  **********************************************/
767         jvmti = false;
768 #endif
769
770         /* initialize properties before commandline handling */
771
772         if (!properties_init())
773                 throw_cacao_exception_exit(string_java_lang_InternalError,
774                                                                    "Unable to init properties");
775
776         /* add some default properties */
777
778         properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
779
780         /* iterate over all passed options */
781
782         while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
783                 switch (opt) {
784                 case OPT_FOO:
785                         opt_foo = true;
786                         break;
787
788                 case OPT_IGNORE:
789                         break;
790                         
791                 case OPT_JAR:
792                         opt_jar = true;
793                         break;
794
795                 case OPT_D32:
796 #if SIZEOF_VOID_P == 8
797                         puts("Running a 32-bit JVM is not supported on this platform.");
798                         exit(1);
799 #endif
800                         break;
801
802                 case OPT_D64:
803 #if SIZEOF_VOID_P == 4
804                         puts("Running a 64-bit JVM is not supported on this platform.");
805                         exit(1);
806 #endif
807                         break;
808
809                 case OPT_CLASSPATH:
810                         /* forget old classpath and set the argument as new classpath */
811                         MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
812
813                         _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
814                         strcpy(_Jv_classpath, opt_arg);
815                         break;
816
817                 case OPT_D:
818                         for (i = 0; i < strlen(opt_arg); i++) {
819                                 if (opt_arg[i] == '=') {
820                                         opt_arg[i] = '\0';
821                                         properties_add(opt_arg, opt_arg + i + 1);
822                                         goto opt_d_done;
823                                 }
824                         }
825
826                         /* if no '=' is given, just create an empty property */
827
828                         properties_add(opt_arg, "");
829
830                 opt_d_done:
831                         break;
832
833                 case OPT_BOOTCLASSPATH:
834                         /* Forget default bootclasspath and set the argument as
835                            new boot classpath. */
836
837                         MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
838
839                         _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
840                         strcpy(_Jv_bootclasspath, opt_arg);
841                         break;
842
843                 case OPT_BOOTCLASSPATH_A:
844                         /* append to end of bootclasspath */
845
846                         len = strlen(_Jv_bootclasspath);
847
848                         _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
849                                                                                  char,
850                                                                                  len,
851                                                                                  len + strlen(":") +
852                                                                                  strlen(opt_arg) + strlen("0"));
853
854                         strcat(_Jv_bootclasspath, ":");
855                         strcat(_Jv_bootclasspath, opt_arg);
856                         break;
857
858                 case OPT_BOOTCLASSPATH_P:
859                         /* prepend in front of bootclasspath */
860
861                         cp = _Jv_bootclasspath;
862                         len = strlen(cp);
863
864                         _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
865                                                                          len + strlen("0"));
866
867                         strcpy(_Jv_bootclasspath, opt_arg);
868                         strcat(_Jv_bootclasspath, ":");
869                         strcat(_Jv_bootclasspath, cp);
870
871                         MFREE(cp, char, len);
872                         break;
873
874                 case OPT_BOOTCLASSPATH_C:
875                         /* use as Java core library, but prepend VM interface classes */
876
877                         MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
878
879                         len = strlen(CACAO_VM_ZIP) +
880                                 strlen(":") +
881                                 strlen(opt_arg) +
882                                 strlen("0");
883
884                         _Jv_bootclasspath = MNEW(char, len);
885
886                         strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
887                         strcat(_Jv_bootclasspath, ":");
888                         strcat(_Jv_bootclasspath, opt_arg);
889                         break;
890
891 #if defined(ENABLE_JVMTI)
892                 case OPT_DEBUG:
893                         /* this option exists only for compatibility reasons */
894                         break;
895
896                 case OPT_NOAGENT:
897                         /* I don't know yet what Xnoagent should do. This is only for 
898                            compatiblity with eclipse - motse */
899                         break;
900
901                 case OPT_XRUNJDWP:
902                         agentbypath = true;
903                         jvmti       = true;
904                         jdwp        = true;
905
906                         len =
907                                 strlen(CACAO_LIBDIR) +
908                                 strlen("/libjdwp.so=") +
909                                 strlen(opt_arg) +
910                                 strlen("0");
911
912                         agentarg = MNEW(char, len);
913
914                         strcpy(agentarg, CACAO_LIBDIR);
915                         strcat(agentarg, "/libjdwp.so=");
916                         strcat(agentarg, &opt_arg[1]);
917                         break;
918
919                 case OPT_AGENTPATH:
920                         agentbypath = true;
921
922                 case OPT_AGENTLIB:
923                         jvmti = true;
924                         agentarg = opt_arg;
925                         break;
926 #endif
927                         
928                 case OPT_MX:
929                 case OPT_MS:
930                 case OPT_SS:
931                         {
932                                 char c;
933                                 c = opt_arg[strlen(opt_arg) - 1];
934
935                                 if ((c == 'k') || (c == 'K')) {
936                                         j = atoi(opt_arg) * 1024;
937
938                                 } else if ((c == 'm') || (c == 'M')) {
939                                         j = atoi(opt_arg) * 1024 * 1024;
940
941                                 } else
942                                         j = atoi(opt_arg);
943
944                                 if (opt == OPT_MX)
945                                         opt_heapmaxsize = j;
946                                 else if (opt == OPT_MS)
947                                         opt_heapstartsize = j;
948                                 else
949                                         opt_stacksize = j;
950                         }
951                         break;
952
953                 case OPT_VERBOSE1:
954                         opt_verbose = true;
955                         break;
956
957                 case OPT_VERBOSE:
958                         if (strcmp("class", opt_arg) == 0)
959                                 opt_verboseclass = true;
960
961                         else if (strcmp("gc", opt_arg) == 0)
962                                 opt_verbosegc = true;
963
964                         else if (strcmp("jni", opt_arg) == 0)
965                                 opt_verbosejni = true;
966
967                         else if (strcmp("call", opt_arg) == 0)
968                                 opt_verbosecall = true;
969
970                         else if (strcmp("jit", opt_arg) == 0) {
971                                 opt_verbose = true;
972                                 loadverbose = true;
973                                 linkverbose = true;
974                                 initverbose = true;
975                                 compileverbose = true;
976                         }
977                         else if (strcmp("exception", opt_arg) == 0)
978                                 opt_verboseexception = true;
979                         break;
980                 case OPT_DEBUGCOLOR:
981                         opt_debugcolor = true;
982                         break;
983
984 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
985                 case OPT_VERBOSETC:
986                         opt_typecheckverbose = true;
987                         break;
988 #endif
989                                 
990                 case OPT_VERSION:
991                         opt_version = true;
992                         opt_exit    = true;
993                         break;
994
995                 case OPT_FULLVERSION:
996                         fullversion();
997                         break;
998
999                 case OPT_SHOWVERSION:
1000                         opt_version = true;
1001                         break;
1002
1003                 case OPT_NOIEEE:
1004                         opt_noieee = true;
1005                         break;
1006
1007 #if defined(ENABLE_VERIFIER)
1008                 case OPT_NOVERIFY:
1009                         opt_verify = false;
1010                         break;
1011 #endif
1012
1013                 case OPT_SOFTNULL:
1014                         checknull = true;
1015                         break;
1016
1017 #if defined(ENABLE_STATISTICS)
1018                 case OPT_TIME:
1019                         opt_getcompilingtime = true;
1020                         opt_getloadingtime = true;
1021                         break;
1022                                         
1023                 case OPT_STAT:
1024                         opt_stat = true;
1025                         break;
1026 #endif
1027                                         
1028                 case OPT_LOG:
1029                         log_init(opt_arg);
1030                         break;
1031                         
1032                 case OPT_CHECK:
1033                         for (i = 0; i < strlen(opt_arg); i++) {
1034                                 switch (opt_arg[i]) {
1035                                 case 'b':
1036                                         checkbounds = false;
1037                                         break;
1038                                 case 's':
1039                                         checksync = false;
1040                                         break;
1041                                 default:
1042                                         usage();
1043                                 }
1044                         }
1045                         break;
1046                         
1047                 case OPT_LOAD:
1048                         opt_run = false;
1049                         makeinitializations = false;
1050                         break;
1051
1052                 case OPT_EAGER:
1053                         opt_eager = true;
1054                         break;
1055
1056 #if !defined(NDEBUG)
1057                 case OPT_ALL:
1058                         compileall = true;
1059                         opt_run = false;
1060                         makeinitializations = false;
1061                         break;
1062
1063                 case OPT_METHOD:
1064                         opt_run = false;
1065                         opt_method = opt_arg;
1066                         makeinitializations = false;
1067                         break;
1068
1069                 case OPT_SIGNATURE:
1070                         opt_signature = opt_arg;
1071                         break;
1072 #endif
1073
1074                 case OPT_SHOW:       /* Display options */
1075                         for (i = 0; i < strlen(opt_arg); i++) {         
1076                                 switch (opt_arg[i]) {
1077                                 case 'c':
1078                                         showconstantpool = true;
1079                                         break;
1080
1081                                 case 'u':
1082                                         showutf = true;
1083                                         break;
1084
1085                                 case 'm':
1086                                         showmethods = true;
1087                                         break;
1088
1089                                 case 'i':
1090                                         opt_showintermediate = true;
1091                                         compileverbose = true;
1092                                         break;
1093
1094 #if defined(ENABLE_DISASSEMBLER)
1095                                 case 'a':
1096                                         opt_showdisassemble = true;
1097                                         compileverbose = true;
1098                                         break;
1099
1100                                 case 'e':
1101                                         opt_showexceptionstubs = true;
1102                                         break;
1103
1104                                 case 'n':
1105                                         opt_shownativestub = true;
1106                                         break;
1107 #endif
1108
1109                                 case 'd':
1110                                         opt_showddatasegment = true;
1111                                         break;
1112
1113                                 default:
1114                                         usage();
1115                                 }
1116                         }
1117                         break;
1118                         
1119 #if defined(ENABLE_LOOP)
1120                 case OPT_OLOOP:
1121                         opt_loops = true;
1122                         break;
1123 #endif
1124
1125 #if defined(ENABLE_INLINING)
1126                 case OPT_INLINING:
1127                         for (i = 0; i < strlen(opt_arg); i++) {         
1128                                 switch (opt_arg[i]) {
1129                                 case 'n':
1130                                         /* define in options.h; Used in main.c, jit.c
1131                                            & inline.c inlining is currently
1132                                            deactivated */
1133                                         break;
1134                                 case 'v':
1135                                         inlinevirtuals = true;
1136                                         break;
1137                                 case 'e':
1138                                         inlineexceptions = true;
1139                                         break;
1140                                 case 'p':
1141                                         inlineparamopt = true;
1142                                         break;
1143                                 case 'o':
1144                                         inlineoutsiders = true;
1145                                         break;
1146                                 default:
1147                                         usage();
1148                                 }
1149                         }
1150                         break;
1151 #endif /* defined(ENABLE_INLINING) */
1152
1153 #if defined(ENABLE_IFCONV)
1154                 case OPT_IFCONV:
1155                         opt_ifconv = true;
1156                         break;
1157 #endif
1158
1159 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1160                 case OPT_LSRA:
1161                         opt_lsra = true;
1162                         break;
1163 #endif
1164
1165                 case OPT_HELP:
1166                         usage();
1167                         break;
1168
1169                 case OPT_X:
1170                         Xusage();
1171                         break;
1172
1173                 case OPT_ESA:
1174                         _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1175                         break;
1176
1177                 case OPT_DSA:
1178                         _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1179                         break;
1180
1181 #if defined(ENABLE_PROFILING)
1182                 case OPT_PROF_OPTION:
1183                         /* use <= to get the last \0 too */
1184
1185                         for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1186                                 if (opt_arg[i] == ',')
1187                                         opt_arg[i] = '\0';
1188
1189                                 if (opt_arg[i] == '\0') {
1190                                         if (strcmp("bb", opt_arg + j) == 0)
1191                                                 opt_prof_bb = true;
1192
1193                                         else {
1194                                                 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1195                                                 usage();
1196                                         }
1197
1198                                         /* set k to next char */
1199
1200                                         j = i + 1;
1201                                 }
1202                         }
1203                         /* fall through */
1204
1205                 case OPT_PROF:
1206                         opt_prof = true;
1207                         break;
1208 #endif
1209
1210                 case OPT_JIT:
1211 #if defined(ENABLE_JIT)
1212                         opt_jit = true;
1213 #else
1214                         printf("-Xjit option not enabled.\n");
1215                         exit(1);
1216 #endif
1217                         break;
1218
1219                 case OPT_INTRP:
1220 #if defined(ENABLE_INTRP)
1221                         opt_intrp = true;
1222 #else
1223                         printf("-Xint option not enabled.\n");
1224                         exit(1);
1225 #endif
1226                         break;
1227
1228 #if defined(ENABLE_INTRP)
1229                 case OPT_STATIC_SUPERS:
1230                         opt_static_supers = atoi(opt_arg);
1231                         break;
1232
1233                 case OPT_NO_DYNAMIC:
1234                         opt_no_dynamic = true;
1235                         break;
1236
1237                 case OPT_NO_REPLICATION:
1238                         opt_no_replication = true;
1239                         break;
1240
1241                 case OPT_NO_QUICKSUPER:
1242                         opt_no_quicksuper = true;
1243                         break;
1244
1245                 case OPT_TRACE:
1246                         vm_debug = true;
1247                         break;
1248 #endif
1249
1250                 default:
1251                         printf("Unknown option: %s\n",
1252                                    vm_args->options[opt_index].optionString);
1253                         usage();
1254                 }
1255         }
1256
1257
1258         /* Now we have all options handled and we can print the version
1259            information. */
1260
1261         if (opt_version)
1262                 version(opt_exit);
1263
1264
1265         /* get the main class *****************************************************/
1266
1267         if (opt_index < vm_args->nOptions) {
1268                 mainstring = vm_args->options[opt_index++].optionString;
1269
1270                 /* Put the jar file into the classpath (if any). */
1271
1272                 if (opt_jar == true) {
1273                         /* free old classpath */
1274
1275                         MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1276
1277                         /* put jarfile into classpath */
1278
1279                         _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1280
1281                         strcpy(_Jv_classpath, mainstring);
1282                 }
1283                 else {
1284                         /* replace .'s with /'s in classname */
1285
1286                         for (i = strlen(mainstring) - 1; i >= 0; i--)
1287                                 if (mainstring[i] == '.')
1288                                         mainstring[i] = '/';
1289                 }
1290         }
1291
1292 #if defined(ENABLE_JVMTI)
1293         if (jvmti) {
1294                 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1295                 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1296
1297                 if (jdwp)
1298                         MFREE(agentarg, char, strlen(agentarg));
1299
1300                 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1301         }
1302
1303 #endif
1304
1305
1306         /* initialize this JVM ****************************************************/
1307
1308         vm_initializing = true;
1309
1310 #if defined(ENABLE_THREADS)
1311         /* pre-initialize some core thread stuff, like the stopworldlock,
1312            thus this has to happen _before_ gc_init()!!! */
1313
1314         threads_preinit();
1315 #endif
1316
1317         /* initialize the garbage collector */
1318
1319         gc_init(opt_heapmaxsize, opt_heapstartsize);
1320
1321 #if defined(ENABLE_INTRP)
1322         /* Allocate main thread stack on the Java heap. */
1323
1324         if (opt_intrp) {
1325                 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1326                 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1327         }
1328 #endif
1329
1330         /* initialize the string hashtable stuff: lock (must be done
1331            _after_ threads_preinit) */
1332
1333         if (!string_init())
1334                 throw_main_exception_exit();
1335
1336         /* initialize the utf8 hashtable stuff: lock, often used utf8
1337            strings (must be done _after_ threads_preinit) */
1338
1339         if (!utf8_init())
1340                 throw_main_exception_exit();
1341
1342         /* initialize the classcache hashtable stuff: lock, hashtable
1343            (must be done _after_ threads_preinit) */
1344
1345         if (!classcache_init())
1346                 throw_main_exception_exit();
1347
1348         /* initialize the loader with bootclasspath (must be done _after_
1349            thread_preinit) */
1350
1351         if (!suck_init())
1352                 throw_main_exception_exit();
1353
1354         suck_add_from_property("java.endorsed.dirs");
1355         suck_add(_Jv_bootclasspath);
1356
1357         /* initialize the memory subsystem (must be done _after_
1358            threads_preinit) */
1359
1360         if (!memory_init())
1361                 throw_main_exception_exit();
1362
1363         /* initialize the finalizer stuff (must be done _after_
1364            threads_preinit) */
1365
1366         if (!finalizer_init())
1367                 throw_main_exception_exit();
1368
1369         /* install architecture dependent signal handler used for exceptions */
1370
1371         signal_init();
1372
1373         /* initialize the codegen subsystems */
1374
1375         codegen_init();
1376
1377         /* initializes jit compiler */
1378
1379         jit_init();
1380
1381         /* machine dependent initialization */
1382
1383 #if defined(ENABLE_JIT)
1384 # if defined(ENABLE_INTRP)
1385         if (opt_intrp)
1386                 intrp_md_init();
1387         else
1388 # endif
1389                 md_init();
1390 #else
1391         intrp_md_init();
1392 #endif
1393
1394         /* initialize the loader subsystems (must be done _after_
1395        classcache_init) */
1396
1397         if (!loader_init())
1398                 throw_main_exception_exit();
1399
1400         if (!linker_init())
1401                 throw_main_exception_exit();
1402
1403         if (!native_init())
1404                 throw_main_exception_exit();
1405
1406         if (!exceptions_init())
1407                 throw_main_exception_exit();
1408
1409         if (!builtin_init())
1410                 throw_main_exception_exit();
1411
1412         /* Initialize the JNI subsystem (must be done _before_
1413            threads_init, as threads_init can call JNI methods
1414            (e.g. NewGlobalRef). */
1415
1416         if (!jni_init())
1417                 throw_main_exception_exit();
1418
1419 #if defined(ENABLE_THREADS)
1420         if (!threads_init())
1421                 throw_main_exception_exit();
1422 #endif
1423
1424         /* That's important, otherwise we get into trouble, if the Runtime
1425            static initializer is called before (circular dependency. This
1426            is with classpath 0.09. Another important thing is, that this
1427            has to happen after initThreads!!! */
1428
1429         if (!initialize_class(class_java_lang_System))
1430                 throw_main_exception_exit();
1431
1432 #if defined(ENABLE_PROFILING)
1433         /* initialize profiling */
1434
1435         if (!profile_init())
1436                 throw_main_exception_exit();
1437 #endif
1438
1439 #if defined(ENABLE_THREADS)
1440         /* initialize recompilation */
1441
1442         if (!recompile_init())
1443                 throw_main_exception_exit();
1444                 
1445         /* finally, start the finalizer thread */
1446
1447         if (!finalizer_start_thread())
1448                 throw_main_exception_exit();
1449
1450         /* start the recompilation thread (must be done before the
1451            profiling thread) */
1452
1453         if (!recompile_start_thread())
1454                 throw_main_exception_exit();
1455
1456 # if defined(ENABLE_PROFILING)
1457         /* start the profile sampling thread */
1458
1459 /*      if (opt_prof) */
1460 /*              if (!profile_start_thread()) */
1461 /*                      throw_main_exception_exit(); */
1462 # endif
1463 #endif
1464
1465 #if defined(ENABLE_JVMTI)
1466         if (jvmti) {
1467                 /* add agent library to native library hashtable */
1468                 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1469         }
1470 #endif
1471
1472         /* increment the number of VMs */
1473
1474         vms++;
1475
1476         /* initialization is done */
1477
1478         vm_initializing = false;
1479
1480         /* everything's ok */
1481
1482         return true;
1483 }
1484
1485
1486 /* vm_run **********************************************************************
1487
1488    Runs the main-method of the passed class.
1489
1490 *******************************************************************************/
1491
1492 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1493 {
1494         utf              *mainutf;
1495         classinfo        *mainclass;
1496         methodinfo       *m;
1497         java_objectarray *oa; 
1498         s4                oalength;
1499         utf              *u;
1500         java_lang_String *s;
1501         s4                status;
1502         s4                i;
1503
1504 #if !defined(NDEBUG)
1505         if (compileall) {
1506                 vm_compile_all();
1507                 return;
1508         }
1509
1510         if (opt_method != NULL) {
1511                 vm_compile_method();
1512                 return;
1513         }
1514 #endif /* !defined(NDEBUG) */
1515
1516         /* should we run the main-method? */
1517
1518         if (mainstring == NULL)
1519                 usage();
1520
1521         /* set return value to OK */
1522
1523         status = 0;
1524
1525         if (opt_jar == true)
1526                 /* open jar file with java.util.jar.JarFile */
1527                 mainstring = vm_get_mainclass_from_jar(mainstring);
1528
1529         /* load the main class */
1530
1531         mainutf = utf_new_char(mainstring);
1532
1533         if (!(mainclass = load_class_from_sysloader(mainutf)))
1534                 throw_main_exception_exit();
1535
1536         /* error loading class */
1537
1538         if ((*exceptionptr != NULL) || (mainclass == NULL))
1539                 throw_main_exception_exit();
1540
1541         if (!link_class(mainclass))
1542                 throw_main_exception_exit();
1543                         
1544         /* find the `main' method of the main class */
1545
1546         m = class_resolveclassmethod(mainclass,
1547                                                                  utf_new_char("main"), 
1548                                                                  utf_new_char("([Ljava/lang/String;)V"),
1549                                                                  class_java_lang_Object,
1550                                                                  false);
1551
1552         if (*exceptionptr) {
1553                 throw_main_exception_exit();
1554         }
1555
1556         /* there is no main method or it isn't static */
1557
1558         if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1559                 *exceptionptr = NULL;
1560
1561                 *exceptionptr =
1562                         new_exception_message(string_java_lang_NoSuchMethodError, "main");
1563                 throw_main_exception_exit();
1564         }
1565
1566         /* build argument array */
1567
1568         oalength = vm_args->nOptions - opt_index;
1569
1570         oa = builtin_anewarray(oalength, class_java_lang_String);
1571
1572         for (i = 0; i < oalength; i++) {
1573                 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1574                 s = javastring_new(u);
1575
1576                 oa->data[i] = (java_objectheader *) s;
1577         }
1578
1579 #ifdef TYPEINFO_DEBUG_TEST
1580         /* test the typeinfo system */
1581         typeinfo_test();
1582 #endif
1583         /*class_showmethods(currentThread->group->header.vftbl->class); */
1584
1585 #if defined(ENABLE_JVMTI)
1586         jvmti_set_phase(JVMTI_PHASE_LIVE);
1587 #endif
1588
1589         /* increase total started thread count */
1590
1591         _Jv_jvm->total_started_thread_count++;
1592
1593         /* start the main thread */
1594
1595         (void) vm_call_method(m, NULL, oa);
1596
1597         /* exception occurred? */
1598
1599         if (*exceptionptr) {
1600                 throw_main_exception();
1601                 status = 1;
1602         }
1603
1604         /* unload the JavaVM */
1605
1606         vm_destroy(vm);
1607
1608         /* and exit */
1609
1610         vm_exit(status);
1611 }
1612
1613
1614 /* vm_destroy ******************************************************************
1615
1616    Unloads a Java VM and reclaims its resources.
1617
1618 *******************************************************************************/
1619
1620 s4 vm_destroy(JavaVM *vm)
1621 {
1622 #if defined(ENABLE_THREADS)
1623         threads_join_all_threads();
1624 #endif
1625
1626         /* everything's ok */
1627
1628         return 0;
1629 }
1630
1631
1632 /* vm_exit *********************************************************************
1633
1634    Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1635
1636 *******************************************************************************/
1637
1638 void vm_exit(s4 status)
1639 {
1640         methodinfo *m;
1641
1642         /* signal that we are exiting */
1643
1644         vm_exiting = true;
1645
1646         assert(class_java_lang_System);
1647         assert(class_java_lang_System->state & CLASS_LOADED);
1648
1649 #if defined(ENABLE_JVMTI)
1650         if (jvmti || (dbgcom!=NULL)) {
1651                 jvmti_set_phase(JVMTI_PHASE_DEAD);
1652                 if (jvmti) jvmti_agentunload();
1653         }
1654 #endif
1655
1656         if (!link_class(class_java_lang_System))
1657                 throw_main_exception_exit();
1658
1659         /* call java.lang.System.exit(I)V */
1660
1661         m = class_resolveclassmethod(class_java_lang_System,
1662                                                                  utf_new_char("exit"),
1663                                                                  utf_int__void,
1664                                                                  class_java_lang_Object,
1665                                                                  true);
1666         
1667         if (m == NULL)
1668                 throw_main_exception_exit();
1669
1670         /* call the exit function with passed exit status */
1671
1672         (void) vm_call_method(m, NULL, status);
1673
1674         /* If we had an exception, just ignore the exception and exit with
1675            the proper code. */
1676
1677         vm_shutdown(status);
1678 }
1679
1680
1681 /* vm_shutdown *****************************************************************
1682
1683    Terminates the system immediately without freeing memory explicitly
1684    (to be used only for abnormal termination).
1685         
1686 *******************************************************************************/
1687
1688 void vm_shutdown(s4 status)
1689 {
1690         if (opt_verbose 
1691 #if defined(ENABLE_STATISTICS)
1692                 || opt_getcompilingtime || opt_stat
1693 #endif
1694            ) 
1695         {
1696                 log_text("CACAO terminated by shutdown");
1697                 dolog("Exit status: %d\n", (s4) status);
1698
1699         }
1700
1701 #if defined(ENABLE_JVMTI)
1702         /* terminate cacaodbgserver */
1703         if (dbgcom!=NULL) {
1704                 pthread_mutex_lock(&dbgcomlock);
1705                 dbgcom->running=1;
1706                 pthread_mutex_unlock(&dbgcomlock);
1707                 jvmti_cacaodbgserver_quit();
1708         }       
1709 #endif
1710
1711         exit(status);
1712 }
1713
1714
1715 /* vm_exit_handler *************************************************************
1716
1717    The exit_handler function is called upon program termination.
1718
1719    ATTENTION: Don't free system resources here! Some threads may still
1720    be running as this is called from VMRuntime.exit(). The OS does the
1721    cleanup for us.
1722
1723 *******************************************************************************/
1724
1725 void vm_exit_handler(void)
1726 {
1727 #if !defined(NDEBUG)
1728         if (showmethods)
1729                 class_showmethods(mainclass);
1730
1731         if (showconstantpool)
1732                 class_showconstantpool(mainclass);
1733
1734         if (showutf)
1735                 utf_show();
1736
1737 # if defined(ENABLE_PROFILING)
1738         if (opt_prof)
1739                 profile_printstats();
1740 # endif
1741 #endif /* !defined(NDEBUG) */
1742
1743 #if defined(ENABLE_RT_TIMING)
1744         rt_timing_print_time_stats(stderr);
1745 #endif
1746
1747 #if defined(ENABLE_CYCLES_STATS)
1748         builtin_print_cycles_stats(stderr);
1749         stacktrace_print_cycles_stats(stderr);
1750 #endif
1751
1752         if (opt_verbose 
1753 #if defined(ENABLE_STATISTICS)
1754                 || opt_getcompilingtime || opt_stat
1755 #endif
1756            ) 
1757         {
1758                 log_text("CACAO terminated");
1759
1760 #if defined(ENABLE_STATISTICS)
1761                 if (opt_stat) {
1762                         print_stats();
1763 #ifdef TYPECHECK_STATISTICS
1764                         typecheck_print_statistics(get_logfile());
1765 #endif
1766                 }
1767
1768                 mem_usagelog(1);
1769
1770                 if (opt_getcompilingtime)
1771                         print_times();
1772 #endif /* defined(ENABLE_STATISTICS) */
1773         }
1774         /* vm_print_profile(stderr);*/
1775 }
1776
1777
1778 /* vm_abort ********************************************************************
1779
1780    Prints an error message and aborts the VM.
1781
1782 *******************************************************************************/
1783
1784 void vm_abort(const char *text, ...)
1785 {
1786         va_list ap;
1787
1788         /* print the log message */
1789
1790         log_start();
1791
1792         va_start(ap, text);
1793         log_vprint(text, ap);
1794         va_end(ap);
1795
1796         log_finish();
1797
1798         /* now abort the VM */
1799
1800         abort();
1801 }
1802
1803
1804 /* vm_get_mainclass_from_jar ***************************************************
1805
1806    Gets the name of the main class from a JAR's manifest file.
1807
1808 *******************************************************************************/
1809
1810 static char *vm_get_mainclass_from_jar(char *mainstring)
1811 {
1812         classinfo         *c;
1813         java_objectheader *o;
1814         methodinfo        *m;
1815         java_lang_String  *s;
1816
1817         c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
1818
1819         if (c == NULL)
1820                 throw_main_exception_exit();
1821         
1822         /* create JarFile object */
1823
1824         o = builtin_new(c);
1825
1826         if (o == NULL)
1827                 throw_main_exception_exit();
1828
1829
1830         m = class_resolveclassmethod(c,
1831                                                                  utf_init, 
1832                                                                  utf_java_lang_String__void,
1833                                                                  class_java_lang_Object,
1834                                                                  true);
1835
1836         if (m == NULL)
1837                 throw_main_exception_exit();
1838
1839         s = javastring_new_from_ascii(mainstring);
1840
1841         (void) vm_call_method(m, o, s);
1842
1843         if (*exceptionptr)
1844                 throw_main_exception_exit();
1845
1846         /* get manifest object */
1847
1848         m = class_resolveclassmethod(c,
1849                                                                  utf_new_char("getManifest"), 
1850                                                                  utf_new_char("()Ljava/util/jar/Manifest;"),
1851                                                                  class_java_lang_Object,
1852                                                                  true);
1853
1854         if (m == NULL)
1855                 throw_main_exception_exit();
1856
1857         o = vm_call_method(m, o);
1858
1859         if (o == NULL) {
1860                 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
1861                 vm_exit(1);
1862         }
1863
1864
1865         /* get Main Attributes */
1866
1867         m = class_resolveclassmethod(o->vftbl->class,
1868                                                                  utf_new_char("getMainAttributes"), 
1869                                                                  utf_new_char("()Ljava/util/jar/Attributes;"),
1870                                                                  class_java_lang_Object,
1871                                                                  true);
1872
1873         if (m == NULL)
1874                 throw_main_exception_exit();
1875
1876         o = vm_call_method(m, o);
1877
1878         if (o == NULL) {
1879                 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
1880                 vm_exit(1);
1881         }
1882
1883
1884         /* get property Main-Class */
1885
1886         m = class_resolveclassmethod(o->vftbl->class,
1887                                                                  utf_new_char("getValue"), 
1888                                                                  utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
1889                                                                  class_java_lang_Object,
1890                                                                  true);
1891
1892         if (m == NULL)
1893                 throw_main_exception_exit();
1894
1895         s = javastring_new_from_ascii("Main-Class");
1896
1897         o = vm_call_method(m, o, s);
1898
1899         if (o == NULL)
1900                 throw_main_exception_exit();
1901
1902         return javastring_tochar(o);
1903 }
1904
1905
1906 /* vm_compile_all **************************************************************
1907
1908    Compile all methods found in the bootclasspath.
1909
1910 *******************************************************************************/
1911
1912 #if !defined(NDEBUG)
1913 static void vm_compile_all(void)
1914 {
1915         classinfo              *c;
1916         methodinfo             *m;
1917         u4                      slot;
1918         classcache_name_entry  *nmen;
1919         classcache_class_entry *clsen;
1920         s4                      i;
1921
1922         /* create all classes found in the bootclasspath */
1923         /* XXX currently only works with zip/jar's */
1924
1925         loader_load_all_classes();
1926
1927         /* link all classes */
1928
1929         for (slot = 0; slot < hashtable_classcache.size; slot++) {
1930                 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
1931
1932                 for (; nmen; nmen = nmen->hashlink) {
1933                         /* iterate over all class entries */
1934
1935                         for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1936                                 c = clsen->classobj;
1937
1938                                 if (c == NULL)
1939                                         continue;
1940
1941                                 if (!(c->state & CLASS_LINKED)) {
1942                                         if (!link_class(c)) {
1943                                                 fprintf(stderr, "Error linking: ");
1944                                                 utf_fprint_printable_ascii_classname(stderr, c->name);
1945                                                 fprintf(stderr, "\n");
1946
1947                                                 /* print out exception and cause */
1948
1949                                                 exceptions_print_exception(*exceptionptr);
1950
1951                                                 /* goto next class */
1952
1953                                                 continue;
1954                                         }
1955                                 }
1956
1957                                 /* compile all class methods */
1958
1959                                 for (i = 0; i < c->methodscount; i++) {
1960                                         m = &(c->methods[i]);
1961
1962                                         if (m->jcode != NULL) {
1963                                                 if (!jit_compile(m)) {
1964                                                         fprintf(stderr, "Error compiling: ");
1965                                                         utf_fprint_printable_ascii_classname(stderr, c->name);
1966                                                         fprintf(stderr, ".");
1967                                                         utf_fprint_printable_ascii(stderr, m->name);
1968                                                         utf_fprint_printable_ascii(stderr, m->descriptor);
1969                                                         fprintf(stderr, "\n");
1970
1971                                                         /* print out exception and cause */
1972
1973                                                         exceptions_print_exception(*exceptionptr);
1974                                                 }
1975                                         }
1976                                 }
1977                         }
1978                 }
1979         }
1980 }
1981 #endif /* !defined(NDEBUG) */
1982
1983
1984 /* vm_compile_method ***********************************************************
1985
1986    Compile a specific method.
1987
1988 *******************************************************************************/
1989
1990 #if !defined(NDEBUG)
1991 static void vm_compile_method(void)
1992 {
1993         methodinfo *m;
1994
1995         /* create, load and link the main class */
1996
1997         if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1998                 throw_main_exception_exit();
1999
2000         if (!link_class(mainclass))
2001                 throw_main_exception_exit();
2002
2003         if (opt_signature != NULL) {
2004                 m = class_resolveclassmethod(mainclass,
2005                                                                          utf_new_char(opt_method),
2006                                                                          utf_new_char(opt_signature),
2007                                                                          mainclass,
2008                                                                          false);
2009         }
2010         else {
2011                 m = class_resolveclassmethod(mainclass,
2012                                                                          utf_new_char(opt_method),
2013                                                                          NULL,
2014                                                                          mainclass,
2015                                                                          false);
2016         }
2017
2018         if (m == NULL) {
2019                 char message[MAXLOGTEXT];
2020                 sprintf(message, "%s%s", opt_method,
2021                                 opt_signature ? opt_signature : "");
2022
2023                 *exceptionptr =
2024                         new_exception_message(string_java_lang_NoSuchMethodException,
2025                                                                   message);
2026                                                                                  
2027                 throw_main_exception_exit();
2028         }
2029                 
2030         jit_compile(m);
2031 }
2032 #endif /* !defined(NDEBUG) */
2033
2034
2035 /* vm_vmargs_from_valist *******************************************************
2036
2037    XXX
2038
2039 *******************************************************************************/
2040
2041 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2042                                                                   vm_arg *vmargs, va_list ap)
2043 {
2044         typedesc *paramtypes;
2045         s4        i;
2046
2047         paramtypes = m->parseddesc->paramtypes;
2048
2049         /* if method is non-static fill first block and skip `this' pointer */
2050
2051         i = 0;
2052
2053         if (o != NULL) {
2054                 /* the `this' pointer */
2055                 vmargs[0].type   = TYPE_ADR;
2056                 vmargs[0].data.l = (u8) (ptrint) o;
2057
2058                 paramtypes++;
2059                 i++;
2060         } 
2061
2062         for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2063                 switch (paramtypes->decltype) {
2064                 /* primitive types */
2065                 case PRIMITIVETYPE_BOOLEAN: 
2066                 case PRIMITIVETYPE_BYTE:
2067                 case PRIMITIVETYPE_CHAR:
2068                 case PRIMITIVETYPE_SHORT: 
2069                 case PRIMITIVETYPE_INT:
2070                         vmargs[i].type   = TYPE_INT;
2071                         vmargs[i].data.l = (s8) va_arg(ap, s4);
2072                         break;
2073
2074                 case PRIMITIVETYPE_LONG:
2075                         vmargs[i].type   = TYPE_LNG;
2076                         vmargs[i].data.l = (s8) va_arg(ap, s8);
2077                         break;
2078
2079                 case PRIMITIVETYPE_FLOAT:
2080                         vmargs[i].type   = TYPE_FLT;
2081 #if defined(__ALPHA__)
2082                         /* this keeps the assembler function much simpler */
2083
2084                         vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2085 #else
2086                         vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2087 #endif
2088                         break;
2089
2090                 case PRIMITIVETYPE_DOUBLE:
2091                         vmargs[i].type   = TYPE_DBL;
2092                         vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2093                         break;
2094
2095                 case TYPE_ADR: 
2096                         vmargs[i].type   = TYPE_ADR;
2097                         vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2098                         break;
2099                 }
2100         }
2101 }
2102
2103
2104 /* vm_vmargs_from_jvalue *******************************************************
2105
2106    XXX
2107
2108 *******************************************************************************/
2109
2110 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2111                                                                   vm_arg *vmargs, jvalue *args)
2112 {
2113         typedesc *paramtypes;
2114         s4        i;
2115         s4        j;
2116
2117         paramtypes = m->parseddesc->paramtypes;
2118
2119         /* if method is non-static fill first block and skip `this' pointer */
2120
2121         i = 0;
2122
2123         if (o != NULL) {
2124                 /* the `this' pointer */
2125                 vmargs[0].type   = TYPE_ADR;
2126                 vmargs[0].data.l = (u8) (ptrint) o;
2127
2128                 paramtypes++;
2129                 i++;
2130         } 
2131
2132         for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2133                 switch (paramtypes->decltype) {
2134                 /* primitive types */
2135                 case PRIMITIVETYPE_BOOLEAN: 
2136                 case PRIMITIVETYPE_BYTE:
2137                 case PRIMITIVETYPE_CHAR:
2138                 case PRIMITIVETYPE_SHORT: 
2139                 case PRIMITIVETYPE_INT:
2140                         vmargs[i].type   = TYPE_INT;
2141                         vmargs[i].data.l = (s8) args[j].i;
2142                         break;
2143
2144                 case PRIMITIVETYPE_LONG:
2145                         vmargs[i].type   = TYPE_LNG;
2146                         vmargs[i].data.l = (s8) args[j].j;
2147                         break;
2148
2149                 case PRIMITIVETYPE_FLOAT:
2150                         vmargs[i].type = TYPE_FLT;
2151 #if defined(__ALPHA__)
2152                         /* this keeps the assembler function much simpler */
2153
2154                         vmargs[i].data.d = (jdouble) args[j].f;
2155 #else
2156                         vmargs[i].data.f = args[j].f;
2157 #endif
2158                         break;
2159
2160                 case PRIMITIVETYPE_DOUBLE:
2161                         vmargs[i].type   = TYPE_DBL;
2162                         vmargs[i].data.d = args[j].d;
2163                         break;
2164
2165                 case TYPE_ADR: 
2166                         vmargs[i].type   = TYPE_ADR;
2167                         vmargs[i].data.l = (u8) (ptrint) args[j].l;
2168                         break;
2169                 }
2170         }
2171 }
2172
2173
2174 /* vm_call_method **************************************************************
2175
2176    Calls a Java method with a variable number of arguments and returns
2177    an address.
2178
2179 *******************************************************************************/
2180
2181 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2182 {
2183         va_list            ap;
2184         java_objectheader *ro;
2185
2186         va_start(ap, o);
2187         ro = vm_call_method_valist(m, o, ap);
2188         va_end(ap);
2189
2190         return ro;
2191 }
2192
2193
2194 /* vm_call_method_valist *******************************************************
2195
2196    Calls a Java method with a variable number of arguments, passed via
2197    a va_list, and returns an address.
2198
2199 *******************************************************************************/
2200
2201 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2202                                                                                  va_list ap)
2203 {
2204         s4                 vmargscount;
2205         vm_arg            *vmargs;
2206         java_objectheader *ro;
2207         s4                 dumpsize;
2208
2209         /* mark start of dump memory area */
2210
2211         dumpsize = dump_size();
2212
2213         /* get number of Java method arguments */
2214
2215         vmargscount = m->parseddesc->paramcount;
2216
2217         /* allocate vm_arg array */
2218
2219         vmargs = DMNEW(vm_arg, vmargscount);
2220
2221         /* fill the vm_arg array from a va_list */
2222
2223         vm_vmargs_from_valist(m, o, vmargs, ap);
2224
2225         /* call the Java method */
2226
2227         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2228
2229         /* release dump area */
2230
2231         dump_release(dumpsize);
2232
2233         return ro;
2234 }
2235
2236
2237 /* vm_call_method_jvalue *******************************************************
2238
2239    Calls a Java method with a variable number of arguments, passed via
2240    a jvalue array, and returns an address.
2241
2242 *******************************************************************************/
2243
2244 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2245                                                                                  jvalue *args)
2246 {
2247         s4                 vmargscount;
2248         vm_arg            *vmargs;
2249         java_objectheader *ro;
2250         s4                 dumpsize;
2251
2252         /* mark start of dump memory area */
2253
2254         dumpsize = dump_size();
2255
2256         /* get number of Java method arguments */
2257
2258         vmargscount = m->parseddesc->paramcount;
2259
2260         /* allocate vm_arg array */
2261
2262         vmargs = DMNEW(vm_arg, vmargscount);
2263
2264         /* fill the vm_arg array from a va_list */
2265
2266         vm_vmargs_from_jvalue(m, o, vmargs, args);
2267
2268         /* call the Java method */
2269
2270         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2271
2272         /* release dump area */
2273
2274         dump_release(dumpsize);
2275
2276         return ro;
2277 }
2278
2279
2280 /* vm_call_method_vmarg ********************************************************
2281
2282    Calls a Java method with a variable number of arguments, passed via
2283    a vm_arg array, and returns an address.
2284
2285 *******************************************************************************/
2286
2287 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2288                                                                                 vm_arg *vmargs)
2289 {
2290         java_objectheader *o;
2291
2292 #if defined(ENABLE_JIT)
2293 # if defined(ENABLE_INTRP)
2294         if (opt_intrp)
2295                 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2296         else
2297 # endif
2298                 o = asm_vm_call_method(m, vmargscount, vmargs);
2299 #else
2300         o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2301 #endif
2302
2303         return o;
2304 }
2305
2306
2307 /* vm_call_method_int **********************************************************
2308
2309    Calls a Java method with a variable number of arguments and returns
2310    an integer (s4).
2311
2312 *******************************************************************************/
2313
2314 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2315 {
2316         va_list ap;
2317         s4      i;
2318
2319         va_start(ap, o);
2320         i = vm_call_method_int_valist(m, o, ap);
2321         va_end(ap);
2322
2323         return i;
2324 }
2325
2326
2327 /* vm_call_method_int_valist ***************************************************
2328
2329    Calls a Java method with a variable number of arguments, passed via
2330    a va_list, and returns an integer (s4).
2331
2332 *******************************************************************************/
2333
2334 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2335 {
2336         s4      vmargscount;
2337         vm_arg *vmargs;
2338         s4      i;
2339         s4      dumpsize;
2340
2341         /* mark start of dump memory area */
2342
2343         dumpsize = dump_size();
2344
2345         /* get number of Java method arguments */
2346
2347         vmargscount = m->parseddesc->paramcount;
2348
2349         /* allocate vm_arg array */
2350
2351         vmargs = DMNEW(vm_arg, vmargscount);
2352
2353         /* fill the vm_arg array from a va_list */
2354
2355         vm_vmargs_from_valist(m, o, vmargs, ap);
2356
2357         /* call the Java method */
2358
2359         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2360
2361         /* release dump area */
2362
2363         dump_release(dumpsize);
2364
2365         return i;
2366 }
2367
2368
2369 /* vm_call_method_int_jvalue ***************************************************
2370
2371    Calls a Java method with a variable number of arguments, passed via
2372    a jvalue array, and returns an integer (s4).
2373
2374 *******************************************************************************/
2375
2376 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2377 {
2378         s4      vmargscount;
2379         vm_arg *vmargs;
2380         s4      i;
2381         s4      dumpsize;
2382
2383         /* mark start of dump memory area */
2384
2385         dumpsize = dump_size();
2386
2387         /* get number of Java method arguments */
2388
2389         vmargscount = m->parseddesc->paramcount;
2390
2391         /* allocate vm_arg array */
2392
2393         vmargs = DMNEW(vm_arg, vmargscount);
2394
2395         /* fill the vm_arg array from a va_list */
2396
2397         vm_vmargs_from_jvalue(m, o, vmargs, args);
2398
2399         /* call the Java method */
2400
2401         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2402
2403         /* release dump area */
2404
2405         dump_release(dumpsize);
2406
2407         return i;
2408 }
2409
2410
2411 /* vm_call_method_int_vmarg ****************************************************
2412
2413    Calls a Java method with a variable number of arguments, passed via
2414    a vm_arg array, and returns an integer (s4).
2415
2416 *******************************************************************************/
2417
2418 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2419 {
2420         s4 i;
2421
2422 #if defined(ENABLE_JIT)
2423 # if defined(ENABLE_INTRP)
2424         if (opt_intrp)
2425                 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2426         else
2427 # endif
2428                 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2429 #else
2430         i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2431 #endif
2432
2433         return i;
2434 }
2435
2436
2437 /* vm_call_method_long *********************************************************
2438
2439    Calls a Java method with a variable number of arguments and returns
2440    a long (s8).
2441
2442 *******************************************************************************/
2443
2444 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2445 {
2446         va_list ap;
2447         s8      l;
2448
2449         va_start(ap, o);
2450         l = vm_call_method_long_valist(m, o, ap);
2451         va_end(ap);
2452
2453         return l;
2454 }
2455
2456
2457 /* vm_call_method_long_valist **************************************************
2458
2459    Calls a Java method with a variable number of arguments, passed via
2460    a va_list, and returns a long (s8).
2461
2462 *******************************************************************************/
2463
2464 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2465 {
2466         s4      vmargscount;
2467         vm_arg *vmargs;
2468         s8      l;
2469         s4      dumpsize;
2470
2471         /* mark start of dump memory area */
2472
2473         dumpsize = dump_size();
2474
2475         /* get number of Java method arguments */
2476
2477         vmargscount = m->parseddesc->paramcount;
2478
2479         /* allocate vm_arg array */
2480
2481         vmargs = DMNEW(vm_arg, vmargscount);
2482
2483         /* fill the vm_arg array from a va_list */
2484
2485         vm_vmargs_from_valist(m, o, vmargs, ap);
2486
2487         /* call the Java method */
2488
2489         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2490
2491         /* release dump area */
2492
2493         dump_release(dumpsize);
2494
2495         return l;
2496 }
2497
2498
2499 /* vm_call_method_long_jvalue **************************************************
2500
2501    Calls a Java method with a variable number of arguments, passed via
2502    a jvalue array, and returns a long (s8).
2503
2504 *******************************************************************************/
2505
2506 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2507 {
2508         s4      vmargscount;
2509         vm_arg *vmargs;
2510         s8      l;
2511         s4      dumpsize;
2512
2513         /* mark start of dump memory area */
2514
2515         dumpsize = dump_size();
2516
2517         /* get number of Java method arguments */
2518
2519         vmargscount = m->parseddesc->paramcount;
2520
2521         /* allocate vm_arg array */
2522
2523         vmargs = DMNEW(vm_arg, vmargscount);
2524
2525         /* fill the vm_arg array from a va_list */
2526
2527         vm_vmargs_from_jvalue(m, o, vmargs, args);
2528
2529         /* call the Java method */
2530
2531         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2532
2533         /* release dump area */
2534
2535         dump_release(dumpsize);
2536
2537         return l;
2538 }
2539
2540
2541 /* vm_call_method_long_vmarg ***************************************************
2542
2543    Calls a Java method with a variable number of arguments, passed via
2544    a vm_arg array, and returns a long (s8).
2545
2546 *******************************************************************************/
2547
2548 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2549 {
2550         s8 l;
2551
2552 #if defined(ENABLE_JIT)
2553 # if defined(ENABLE_INTRP)
2554         if (opt_intrp)
2555                 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2556         else
2557 # endif
2558                 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2559 #else
2560         l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2561 #endif
2562
2563         return l;
2564 }
2565
2566
2567 /* vm_call_method_float ********************************************************
2568
2569    Calls a Java method with a variable number of arguments and returns
2570    an float.
2571
2572 *******************************************************************************/
2573
2574 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2575 {
2576         va_list ap;
2577         float   f;
2578
2579         va_start(ap, o);
2580         f = vm_call_method_float_valist(m, o, ap);
2581         va_end(ap);
2582
2583         return f;
2584 }
2585
2586
2587 /* vm_call_method_float_valist *************************************************
2588
2589    Calls a Java method with a variable number of arguments, passed via
2590    a va_list, and returns a float.
2591
2592 *******************************************************************************/
2593
2594 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2595                                                                   va_list ap)
2596 {
2597         s4      vmargscount;
2598         vm_arg *vmargs;
2599         float   f;
2600         s4      dumpsize;
2601
2602         /* mark start of dump memory area */
2603
2604         dumpsize = dump_size();
2605
2606         /* get number of Java method arguments */
2607
2608         vmargscount = m->parseddesc->paramcount;
2609
2610         /* allocate vm_arg array */
2611
2612         vmargs = DMNEW(vm_arg, vmargscount);
2613
2614         /* fill the vm_arg array from a va_list */
2615
2616         vm_vmargs_from_valist(m, o, vmargs, ap);
2617
2618         /* call the Java method */
2619
2620         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2621
2622         /* release dump area */
2623
2624         dump_release(dumpsize);
2625
2626         return f;
2627 }
2628
2629
2630 /* vm_call_method_float_jvalue *************************************************
2631
2632    Calls a Java method with a variable number of arguments, passed via
2633    a jvalue array, and returns a float.
2634
2635 *******************************************************************************/
2636
2637 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2638                                                                   jvalue *args)
2639 {
2640         s4      vmargscount;
2641         vm_arg *vmargs;
2642         float   f;
2643         s4      dumpsize;
2644
2645         /* mark start of dump memory area */
2646
2647         dumpsize = dump_size();
2648
2649         /* get number of Java method arguments */
2650
2651         vmargscount = m->parseddesc->paramcount;
2652
2653         /* allocate vm_arg array */
2654
2655         vmargs = DMNEW(vm_arg, vmargscount);
2656
2657         /* fill the vm_arg array from a va_list */
2658
2659         vm_vmargs_from_jvalue(m, o, vmargs, args);
2660
2661         /* call the Java method */
2662
2663         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2664
2665         /* release dump area */
2666
2667         dump_release(dumpsize);
2668
2669         return f;
2670 }
2671
2672
2673 /* vm_call_method_float_vmarg **************************************************
2674
2675    Calls a Java method with a variable number of arguments and returns
2676    an float.
2677
2678 *******************************************************************************/
2679
2680 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2681 {
2682         float f;
2683
2684 #if defined(ENABLE_JIT)
2685 # if defined(ENABLE_INTRP)
2686         if (opt_intrp)
2687                 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2688         else
2689 # endif
2690                 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2691 #else
2692         f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2693 #endif
2694
2695         return f;
2696 }
2697
2698
2699 /* vm_call_method_double *******************************************************
2700
2701    Calls a Java method with a variable number of arguments and returns
2702    a double.
2703
2704 *******************************************************************************/
2705
2706 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2707 {
2708         va_list ap;
2709         double  d;
2710
2711         va_start(ap, o);
2712         d = vm_call_method_double_valist(m, o, ap);
2713         va_end(ap);
2714
2715         return d;
2716 }
2717
2718
2719 /* vm_call_method_double_valist ************************************************
2720
2721    Calls a Java method with a variable number of arguments, passed via
2722    a va_list, and returns a double.
2723
2724 *******************************************************************************/
2725
2726 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2727                                                                         va_list ap)
2728 {
2729         s4      vmargscount;
2730         vm_arg *vmargs;
2731         double  d;
2732         s4      dumpsize;
2733
2734         /* mark start of dump memory area */
2735
2736         dumpsize = dump_size();
2737
2738         /* get number of Java method arguments */
2739
2740         vmargscount = m->parseddesc->paramcount;
2741
2742         /* allocate vm_arg array */
2743
2744         vmargs = DMNEW(vm_arg, vmargscount);
2745
2746         /* fill the vm_arg array from a va_list */
2747
2748         vm_vmargs_from_valist(m, o, vmargs, ap);
2749
2750         /* call the Java method */
2751
2752         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2753
2754         /* release dump area */
2755
2756         dump_release(dumpsize);
2757
2758         return d;
2759 }
2760
2761
2762 /* vm_call_method_double_jvalue ************************************************
2763
2764    Calls a Java method with a variable number of arguments, passed via
2765    a jvalue array, and returns a double.
2766
2767 *******************************************************************************/
2768
2769 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2770                                                                         jvalue *args)
2771 {
2772         s4      vmargscount;
2773         vm_arg *vmargs;
2774         double  d;
2775         s4      dumpsize;
2776
2777         /* mark start of dump memory area */
2778
2779         dumpsize = dump_size();
2780
2781         /* get number of Java method arguments */
2782
2783         vmargscount = m->parseddesc->paramcount;
2784
2785         /* allocate vm_arg array */
2786
2787         vmargs = DMNEW(vm_arg, vmargscount);
2788
2789         /* fill the vm_arg array from a va_list */
2790
2791         vm_vmargs_from_jvalue(m, o, vmargs, args);
2792
2793         /* call the Java method */
2794
2795         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2796
2797         /* release dump area */
2798
2799         dump_release(dumpsize);
2800
2801         return d;
2802 }
2803
2804
2805 /* vm_call_method_double_vmarg *************************************************
2806
2807    Calls a Java method with a variable number of arguments and returns
2808    a double.
2809
2810 *******************************************************************************/
2811
2812 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2813                                                                    vm_arg *vmargs)
2814 {
2815         double d;
2816
2817 #if defined(ENABLE_JIT)
2818 # if defined(ENABLE_INTRP)
2819         if (opt_intrp)
2820                 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2821         else
2822 # endif
2823                 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2824 #else
2825         d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2826 #endif
2827
2828         return d;
2829 }
2830
2831
2832 /*
2833  * These are local overrides for various environment variables in Emacs.
2834  * Please do not remove this and leave it at the end of the file, where
2835  * Emacs will automagically detect them.
2836  * ---------------------------------------------------------------------
2837  * Local variables:
2838  * mode: c
2839  * indent-tabs-mode: t
2840  * c-basic-offset: 4
2841  * tab-width: 4
2842  * End:
2843  */