* src/vm/vm.c (XXusage): Commented. We don't use it anymore but we
[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 8329 2007-08-16 17:57:27Z twisti $
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         if (!localref_table_init())
759                 goto error;
760 #endif
761
762         /* now return the values */
763
764         *p_vm  = (JavaVM *) vm;
765         *p_env = (void *) env;
766
767         return true;
768
769  error:
770         /* release allocated memory */
771
772         FREE(env, _Jv_JNIEnv);
773         FREE(vm, _Jv_JavaVM);
774
775         return false;
776 }
777
778
779 /* vm_create *******************************************************************
780
781    Creates a JVM.  Called by vm_createjvm.
782
783 *******************************************************************************/
784
785 bool vm_create(JavaVMInitArgs *vm_args)
786 {
787         char *cp;
788         s4    len;
789         s4    opt;
790         s4    i, j;
791         bool  opt_version;
792         bool  opt_exit;
793
794 #if defined(ENABLE_JVMTI)
795         lt_dlhandle  handle;
796         char *libname, *agentarg;
797         bool jdwp,agentbypath;
798         jdwp = agentbypath = false;
799 #endif
800
801 #if defined(ENABLE_VMLOG)
802         vmlog_cacao_init(vm_args);
803 #endif
804
805         /* check the JNI version requested */
806
807         switch (vm_args->version) {
808         case JNI_VERSION_1_1:
809                 break;
810         case JNI_VERSION_1_2:
811         case JNI_VERSION_1_4:
812                 break;
813         default:
814                 return false;
815         }
816
817         /* we only support 1 JVM instance */
818
819         if (vms > 0)
820                 return false;
821
822         if (atexit(vm_exit_handler))
823                 vm_abort("atexit failed: %s\n", strerror(errno));
824
825         if (opt_verbose)
826                 log_text("CACAO started -------------------------------------------------------");
827
828         /* We need to check if the actual size of a java.lang.Class object
829            is smaller or equal than the assumption made in
830            src/vmcore/class.h. */
831
832         if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
833                 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
834
835         /* set the VM starttime */
836
837         _Jv_jvm->starttime = builtin_currenttimemillis();
838
839         /* get stuff from the environment *****************************************/
840
841 #if defined(WITH_JRE_LAYOUT)
842         /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
843
844         cacao_prefix = MNEW(char, 4096);
845
846         if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
847                 vm_abort("readlink failed: %s\n", strerror(errno));
848
849         /* get the path of the current executable */
850
851         cacao_prefix = dirname(cacao_prefix);
852
853         if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
854                 vm_abort("libjvm name to long for buffer\n");
855
856         /* concatenate the library name */
857
858         strcat(cacao_prefix, "/..");
859
860         /* now set path to libjvm.so */
861
862         len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
863
864         cacao_libjvm = MNEW(char, len);
865         strcpy(cacao_libjvm, cacao_prefix);
866         strcat(cacao_libjvm, "/lib/libjvm");
867
868         /* and finally set the path to GNU Classpath libraries */
869
870         len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
871
872         classpath_libdir = MNEW(char, len);
873         strcpy(classpath_libdir, cacao_prefix);
874         strcat(classpath_libdir, "/lib/classpath");
875 #else
876         cacao_prefix     = CACAO_PREFIX;
877         cacao_libjvm     = CACAO_LIBDIR"/libjvm";
878
879 # if defined(WITH_CLASSPATH_GNU)
880         classpath_libdir = CLASSPATH_LIBDIR"/classpath";
881 # else
882         classpath_libdir = CLASSPATH_LIBDIR;
883 # endif
884 #endif
885
886         /* set the bootclasspath */
887
888         cp = getenv("BOOTCLASSPATH");
889
890         if (cp != NULL) {
891                 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
892                 strcpy(_Jv_bootclasspath, cp);
893         }
894         else {
895 #if defined(WITH_JRE_LAYOUT)
896                 len =
897 # if defined(WITH_CLASSPATH_GNU)
898                         strlen(cacao_prefix) +
899                         strlen("/share/cacao/vm.zip") +
900                         strlen(":") +
901 # endif
902                         strlen(cacao_prefix) +
903                         strlen("/share/classpath/glibj.zip") +
904                         strlen("0");
905
906                 _Jv_bootclasspath = MNEW(char, len);
907 # if defined(WITH_CLASSPATH_GNU)
908                 strcat(_Jv_bootclasspath, cacao_prefix);
909                 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
910                 strcat(_Jv_bootclasspath, ":");
911 # endif
912                 strcat(_Jv_bootclasspath, cacao_prefix);
913                 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
914 #else
915 # if defined(WITH_CLASSPATH_GNU)
916                 len =
917                         strlen(CACAO_VM_ZIP) +
918                         strlen(":") +
919                         strlen(CLASSPATH_CLASSES) +
920                         strlen("0");
921 # elif defined(WITH_CLASSPATH_SUN)
922                 /* This is the bootclasspath taken from HotSpot (see
923                    hotspot/src/share/vm/runtime/os.cpp
924                    (os::set_boot_path)). */
925
926                 len =
927                         strlen(CLASSPATH_PREFIX"/lib/resources.jar:"
928                                    CLASSPATH_PREFIX"/lib/rt.jar:"
929                                    CLASSPATH_PREFIX"/lib/sunrsasign.jar:"
930                                    CLASSPATH_PREFIX"/lib/jsse.jar:"
931                                    CLASSPATH_PREFIX"/lib/jce.jar:"
932                                    CLASSPATH_PREFIX"/lib/charsets.jar:"
933                                    CLASSPATH_PREFIX"/classes") +
934                         strlen("0");
935 # elif defined(WITH_CLASSPATH_CLDC1_1)
936                 len =
937                         strlen(CLASSPATH_CLASSES) +
938                         strlen("0");
939 # else
940 #  error unknown classpath configuration
941 # endif
942
943                 _Jv_bootclasspath = MNEW(char, len);
944
945 # if defined(WITH_CLASSPATH_GNU)
946                 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
947                 strcat(_Jv_bootclasspath, ":");
948                 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
949 # elif defined(WITH_CLASSPATH_SUN)
950                 strcpy(_Jv_bootclasspath,
951                            CLASSPATH_PREFIX"/lib/resources.jar:"
952                            CLASSPATH_PREFIX"/lib/rt.jar:"
953                            CLASSPATH_PREFIX"/lib/sunrsasign.jar:"
954                            CLASSPATH_PREFIX"/lib/jsse.jar:"
955                            CLASSPATH_PREFIX"/lib/jce.jar:"
956                            CLASSPATH_PREFIX"/lib/charsets.jar:"
957                            CLASSPATH_PREFIX"/classes");
958 # elif defined(WITH_CLASSPATH_CLDC1_1)
959                 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
960 # else
961 #  error unknown classpath configuration
962 # endif
963 #endif
964         }
965
966         /* set the classpath */
967
968         cp = getenv("CLASSPATH");
969
970         if (cp != NULL) {
971                 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
972                 strcat(_Jv_classpath, cp);
973         }
974         else {
975                 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
976                 strcpy(_Jv_classpath, ".");
977         }
978
979         /* Get and set java.library.path. */
980
981         _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
982
983         if (_Jv_java_library_path == NULL)
984                 _Jv_java_library_path = "";
985
986         /* interpret the options **************************************************/
987
988         opt_version       = false;
989         opt_exit          = false;
990
991         opt_noieee        = false;
992
993         opt_heapmaxsize   = HEAP_MAXSIZE;
994         opt_heapstartsize = HEAP_STARTSIZE;
995         opt_stacksize     = STACK_SIZE;
996
997
998 #if defined(ENABLE_JVMTI)
999         /* initialize JVMTI related  **********************************************/
1000         jvmti = false;
1001 #endif
1002
1003         /* Initialize and fill properties before command-line handling. */
1004
1005         if (!properties_init())
1006                 vm_abort("vm_create: properties_init failed");
1007
1008         /* Set the classpath properties. */
1009
1010 #if defined(ENABLE_JAVASE)
1011         properties_add("java.boot.class.path", _Jv_bootclasspath);
1012         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1013         properties_add("java.class.path", _Jv_classpath);
1014 #endif
1015
1016         /* iterate over all passed options */
1017
1018         while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
1019                 switch (opt) {
1020                 case OPT_FOO:
1021                         opt_foo = true;
1022                         break;
1023
1024                 case OPT_IGNORE:
1025                         break;
1026                         
1027                 case OPT_JAR:
1028                         opt_jar = true;
1029                         break;
1030
1031                 case OPT_D32:
1032 #if SIZEOF_VOID_P == 8
1033                         puts("Running a 32-bit JVM is not supported on this platform.");
1034                         exit(1);
1035 #endif
1036                         break;
1037
1038                 case OPT_D64:
1039 #if SIZEOF_VOID_P == 4
1040                         puts("Running a 64-bit JVM is not supported on this platform.");
1041                         exit(1);
1042 #endif
1043                         break;
1044
1045                 case OPT_CLASSPATH:
1046                         /* forget old classpath and set the argument as new classpath */
1047                         MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1048
1049                         _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
1050                         strcpy(_Jv_classpath, opt_arg);
1051
1052 #if defined(ENABLE_JAVASE)
1053                         properties_add("java.class.path", _Jv_classpath);
1054 #endif
1055                         break;
1056
1057                 case OPT_D:
1058                         for (i = 0; i < strlen(opt_arg); i++) {
1059                                 if (opt_arg[i] == '=') {
1060                                         opt_arg[i] = '\0';
1061                                         properties_add(opt_arg, opt_arg + i + 1);
1062                                         goto opt_d_done;
1063                                 }
1064                         }
1065
1066                         /* if no '=' is given, just create an empty property */
1067
1068                         properties_add(opt_arg, "");
1069
1070                 opt_d_done:
1071                         break;
1072
1073                 case OPT_BOOTCLASSPATH:
1074                         /* Forget default bootclasspath and set the argument as
1075                            new boot classpath. */
1076
1077                         MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1078
1079                         _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
1080                         strcpy(_Jv_bootclasspath, opt_arg);
1081
1082 #if defined(ENABLE_JAVASE)
1083                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1084                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1085 #endif
1086                         break;
1087
1088                 case OPT_BOOTCLASSPATH_A:
1089                         /* append to end of bootclasspath */
1090
1091                         len = strlen(_Jv_bootclasspath);
1092
1093                         _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1094                                                                                  char,
1095                                                                                  len + strlen("0"),
1096                                                                                  len + strlen(":") +
1097                                                                                  strlen(opt_arg) + strlen("0"));
1098
1099                         strcat(_Jv_bootclasspath, ":");
1100                         strcat(_Jv_bootclasspath, opt_arg);
1101
1102 #if defined(ENABLE_JAVASE)
1103                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1104                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1105 #endif
1106                         break;
1107
1108                 case OPT_BOOTCLASSPATH_P:
1109                         /* prepend in front of bootclasspath */
1110
1111                         cp = _Jv_bootclasspath;
1112                         len = strlen(cp);
1113
1114                         _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1115                                                                          len + strlen("0"));
1116
1117                         strcpy(_Jv_bootclasspath, opt_arg);
1118                         strcat(_Jv_bootclasspath, ":");
1119                         strcat(_Jv_bootclasspath, cp);
1120
1121                         MFREE(cp, char, len);
1122
1123 #if defined(ENABLE_JAVASE)
1124                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1125                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1126 #endif
1127                         break;
1128
1129                 case OPT_BOOTCLASSPATH_C:
1130                         /* use as Java core library, but prepend VM interface classes */
1131
1132                         MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1133
1134                         len = strlen(CACAO_VM_ZIP) +
1135                                 strlen(":") +
1136                                 strlen(opt_arg) +
1137                                 strlen("0");
1138
1139                         _Jv_bootclasspath = MNEW(char, len);
1140
1141                         strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1142                         strcat(_Jv_bootclasspath, ":");
1143                         strcat(_Jv_bootclasspath, opt_arg);
1144
1145 #if defined(ENABLE_JAVASE)
1146                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1147                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1148 #endif
1149                         break;
1150
1151 #if defined(ENABLE_JVMTI)
1152                 case OPT_DEBUG:
1153                         /* this option exists only for compatibility reasons */
1154                         break;
1155
1156                 case OPT_NOAGENT:
1157                         /* I don't know yet what Xnoagent should do. This is only for 
1158                            compatiblity with eclipse - motse */
1159                         break;
1160
1161                 case OPT_XRUNJDWP:
1162                         agentbypath = true;
1163                         jvmti       = true;
1164                         jdwp        = true;
1165
1166                         len =
1167                                 strlen(CACAO_LIBDIR) +
1168                                 strlen("/libjdwp.so=") +
1169                                 strlen(opt_arg) +
1170                                 strlen("0");
1171
1172                         agentarg = MNEW(char, len);
1173
1174                         strcpy(agentarg, CACAO_LIBDIR);
1175                         strcat(agentarg, "/libjdwp.so=");
1176                         strcat(agentarg, &opt_arg[1]);
1177                         break;
1178
1179                 case OPT_AGENTPATH:
1180                         agentbypath = true;
1181
1182                 case OPT_AGENTLIB:
1183                         jvmti = true;
1184                         agentarg = opt_arg;
1185                         break;
1186 #endif
1187                         
1188                 case OPT_MX:
1189                 case OPT_MS:
1190                 case OPT_SS:
1191                         {
1192                                 char c;
1193                                 c = opt_arg[strlen(opt_arg) - 1];
1194
1195                                 if ((c == 'k') || (c == 'K')) {
1196                                         j = atoi(opt_arg) * 1024;
1197
1198                                 } else if ((c == 'm') || (c == 'M')) {
1199                                         j = atoi(opt_arg) * 1024 * 1024;
1200
1201                                 } else
1202                                         j = atoi(opt_arg);
1203
1204                                 if (opt == OPT_MX)
1205                                         opt_heapmaxsize = j;
1206                                 else if (opt == OPT_MS)
1207                                         opt_heapstartsize = j;
1208                                 else
1209                                         opt_stacksize = j;
1210                         }
1211                         break;
1212
1213                 case OPT_VERBOSE1:
1214                         opt_verbose = true;
1215                         break;
1216
1217                 case OPT_VERBOSE:
1218                         if (strcmp("class", opt_arg) == 0) {
1219                                 opt_verboseclass = true;
1220                         }
1221                         else if (strcmp("gc", opt_arg) == 0) {
1222                                 opt_verbosegc = true;
1223                         }
1224                         else if (strcmp("jni", opt_arg) == 0) {
1225                                 opt_verbosejni = true;
1226                         }
1227 #if !defined(NDEBUG)
1228                         else if (strcmp("jit", opt_arg) == 0) {
1229                                 opt_verbose = true;
1230                                 loadverbose = true;
1231                                 initverbose = true;
1232                                 compileverbose = true;
1233                         }
1234                         else if (strcmp("threads", opt_arg) == 0) {
1235                                 opt_verbosethreads = true;
1236                         }
1237 #endif
1238                         else {
1239                                 printf("Unknown -verbose option: %s\n", opt_arg);
1240                                 usage();
1241                         }
1242                         break;
1243
1244                 case OPT_DEBUGCOLOR:
1245                         opt_debugcolor = true;
1246                         break;
1247
1248 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1249                 case OPT_VERBOSETC:
1250                         opt_typecheckverbose = true;
1251                         break;
1252 #endif
1253                                 
1254                 case OPT_VERSION:
1255                         opt_version = true;
1256                         opt_exit    = true;
1257                         break;
1258
1259                 case OPT_FULLVERSION:
1260                         fullversion();
1261                         break;
1262
1263                 case OPT_SHOWVERSION:
1264                         opt_version = true;
1265                         break;
1266
1267                 case OPT_NOIEEE:
1268                         opt_noieee = true;
1269                         break;
1270
1271 #if defined(ENABLE_VERIFIER)
1272                 case OPT_NOVERIFY:
1273                         opt_verify = false;
1274                         break;
1275 #endif
1276
1277 #if defined(ENABLE_STATISTICS)
1278                 case OPT_TIME:
1279                         opt_getcompilingtime = true;
1280                         opt_getloadingtime = true;
1281                         break;
1282                                         
1283                 case OPT_STAT:
1284                         opt_stat = true;
1285                         break;
1286 #endif
1287                                         
1288                 case OPT_LOG:
1289                         log_init(opt_arg);
1290                         break;
1291                         
1292                 case OPT_CHECK:
1293                         for (i = 0; i < strlen(opt_arg); i++) {
1294                                 switch (opt_arg[i]) {
1295                                 case 'b':
1296                                         checkbounds = false;
1297                                         break;
1298                                 case 's':
1299                                         checksync = false;
1300                                         break;
1301                                 default:
1302                                         usage();
1303                                 }
1304                         }
1305                         break;
1306                         
1307                 case OPT_LOAD:
1308                         opt_run = false;
1309                         makeinitializations = false;
1310                         break;
1311
1312 #if !defined(NDEBUG)
1313                 case OPT_ALL:
1314                         compileall = true;
1315                         opt_run = false;
1316                         makeinitializations = false;
1317                         break;
1318
1319                 case OPT_METHOD:
1320                         opt_run = false;
1321                         opt_method = opt_arg;
1322                         makeinitializations = false;
1323                         break;
1324
1325                 case OPT_SIGNATURE:
1326                         opt_signature = opt_arg;
1327                         break;
1328 #endif
1329
1330                 case OPT_SHOW:       /* Display options */
1331                         for (i = 0; i < strlen(opt_arg); i++) {         
1332                                 switch (opt_arg[i]) {
1333                                 case 'c':
1334                                         showconstantpool = true;
1335                                         break;
1336
1337                                 case 'u':
1338                                         showutf = true;
1339                                         break;
1340
1341                                 case 'm':
1342                                         showmethods = true;
1343                                         break;
1344
1345                                 case 'i':
1346                                         opt_showintermediate = true;
1347                                         compileverbose = true;
1348                                         break;
1349
1350 #if defined(ENABLE_DISASSEMBLER)
1351                                 case 'a':
1352                                         opt_showdisassemble = true;
1353                                         compileverbose = true;
1354                                         break;
1355
1356                                 case 'o':
1357                                         opt_shownops = true;
1358                                         break;
1359
1360                                 case 'e':
1361                                         opt_showexceptionstubs = true;
1362                                         break;
1363
1364                                 case 'n':
1365                                         opt_shownativestub = true;
1366                                         break;
1367 #endif
1368
1369                                 case 'd':
1370                                         opt_showddatasegment = true;
1371                                         break;
1372
1373                                 default:
1374                                         usage();
1375                                 }
1376                         }
1377                         break;
1378                         
1379 #if defined(ENABLE_LOOP)
1380                 case OPT_OLOOP:
1381                         opt_loops = true;
1382                         break;
1383 #endif
1384
1385 #if defined(ENABLE_INLINING)
1386 #if defined(ENABLE_INLINING_DEBUG)
1387                 case OPT_INLINE_DEBUG_ALL:
1388                         opt_inline_debug_all = true;
1389                         break;
1390                 case OPT_INLINE_DEBUG_END:
1391                         opt_inline_debug_end_counter = atoi(opt_arg);
1392                         break;
1393                 case OPT_INLINE_DEBUG_MIN:
1394                         opt_inline_debug_min_size = atoi(opt_arg);
1395                         break;
1396                 case OPT_INLINE_DEBUG_MAX:
1397                         opt_inline_debug_max_size = atoi(opt_arg);
1398                         break;
1399 #endif /* defined(ENABLE_INLINING_DEBUG) */
1400 #if !defined(NDEBUG)
1401                 case OPT_INLINE_LOG:
1402                         opt_inline_debug_log = true;
1403                         break;
1404 #endif /* !defined(NDEBUG) */
1405
1406                 case OPT_INLINING:
1407                         opt_inlining = true;
1408                         break;
1409 #endif /* defined(ENABLE_INLINING) */
1410
1411 #if defined(ENABLE_IFCONV)
1412                 case OPT_IFCONV:
1413                         opt_ifconv = true;
1414                         break;
1415 #endif
1416
1417 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1418                 case OPT_LSRA:
1419                         opt_lsra = true;
1420                         break;
1421 #endif
1422
1423                 case OPT_HELP:
1424                         usage();
1425                         break;
1426
1427                 case OPT_X:
1428                         Xusage();
1429                         break;
1430
1431                 case OPT_XX:
1432                         options_xx(opt_arg);
1433                         break;
1434
1435                 case OPT_EA:
1436                         /* currently ignored */
1437                         break;
1438
1439                 case OPT_DA:
1440                         /* currently ignored */
1441                         break;
1442
1443                 case OPT_ESA:
1444                         _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1445                         break;
1446
1447                 case OPT_DSA:
1448                         _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1449                         break;
1450
1451 #if defined(ENABLE_PROFILING)
1452                 case OPT_PROF_OPTION:
1453                         /* use <= to get the last \0 too */
1454
1455                         for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1456                                 if (opt_arg[i] == ',')
1457                                         opt_arg[i] = '\0';
1458
1459                                 if (opt_arg[i] == '\0') {
1460                                         if (strcmp("bb", opt_arg + j) == 0)
1461                                                 opt_prof_bb = true;
1462
1463                                         else {
1464                                                 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1465                                                 usage();
1466                                         }
1467
1468                                         /* set k to next char */
1469
1470                                         j = i + 1;
1471                                 }
1472                         }
1473                         /* fall through */
1474
1475                 case OPT_PROF:
1476                         opt_prof = true;
1477                         break;
1478 #endif
1479
1480                 case OPT_JIT:
1481 #if defined(ENABLE_JIT)
1482                         opt_jit = true;
1483 #else
1484                         printf("-Xjit option not enabled.\n");
1485                         exit(1);
1486 #endif
1487                         break;
1488
1489                 case OPT_INTRP:
1490 #if defined(ENABLE_INTRP)
1491                         opt_intrp = true;
1492 #else
1493                         printf("-Xint option not enabled.\n");
1494                         exit(1);
1495 #endif
1496                         break;
1497
1498 #if defined(ENABLE_INTRP)
1499                 case OPT_STATIC_SUPERS:
1500                         opt_static_supers = atoi(opt_arg);
1501                         break;
1502
1503                 case OPT_NO_DYNAMIC:
1504                         opt_no_dynamic = true;
1505                         break;
1506
1507                 case OPT_NO_REPLICATION:
1508                         opt_no_replication = true;
1509                         break;
1510
1511                 case OPT_NO_QUICKSUPER:
1512                         opt_no_quicksuper = true;
1513                         break;
1514
1515                 case OPT_TRACE:
1516                         vm_debug = true;
1517                         break;
1518 #endif
1519
1520 #if defined(ENABLE_DEBUG_FILTER)
1521                 case OPT_FILTER_VERBOSECALL_INCLUDE:
1522                         opt_filter_verbosecall_include = opt_arg;
1523                         break;
1524
1525                 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1526                         opt_filter_verbosecall_exclude = opt_arg;
1527                         break;
1528
1529                 case OPT_FILTER_SHOW_METHOD:
1530                         opt_filter_show_method = opt_arg;
1531                         break;
1532
1533 #endif
1534                 default:
1535                         printf("Unknown option: %s\n",
1536                                    vm_args->options[opt_index].optionString);
1537                         usage();
1538                 }
1539         }
1540
1541         /* get the main class *****************************************************/
1542
1543         if (opt_index < vm_args->nOptions) {
1544                 mainstring = vm_args->options[opt_index++].optionString;
1545
1546                 /* Put the jar file into the classpath (if any). */
1547
1548                 if (opt_jar == true) {
1549                         /* free old classpath */
1550
1551                         MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1552
1553                         /* put jarfile into classpath */
1554
1555                         _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1556
1557                         strcpy(_Jv_classpath, mainstring);
1558
1559 #if defined(ENABLE_JAVASE)
1560                         properties_add("java.class.path", _Jv_classpath);
1561 #endif
1562                 }
1563                 else {
1564                         /* replace .'s with /'s in classname */
1565
1566                         for (i = strlen(mainstring) - 1; i >= 0; i--)
1567                                 if (mainstring[i] == '.')
1568                                         mainstring[i] = '/';
1569                 }
1570         }
1571
1572 #if defined(ENABLE_JVMTI)
1573         if (jvmti) {
1574                 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1575                 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1576
1577                 if (jdwp)
1578                         MFREE(agentarg, char, strlen(agentarg));
1579
1580                 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1581         }
1582 #endif
1583
1584         /* initialize this JVM ****************************************************/
1585
1586         vm_initializing = true;
1587
1588         /* initialize the garbage collector */
1589
1590         gc_init(opt_heapmaxsize, opt_heapstartsize);
1591
1592 #if defined(ENABLE_THREADS)
1593         /* AFTER: gc_init (directly after, as this initializes the
1594            stopworldlock lock */
1595
1596         threads_preinit();
1597 #endif
1598
1599         /* install architecture dependent signal handlers */
1600
1601         if (!signal_init())
1602                 vm_abort("vm_create: signal_init failed");
1603
1604 #if defined(ENABLE_INTRP)
1605         /* Allocate main thread stack on the Java heap. */
1606
1607         if (opt_intrp) {
1608                 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1609                 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1610         }
1611 #endif
1612
1613         /* AFTER: threads_preinit */
1614
1615         if (!string_init())
1616                 vm_abort("vm_create: string_init failed");
1617
1618         /* AFTER: threads_preinit */
1619
1620         if (!utf8_init())
1621                 vm_abort("vm_create: utf8_init failed");
1622
1623         /* AFTER: thread_preinit */
1624
1625         if (!suck_init())
1626                 vm_abort("vm_create: suck_init failed");
1627
1628         suck_add_from_property("java.endorsed.dirs");
1629
1630         /* Now we have all options handled and we can print the version
1631            information.
1632
1633            AFTER: suck_add_from_property("java.endorsed.dirs"); */
1634
1635         if (opt_version)
1636                 version(opt_exit);
1637
1638         /* AFTER: utf8_init */
1639
1640         suck_add(_Jv_bootclasspath);
1641
1642         /* initialize the classcache hashtable stuff: lock, hashtable
1643            (must be done _after_ threads_preinit) */
1644
1645         if (!classcache_init())
1646                 vm_abort("vm_create: classcache_init failed");
1647
1648         /* initialize the memory subsystem (must be done _after_
1649            threads_preinit) */
1650
1651         if (!memory_init())
1652                 vm_abort("vm_create: memory_init failed");
1653
1654         /* initialize the finalizer stuff (must be done _after_
1655            threads_preinit) */
1656
1657         if (!finalizer_init())
1658                 vm_abort("vm_create: finalizer_init failed");
1659
1660         /* initialize the codegen subsystems */
1661
1662         codegen_init();
1663
1664         /* initializes jit compiler */
1665
1666         jit_init();
1667
1668         /* machine dependent initialization */
1669
1670 #if defined(ENABLE_JIT)
1671 # if defined(ENABLE_INTRP)
1672         if (opt_intrp)
1673                 intrp_md_init();
1674         else
1675 # endif
1676                 md_init();
1677 #else
1678         intrp_md_init();
1679 #endif
1680
1681         /* initialize the loader subsystems (must be done _after_
1682        classcache_init) */
1683
1684         if (!loader_init())
1685                 vm_abort("vm_create: loader_init failed");
1686
1687         /* Link some important VM classes. */
1688         /* AFTER: utf8_init */
1689
1690         if (!linker_init())
1691                 vm_abort("vm_create: linker_init failed");
1692
1693         if (!primitive_init())
1694                 vm_abort("vm_create: primitive_init failed");
1695
1696         if (!exceptions_init())
1697                 vm_abort("vm_create: exceptions_init failed");
1698
1699         if (!builtin_init())
1700                 vm_abort("vm_create: builtin_init failed");
1701
1702         /* Initialize the native subsystem. */
1703         /* BEFORE: threads_init */
1704
1705         if (!native_init())
1706                 vm_abort("vm_create: native_init failed");
1707
1708         /* Register the native methods implemented in the VM. */
1709         /* BEFORE: threads_init */
1710
1711         if (!nativevm_preinit())
1712                 vm_abort("vm_create: nativevm_preinit failed");
1713
1714 #if defined(ENABLE_JNI)
1715         /* Initialize the JNI subsystem (must be done _before_
1716            threads_init, as threads_init can call JNI methods
1717            (e.g. NewGlobalRef). */
1718
1719         if (!jni_init())
1720                 vm_abort("vm_create: jni_init failed");
1721 #endif
1722
1723 #if defined(ENABLE_THREADS)
1724         if (!threads_init())
1725                 vm_abort("vm_create: threads_init failed");
1726 #endif
1727
1728         /* Initialize the native VM subsystem. */
1729         /* AFTER: threads_init (at least for SUN's classes) */
1730
1731         if (!nativevm_init())
1732                 vm_abort("vm_create: nativevm_init failed");
1733
1734 #if defined(ENABLE_PROFILING)
1735         /* initialize profiling */
1736
1737         if (!profile_init())
1738                 vm_abort("vm_create: profile_init failed");
1739 #endif
1740
1741 #if defined(ENABLE_THREADS)
1742         /* initialize recompilation */
1743
1744         if (!recompile_init())
1745                 vm_abort("vm_create: recompile_init failed");
1746
1747         /* start the signal handler thread */
1748
1749 #if defined(__LINUX__)
1750         /* XXX Remove for exact-GC. */
1751         if (threads_pthreads_implementation_nptl)
1752 #endif
1753                 if (!signal_start_thread())
1754                         vm_abort("vm_create: signal_start_thread failed");
1755
1756         /* finally, start the finalizer thread */
1757
1758         if (!finalizer_start_thread())
1759                 vm_abort("vm_create: finalizer_start_thread failed");
1760
1761 # if !defined(NDEBUG)
1762         /* start the memory profiling thread */
1763
1764         if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1765                 if (!memory_start_thread())
1766                         vm_abort("vm_create: memory_start_thread failed");
1767 # endif
1768
1769         /* start the recompilation thread (must be done before the
1770            profiling thread) */
1771
1772         if (!recompile_start_thread())
1773                 vm_abort("vm_create: recompile_start_thread failed");
1774
1775 # if defined(ENABLE_PROFILING)
1776         /* start the profile sampling thread */
1777
1778 /*      if (opt_prof) */
1779 /*              if (!profile_start_thread()) */
1780 /*                      vm_abort("vm_create: profile_start_thread failed"); */
1781 # endif
1782 #endif
1783
1784 #if defined(ENABLE_JVMTI)
1785         if (jvmti) {
1786                 /* add agent library to native library hashtable */
1787                 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1788         }
1789 #endif
1790
1791         /* increment the number of VMs */
1792
1793         vms++;
1794
1795         /* initialization is done */
1796
1797         vm_initializing = false;
1798
1799         /* everything's ok */
1800
1801         return true;
1802 }
1803
1804
1805 /* vm_run **********************************************************************
1806
1807    Runs the main-method of the passed class.
1808
1809 *******************************************************************************/
1810
1811 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1812 {
1813         utf                       *mainutf;
1814         classinfo                 *mainclass;
1815         java_handle_t             *e;
1816         methodinfo                *m;
1817         java_handle_objectarray_t *oa; 
1818         s4                         oalength;
1819         utf                       *u;
1820         java_handle_t             *s;
1821         s4                         status;
1822         s4                         i;
1823
1824 #if !defined(NDEBUG)
1825         if (compileall) {
1826                 vm_compile_all();
1827                 return;
1828         }
1829
1830         if (opt_method != NULL) {
1831                 vm_compile_method();
1832                 return;
1833         }
1834 #endif /* !defined(NDEBUG) */
1835
1836         /* should we run the main-method? */
1837
1838         if (mainstring == NULL)
1839                 usage();
1840
1841         /* set return value to OK */
1842
1843         status = 0;
1844
1845         if (opt_jar == true) {
1846                 /* open jar file with java.util.jar.JarFile */
1847
1848                 mainstring = vm_get_mainclass_from_jar(mainstring);
1849
1850                 if (mainstring == NULL)
1851                         vm_exit(1);
1852         }
1853
1854         /* load the main class */
1855
1856         mainutf = utf_new_char(mainstring);
1857
1858 #if defined(ENABLE_JAVAME_CLDC1_1)
1859         mainclass = load_class_bootstrap(mainutf);
1860 #else
1861         mainclass = load_class_from_sysloader(mainutf);
1862 #endif
1863
1864         /* error loading class */
1865
1866         e = exceptions_get_and_clear_exception();
1867
1868         if ((e != NULL) || (mainclass == NULL)) {
1869                 exceptions_throw_noclassdeffounderror_cause(e);
1870                 exceptions_print_stacktrace(); 
1871                 vm_exit(1);
1872         }
1873
1874         if (!link_class(mainclass)) {
1875                 exceptions_print_stacktrace();
1876                 vm_exit(1);
1877         }
1878                         
1879         /* find the `main' method of the main class */
1880
1881         m = class_resolveclassmethod(mainclass,
1882                                                                  utf_new_char("main"), 
1883                                                                  utf_new_char("([Ljava/lang/String;)V"),
1884                                                                  class_java_lang_Object,
1885                                                                  false);
1886
1887         if (exceptions_get_exception()) {
1888                 exceptions_print_stacktrace();
1889                 vm_exit(1);
1890         }
1891
1892         /* there is no main method or it isn't static */
1893
1894         if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1895                 exceptions_clear_exception();
1896                 exceptions_throw_nosuchmethoderror(mainclass,
1897                                                                                    utf_new_char("main"), 
1898                                                                                    utf_new_char("([Ljava/lang/String;)V"));
1899
1900                 exceptions_print_stacktrace();
1901                 vm_exit(1);
1902         }
1903
1904         /* build argument array */
1905
1906         oalength = vm_args->nOptions - opt_index;
1907
1908         oa = builtin_anewarray(oalength, class_java_lang_String);
1909
1910         for (i = 0; i < oalength; i++) {
1911                 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1912                 s = javastring_new(u);
1913
1914                 LLNI_objectarray_element_set(oa, i, s);
1915         }
1916
1917 #ifdef TYPEINFO_DEBUG_TEST
1918         /* test the typeinfo system */
1919         typeinfo_test();
1920 #endif
1921         /*class_showmethods(currentThread->group->header.vftbl->class); */
1922
1923 #if defined(ENABLE_JVMTI)
1924         jvmti_set_phase(JVMTI_PHASE_LIVE);
1925 #endif
1926
1927         /* set ThreadMXBean variables */
1928
1929         _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1930         _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1931
1932         if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1933                 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1934                 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1935                         _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1936
1937         /* start the main thread */
1938
1939         (void) vm_call_method(m, NULL, oa);
1940
1941         /* exception occurred? */
1942
1943         if (exceptions_get_exception()) {
1944                 exceptions_print_stacktrace();
1945                 status = 1;
1946         }
1947
1948         /* unload the JavaVM */
1949
1950         (void) vm_destroy(vm);
1951
1952         /* and exit */
1953
1954         vm_exit(status);
1955 }
1956
1957
1958 /* vm_destroy ******************************************************************
1959
1960    Unloads a Java VM and reclaims its resources.
1961
1962 *******************************************************************************/
1963
1964 s4 vm_destroy(JavaVM *vm)
1965 {
1966 #if defined(ENABLE_THREADS)
1967         threads_join_all_threads();
1968 #endif
1969
1970         /* everything's ok */
1971
1972         return 0;
1973 }
1974
1975
1976 /* vm_exit *********************************************************************
1977
1978    Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1979
1980 *******************************************************************************/
1981
1982 void vm_exit(s4 status)
1983 {
1984         methodinfo *m;
1985
1986         /* signal that we are exiting */
1987
1988         vm_exiting = true;
1989
1990         assert(class_java_lang_System);
1991         assert(class_java_lang_System->state & CLASS_LOADED);
1992
1993 #if defined(ENABLE_JVMTI)
1994         if (jvmti || (dbgcom!=NULL)) {
1995                 jvmti_set_phase(JVMTI_PHASE_DEAD);
1996                 if (jvmti) jvmti_agentunload();
1997         }
1998 #endif
1999
2000         if (!link_class(class_java_lang_System)) {
2001                 exceptions_print_stacktrace();
2002                 exit(1);
2003         }
2004
2005         /* call java.lang.System.exit(I)V */
2006
2007         m = class_resolveclassmethod(class_java_lang_System,
2008                                                                  utf_new_char("exit"),
2009                                                                  utf_int__void,
2010                                                                  class_java_lang_Object,
2011                                                                  true);
2012         
2013         if (m == NULL) {
2014                 exceptions_print_stacktrace();
2015                 exit(1);
2016         }
2017
2018         /* call the exit function with passed exit status */
2019
2020         (void) vm_call_method(m, NULL, status);
2021
2022         /* If we had an exception, just ignore the exception and exit with
2023            the proper code. */
2024
2025         vm_shutdown(status);
2026 }
2027
2028
2029 /* vm_shutdown *****************************************************************
2030
2031    Terminates the system immediately without freeing memory explicitly
2032    (to be used only for abnormal termination).
2033         
2034 *******************************************************************************/
2035
2036 void vm_shutdown(s4 status)
2037 {
2038         if (opt_verbose 
2039 #if defined(ENABLE_STATISTICS)
2040                 || opt_getcompilingtime || opt_stat
2041 #endif
2042            ) 
2043         {
2044                 log_text("CACAO terminated by shutdown");
2045                 dolog("Exit status: %d\n", (s4) status);
2046
2047         }
2048
2049 #if defined(ENABLE_JVMTI)
2050         /* terminate cacaodbgserver */
2051         if (dbgcom!=NULL) {
2052                 pthread_mutex_lock(&dbgcomlock);
2053                 dbgcom->running=1;
2054                 pthread_mutex_unlock(&dbgcomlock);
2055                 jvmti_cacaodbgserver_quit();
2056         }       
2057 #endif
2058
2059         exit(status);
2060 }
2061
2062
2063 /* vm_exit_handler *************************************************************
2064
2065    The exit_handler function is called upon program termination.
2066
2067    ATTENTION: Don't free system resources here! Some threads may still
2068    be running as this is called from VMRuntime.exit(). The OS does the
2069    cleanup for us.
2070
2071 *******************************************************************************/
2072
2073 void vm_exit_handler(void)
2074 {
2075 #if !defined(NDEBUG)
2076         if (showmethods)
2077                 class_showmethods(mainclass);
2078
2079         if (showconstantpool)
2080                 class_showconstantpool(mainclass);
2081
2082         if (showutf)
2083                 utf_show();
2084
2085 # if defined(ENABLE_PROFILING)
2086         if (opt_prof)
2087                 profile_printstats();
2088 # endif
2089 #endif /* !defined(NDEBUG) */
2090
2091 #if defined(ENABLE_RT_TIMING)
2092         rt_timing_print_time_stats(stderr);
2093 #endif
2094
2095 #if defined(ENABLE_CYCLES_STATS)
2096         builtin_print_cycles_stats(stderr);
2097         stacktrace_print_cycles_stats(stderr);
2098 #endif
2099
2100         if (opt_verbose 
2101 #if defined(ENABLE_STATISTICS)
2102                 || opt_getcompilingtime || opt_stat
2103 #endif
2104            ) 
2105         {
2106                 log_text("CACAO terminated");
2107
2108 #if defined(ENABLE_STATISTICS)
2109                 if (opt_stat) {
2110                         print_stats();
2111 #ifdef TYPECHECK_STATISTICS
2112                         typecheck_print_statistics(get_logfile());
2113 #endif
2114                 }
2115
2116                 if (opt_getcompilingtime)
2117                         print_times();
2118 #endif /* defined(ENABLE_STATISTICS) */
2119         }
2120         /* vm_print_profile(stderr);*/
2121 }
2122
2123
2124 /* vm_abort ********************************************************************
2125
2126    Prints an error message and aborts the VM.
2127
2128 *******************************************************************************/
2129
2130 void vm_abort(const char *text, ...)
2131 {
2132         va_list ap;
2133
2134         /* print the log message */
2135
2136         log_start();
2137
2138         va_start(ap, text);
2139         log_vprint(text, ap);
2140         va_end(ap);
2141
2142         log_finish();
2143
2144         /* now abort the VM */
2145
2146         abort();
2147 }
2148
2149
2150 /* vm_get_mainclass_from_jar ***************************************************
2151
2152    Gets the name of the main class from a JAR's manifest file.
2153
2154 *******************************************************************************/
2155
2156 static char *vm_get_mainclass_from_jar(char *mainstring)
2157 {
2158         classinfo     *c;
2159         java_handle_t *o;
2160         methodinfo    *m;
2161         java_handle_t *s;
2162
2163         c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2164
2165         if (c == NULL) {
2166                 exceptions_print_stacktrace();
2167                 return NULL;
2168         }
2169
2170         /* create JarFile object */
2171
2172         o = builtin_new(c);
2173
2174         if (o == NULL) {
2175                 exceptions_print_stacktrace();
2176                 return NULL;
2177         }
2178
2179         m = class_resolveclassmethod(c,
2180                                                                  utf_init, 
2181                                                                  utf_java_lang_String__void,
2182                                                                  class_java_lang_Object,
2183                                                                  true);
2184
2185         if (m == NULL) {
2186                 exceptions_print_stacktrace();
2187                 return NULL;
2188         }
2189
2190         s = javastring_new_from_ascii(mainstring);
2191
2192         (void) vm_call_method(m, o, s);
2193
2194         if (exceptions_get_exception()) {
2195                 exceptions_print_stacktrace();
2196                 return NULL;
2197         }
2198
2199         /* get manifest object */
2200
2201         m = class_resolveclassmethod(c,
2202                                                                  utf_new_char("getManifest"), 
2203                                                                  utf_new_char("()Ljava/util/jar/Manifest;"),
2204                                                                  class_java_lang_Object,
2205                                                                  true);
2206
2207         if (m == NULL) {
2208                 exceptions_print_stacktrace();
2209                 return NULL;
2210         }
2211
2212         o = vm_call_method(m, o);
2213
2214         if (o == NULL) {
2215                 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2216                 return NULL;
2217         }
2218
2219
2220         /* get Main Attributes */
2221
2222         m = class_resolveclassmethod(o->vftbl->class,
2223                                                                  utf_new_char("getMainAttributes"), 
2224                                                                  utf_new_char("()Ljava/util/jar/Attributes;"),
2225                                                                  class_java_lang_Object,
2226                                                                  true);
2227
2228         if (m == NULL) {
2229                 exceptions_print_stacktrace();
2230                 return NULL;
2231         }
2232
2233         o = vm_call_method(m, o);
2234
2235         if (o == NULL) {
2236                 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2237                 return NULL;
2238         }
2239
2240
2241         /* get property Main-Class */
2242
2243         m = class_resolveclassmethod(o->vftbl->class,
2244                                                                  utf_new_char("getValue"), 
2245                                                                  utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2246                                                                  class_java_lang_Object,
2247                                                                  true);
2248
2249         if (m == NULL) {
2250                 exceptions_print_stacktrace();
2251                 return NULL;
2252         }
2253
2254         s = javastring_new_from_ascii("Main-Class");
2255
2256         o = vm_call_method(m, o, s);
2257
2258         if (o == NULL) {
2259                 exceptions_print_stacktrace();
2260                 return NULL;
2261         }
2262
2263         return javastring_tochar(o);
2264 }
2265
2266
2267 /* vm_compile_all **************************************************************
2268
2269    Compile all methods found in the bootclasspath.
2270
2271 *******************************************************************************/
2272
2273 #if !defined(NDEBUG)
2274 static void vm_compile_all(void)
2275 {
2276         classinfo              *c;
2277         methodinfo             *m;
2278         u4                      slot;
2279         classcache_name_entry  *nmen;
2280         classcache_class_entry *clsen;
2281         s4                      i;
2282
2283         /* create all classes found in the bootclasspath */
2284         /* XXX currently only works with zip/jar's */
2285
2286         loader_load_all_classes();
2287
2288         /* link all classes */
2289
2290         for (slot = 0; slot < hashtable_classcache.size; slot++) {
2291                 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2292
2293                 for (; nmen; nmen = nmen->hashlink) {
2294                         /* iterate over all class entries */
2295
2296                         for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2297                                 c = clsen->classobj;
2298
2299                                 if (c == NULL)
2300                                         continue;
2301
2302                                 if (!(c->state & CLASS_LINKED)) {
2303                                         if (!link_class(c)) {
2304                                                 fprintf(stderr, "Error linking: ");
2305                                                 utf_fprint_printable_ascii_classname(stderr, c->name);
2306                                                 fprintf(stderr, "\n");
2307
2308                                                 /* print out exception and cause */
2309
2310                                                 exceptions_print_current_exception();
2311
2312                                                 /* goto next class */
2313
2314                                                 continue;
2315                                         }
2316                                 }
2317
2318                                 /* compile all class methods */
2319
2320                                 for (i = 0; i < c->methodscount; i++) {
2321                                         m = &(c->methods[i]);
2322
2323                                         if (m->jcode != NULL) {
2324                                                 if (!jit_compile(m)) {
2325                                                         fprintf(stderr, "Error compiling: ");
2326                                                         utf_fprint_printable_ascii_classname(stderr, c->name);
2327                                                         fprintf(stderr, ".");
2328                                                         utf_fprint_printable_ascii(stderr, m->name);
2329                                                         utf_fprint_printable_ascii(stderr, m->descriptor);
2330                                                         fprintf(stderr, "\n");
2331
2332                                                         /* print out exception and cause */
2333
2334                                                         exceptions_print_current_exception();
2335                                                 }
2336                                         }
2337                                 }
2338                         }
2339                 }
2340         }
2341 }
2342 #endif /* !defined(NDEBUG) */
2343
2344
2345 /* vm_compile_method ***********************************************************
2346
2347    Compile a specific method.
2348
2349 *******************************************************************************/
2350
2351 #if !defined(NDEBUG)
2352 static void vm_compile_method(void)
2353 {
2354         methodinfo *m;
2355
2356         /* create, load and link the main class */
2357
2358         mainclass = load_class_bootstrap(utf_new_char(mainstring));
2359
2360         if (mainclass == NULL)
2361                 exceptions_print_stacktrace();
2362
2363         if (!link_class(mainclass))
2364                 exceptions_print_stacktrace();
2365
2366         if (opt_signature != NULL) {
2367                 m = class_resolveclassmethod(mainclass,
2368                                                                          utf_new_char(opt_method),
2369                                                                          utf_new_char(opt_signature),
2370                                                                          mainclass,
2371                                                                          false);
2372         }
2373         else {
2374                 m = class_resolveclassmethod(mainclass,
2375                                                                          utf_new_char(opt_method),
2376                                                                          NULL,
2377                                                                          mainclass,
2378                                                                          false);
2379         }
2380
2381         if (m == NULL)
2382                 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2383                                  opt_method, opt_signature ? opt_signature : "");
2384                 
2385         jit_compile(m);
2386 }
2387 #endif /* !defined(NDEBUG) */
2388
2389
2390 /* vm_array_store_int **********************************************************
2391
2392    Helper function to store an integer into the argument array, taking
2393    care of architecture specific issues.
2394
2395 *******************************************************************************/
2396
2397 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2398 {
2399         int32_t index;
2400
2401         if (!pd->inmemory) {
2402                 index        = pd->index;
2403                 array[index] = (int64_t) value;
2404         }
2405         else {
2406                 index        = ARG_CNT + pd->index;
2407 #if SIZEOF_VOID_P == 8
2408                 array[index] = (int64_t) value;
2409 #else
2410 # if WORDS_BIGENDIAN == 1
2411                 array[index] = ((int64_t) value) << 32;
2412 # else
2413                 array[index] = (int64_t) value;
2414 # endif
2415 #endif
2416         }
2417 }
2418
2419
2420 /* vm_array_store_lng **********************************************************
2421
2422    Helper function to store a long into the argument array, taking
2423    care of architecture specific issues.
2424
2425 *******************************************************************************/
2426
2427 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2428 {
2429         int32_t index;
2430
2431 #if SIZEOF_VOID_P == 8
2432         if (!pd->inmemory)
2433                 index = pd->index;
2434         else
2435                 index = ARG_CNT + pd->index;
2436
2437         array[index] = value;
2438 #else
2439         if (!pd->inmemory) {
2440                 /* move low and high 32-bits into it's own argument slot */
2441
2442                 index        = GET_LOW_REG(pd->index);
2443                 array[index] = value & 0x00000000ffffffff;
2444
2445                 index        = GET_HIGH_REG(pd->index);
2446                 array[index] = value >> 32;
2447         }
2448         else {
2449                 index        = ARG_CNT + pd->index;
2450                 array[index] = value;
2451         }
2452 #endif
2453 }
2454
2455
2456 /* vm_array_store_flt **********************************************************
2457
2458    Helper function to store a float into the argument array, taking
2459    care of architecture specific issues.
2460
2461 *******************************************************************************/
2462
2463 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2464 {
2465         int32_t index;
2466
2467         if (!pd->inmemory) {
2468 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2469                 index        = pd->index;
2470 #else
2471                 index        = INT_ARG_CNT + pd->index;
2472 #endif
2473 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
2474                 array[index] = value >> 32;
2475 #else
2476                 array[index] = value;
2477 #endif
2478         }
2479         else {
2480                 index        = ARG_CNT + pd->index;
2481 #if defined(__SPARC_64__)
2482                 array[index] = value >> 32;
2483 #else
2484                 array[index] = value;
2485 #endif
2486         }
2487 }
2488
2489
2490 /* vm_array_store_dbl **********************************************************
2491
2492    Helper function to store a double into the argument array, taking
2493    care of architecture specific issues.
2494
2495 *******************************************************************************/
2496
2497 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2498 {
2499         int32_t index;
2500
2501         if (!pd->inmemory) {
2502 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2503                 index        = GET_LOW_REG(pd->index);
2504                 array[index] = value & 0x00000000ffffffff;
2505
2506                 index        = GET_HIGH_REG(pd->index);
2507                 array[index] = value >> 32;
2508 #else
2509                 index        = INT_ARG_CNT + pd->index;
2510                 array[index] = value;
2511 #endif
2512         }
2513         else {
2514                 index        = ARG_CNT + pd->index;
2515                 array[index] = value;
2516         }
2517 }
2518
2519
2520 /* vm_array_store_adr **********************************************************
2521
2522    Helper function to store an address into the argument array, taking
2523    care of architecture specific issues.
2524
2525 *******************************************************************************/
2526
2527 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2528 {
2529         int32_t index;
2530
2531         if (!pd->inmemory) {
2532 #if defined(HAS_ADDRESS_REGISTER_FILE)
2533                 /* When the architecture has address registers, place them
2534                    after integer and float registers. */
2535
2536                 index        = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2537 #else
2538                 index        = pd->index;
2539 #endif
2540                 array[index] = (uint64_t) (intptr_t) value;
2541         }
2542         else {
2543                 index        = ARG_CNT + pd->index;
2544 #if SIZEOF_VOID_P == 8
2545                 array[index] = (uint64_t) (intptr_t) value;
2546 #else
2547 # if WORDS_BIGENDIAN == 1
2548                 array[index] = ((uint64_t) (intptr_t) value) << 32;
2549 # else
2550                 array[index] = (uint64_t) (intptr_t) value;
2551 # endif
2552 #endif
2553         }
2554 }
2555
2556
2557 /* vm_array_from_valist ********************************************************
2558
2559    XXX
2560
2561 *******************************************************************************/
2562
2563 uint64_t *vm_array_from_valist(methodinfo *m, java_object_t *o, va_list ap)
2564 {
2565         methoddesc *md;
2566         paramdesc  *pd;
2567         typedesc   *td;
2568         uint64_t   *array;
2569         int32_t     i;
2570         imm_union   value;
2571
2572         /* get the descriptors */
2573
2574         md = m->parseddesc;
2575         pd = md->params;
2576         td = md->paramtypes;
2577
2578         /* allocate argument array */
2579
2580         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2581
2582         /* if method is non-static fill first block and skip `this' pointer */
2583
2584         i = 0;
2585
2586         if (o != NULL) {
2587                 /* the `this' pointer */
2588                 vm_array_store_adr(array, pd, o);
2589
2590                 pd++;
2591                 td++;
2592                 i++;
2593         } 
2594
2595         for (; i < md->paramcount; i++, pd++, td++) {
2596                 switch (td->type) {
2597                 case TYPE_INT:
2598                         value.i = va_arg(ap, int32_t);
2599                         vm_array_store_int(array, pd, value.i);
2600                         break;
2601
2602                 case TYPE_LNG:
2603                         value.l = va_arg(ap, int64_t);
2604                         vm_array_store_lng(array, pd, value.l);
2605                         break;
2606
2607                 case TYPE_FLT:
2608 #if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__)
2609                         /* This is required to load the correct float value in
2610                            assembler code. */
2611
2612                         value.d = (double) va_arg(ap, double);
2613 #else
2614                         value.f = (float) va_arg(ap, double);
2615 #endif
2616                         vm_array_store_flt(array, pd, value.l);
2617                         break;
2618
2619                 case TYPE_DBL:
2620                         value.d = va_arg(ap, double);
2621                         vm_array_store_dbl(array, pd, value.l);
2622                         break;
2623
2624                 case TYPE_ADR: 
2625                         value.a = va_arg(ap, void*);
2626                         vm_array_store_adr(array, pd, value.a);
2627                         break;
2628                 }
2629         }
2630
2631         return array;
2632 }
2633
2634
2635 /* vm_array_from_jvalue ********************************************************
2636
2637    XXX
2638
2639 *******************************************************************************/
2640
2641 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_object_t *o,
2642                                                                           const jvalue *args)
2643 {
2644         methoddesc *md;
2645         paramdesc  *pd;
2646         typedesc   *td;
2647         uint64_t   *array;
2648         int32_t     i;
2649         int32_t     j;
2650
2651         /* get the descriptors */
2652
2653         md = m->parseddesc;
2654         pd = md->params;
2655         td = md->paramtypes;
2656
2657         /* allocate argument array */
2658
2659 #if defined(HAS_ADDRESS_REGISTER_FILE)
2660         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2661 #else
2662         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2663 #endif
2664
2665         /* if method is non-static fill first block and skip `this' pointer */
2666
2667         i = 0;
2668
2669         if (o != NULL) {
2670                 /* the `this' pointer */
2671                 vm_array_store_adr(array, pd, o);
2672
2673                 pd++;
2674                 td++;
2675                 i++;
2676         } 
2677
2678         for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2679                 switch (td->decltype) {
2680                 case TYPE_INT:
2681                         vm_array_store_int(array, pd, args[j].i);
2682                         break;
2683
2684                 case TYPE_LNG:
2685                         vm_array_store_lng(array, pd, args[j].j);
2686                         break;
2687
2688                 case TYPE_FLT:
2689                         vm_array_store_flt(array, pd, args[j].j);
2690                         break;
2691
2692                 case TYPE_DBL:
2693                         vm_array_store_dbl(array, pd, args[j].j);
2694                         break;
2695
2696                 case TYPE_ADR: 
2697                         vm_array_store_adr(array, pd, args[j].l);
2698                         break;
2699                 }
2700         }
2701
2702         return array;
2703 }
2704
2705
2706 /* vm_array_from_objectarray ***************************************************
2707
2708    XXX
2709
2710 *******************************************************************************/
2711
2712 uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
2713                                                                         java_handle_objectarray_t *params)
2714 {
2715         methoddesc    *md;
2716         paramdesc     *pd;
2717         typedesc      *td;
2718         uint64_t      *array;
2719         java_handle_t *param;
2720         classinfo     *c;
2721         int            type;
2722         int32_t        i;
2723         int32_t        j;
2724         imm_union      value;
2725
2726         /* get the descriptors */
2727
2728         md = m->parseddesc;
2729         pd = md->params;
2730         td = md->paramtypes;
2731
2732         /* allocate argument array */
2733
2734         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2735
2736         /* if method is non-static fill first block and skip `this' pointer */
2737
2738         i = 0;
2739
2740         if (o != NULL) {
2741                 /* this pointer */
2742                 vm_array_store_adr(array, pd, o);
2743
2744                 pd++;
2745                 td++;
2746                 i++;
2747         }
2748
2749         for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2750                 LLNI_objectarray_element_get(params, j, param);
2751
2752                 switch (td->type) {
2753                 case TYPE_INT:
2754                         if (param == NULL)
2755                                 goto illegal_arg;
2756
2757                         /* convert the value according to its declared type */
2758
2759                         c    = param->vftbl->class;
2760                         type = primitive_type_get_by_wrapperclass(c);
2761
2762                         switch (td->decltype) {
2763                         case PRIMITIVETYPE_BOOLEAN:
2764                                 switch (type) {
2765                                 case PRIMITIVETYPE_BOOLEAN:
2766                                         /* This type is OK. */
2767                                         break;
2768                                 default:
2769                                         goto illegal_arg;
2770                                 }
2771                                 break;
2772
2773                         case PRIMITIVETYPE_BYTE:
2774                                 switch (type) {
2775                                 case PRIMITIVETYPE_BYTE:
2776                                         /* This type is OK. */
2777                                         break;
2778                                 default:
2779                                         goto illegal_arg;
2780                                 }
2781                                 break;
2782
2783                         case PRIMITIVETYPE_CHAR:
2784                                 switch (type) {
2785                                 case PRIMITIVETYPE_CHAR:
2786                                         /* This type is OK. */
2787                                         break;
2788                                 default:
2789                                         goto illegal_arg;
2790                                 }
2791                                 break;
2792
2793                         case PRIMITIVETYPE_SHORT:
2794                                 switch (type) {
2795                                 case PRIMITIVETYPE_BYTE:
2796                                 case PRIMITIVETYPE_SHORT:
2797                                         /* These types are OK. */
2798                                         break;
2799                                 default:
2800                                         goto illegal_arg;
2801                                 }
2802                                 break;
2803
2804                         case PRIMITIVETYPE_INT:
2805                                 switch (type) {
2806                                 case PRIMITIVETYPE_BYTE:
2807                                 case PRIMITIVETYPE_SHORT:
2808                                 case PRIMITIVETYPE_INT:
2809                                         /* These types are OK. */
2810                                         break;
2811                                 default:
2812                                         goto illegal_arg;
2813                                 }
2814                                 break;
2815
2816                         default:
2817                                 vm_abort("vm_array_from_objectarray: invalid type %d",
2818                                                  td->decltype);
2819                         }
2820
2821                         value = primitive_unbox(param);
2822                         vm_array_store_int(array, pd, value.i);
2823                         break;
2824
2825                 case TYPE_LNG:
2826                         if (param == NULL)
2827                                 goto illegal_arg;
2828
2829                         c    = param->vftbl->class;
2830                         type = primitive_type_get_by_wrapperclass(c);
2831
2832                         assert(td->decltype == PRIMITIVETYPE_LONG);
2833
2834                         switch (type) {
2835                         case PRIMITIVETYPE_BYTE:
2836                         case PRIMITIVETYPE_SHORT:
2837                         case PRIMITIVETYPE_INT:
2838                         case PRIMITIVETYPE_LONG:
2839                                 /* These types are OK. */
2840                                 break;
2841                         default:
2842                                 goto illegal_arg;
2843                         }
2844
2845                         value = primitive_unbox(param);
2846                         vm_array_store_lng(array, pd, value.l);
2847                         break;
2848
2849                 case TYPE_FLT:
2850                         if (param == NULL)
2851                                 goto illegal_arg;
2852
2853                         c    = param->vftbl->class;
2854                         type = primitive_type_get_by_wrapperclass(c);
2855
2856                         assert(td->decltype == PRIMITIVETYPE_FLOAT);
2857
2858                         switch (type) {
2859                         case PRIMITIVETYPE_FLOAT:
2860                                 /* This type is OK. */
2861                                 break;
2862                         default:
2863                                 goto illegal_arg;
2864                         }
2865
2866                         value = primitive_unbox(param);
2867                         vm_array_store_flt(array, pd, value.l);
2868                         break;
2869
2870                 case TYPE_DBL:
2871                         if (param == NULL)
2872                                 goto illegal_arg;
2873
2874                         c    = param->vftbl->class;
2875                         type = primitive_type_get_by_wrapperclass(c);
2876
2877                         assert(td->decltype == PRIMITIVETYPE_DOUBLE);
2878
2879                         switch (type) {
2880                         case PRIMITIVETYPE_FLOAT:
2881                         case PRIMITIVETYPE_DOUBLE:
2882                                 /* These types are OK. */
2883                                 break;
2884                         default:
2885                                 goto illegal_arg;
2886                         }
2887
2888                         value = primitive_unbox(param);
2889                         vm_array_store_dbl(array, pd, value.l);
2890                         break;
2891                 
2892                 case TYPE_ADR:
2893                         if (!resolve_class_from_typedesc(td, true, true, &c))
2894                                 return false;
2895
2896                         if (param != NULL) {
2897                                 if (td->arraydim > 0) {
2898                                         if (!builtin_arrayinstanceof(param, c))
2899                                                 goto illegal_arg;
2900                                 }
2901                                 else {
2902                                         if (!builtin_instanceof(param, c))
2903                                                 goto illegal_arg;
2904                                 }
2905                         }
2906
2907                         vm_array_store_adr(array, pd, param);
2908                         break;
2909
2910                 default:
2911                         vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
2912                 }
2913         }
2914
2915         return array;
2916
2917 illegal_arg:
2918         exceptions_throw_illegalargumentexception();
2919         return NULL;
2920 }
2921
2922
2923 /* vm_call_method **************************************************************
2924
2925    Calls a Java method with a variable number of arguments.
2926
2927 *******************************************************************************/
2928
2929 #define VM_CALL_METHOD(name, type)                                  \
2930 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...)     \
2931 {                                                                   \
2932         va_list ap;                                                     \
2933         type    value;                                                  \
2934                                                                     \
2935         va_start(ap, o);                                                \
2936         value = vm_call_method##name##_valist(m, o, ap);                \
2937         va_end(ap);                                                     \
2938                                                                     \
2939         return value;                                                   \
2940 }
2941
2942 VM_CALL_METHOD(,        java_handle_t *)
2943 VM_CALL_METHOD(_int,    int32_t)
2944 VM_CALL_METHOD(_long,   int64_t)
2945 VM_CALL_METHOD(_float,  float)
2946 VM_CALL_METHOD(_double, double)
2947
2948
2949 /* vm_call_method_valist *******************************************************
2950
2951    Calls a Java method with a variable number of arguments, passed via
2952    a va_list.
2953
2954 *******************************************************************************/
2955
2956 #define VM_CALL_METHOD_VALIST(name, type)                               \
2957 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o,     \
2958                                                                    va_list ap)                          \
2959 {                                                                       \
2960         int32_t   dumpsize;                                                 \
2961         uint64_t *array;                                                    \
2962         type      value;                                                    \
2963                                                                         \
2964         dumpsize = dump_size();                                             \
2965         array = vm_array_from_valist(m, o, ap);                             \
2966         value = vm_call##name##_array(m, array);                            \
2967         dump_release(dumpsize);                                             \
2968                                                                         \
2969         return value;                                                       \
2970 }
2971
2972 VM_CALL_METHOD_VALIST(,        java_handle_t *)
2973 VM_CALL_METHOD_VALIST(_int,    int32_t)
2974 VM_CALL_METHOD_VALIST(_long,   int64_t)
2975 VM_CALL_METHOD_VALIST(_float,  float)
2976 VM_CALL_METHOD_VALIST(_double, double)
2977
2978
2979 /* vm_call_method_jvalue *******************************************************
2980
2981    Calls a Java method with a variable number of arguments, passed via
2982    a jvalue array.
2983
2984 *******************************************************************************/
2985
2986 #define VM_CALL_METHOD_JVALUE(name, type)                               \
2987 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o,     \
2988                                                            const jvalue *args)                  \
2989 {                                                                       \
2990         int32_t   dumpsize;                                                 \
2991         uint64_t *array;                                                    \
2992         type      value;                                                    \
2993                                                                         \
2994         dumpsize = dump_size();                                             \
2995         array = vm_array_from_jvalue(m, o, args);                           \
2996         value = vm_call##name##_array(m, array);                            \
2997         dump_release(dumpsize);                                             \
2998                                                                         \
2999         return value;                                                       \
3000 }
3001
3002 VM_CALL_METHOD_JVALUE(,        java_handle_t *)
3003 VM_CALL_METHOD_JVALUE(_int,    int32_t)
3004 VM_CALL_METHOD_JVALUE(_long,   int64_t)
3005 VM_CALL_METHOD_JVALUE(_float,  float)
3006 VM_CALL_METHOD_JVALUE(_double, double)
3007
3008
3009 /* vm_call_array ***************************************************************
3010
3011    Calls a Java method with a variable number of arguments, passed via
3012    an argument array.
3013
3014 *******************************************************************************/
3015
3016 #define VM_CALL_ARRAY(name, type)                            \
3017 type vm_call##name##_array(methodinfo *m, uint64_t *array)   \
3018 {                                                            \
3019         methoddesc *md;                                          \
3020         void       *pv;                                          \
3021         type        value;                                       \
3022                                                              \
3023         md = m->parseddesc;                                      \
3024                                                              \
3025         if (m->code == NULL)                                     \
3026                 if (!jit_compile(m))                                 \
3027                         return 0;                                        \
3028                                                              \
3029     pv = m->code->entrypoint;                                \
3030                                                              \
3031         STATISTICS(count_calls_native_to_java++);                \
3032                                                              \
3033         value = asm_vm_call_method##name(pv, array, md->memuse); \
3034                                                              \
3035         return value;                                            \
3036 }
3037
3038 VM_CALL_ARRAY(,        java_handle_t *)
3039 VM_CALL_ARRAY(_int,    int32_t)
3040 VM_CALL_ARRAY(_long,   int64_t)
3041 VM_CALL_ARRAY(_float,  float)
3042 VM_CALL_ARRAY(_double, double)
3043
3044
3045 /*
3046  * These are local overrides for various environment variables in Emacs.
3047  * Please do not remove this and leave it at the end of the file, where
3048  * Emacs will automagically detect them.
3049  * ---------------------------------------------------------------------
3050  * Local variables:
3051  * mode: c
3052  * indent-tabs-mode: t
3053  * c-basic-offset: 4
3054  * tab-width: 4
3055  * End:
3056  */