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