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