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