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