* src/vm/vm.c (version): Removed configuration output.
[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 8236 2007-07-27 10:18:17Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <errno.h>
34 #include <stdint.h>
35 #include <stdlib.h>
36
37 #if defined(WITH_JRE_LAYOUT)
38 # include <libgen.h>
39 # include <unistd.h>
40 #endif
41
42 #include "vm/types.h"
43
44 #include "arch.h"
45 #include "md-abi.h"
46
47 #include "vm/jit/abi-asm.h"
48
49 #include "mm/gc-common.h"
50 #include "mm/memory.h"
51
52 #include "native/jni.h"
53 #include "native/native.h"
54
55 #include "native/include/java_lang_Object.h"             /* required by j.l.C */
56 #include "native/include/java_lang_String.h"             /* required by j.l.C */
57
58 #if defined(WITH_CLASSPATH_SUN)
59 # include "native/include/java_nio_ByteBuffer.h"        /* required by j.l.CL */
60 # include "native/include/java_lang_ClassLoader.h"       /* required by j.l.C */
61 #endif
62
63 #include "native/include/java_lang_Class.h"
64
65 #include "native/include/java_lang_Byte.h"
66 #include "native/include/java_lang_Character.h"
67 #include "native/include/java_lang_Short.h"
68 #include "native/include/java_lang_Integer.h"
69 #include "native/include/java_lang_Boolean.h"
70 #include "native/include/java_lang_Long.h"
71 #include "native/include/java_lang_Float.h"
72 #include "native/include/java_lang_Double.h"
73
74 #include "native/vm/nativevm.h"
75
76 #include "threads/threads-common.h"
77
78 #include "toolbox/logging.h"
79
80 #include "vm/builtin.h"
81 #include "vm/exceptions.h"
82 #include "vm/finalizer.h"
83 #include "vm/global.h"
84 #include "vm/initialize.h"
85 #include "vm/properties.h"
86 #include "vm/signallocal.h"
87 #include "vm/stringlocal.h"
88 #include "vm/vm.h"
89
90 #include "vm/jit/jit.h"
91 #include "vm/jit/md.h"
92 #include "vm/jit/asmpart.h"
93
94 #if defined(ENABLE_PROFILING)
95 # include "vm/jit/optimizing/profile.h"
96 #endif
97
98 #include "vm/jit/optimizing/recompile.h"
99
100 #include "vmcore/classcache.h"
101 #include "vmcore/options.h"
102 #include "vmcore/primitive.h"
103 #include "vmcore/statistics.h"
104 #include "vmcore/suck.h"
105
106 #if defined(ENABLE_JVMTI)
107 # include "native/jvmti/cacaodbg.h"
108 #endif
109
110 #if defined(ENABLE_VMLOG)
111 #include <vmlog_cacao.h>
112 #endif
113
114
115 /* Invocation API variables ***************************************************/
116
117 _Jv_JavaVM *_Jv_jvm;                    /* denotes a Java VM                  */
118 _Jv_JNIEnv *_Jv_env;                    /* pointer to native method interface */
119
120
121 /* global variables ***********************************************************/
122
123 s4 vms = 0;                             /* number of VMs created              */
124
125 bool vm_initializing = false;
126 bool vm_exiting = false;
127
128 char      *cacao_prefix = NULL;
129 char      *cacao_libjvm = NULL;
130 char      *classpath_libdir = NULL;
131
132 char      *_Jv_bootclasspath;           /* contains the boot classpath        */
133 char      *_Jv_classpath;               /* contains the classpath             */
134 char      *_Jv_java_library_path;
135
136 char      *mainstring = NULL;
137 classinfo *mainclass = NULL;
138
139 char *specificmethodname = NULL;
140 char *specificsignature = NULL;
141
142 bool startit = true;
143
144 #if defined(ENABLE_INTRP)
145 u1 *intrp_main_stack = NULL;
146 #endif
147
148
149 /* define heap sizes **********************************************************/
150
151 #define HEAP_MAXSIZE      128 * 1024 * 1024 /* default 128MB                  */
152 #define HEAP_STARTSIZE      2 * 1024 * 1024 /* default 2MB                    */
153 #define STACK_SIZE                64 * 1024 /* default 64kB                   */
154
155
156 /* define command line options ************************************************/
157
158 enum {
159         OPT_FOO,
160
161         /* Java options */
162
163         OPT_JAR,
164
165         OPT_D32,
166         OPT_D64,
167
168         OPT_CLASSPATH,
169         OPT_D,
170
171         OPT_VERBOSE,
172
173         OPT_VERSION,
174         OPT_SHOWVERSION,
175         OPT_FULLVERSION,
176
177         OPT_HELP,
178         OPT_X,
179         OPT_XX,
180
181         OPT_EA,
182         OPT_DA,
183
184         OPT_ESA,
185         OPT_DSA,
186
187         /* Java non-standard options */
188
189         OPT_JIT,
190         OPT_INTRP,
191
192         OPT_BOOTCLASSPATH,
193         OPT_BOOTCLASSPATH_A,
194         OPT_BOOTCLASSPATH_P,
195
196         OPT_BOOTCLASSPATH_C,
197
198 #if defined(ENABLE_PROFILING)
199         OPT_PROF,
200         OPT_PROF_OPTION,
201 #endif
202
203         OPT_MS,
204         OPT_MX,
205
206         /* CACAO options */
207
208         OPT_VERBOSE1,
209         OPT_NOIEEE,
210
211 #if defined(ENABLE_STATISTICS)
212         OPT_TIME,
213         OPT_STAT,
214 #endif
215
216         OPT_LOG,
217         OPT_CHECK,
218         OPT_LOAD,
219         OPT_SHOW,
220         OPT_DEBUGCOLOR,
221
222 #if !defined(NDEBUG)
223         OPT_ALL,
224         OPT_METHOD,
225         OPT_SIGNATURE,
226 #endif
227
228 #if defined(ENABLE_VERIFIER)
229         OPT_NOVERIFY,
230 #if defined(TYPECHECK_VERBOSE)
231         OPT_VERBOSETC,
232 #endif
233 #endif /* defined(ENABLE_VERIFIER) */
234
235         /* optimization options */
236
237 #if defined(ENABLE_LOOP)
238         OPT_OLOOP,
239 #endif
240         
241 #if defined(ENABLE_IFCONV)
242         OPT_IFCONV,
243 #endif
244
245 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
246         OPT_LSRA,
247 #endif
248
249 #if defined(ENABLE_INLINING)
250         OPT_INLINING,
251 #if !defined(NDEBUG)
252         OPT_INLINE_LOG,
253 #endif
254 #if defined(ENABLE_INLINING_DEBUG)
255         OPT_INLINE_DEBUG_ALL,
256         OPT_INLINE_DEBUG_END,
257         OPT_INLINE_DEBUG_MIN,
258         OPT_INLINE_DEBUG_MAX,
259 #endif /* defined(ENABLE_INLINING_DEBUG) */
260 #endif /* defined(ENABLE_INLINING) */
261
262 #if defined(ENABLE_INTRP)
263         /* interpreter options */
264
265         OPT_NO_DYNAMIC,
266         OPT_NO_REPLICATION,
267         OPT_NO_QUICKSUPER,
268         OPT_STATIC_SUPERS,
269         OPT_TRACE,
270 #endif
271
272         OPT_SS,
273
274 #ifdef ENABLE_JVMTI
275         OPT_DEBUG,
276         OPT_XRUNJDWP,
277         OPT_NOAGENT,
278         OPT_AGENTLIB,
279         OPT_AGENTPATH,
280 #endif
281
282 #if defined(ENABLE_DEBUG_FILTER)
283         OPT_FILTER_VERBOSECALL_INCLUDE,
284         OPT_FILTER_VERBOSECALL_EXCLUDE,
285         OPT_FILTER_SHOW_METHOD,
286 #endif
287
288         DUMMY
289 };
290
291
292 opt_struct opts[] = {
293         { "foo",               false, OPT_FOO },
294
295         /* Java options */
296
297         { "jar",               false, OPT_JAR },
298
299         { "d32",               false, OPT_D32 },
300         { "d64",               false, OPT_D64 },
301         { "client",            false, OPT_IGNORE },
302         { "server",            false, OPT_IGNORE },
303         { "jvm",               false, OPT_IGNORE },
304         { "hotspot",           false, OPT_IGNORE },
305
306         { "classpath",         true,  OPT_CLASSPATH },
307         { "cp",                true,  OPT_CLASSPATH },
308         { "D",                 true,  OPT_D },
309         { "version",           false, OPT_VERSION },
310         { "showversion",       false, OPT_SHOWVERSION },
311         { "fullversion",       false, OPT_FULLVERSION },
312         { "help",              false, OPT_HELP },
313         { "?",                 false, OPT_HELP },
314         { "X",                 false, OPT_X },
315         { "XX:",               true,  OPT_XX },
316         { "XX",                false, OPT_XX },
317
318         { "ea:",               true,  OPT_EA },
319         { "da:",               true,  OPT_DA },
320         { "ea",                false, OPT_EA },
321         { "da",                false, OPT_DA },
322
323         { "esa",                     false, OPT_ESA },
324         { "enablesystemassertions",  false, OPT_ESA },
325         { "dsa",                     false, OPT_DSA },
326         { "disablesystemassertions", false, OPT_DSA },
327
328         { "noasyncgc",         false, OPT_IGNORE },
329 #if defined(ENABLE_VERIFIER)
330         { "noverify",          false, OPT_NOVERIFY },
331 #endif
332         { "v",                 false, OPT_VERBOSE1 },
333         { "verbose:",          true,  OPT_VERBOSE },
334
335 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
336         { "verbosetc",         false, OPT_VERBOSETC },
337 #endif
338 #if defined(__ALPHA__)
339         { "noieee",            false, OPT_NOIEEE },
340 #endif
341 #if defined(ENABLE_STATISTICS)
342         { "time",              false, OPT_TIME },
343         { "stat",              false, OPT_STAT },
344 #endif
345         { "log",               true,  OPT_LOG },
346         { "c",                 true,  OPT_CHECK },
347         { "l",                 false, OPT_LOAD },
348
349 #if !defined(NDEBUG)
350         { "all",               false, OPT_ALL },
351         { "sig",               true,  OPT_SIGNATURE },
352 #endif
353
354 #if defined(ENABLE_LOOP)
355         { "oloop",             false, OPT_OLOOP },
356 #endif
357 #if defined(ENABLE_IFCONV)
358         { "ifconv",            false, OPT_IFCONV },
359 #endif
360 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
361         { "lsra",              false, OPT_LSRA },
362 #endif
363
364 #if defined(ENABLE_INTRP)
365         /* interpreter options */
366
367         { "trace",             false, OPT_TRACE },
368         { "static-supers",     true,  OPT_STATIC_SUPERS },
369         { "no-dynamic",        false, OPT_NO_DYNAMIC },
370         { "no-replication",    false, OPT_NO_REPLICATION },
371         { "no-quicksuper",     false, OPT_NO_QUICKSUPER },
372 #endif
373
374         /* JVMTI Agent Command Line Options */
375 #ifdef ENABLE_JVMTI
376         { "agentlib:",         true,  OPT_AGENTLIB },
377         { "agentpath:",        true,  OPT_AGENTPATH },
378 #endif
379
380         /* Java non-standard options */
381
382         { "Xjit",              false, OPT_JIT },
383         { "Xint",              false, OPT_INTRP },
384         { "Xbootclasspath:",   true,  OPT_BOOTCLASSPATH },
385         { "Xbootclasspath/a:", true,  OPT_BOOTCLASSPATH_A },
386         { "Xbootclasspath/p:", true,  OPT_BOOTCLASSPATH_P },
387         { "Xbootclasspath/c:", true,  OPT_BOOTCLASSPATH_C },
388
389 #ifdef ENABLE_JVMTI
390         { "Xdebug",            false, OPT_DEBUG },
391         { "Xnoagent",          false, OPT_NOAGENT },
392         { "Xrunjdwp",          true,  OPT_XRUNJDWP },
393 #endif 
394
395         { "Xms",               true,  OPT_MS },
396         { "ms",                true,  OPT_MS },
397         { "Xmx",               true,  OPT_MX },
398         { "mx",                true,  OPT_MX },
399         { "Xss",               true,  OPT_SS },
400         { "ss",                true,  OPT_SS },
401
402 #if defined(ENABLE_PROFILING)
403         { "Xprof:",            true,  OPT_PROF_OPTION },
404         { "Xprof",             false, OPT_PROF },
405 #endif
406
407         /* inlining options */
408
409 #if defined(ENABLE_INLINING)
410 #if defined(ENABLE_INLINING_DEBUG)
411         { "ia",                false, OPT_INLINE_DEBUG_ALL },
412         { "ii",                true,  OPT_INLINE_DEBUG_MIN },
413         { "im",                true,  OPT_INLINE_DEBUG_MAX },
414         { "ie",                true,  OPT_INLINE_DEBUG_END },
415 #endif /* defined(ENABLE_INLINING_DEBUG) */
416 #if !defined(NDEBUG)
417         { "il",                false, OPT_INLINE_LOG },
418 #endif
419         { "i",                 false, OPT_INLINING },
420 #endif /* defined(ENABLE_INLINING) */
421
422         /* keep these at the end of the list */
423
424 #if !defined(NDEBUG)
425         { "m",                 true,  OPT_METHOD },
426 #endif
427
428         { "s",                 true,  OPT_SHOW },
429         { "debug-color",      false,  OPT_DEBUGCOLOR },
430
431 #if defined(ENABLE_DEBUG_FILTER)
432         { "XXfi",              true,  OPT_FILTER_VERBOSECALL_INCLUDE },
433         { "XXfx",              true,  OPT_FILTER_VERBOSECALL_EXCLUDE },
434         { "XXfm",              true,  OPT_FILTER_SHOW_METHOD },
435 #endif
436
437         { NULL,                false, 0 }
438 };
439
440
441 /* usage ***********************************************************************
442
443    Prints the correct usage syntax to stdout.
444
445 *******************************************************************************/
446
447 void usage(void)
448 {
449         puts("Usage: cacao [-options] classname [arguments]");
450         puts("               (to run a class file)");
451         puts("   or  cacao [-options] -jar jarfile [arguments]");
452         puts("               (to run a standalone jar file)\n");
453
454         puts("where options include:");
455         puts("    -d32                     use 32-bit data model if available");
456         puts("    -d64                     use 64-bit data model if available");
457         puts("    -client                  compatibility (currently ignored)");
458         puts("    -server                  compatibility (currently ignored)");
459         puts("    -jvm                     compatibility (currently ignored)");
460         puts("    -hotspot                 compatibility (currently ignored)\n");
461
462         puts("    -cp <path>               specify a path to look for classes");
463         puts("    -classpath <path>        specify a path to look for classes");
464         puts("    -D<name>=<value>         add an entry to the property list");
465         puts("    -verbose[:class|gc|jni]  enable specific verbose output");
466         puts("    -version                 print product version and exit");
467         puts("    -fullversion             print jpackage-compatible product version and exit");
468         puts("    -showversion             print product version and continue");
469         puts("    -help, -?                print this help message");
470         puts("    -X                       print help on non-standard Java options");
471         puts("    -XX                      print help on debugging options");
472     puts("    -ea[:<packagename>...|:<classname>]");
473     puts("    -enableassertions[:<packagename>...|:<classname>]");
474         puts("                             enable assertions with specified granularity");
475         puts("    -da[:<packagename>...|:<classname>]");
476         puts("    -disableassertions[:<packagename>...|:<classname>]");
477         puts("                             disable assertions with specified granularity");
478         puts("    -esa | -enablesystemassertions");
479         puts("                             enable system assertions");
480         puts("    -dsa | -disablesystemassertions");
481         puts("                             disable system assertions");
482
483 #ifdef ENABLE_JVMTI
484         puts("    -agentlib:<agent-lib-name>=<options>  library to load containg JVMTI agent");
485         puts ("                                         for jdwp help use: -agentlib:jdwp=help");
486         puts("    -agentpath:<path-to-agent>=<options>  path to library containg JVMTI agent");
487 #endif
488
489         /* exit with error code */
490
491         exit(1);
492 }   
493
494
495 static void Xusage(void)
496 {
497 #if defined(ENABLE_JIT)
498         puts("    -Xjit                    JIT mode execution (default)");
499 #endif
500 #if defined(ENABLE_INTRP)
501         puts("    -Xint                    interpreter mode execution");
502 #endif
503         puts("    -Xbootclasspath:<zip/jar files and directories separated by :>");
504     puts("                             value is set as bootstrap class path");
505         puts("    -Xbootclasspath/a:<zip/jar files and directories separated by :>");
506         puts("                             value is appended to the bootstrap class path");
507         puts("    -Xbootclasspath/p:<zip/jar files and directories separated by :>");
508         puts("                             value is prepended to the bootstrap class path");
509         puts("    -Xbootclasspath/c:<zip/jar files and directories separated by :>");
510         puts("                             value is used as Java core library, but the");
511         puts("                             hardcoded VM interface classes are prepended");
512         printf("    -Xms<size>               set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
513         printf("    -Xmx<size>               set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
514         printf("    -Xss<size>               set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
515
516 #if defined(ENABLE_PROFILING)
517         puts("    -Xprof[:bb]              collect and print profiling data");
518 #endif
519
520 #if defined(ENABLE_JVMTI)
521     /* -Xdebug option depend on gnu classpath JDWP options. options: 
522          transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
523         puts("    -Xdebug                  enable remote debugging\n");
524         puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
525         puts("                             enable remote debugging\n");
526 #endif 
527
528         /* exit with error code */
529
530         exit(1);
531 }   
532
533
534 static void XXusage(void)
535 {
536         puts("    -v                       write state-information");
537 #if !defined(NDEBUG)
538         puts("    -verbose[:jit|threads]");
539         puts("                             enable specific verbose output");
540         puts("    -debug-color             colored output for ANSI terms");
541 #endif
542 #ifdef TYPECHECK_VERBOSE
543         puts("    -verbosetc               write debug messages while typechecking");
544 #endif
545 #if defined(__ALPHA__)
546         puts("    -noieee                  don't use ieee compliant arithmetic");
547 #endif
548 #if defined(ENABLE_VERIFIER)
549         puts("    -noverify                don't verify classfiles");
550 #endif
551 #if defined(ENABLE_STATISTICS)
552         puts("    -time                    measure the runtime");
553         puts("    -stat                    detailed compiler statistics");
554 #endif
555         puts("    -log logfile             specify a name for the logfile");
556         puts("    -c(heck)b(ounds)         don't check array bounds");
557         puts("            s(ync)           don't check for synchronization");
558 #if defined(ENABLE_LOOP)
559         puts("    -oloop                   optimize array accesses in loops");
560 #endif
561         puts("    -l                       don't start the class after loading");
562 #if !defined(NDEBUG)
563         puts("    -all                     compile all methods, no execution");
564         puts("    -m                       compile only a specific method");
565         puts("    -sig                     specify signature for a specific method");
566 #endif
567
568         puts("    -s...                    show...");
569         puts("      (c)onstants            the constant pool");
570         puts("      (m)ethods              class fields and methods");
571         puts("      (u)tf                  the utf - hash");
572         puts("      (i)ntermediate         intermediate representation");
573 #if defined(ENABLE_DISASSEMBLER)
574         puts("      (a)ssembler            disassembled listing");
575         puts("      n(o)ps                 show NOPs in disassembler output");
576         puts("      (e)xceptionstubs       disassembled exception stubs (only with -sa)");
577         puts("      (n)ative               disassembled native stubs");
578 #endif
579         puts("      (d)atasegment          data segment listing");
580
581 #if defined(ENABLE_INLINING)
582         puts("    -i                       activate inlining");
583 #if !defined(NDEBUG)
584         puts("    -il                      log inlining");
585 #endif
586 #if defined(ENABLE_INLINING_DEBUG)
587         puts("    -ia                      use inlining for all methods");
588         puts("    -ii <size>               set minimum size for inlined result");
589         puts("    -im <size>               set maximum size for inlined result");
590         puts("    -ie <number>             stop inlining after the given number of roots");
591 #endif /* defined(ENABLE_INLINING_DEBUG) */
592 #endif /* defined(ENABLE_INLINING) */
593
594 #if defined(ENABLE_IFCONV)
595         puts("    -ifconv                  use if-conversion");
596 #endif
597 #if defined(ENABLE_LSRA)
598         puts("    -lsra                    use linear scan register allocation");
599 #endif
600 #if defined(ENABLE_SSA)
601         puts("    -lsra                    use linear scan register allocation (with SSA)");
602 #endif
603 #if defined(ENABLE_DEBUG_FILTER)
604         puts("    -XXfi <regex>            begin of dynamic scope for verbosecall filter");
605         puts("    -XXfx <regex>            end of dynamic scope for verbosecall filter");
606         puts("    -XXfm <regex>            filter for show options");
607 #endif
608         /* exit with error code */
609
610         exit(1);
611 }
612
613
614 /* version *********************************************************************
615
616    Only prints cacao version information.
617
618 *******************************************************************************/
619
620 static void version(bool opt_exit)
621 {
622         puts("java version \""JAVA_VERSION"\"");
623         puts("CACAO version "VERSION"");
624
625         puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
626         puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
627         puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
628         puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
629
630         puts("This program is free software; you can redistribute it and/or");
631         puts("modify it under the terms of the GNU General Public License as");
632         puts("published by the Free Software Foundation; either version 2, or (at");
633         puts("your option) any later version.\n");
634
635         puts("This program is distributed in the hope that it will be useful, but");
636         puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
637         puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU");
638         puts("General Public License for more details.");
639
640         /* exit normally, if requested */
641
642         if (opt_exit)
643                 exit(0);
644 }
645
646
647 /* fullversion *****************************************************************
648
649    Prints a Sun compatible version information (required e.g. by
650    jpackage, www.jpackage.org).
651
652 *******************************************************************************/
653
654 static void fullversion(void)
655 {
656         puts("java full version \"cacao-"JAVA_VERSION"\"");
657
658         /* exit normally */
659
660         exit(0);
661 }
662
663
664 void vm_printconfig(void)
665 {
666         puts("Configure/Build options:\n");
667         puts("  ./configure: "VERSION_CONFIGURE_ARGS"");
668 #if defined(__VERSION__)
669         puts("  CC         : "VERSION_CC" ("__VERSION__")");
670 #else
671         puts("  CC         : "VERSION_CC"");
672 #endif
673         puts("  CFLAGS     : "VERSION_CFLAGS"\n");
674
675         puts("Default variables:\n");
676         printf("  maximum heap size              : %d\n", HEAP_MAXSIZE);
677         printf("  initial heap size              : %d\n", HEAP_STARTSIZE);
678         printf("  stack size                     : %d\n", STACK_SIZE);
679 #if defined(WITH_CLASSPATH_GNU)
680         puts("  java.boot.class.path           : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
681 #else
682         puts("  java.boot.class.path           : "CLASSPATH_CLASSES"");
683 #endif
684         puts("  gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
685
686         puts("Runtime variables:\n");
687         printf("  maximum heap size              : %d\n", opt_heapmaxsize);
688         printf("  initial heap size              : %d\n", opt_heapstartsize);
689         printf("  stack size                     : %d\n", opt_stacksize);
690         printf("  libjvm.so                      : %s\n", cacao_libjvm);
691         printf("  java.boot.class.path           : %s\n", _Jv_bootclasspath);
692         printf("  gnu.classpath.boot.library.path: %s\n", classpath_libdir);
693         printf("  java.class.path                : %s\n", _Jv_classpath);
694 }
695
696
697 /* forward declarations *******************************************************/
698
699 static char *vm_get_mainclass_from_jar(char *mainstring);
700 #if !defined(NDEBUG)
701 static void  vm_compile_all(void);
702 static void  vm_compile_method(void);
703 #endif
704
705
706 /* vm_createjvm ****************************************************************
707
708    Implementation for JNI_CreateJavaVM.
709
710 *******************************************************************************/
711
712 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
713 {
714         JavaVMInitArgs *_vm_args;
715         _Jv_JNIEnv     *env;
716         _Jv_JavaVM     *vm;
717
718         /* get the arguments for the new JVM */
719
720         _vm_args = (JavaVMInitArgs *) vm_args;
721
722         /* get the VM and Env tables (must be set before vm_create) */
723
724         env = NEW(_Jv_JNIEnv);
725
726 #if defined(ENABLE_JNI)
727         env->env = &_Jv_JNINativeInterface;
728 #endif
729
730         /* XXX Set the global variable.  Maybe we should do that differently. */
731
732         _Jv_env = env;
733
734         /* create and fill a JavaVM structure */
735
736         vm = NEW(_Jv_JavaVM);
737
738 #if defined(ENABLE_JNI)
739         vm->functions = &_Jv_JNIInvokeInterface;
740 #endif
741
742         /* XXX Set the global variable.  Maybe we should do that differently. */
743         /* XXX JVMTI Agents needs a JavaVM  */
744
745         _Jv_jvm = vm;
746
747         /* actually create the JVM */
748
749         if (!vm_create(_vm_args))
750                 goto error;
751
752 #if defined(ENABLE_JNI)
753         /* setup the local ref table (must be created after vm_create) */
754
755         if (!jni_init_localref_table())
756                 goto error;
757 #endif
758
759         /* now return the values */
760
761         *p_vm  = (JavaVM *) vm;
762         *p_env = (void *) env;
763
764         return true;
765
766  error:
767         /* release allocated memory */
768
769         FREE(env, _Jv_JNIEnv);
770         FREE(vm, _Jv_JavaVM);
771
772         return false;
773 }
774
775
776 /* vm_create *******************************************************************
777
778    Creates a JVM.  Called by vm_createjvm.
779
780 *******************************************************************************/
781
782 bool vm_create(JavaVMInitArgs *vm_args)
783 {
784         char *cp;
785         s4    len;
786         s4    opt;
787         s4    i, j;
788         bool  opt_version;
789         bool  opt_exit;
790
791 #if defined(ENABLE_JVMTI)
792         lt_dlhandle  handle;
793         char *libname, *agentarg;
794         bool jdwp,agentbypath;
795         jdwp = agentbypath = false;
796 #endif
797
798 #if defined(ENABLE_VMLOG)
799         vmlog_cacao_init(vm_args);
800 #endif
801
802         /* check the JNI version requested */
803
804         switch (vm_args->version) {
805         case JNI_VERSION_1_1:
806                 break;
807         case JNI_VERSION_1_2:
808         case JNI_VERSION_1_4:
809                 break;
810         default:
811                 return false;
812         }
813
814         /* we only support 1 JVM instance */
815
816         if (vms > 0)
817                 return false;
818
819         if (atexit(vm_exit_handler))
820                 vm_abort("atexit failed: %s\n", strerror(errno));
821
822         if (opt_verbose)
823                 log_text("CACAO started -------------------------------------------------------");
824
825         /* We need to check if the actual size of a java.lang.Class object
826            is smaller or equal than the assumption made in
827            src/vmcore/class.h. */
828
829         if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
830                 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
831
832         /* set the VM starttime */
833
834         _Jv_jvm->starttime = builtin_currenttimemillis();
835
836         /* get stuff from the environment *****************************************/
837
838 #if defined(WITH_JRE_LAYOUT)
839         /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
840
841         cacao_prefix = MNEW(char, 4096);
842
843         if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
844                 vm_abort("readlink failed: %s\n", strerror(errno));
845
846         /* get the path of the current executable */
847
848         cacao_prefix = dirname(cacao_prefix);
849
850         if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
851                 vm_abort("libjvm name to long for buffer\n");
852
853         /* concatenate the library name */
854
855         strcat(cacao_prefix, "/..");
856
857         /* now set path to libjvm.so */
858
859         len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
860
861         cacao_libjvm = MNEW(char, len);
862         strcpy(cacao_libjvm, cacao_prefix);
863         strcat(cacao_libjvm, "/lib/libjvm");
864
865         /* and finally set the path to GNU Classpath libraries */
866
867         len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
868
869         classpath_libdir = MNEW(char, len);
870         strcpy(classpath_libdir, cacao_prefix);
871         strcat(classpath_libdir, "/lib/classpath");
872 #else
873         cacao_prefix     = CACAO_PREFIX;
874         cacao_libjvm     = CACAO_LIBDIR"/libjvm";
875
876 # if defined(WITH_CLASSPATH_GNU)
877         classpath_libdir = CLASSPATH_LIBDIR"/classpath";
878 # else
879         classpath_libdir = CLASSPATH_LIBDIR;
880 # endif
881 #endif
882
883         /* set the bootclasspath */
884
885         cp = getenv("BOOTCLASSPATH");
886
887         if (cp != NULL) {
888                 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
889                 strcpy(_Jv_bootclasspath, cp);
890         }
891         else {
892 #if defined(WITH_JRE_LAYOUT)
893                 len =
894 # if defined(WITH_CLASSPATH_GNU)
895                         strlen(cacao_prefix) +
896                         strlen("/share/cacao/vm.zip") +
897                         strlen(":") +
898 # endif
899                         strlen(cacao_prefix) +
900                         strlen("/share/classpath/glibj.zip") +
901                         strlen("0");
902
903                 _Jv_bootclasspath = MNEW(char, len);
904 # if defined(WITH_CLASSPATH_GNU)
905                 strcat(_Jv_bootclasspath, cacao_prefix);
906                 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
907                 strcat(_Jv_bootclasspath, ":");
908 # endif
909                 strcat(_Jv_bootclasspath, cacao_prefix);
910                 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
911 #else
912                 len =
913 # if defined(WITH_CLASSPATH_GNU)
914                         strlen(CACAO_VM_ZIP) +
915                         strlen(":") +
916 # endif
917                         strlen(CLASSPATH_CLASSES) +
918                         strlen("0");
919
920                 _Jv_bootclasspath = MNEW(char, len);
921 # if defined(WITH_CLASSPATH_GNU)
922                 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
923                 strcat(_Jv_bootclasspath, ":");
924 # endif
925                 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
926 #endif
927         }
928
929         /* set the classpath */
930
931         cp = getenv("CLASSPATH");
932
933         if (cp != NULL) {
934                 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
935                 strcat(_Jv_classpath, cp);
936         }
937         else {
938                 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
939                 strcpy(_Jv_classpath, ".");
940         }
941
942         /* Get and set java.library.path. */
943
944         _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
945
946         if (_Jv_java_library_path == NULL)
947                 _Jv_java_library_path = "";
948
949         /* interpret the options **************************************************/
950
951         opt_version       = false;
952         opt_exit          = false;
953
954         opt_noieee        = false;
955
956         opt_heapmaxsize   = HEAP_MAXSIZE;
957         opt_heapstartsize = HEAP_STARTSIZE;
958         opt_stacksize     = STACK_SIZE;
959
960
961 #if defined(ENABLE_JVMTI)
962         /* initialize JVMTI related  **********************************************/
963         jvmti = false;
964 #endif
965
966         /* Initialize and fill properties before command-line handling. */
967
968         if (!properties_init())
969                 vm_abort("vm_create: properties_init failed");
970
971         /* Set the classpath properties. */
972
973 #if defined(ENABLE_JAVASE)
974         properties_add("java.boot.class.path", _Jv_bootclasspath);
975         properties_add("sun.boot.class.path", _Jv_bootclasspath);
976         properties_add("java.class.path", _Jv_classpath);
977 #endif
978
979         /* iterate over all passed options */
980
981         while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
982                 switch (opt) {
983                 case OPT_FOO:
984                         opt_foo = true;
985                         break;
986
987                 case OPT_IGNORE:
988                         break;
989                         
990                 case OPT_JAR:
991                         opt_jar = true;
992                         break;
993
994                 case OPT_D32:
995 #if SIZEOF_VOID_P == 8
996                         puts("Running a 32-bit JVM is not supported on this platform.");
997                         exit(1);
998 #endif
999                         break;
1000
1001                 case OPT_D64:
1002 #if SIZEOF_VOID_P == 4
1003                         puts("Running a 64-bit JVM is not supported on this platform.");
1004                         exit(1);
1005 #endif
1006                         break;
1007
1008                 case OPT_CLASSPATH:
1009                         /* forget old classpath and set the argument as new classpath */
1010                         MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1011
1012                         _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
1013                         strcpy(_Jv_classpath, opt_arg);
1014
1015 #if defined(ENABLE_JAVASE)
1016                         properties_add("java.class.path", _Jv_classpath);
1017 #endif
1018                         break;
1019
1020                 case OPT_D:
1021                         for (i = 0; i < strlen(opt_arg); i++) {
1022                                 if (opt_arg[i] == '=') {
1023                                         opt_arg[i] = '\0';
1024                                         properties_add(opt_arg, opt_arg + i + 1);
1025                                         goto opt_d_done;
1026                                 }
1027                         }
1028
1029                         /* if no '=' is given, just create an empty property */
1030
1031                         properties_add(opt_arg, "");
1032
1033                 opt_d_done:
1034                         break;
1035
1036                 case OPT_BOOTCLASSPATH:
1037                         /* Forget default bootclasspath and set the argument as
1038                            new boot classpath. */
1039
1040                         MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1041
1042                         _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
1043                         strcpy(_Jv_bootclasspath, opt_arg);
1044
1045 #if defined(ENABLE_JAVASE)
1046                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1047                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1048 #endif
1049                         break;
1050
1051                 case OPT_BOOTCLASSPATH_A:
1052                         /* append to end of bootclasspath */
1053
1054                         len = strlen(_Jv_bootclasspath);
1055
1056                         _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1057                                                                                  char,
1058                                                                                  len + strlen("0"),
1059                                                                                  len + strlen(":") +
1060                                                                                  strlen(opt_arg) + strlen("0"));
1061
1062                         strcat(_Jv_bootclasspath, ":");
1063                         strcat(_Jv_bootclasspath, opt_arg);
1064
1065 #if defined(ENABLE_JAVASE)
1066                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1067                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1068 #endif
1069                         break;
1070
1071                 case OPT_BOOTCLASSPATH_P:
1072                         /* prepend in front of bootclasspath */
1073
1074                         cp = _Jv_bootclasspath;
1075                         len = strlen(cp);
1076
1077                         _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1078                                                                          len + strlen("0"));
1079
1080                         strcpy(_Jv_bootclasspath, opt_arg);
1081                         strcat(_Jv_bootclasspath, ":");
1082                         strcat(_Jv_bootclasspath, cp);
1083
1084                         MFREE(cp, char, len);
1085
1086 #if defined(ENABLE_JAVASE)
1087                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1088                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1089 #endif
1090                         break;
1091
1092                 case OPT_BOOTCLASSPATH_C:
1093                         /* use as Java core library, but prepend VM interface classes */
1094
1095                         MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1096
1097                         len = strlen(CACAO_VM_ZIP) +
1098                                 strlen(":") +
1099                                 strlen(opt_arg) +
1100                                 strlen("0");
1101
1102                         _Jv_bootclasspath = MNEW(char, len);
1103
1104                         strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1105                         strcat(_Jv_bootclasspath, ":");
1106                         strcat(_Jv_bootclasspath, opt_arg);
1107
1108 #if defined(ENABLE_JAVASE)
1109                         properties_add("java.boot.class.path", _Jv_bootclasspath);
1110                         properties_add("sun.boot.class.path", _Jv_bootclasspath);
1111 #endif
1112                         break;
1113
1114 #if defined(ENABLE_JVMTI)
1115                 case OPT_DEBUG:
1116                         /* this option exists only for compatibility reasons */
1117                         break;
1118
1119                 case OPT_NOAGENT:
1120                         /* I don't know yet what Xnoagent should do. This is only for 
1121                            compatiblity with eclipse - motse */
1122                         break;
1123
1124                 case OPT_XRUNJDWP:
1125                         agentbypath = true;
1126                         jvmti       = true;
1127                         jdwp        = true;
1128
1129                         len =
1130                                 strlen(CACAO_LIBDIR) +
1131                                 strlen("/libjdwp.so=") +
1132                                 strlen(opt_arg) +
1133                                 strlen("0");
1134
1135                         agentarg = MNEW(char, len);
1136
1137                         strcpy(agentarg, CACAO_LIBDIR);
1138                         strcat(agentarg, "/libjdwp.so=");
1139                         strcat(agentarg, &opt_arg[1]);
1140                         break;
1141
1142                 case OPT_AGENTPATH:
1143                         agentbypath = true;
1144
1145                 case OPT_AGENTLIB:
1146                         jvmti = true;
1147                         agentarg = opt_arg;
1148                         break;
1149 #endif
1150                         
1151                 case OPT_MX:
1152                 case OPT_MS:
1153                 case OPT_SS:
1154                         {
1155                                 char c;
1156                                 c = opt_arg[strlen(opt_arg) - 1];
1157
1158                                 if ((c == 'k') || (c == 'K')) {
1159                                         j = atoi(opt_arg) * 1024;
1160
1161                                 } else if ((c == 'm') || (c == 'M')) {
1162                                         j = atoi(opt_arg) * 1024 * 1024;
1163
1164                                 } else
1165                                         j = atoi(opt_arg);
1166
1167                                 if (opt == OPT_MX)
1168                                         opt_heapmaxsize = j;
1169                                 else if (opt == OPT_MS)
1170                                         opt_heapstartsize = j;
1171                                 else
1172                                         opt_stacksize = j;
1173                         }
1174                         break;
1175
1176                 case OPT_VERBOSE1:
1177                         opt_verbose = true;
1178                         break;
1179
1180                 case OPT_VERBOSE:
1181                         if (strcmp("class", opt_arg) == 0) {
1182                                 opt_verboseclass = true;
1183                         }
1184                         else if (strcmp("gc", opt_arg) == 0) {
1185                                 opt_verbosegc = true;
1186                         }
1187                         else if (strcmp("jni", opt_arg) == 0) {
1188                                 opt_verbosejni = true;
1189                         }
1190 #if !defined(NDEBUG)
1191                         else if (strcmp("jit", opt_arg) == 0) {
1192                                 opt_verbose = true;
1193                                 loadverbose = true;
1194                                 linkverbose = true;
1195                                 initverbose = true;
1196                                 compileverbose = true;
1197                         }
1198                         else if (strcmp("threads", opt_arg) == 0) {
1199                                 opt_verbosethreads = true;
1200                         }
1201 #endif
1202                         else {
1203                                 printf("Unknown -verbose option: %s\n", opt_arg);
1204                                 usage();
1205                         }
1206                         break;
1207
1208                 case OPT_DEBUGCOLOR:
1209                         opt_debugcolor = true;
1210                         break;
1211
1212 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1213                 case OPT_VERBOSETC:
1214                         opt_typecheckverbose = true;
1215                         break;
1216 #endif
1217                                 
1218                 case OPT_VERSION:
1219                         opt_version = true;
1220                         opt_exit    = true;
1221                         break;
1222
1223                 case OPT_FULLVERSION:
1224                         fullversion();
1225                         break;
1226
1227                 case OPT_SHOWVERSION:
1228                         opt_version = true;
1229                         break;
1230
1231                 case OPT_NOIEEE:
1232                         opt_noieee = true;
1233                         break;
1234
1235 #if defined(ENABLE_VERIFIER)
1236                 case OPT_NOVERIFY:
1237                         opt_verify = false;
1238                         break;
1239 #endif
1240
1241 #if defined(ENABLE_STATISTICS)
1242                 case OPT_TIME:
1243                         opt_getcompilingtime = true;
1244                         opt_getloadingtime = true;
1245                         break;
1246                                         
1247                 case OPT_STAT:
1248                         opt_stat = true;
1249                         break;
1250 #endif
1251                                         
1252                 case OPT_LOG:
1253                         log_init(opt_arg);
1254                         break;
1255                         
1256                 case OPT_CHECK:
1257                         for (i = 0; i < strlen(opt_arg); i++) {
1258                                 switch (opt_arg[i]) {
1259                                 case 'b':
1260                                         checkbounds = false;
1261                                         break;
1262                                 case 's':
1263                                         checksync = false;
1264                                         break;
1265                                 default:
1266                                         usage();
1267                                 }
1268                         }
1269                         break;
1270                         
1271                 case OPT_LOAD:
1272                         opt_run = false;
1273                         makeinitializations = false;
1274                         break;
1275
1276 #if !defined(NDEBUG)
1277                 case OPT_ALL:
1278                         compileall = true;
1279                         opt_run = false;
1280                         makeinitializations = false;
1281                         break;
1282
1283                 case OPT_METHOD:
1284                         opt_run = false;
1285                         opt_method = opt_arg;
1286                         makeinitializations = false;
1287                         break;
1288
1289                 case OPT_SIGNATURE:
1290                         opt_signature = opt_arg;
1291                         break;
1292 #endif
1293
1294                 case OPT_SHOW:       /* Display options */
1295                         for (i = 0; i < strlen(opt_arg); i++) {         
1296                                 switch (opt_arg[i]) {
1297                                 case 'c':
1298                                         showconstantpool = true;
1299                                         break;
1300
1301                                 case 'u':
1302                                         showutf = true;
1303                                         break;
1304
1305                                 case 'm':
1306                                         showmethods = true;
1307                                         break;
1308
1309                                 case 'i':
1310                                         opt_showintermediate = true;
1311                                         compileverbose = true;
1312                                         break;
1313
1314 #if defined(ENABLE_DISASSEMBLER)
1315                                 case 'a':
1316                                         opt_showdisassemble = true;
1317                                         compileverbose = true;
1318                                         break;
1319
1320                                 case 'o':
1321                                         opt_shownops = true;
1322                                         break;
1323
1324                                 case 'e':
1325                                         opt_showexceptionstubs = true;
1326                                         break;
1327
1328                                 case 'n':
1329                                         opt_shownativestub = true;
1330                                         break;
1331 #endif
1332
1333                                 case 'd':
1334                                         opt_showddatasegment = true;
1335                                         break;
1336
1337                                 default:
1338                                         usage();
1339                                 }
1340                         }
1341                         break;
1342                         
1343 #if defined(ENABLE_LOOP)
1344                 case OPT_OLOOP:
1345                         opt_loops = true;
1346                         break;
1347 #endif
1348
1349 #if defined(ENABLE_INLINING)
1350 #if defined(ENABLE_INLINING_DEBUG)
1351                 case OPT_INLINE_DEBUG_ALL:
1352                         opt_inline_debug_all = true;
1353                         break;
1354                 case OPT_INLINE_DEBUG_END:
1355                         opt_inline_debug_end_counter = atoi(opt_arg);
1356                         break;
1357                 case OPT_INLINE_DEBUG_MIN:
1358                         opt_inline_debug_min_size = atoi(opt_arg);
1359                         break;
1360                 case OPT_INLINE_DEBUG_MAX:
1361                         opt_inline_debug_max_size = atoi(opt_arg);
1362                         break;
1363 #endif /* defined(ENABLE_INLINING_DEBUG) */
1364 #if !defined(NDEBUG)
1365                 case OPT_INLINE_LOG:
1366                         opt_inline_debug_log = true;
1367                         break;
1368 #endif /* !defined(NDEBUG) */
1369
1370                 case OPT_INLINING:
1371                         opt_inlining = true;
1372                         break;
1373 #endif /* defined(ENABLE_INLINING) */
1374
1375 #if defined(ENABLE_IFCONV)
1376                 case OPT_IFCONV:
1377                         opt_ifconv = true;
1378                         break;
1379 #endif
1380
1381 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1382                 case OPT_LSRA:
1383                         opt_lsra = true;
1384                         break;
1385 #endif
1386
1387                 case OPT_HELP:
1388                         usage();
1389                         break;
1390
1391                 case OPT_X:
1392                         Xusage();
1393                         break;
1394
1395                 case OPT_XX:
1396                         options_xx(opt_arg);
1397                         break;
1398
1399                 case OPT_EA:
1400                         /* currently ignored */
1401                         break;
1402
1403                 case OPT_DA:
1404                         /* currently ignored */
1405                         break;
1406
1407                 case OPT_ESA:
1408                         _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1409                         break;
1410
1411                 case OPT_DSA:
1412                         _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1413                         break;
1414
1415 #if defined(ENABLE_PROFILING)
1416                 case OPT_PROF_OPTION:
1417                         /* use <= to get the last \0 too */
1418
1419                         for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1420                                 if (opt_arg[i] == ',')
1421                                         opt_arg[i] = '\0';
1422
1423                                 if (opt_arg[i] == '\0') {
1424                                         if (strcmp("bb", opt_arg + j) == 0)
1425                                                 opt_prof_bb = true;
1426
1427                                         else {
1428                                                 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1429                                                 usage();
1430                                         }
1431
1432                                         /* set k to next char */
1433
1434                                         j = i + 1;
1435                                 }
1436                         }
1437                         /* fall through */
1438
1439                 case OPT_PROF:
1440                         opt_prof = true;
1441                         break;
1442 #endif
1443
1444                 case OPT_JIT:
1445 #if defined(ENABLE_JIT)
1446                         opt_jit = true;
1447 #else
1448                         printf("-Xjit option not enabled.\n");
1449                         exit(1);
1450 #endif
1451                         break;
1452
1453                 case OPT_INTRP:
1454 #if defined(ENABLE_INTRP)
1455                         opt_intrp = true;
1456 #else
1457                         printf("-Xint option not enabled.\n");
1458                         exit(1);
1459 #endif
1460                         break;
1461
1462 #if defined(ENABLE_INTRP)
1463                 case OPT_STATIC_SUPERS:
1464                         opt_static_supers = atoi(opt_arg);
1465                         break;
1466
1467                 case OPT_NO_DYNAMIC:
1468                         opt_no_dynamic = true;
1469                         break;
1470
1471                 case OPT_NO_REPLICATION:
1472                         opt_no_replication = true;
1473                         break;
1474
1475                 case OPT_NO_QUICKSUPER:
1476                         opt_no_quicksuper = true;
1477                         break;
1478
1479                 case OPT_TRACE:
1480                         vm_debug = true;
1481                         break;
1482 #endif
1483
1484 #if defined(ENABLE_DEBUG_FILTER)
1485                 case OPT_FILTER_VERBOSECALL_INCLUDE:
1486                         opt_filter_verbosecall_include = opt_arg;
1487                         break;
1488
1489                 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1490                         opt_filter_verbosecall_exclude = opt_arg;
1491                         break;
1492
1493                 case OPT_FILTER_SHOW_METHOD:
1494                         opt_filter_show_method = opt_arg;
1495                         break;
1496
1497 #endif
1498                 default:
1499                         printf("Unknown option: %s\n",
1500                                    vm_args->options[opt_index].optionString);
1501                         usage();
1502                 }
1503         }
1504
1505         /* get the main class *****************************************************/
1506
1507         if (opt_index < vm_args->nOptions) {
1508                 mainstring = vm_args->options[opt_index++].optionString;
1509
1510                 /* Put the jar file into the classpath (if any). */
1511
1512                 if (opt_jar == true) {
1513                         /* free old classpath */
1514
1515                         MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1516
1517                         /* put jarfile into classpath */
1518
1519                         _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1520
1521                         strcpy(_Jv_classpath, mainstring);
1522
1523 #if defined(ENABLE_JAVASE)
1524                         properties_add("java.class.path", _Jv_classpath);
1525 #endif
1526                 }
1527                 else {
1528                         /* replace .'s with /'s in classname */
1529
1530                         for (i = strlen(mainstring) - 1; i >= 0; i--)
1531                                 if (mainstring[i] == '.')
1532                                         mainstring[i] = '/';
1533                 }
1534         }
1535
1536 #if defined(ENABLE_JVMTI)
1537         if (jvmti) {
1538                 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1539                 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1540
1541                 if (jdwp)
1542                         MFREE(agentarg, char, strlen(agentarg));
1543
1544                 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1545         }
1546 #endif
1547
1548         /* initialize this JVM ****************************************************/
1549
1550         vm_initializing = true;
1551
1552         /* initialize the garbage collector */
1553
1554         gc_init(opt_heapmaxsize, opt_heapstartsize);
1555
1556 #if defined(ENABLE_THREADS)
1557         /* AFTER: gc_init (directly after, as this initializes the
1558            stopworldlock lock */
1559
1560         threads_preinit();
1561 #endif
1562
1563         /* install architecture dependent signal handlers */
1564
1565         if (!signal_init())
1566                 vm_abort("vm_create: signal_init failed");
1567
1568 #if defined(ENABLE_INTRP)
1569         /* Allocate main thread stack on the Java heap. */
1570
1571         if (opt_intrp) {
1572                 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1573                 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1574         }
1575 #endif
1576
1577         /* AFTER: threads_preinit */
1578
1579         if (!string_init())
1580                 vm_abort("vm_create: string_init failed");
1581
1582         /* AFTER: threads_preinit */
1583
1584         if (!utf8_init())
1585                 vm_abort("vm_create: utf8_init failed");
1586
1587         /* AFTER: thread_preinit */
1588
1589         if (!suck_init())
1590                 vm_abort("vm_create: suck_init failed");
1591
1592         suck_add_from_property("java.endorsed.dirs");
1593
1594         /* Now we have all options handled and we can print the version
1595            information.
1596
1597            AFTER: suck_add_from_property("java.endorsed.dirs"); */
1598
1599         if (opt_version)
1600                 version(opt_exit);
1601
1602         /* AFTER: utf8_init */
1603
1604         suck_add(_Jv_bootclasspath);
1605
1606         /* initialize the classcache hashtable stuff: lock, hashtable
1607            (must be done _after_ threads_preinit) */
1608
1609         if (!classcache_init())
1610                 vm_abort("vm_create: classcache_init failed");
1611
1612         /* initialize the memory subsystem (must be done _after_
1613            threads_preinit) */
1614
1615         if (!memory_init())
1616                 vm_abort("vm_create: memory_init failed");
1617
1618         /* initialize the finalizer stuff (must be done _after_
1619            threads_preinit) */
1620
1621         if (!finalizer_init())
1622                 vm_abort("vm_create: finalizer_init failed");
1623
1624         /* initialize the codegen subsystems */
1625
1626         codegen_init();
1627
1628         /* initializes jit compiler */
1629
1630         jit_init();
1631
1632         /* machine dependent initialization */
1633
1634 #if defined(ENABLE_JIT)
1635 # if defined(ENABLE_INTRP)
1636         if (opt_intrp)
1637                 intrp_md_init();
1638         else
1639 # endif
1640                 md_init();
1641 #else
1642         intrp_md_init();
1643 #endif
1644
1645         /* initialize the loader subsystems (must be done _after_
1646        classcache_init) */
1647
1648         if (!loader_init())
1649                 vm_abort("vm_create: loader_init failed");
1650
1651         /* Link some important VM classes. */
1652         /* AFTER: utf8_init */
1653
1654         if (!linker_init())
1655                 vm_abort("vm_create: linker_init failed");
1656
1657         if (!primitive_init())
1658                 vm_abort("vm_create: primitive_init failed");
1659
1660         if (!exceptions_init())
1661                 vm_abort("vm_create: exceptions_init failed");
1662
1663         if (!builtin_init())
1664                 vm_abort("vm_create: builtin_init failed");
1665
1666         /* Initialize the native subsystem. */
1667         /* BEFORE: threads_init */
1668
1669         if (!native_init())
1670                 vm_abort("vm_create: native_init failed");
1671
1672         /* Register the native methods implemented in the VM. */
1673         /* BEFORE: threads_init */
1674
1675         if (!nativevm_preinit())
1676                 vm_abort("vm_create: nativevm_preinit failed");
1677
1678 #if defined(ENABLE_JNI)
1679         /* Initialize the JNI subsystem (must be done _before_
1680            threads_init, as threads_init can call JNI methods
1681            (e.g. NewGlobalRef). */
1682
1683         if (!jni_init())
1684                 vm_abort("vm_create: jni_init failed");
1685 #endif
1686
1687 #if defined(ENABLE_THREADS)
1688         if (!threads_init())
1689                 vm_abort("vm_create: threads_init failed");
1690 #endif
1691
1692         /* Initialize the native VM subsystem. */
1693         /* AFTER: threads_init (at least for SUN's classes) */
1694
1695         if (!nativevm_init())
1696                 vm_abort("vm_create: nativevm_init failed");
1697
1698 #if defined(ENABLE_PROFILING)
1699         /* initialize profiling */
1700
1701         if (!profile_init())
1702                 vm_abort("vm_create: profile_init failed");
1703 #endif
1704
1705 #if defined(ENABLE_THREADS)
1706         /* initialize recompilation */
1707
1708         if (!recompile_init())
1709                 vm_abort("vm_create: recompile_init failed");
1710
1711         /* start the signal handler thread */
1712
1713 #if defined(__LINUX__)
1714         /* XXX Remove for exact-GC. */
1715         if (threads_pthreads_implementation_nptl)
1716 #endif
1717                 if (!signal_start_thread())
1718                         vm_abort("vm_create: signal_start_thread failed");
1719
1720         /* finally, start the finalizer thread */
1721
1722         if (!finalizer_start_thread())
1723                 vm_abort("vm_create: finalizer_start_thread failed");
1724
1725 # if !defined(NDEBUG)
1726         /* start the memory profiling thread */
1727
1728         if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1729                 if (!memory_start_thread())
1730                         vm_abort("vm_create: memory_start_thread failed");
1731 # endif
1732
1733         /* start the recompilation thread (must be done before the
1734            profiling thread) */
1735
1736         if (!recompile_start_thread())
1737                 vm_abort("vm_create: recompile_start_thread failed");
1738
1739 # if defined(ENABLE_PROFILING)
1740         /* start the profile sampling thread */
1741
1742 /*      if (opt_prof) */
1743 /*              if (!profile_start_thread()) */
1744 /*                      vm_abort("vm_create: profile_start_thread failed"); */
1745 # endif
1746 #endif
1747
1748 #if defined(ENABLE_JVMTI)
1749         if (jvmti) {
1750                 /* add agent library to native library hashtable */
1751                 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1752         }
1753 #endif
1754
1755         /* increment the number of VMs */
1756
1757         vms++;
1758
1759         /* initialization is done */
1760
1761         vm_initializing = false;
1762
1763         /* everything's ok */
1764
1765         return true;
1766 }
1767
1768
1769 /* vm_run **********************************************************************
1770
1771    Runs the main-method of the passed class.
1772
1773 *******************************************************************************/
1774
1775 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1776 {
1777         utf               *mainutf;
1778         classinfo         *mainclass;
1779         java_objectheader *e;
1780         methodinfo        *m;
1781         java_objectarray  *oa; 
1782         s4                 oalength;
1783         utf               *u;
1784         java_objectheader *s;
1785         s4                 status;
1786         s4                 i;
1787
1788 #if !defined(NDEBUG)
1789         if (compileall) {
1790                 vm_compile_all();
1791                 return;
1792         }
1793
1794         if (opt_method != NULL) {
1795                 vm_compile_method();
1796                 return;
1797         }
1798 #endif /* !defined(NDEBUG) */
1799
1800         /* should we run the main-method? */
1801
1802         if (mainstring == NULL)
1803                 usage();
1804
1805         /* set return value to OK */
1806
1807         status = 0;
1808
1809         if (opt_jar == true) {
1810                 /* open jar file with java.util.jar.JarFile */
1811
1812                 mainstring = vm_get_mainclass_from_jar(mainstring);
1813
1814                 if (mainstring == NULL)
1815                         vm_exit(1);
1816         }
1817
1818         /* load the main class */
1819
1820         mainutf = utf_new_char(mainstring);
1821
1822 #if defined(ENABLE_JAVAME_CLDC1_1)
1823         mainclass = load_class_bootstrap(mainutf);
1824 #else
1825         mainclass = load_class_from_sysloader(mainutf);
1826 #endif
1827
1828         /* error loading class */
1829
1830         e = exceptions_get_and_clear_exception();
1831
1832         if ((e != NULL) || (mainclass == NULL)) {
1833                 exceptions_throw_noclassdeffounderror_cause(e);
1834                 exceptions_print_stacktrace(); 
1835                 vm_exit(1);
1836         }
1837
1838         if (!link_class(mainclass)) {
1839                 exceptions_print_stacktrace();
1840                 vm_exit(1);
1841         }
1842                         
1843         /* find the `main' method of the main class */
1844
1845         m = class_resolveclassmethod(mainclass,
1846                                                                  utf_new_char("main"), 
1847                                                                  utf_new_char("([Ljava/lang/String;)V"),
1848                                                                  class_java_lang_Object,
1849                                                                  false);
1850
1851         if (exceptions_get_exception()) {
1852                 exceptions_print_stacktrace();
1853                 vm_exit(1);
1854         }
1855
1856         /* there is no main method or it isn't static */
1857
1858         if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1859                 exceptions_clear_exception();
1860                 exceptions_throw_nosuchmethoderror(mainclass,
1861                                                                                    utf_new_char("main"), 
1862                                                                                    utf_new_char("([Ljava/lang/String;)V"));
1863
1864                 exceptions_print_stacktrace();
1865                 vm_exit(1);
1866         }
1867
1868         /* build argument array */
1869
1870         oalength = vm_args->nOptions - opt_index;
1871
1872         oa = builtin_anewarray(oalength, class_java_lang_String);
1873
1874         for (i = 0; i < oalength; i++) {
1875                 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1876                 s = javastring_new(u);
1877
1878                 oa->data[i] = s;
1879         }
1880
1881 #ifdef TYPEINFO_DEBUG_TEST
1882         /* test the typeinfo system */
1883         typeinfo_test();
1884 #endif
1885         /*class_showmethods(currentThread->group->header.vftbl->class); */
1886
1887 #if defined(ENABLE_JVMTI)
1888         jvmti_set_phase(JVMTI_PHASE_LIVE);
1889 #endif
1890
1891         /* set ThreadMXBean variables */
1892
1893         _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1894         _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1895
1896         if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1897                 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1898                 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1899                         _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1900
1901         /* start the main thread */
1902
1903         (void) vm_call_method(m, NULL, oa);
1904
1905         /* exception occurred? */
1906
1907         if (exceptions_get_exception()) {
1908                 exceptions_print_stacktrace();
1909                 status = 1;
1910         }
1911
1912         /* unload the JavaVM */
1913
1914         (void) vm_destroy(vm);
1915
1916         /* and exit */
1917
1918         vm_exit(status);
1919 }
1920
1921
1922 /* vm_destroy ******************************************************************
1923
1924    Unloads a Java VM and reclaims its resources.
1925
1926 *******************************************************************************/
1927
1928 s4 vm_destroy(JavaVM *vm)
1929 {
1930 #if defined(ENABLE_THREADS)
1931         threads_join_all_threads();
1932 #endif
1933
1934         /* everything's ok */
1935
1936         return 0;
1937 }
1938
1939
1940 /* vm_exit *********************************************************************
1941
1942    Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1943
1944 *******************************************************************************/
1945
1946 void vm_exit(s4 status)
1947 {
1948         methodinfo *m;
1949
1950         /* signal that we are exiting */
1951
1952         vm_exiting = true;
1953
1954         assert(class_java_lang_System);
1955         assert(class_java_lang_System->state & CLASS_LOADED);
1956
1957 #if defined(ENABLE_JVMTI)
1958         if (jvmti || (dbgcom!=NULL)) {
1959                 jvmti_set_phase(JVMTI_PHASE_DEAD);
1960                 if (jvmti) jvmti_agentunload();
1961         }
1962 #endif
1963
1964         if (!link_class(class_java_lang_System)) {
1965                 exceptions_print_stacktrace();
1966                 exit(1);
1967         }
1968
1969         /* call java.lang.System.exit(I)V */
1970
1971         m = class_resolveclassmethod(class_java_lang_System,
1972                                                                  utf_new_char("exit"),
1973                                                                  utf_int__void,
1974                                                                  class_java_lang_Object,
1975                                                                  true);
1976         
1977         if (m == NULL) {
1978                 exceptions_print_stacktrace();
1979                 exit(1);
1980         }
1981
1982         /* call the exit function with passed exit status */
1983
1984         (void) vm_call_method(m, NULL, status);
1985
1986         /* If we had an exception, just ignore the exception and exit with
1987            the proper code. */
1988
1989         vm_shutdown(status);
1990 }
1991
1992
1993 /* vm_shutdown *****************************************************************
1994
1995    Terminates the system immediately without freeing memory explicitly
1996    (to be used only for abnormal termination).
1997         
1998 *******************************************************************************/
1999
2000 void vm_shutdown(s4 status)
2001 {
2002         if (opt_verbose 
2003 #if defined(ENABLE_STATISTICS)
2004                 || opt_getcompilingtime || opt_stat
2005 #endif
2006            ) 
2007         {
2008                 log_text("CACAO terminated by shutdown");
2009                 dolog("Exit status: %d\n", (s4) status);
2010
2011         }
2012
2013 #if defined(ENABLE_JVMTI)
2014         /* terminate cacaodbgserver */
2015         if (dbgcom!=NULL) {
2016                 pthread_mutex_lock(&dbgcomlock);
2017                 dbgcom->running=1;
2018                 pthread_mutex_unlock(&dbgcomlock);
2019                 jvmti_cacaodbgserver_quit();
2020         }       
2021 #endif
2022
2023         exit(status);
2024 }
2025
2026
2027 /* vm_exit_handler *************************************************************
2028
2029    The exit_handler function is called upon program termination.
2030
2031    ATTENTION: Don't free system resources here! Some threads may still
2032    be running as this is called from VMRuntime.exit(). The OS does the
2033    cleanup for us.
2034
2035 *******************************************************************************/
2036
2037 void vm_exit_handler(void)
2038 {
2039 #if !defined(NDEBUG)
2040         if (showmethods)
2041                 class_showmethods(mainclass);
2042
2043         if (showconstantpool)
2044                 class_showconstantpool(mainclass);
2045
2046         if (showutf)
2047                 utf_show();
2048
2049 # if defined(ENABLE_PROFILING)
2050         if (opt_prof)
2051                 profile_printstats();
2052 # endif
2053 #endif /* !defined(NDEBUG) */
2054
2055 #if defined(ENABLE_RT_TIMING)
2056         rt_timing_print_time_stats(stderr);
2057 #endif
2058
2059 #if defined(ENABLE_CYCLES_STATS)
2060         builtin_print_cycles_stats(stderr);
2061         stacktrace_print_cycles_stats(stderr);
2062 #endif
2063
2064         if (opt_verbose 
2065 #if defined(ENABLE_STATISTICS)
2066                 || opt_getcompilingtime || opt_stat
2067 #endif
2068            ) 
2069         {
2070                 log_text("CACAO terminated");
2071
2072 #if defined(ENABLE_STATISTICS)
2073                 if (opt_stat) {
2074                         print_stats();
2075 #ifdef TYPECHECK_STATISTICS
2076                         typecheck_print_statistics(get_logfile());
2077 #endif
2078                 }
2079
2080                 if (opt_getcompilingtime)
2081                         print_times();
2082 #endif /* defined(ENABLE_STATISTICS) */
2083         }
2084         /* vm_print_profile(stderr);*/
2085 }
2086
2087
2088 /* vm_abort ********************************************************************
2089
2090    Prints an error message and aborts the VM.
2091
2092 *******************************************************************************/
2093
2094 void vm_abort(const char *text, ...)
2095 {
2096         va_list ap;
2097
2098         /* print the log message */
2099
2100         log_start();
2101
2102         va_start(ap, text);
2103         log_vprint(text, ap);
2104         va_end(ap);
2105
2106         log_finish();
2107
2108         /* now abort the VM */
2109
2110         abort();
2111 }
2112
2113
2114 /* vm_get_mainclass_from_jar ***************************************************
2115
2116    Gets the name of the main class from a JAR's manifest file.
2117
2118 *******************************************************************************/
2119
2120 static char *vm_get_mainclass_from_jar(char *mainstring)
2121 {
2122         classinfo         *c;
2123         java_objectheader *o;
2124         methodinfo        *m;
2125         java_objectheader *s;
2126
2127         c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2128
2129         if (c == NULL) {
2130                 exceptions_print_stacktrace();
2131                 return NULL;
2132         }
2133
2134         /* create JarFile object */
2135
2136         o = builtin_new(c);
2137
2138         if (o == NULL) {
2139                 exceptions_print_stacktrace();
2140                 return NULL;
2141         }
2142
2143         m = class_resolveclassmethod(c,
2144                                                                  utf_init, 
2145                                                                  utf_java_lang_String__void,
2146                                                                  class_java_lang_Object,
2147                                                                  true);
2148
2149         if (m == NULL) {
2150                 exceptions_print_stacktrace();
2151                 return NULL;
2152         }
2153
2154         s = javastring_new_from_ascii(mainstring);
2155
2156         (void) vm_call_method(m, o, s);
2157
2158         if (exceptions_get_exception()) {
2159                 exceptions_print_stacktrace();
2160                 return NULL;
2161         }
2162
2163         /* get manifest object */
2164
2165         m = class_resolveclassmethod(c,
2166                                                                  utf_new_char("getManifest"), 
2167                                                                  utf_new_char("()Ljava/util/jar/Manifest;"),
2168                                                                  class_java_lang_Object,
2169                                                                  true);
2170
2171         if (m == NULL) {
2172                 exceptions_print_stacktrace();
2173                 return NULL;
2174         }
2175
2176         o = vm_call_method(m, o);
2177
2178         if (o == NULL) {
2179                 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2180                 return NULL;
2181         }
2182
2183
2184         /* get Main Attributes */
2185
2186         m = class_resolveclassmethod(o->vftbl->class,
2187                                                                  utf_new_char("getMainAttributes"), 
2188                                                                  utf_new_char("()Ljava/util/jar/Attributes;"),
2189                                                                  class_java_lang_Object,
2190                                                                  true);
2191
2192         if (m == NULL) {
2193                 exceptions_print_stacktrace();
2194                 return NULL;
2195         }
2196
2197         o = vm_call_method(m, o);
2198
2199         if (o == NULL) {
2200                 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2201                 return NULL;
2202         }
2203
2204
2205         /* get property Main-Class */
2206
2207         m = class_resolveclassmethod(o->vftbl->class,
2208                                                                  utf_new_char("getValue"), 
2209                                                                  utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2210                                                                  class_java_lang_Object,
2211                                                                  true);
2212
2213         if (m == NULL) {
2214                 exceptions_print_stacktrace();
2215                 return NULL;
2216         }
2217
2218         s = javastring_new_from_ascii("Main-Class");
2219
2220         o = vm_call_method(m, o, s);
2221
2222         if (o == NULL) {
2223                 exceptions_print_stacktrace();
2224                 return NULL;
2225         }
2226
2227         return javastring_tochar(o);
2228 }
2229
2230
2231 /* vm_compile_all **************************************************************
2232
2233    Compile all methods found in the bootclasspath.
2234
2235 *******************************************************************************/
2236
2237 #if !defined(NDEBUG)
2238 static void vm_compile_all(void)
2239 {
2240         classinfo              *c;
2241         methodinfo             *m;
2242         u4                      slot;
2243         classcache_name_entry  *nmen;
2244         classcache_class_entry *clsen;
2245         s4                      i;
2246
2247         /* create all classes found in the bootclasspath */
2248         /* XXX currently only works with zip/jar's */
2249
2250         loader_load_all_classes();
2251
2252         /* link all classes */
2253
2254         for (slot = 0; slot < hashtable_classcache.size; slot++) {
2255                 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2256
2257                 for (; nmen; nmen = nmen->hashlink) {
2258                         /* iterate over all class entries */
2259
2260                         for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2261                                 c = clsen->classobj;
2262
2263                                 if (c == NULL)
2264                                         continue;
2265
2266                                 if (!(c->state & CLASS_LINKED)) {
2267                                         if (!link_class(c)) {
2268                                                 fprintf(stderr, "Error linking: ");
2269                                                 utf_fprint_printable_ascii_classname(stderr, c->name);
2270                                                 fprintf(stderr, "\n");
2271
2272                                                 /* print out exception and cause */
2273
2274                                                 exceptions_print_current_exception();
2275
2276                                                 /* goto next class */
2277
2278                                                 continue;
2279                                         }
2280                                 }
2281
2282                                 /* compile all class methods */
2283
2284                                 for (i = 0; i < c->methodscount; i++) {
2285                                         m = &(c->methods[i]);
2286
2287                                         if (m->jcode != NULL) {
2288                                                 if (!jit_compile(m)) {
2289                                                         fprintf(stderr, "Error compiling: ");
2290                                                         utf_fprint_printable_ascii_classname(stderr, c->name);
2291                                                         fprintf(stderr, ".");
2292                                                         utf_fprint_printable_ascii(stderr, m->name);
2293                                                         utf_fprint_printable_ascii(stderr, m->descriptor);
2294                                                         fprintf(stderr, "\n");
2295
2296                                                         /* print out exception and cause */
2297
2298                                                         exceptions_print_current_exception();
2299                                                 }
2300                                         }
2301                                 }
2302                         }
2303                 }
2304         }
2305 }
2306 #endif /* !defined(NDEBUG) */
2307
2308
2309 /* vm_compile_method ***********************************************************
2310
2311    Compile a specific method.
2312
2313 *******************************************************************************/
2314
2315 #if !defined(NDEBUG)
2316 static void vm_compile_method(void)
2317 {
2318         methodinfo *m;
2319
2320         /* create, load and link the main class */
2321
2322         mainclass = load_class_bootstrap(utf_new_char(mainstring));
2323
2324         if (mainclass == NULL)
2325                 exceptions_print_stacktrace();
2326
2327         if (!link_class(mainclass))
2328                 exceptions_print_stacktrace();
2329
2330         if (opt_signature != NULL) {
2331                 m = class_resolveclassmethod(mainclass,
2332                                                                          utf_new_char(opt_method),
2333                                                                          utf_new_char(opt_signature),
2334                                                                          mainclass,
2335                                                                          false);
2336         }
2337         else {
2338                 m = class_resolveclassmethod(mainclass,
2339                                                                          utf_new_char(opt_method),
2340                                                                          NULL,
2341                                                                          mainclass,
2342                                                                          false);
2343         }
2344
2345         if (m == NULL)
2346                 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2347                                  opt_method, opt_signature ? opt_signature : "");
2348                 
2349         jit_compile(m);
2350 }
2351 #endif /* !defined(NDEBUG) */
2352
2353
2354 /* vm_array_store_int **********************************************************
2355
2356    Helper function to store an integer into the argument array, taking
2357    care of architecture specific issues.
2358
2359 *******************************************************************************/
2360
2361 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2362 {
2363         int32_t index;
2364
2365         if (!pd->inmemory) {
2366                 index        = pd->index;
2367                 array[index] = (int64_t) value;
2368         }
2369         else {
2370                 index        = ARG_CNT + pd->index;
2371 #if SIZEOF_VOID_P == 8
2372                 array[index] = (int64_t) value;
2373 #else
2374 # if WORDS_BIGENDIAN == 1
2375                 array[index] = ((int64_t) value) << 32;
2376 # else
2377                 array[index] = (int64_t) value;
2378 # endif
2379 #endif
2380         }
2381 }
2382
2383
2384 /* vm_array_store_lng **********************************************************
2385
2386    Helper function to store a long into the argument array, taking
2387    care of architecture specific issues.
2388
2389 *******************************************************************************/
2390
2391 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2392 {
2393         int32_t index;
2394
2395 #if SIZEOF_VOID_P == 8
2396         if (!pd->inmemory)
2397                 index = pd->index;
2398         else
2399                 index = ARG_CNT + pd->index;
2400
2401         array[index] = value;
2402 #else
2403         if (!pd->inmemory) {
2404                 /* move low and high 32-bits into it's own argument slot */
2405
2406                 index        = GET_LOW_REG(pd->index);
2407                 array[index] = value & 0x00000000ffffffff;
2408
2409                 index        = GET_HIGH_REG(pd->index);
2410                 array[index] = value >> 32;
2411         }
2412         else {
2413                 index        = ARG_CNT + pd->index;
2414                 array[index] = value;
2415         }
2416 #endif
2417 }
2418
2419
2420 /* vm_array_store_flt **********************************************************
2421
2422    Helper function to store a float into the argument array, taking
2423    care of architecture specific issues.
2424
2425 *******************************************************************************/
2426
2427 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2428 {
2429         int32_t index;
2430
2431         if (!pd->inmemory) {
2432 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2433                 index        = pd->index;
2434 #else
2435                 index        = INT_ARG_CNT + pd->index;
2436 #endif
2437 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2438                 array[index] = value >> 32;
2439 #else
2440                 array[index] = value;
2441 #endif
2442         }
2443         else {
2444                 index        = ARG_CNT + pd->index;
2445 #if defined(__SPARC_64__)
2446                 array[index] = value >> 32;
2447 #else
2448                 array[index] = value;
2449 #endif
2450         }
2451 }
2452
2453
2454 /* vm_array_store_dbl **********************************************************
2455
2456    Helper function to store a double into the argument array, taking
2457    care of architecture specific issues.
2458
2459 *******************************************************************************/
2460
2461 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2462 {
2463         int32_t index;
2464
2465         if (!pd->inmemory) {
2466 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2467                 index        = GET_LOW_REG(pd->index);
2468                 array[index] = value & 0x00000000ffffffff;
2469
2470                 index        = GET_HIGH_REG(pd->index);
2471                 array[index] = value >> 32;
2472 #else
2473                 index        = INT_ARG_CNT + pd->index;
2474                 array[index] = value;
2475 #endif
2476         }
2477         else {
2478                 index        = ARG_CNT + pd->index;
2479                 array[index] = value;
2480         }
2481 }
2482
2483
2484 /* vm_array_store_adr **********************************************************
2485
2486    Helper function to store an address into the argument array, taking
2487    care of architecture specific issues.
2488
2489 *******************************************************************************/
2490
2491 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2492 {
2493         int32_t index;
2494
2495         if (!pd->inmemory) {
2496 #if defined(HAS_ADDRESS_REGISTER_FILE)
2497                 /* When the architecture has address registers, place them
2498                    after integer and float registers. */
2499
2500                 index        = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2501 #else
2502                 index        = pd->index;
2503 #endif
2504                 array[index] = (uint64_t) (intptr_t) value;
2505         }
2506         else {
2507                 index        = ARG_CNT + pd->index;
2508 #if SIZEOF_VOID_P == 8
2509                 array[index] = (uint64_t) (intptr_t) value;
2510 #else
2511 # if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2512                 array[index] = ((uint64_t) (intptr_t) value) << 32;
2513 # else
2514                 array[index] = (uint64_t) (intptr_t) value;
2515 # endif
2516 #endif
2517         }
2518 }
2519
2520
2521 /* vm_vmargs_from_valist *******************************************************
2522
2523    XXX
2524
2525 *******************************************************************************/
2526
2527 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2528 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2529                                                                   vm_arg *vmargs, va_list ap)
2530 {
2531         typedesc *paramtypes;
2532         s4        i;
2533
2534         paramtypes = m->parseddesc->paramtypes;
2535
2536         /* if method is non-static fill first block and skip `this' pointer */
2537
2538         i = 0;
2539
2540         if (o != NULL) {
2541                 /* the `this' pointer */
2542                 vmargs[0].type   = TYPE_ADR;
2543                 vmargs[0].data.l = (u8) (ptrint) o;
2544
2545                 paramtypes++;
2546                 i++;
2547         } 
2548
2549         for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2550                 switch (paramtypes->type) {
2551                 case TYPE_INT:
2552                         vmargs[i].type   = TYPE_INT;
2553                         vmargs[i].data.l = (s8) va_arg(ap, s4);
2554                         break;
2555
2556                 case TYPE_LNG:
2557                         vmargs[i].type   = TYPE_LNG;
2558                         vmargs[i].data.l = (s8) va_arg(ap, s8);
2559                         break;
2560
2561                 case TYPE_FLT:
2562                         vmargs[i].type   = TYPE_FLT;
2563 #if defined(__ALPHA__)
2564                         /* this keeps the assembler function much simpler */
2565
2566                         vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2567 #else
2568                         vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2569 #endif
2570                         break;
2571
2572                 case TYPE_DBL:
2573                         vmargs[i].type   = TYPE_DBL;
2574                         vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2575                         break;
2576
2577                 case TYPE_ADR: 
2578                         vmargs[i].type   = TYPE_ADR;
2579                         vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2580                         break;
2581                 }
2582         }
2583 }
2584 #else
2585 uint64_t *vm_array_from_valist(methodinfo *m, java_objectheader *o, va_list ap)
2586 {
2587         methoddesc *md;
2588         paramdesc  *pd;
2589         typedesc   *td;
2590         uint64_t   *array;
2591         int32_t     i;
2592         imm_union   value;
2593
2594         /* get the descriptors */
2595
2596         md = m->parseddesc;
2597         pd = md->params;
2598         td = md->paramtypes;
2599
2600         /* allocate argument array */
2601
2602         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2603
2604         /* if method is non-static fill first block and skip `this' pointer */
2605
2606         i = 0;
2607
2608         if (o != NULL) {
2609                 /* the `this' pointer */
2610                 vm_array_store_adr(array, pd, o);
2611
2612                 pd++;
2613                 td++;
2614                 i++;
2615         } 
2616
2617         for (; i < md->paramcount; i++, pd++, td++) {
2618                 switch (td->type) {
2619                 case TYPE_INT:
2620                         value.i = va_arg(ap, int32_t);
2621                         vm_array_store_int(array, pd, value.i);
2622                         break;
2623
2624                 case TYPE_LNG:
2625                         value.l = va_arg(ap, int64_t);
2626                         vm_array_store_lng(array, pd, value.l);
2627                         break;
2628
2629                 case TYPE_FLT:
2630 #if defined(__ALPHA__) || defined(__POWERPC64__)
2631                         /* this keeps the assembler function much simpler */
2632
2633                         value.d = (double) va_arg(ap, double);
2634 #else
2635                         value.f = (float) va_arg(ap, double);
2636 #endif
2637                         vm_array_store_flt(array, pd, value.l);
2638                         break;
2639
2640                 case TYPE_DBL:
2641                         value.d = va_arg(ap, double);
2642                         vm_array_store_dbl(array, pd, value.l);
2643                         break;
2644
2645                 case TYPE_ADR: 
2646                         value.a = va_arg(ap, void*);
2647                         vm_array_store_adr(array, pd, value.a);
2648                         break;
2649                 }
2650         }
2651
2652         return array;
2653 }
2654 #endif
2655
2656
2657 /* vm_vmargs_from_jvalue *******************************************************
2658
2659    XXX
2660
2661 *******************************************************************************/
2662
2663 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2664 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2665                                                                   vm_arg *vmargs, const jvalue *args)
2666 {
2667         typedesc *paramtypes;
2668         s4        i;
2669         s4        j;
2670
2671         paramtypes = m->parseddesc->paramtypes;
2672
2673         /* if method is non-static fill first block and skip `this' pointer */
2674
2675         i = 0;
2676
2677         if (o != NULL) {
2678                 /* the `this' pointer */
2679                 vmargs[0].type   = TYPE_ADR;
2680                 vmargs[0].data.l = (u8) (ptrint) o;
2681
2682                 paramtypes++;
2683                 i++;
2684         } 
2685
2686         for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2687                 switch (paramtypes->decltype) {
2688                 case TYPE_INT:
2689                         vmargs[i].type   = TYPE_INT;
2690                         vmargs[i].data.l = (s8) args[j].i;
2691                         break;
2692
2693                 case TYPE_LNG:
2694                         vmargs[i].type   = TYPE_LNG;
2695                         vmargs[i].data.l = (s8) args[j].j;
2696                         break;
2697
2698                 case TYPE_FLT:
2699                         vmargs[i].type = TYPE_FLT;
2700 #if defined(__ALPHA__)
2701                         /* this keeps the assembler function much simpler */
2702
2703                         vmargs[i].data.d = (jdouble) args[j].f;
2704 #else
2705                         vmargs[i].data.f = args[j].f;
2706 #endif
2707                         break;
2708
2709                 case TYPE_DBL:
2710                         vmargs[i].type   = TYPE_DBL;
2711                         vmargs[i].data.d = args[j].d;
2712                         break;
2713
2714                 case TYPE_ADR: 
2715                         vmargs[i].type   = TYPE_ADR;
2716                         vmargs[i].data.l = (u8) (ptrint) args[j].l;
2717                         break;
2718                 }
2719         }
2720 }
2721 #else
2722 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_objectheader *o,
2723                                                                           const jvalue *args)
2724 {
2725         methoddesc *md;
2726         paramdesc  *pd;
2727         typedesc   *td;
2728         uint64_t   *array;
2729         int32_t     i;
2730         int32_t     j;
2731
2732         /* get the descriptors */
2733
2734         md = m->parseddesc;
2735         pd = md->params;
2736         td = md->paramtypes;
2737
2738         /* allocate argument array */
2739
2740 #if defined(HAS_ADDRESS_REGISTER_FILE)
2741         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2742 #else
2743         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2744 #endif
2745
2746         /* if method is non-static fill first block and skip `this' pointer */
2747
2748         i = 0;
2749
2750         if (o != NULL) {
2751                 /* the `this' pointer */
2752                 vm_array_store_adr(array, pd, o);
2753
2754                 pd++;
2755                 td++;
2756                 i++;
2757         } 
2758
2759         for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2760                 switch (td->decltype) {
2761                 case TYPE_INT:
2762                         vm_array_store_int(array, pd, args[j].i);
2763                         break;
2764
2765                 case TYPE_LNG:
2766                         vm_array_store_lng(array, pd, args[j].j);
2767                         break;
2768
2769                 case TYPE_FLT:
2770                         vm_array_store_flt(array, pd, args[j].j);
2771                         break;
2772
2773                 case TYPE_DBL:
2774                         vm_array_store_dbl(array, pd, args[j].j);
2775                         break;
2776
2777                 case TYPE_ADR: 
2778                         vm_array_store_adr(array, pd, args[j].l);
2779                         break;
2780                 }
2781         }
2782
2783         return array;
2784 }
2785 #endif
2786
2787 /* vm_vmargs_from_objectarray **************************************************
2788
2789    XXX
2790
2791 *******************************************************************************/
2792
2793 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2794 bool vm_vmargs_from_objectarray(methodinfo *m, java_objectheader *o,
2795                                                                 vm_arg *vmargs, java_objectarray *params)
2796 {
2797         java_objectheader *param;
2798         typedesc          *paramtypes;
2799         classinfo         *c;
2800         int32_t            i;
2801         int32_t            j;
2802         int64_t            value;
2803
2804         paramtypes = m->parseddesc->paramtypes;
2805
2806         /* if method is non-static fill first block and skip `this' pointer */
2807
2808         i = 0;
2809
2810         if (o != NULL) {
2811                 /* this pointer */
2812                 vmargs[0].type   = TYPE_ADR;
2813                 vmargs[0].data.l = (uint64_t) (intptr_t) o;
2814
2815                 paramtypes++;
2816                 i++;
2817         }
2818
2819         for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2820                 switch (paramtypes->type) {
2821                 /* primitive types */
2822                 case TYPE_INT:
2823                 case TYPE_LNG:
2824                 case TYPE_FLT:
2825                 case TYPE_DBL:
2826                         param = params->data[j];
2827
2828                         if (param == NULL)
2829                                 goto illegal_arg;
2830
2831                         /* internally used data type */
2832                         vmargs[i].type = paramtypes->type;
2833
2834                         /* convert the value according to its declared type */
2835
2836                         c = param->vftbl->class;
2837
2838                         switch (paramtypes->decltype) {
2839                         case PRIMITIVETYPE_BOOLEAN:
2840                                 if (c == class_java_lang_Boolean)
2841                                         value = (int64_t) ((java_lang_Boolean *) param)->value;
2842                                 else
2843                                         goto illegal_arg;
2844
2845                                 vmargs[i].data.l = value;
2846                                 break;
2847
2848                         case PRIMITIVETYPE_BYTE:
2849                                 if (c == class_java_lang_Byte)
2850                                         value = (int64_t) ((java_lang_Byte *) param)->value;
2851                                 else
2852                                         goto illegal_arg;
2853
2854                                 vmargs[i].data.l = value;
2855                                 break;
2856
2857                         case PRIMITIVETYPE_CHAR:
2858                                 if (c == class_java_lang_Character)
2859                                         value = (int64_t) ((java_lang_Character *) param)->value;
2860                                 else
2861                                         goto illegal_arg;
2862
2863                                 vmargs[i].data.l = value;
2864                                 break;
2865
2866                         case PRIMITIVETYPE_SHORT:
2867                                 if (c == class_java_lang_Short)
2868                                         value = (int64_t) ((java_lang_Short *) param)->value;
2869                                 else if (c == class_java_lang_Byte)
2870                                         value = (int64_t) ((java_lang_Byte *) param)->value;
2871                                 else
2872                                         goto illegal_arg;
2873
2874                                 vmargs[i].data.l = value;
2875                                 break;
2876
2877                         case PRIMITIVETYPE_INT:
2878                                 if (c == class_java_lang_Integer)
2879                                         value = (int64_t) ((java_lang_Integer *) param)->value;
2880                                 else if (c == class_java_lang_Short)
2881                                         value = (int64_t) ((java_lang_Short *) param)->value;
2882                                 else if (c == class_java_lang_Byte)
2883                                         value = (int64_t) ((java_lang_Byte *) param)->value;
2884                                 else
2885                                         goto illegal_arg;
2886
2887                                 vmargs[i].data.l = value;
2888                                 break;
2889
2890                         case PRIMITIVETYPE_LONG:
2891                                 if (c == class_java_lang_Long)
2892                                         value = (int64_t) ((java_lang_Long *) param)->value;
2893                                 else if (c == class_java_lang_Integer)
2894                                         value = (int64_t) ((java_lang_Integer *) param)->value;
2895                                 else if (c == class_java_lang_Short)
2896                                         value = (int64_t) ((java_lang_Short *) param)->value;
2897                                 else if (c == class_java_lang_Byte)
2898                                         value = (int64_t) ((java_lang_Byte *) param)->value;
2899                                 else
2900                                         goto illegal_arg;
2901
2902                                 vmargs[i].data.l = value;
2903                                 break;
2904
2905                         case PRIMITIVETYPE_FLOAT:
2906                                 if (c == class_java_lang_Float)
2907                                         vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2908                                 else
2909                                         goto illegal_arg;
2910                                 break;
2911
2912                         case PRIMITIVETYPE_DOUBLE:
2913                                 if (c == class_java_lang_Double)
2914                                         vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
2915                                 else if (c == class_java_lang_Float)
2916                                         vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2917                                 else
2918                                         goto illegal_arg;
2919                                 break;
2920
2921                         default:
2922                                 goto illegal_arg;
2923                         }
2924                         break;
2925                 
2926                 case TYPE_ADR:
2927                         if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
2928                                 return false;
2929
2930                         if (params->data[j] != 0) {
2931                                 if (paramtypes->arraydim > 0) {
2932                                         if (!builtin_arrayinstanceof(params->data[j], c))
2933                                                 goto illegal_arg;
2934
2935                                 } else {
2936                                         if (!builtin_instanceof(params->data[j], c))
2937                                                 goto illegal_arg;
2938                                 }
2939                         }
2940
2941                         vmargs[i].type   = TYPE_ADR;
2942                         vmargs[i].data.l = (u8) (ptrint) params->data[j];
2943                         break;
2944
2945                 default:
2946                         goto illegal_arg;
2947                 }
2948         }
2949
2950 /*      if (rettype) */
2951 /*              *rettype = descr->returntype.decltype; */
2952
2953         return true;
2954
2955 illegal_arg:
2956         exceptions_throw_illegalargumentexception();
2957         return false;
2958 }
2959 #else
2960 uint64_t *vm_array_from_objectarray(methodinfo *m, java_objectheader *o,
2961                                                                         java_objectarray *params)
2962 {
2963         methoddesc        *md;
2964         paramdesc         *pd;
2965         typedesc          *td;
2966         uint64_t          *array;
2967         java_objectheader *param;
2968         classinfo         *c;
2969         int32_t            i;
2970         int32_t            j;
2971         imm_union          value;
2972
2973         /* get the descriptors */
2974
2975         md = m->parseddesc;
2976         pd = md->params;
2977         td = md->paramtypes;
2978
2979         /* allocate argument array */
2980
2981         array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2982
2983         /* if method is non-static fill first block and skip `this' pointer */
2984
2985         i = 0;
2986
2987         if (o != NULL) {
2988                 /* this pointer */
2989                 vm_array_store_adr(array, pd, o);
2990
2991                 pd++;
2992                 td++;
2993                 i++;
2994         }
2995
2996         for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2997                 param = params->data[j];
2998
2999                 switch (td->type) {
3000                 case TYPE_INT:
3001                         if (param == NULL)
3002                                 goto illegal_arg;
3003
3004                         /* convert the value according to its declared type */
3005
3006                         c = param->vftbl->class;
3007
3008                         switch (td->decltype) {
3009                         case PRIMITIVETYPE_BOOLEAN:
3010                                 if (c == class_java_lang_Boolean)
3011                                         value.i = ((java_lang_Boolean *) param)->value;
3012                                 else
3013                                         goto illegal_arg;
3014                                 break;
3015
3016                         case PRIMITIVETYPE_BYTE:
3017                                 if (c == class_java_lang_Byte)
3018                                         value.i = ((java_lang_Byte *) param)->value;
3019                                 else
3020                                         goto illegal_arg;
3021                                 break;
3022
3023                         case PRIMITIVETYPE_CHAR:
3024                                 if (c == class_java_lang_Character)
3025                                         value.i = ((java_lang_Character *) param)->value;
3026                                 else
3027                                         goto illegal_arg;
3028                                 break;
3029
3030                         case PRIMITIVETYPE_SHORT:
3031                                 if (c == class_java_lang_Short)
3032                                         value.i = ((java_lang_Short *) param)->value;
3033                                 else if (c == class_java_lang_Byte)
3034                                         value.i = ((java_lang_Byte *) param)->value;
3035                                 else
3036                                         goto illegal_arg;
3037                                 break;
3038
3039                         case PRIMITIVETYPE_INT:
3040                                 if (c == class_java_lang_Integer)
3041                                         value.i = ((java_lang_Integer *) param)->value;
3042                                 else if (c == class_java_lang_Short)
3043                                         value.i = ((java_lang_Short *) param)->value;
3044                                 else if (c == class_java_lang_Byte)
3045                                         value.i = ((java_lang_Byte *) param)->value;
3046                                 else
3047                                         goto illegal_arg;
3048                                 break;
3049
3050                         default:
3051                                 goto illegal_arg;
3052                         }
3053
3054                         vm_array_store_int(array, pd, value.i);
3055                         break;
3056
3057                 case TYPE_LNG:
3058                         if (param == NULL)
3059                                 goto illegal_arg;
3060
3061                         /* convert the value according to its declared type */
3062
3063                         c = param->vftbl->class;
3064
3065                         switch (td->decltype) {
3066                         case PRIMITIVETYPE_LONG:
3067                                 if (c == class_java_lang_Long)
3068                                         value.l = ((java_lang_Long *) param)->value;
3069                                 else if (c == class_java_lang_Integer)
3070                                         value.l = (int64_t) ((java_lang_Integer *) param)->value;
3071                                 else if (c == class_java_lang_Short)
3072                                         value.l = (int64_t) ((java_lang_Short *) param)->value;
3073                                 else if (c == class_java_lang_Byte)
3074                                         value.l = (int64_t) ((java_lang_Byte *) param)->value;
3075                                 else
3076                                         goto illegal_arg;
3077                                 break;
3078
3079                         default:
3080                                 goto illegal_arg;
3081                         }
3082
3083                         vm_array_store_lng(array, pd, value.l);
3084                         break;
3085
3086                 case TYPE_FLT:
3087                         if (param == NULL)
3088                                 goto illegal_arg;
3089
3090                         /* convert the value according to its declared type */
3091
3092                         c = param->vftbl->class;
3093
3094                         switch (td->decltype) {
3095                         case PRIMITIVETYPE_FLOAT:
3096                                 if (c == class_java_lang_Float)
3097                                         value.f = ((java_lang_Float *) param)->value;
3098                                 else
3099                                         goto illegal_arg;
3100                                 break;
3101
3102                         default:
3103                                 goto illegal_arg;
3104                         }
3105
3106                         vm_array_store_flt(array, pd, value.l);
3107                         break;
3108
3109                 case TYPE_DBL:
3110                         if (param == NULL)
3111                                 goto illegal_arg;
3112
3113                         /* convert the value according to its declared type */
3114
3115                         c = param->vftbl->class;
3116
3117                         switch (td->decltype) {
3118                         case PRIMITIVETYPE_DOUBLE:
3119                                 if (c == class_java_lang_Double)
3120                                         value.d = ((java_lang_Double *) param)->value;
3121                                 else if (c == class_java_lang_Float)
3122                                         value.f = ((java_lang_Float *) param)->value;
3123                                 else
3124                                         goto illegal_arg;
3125                                 break;
3126
3127                         default:
3128                                 goto illegal_arg;
3129                         }
3130
3131                         vm_array_store_dbl(array, pd, value.l);
3132                         break;
3133                 
3134                 case TYPE_ADR:
3135                         if (!resolve_class_from_typedesc(td, true, true, &c))
3136                                 return false;
3137
3138                         if (param != NULL) {
3139                                 if (td->arraydim > 0) {
3140                                         if (!builtin_arrayinstanceof(param, c))
3141                                                 goto illegal_arg;
3142                                 }
3143                                 else {
3144                                         if (!builtin_instanceof(param, c))
3145                                                 goto illegal_arg;
3146                                 }
3147                         }
3148
3149                         vm_array_store_adr(array, pd, param);
3150                         break;
3151
3152                 default:
3153                         goto illegal_arg;
3154                 }
3155         }
3156
3157         return array;
3158
3159 illegal_arg:
3160         exceptions_throw_illegalargumentexception();
3161         return NULL;
3162 }
3163 #endif
3164
3165
3166 /* vm_call_method **************************************************************
3167
3168    Calls a Java method with a variable number of arguments and returns
3169    an address.
3170
3171 *******************************************************************************/
3172
3173 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
3174 {
3175         va_list            ap;
3176         java_objectheader *ro;
3177
3178         va_start(ap, o);
3179         ro = vm_call_method_valist(m, o, ap);
3180         va_end(ap);
3181
3182         return ro;
3183 }
3184
3185
3186 /* vm_call_method_valist *******************************************************
3187
3188    Calls a Java method with a variable number of arguments, passed via
3189    a va_list, and returns an address.
3190
3191 *******************************************************************************/
3192
3193 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
3194                                                                                  va_list ap)
3195 {
3196 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3197         s4                 vmargscount;
3198         vm_arg            *vmargs;
3199         java_objectheader *ro;
3200         s4                 dumpsize;
3201
3202         /* mark start of dump memory area */
3203
3204         dumpsize = dump_size();
3205
3206         /* get number of Java method arguments */
3207
3208         vmargscount = m->parseddesc->paramcount;
3209
3210         /* allocate vm_arg array */
3211
3212         vmargs = DMNEW(vm_arg, vmargscount);
3213
3214         /* fill the vm_arg array from a va_list */
3215
3216         vm_vmargs_from_valist(m, o, vmargs, ap);
3217
3218         /* call the Java method */
3219
3220         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3221
3222         /* release dump area */
3223
3224         dump_release(dumpsize);
3225
3226         return ro;
3227 #else
3228         java_objectheader *ro;
3229         int32_t            dumpsize;
3230         uint64_t          *array;
3231
3232         /* mark start of dump memory area */
3233
3234         dumpsize = dump_size();
3235
3236         /* fill the argument array from a va_list */
3237
3238         array = vm_array_from_valist(m, o, ap);
3239
3240         /* call the Java method */
3241
3242         ro = vm_call_array(m, array);
3243
3244         /* release dump area */
3245
3246         dump_release(dumpsize);
3247
3248         return ro;
3249 #endif
3250 }
3251
3252
3253 /* vm_call_method_jvalue *******************************************************
3254
3255    Calls a Java method with a variable number of arguments, passed via
3256    a jvalue array, and returns an address.
3257
3258 *******************************************************************************/
3259
3260 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
3261                                                                                  const jvalue *args)
3262 {
3263 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3264         s4                 vmargscount;
3265         vm_arg            *vmargs;
3266         java_objectheader *ro;
3267         s4                 dumpsize;
3268
3269         /* mark start of dump memory area */
3270
3271         dumpsize = dump_size();
3272
3273         /* get number of Java method arguments */
3274
3275         vmargscount = m->parseddesc->paramcount;
3276
3277         /* allocate vm_arg array */
3278
3279         vmargs = DMNEW(vm_arg, vmargscount);
3280
3281         /* fill the vm_arg array from a va_list */
3282
3283         vm_vmargs_from_jvalue(m, o, vmargs, args);
3284
3285         /* call the Java method */
3286
3287         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3288
3289         /* release dump area */
3290
3291         dump_release(dumpsize);
3292
3293         return ro;
3294 #else
3295         java_objectheader *ro;
3296         int32_t            dumpsize;
3297         uint64_t          *array;
3298
3299         /* mark start of dump memory area */
3300
3301         dumpsize = dump_size();
3302
3303         /* fill the argument array from a va_list */
3304
3305         array = vm_array_from_jvalue(m, o, args);
3306
3307         /* call the Java method */
3308
3309         ro = vm_call_array(m, array);
3310
3311         /* release dump area */
3312
3313         dump_release(dumpsize);
3314
3315         return ro;
3316 #endif
3317 }
3318
3319
3320 /* vm_call_array ***************************************************************
3321
3322    Calls a Java method with a variable number of arguments, passed via
3323    an argument array, and returns an address.
3324
3325 *******************************************************************************/
3326
3327 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3328 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
3329                                                                                 vm_arg *vmargs)
3330 {
3331         java_objectheader *o;
3332
3333         STATISTICS(count_calls_native_to_java++);
3334
3335 #if defined(ENABLE_JIT)
3336 # if defined(ENABLE_INTRP)
3337         if (opt_intrp)
3338                 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3339         else
3340 # endif
3341                 o = asm_vm_call_method(m, vmargscount, vmargs);
3342 #else
3343         o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3344 #endif
3345
3346         return o;
3347 }
3348 #else
3349 java_objectheader *vm_call_array(methodinfo *m, uint64_t *array)
3350 {
3351         methoddesc        *md;
3352         java_objectheader *o;
3353
3354         md = m->parseddesc;
3355
3356         /* compile the method if not already done */
3357
3358         if (m->code == NULL)
3359                 if (!jit_compile(m))
3360                         return NULL;
3361
3362         STATISTICS(count_calls_native_to_java++);
3363
3364 #if defined(ENABLE_JIT)
3365 # if defined(ENABLE_INTRP)
3366         if (opt_intrp)
3367                 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3368         else
3369 # endif
3370                 o = asm_vm_call_method(m->code->entrypoint, array, md->memuse);
3371 #else
3372         o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3373 #endif
3374
3375         return o;
3376 }
3377 #endif
3378
3379
3380 /* vm_call_int_array ***********************************************************
3381
3382    Calls a Java method with a variable number of arguments, passed via
3383    an argument array, and returns an integer (int32_t).
3384
3385 *******************************************************************************/
3386
3387 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3388 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3389 {
3390         s4 i;
3391
3392         STATISTICS(count_calls_native_to_java++);
3393
3394 #if defined(ENABLE_JIT)
3395 # if defined(ENABLE_INTRP)
3396         if (opt_intrp)
3397                 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3398         else
3399 # endif
3400                 i = asm_vm_call_method_int(m, vmargscount, vmargs);
3401 #else
3402         i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3403 #endif
3404
3405         return i;
3406 }
3407 #else
3408 int32_t vm_call_int_array(methodinfo *m, uint64_t *array)
3409 {
3410         methoddesc *md;
3411         int32_t     i;
3412
3413         md = m->parseddesc;
3414
3415         /* compile the method if not already done */
3416
3417         if (m->code == NULL)
3418                 if (!jit_compile(m))
3419                         return 0;
3420
3421         STATISTICS(count_calls_native_to_java++);
3422
3423 #if defined(ENABLE_JIT)
3424 # if defined(ENABLE_INTRP)
3425         if (opt_intrp)
3426                 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3427         else
3428 # endif
3429                 i = asm_vm_call_method_int(m->code->entrypoint, array, md->memuse);
3430 #else
3431         i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3432 #endif
3433
3434         return i;
3435 }
3436 #endif
3437
3438
3439 /* vm_call_method_int **********************************************************
3440
3441    Calls a Java method with a variable number of arguments and returns
3442    an integer (s4).
3443
3444 *******************************************************************************/
3445
3446 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
3447 {
3448         va_list ap;
3449         s4      i;
3450
3451         va_start(ap, o);
3452         i = vm_call_method_int_valist(m, o, ap);
3453         va_end(ap);
3454
3455         return i;
3456 }
3457
3458
3459 /* vm_call_method_int_valist ***************************************************
3460
3461    Calls a Java method with a variable number of arguments, passed via
3462    a va_list, and returns an integer (int32_t).
3463
3464 *******************************************************************************/
3465
3466 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3467 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3468 {
3469         s4      vmargscount;
3470         vm_arg *vmargs;
3471         s4      i;
3472         s4      dumpsize;
3473
3474         /* mark start of dump memory area */
3475
3476         dumpsize = dump_size();
3477
3478         /* get number of Java method arguments */
3479
3480         vmargscount = m->parseddesc->paramcount;
3481
3482         /* allocate vm_arg array */
3483
3484         vmargs = DMNEW(vm_arg, vmargscount);
3485
3486         /* fill the vm_arg array from a va_list */
3487
3488         vm_vmargs_from_valist(m, o, vmargs, ap);
3489
3490         /* call the Java method */
3491
3492         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3493
3494         /* release dump area */
3495
3496         dump_release(dumpsize);
3497
3498         return i;
3499 }
3500 #else
3501 int32_t vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3502 {
3503         int32_t   dumpsize;
3504         uint64_t *array;
3505         int32_t   i;
3506
3507         /* mark start of dump memory area */
3508
3509         dumpsize = dump_size();
3510
3511         /* fill the argument array from a va_list */
3512
3513         array = vm_array_from_valist(m, o, ap);
3514
3515         /* call the Java method */
3516
3517         i = vm_call_int_array(m, array);
3518
3519         /* release dump area */
3520
3521         dump_release(dumpsize);
3522
3523         return i;
3524 }
3525 #endif
3526
3527
3528 /* vm_call_method_int_jvalue ***************************************************
3529
3530    Calls a Java method with a variable number of arguments, passed via
3531    a jvalue array, and returns an integer (s4).
3532
3533 *******************************************************************************/
3534
3535 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3536 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3537                                                          const jvalue *args)
3538 {
3539         s4      vmargscount;
3540         vm_arg *vmargs;
3541         s4      i;
3542         s4      dumpsize;
3543
3544         /* mark start of dump memory area */
3545
3546         dumpsize = dump_size();
3547
3548         /* get number of Java method arguments */
3549
3550         vmargscount = m->parseddesc->paramcount;
3551
3552         /* allocate vm_arg array */
3553
3554         vmargs = DMNEW(vm_arg, vmargscount);
3555
3556         /* fill the vm_arg array from a va_list */
3557
3558         vm_vmargs_from_jvalue(m, o, vmargs, args);
3559
3560         /* call the Java method */
3561
3562         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3563
3564         /* release dump area */
3565
3566         dump_release(dumpsize);
3567
3568         return i;
3569 }
3570 #else
3571 int32_t vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3572                                                                   const jvalue *args)
3573 {
3574         int32_t   dumpsize;
3575         uint64_t *array;
3576         int32_t   i;
3577
3578         /* mark start of dump memory area */
3579
3580         dumpsize = dump_size();
3581
3582         /* fill the argument array from a va_list */
3583
3584         array = vm_array_from_jvalue(m, o, args);
3585
3586         /* call the Java method */
3587
3588         i = vm_call_int_array(m, array);
3589
3590         /* release dump area */
3591
3592         dump_release(dumpsize);
3593
3594         return i;
3595 }
3596 #endif
3597
3598
3599 /* vm_call_long_array **********************************************************
3600
3601    Calls a Java method with a variable number of arguments, passed via
3602    an argument array, and returns a long (int64_t).
3603
3604 *******************************************************************************/
3605
3606 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3607 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3608 {
3609         s8 l;
3610
3611         STATISTICS(count_calls_native_to_java++);
3612
3613 #if defined(ENABLE_JIT)
3614 # if defined(ENABLE_INTRP)
3615         if (opt_intrp)
3616                 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3617         else
3618 # endif
3619                 l = asm_vm_call_method_long(m, vmargscount, vmargs);
3620 #else
3621         l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3622 #endif
3623
3624         return l;
3625 }
3626 #else
3627 int64_t vm_call_long_array(methodinfo *m, uint64_t *array)
3628 {
3629         methoddesc *md;
3630         int64_t     l;
3631
3632         md = m->parseddesc;
3633
3634         /* compile the method if not already done */
3635
3636         if (m->code == NULL)
3637                 if (!jit_compile(m))
3638                         return 0;
3639
3640         STATISTICS(count_calls_native_to_java++);
3641
3642 #if defined(ENABLE_JIT)
3643 # if defined(ENABLE_INTRP)
3644         if (opt_intrp)
3645                 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3646         else
3647 # endif
3648                 l = asm_vm_call_method_long(m->code->entrypoint, array, md->memuse);
3649 #else
3650         l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3651 #endif
3652
3653         return l;
3654 }
3655 #endif
3656
3657
3658 /* vm_call_method_long *********************************************************
3659
3660    Calls a Java method with a variable number of arguments and returns
3661    a long (s8).
3662
3663 *******************************************************************************/
3664
3665 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
3666 {
3667         va_list ap;
3668         s8      l;
3669
3670         va_start(ap, o);
3671         l = vm_call_method_long_valist(m, o, ap);
3672         va_end(ap);
3673
3674         return l;
3675 }
3676
3677
3678 /* vm_call_method_long_valist **************************************************
3679
3680    Calls a Java method with a variable number of arguments, passed via
3681    a va_list, and returns a long (s8).
3682
3683 *******************************************************************************/
3684
3685 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3686 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3687 {
3688         s4      vmargscount;
3689         vm_arg *vmargs;
3690         s8      l;
3691         s4      dumpsize;
3692
3693         /* mark start of dump memory area */
3694
3695         dumpsize = dump_size();
3696
3697         /* get number of Java method arguments */
3698
3699         vmargscount = m->parseddesc->paramcount;
3700
3701         /* allocate vm_arg array */
3702
3703         vmargs = DMNEW(vm_arg, vmargscount);
3704
3705         /* fill the vm_arg array from a va_list */
3706
3707         vm_vmargs_from_valist(m, o, vmargs, ap);
3708
3709         /* call the Java method */
3710
3711         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3712
3713         /* release dump area */
3714
3715         dump_release(dumpsize);
3716
3717         return l;
3718 }
3719 #else
3720 int64_t vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3721 {
3722         int32_t   dumpsize;
3723         uint64_t *array;
3724         int64_t   l;
3725
3726         /* mark start of dump memory area */
3727
3728         dumpsize = dump_size();
3729
3730         /* fill the argument array from a va_list */
3731
3732         array = vm_array_from_valist(m, o, ap);
3733
3734         /* call the Java method */
3735
3736         l = vm_call_long_array(m, array);
3737
3738         /* release dump area */
3739
3740         dump_release(dumpsize);
3741
3742         return l;
3743 }
3744 #endif
3745
3746
3747 /* vm_call_method_long_jvalue **************************************************
3748
3749    Calls a Java method with a variable number of arguments, passed via
3750    a jvalue array, and returns a long (s8).
3751
3752 *******************************************************************************/
3753
3754 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3755 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3756                                                           const jvalue *args)
3757 {
3758         s4      vmargscount;
3759         vm_arg *vmargs;
3760         s8      l;
3761         s4      dumpsize;
3762
3763         /* mark start of dump memory area */
3764
3765         dumpsize = dump_size();
3766
3767         /* get number of Java method arguments */
3768
3769         vmargscount = m->parseddesc->paramcount;
3770
3771         /* allocate vm_arg array */
3772
3773         vmargs = DMNEW(vm_arg, vmargscount);
3774
3775         /* fill the vm_arg array from a va_list */
3776
3777         vm_vmargs_from_jvalue(m, o, vmargs, args);
3778
3779         /* call the Java method */
3780
3781         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3782
3783         /* release dump area */
3784
3785         dump_release(dumpsize);
3786
3787         return l;
3788 }
3789 #else
3790 int64_t vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3791                                                                    const jvalue *args)
3792 {
3793         int32_t   dumpsize;
3794         uint64_t *array;
3795         int64_t   l;
3796
3797         /* mark start of dump memory area */
3798
3799         dumpsize = dump_size();
3800
3801         /* fill the argument array from a va_list */
3802
3803         array = vm_array_from_jvalue(m, o, args);
3804
3805         /* call the Java method */
3806
3807         l = vm_call_long_array(m, array);
3808
3809         /* release dump area */
3810
3811         dump_release(dumpsize);
3812
3813         return l;
3814 }
3815 #endif
3816
3817
3818 /* vm_call_float_array *********************************************************
3819
3820    Calls a Java method with a variable number of arguments and returns
3821    an float.
3822
3823 *******************************************************************************/
3824
3825 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3826 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3827 {
3828         float f;
3829
3830         vm_abort("IMPLEMENT ME!");
3831
3832         STATISTICS(count_calls_native_to_java++);
3833
3834 #if defined(ENABLE_JIT)
3835 # if defined(ENABLE_INTRP)
3836         if (opt_intrp)
3837                 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3838         else
3839 # endif
3840                 f = asm_vm_call_method_float(m, vmargscount, vmargs);
3841 #else
3842         f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3843 #endif
3844
3845         return f;
3846 }
3847 #else
3848 float vm_call_float_array(methodinfo *m, uint64_t *array)
3849 {
3850         methoddesc *md;
3851         float       f;
3852
3853         md = m->parseddesc;
3854
3855         /* compile the method if not already done */
3856
3857         if (m->code == NULL)
3858                 if (!jit_compile(m))
3859                         return 0;
3860
3861         STATISTICS(count_calls_native_to_java++);
3862
3863 #if defined(ENABLE_JIT)
3864 # if defined(ENABLE_INTRP)
3865         if (opt_intrp)
3866                 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3867         else
3868 # endif
3869                 f = asm_vm_call_method_float(m->code->entrypoint, array, md->memuse);
3870 #else
3871         f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3872 #endif
3873
3874         return f;
3875 }
3876 #endif
3877
3878 /* vm_call_method_float ********************************************************
3879
3880    Calls a Java method with a variable number of arguments and returns
3881    an float.
3882
3883 *******************************************************************************/
3884
3885 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
3886 {
3887         va_list ap;
3888         float   f;
3889
3890         va_start(ap, o);
3891         f = vm_call_method_float_valist(m, o, ap);
3892         va_end(ap);
3893
3894         return f;
3895 }
3896
3897
3898 /* vm_call_method_float_valist *************************************************
3899
3900    Calls a Java method with a variable number of arguments, passed via
3901    a va_list, and returns a float.
3902
3903 *******************************************************************************/
3904
3905 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3906 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
3907                                                                   va_list ap)
3908 {
3909         s4      vmargscount;
3910         vm_arg *vmargs;
3911         float   f;
3912         s4      dumpsize;
3913
3914         /* mark start of dump memory area */
3915
3916         dumpsize = dump_size();
3917
3918         /* get number of Java method arguments */
3919
3920         vmargscount = m->parseddesc->paramcount;
3921
3922         /* allocate vm_arg array */
3923
3924         vmargs = DMNEW(vm_arg, vmargscount);
3925
3926         /* fill the vm_arg array from a va_list */
3927
3928         vm_vmargs_from_valist(m, o, vmargs, ap);
3929
3930         /* call the Java method */
3931
3932         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3933
3934         /* release dump area */
3935
3936         dump_release(dumpsize);
3937
3938         return f;
3939 }
3940 #else
3941 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o, va_list ap)
3942 {
3943         int32_t   dumpsize;
3944         uint64_t *array;
3945         float     f;
3946
3947         /* mark start of dump memory area */
3948
3949         dumpsize = dump_size();
3950
3951         /* fill the argument array from a va_list */
3952
3953         array = vm_array_from_valist(m, o, ap);
3954
3955         /* call the Java method */
3956
3957         f = vm_call_float_array(m, array);
3958
3959         /* release dump area */
3960
3961         dump_release(dumpsize);
3962
3963         return f;
3964 }
3965 #endif
3966
3967 /* vm_call_method_float_jvalue *************************************************
3968
3969    Calls a Java method with a variable number of arguments, passed via
3970    a jvalue array, and returns a float.
3971
3972 *******************************************************************************/
3973
3974 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3975 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
3976                                                                   const jvalue *args)
3977 {
3978         s4      vmargscount;
3979         vm_arg *vmargs;
3980         float   f;
3981         s4      dumpsize;
3982
3983         /* mark start of dump memory area */
3984
3985         dumpsize = dump_size();
3986
3987         /* get number of Java method arguments */
3988
3989         vmargscount = m->parseddesc->paramcount;
3990
3991         /* allocate vm_arg array */
3992
3993         vmargs = DMNEW(vm_arg, vmargscount);
3994
3995         /* fill the vm_arg array from a va_list */
3996
3997         vm_vmargs_from_jvalue(m, o, vmargs, args);
3998
3999         /* call the Java method */
4000
4001         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
4002
4003         /* release dump area */
4004
4005         dump_release(dumpsize);
4006
4007         return f;
4008 }
4009 #else
4010 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4011 {
4012         int32_t   dumpsize;
4013         uint64_t *array;
4014         float     f;
4015
4016         /* mark start of dump memory area */
4017
4018         dumpsize = dump_size();
4019
4020         /* fill the argument array from a va_list */
4021
4022         array = vm_array_from_jvalue(m, o, args);
4023
4024         /* call the Java method */
4025
4026         f = vm_call_float_array(m, array);
4027
4028         /* release dump area */
4029
4030         dump_release(dumpsize);
4031
4032         return f;
4033 }
4034 #endif
4035
4036
4037 /* vm_call_double_array ********************************************************
4038
4039    Calls a Java method with a variable number of arguments and returns
4040    a double.
4041
4042 *******************************************************************************/
4043
4044 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4045 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
4046                                                                    vm_arg *vmargs)
4047 {
4048         double d;
4049
4050         vm_abort("IMPLEMENT ME!");
4051
4052         STATISTICS(count_calls_native_to_java++);
4053
4054 #if defined(ENABLE_JIT)
4055 # if defined(ENABLE_INTRP)
4056         if (opt_intrp)
4057                 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4058         else
4059 # endif
4060                 d = asm_vm_call_method_double(m, vmargscount, vmargs);
4061 #else
4062         d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4063 #endif
4064
4065         return d;
4066 }
4067 #else
4068 double vm_call_double_array(methodinfo *m, uint64_t *array)
4069 {
4070         methoddesc *md;
4071         double      d;
4072
4073         md = m->parseddesc;
4074
4075         /* compile the method if not already done */
4076
4077         if (m->code == NULL)
4078                 if (!jit_compile(m))
4079                         return 0;
4080
4081         STATISTICS(count_calls_native_to_java++);
4082
4083 #if defined(ENABLE_JIT)
4084 # if defined(ENABLE_INTRP)
4085         if (opt_intrp)
4086                 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4087         else
4088 # endif
4089                 d = asm_vm_call_method_double(m->code->entrypoint, array, md->memuse);
4090 #else
4091         d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4092 #endif
4093
4094         return d;
4095 }
4096 #endif
4097
4098
4099 /* vm_call_method_double *******************************************************
4100
4101    Calls a Java method with a variable number of arguments and returns
4102    a double.
4103
4104 *******************************************************************************/
4105
4106 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
4107 {
4108         va_list ap;
4109         double  d;
4110
4111         va_start(ap, o);
4112         d = vm_call_method_double_valist(m, o, ap);
4113         va_end(ap);
4114
4115         return d;
4116 }
4117
4118
4119 /* vm_call_method_double_valist ************************************************
4120
4121    Calls a Java method with a variable number of arguments, passed via
4122    a va_list, and returns a double.
4123
4124 *******************************************************************************/
4125
4126 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4127 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
4128                                                                         va_list ap)
4129 {
4130         s4      vmargscount;
4131         vm_arg *vmargs;
4132         double  d;
4133         s4      dumpsize;
4134
4135         /* mark start of dump memory area */
4136
4137         dumpsize = dump_size();
4138
4139         /* get number of Java method arguments */
4140
4141         vmargscount = m->parseddesc->paramcount;
4142
4143         /* allocate vm_arg array */
4144
4145         vmargs = DMNEW(vm_arg, vmargscount);
4146
4147         /* fill the vm_arg array from a va_list */
4148
4149         vm_vmargs_from_valist(m, o, vmargs, ap);
4150
4151         /* call the Java method */
4152
4153         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4154
4155         /* release dump area */
4156
4157         dump_release(dumpsize);
4158
4159         return d;
4160 }
4161 #else
4162 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o, va_list ap)
4163 {
4164         int32_t   dumpsize;
4165         uint64_t *array;
4166         double    d;
4167
4168         /* mark start of dump memory area */
4169
4170         dumpsize = dump_size();
4171
4172         /* fill the argument array from a va_list */
4173
4174         array = vm_array_from_valist(m, o, ap);
4175
4176         /* call the Java method */
4177
4178         d = vm_call_double_array(m, array);
4179
4180         /* release dump area */
4181
4182         dump_release(dumpsize);
4183
4184         return d;
4185 }
4186 #endif
4187
4188
4189 /* vm_call_method_double_jvalue ************************************************
4190
4191    Calls a Java method with a variable number of arguments, passed via
4192    a jvalue array, and returns a double.
4193
4194 *******************************************************************************/
4195
4196 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4197 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
4198                                                                         const jvalue *args)
4199 {
4200         s4      vmargscount;
4201         vm_arg *vmargs;
4202         double  d;
4203         s4      dumpsize;
4204
4205         /* mark start of dump memory area */
4206
4207         dumpsize = dump_size();
4208
4209         /* get number of Java method arguments */
4210
4211         vmargscount = m->parseddesc->paramcount;
4212
4213         /* allocate vm_arg array */
4214
4215         vmargs = DMNEW(vm_arg, vmargscount);
4216
4217         /* fill the vm_arg array from a va_list */
4218
4219         vm_vmargs_from_jvalue(m, o, vmargs, args);
4220
4221         /* call the Java method */
4222
4223         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4224
4225         /* release dump area */
4226
4227         dump_release(dumpsize);
4228
4229         return d;
4230 }
4231 #else
4232 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4233 {
4234         int32_t   dumpsize;
4235         uint64_t *array;
4236         double    d;
4237
4238         /* mark start of dump memory area */
4239
4240         dumpsize = dump_size();
4241
4242         /* fill the argument array from a va_list */
4243
4244         array = vm_array_from_jvalue(m, o, args);
4245
4246         /* call the Java method */
4247
4248         d = vm_call_double_array(m, array);
4249
4250         /* release dump area */
4251
4252         dump_release(dumpsize);
4253
4254         return d;
4255 }
4256 #endif
4257
4258 /*
4259  * These are local overrides for various environment variables in Emacs.
4260  * Please do not remove this and leave it at the end of the file, where
4261  * Emacs will automagically detect them.
4262  * ---------------------------------------------------------------------
4263  * Local variables:
4264  * mode: c
4265  * indent-tabs-mode: t
4266  * c-basic-offset: 4
4267  * tab-width: 4
4268  * End:
4269  */