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