* src/vm/vm.c (vm_abort): New method.
[cacao.git] / src / vm / vm.c
1 /* src/vm/finalizer.c - finalizer linked list and thread
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes: Martin Platter
30
31    $Id: finalizer.c 4357 2006-01-22 23:33:38Z twisti $
32
33 */
34
35
36 #include "config.h"
37
38 #include <assert.h>
39 #include <stdlib.h>
40
41 #include "vm/types.h"
42
43 #include "mm/boehm.h"
44 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/native.h"
47
48 #if defined(ENABLE_THREADS)
49 # include "threads/native/threads.h"
50 #endif
51
52 #include "vm/classcache.h"
53 #include "vm/exceptions.h"
54 #include "vm/finalizer.h"
55 #include "vm/global.h"
56 #include "vm/initialize.h"
57 #include "vm/options.h"
58 #include "vm/properties.h"
59 #include "vm/signallocal.h"
60 #include "vm/stringlocal.h"
61 #include "vm/suck.h"
62 #include "vm/vm.h"
63 #include "vm/jit/jit.h"
64 #include "vm/jit/asmpart.h"
65 #include "vm/jit/profile/profile.h"
66 #include "vm/rt-timing.h"
67
68 #if defined(ENABLE_JVMTI)
69 #include "native/jvmti/cacaodbg.h"
70 #endif
71
72 /* Invocation API variables ***************************************************/
73
74 _Jv_JavaVM *_Jv_jvm;                    /* denotes a Java VM                  */
75 _Jv_JNIEnv *_Jv_env;                    /* pointer to native method interface */
76
77
78 /* global variables ***********************************************************/
79
80 s4 vms = 0;                             /* number of VMs created              */
81
82 bool vm_initializing = false;
83 bool vm_exiting = false;
84
85 #if defined(ENABLE_INTRP)
86 u1 *intrp_main_stack = NULL;
87 #endif
88
89 char *mainstring = NULL;
90 classinfo *mainclass = NULL;
91
92 char *specificmethodname = NULL;
93 char *specificsignature = NULL;
94
95 bool startit = true;
96
97
98 /* define heap sizes **********************************************************/
99
100 #define HEAP_MAXSIZE      64 * 1024 * 1024  /* default 64MB                   */
101 #define HEAP_STARTSIZE    2  * 1024 * 1024  /* default 2MB                    */
102 #define STACK_SIZE              128 * 1024  /* default 128kB                  */
103
104
105 /* define command line options ************************************************/
106
107 enum {
108         /* Java options */
109
110         OPT_JAR,
111
112         OPT_D32,
113         OPT_D64,
114
115         OPT_CLASSPATH,
116         OPT_D,
117
118         OPT_VERBOSE,
119
120         OPT_VERSION,
121         OPT_SHOWVERSION,
122         OPT_FULLVERSION,
123
124         OPT_HELP,
125         OPT_X,
126
127         /* Java non-standard options */
128
129         OPT_JIT,
130         OPT_INTRP,
131
132         OPT_BOOTCLASSPATH,
133         OPT_BOOTCLASSPATH_A,
134         OPT_BOOTCLASSPATH_P,
135
136         OPT_PROF,
137         OPT_PROF_OPTION,
138
139         OPT_MS,
140         OPT_MX,
141
142         /* CACAO options */
143
144         OPT_VERBOSE1,
145         OPT_NOIEEE,
146         OPT_SOFTNULL,
147
148 #if defined(ENABLE_STATISTICS)
149         OPT_TIME,
150         OPT_STAT,
151 #endif
152
153         OPT_LOG,
154         OPT_CHECK,
155         OPT_LOAD,
156         OPT_METHOD,
157         OPT_SIGNATURE,
158         OPT_SHOW,
159         OPT_ALL,
160
161 #if defined(ENABLE_VERIFIER)
162         OPT_NOVERIFY,
163 #if defined(TYPECHECK_VERBOSE)
164         OPT_VERBOSETC,
165 #endif
166 #endif /* defined(ENABLE_VERIFIER) */
167         OPT_EAGER,
168
169         /* optimization options */
170
171 #if defined(ENABLE_LOOP)
172         OPT_OLOOP,
173 #endif
174         
175 #if defined(ENABLE_IFCONV)
176         OPT_IFCONV,
177 #endif
178
179 #if defined(ENABLE_LSRA)
180         OPT_LSRA,
181 #endif
182
183 #if defined(ENABLE_INLINING)
184         OPT_INLINING,
185 #endif
186
187 #if defined(ENABLE_INTRP)
188         /* interpreter options */
189
190         OPT_NO_DYNAMIC,
191         OPT_NO_REPLICATION,
192         OPT_NO_QUICKSUPER,
193         OPT_STATIC_SUPERS,
194         OPT_TRACE,
195 #endif
196
197         OPT_SS,
198
199 #ifdef ENABLE_JVMTI
200         OPT_DEBUG,
201         OPT_XRUNJDWP,
202         OPT_NOAGENT,
203         OPT_AGENTLIB,
204         OPT_AGENTPATH,
205 #endif
206
207         DUMMY
208 };
209
210
211 opt_struct opts[] = {
212         /* Java options */
213
214         { "jar",               false, OPT_JAR },
215
216         { "d32",               false, OPT_D32 },
217         { "d64",               false, OPT_D64 },
218         { "client",            false, OPT_IGNORE },
219         { "server",            false, OPT_IGNORE },
220         { "hotspot",           false, OPT_IGNORE },
221
222         { "classpath",         true,  OPT_CLASSPATH },
223         { "cp",                true,  OPT_CLASSPATH },
224         { "D",                 true,  OPT_D },
225         { "version",           false, OPT_VERSION },
226         { "showversion",       false, OPT_SHOWVERSION },
227         { "fullversion",       false, OPT_FULLVERSION },
228         { "help",              false, OPT_HELP },
229         { "?",                 false, OPT_HELP },
230         { "X",                 false, OPT_X },
231
232         { "noasyncgc",         false, OPT_IGNORE },
233 #if defined(ENABLE_VERIFIER)
234         { "noverify",          false, OPT_NOVERIFY },
235 #endif
236         { "v",                 false, OPT_VERBOSE1 },
237         { "verbose:",          true,  OPT_VERBOSE },
238
239 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
240         { "verbosetc",         false, OPT_VERBOSETC },
241 #endif
242 #if defined(__ALPHA__)
243         { "noieee",            false, OPT_NOIEEE },
244 #endif
245         { "softnull",          false, OPT_SOFTNULL },
246 #if defined(ENABLE_STATISTICS)
247         { "time",              false, OPT_TIME },
248         { "stat",              false, OPT_STAT },
249 #endif
250         { "log",               true,  OPT_LOG },
251         { "c",                 true,  OPT_CHECK },
252         { "l",                 false, OPT_LOAD },
253         { "eager",             false, OPT_EAGER },
254         { "sig",               true,  OPT_SIGNATURE },
255         { "all",               false, OPT_ALL },
256 #if defined(ENABLE_LOOP)
257         { "oloop",             false, OPT_OLOOP },
258 #endif
259 #if defined(ENABLE_IFCONV)
260         { "ifconv",            false, OPT_IFCONV },
261 #endif
262 #if defined(ENABLE_LSRA)
263         { "lsra",              false, OPT_LSRA },
264 #endif
265
266 #if defined(ENABLE_INTRP)
267         /* interpreter options */
268
269         { "trace",             false, OPT_TRACE },
270         { "static-supers",     true,  OPT_STATIC_SUPERS },
271         { "no-dynamic",        false, OPT_NO_DYNAMIC },
272         { "no-replication",    false, OPT_NO_REPLICATION },
273         { "no-quicksuper",     false, OPT_NO_QUICKSUPER },
274 #endif
275
276         /* JVMTI Agent Command Line Options */
277 #ifdef ENABLE_JVMTI
278         { "agentlib:",         true,  OPT_AGENTLIB },
279         { "agentpath:",        true,  OPT_AGENTPATH },
280 #endif
281
282         /* Java non-standard options */
283
284         { "Xjit",              false, OPT_JIT },
285         { "Xint",              false, OPT_INTRP },
286         { "Xbootclasspath:",   true,  OPT_BOOTCLASSPATH },
287         { "Xbootclasspath/a:", true,  OPT_BOOTCLASSPATH_A },
288         { "Xbootclasspath/p:", true,  OPT_BOOTCLASSPATH_P },
289 #ifdef ENABLE_JVMTI
290         { "Xdebug",            false, OPT_DEBUG },
291         { "Xnoagent",          false, OPT_NOAGENT },
292         { "Xrunjdwp",          true,  OPT_XRUNJDWP },
293 #endif 
294         { "Xms",               true,  OPT_MS },
295         { "ms",                true,  OPT_MS },
296         { "Xmx",               true,  OPT_MX },
297         { "mx",                true,  OPT_MX },
298         { "Xss",               true,  OPT_SS },
299         { "ss",                true,  OPT_SS },
300         { "Xprof:",            true,  OPT_PROF_OPTION },
301         { "Xprof",             false, OPT_PROF },
302
303         /* keep these at the end of the list */
304
305 #if defined(ENABLE_INLINING)
306         { "i",                 true,  OPT_INLINING },
307 #endif
308         { "m",                 true,  OPT_METHOD },
309         { "s",                 true,  OPT_SHOW },
310
311         { NULL,                false, 0 }
312 };
313
314
315 /* usage ***********************************************************************
316
317    Prints the correct usage syntax to stdout.
318
319 *******************************************************************************/
320
321 void usage(void)
322 {
323         puts("Usage: cacao [-options] classname [arguments]");
324         puts("               (to run a class file)");
325         puts("   or  cacao [-options] -jar jarfile [arguments]");
326         puts("               (to run a standalone jar file)\n");
327
328         puts("Java options:");
329         puts("    -d32                     use 32-bit data model if available");
330         puts("    -d64                     use 64-bit data model if available");
331         puts("    -client                  compatibility (currently ignored)");
332         puts("    -server                  compatibility (currently ignored)");
333         puts("    -hotspot                 compatibility (currently ignored)\n");
334
335         puts("    -cp <path>               specify a path to look for classes");
336         puts("    -classpath <path>        specify a path to look for classes");
337         puts("    -D<name>=<value>         add an entry to the property list");
338         puts("    -verbose[:class|gc|jni]  enable specific verbose output");
339         puts("    -version                 print product version and exit");
340         puts("    -fullversion             print jpackage-compatible product version and exit");
341         puts("    -showversion             print product version and continue");
342         puts("    -help, -?                print this help message");
343         puts("    -X                       print help on non-standard Java options\n");
344
345 #ifdef ENABLE_JVMTI
346         puts("    -agentlib:<agent-lib-name>=<options>  library to load containg JVMTI agent");
347         puts("    -agentpath:<path-to-agent>=<options>  path to library containg JVMTI agent");
348 #endif
349
350         puts("CACAO options:\n");
351         puts("    -v                       write state-information");
352         puts("    -verbose[:call|exception]enable specific verbose output");
353 #ifdef TYPECHECK_VERBOSE
354         puts("    -verbosetc               write debug messages while typechecking");
355 #endif
356 #if defined(__ALPHA__)
357         puts("    -noieee                  don't use ieee compliant arithmetic");
358 #endif
359 #if defined(ENABLE_VERIFIER)
360         puts("    -noverify                don't verify classfiles");
361 #endif
362         puts("    -softnull                use software nullpointer check");
363 #if defined(ENABLE_STATISTICS)
364         puts("    -time                    measure the runtime");
365         puts("    -stat                    detailed compiler statistics");
366 #endif
367         puts("    -log logfile             specify a name for the logfile");
368         puts("    -c(heck)b(ounds)         don't check array bounds");
369         puts("            s(ync)           don't check for synchronization");
370 #if defined(ENABLE_LOOP)
371         puts("    -oloop                   optimize array accesses in loops");
372 #endif
373         puts("    -l                       don't start the class after loading");
374         puts("    -eager                   perform eager class loading and linking");
375         puts("    -all                     compile all methods, no execution");
376         puts("    -m                       compile only a specific method");
377         puts("    -sig                     specify signature for a specific method");
378         puts("    -s(how)a(ssembler)       show disassembled listing");
379         puts("           c(onstants)       show the constant pool");
380         puts("           d(atasegment)     show data segment listing");
381         puts("           e(xceptionstubs)  show disassembled exception stubs (only with -sa)");
382         puts("           i(ntermediate)    show intermediate representation");
383         puts("           m(ethods)         show class fields and methods");
384         puts("           n(ative)          show disassembled native stubs");
385         puts("           u(tf)             show the utf - hash");
386 #if defined(ENABLE_INLINING)
387         puts("    -i     n(line)           activate inlining");
388         puts("           v(irtual)         inline virtual methods (uses/turns rt option on)");
389         puts("           e(exception)      inline methods with exceptions");
390         puts("           p(aramopt)        optimize argument renaming");
391         puts("           o(utsiders)       inline methods of foreign classes");
392 #endif /* defined(ENABLE_INLINING) */
393 #if defined(ENABLE_IFCONV)
394         puts("    -ifconv                  use if-conversion");
395 #endif
396 #if defined(ENABLE_LSRA)
397         puts("    -lsra                    use linear scan register allocation");
398 #endif
399
400         /* exit with error code */
401
402         exit(1);
403 }   
404
405
406 static void Xusage(void)
407 {
408 #if defined(ENABLE_JIT)
409         puts("    -Xjit                    JIT mode execution (default)");
410 #endif
411 #if defined(ENABLE_INTRP)
412         puts("    -Xint                    interpreter mode execution");
413 #endif
414         puts("    -Xbootclasspath:<zip/jar files and directories separated by :>");
415     puts("                             value is set as bootstrap class path");
416         puts("    -Xbootclasspath/a:<zip/jar files and directories separated by :>");
417         puts("                             value is appended to the bootstrap class path");
418         puts("    -Xbootclasspath/p:<zip/jar files and directories separated by :>");
419         puts("                             value is prepended to the bootstrap class path");
420         puts("    -Xms<size>               set the initial size of the heap (default: 2MB)");
421         puts("    -Xmx<size>               set the maximum size of the heap (default: 64MB)");
422         puts("    -Xss<size>               set the thread stack size (default: 128kB)");
423         puts("    -Xprof[:bb]              collect and print profiling data");
424 #if defined(ENABLE_JVMTI)
425     /* -Xdebug option depend on gnu classpath JDWP options. options: 
426          transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
427         puts("    -Xdebug           enable remote debugging\n");
428         puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
429         puts("                      enable remote debugging\n");
430 #endif 
431
432         /* exit with error code */
433
434         exit(1);
435 }   
436
437
438 /* version *********************************************************************
439
440    Only prints cacao version information.
441
442 *******************************************************************************/
443
444 static void version(void)
445 {
446         puts("java version \""JAVA_VERSION"\"");
447         puts("CACAO version "VERSION"");
448
449         puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
450         puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
451         puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
452         puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
453
454         puts("This program is free software; you can redistribute it and/or");
455         puts("modify it under the terms of the GNU General Public License as");
456         puts("published by the Free Software Foundation; either version 2, or (at");
457         puts("your option) any later version.\n");
458
459         puts("This program is distributed in the hope that it will be useful, but");
460         puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
461         puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU");
462         puts("General Public License for more details.\n");
463
464         puts("Configure/Build options:\n");
465         puts("  ./configure: "VERSION_CONFIGURE_ARGS"");
466 #if defined(__VERSION__)
467         puts("  CC         : "VERSION_CC" ("__VERSION__")");
468 #else
469         puts("  CC         : "VERSION_CC"");
470 #endif
471         puts("  CFLAGS     : "VERSION_CFLAGS"\n");
472
473         puts("Default classpath variables:\n");
474         puts("  java.boot.class.path    : "CACAO_VM_ZIP_PATH":"CLASSPATH_GLIBJ_ZIP_PATH"");
475         puts("  java.library.path       : "CLASSPATH_LIBRARY_PATH"\n");
476
477         puts("Runtime classpath variables:\n");
478         printf("  java.boot.class.path    : %s\n", bootclasspath);
479 }
480
481
482 /* fullversion *****************************************************************
483
484    Prints a Sun compatible version information (required e.g. by
485    jpackage, www.jpackage.org).
486
487 *******************************************************************************/
488
489 static void fullversion(void)
490 {
491         puts("java full version \"cacao-"JAVA_VERSION"\"");
492
493         /* exit normally */
494
495         exit(0);
496 }
497
498
499 /* vm_create *******************************************************************
500
501    Creates a JVM.  Called by JNI_CreateJavaVM.
502
503 *******************************************************************************/
504
505 bool vm_create(JavaVMInitArgs *vm_args)
506 {
507         char *cp;
508         s4    cplen;
509         u4    heapmaxsize;
510         u4    heapstartsize;
511         s4    opt;
512         s4    i, j, k;
513
514
515 #if defined(ENABLE_JVMTI)
516         lt_dlhandle  handle;
517         char* libname;
518         bool agentbypath = false;;
519 #endif
520         
521
522
523         /* check the JNI version requested */
524
525         switch (vm_args->version) {
526         case JNI_VERSION_1_1:
527                 break;
528         case JNI_VERSION_1_2:
529         case JNI_VERSION_1_4:
530                 break;
531         default:
532                 return false;
533         }
534
535         /* we only support 1 JVM instance */
536
537         if (vms > 0)
538                 return false;
539
540
541         /* get stuff from the environment *****************************************/
542
543 #if defined(DISABLE_GC)
544         nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
545 #endif
546
547
548         /* set the bootclasspath */
549
550         cp = getenv("BOOTCLASSPATH");
551
552         if (cp) {
553                 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
554                 strcpy(bootclasspath, cp);
555
556         } else {
557                 cplen = strlen(CACAO_VM_ZIP_PATH) +
558                         strlen(":") +
559                         strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
560                         strlen("0");
561
562                 bootclasspath = MNEW(char, cplen);
563                 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
564                 strcat(bootclasspath, ":");
565                 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
566         }
567
568
569         /* set the classpath */
570
571         cp = getenv("CLASSPATH");
572
573         if (cp) {
574                 classpath = MNEW(char, strlen(cp) + strlen("0"));
575                 strcat(classpath, cp);
576
577         } else {
578                 classpath = MNEW(char, strlen(".") + strlen("0"));
579                 strcpy(classpath, ".");
580         }
581
582
583         /* interpret the options **************************************************/
584    
585         checknull  = false;
586         opt_noieee = false;
587
588         heapmaxsize   = HEAP_MAXSIZE;
589         heapstartsize = HEAP_STARTSIZE;
590         opt_stacksize = STACK_SIZE;
591
592
593 #if defined(ENABLE_JVMTI)
594         /* initialize JVMTI related  **********************************************/
595         jdwp = jvmti = false;
596 #endif
597
598         /* initialize properties before commandline handling */
599
600         if (!properties_init())
601                 throw_cacao_exception_exit(string_java_lang_InternalError,
602                                                                    "Unable to init properties");
603
604         /* add some default properties */
605
606         properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
607
608
609         /* iterate over all passed options */
610
611         while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
612                 switch (opt) {
613                 case OPT_IGNORE:
614                         break;
615                         
616                 case OPT_JAR:
617                         opt_jar = true;
618                         break;
619
620                 case OPT_D32:
621 #if SIZEOF_VOID_P == 8
622                         puts("Running a 32-bit JVM is not supported on this platform.");
623                         exit(1);
624 #endif
625                         break;
626
627                 case OPT_D64:
628 #if SIZEOF_VOID_P == 4
629                         puts("Running a 64-bit JVM is not supported on this platform.");
630                         exit(1);
631 #endif
632                         break;
633
634                 case OPT_CLASSPATH:
635                         /* forget old classpath and set the argument as new classpath */
636                         MFREE(classpath, char, strlen(classpath));
637
638                         classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
639                         strcpy(classpath, opt_arg);
640                         break;
641
642                 case OPT_D:
643                         for (j = 0; j < strlen(opt_arg); j++) {
644                                 if (opt_arg[j] == '=') {
645                                         opt_arg[j] = '\0';
646                                         properties_add(opt_arg, opt_arg + j + 1);
647                                         goto didit;
648                                 }
649                         }
650
651                         /* if no '=' is given, just create an empty property */
652
653                         properties_add(opt_arg, "");
654
655                 didit:
656                         break;
657
658                 case OPT_BOOTCLASSPATH:
659                         /* Forget default bootclasspath and set the argument as
660                            new boot classpath. */
661                         MFREE(bootclasspath, char, strlen(bootclasspath));
662
663                         bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
664                         strcpy(bootclasspath, opt_arg);
665                         break;
666
667                 case OPT_BOOTCLASSPATH_A:
668                         /* append to end of bootclasspath */
669                         cplen = strlen(bootclasspath);
670
671                         bootclasspath = MREALLOC(bootclasspath,
672                                                                          char,
673                                                                          cplen,
674                                                                          cplen + strlen(":") +
675                                                                          strlen(opt_arg) + strlen("0"));
676
677                         strcat(bootclasspath, ":");
678                         strcat(bootclasspath, opt_arg);
679                         break;
680
681                 case OPT_BOOTCLASSPATH_P:
682                         /* prepend in front of bootclasspath */
683                         cp = bootclasspath;
684                         cplen = strlen(cp);
685
686                         bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
687                                                                  cplen + strlen("0"));
688
689                         strcpy(bootclasspath, opt_arg);
690                         strcat(bootclasspath, ":");
691                         strcat(bootclasspath, cp);
692
693                         MFREE(cp, char, cplen);
694                         break;
695
696 #if defined(ENABLE_JVMTI)
697                 case OPT_DEBUG:
698                         jdwp=true;
699                         break;
700                 case OPT_NOAGENT:
701                         /* I don't know yet what Xnoagent should do. This is only for 
702                            compatiblity with eclipse - motse */
703                         break;
704                 case OPT_XRUNJDWP:
705                         transport = opt_arg;
706                         j=0;
707                         while (transport[j]!='=') j++;
708                         j++;
709                         while (j<strlen(transport)) {
710                                 if (strncmp("suspend=",&transport[j],8)==0) {
711                                         if ((j+8)>=strlen(transport) || 
712                                                 (transport[j+8]!= 'y' && transport[j+8]!= 'n')) {
713                                                 printf("bad Xrunjdwp option: -Xrunjdwp%s\n",transport);
714                                                 usage();
715                                                 break;
716                                         }
717                                         else {
718                                                 suspend = transport[j+8] == 'y';
719                                                 break;
720                                         }
721                                 }
722                                 while (transport[j]!=',') j++;
723                                 j++;
724                         }
725                         
726                         break;
727
728                 case OPT_AGENTPATH:
729                         agentbypath = true;
730                 case OPT_AGENTLIB:
731                         jvmti=true;
732                         agentarg = opt_arg;
733                         break;
734 #endif
735                         
736                 case OPT_MX:
737                 case OPT_MS:
738                 case OPT_SS:
739                         {
740                                 char c;
741                                 c = opt_arg[strlen(opt_arg) - 1];
742
743                                 if ((c == 'k') || (c == 'K')) {
744                                         j = atoi(opt_arg) * 1024;
745
746                                 } else if ((c == 'm') || (c == 'M')) {
747                                         j = atoi(opt_arg) * 1024 * 1024;
748
749                                 } else
750                                         j = atoi(opt_arg);
751
752                                 if (opt == OPT_MX)
753                                         heapmaxsize = j;
754                                 else if (opt == OPT_MS)
755                                         heapstartsize = j;
756                                 else
757                                         opt_stacksize = j;
758                         }
759                         break;
760
761                 case OPT_VERBOSE1:
762                         opt_verbose = true;
763                         break;
764
765                 case OPT_VERBOSE:
766                         if (strcmp("class", opt_arg) == 0)
767                                 opt_verboseclass = true;
768
769                         else if (strcmp("gc", opt_arg) == 0)
770                                 opt_verbosegc = true;
771
772                         else if (strcmp("jni", opt_arg) == 0)
773                                 opt_verbosejni = true;
774
775                         else if (strcmp("call", opt_arg) == 0)
776                                 opt_verbosecall = true;
777
778                         else if (strcmp("jit", opt_arg) == 0) {
779                                 opt_verbose = true;
780                                 loadverbose = true;
781                                 linkverbose = true;
782                                 initverbose = true;
783                                 compileverbose = true;
784                         }
785                         else if (strcmp("exception", opt_arg) == 0)
786                                 opt_verboseexception = true;
787                         break;
788
789 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
790                 case OPT_VERBOSETC:
791                         opt_typecheckverbose = true;
792                         break;
793 #endif
794                                 
795                 case OPT_VERSION:
796                         version();
797                         exit(0);
798                         break;
799
800                 case OPT_FULLVERSION:
801                         fullversion();
802                         break;
803
804                 case OPT_SHOWVERSION:
805                         version();
806                         break;
807
808                 case OPT_NOIEEE:
809                         opt_noieee = true;
810                         break;
811
812 #if defined(ENABLE_VERIFIER)
813                 case OPT_NOVERIFY:
814                         opt_verify = false;
815                         break;
816 #endif
817
818                 case OPT_SOFTNULL:
819                         checknull = true;
820                         break;
821
822 #if defined(ENABLE_STATISTICS)
823                 case OPT_TIME:
824                         opt_getcompilingtime = true;
825                         opt_getloadingtime = true;
826                         break;
827                                         
828                 case OPT_STAT:
829                         opt_stat = true;
830                         break;
831 #endif
832                                         
833                 case OPT_LOG:
834                         log_init(opt_arg);
835                         break;
836                         
837                 case OPT_CHECK:
838                         for (j = 0; j < strlen(opt_arg); j++) {
839                                 switch (opt_arg[j]) {
840                                 case 'b':
841                                         checkbounds = false;
842                                         break;
843                                 case 's':
844                                         checksync = false;
845                                         break;
846                                 default:
847                                         usage();
848                                 }
849                         }
850                         break;
851                         
852                 case OPT_LOAD:
853                         opt_run = false;
854                         makeinitializations = false;
855                         break;
856
857                 case OPT_EAGER:
858                         opt_eager = true;
859                         break;
860
861                 case OPT_METHOD:
862                         opt_run = false;
863                         opt_method = opt_arg;
864                         makeinitializations = false;
865                         break;
866                         
867                 case OPT_SIGNATURE:
868                         opt_signature = opt_arg;
869                         break;
870                         
871                 case OPT_ALL:
872                         compileall = true;
873                         opt_run = false;
874                         makeinitializations = false;
875                         break;
876                         
877                 case OPT_SHOW:       /* Display options */
878                         for (j = 0; j < strlen(opt_arg); j++) {         
879                                 switch (opt_arg[j]) {
880                                 case 'a':
881                                         opt_showdisassemble = true;
882                                         compileverbose = true;
883                                         break;
884                                 case 'c':
885                                         showconstantpool = true;
886                                         break;
887                                 case 'd':
888                                         opt_showddatasegment = true;
889                                         break;
890                                 case 'e':
891                                         opt_showexceptionstubs = true;
892                                         break;
893                                 case 'i':
894                                         opt_showintermediate = true;
895                                         compileverbose = true;
896                                         break;
897                                 case 'm':
898                                         showmethods = true;
899                                         break;
900                                 case 'n':
901                                         opt_shownativestub = true;
902                                         break;
903                                 case 'u':
904                                         showutf = true;
905                                         break;
906                                 default:
907                                         usage();
908                                 }
909                         }
910                         break;
911                         
912 #if defined(ENABLE_LOOP)
913                 case OPT_OLOOP:
914                         opt_loops = true;
915                         break;
916 #endif
917
918 #if defined(ENABLE_INLINING)
919                 case OPT_INLINING:
920                         for (j = 0; j < strlen(opt_arg); j++) {         
921                                 switch (opt_arg[j]) {
922                                 case 'n':
923                                         /* define in options.h; Used in main.c, jit.c
924                                            & inline.c inlining is currently
925                                            deactivated */
926                                         break;
927                                 case 'v':
928                                         inlinevirtuals = true;
929                                         break;
930                                 case 'e':
931                                         inlineexceptions = true;
932                                         break;
933                                 case 'p':
934                                         inlineparamopt = true;
935                                         break;
936                                 case 'o':
937                                         inlineoutsiders = true;
938                                         break;
939                                 default:
940                                         usage();
941                                 }
942                         }
943                         break;
944 #endif /* defined(ENABLE_INLINING) */
945
946 #if defined(ENABLE_IFCONV)
947                 case OPT_IFCONV:
948                         opt_ifconv = true;
949                         break;
950 #endif
951
952 #if defined(ENABLE_LSRA)
953                 case OPT_LSRA:
954                         opt_lsra = true;
955                         break;
956 #endif
957
958                 case OPT_HELP:
959                         usage();
960                         break;
961
962                 case OPT_X:
963                         Xusage();
964                         break;
965
966                 case OPT_PROF_OPTION:
967                         /* use <= to get the last \0 too */
968
969                         for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
970                                 if (opt_arg[j] == ',')
971                                         opt_arg[j] = '\0';
972
973                                 if (opt_arg[j] == '\0') {
974                                         if (strcmp("bb", opt_arg + k) == 0)
975                                                 opt_prof_bb = true;
976
977                                         else {
978                                                 printf("Unknown option: -Xprof:%s\n", opt_arg + k);
979                                                 usage();
980                                         }
981
982                                         /* set k to next char */
983
984                                         k = j + 1;
985                                 }
986                         }
987                         /* fall through */
988
989                 case OPT_PROF:
990                         opt_prof = true;
991                         break;
992
993                 case OPT_JIT:
994 #if defined(ENABLE_JIT)
995                         opt_jit = true;
996 #else
997                         printf("-Xjit option not enabled.\n");
998                         exit(1);
999 #endif
1000                         break;
1001
1002                 case OPT_INTRP:
1003 #if defined(ENABLE_INTRP)
1004                         opt_intrp = true;
1005 #else
1006                         printf("-Xint option not enabled.\n");
1007                         exit(1);
1008 #endif
1009                         break;
1010
1011 #if defined(ENABLE_INTRP)
1012                 case OPT_STATIC_SUPERS:
1013                         opt_static_supers = atoi(opt_arg);
1014                         break;
1015
1016                 case OPT_NO_DYNAMIC:
1017                         opt_no_dynamic = true;
1018                         break;
1019
1020                 case OPT_NO_REPLICATION:
1021                         opt_no_replication = true;
1022                         break;
1023
1024                 case OPT_NO_QUICKSUPER:
1025                         opt_no_quicksuper = true;
1026                         break;
1027
1028                 case OPT_TRACE:
1029                         vm_debug = true;
1030                         break;
1031 #endif
1032
1033                 default:
1034                         printf("Unknown option: %s\n",
1035                                    vm_args->options[opt_index].optionString);
1036                         usage();
1037                 }
1038         }
1039
1040
1041         /* get the main class *****************************************************/
1042
1043         if (opt_index < vm_args->nOptions) {
1044                 mainstring = vm_args->options[opt_index++].optionString;
1045
1046                 /* Put the jar file into the classpath (if any). */
1047
1048                 if (opt_jar == true) {
1049                         /* free old classpath */
1050
1051                         MFREE(classpath, char, strlen(classpath));
1052
1053                         /* put jarfile into classpath */
1054
1055                         classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1056
1057                         strcpy(classpath, mainstring);
1058                 
1059                 } else {
1060                         /* replace .'s with /'s in classname */
1061
1062                         for (i = strlen(mainstring) - 1; i >= 0; i--)
1063                                 if (mainstring[i] == '.')
1064                                         mainstring[i] = '/';
1065                 }
1066         }
1067
1068 #if defined(ENABLE_JVMTI)
1069         if (jvmti) {
1070                 set_jvmti_phase(JVMTI_PHASE_ONLOAD);
1071                 agentload(agentarg, agentbypath, &handle, &libname);
1072         }
1073         set_jvmti_phase(JVMTI_PHASE_PRIMORDIAL);
1074 #endif
1075
1076
1077         /* initialize this JVM ****************************************************/
1078
1079         vm_initializing = true;
1080
1081         /* initialize the garbage collector */
1082
1083         gc_init(heapmaxsize, heapstartsize);
1084
1085 #if defined(ENABLE_INTRP)
1086         /* Allocate main thread stack on the Java heap. */
1087
1088         if (opt_intrp) {
1089                 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1090                 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1091         }
1092 #endif
1093
1094 #if defined(ENABLE_THREADS)
1095         threads_preinit();
1096 #endif
1097
1098         /* initialize the string hashtable stuff: lock (must be done
1099            _after_ threads_preinit) */
1100
1101         if (!string_init())
1102                 throw_main_exception_exit();
1103
1104         /* initialize the utf8 hashtable stuff: lock, often used utf8
1105            strings (must be done _after_ threads_preinit) */
1106
1107         if (!utf8_init())
1108                 throw_main_exception_exit();
1109
1110         /* initialize the classcache hashtable stuff: lock, hashtable
1111            (must be done _after_ threads_preinit) */
1112
1113         if (!classcache_init())
1114                 throw_main_exception_exit();
1115
1116         /* initialize the loader with bootclasspath (must be done _after_
1117            thread_preinit) */
1118
1119         if (!suck_init())
1120                 throw_main_exception_exit();
1121
1122         suck_add_from_property("java.endorsed.dirs");
1123         suck_add(bootclasspath);
1124
1125         /* initialize the memory subsystem (must be done _after_
1126            threads_preinit) */
1127
1128         if (!memory_init())
1129                 throw_main_exception_exit();
1130
1131         /* initialize the finalizer stuff (must be done _after_
1132            threads_preinit) */
1133
1134         if (!finalizer_init())
1135                 throw_main_exception_exit();
1136
1137         /* install architecture dependent signal handler used for exceptions */
1138
1139         signal_init();
1140
1141         /* initialize the codegen subsystems */
1142
1143         codegen_init();
1144
1145         /* initializes jit compiler */
1146
1147         jit_init();
1148
1149         /* machine dependent initialization */
1150
1151 #if defined(ENABLE_JIT)
1152 # if defined(ENABLE_INTRP)
1153         if (opt_intrp)
1154                 intrp_md_init();
1155         else
1156 # endif
1157                 md_init();
1158 #else
1159         intrp_md_init();
1160 #endif
1161
1162         /* initialize the loader subsystems (must be done _after_
1163        classcache_init) */
1164
1165         if (!loader_init())
1166                 throw_main_exception_exit();
1167
1168         if (!linker_init())
1169                 throw_main_exception_exit();
1170
1171         if (!native_init())
1172                 throw_main_exception_exit();
1173
1174         if (!exceptions_init())
1175                 throw_main_exception_exit();
1176
1177         if (!builtin_init())
1178                 throw_main_exception_exit();
1179
1180         /* Initialize the JNI subsystem (must be done _before_
1181            threads_init, as threads_init can call JNI methods
1182            (e.g. NewGlobalRef). */
1183
1184         if (!jni_init())
1185                 throw_main_exception_exit();
1186
1187 #if defined(ENABLE_THREADS)
1188         if (!threads_init())
1189                 throw_main_exception_exit();
1190 #endif
1191
1192         /* That's important, otherwise we get into trouble, if the Runtime
1193            static initializer is called before (circular dependency. This
1194            is with classpath 0.09. Another important thing is, that this
1195            has to happen after initThreads!!! */
1196
1197         if (!initialize_class(class_java_lang_System))
1198                 throw_main_exception_exit();
1199
1200 #if defined(ENABLE_PROFILING)
1201         /* initialize profiling */
1202
1203         if (!profile_init())
1204                 throw_main_exception_exit();
1205 #endif
1206
1207 #if defined(ENABLE_THREADS)
1208         /* finally, start the finalizer thread */
1209
1210         if (!finalizer_start_thread())
1211                 throw_main_exception_exit();
1212
1213         /* start the profile sampling thread */
1214
1215 /*      if (!profile_start_thread()) */
1216 /*              throw_main_exception_exit(); */
1217 #endif
1218
1219 #if defined(ENABLE_JVMTI)
1220         if (jvmti) {
1221                 /* add agent library to native library hashtable */
1222                 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1223         }
1224 #endif
1225
1226         /* increment the number of VMs */
1227
1228         vms++;
1229
1230         /* initialization is done */
1231
1232         vm_initializing = false;
1233
1234         /* everything's ok */
1235
1236         return true;
1237 }
1238
1239
1240 /* vm_destroy ******************************************************************
1241
1242    Unloads a Java VM and reclaims its resources.
1243
1244 *******************************************************************************/
1245
1246 s4 vm_destroy(JavaVM *vm)
1247 {
1248 #if defined(ENABLE_THREADS)
1249         threads_join_all_threads();
1250 #endif
1251
1252         /* everything's ok */
1253
1254         return 0;
1255 }
1256
1257
1258 /* vm_exit *********************************************************************
1259
1260    Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1261
1262 *******************************************************************************/
1263
1264 void vm_exit(s4 status)
1265 {
1266         methodinfo *m;
1267
1268         /* signal that we are exiting */
1269
1270         vm_exiting = true;
1271
1272         assert(class_java_lang_System);
1273         assert(class_java_lang_System->state & CLASS_LOADED);
1274
1275 #if defined(ENABLE_JVMTI)
1276         set_jvmti_phase(JVMTI_PHASE_DEAD);
1277         if (jvmti) agentunload();
1278 #endif
1279
1280         if (!link_class(class_java_lang_System))
1281                 throw_main_exception_exit();
1282
1283         /* call java.lang.System.exit(I)V */
1284
1285         m = class_resolveclassmethod(class_java_lang_System,
1286                                                                  utf_new_char("exit"),
1287                                                                  utf_int__void,
1288                                                                  class_java_lang_Object,
1289                                                                  true);
1290         
1291         if (m == NULL)
1292                 throw_main_exception_exit();
1293
1294         /* call the exit function with passed exit status */
1295
1296         (void) vm_call_method(m, NULL, status);
1297
1298         /* If we had an exception, just ignore the exception and exit with
1299            the proper code. */
1300
1301         vm_shutdown(status);
1302 }
1303
1304
1305 /* vm_shutdown *****************************************************************
1306
1307    Terminates the system immediately without freeing memory explicitly
1308    (to be used only for abnormal termination).
1309         
1310 *******************************************************************************/
1311
1312 void vm_shutdown(s4 status)
1313 {
1314         if (opt_verbose 
1315 #if defined(ENABLE_STATISTICS)
1316                 || opt_getcompilingtime || opt_stat
1317 #endif
1318            ) 
1319         {
1320                 log_text("CACAO terminated by shutdown");
1321                 dolog("Exit status: %d\n", (s4) status);
1322         }
1323
1324         exit(status);
1325 }
1326
1327
1328 /* vm_exit_handler *************************************************************
1329
1330    The exit_handler function is called upon program termination.
1331
1332    ATTENTION: Don't free system resources here! Some threads may still
1333    be running as this is called from VMRuntime.exit(). The OS does the
1334    cleanup for us.
1335
1336 *******************************************************************************/
1337
1338 void vm_exit_handler(void)
1339 {
1340 #if !defined(NDEBUG)
1341         if (showmethods)
1342                 class_showmethods(mainclass);
1343
1344         if (showconstantpool)
1345                 class_showconstantpool(mainclass);
1346
1347         if (showutf)
1348                 utf_show();
1349
1350 # if defined(ENABLE_PROFILING)
1351         if (opt_prof)
1352                 profile_printstats();
1353 # endif
1354 #endif /* !defined(NDEBUG) */
1355
1356 #if defined(ENABLE_RT_TIMING)
1357         rt_timing_print_time_stats(stderr);
1358 #endif
1359
1360 #if defined(ENABLE_CYCLES_STATS)
1361         builtin_print_cycles_stats(stderr);
1362         stacktrace_print_cycles_stats(stderr);
1363 #endif
1364
1365         if (opt_verbose 
1366 #if defined(ENABLE_STATISTICS)
1367                 || opt_getcompilingtime || opt_stat
1368 #endif
1369            ) 
1370         {
1371                 log_text("CACAO terminated");
1372
1373 #if defined(ENABLE_STATISTICS)
1374                 if (opt_stat) {
1375                         print_stats();
1376 #ifdef TYPECHECK_STATISTICS
1377                         typecheck_print_statistics(get_logfile());
1378 #endif
1379                 }
1380
1381                 mem_usagelog(1);
1382
1383                 if (opt_getcompilingtime)
1384                         print_times();
1385 #endif /* defined(ENABLE_STATISTICS) */
1386         }
1387         /* vm_print_profile(stderr);*/
1388 }
1389
1390
1391 /* vm_abort ********************************************************************
1392
1393    Prints an error message and aborts the VM.
1394
1395 *******************************************************************************/
1396
1397 void vm_abort(const char *text, ...)
1398 {
1399         va_list ap;
1400
1401         /* print the log message */
1402
1403         log_start();
1404
1405         va_start(ap, text);
1406         log_vprint(text, ap);
1407         va_end(ap);
1408
1409         log_finish();
1410
1411         /* now abort the VM */
1412
1413         abort();
1414 }
1415
1416
1417 /* vm_vmargs_from_valist *******************************************************
1418
1419    XXX
1420
1421 *******************************************************************************/
1422
1423 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
1424                                                                   vm_arg *vmargs, va_list ap)
1425 {
1426         typedesc *paramtypes;
1427         s4        i;
1428
1429         paramtypes = m->parseddesc->paramtypes;
1430
1431         /* if method is non-static fill first block and skip `this' pointer */
1432
1433         i = 0;
1434
1435         if (o != NULL) {
1436                 /* the `this' pointer */
1437                 vmargs[0].type   = TYPE_ADR;
1438                 vmargs[0].data.l = (u8) (ptrint) o;
1439
1440                 paramtypes++;
1441                 i++;
1442         } 
1443
1444         for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
1445                 switch (paramtypes->decltype) {
1446                 /* primitive types */
1447                 case PRIMITIVETYPE_BOOLEAN: 
1448                 case PRIMITIVETYPE_BYTE:
1449                 case PRIMITIVETYPE_CHAR:
1450                 case PRIMITIVETYPE_SHORT: 
1451                 case PRIMITIVETYPE_INT:
1452                         vmargs[i].type   = TYPE_INT;
1453                         vmargs[i].data.l = (s8) va_arg(ap, s4);
1454                         break;
1455
1456                 case PRIMITIVETYPE_LONG:
1457                         vmargs[i].type   = TYPE_LNG;
1458                         vmargs[i].data.l = (s8) va_arg(ap, s8);
1459                         break;
1460
1461                 case PRIMITIVETYPE_FLOAT:
1462                         vmargs[i].type   = TYPE_FLT;
1463 #if defined(__ALPHA__)
1464                         /* this keeps the assembler function much simpler */
1465
1466                         vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1467 #else
1468                         vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
1469 #endif
1470                         break;
1471
1472                 case PRIMITIVETYPE_DOUBLE:
1473                         vmargs[i].type   = TYPE_DBL;
1474                         vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1475                         break;
1476
1477                 case TYPE_ADR: 
1478                         vmargs[i].type   = TYPE_ADR;
1479                         vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
1480                         break;
1481                 }
1482         }
1483 }
1484
1485
1486 /* vm_vmargs_from_jvalue *******************************************************
1487
1488    XXX
1489
1490 *******************************************************************************/
1491
1492 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
1493                                                                   vm_arg *vmargs, jvalue *args)
1494 {
1495         typedesc *paramtypes;
1496         s4        i;
1497         s4        j;
1498
1499         paramtypes = m->parseddesc->paramtypes;
1500
1501         /* if method is non-static fill first block and skip `this' pointer */
1502
1503         i = 0;
1504
1505         if (o != NULL) {
1506                 /* the `this' pointer */
1507                 vmargs[0].type   = TYPE_ADR;
1508                 vmargs[0].data.l = (u8) (ptrint) o;
1509
1510                 paramtypes++;
1511                 i++;
1512         } 
1513
1514         for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
1515                 switch (paramtypes->decltype) {
1516                 /* primitive types */
1517                 case PRIMITIVETYPE_BOOLEAN: 
1518                 case PRIMITIVETYPE_BYTE:
1519                 case PRIMITIVETYPE_CHAR:
1520                 case PRIMITIVETYPE_SHORT: 
1521                 case PRIMITIVETYPE_INT:
1522                         vmargs[i].type   = TYPE_INT;
1523                         vmargs[i].data.l = (s8) args[j].i;
1524                         break;
1525
1526                 case PRIMITIVETYPE_LONG:
1527                         vmargs[i].type   = TYPE_LNG;
1528                         vmargs[i].data.l = (s8) args[j].j;
1529                         break;
1530
1531                 case PRIMITIVETYPE_FLOAT:
1532                         vmargs[i].type = TYPE_FLT;
1533 #if defined(__ALPHA__)
1534                         /* this keeps the assembler function much simpler */
1535
1536                         vmargs[i].data.d = (jdouble) args[j].f;
1537 #else
1538                         vmargs[i].data.f = args[j].f;
1539 #endif
1540                         break;
1541
1542                 case PRIMITIVETYPE_DOUBLE:
1543                         vmargs[i].type   = TYPE_DBL;
1544                         vmargs[i].data.d = args[j].d;
1545                         break;
1546
1547                 case TYPE_ADR: 
1548                         vmargs[i].type   = TYPE_ADR;
1549                         vmargs[i].data.l = (u8) (ptrint) args[j].l;
1550                         break;
1551                 }
1552         }
1553 }
1554
1555
1556 /* vm_call_method **************************************************************
1557
1558    Calls a Java method with a variable number of arguments and returns
1559    an address.
1560
1561 *******************************************************************************/
1562
1563 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
1564 {
1565         va_list            ap;
1566         java_objectheader *ro;
1567
1568         va_start(ap, o);
1569         ro = vm_call_method_valist(m, o, ap);
1570         va_end(ap);
1571
1572         return ro;
1573 }
1574
1575
1576 /* vm_call_method_valist *******************************************************
1577
1578    Calls a Java method with a variable number of arguments, passed via
1579    a va_list, and returns an address.
1580
1581 *******************************************************************************/
1582
1583 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
1584                                                                                  va_list ap)
1585 {
1586         s4                 vmargscount;
1587         vm_arg            *vmargs;
1588         java_objectheader *ro;
1589         s4                 dumpsize;
1590
1591         /* mark start of dump memory area */
1592
1593         dumpsize = dump_size();
1594
1595         /* get number of Java method arguments */
1596
1597         vmargscount = m->parseddesc->paramcount;
1598
1599         /* allocate vm_arg array */
1600
1601         vmargs = DMNEW(vm_arg, vmargscount);
1602
1603         /* fill the vm_arg array from a va_list */
1604
1605         vm_vmargs_from_valist(m, o, vmargs, ap);
1606
1607         /* call the Java method */
1608
1609         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1610
1611         /* release dump area */
1612
1613         dump_release(dumpsize);
1614
1615         return ro;
1616 }
1617
1618
1619 /* vm_call_method_jvalue *******************************************************
1620
1621    Calls a Java method with a variable number of arguments, passed via
1622    a jvalue array, and returns an address.
1623
1624 *******************************************************************************/
1625
1626 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
1627                                                                                  jvalue *args)
1628 {
1629         s4                 vmargscount;
1630         vm_arg            *vmargs;
1631         java_objectheader *ro;
1632         s4                 dumpsize;
1633
1634         /* mark start of dump memory area */
1635
1636         dumpsize = dump_size();
1637
1638         /* get number of Java method arguments */
1639
1640         vmargscount = m->parseddesc->paramcount;
1641
1642         /* allocate vm_arg array */
1643
1644         vmargs = DMNEW(vm_arg, vmargscount);
1645
1646         /* fill the vm_arg array from a va_list */
1647
1648         vm_vmargs_from_jvalue(m, o, vmargs, args);
1649
1650         /* call the Java method */
1651
1652         ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1653
1654         /* release dump area */
1655
1656         dump_release(dumpsize);
1657
1658         return ro;
1659 }
1660
1661
1662 /* vm_call_method_vmarg ********************************************************
1663
1664    Calls a Java method with a variable number of arguments, passed via
1665    a vm_arg array, and returns an address.
1666
1667 *******************************************************************************/
1668
1669 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
1670                                                                                 vm_arg *vmargs)
1671 {
1672         java_objectheader *o;
1673
1674 #if defined(ENABLE_JIT)
1675 # if defined(ENABLE_INTRP)
1676         if (opt_intrp)
1677                 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1678         else
1679 # endif
1680                 o = asm_vm_call_method(m, vmargscount, vmargs);
1681 #else
1682         o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1683 #endif
1684
1685         return o;
1686 }
1687
1688
1689 /* vm_call_method_int **********************************************************
1690
1691    Calls a Java method with a variable number of arguments and returns
1692    an integer (s4).
1693
1694 *******************************************************************************/
1695
1696 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
1697 {
1698         va_list ap;
1699         s4      i;
1700
1701         va_start(ap, o);
1702         i = vm_call_method_int_valist(m, o, ap);
1703         va_end(ap);
1704
1705         return i;
1706 }
1707
1708
1709 /* vm_call_method_int_valist ***************************************************
1710
1711    Calls a Java method with a variable number of arguments, passed via
1712    a va_list, and returns an integer (s4).
1713
1714 *******************************************************************************/
1715
1716 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
1717 {
1718         s4      vmargscount;
1719         vm_arg *vmargs;
1720         s4      i;
1721         s4      dumpsize;
1722
1723         /* mark start of dump memory area */
1724
1725         dumpsize = dump_size();
1726
1727         /* get number of Java method arguments */
1728
1729         vmargscount = m->parseddesc->paramcount;
1730
1731         /* allocate vm_arg array */
1732
1733         vmargs = DMNEW(vm_arg, vmargscount);
1734
1735         /* fill the vm_arg array from a va_list */
1736
1737         vm_vmargs_from_valist(m, o, vmargs, ap);
1738
1739         /* call the Java method */
1740
1741         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1742
1743         /* release dump area */
1744
1745         dump_release(dumpsize);
1746
1747         return i;
1748 }
1749
1750
1751 /* vm_call_method_int_jvalue ***************************************************
1752
1753    Calls a Java method with a variable number of arguments, passed via
1754    a jvalue array, and returns an integer (s4).
1755
1756 *******************************************************************************/
1757
1758 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1759 {
1760         s4      vmargscount;
1761         vm_arg *vmargs;
1762         s4      i;
1763         s4      dumpsize;
1764
1765         /* mark start of dump memory area */
1766
1767         dumpsize = dump_size();
1768
1769         /* get number of Java method arguments */
1770
1771         vmargscount = m->parseddesc->paramcount;
1772
1773         /* allocate vm_arg array */
1774
1775         vmargs = DMNEW(vm_arg, vmargscount);
1776
1777         /* fill the vm_arg array from a va_list */
1778
1779         vm_vmargs_from_jvalue(m, o, vmargs, args);
1780
1781         /* call the Java method */
1782
1783         i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1784
1785         /* release dump area */
1786
1787         dump_release(dumpsize);
1788
1789         return i;
1790 }
1791
1792
1793 /* vm_call_method_int_vmarg ****************************************************
1794
1795    Calls a Java method with a variable number of arguments, passed via
1796    a vm_arg array, and returns an integer (s4).
1797
1798 *******************************************************************************/
1799
1800 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1801 {
1802         s4 i;
1803
1804 #if defined(ENABLE_JIT)
1805 # if defined(ENABLE_INTRP)
1806         if (opt_intrp)
1807                 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1808         else
1809 # endif
1810                 i = asm_vm_call_method_int(m, vmargscount, vmargs);
1811 #else
1812         i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1813 #endif
1814
1815         return i;
1816 }
1817
1818
1819 /* vm_call_method_long *********************************************************
1820
1821    Calls a Java method with a variable number of arguments and returns
1822    a long (s8).
1823
1824 *******************************************************************************/
1825
1826 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
1827 {
1828         va_list ap;
1829         s8      l;
1830
1831         va_start(ap, o);
1832         l = vm_call_method_long_valist(m, o, ap);
1833         va_end(ap);
1834
1835         return l;
1836 }
1837
1838
1839 /* vm_call_method_long_valist **************************************************
1840
1841    Calls a Java method with a variable number of arguments, passed via
1842    a va_list, and returns a long (s8).
1843
1844 *******************************************************************************/
1845
1846 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
1847 {
1848         s4      vmargscount;
1849         vm_arg *vmargs;
1850         s8      l;
1851         s4      dumpsize;
1852
1853         /* mark start of dump memory area */
1854
1855         dumpsize = dump_size();
1856
1857         /* get number of Java method arguments */
1858
1859         vmargscount = m->parseddesc->paramcount;
1860
1861         /* allocate vm_arg array */
1862
1863         vmargs = DMNEW(vm_arg, vmargscount);
1864
1865         /* fill the vm_arg array from a va_list */
1866
1867         vm_vmargs_from_valist(m, o, vmargs, ap);
1868
1869         /* call the Java method */
1870
1871         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1872
1873         /* release dump area */
1874
1875         dump_release(dumpsize);
1876
1877         return l;
1878 }
1879
1880
1881 /* vm_call_method_long_jvalue **************************************************
1882
1883    Calls a Java method with a variable number of arguments, passed via
1884    a jvalue array, and returns a long (s8).
1885
1886 *******************************************************************************/
1887
1888 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1889 {
1890         s4      vmargscount;
1891         vm_arg *vmargs;
1892         s8      l;
1893         s4      dumpsize;
1894
1895         /* mark start of dump memory area */
1896
1897         dumpsize = dump_size();
1898
1899         /* get number of Java method arguments */
1900
1901         vmargscount = m->parseddesc->paramcount;
1902
1903         /* allocate vm_arg array */
1904
1905         vmargs = DMNEW(vm_arg, vmargscount);
1906
1907         /* fill the vm_arg array from a va_list */
1908
1909         vm_vmargs_from_jvalue(m, o, vmargs, args);
1910
1911         /* call the Java method */
1912
1913         l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1914
1915         /* release dump area */
1916
1917         dump_release(dumpsize);
1918
1919         return l;
1920 }
1921
1922
1923 /* vm_call_method_long_vmarg ***************************************************
1924
1925    Calls a Java method with a variable number of arguments, passed via
1926    a vm_arg array, and returns a long (s8).
1927
1928 *******************************************************************************/
1929
1930 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1931 {
1932         s8 l;
1933
1934 #if defined(ENABLE_JIT)
1935 # if defined(ENABLE_INTRP)
1936         if (opt_intrp)
1937                 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1938         else
1939 # endif
1940                 l = asm_vm_call_method_long(m, vmargscount, vmargs);
1941 #else
1942         l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1943 #endif
1944
1945         return l;
1946 }
1947
1948
1949 /* vm_call_method_float ********************************************************
1950
1951    Calls a Java method with a variable number of arguments and returns
1952    an float.
1953
1954 *******************************************************************************/
1955
1956 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
1957 {
1958         va_list ap;
1959         float   f;
1960
1961         va_start(ap, o);
1962         f = vm_call_method_float_valist(m, o, ap);
1963         va_end(ap);
1964
1965         return f;
1966 }
1967
1968
1969 /* vm_call_method_float_valist *************************************************
1970
1971    Calls a Java method with a variable number of arguments, passed via
1972    a va_list, and returns a float.
1973
1974 *******************************************************************************/
1975
1976 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
1977                                                                   va_list ap)
1978 {
1979         s4      vmargscount;
1980         vm_arg *vmargs;
1981         float   f;
1982         s4      dumpsize;
1983
1984         /* mark start of dump memory area */
1985
1986         dumpsize = dump_size();
1987
1988         /* get number of Java method arguments */
1989
1990         vmargscount = m->parseddesc->paramcount;
1991
1992         /* allocate vm_arg array */
1993
1994         vmargs = DMNEW(vm_arg, vmargscount);
1995
1996         /* fill the vm_arg array from a va_list */
1997
1998         vm_vmargs_from_valist(m, o, vmargs, ap);
1999
2000         /* call the Java method */
2001
2002         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2003
2004         /* release dump area */
2005
2006         dump_release(dumpsize);
2007
2008         return f;
2009 }
2010
2011
2012 /* vm_call_method_float_jvalue *************************************************
2013
2014    Calls a Java method with a variable number of arguments, passed via
2015    a jvalue array, and returns a float.
2016
2017 *******************************************************************************/
2018
2019 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2020                                                                   jvalue *args)
2021 {
2022         s4      vmargscount;
2023         vm_arg *vmargs;
2024         float   f;
2025         s4      dumpsize;
2026
2027         /* mark start of dump memory area */
2028
2029         dumpsize = dump_size();
2030
2031         /* get number of Java method arguments */
2032
2033         vmargscount = m->parseddesc->paramcount;
2034
2035         /* allocate vm_arg array */
2036
2037         vmargs = DMNEW(vm_arg, vmargscount);
2038
2039         /* fill the vm_arg array from a va_list */
2040
2041         vm_vmargs_from_jvalue(m, o, vmargs, args);
2042
2043         /* call the Java method */
2044
2045         f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2046
2047         /* release dump area */
2048
2049         dump_release(dumpsize);
2050
2051         return f;
2052 }
2053
2054
2055 /* vm_call_method_float_vmarg **************************************************
2056
2057    Calls a Java method with a variable number of arguments and returns
2058    an float.
2059
2060 *******************************************************************************/
2061
2062 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2063 {
2064         float f;
2065
2066 #if defined(ENABLE_JIT)
2067 # if defined(ENABLE_INTRP)
2068         if (opt_intrp)
2069                 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2070         else
2071 # endif
2072                 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2073 #else
2074         f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2075 #endif
2076
2077         return f;
2078 }
2079
2080
2081 /* vm_call_method_double *******************************************************
2082
2083    Calls a Java method with a variable number of arguments and returns
2084    a double.
2085
2086 *******************************************************************************/
2087
2088 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2089 {
2090         va_list ap;
2091         double  d;
2092
2093         va_start(ap, o);
2094         d = vm_call_method_double_valist(m, o, ap);
2095         va_end(ap);
2096
2097         return d;
2098 }
2099
2100
2101 /* vm_call_method_double_valist ************************************************
2102
2103    Calls a Java method with a variable number of arguments, passed via
2104    a va_list, and returns a double.
2105
2106 *******************************************************************************/
2107
2108 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2109                                                                         va_list ap)
2110 {
2111         s4      vmargscount;
2112         vm_arg *vmargs;
2113         double  d;
2114         s4      dumpsize;
2115
2116         /* mark start of dump memory area */
2117
2118         dumpsize = dump_size();
2119
2120         /* get number of Java method arguments */
2121
2122         vmargscount = m->parseddesc->paramcount;
2123
2124         /* allocate vm_arg array */
2125
2126         vmargs = DMNEW(vm_arg, vmargscount);
2127
2128         /* fill the vm_arg array from a va_list */
2129
2130         vm_vmargs_from_valist(m, o, vmargs, ap);
2131
2132         /* call the Java method */
2133
2134         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2135
2136         /* release dump area */
2137
2138         dump_release(dumpsize);
2139
2140         return d;
2141 }
2142
2143
2144 /* vm_call_method_double_jvalue ************************************************
2145
2146    Calls a Java method with a variable number of arguments, passed via
2147    a jvalue array, and returns a double.
2148
2149 *******************************************************************************/
2150
2151 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2152                                                                         jvalue *args)
2153 {
2154         s4      vmargscount;
2155         vm_arg *vmargs;
2156         double  d;
2157         s4      dumpsize;
2158
2159         /* mark start of dump memory area */
2160
2161         dumpsize = dump_size();
2162
2163         /* get number of Java method arguments */
2164
2165         vmargscount = m->parseddesc->paramcount;
2166
2167         /* allocate vm_arg array */
2168
2169         vmargs = DMNEW(vm_arg, vmargscount);
2170
2171         /* fill the vm_arg array from a va_list */
2172
2173         vm_vmargs_from_jvalue(m, o, vmargs, args);
2174
2175         /* call the Java method */
2176
2177         d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2178
2179         /* release dump area */
2180
2181         dump_release(dumpsize);
2182
2183         return d;
2184 }
2185
2186
2187 /* vm_call_method_double_vmarg *************************************************
2188
2189    Calls a Java method with a variable number of arguments and returns
2190    a double.
2191
2192 *******************************************************************************/
2193
2194 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2195                                                                    vm_arg *vmargs)
2196 {
2197         double d;
2198
2199 #if defined(ENABLE_JIT)
2200 # if defined(ENABLE_INTRP)
2201         if (opt_intrp)
2202                 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2203         else
2204 # endif
2205                 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2206 #else
2207         d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2208 #endif
2209
2210         return d;
2211 }
2212
2213
2214 /*
2215  * These are local overrides for various environment variables in Emacs.
2216  * Please do not remove this and leave it at the end of the file, where
2217  * Emacs will automagically detect them.
2218  * ---------------------------------------------------------------------
2219  * Local variables:
2220  * mode: c
2221  * indent-tabs-mode: t
2222  * c-basic-offset: 4
2223  * tab-width: 4
2224  * End:
2225  */