CACAO
vm.cpp
Go to the documentation of this file.
1 /* src/vm/vm.cpp - VM startup and shutdown functions
2 
3  Copyright (C) 1996-2014
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <cassert>
29 #include <cerrno>
30 #include <cstdlib>
31 #include <exception>
32 #include <stdint.h>
33 #include <inttypes.h>
34 
35 #include "md-abi.hpp"
36 
37 #include "mm/codememory.hpp"
38 #include "mm/dumpmemory.hpp"
39 #include "mm/gc.hpp"
40 #include "mm/memory.hpp"
41 
42 #include "native/jni.hpp"
43 #include "native/llni.hpp"
44 #include "native/localref.hpp"
45 #include "native/native.hpp"
46 
47 #include "native/vm/nativevm.hpp"
48 
49 #include "threads/lock.hpp"
50 #include "threads/thread.hpp"
51 
52 #include "toolbox/logging.hpp"
53 
54 #include "vm/array.hpp"
55 #include "vm/assertion.hpp"
56 #include "vm/classcache.hpp"
57 #include "vm/exceptions.hpp"
58 #include "vm/descriptor.hpp"
59 #include "vm/finalizer.hpp"
60 #include "vm/global.hpp"
61 #include "vm/globals.hpp"
62 #include "vm/hook.hpp"
63 #include "vm/initialize.hpp"
64 #include "vm/javaobjects.hpp"
65 #include "vm/options.hpp"
66 #include "vm/os.hpp"
67 #include "vm/primitive.hpp"
68 #include "vm/properties.hpp"
69 #include "vm/rt-timing.hpp"
70 #include "vm/signallocal.hpp"
71 #include "vm/statistics.hpp"
72 #include "vm/string.hpp"
73 #include "vm/suck.hpp"
74 #include "vm/types.hpp"
75 #include "vm/vm.hpp"
76 
77 #include "vm/jit/abi-asm.hpp"
78 #include "vm/jit/argument.hpp"
79 #include "vm/jit/asmpart.hpp"
80 #include "vm/jit/builtin.hpp"
81 #include "vm/jit/code.hpp"
82 #include "vm/jit/disass.hpp"
83 #include "vm/jit/jit.hpp"
84 #include "vm/jit/methodtree.hpp"
85 #include "vm/jit/stacktrace.hpp"
86 #include "vm/jit/trap.hpp"
87 
90 
91 using namespace cacao;
92 
93 
94 STAT_DECLARE_GROUP(function_call_stat)
95 STAT_REGISTER_GROUP_VAR(u8,count_calls_native_to_java,0,"calls native to java","native-to-java calls",function_call_stat)
96 /**
97  * This is _the_ VM instance.
98  */
99 VM* VM::_vm = NULL;
100 
101 
102 /* global variables ***********************************************************/
103 
104 s4 vms = 0; /* number of VMs created */
105 
106 #if !defined(NDEBUG)
107 static classinfo *mainclass = NULL;
108 #endif
109 
110 #if defined(ENABLE_INTRP)
111 u1 *intrp_main_stack = NULL;
112 #endif
113 
114 
115 /* define heap sizes **********************************************************/
116 
117 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
118 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
119 #define STACK_SIZE 512 * 1024 /* default 512kB */
120 
121 
122 /* define command line options ************************************************/
123 
124 enum {
126 
127  /* Java options */
128 
130 
133 
136 
138 
142 
146 
151 
152 
155 
156  /* Java non-standard options */
157 
160 
164 
166 
167 #if defined(ENABLE_PROFILING)
168  OPT_PROF,
169  OPT_PROF_OPTION,
170 #endif
171 
174 
176 
177  /* CACAO options */
178 
180 
181 #if defined(ENABLE_STATISTICS)
182  OPT_TIME,
183  OPT_STAT,
184 #endif
185 
191 
192 #if defined(ENABLE_VERIFIER)
196 #if defined(TYPECHECK_VERBOSE)
197  OPT_VERBOSETC,
198 #endif
199 #endif /* defined(ENABLE_VERIFIER) */
200 
201  /* optimization options */
202 
203 #if defined(ENABLE_LOOP)
204  OPT_OLOOP,
205 #endif
206 
207 #if defined(ENABLE_IFCONV)
209 #endif
210 
211 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
212  OPT_LSRA,
213 #endif
214 
215 #if defined(ENABLE_INTRP)
216  /* interpreter options */
217 
218  OPT_NO_DYNAMIC,
219  OPT_NO_REPLICATION,
220  OPT_NO_QUICKSUPER,
221  OPT_STATIC_SUPERS,
222  OPT_TRACE,
223 #endif
224 
226 
227 #if defined(ENABLE_JVMTI)
228  OPT_AGENTLIB,
229  OPT_AGENTPATH,
230  OPT_RUN,
231 #endif
232 
233 #if defined(ENABLE_DEBUG_FILTER)
237 #endif
238 
240 };
241 
242 
244  { "foo", false, OPT_FOO },
245 
246  /* Java options */
247 
248  { "jar", false, OPT_JAR },
249 
250  { "d32", false, OPT_D32 },
251  { "d64", false, OPT_D64 },
252  { "client", false, OPT_IGNORE },
253  { "server", false, OPT_IGNORE },
254  { "jvm", false, OPT_IGNORE },
255  { "hotspot", false, OPT_IGNORE },
256 
257  { "classpath", true, OPT_CLASSPATH },
258  { "cp", true, OPT_CLASSPATH },
259  { "D", true, OPT_D },
260  { "version", false, OPT_VERSION },
261  { "showversion", false, OPT_SHOWVERSION },
262  { "fullversion", false, OPT_FULLVERSION },
263  { "help", false, OPT_HELP },
264  { "?", false, OPT_HELP },
265  { "X", false, OPT_X },
266  { "XX:", true, OPT_XX },
267 
268  { "ea:", true, OPT_EA },
269  { "da:", true, OPT_DA },
270  { "ea", false, OPT_EA_NOARG },
271  { "da", false, OPT_DA_NOARG },
272 
273  { "enableassertions:", true, OPT_EA },
274  { "disableassertions:", true, OPT_DA },
275  { "enableassertions", false, OPT_EA_NOARG },
276  { "disableassertions", false, OPT_DA_NOARG },
277 
278  { "esa", false, OPT_ESA },
279  { "enablesystemassertions", false, OPT_ESA },
280  { "dsa", false, OPT_DSA },
281  { "disablesystemassertions", false, OPT_DSA },
282 
283  { "noasyncgc", false, OPT_IGNORE },
284 #if defined(ENABLE_VERIFIER)
285  { "noverify", false, OPT_NOVERIFY },
286  { "Xverify:all", false, OPT_XVERIFY_ALL },
287  { "Xverify:none", false, OPT_XVERIFY_NONE },
288 #endif
289  { "v", false, OPT_VERBOSE1 },
290  { "verbose:", true, OPT_VERBOSE },
291 
292 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
293  { "verbosetc", false, OPT_VERBOSETC },
294 #endif
295 #if defined(ENABLE_STATISTICS)
296  { "time", false, OPT_TIME },
297  { "stat", false, OPT_STAT },
298 #endif
299  { "log", true, OPT_LOG },
300  { "c", true, OPT_CHECK },
301  { "l", false, OPT_LOAD },
302 
303 #if defined(ENABLE_LOOP)
304  { "oloop", false, OPT_OLOOP },
305 #endif
306 #if defined(ENABLE_IFCONV)
307  { "ifconv", false, OPT_IFCONV },
308 #endif
309 #if defined(ENABLE_LSRA)
310  { "lsra", false, OPT_LSRA },
311 #endif
312 #if defined(ENABLE_SSA)
313  { "lsra", true, OPT_LSRA },
314 #endif
315 
316 #if defined(ENABLE_INTRP)
317  /* interpreter options */
318 
319  { "trace", false, OPT_TRACE },
320  { "static-supers", true, OPT_STATIC_SUPERS },
321  { "no-dynamic", false, OPT_NO_DYNAMIC },
322  { "no-replication", false, OPT_NO_REPLICATION },
323  { "no-quicksuper", false, OPT_NO_QUICKSUPER },
324 #endif
325 
326  /* JVMTI Agent Command Line Options */
327 #if defined(ENABLE_JVMTI)
328  { "agentlib:", true, OPT_AGENTLIB },
329  { "agentpath:", true, OPT_AGENTPATH },
330 #endif
331 
332  /* Java non-standard options */
333 
334  { "Xjit", false, OPT_JIT },
335  { "Xint", false, OPT_INTRP },
336  { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
337  { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
338  { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
339  { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
340 
341 #if defined(ENABLE_JVMTI)
342  { "Xdebug", false, OPT_IGNORE },
343  { "Xnoagent", false, OPT_IGNORE },
344  { "Xrun", true, OPT_RUN },
345 #endif
346 
347  { "Xms", true, OPT_MS },
348  { "ms", true, OPT_MS },
349  { "Xmx", true, OPT_MX },
350  { "mx", true, OPT_MX },
351  { "Xss", true, OPT_SS },
352  { "ss", true, OPT_SS },
353 
354  { "Xcheck:jni", false, OPT_XCHECK_JNI },
355 
356 #if defined(ENABLE_PROFILING)
357  { "Xprof:", true, OPT_PROF_OPTION },
358  { "Xprof", false, OPT_PROF },
359 #endif
360 
361  /* keep these at the end of the list */
362 
363  { "s", true, OPT_SHOW },
364  { "debug-color", false, OPT_DEBUGCOLOR },
365 
366 #if defined(ENABLE_DEBUG_FILTER)
367  { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
368  { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
369  { "XXfm", true, OPT_FILTER_SHOW_METHOD },
370 #endif
371 
372  { NULL, false, 0 }
373 };
374 
375 
376 /* usage ***********************************************************************
377 
378  Prints the correct usage syntax to stdout.
379 
380 *******************************************************************************/
381 
382 static void usage(void)
383 {
384  puts("Usage: cacao [-options] classname [arguments]");
385  puts(" (to run a class file)");
386  puts(" or cacao [-options] -jar jarfile [arguments]");
387  puts(" (to run a standalone jar file)\n");
388 
389  puts("where options include:");
390  puts(" -d32 use 32-bit data model if available");
391  puts(" -d64 use 64-bit data model if available");
392  puts(" -client compatibility (currently ignored)");
393  puts(" -server compatibility (currently ignored)");
394  puts(" -jvm compatibility (currently ignored)");
395  puts(" -hotspot compatibility (currently ignored)\n");
396 
397  puts(" -cp <path> specify a path to look for classes");
398  puts(" -classpath <path> specify a path to look for classes");
399  puts(" -D<name>=<value> add an entry to the property list");
400  puts(" -verbose[:class|gc|jni] enable specific verbose output");
401  puts(" -version print product version and exit");
402  puts(" -fullversion print jpackage-compatible product version and exit");
403  puts(" -showversion print product version and continue");
404  puts(" -help, -? print this help message");
405  puts(" -X print help on non-standard Java options");
406  puts(" -XX print help on debugging options");
407  puts(" -ea[:<packagename>...|:<classname>]");
408  puts(" -enableassertions[:<packagename>...|:<classname>]");
409  puts(" enable assertions with specified granularity");
410  puts(" -da[:<packagename>...|:<classname>]");
411  puts(" -disableassertions[:<packagename>...|:<classname>]");
412  puts(" disable assertions with specified granularity");
413  puts(" -esa | -enablesystemassertions");
414  puts(" enable system assertions");
415  puts(" -dsa | -disablesystemassertions");
416  puts(" disable system assertions");
417 
418 #if defined(ENABLE_JVMTI)
419  puts(" -agentlib:<agent-lib-name>=<options>");
420  puts(" load native agent library by library name");
421  puts(" for additional help use: -agentlib:jdwp=help");
422  puts(" -agentpath:<path-to-agent>=<options>");
423  puts(" load native agent library by full pathname");
424 #endif
425 
426  /* exit with error code */
427 
428  exit(1);
429 }
430 
431 
432 static void Xusage(void)
433 {
434 #if defined(ENABLE_JIT)
435  puts(" -Xjit JIT mode execution (default)");
436 #endif
437 #if defined(ENABLE_INTRP)
438  puts(" -Xint interpreter mode execution");
439 #endif
440  puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
441  puts(" value is set as bootstrap class path");
442  puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
443  puts(" value is appended to the bootstrap class path");
444  puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
445  puts(" value is prepended to the bootstrap class path");
446  puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
447  puts(" value is used as Java core library, but the");
448  puts(" hardcoded VM interface classes are prepended");
449  printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
450  printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
451  printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
452 
453 #if defined(ENABLE_PROFILING)
454  puts(" -Xprof[:bb] collect and print profiling data");
455 #endif
456 
457  /* exit with error code */
458 
459  exit(1);
460 }
461 
462 
463 #if 0
464 static void XXusage(void)
465 {
466  puts(" -v write state-information");
467 #if !defined(NDEBUG)
468  puts(" -verbose:jit enable specific verbose output");
469  puts(" -debug-color colored output for ANSI terms");
470 #endif
471 #ifdef TYPECHECK_VERBOSE
472  puts(" -verbosetc write debug messages while typechecking");
473 #endif
474 #if defined(ENABLE_VERIFIER)
475  puts(" -noverify don't verify classfiles");
476 #endif
477 #if defined(ENABLE_STATISTICS)
478  puts(" -time measure the runtime");
479  puts(" -stat detailed compiler statistics");
480 #endif
481  puts(" -log logfile specify a name for the logfile");
482  puts(" -c(heck)b(ounds) don't check array bounds");
483  puts(" s(ync) don't check for synchronization");
484 #if defined(ENABLE_LOOP)
485  puts(" -oloop optimize array accesses in loops");
486 #endif
487  puts(" -l don't start the class after loading");
488 
489  puts(" -s... show...");
490  puts(" (c)onstants the constant pool");
491  puts(" (m)ethods class fields and methods");
492  puts(" (u)tf the utf - hash");
493  puts(" (i)ntermediate intermediate representation");
494 #if defined(ENABLE_DISASSEMBLER)
495  puts(" (a)ssembler disassembled listing");
496  puts(" n(o)ps show NOPs in disassembler output");
497 #endif
498  puts(" (d)atasegment data segment listing");
499 
500 #if defined(ENABLE_IFCONV)
501  puts(" -ifconv use if-conversion");
502 #endif
503 #if defined(ENABLE_LSRA)
504  puts(" -lsra use linear scan register allocation");
505 #endif
506 #if defined(ENABLE_SSA)
507  puts(" -lsra:... use linear scan register allocation (with SSA)");
508  puts(" (d)ead code elimination");
509  puts(" (c)opy propagation");
510 #endif
511 #if defined(ENABLE_DEBUG_FILTER)
512  puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
513  puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
514  puts(" -XXfm <regex> filter for show options");
515 #endif
516  /* exit with error code */
517 
518  exit(1);
519 }
520 #endif
521 
522 
523 /* version *********************************************************************
524 
525  Only prints cacao version information.
526 
527 *******************************************************************************/
528 
529 static void version(bool opt_exit)
530 {
531  puts("java version \"" JAVA_VERSION "\"");
532  puts("CACAO version " VERSION_FULL "\n");
533 
534  puts("Copyright (C) 1996-2014");
535  puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
536  puts("This is free software; see the source for copying conditions. There is NO");
537  puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
538 
539  /* exit normally, if requested */
540 
541  if (opt_exit)
542  exit(0);
543 }
544 
545 
546 /* fullversion *****************************************************************
547 
548  Prints a Sun compatible version information (required e.g. by
549  jpackage, www.jpackage.org).
550 
551 *******************************************************************************/
552 
553 static void fullversion(void)
554 {
555  puts("java full version \"cacao-" JAVA_VERSION "\"");
556 
557  /* exit normally */
558 
559  exit(0);
560 }
561 
562 
563 /* forward declarations *******************************************************/
564 
565 static char *vm_get_mainclass_from_jar(char *mainstring);
566 
567 #if !defined(NDEBUG)
568 #define COMPILE_METHOD
569 #else
570 #define COMPILE_METHOD
571 #endif
572 
573 #if defined(COMPILE_METHOD)
574 static void vm_compile_method(char* mainname);
575 #endif
576 
577 #if !defined(NDEBUG)
578 static void vm_compile_all(void);
579 #endif
580 
581 /**
582  * Implementation for JNI_CreateJavaVM. This function creates a VM
583  * object.
584  *
585  * @param p_vm
586  * @param p_env
587  * @param vm_args
588  *
589  * @return true on success, false otherwise.
590  */
591 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
592 {
593  JavaVMInitArgs* _vm_args;
594 
595  // Get the arguments for the new JVM.
596  _vm_args = (JavaVMInitArgs *) vm_args;
597 
598  // Instantiate a new VM.
599  try {
600  _vm = new VM(_vm_args);
601  }
602  catch (std::exception e) {
603  // FIXME How can we delete the resources allocated?
604 // /* release allocated memory */
605 // FREE(env, _Jv_JNIEnv);
606 // FREE(vm, _Jv_JavaVM);
607 
608  _vm = NULL;
609 
610  return false;
611  }
612 
613  // Return the values.
614 
615  *p_vm = _vm->get_javavm();
616  *p_env = _vm->get_jnienv();
617 
618  return true;
619 }
620 
621 
622 /**
623  * C wrapper for VM::create.
624  */
625 extern "C" {
626  bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
627  {
628  return VM::create(p_vm, p_env, vm_args);
629  }
630 }
631 
632 
633 /**
634  * VM constructor.
635  */
636 VM::VM(JavaVMInitArgs* vm_args)
637 {
638  // Very first thing to do: we are initializing.
639  _initializing = true;
640 
641  // Make sure logging works
642 
643 
644  // Make ourself globally visible.
645  // XXX Is this a good idea?
646  _vm = this;
647 
648  /* create and fill a JavaVM structure */
649 
650  _javavm = new JavaVM();
651 
652 #if defined(ENABLE_JNI)
653  _javavm->functions = &_Jv_JNIInvokeInterface;
654 #endif
655 
656  /* get the VM and Env tables (must be set before vm_create) */
657  /* XXX JVMTI Agents needs a JavaVM */
658 
659  _jnienv = new JNIEnv();
660 
661 #if defined(ENABLE_JNI)
662  _jnienv->functions = &_Jv_JNINativeInterface;
663 #endif
664 
665  /* actually create the JVM */
666 
667  int len = 0;
668  char *p;
669  char *boot_class_path;
670  char *boot_class_path_p = NULL;
671  char *class_path;
672  int opt;
673  bool opt_version;
674  bool opt_exit;
675 
676 #if defined(ENABLE_JNI)
677  /* Check the JNI version requested. */
678 
679  if (!jni_version_check(vm_args->version))
680  throw std::exception();
681 #endif
682 
683  /* We only support 1 JVM instance. */
684 
685  if (vms > 0)
686  throw std::exception();
687 
688  /* Install the exit handler. */
689 
690  if (atexit(vm_exit_handler))
691  os::abort("atexit failed: %s\n", strerror(errno));
692 
693  /* Set some options. */
694 
695  opt_version = false;
696  opt_exit = false;
697 
701 
702  // First of all, parse the -XX options.
703  options_xx(vm_args);
704 
705  // After -XX options are parsed, print the build-time
706  // configuration, if requested.
707  if (opt_PrintConfig)
708  print_build_time_config();
709 
710  /* We need to check if the actual size of a java.lang.Class object
711  is smaller or equal than the assumption made in
712  src/vm/class.hpp. */
713 
714 // FIXME We need to check the size of java.lang.Class!!!
715 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
716 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
717 
718  /* set the VM starttime */
719 
720  _starttime = builtin_currenttimemillis();
721 
722  /* iterate over all passed options */
723 
724  while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
725  switch (opt) {
726  case OPT_FOO:
727  opt_foo = true;
728  break;
729 
730  case OPT_IGNORE:
731  break;
732 
733  case OPT_JAR:
734  opt_jar = true;
735  break;
736 
737  case OPT_D32:
738 #if SIZEOF_VOID_P == 8
739  puts("Running a 32-bit JVM is not supported on this platform.");
740  exit(1);
741 #endif
742  break;
743 
744  case OPT_D64:
745 #if SIZEOF_VOID_P == 4
746  puts("Running a 64-bit JVM is not supported on this platform.");
747  exit(1);
748 #endif
749  break;
750 
751  case OPT_CLASSPATH:
752  /* Forget old classpath and set the argument as new
753  classpath. */
754 
755  // FIXME Make class_path const char*.
756  class_path = (char*) _properties.get("java.class.path");
757 
758  p = MNEW(char, strlen(opt_arg) + strlen("0"));
759 
760  strcpy(p, opt_arg);
761 
762 #if defined(ENABLE_JAVASE)
763  _properties.put("java.class.path", p);
764 #endif
765 
766  MFREE(class_path, char, strlen(class_path));
767  break;
768 
769  case OPT_D:
770  for (unsigned int i = 0; i < strlen(opt_arg); i++) {
771  if (opt_arg[i] == '=') {
772  opt_arg[i] = '\0';
773  _properties.put(opt_arg, opt_arg + i + 1);
774  goto opt_d_done;
775  }
776  }
777 
778  /* if no '=' is given, just create an empty property */
779 
780  _properties.put(opt_arg, "");
781 
782  opt_d_done:
783  break;
784 
785  case OPT_BOOTCLASSPATH:
786  /* Forget default bootclasspath and set the argument as
787  new boot classpath. */
788 
789  /* Forget stored -Xbootclasspath/p value */
790  if (boot_class_path_p != NULL) {
791  MFREE(boot_class_path_p, char, len);
792  boot_class_path_p = NULL;
793  }
794  // FIXME Make boot_class_path const char*.
795  boot_class_path = (char*) _properties.get("sun.boot.class.path");
796 
797  p = MNEW(char, strlen(opt_arg) + strlen("0"));
798 
799  strcpy(p, opt_arg);
800 
801  _properties.put("sun.boot.class.path", p);
802  _properties.put("java.boot.class.path", p);
803 
804  MFREE(boot_class_path, char, strlen(boot_class_path));
805  break;
806 
807  case OPT_BOOTCLASSPATH_A:
808  /* Append to bootclasspath. */
809 
810  // FIXME Make boot_class_path const char*.
811  boot_class_path = (char*) _properties.get("sun.boot.class.path");
812 
813  len = strlen(boot_class_path);
814 
815  // XXX (char*) quick hack
816  p = (char*) MREALLOC(boot_class_path,
817  char,
818  len + strlen("0"),
819  len + strlen(":") +
820  strlen(opt_arg) + strlen("0"));
821 
822  strcat(p, ":");
823  strcat(p, opt_arg);
824 
825  _properties.put("sun.boot.class.path", p);
826  _properties.put("java.boot.class.path", p);
827  break;
828 
829  case OPT_BOOTCLASSPATH_P:
830  /* Prepend to bootclasspath. */
831  /* Note: we can not add this value directly to sun/java.boot.class.path
832  because we need to take care of the ordering regarding the
833  endorseddirs property */
834 
835  if (boot_class_path_p == NULL) {
836  boot_class_path_p = MNEW(char, strlen(opt_arg) + strlen("0"));
837  strcpy(boot_class_path_p, opt_arg);
838  } else {
839  len = strlen(boot_class_path_p);
840  p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
841  strcpy(p, opt_arg);
842  strcat(p, ":");
843  strcat(p, boot_class_path_p);
844  MFREE(boot_class_path_p, char, len);
845  boot_class_path_p = p;
846  }
847  break;
848 
849  case OPT_BOOTCLASSPATH_C:
850  /* Use as Java core library, but prepend VM interface
851  classes. */
852 
853  // FIXME Make boot_class_path const char*.
854  boot_class_path = (char*) _properties.get("sun.boot.class.path");
855 
856  len =
857  strlen(CACAO_VM_ZIP) +
858  strlen(":") +
859  strlen(opt_arg) +
860  strlen("0");
861 
862  p = MNEW(char, len);
863 
864  strcpy(p, CACAO_VM_ZIP);
865  strcat(p, ":");
866  strcat(p, opt_arg);
867 
868  _properties.put("sun.boot.class.path", p);
869  _properties.put("java.boot.class.path", p);
870 
871  MFREE(boot_class_path, char, strlen(boot_class_path));
872  break;
873 
874 #if defined(ENABLE_JVMTI)
875  case OPT_AGENTLIB:
876  // Parse option argument.
877  p = strchr(opt_arg, '=');
878  if (p != NULL)
879  *(p++) = '\0';
880 
881  _nativeagents.register_agent_library(opt_arg, p);
882  break;
883 
884  case OPT_AGENTPATH:
885  // Parse option argument.
886  p = strchr(opt_arg, '=');
887  if (p != NULL)
888  *(p++) = '\0';
889 
890  _nativeagents.register_agent_path(opt_arg, p);
891  break;
892 
893  case OPT_RUN:
894  // Parse option argument.
895  p = strchr(opt_arg, ':');
896  if (p != NULL)
897  *(p++) = '\0';
898 
899  _nativeagents.register_agent_library(opt_arg, p);
900  break;
901 #endif
902 
903  case OPT_MX:
904  case OPT_MS:
905  case OPT_SS:
906  {
907  char c;
908  int j;
909 
910  c = opt_arg[strlen(opt_arg) - 1];
911 
912  if ((c == 'k') || (c == 'K')) {
913  j = atoi(opt_arg) * 1024;
914 
915  } else if ((c == 'm') || (c == 'M')) {
916  j = atoi(opt_arg) * 1024 * 1024;
917 
918  } else
919  j = atoi(opt_arg);
920 
921  if (opt == OPT_MX)
922  opt_heapmaxsize = j;
923  else if (opt == OPT_MS)
924  opt_heapstartsize = j;
925  else
926  opt_stacksize = j;
927  }
928  break;
929 
930  case OPT_XCHECK_JNI:
931  // HotSpot compatibility option.
932  break;
933 
934  case OPT_VERBOSE1:
935  opt_verbose = true;
936  break;
937 
938  case OPT_VERBOSE:
939  if (strcmp("class", opt_arg) == 0) {
940  opt_verboseclass = true;
941  }
942  else if (strcmp("gc", opt_arg) == 0) {
943  opt_verbosegc = true;
944  }
945  else if (strcmp("jni", opt_arg) == 0) {
946  opt_verbosejni = true;
947  }
948 #if !defined(NDEBUG)
949  else if (strcmp("jit", opt_arg) == 0) {
950  opt_verbose = true;
951  loadverbose = true;
952  initverbose = true;
953  compileverbose = true;
954  }
955 #endif
956  else {
957  printf("Unknown -verbose option: %s\n", opt_arg);
958  usage();
959  }
960  break;
961 
962  case OPT_DEBUGCOLOR:
963  opt_debugcolor = true;
964  break;
965 
966 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
967  case OPT_VERBOSETC:
968  opt_typecheckverbose = true;
969  break;
970 #endif
971 
972  case OPT_VERSION:
973  opt_version = true;
974  opt_exit = true;
975  break;
976 
977  case OPT_FULLVERSION:
978  fullversion();
979  break;
980 
981  case OPT_SHOWVERSION:
982  opt_version = true;
983  break;
984 
985 #if defined(ENABLE_VERIFIER)
986  case OPT_XVERIFY_ALL:
987  opt_verify = true;
988  break;
989 
990  case OPT_NOVERIFY:
991  case OPT_XVERIFY_NONE:
992  opt_verify = false;
993  break;
994 #endif
995 
996 #if defined(ENABLE_STATISTICS)
997  case OPT_TIME:
998  opt_getcompilingtime = true;
999  opt_getloadingtime = true;
1000  break;
1001 
1002  case OPT_STAT:
1003  opt_stat = true;
1004  break;
1005 #endif
1006 
1007  case OPT_LOG:
1008  log_init(opt_arg);
1009  break;
1010 
1011  case OPT_CHECK:
1012  for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1013  switch (opt_arg[i]) {
1014  case 'b':
1015  checkbounds = false;
1016  break;
1017  case 's':
1018  checksync = false;
1019  break;
1020  default:
1021  usage();
1022  }
1023  }
1024  break;
1025 
1026  case OPT_LOAD:
1027  opt_run = false;
1028  makeinitializations = false;
1029  break;
1030 
1031  case OPT_SHOW: /* Display options */
1032  for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1033  switch (opt_arg[i]) {
1034  case 'c':
1035  showconstantpool = true;
1036  break;
1037 
1038  case 'u':
1039  showutf = true;
1040  break;
1041 
1042  case 'm':
1043  showmethods = true;
1044  break;
1045 
1046  case 'i':
1047  opt_showintermediate = true;
1048  compileverbose = true;
1049  break;
1050 
1051 #if defined(ENABLE_DISASSEMBLER)
1052  case 'a':
1053  opt_showdisassemble = true;
1054  compileverbose = true;
1055  break;
1056 #endif
1057 
1058  case 'd':
1059  opt_showddatasegment = true;
1060  break;
1061 
1062  default:
1063  usage();
1064  }
1065  }
1066  break;
1067 
1068 #if defined(ENABLE_LOOP)
1069  case OPT_OLOOP:
1070  opt_loops = true;
1071  break;
1072 #endif
1073 
1074 #if defined(ENABLE_IFCONV)
1075  case OPT_IFCONV:
1076  opt_ifconv = true;
1077  break;
1078 #endif
1079 
1080 #if defined(ENABLE_LSRA)
1081  case OPT_LSRA:
1082  opt_lsra = true;
1083  break;
1084 #endif
1085 #if defined(ENABLE_SSA)
1086  case OPT_LSRA:
1087  opt_lsra = true;
1088  for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1089  switch (opt_arg[i]) {
1090  case 'c':
1091  opt_ssa_cp = true;
1092  break;
1093 
1094  case 'd':
1095  opt_ssa_dce = true;
1096  break;
1097 
1098  case ':':
1099  break;
1100 
1101  default:
1102  usage();
1103  }
1104  }
1105  break;
1106 #endif
1107 
1108  case OPT_HELP:
1109  usage();
1110  break;
1111 
1112  case OPT_X:
1113  Xusage();
1114  break;
1115 
1116  case OPT_XX:
1117  /* Already parsed. */
1118  break;
1119 
1120  case OPT_EA:
1121 #if defined(ENABLE_ASSERTION)
1122  assertion_ea_da(opt_arg, true);
1123 #endif
1124  break;
1125 
1126  case OPT_DA:
1127 #if defined(ENABLE_ASSERTION)
1128  assertion_ea_da(opt_arg, false);
1129 #endif
1130  break;
1131 
1132  case OPT_EA_NOARG:
1133 #if defined(ENABLE_ASSERTION)
1134  assertion_user_enabled = true;
1135 #endif
1136  break;
1137 
1138  case OPT_DA_NOARG:
1139 #if defined(ENABLE_ASSERTION)
1140  assertion_user_enabled = false;
1141 #endif
1142  break;
1143 
1144  case OPT_ESA:
1145 #if defined(ENABLE_ASSERTION)
1146  assertion_system_enabled = true;
1147 #endif
1148  break;
1149 
1150  case OPT_DSA:
1151 #if defined(ENABLE_ASSERTION)
1152  assertion_system_enabled = false;
1153 #endif
1154  break;
1155 
1156 #if defined(ENABLE_PROFILING)
1157  case OPT_PROF_OPTION:
1158  /* use <= to get the last \0 too */
1159 
1160  for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1161  if (opt_arg[i] == ',')
1162  opt_arg[i] = '\0';
1163 
1164  if (opt_arg[i] == '\0') {
1165  if (strcmp("bb", opt_arg + j) == 0)
1166  opt_prof_bb = true;
1167 
1168  else {
1169  fprintf(stderr, "Unknown option: -Xprof:%s\n", opt_arg + j);
1170  usage();
1171  }
1172 
1173  /* set k to next char */
1174 
1175  j = i + 1;
1176  }
1177  }
1178  /* fall through */
1179 
1180  case OPT_PROF:
1181  opt_prof = true;
1182  break;
1183 #endif
1184 
1185  case OPT_JIT:
1186 #if defined(ENABLE_JIT)
1187  opt_jit = true;
1188 #else
1189  printf("-Xjit option not enabled.\n");
1190  exit(1);
1191 #endif
1192  break;
1193 
1194  case OPT_INTRP:
1195 #if defined(ENABLE_INTRP)
1196  opt_intrp = true;
1197 #else
1198  printf("-Xint option not enabled.\n");
1199  exit(1);
1200 #endif
1201  break;
1202 
1203 #if defined(ENABLE_INTRP)
1204  case OPT_STATIC_SUPERS:
1205  opt_static_supers = atoi(opt_arg);
1206  break;
1207 
1208  case OPT_NO_DYNAMIC:
1209  opt_no_dynamic = true;
1210  break;
1211 
1212  case OPT_NO_REPLICATION:
1213  opt_no_replication = true;
1214  break;
1215 
1216  case OPT_NO_QUICKSUPER:
1217  opt_no_quicksuper = true;
1218  break;
1219 
1220  case OPT_TRACE:
1221  vm_debug = true;
1222  break;
1223 #endif
1224 
1225 #if defined(ENABLE_DEBUG_FILTER)
1228  break;
1229 
1232  break;
1233 
1236  break;
1237 
1238 #endif
1239  default:
1240  fprintf(stderr, "Unknown option: %s\n",
1241  vm_args->options[opt_index++].optionString);
1242  }
1243  }
1244 
1245  // Print the preliminary run-time VM configuration after options
1246  // are parsed.
1247  if (opt_PrintConfig)
1248  print_run_time_config();
1249 
1250  /* initialize the garbage collector */
1251 
1253 
1254  /* AFTER: gc_init */
1255 
1256  threads_preinit();
1257  lock_init();
1258 
1259  /* install architecture dependent signal handlers */
1260 
1261  if (!signal_init())
1262  os::abort("vm_create: signal_init failed");
1263 
1264 #if defined(ENABLE_INTRP)
1265  /* Allocate main thread stack on the Java heap. */
1266 
1267  if (opt_intrp) {
1268  intrp_main_stack = GCMNEW(u1, opt_stacksize);
1269  MSET(intrp_main_stack, 0, u1, opt_stacksize);
1270  }
1271 #endif
1272 
1273  /* AFTER: threads_preinit */
1274 
1276 
1277  /* AFTER: threads_preinit */
1278 
1280 
1281  // Hook point before the VM is initialized.
1282  Hook::vm_preinit();
1283 
1284 #if defined(ENABLE_JVMTI)
1285  // AFTER: utf8_init
1286  if (!_nativeagents.load_agents())
1287  os::abort("vm_create: load_agents failed");
1288 #endif
1289 
1290  /* AFTER: thread_preinit */
1291 
1292  /* Add -Xbootclasspath/p if it exists */
1293  if (boot_class_path_p != NULL)
1294  _suckclasspath.add(boot_class_path_p);
1295 
1296  _suckclasspath.add_from_property("java.endorsed.dirs");
1297 
1298  /* Now we have all options handled and we can print the version
1299  information.
1300 
1301  AFTER: suck_add_from_property("java.endorsed.dirs"); */
1302 
1303  if (opt_version)
1304  version(opt_exit);
1305 
1306  /* AFTER: utf8_init */
1307 
1308  // FIXME Make boot_class_path const char*.
1309  boot_class_path = (char*) _properties.get("sun.boot.class.path");
1310  _suckclasspath.add(boot_class_path);
1311 
1312  /* initialize the classcache hashtable stuff: lock, hashtable
1313  (must be done _after_ threads_preinit) */
1314 
1315  if (!classcache_init())
1316  os::abort("vm_create: classcache_init failed");
1317 
1318  /* Initialize the code memory management. */
1319  /* AFTER: threads_preinit */
1320 
1321  codememory_init();
1322 
1323  /* initialize the finalizer stuff (must be done _after_
1324  threads_preinit) */
1325 
1326  if (!finalizer_init())
1327  os::abort("vm_create: finalizer_init failed");
1328 
1329  /* Initialize the JIT compiler. */
1330 
1331  jit_init();
1332  code_init();
1333  methodtree_init();
1334 
1335  /* AFTER: utf8_init, classcache_init */
1336 
1337  loader_preinit();
1338  linker_preinit();
1339 
1340  // AFTER: loader_preinit, linker_preinit
1342 
1343  loader_init();
1345  linker_init();
1346 
1347  // AFTER: loader_init, linker_init
1349  method_init();
1350 
1351 #if defined(ENABLE_JIT)
1352  trap_init();
1353 #endif
1354 
1355  if (!builtin_init())
1356  os::abort("vm_create: builtin_init failed");
1357 
1358  /* Register the native methods implemented in the VM. */
1359  /* BEFORE: threads_init */
1360 
1361  nativevm_preinit();
1362 
1363 #if defined(ENABLE_JNI)
1364  /* Initialize the JNI subsystem (must be done _before_
1365  threads_init, as threads_init can call JNI methods
1366  (e.g. NewGlobalRef). */
1367 
1368  if (!jni_init())
1369  os::abort("vm_create: jni_init failed");
1370 #endif
1371 
1372 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1373  /* Initialize the local reference table for the main thread. */
1374  /* BEFORE: threads_init */
1375 
1376  if (!localref_table_init())
1377  os::abort("vm_create: localref_table_init failed");
1378 #endif
1379 
1380  /* Iinitialize some important system classes. */
1381  /* BEFORE: threads_init */
1382 
1383  initialize_init();
1384  threads_init();
1385 
1386  /* Initialize the native VM subsystem. */
1387  /* AFTER: threads_init (at least for SUN's classes) */
1388 
1389  if (!nativevm_init())
1390  os::abort("vm_create: nativevm_init failed");
1391 
1392 #if defined(ENABLE_PROFILING)
1393  /* initialize profiling */
1394 
1395  if (!profile_init())
1396  os::abort("vm_create: profile_init failed");
1397 #endif
1398 
1399  /* start the signal handler thread */
1400 
1401 #if defined(__LINUX__)
1402  /* XXX Remove for exact-GC. */
1403  if (threads_pthreads_implementation_nptl)
1404 #endif
1405  if (!signal_start_thread())
1406  os::abort("vm_create: signal_start_thread failed");
1407 
1408  /* finally, start the finalizer thread */
1409 
1410  if (!finalizer_start_thread())
1411  os::abort("vm_create: finalizer_start_thread failed");
1412 
1413 #if !defined(NDEBUG)
1414  /* start the memory profiling thread */
1415 
1417  if (!memory_start_thread())
1418  os::abort("vm_create: memory_start_thread failed");
1419 #endif
1420 
1421 #ifdef ENABLE_THREADS
1422  // Start the recompilation thread (must be done before the
1423  // profiling thread).
1424  // FIXME Only works for one recompiler.
1425  _recompiler.start();
1426 #endif
1427 
1428 #if defined(ENABLE_PROFILING)
1429  /* start the profile sampling thread */
1430 
1431 /* if (opt_prof) */
1432 /* if (!profile_start_thread()) */
1433 /* os::abort("vm_create: profile_start_thread failed"); */
1434 #endif
1435 
1436  /* Increment the number of VMs. */
1437 
1438  vms++;
1439 
1440  // Initialization is done, VM is created.
1441  _created = true;
1442  _initializing = false;
1443 
1444  // Set the VM inittime.
1445  _inittime = builtin_currenttimemillis();
1446 
1447  // Hook point after the VM is initialized.
1448  Hook::vm_init();
1449 
1450  // Print the run-time VM configuration after all stuff is set and
1451  // the VM is initialized.
1452  if (opt_PrintConfig)
1453  print_run_time_config();
1454 
1455  // Start runtime agents after the VM is created.
1456  if (!start_runtime_agents())
1457  os::abort("vm_create: start_runtime_agents failed");
1458 }
1459 
1460 
1461 /**
1462  * Print build-time (default) VM configuration.
1463  */
1465 {
1466  puts("CACAO " VERSION_FULL " configure/build options:");
1467  puts("");
1468  puts(" ./configure: " VERSION_CONFIGURE_ARGS "");
1469 #if defined(__VERSION__)
1470  puts(" CC : " VERSION_CC " (" __VERSION__ ")");
1471  puts(" CXX : " VERSION_CXX " (" __VERSION__ ")");
1472 #else
1473  puts(" CC : " VERSION_CC "");
1474  puts(" CXX : " VERSION_CXX "");
1475 #endif
1476  puts(" CFLAGS : " VERSION_CFLAGS "");
1477  puts(" CXXFLAGS : " VERSION_CXXFLAGS "");
1478  puts(" CPPFLAGS : " VERSION_CPPFLAGS "");
1479 
1480  puts("");
1481 
1482  puts("Build-time (default) variables:\n");
1483  printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1484  printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1485  printf(" stack size : %d\n", STACK_SIZE);
1486 
1487 #if defined(ENABLE_JRE_LAYOUT)
1488  // When we're building with JRE-layout, the default paths are the
1489  // same as the runtime paths.
1490 #else
1491 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1492  puts(" gnu.classpath.boot.library.path: " JAVA_RUNTIME_LIBRARY_LIBDIR);
1493  puts(" java.boot.class.path : " CACAO_VM_ZIP ":" JAVA_RUNTIME_LIBRARY_CLASSES);
1494 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1495  puts(" sun.boot.library.path : " JAVA_RUNTIME_LIBRARY_LIBDIR);
1496  puts(" java.boot.class.path : " JAVA_RUNTIME_LIBRARY_CLASSES);
1497 # endif
1498 #endif
1499 
1500  puts("");
1501 }
1502 
1503 
1504 /**
1505  * Print run-time VM configuration.
1506  */
1508 {
1509  puts("Run-time variables:\n");
1510  printf(" maximum heap size : %d\n", opt_heapmaxsize);
1511  printf(" initial heap size : %d\n", opt_heapstartsize);
1512  printf(" stack size : %d\n", opt_stacksize);
1513 
1514 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1515  printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1516 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1517  printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1518 #endif
1519 
1520  printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1521  printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1522 
1523  puts("");
1524 }
1525 
1526 
1527 /**
1528  * Start runtime agents which are provided by the JRE but need to be
1529  * started explicitly by the VM.
1530  */
1532 {
1533 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1534 
1535  // Nothing to do.
1536 
1537 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1538 
1539  // Check whether the management agent should be loaded.
1540  if ((_properties.get("com.sun.management.jmxremote") != NULL) ||
1541  (_properties.get("com.sun.management.snmp") != NULL))
1542  {
1543 
1544  // Load the management agent class.
1545  classinfo* class_sun_management_Agent;
1546  if (!(class_sun_management_Agent = load_class_from_sysloader(Utf8String::from_utf8("sun/management/Agent"))))
1547  return false;
1548 
1549  // Link the management agent class.
1550  if (!link_class(class_sun_management_Agent))
1551  return false;
1552 
1553  // Actually start the management agent.
1554  methodinfo* m = class_resolveclassmethod(class_sun_management_Agent,
1555  Utf8String::from_utf8("startAgent"),
1556  utf8::void__void,
1558  false);
1559 
1560  if (m == NULL)
1561  return false;
1562 
1563  (void) vm_call_method(m, NULL);
1564 
1565  if (exceptions_get_exception() != NULL)
1566  return false;
1567  }
1568 
1569 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
1570 
1571  // Nothing to do.
1572 
1573 #else
1574 # error unknown classpath configuration
1575 #endif
1576 
1577  return true;
1578 }
1579 
1580 static void write_logfiles();
1581 
1582 /* vm_run **********************************************************************
1583 
1584  Runs the main-method of the passed class.
1585 
1586 *******************************************************************************/
1587 
1588 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1589 {
1590  methodinfo* m;
1591  int status;
1592 
1593 #if !defined(NDEBUG)
1594  if (opt_CompileAll) {
1595  vm_compile_all();
1596  /* write logfiles */
1597  write_logfiles();
1598  return;
1599  }
1600 #endif
1601 
1602  /* Get the main class or jar file argument. */
1603 
1604  char* mainname = NULL;
1605 
1606  if (opt_index < vm_args->nOptions) {
1607  /* Get main-class argument. */
1608 
1609  mainname = vm_args->options[opt_index].optionString;
1610 
1611  /* If the main class argument is a jar file, put it into the
1612  classpath. */
1613 
1614  if (opt_jar == true) {
1615  char* p = MNEW(char, strlen(mainname) + strlen("0"));
1616 
1617  strcpy(p, mainname);
1618 
1619 #if defined(ENABLE_JAVASE)
1620  VM::get_current()->get_properties().put("java.class.path", p);
1621 #endif
1622  }
1623  else {
1624  /* Replace dots with slashes in the class name. */
1625 
1626  for (unsigned int i = 0; i < strlen(mainname); i++)
1627  if (mainname[i] == '.')
1628  mainname[i] = '/';
1629  }
1630 
1631  /* Move index to first argument. */
1632 
1633  opt_index++;
1634  }
1635 
1636  /* Do we have a main-class argument? */
1637 
1638  if (mainname == NULL)
1639  usage();
1640 
1641 #if defined(COMPILE_METHOD)
1642  if (opt_CompileMethod != NULL) {
1643  vm_compile_method(mainname);
1644  /* write logfiles */
1645  write_logfiles();
1646  return;
1647  }
1648 #endif
1649 
1650  /* Build argument array. */
1651 
1652  int32_t oalength = vm_args->nOptions - opt_index;
1653 
1654  ObjectArray oa(oalength, class_java_lang_String);
1655 
1656  if (oa.is_null())
1657  vm_exit(1);
1658 
1659  for (int i = 0; i < oalength; i++) {
1660  char* option = vm_args->options[opt_index + i].optionString;
1661 
1662  java_handle_t* s = JavaString::from_utf8(option);
1663 
1664  oa.set_element(i, s);
1665  }
1666 
1667  /* set return value to OK */
1668 
1669  status = 0;
1670 
1671  if (opt_jar == true) {
1672  /* open jar file with java.util.jar.JarFile */
1673 
1674  mainname = vm_get_mainclass_from_jar(mainname);
1675 
1676  if (mainname == NULL)
1677  vm_exit(1);
1678  }
1679 
1680  /* load the main class */
1681 
1682  Utf8String mainutf = Utf8String::from_utf8(mainname);
1683 
1684 #if defined(ENABLE_JAVAME_CLDC1_1)
1686 #else
1687  classinfo* mainclass = load_class_from_sysloader(mainutf);
1688 #endif
1689 
1690  /* error loading class */
1691 
1693 
1694  if ((e != NULL) || (mainclass == NULL)) {
1697  vm_exit(1);
1698  }
1699 
1700  if (!link_class(mainclass)) {
1702  vm_exit(1);
1703  }
1704 
1705  /* find the `main' method of the main class */
1706 
1707  m = class_resolveclassmethod(mainclass,
1708  Utf8String::from_utf8("main"),
1709  Utf8String::from_utf8("([Ljava/lang/String;)V"),
1711  false);
1712 
1713  if (exceptions_get_exception()) {
1715  vm_exit(1);
1716  }
1717 
1718  /* there is no main method or it isn't static */
1719 
1720  if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1723  Utf8String::from_utf8("main"),
1724  Utf8String::from_utf8("([Ljava/lang/String;)V"));
1725 
1727  vm_exit(1);
1728  }
1729 
1730 #ifdef TYPEINFO_DEBUG_TEST
1731  /* test the typeinfo system */
1732  typeinfo_test();
1733 #endif
1734 
1735  /* start the main thread */
1736 
1737  (void) vm_call_method(m, NULL, oa.get_handle());
1738 
1739  /* exception occurred? */
1740 
1741  if (exceptions_get_exception()) {
1743  status = 1;
1744  }
1745 
1746  /* Detach the main thread so that it appears to have ended when
1747  the application's main method exits. */
1748 
1750  os::abort("vm_run: Could not detach main thread.");
1751 
1752  /* write logfiles */
1753  write_logfiles();
1754 
1755  /* Destroy the JavaVM. */
1756 
1757  (void) vm_destroy(vm);
1758 
1759  /* And exit. */
1760 
1761  vm_exit(status);
1762 }
1763 
1764 
1765 /* vm_destroy ******************************************************************
1766 
1767  Unloads a Java VM and reclaims its resources.
1768 
1769 *******************************************************************************/
1770 
1772 {
1773  /* Create a a trivial new Java waiter thread called
1774  "DestroyJavaVM". */
1775 
1776  JavaVMAttachArgs args;
1777 
1778  args.name = (char*) "DestroyJavaVM";
1779  args.group = NULL;
1780 
1781  if (!thread_attach_current_thread(&args, false))
1782  return 1;
1783 
1784  /* Wait until we are the last non-daemon thread. */
1785 
1787 
1788  // Hook point before the VM is actually destroyed.
1790 
1791  /* VM is gone. */
1792 
1793 // _created = false;
1794 
1795  /* Everything is ok. */
1796 
1797  return 0;
1798 }
1799 
1800 
1801 /* vm_exit *********************************************************************
1802 
1803  Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1804 
1805 *******************************************************************************/
1806 
1807 void vm_exit(s4 status)
1808 {
1809  methodinfo *m;
1810 
1811  /* signal that we are exiting */
1812 
1813 // _exiting = true;
1814 
1815  assert(class_java_lang_System);
1817 
1818 #if defined(ENABLE_JVMTI)
1819  if (jvmti || (dbgcom!=NULL)) {
1821  if (jvmti) jvmti_agentunload();
1822  }
1823 #endif
1824 
1827  exit(1);
1828  }
1829 
1830  /* call java.lang.System.exit(I)V */
1831 
1833  Utf8String::from_utf8("exit"),
1834  utf8::int__void,
1836  true);
1837 
1838  if (m == NULL) {
1840  exit(1);
1841  }
1842 
1843  /* call the exit function with passed exit status */
1844 
1845  (void) vm_call_method(m, NULL, status);
1846 
1847  /* If we had an exception, just ignore the exception and exit with
1848  the proper code. */
1849 
1850  vm_shutdown(status);
1851 }
1852 
1853 
1854 /* vm_shutdown *****************************************************************
1855 
1856  Terminates the system immediately without freeing memory explicitly
1857  (to be used only for abnormal termination).
1858 
1859 *******************************************************************************/
1860 
1861 void vm_shutdown(s4 status)
1862 {
1863  if (opt_verbose
1864 #if defined(ENABLE_STATISTICS)
1865  || opt_getcompilingtime || opt_stat
1866 #endif
1867  )
1868  {
1869  log_text("CACAO terminated by shutdown");
1870  dolog("Exit status: %d\n", (s4) status);
1871 
1872  }
1873 
1874 #if defined(ENABLE_JVMTI)
1875  /* terminate cacaodbgserver */
1876  if (dbgcom!=NULL) {
1877  mutex_lock(&dbgcomlock);
1878  dbgcom->running=1;
1879  mutex_unlock(&dbgcomlock);
1881  }
1882 #endif
1883 
1884 #if defined(ENABLE_THREADS)
1886 #endif
1887 
1888  exit(status);
1889 }
1890 
1891 #include "toolbox/OStream.hpp"
1892 
1893 /* vm_exit_handler *************************************************************
1894 
1895  The exit_handler function is called upon program termination.
1896 
1897  ATTENTION: Don't free system resources here! Some threads may still
1898  be running as this is called from VMRuntime.exit(). The OS does the
1899  cleanup for us.
1900 
1901 *******************************************************************************/
1902 
1904 {
1905 #if !defined(NDEBUG)
1906  if (showmethods)
1908 
1909  if (showconstantpool)
1911 
1912 # if defined(ENABLE_PROFILING)
1913  if (opt_prof)
1915 # endif
1916 #endif /* !defined(NDEBUG) */
1917 
1918 #if defined(ENABLE_CYCLES_STATS)
1919  builtin_print_cycles_stats(log_get_logfile());
1920  stacktrace_print_cycles_stats(log_get_logfile());
1921 #endif
1922 
1923  if (opt_verbose
1924 #if defined(ENABLE_STATISTICS)
1925  || opt_getcompilingtime || opt_stat
1926 #endif
1927  )
1928  {
1929  log_text("CACAO terminated");
1930 
1931 #if 0 && defined(ENABLE_STATISTICS)
1932  if (opt_stat) {
1933 #ifdef TYPECHECK_STATISTICS
1934 // XXX TYPECHECK_STATISTICS is currently not usable
1935  typecheck_print_statistics(get_logfile());
1936 #endif
1937  }
1938 
1939 #endif /* defined(ENABLE_STATISTICS) */
1940  }
1941  /* vm_print_profile(stderr);*/
1942 }
1943 
1944 static void write_logfiles() {
1945 #if defined(ENABLE_RT_TIMING)
1946  if (!opt_RtTimingLogfile) {
1947  FILE *file = fopen("rt-timing.log", "w");
1948  if (file == NULL)
1949  /* fallback to stdout */
1950  file = stdout;
1951  opt_RtTimingLogfile = file;
1952  }
1953  {
1954  assert(opt_RtTimingLogfile);
1955  cacao::OStream OS(opt_RtTimingLogfile);
1956  if (!opt_RtTimingCSV) {
1957  OS << "\nreal-time measurment:\n" << cacao::nl;
1958  cacao::RTGroup::root().print(OS);
1959  }
1960  else {
1961  cacao::RTGroup::print_csv_header(OS);
1962  cacao::RTGroup::root().print_csv(OS);
1963  }
1964  }
1965 #endif
1966 
1967 #if defined(ENABLE_STATISTICS)
1968  if (!opt_StatisticsLogfile) {
1969  FILE *file = fopen("statistics.log", "w");
1970  if (file == NULL)
1971  /* fallback to stdout */
1972  file = stdout;
1973  opt_StatisticsLogfile = file;
1974  }
1975  {
1976  assert(opt_StatisticsLogfile);
1977  cacao::OStream OS(opt_StatisticsLogfile);
1978  if (!opt_StatisticsCSV) {
1979  cacao::StatGroup::root().print(OS);
1980  }
1981  else {
1982  cacao::StatGroup::print_csv_header(OS);
1983  cacao::StatGroup::root().print_csv(OS);
1984  }
1985  }
1986 #endif
1987 
1988 }
1989 
1990 /* vm_abort_disassemble ********************************************************
1991 
1992  Prints an error message, disassemble the given code range (if
1993  enabled) and aborts the VM.
1994 
1995  IN:
1996  pc.......PC to disassemble
1997  count....number of instructions to disassemble
1998 
1999 *******************************************************************************/
2000 
2001 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2002 {
2003  va_list ap;
2004 #if defined(ENABLE_DISASSEMBLER)
2005  int i;
2006 #endif
2007 
2008  /* Print debug message. */
2009 
2010  log_start();
2011 
2012  va_start(ap, text);
2013  log_vprint(text, ap);
2014  va_end(ap);
2015 
2016  log_finish();
2017 
2018  /* Print the PC. */
2019 
2020  log_println("PC=0x%0" PRINTF_INTPTR_NUM_HEXDIGITS PRIxPTR, (intptr_t) pc);
2021 
2022 #if defined(ENABLE_DISASSEMBLER)
2023  log_println("machine instructions at PC:");
2024 
2025  /* Disassemble the given number of instructions. */
2026 
2027  for (i = 0; i < count; i++)
2028  // FIXME disassinstr should use void*.
2029  pc = disassinstr((u1*) pc);
2030 #endif
2031 
2032  os::abort("Aborting...");
2033 }
2034 
2035 
2036 /* vm_get_mainclass_from_jar ***************************************************
2037 
2038  Gets the name of the main class from a JAR's manifest file.
2039 
2040 *******************************************************************************/
2041 
2042 static char *vm_get_mainclass_from_jar(char *mainname)
2043 {
2044  classinfo *c;
2045  java_handle_t *o;
2046  methodinfo *m;
2047  java_handle_t *s;
2048 
2049 #if defined(ENABLE_JAVAME_CLDC1_1)
2050  c = load_class_bootstrap(Utf8String::from_utf8("java/util/jar/JarFile"));
2051 #else
2052  c = load_class_from_sysloader(Utf8String::from_utf8("java/util/jar/JarFile"));
2053 #endif
2054 
2055  if (c == NULL) {
2057  return NULL;
2058  }
2059 
2060  /* create JarFile object */
2061 
2062  o = builtin_new(c);
2063 
2064  if (o == NULL) {
2066  return NULL;
2067  }
2068 
2070  utf8::init,
2071  utf8::java_lang_String__void,
2073  true);
2074 
2075  if (m == NULL) {
2077  return NULL;
2078  }
2079 
2080  s = JavaString::from_utf8(mainname);
2081 
2082  (void) vm_call_method(m, o, s);
2083 
2084  if (exceptions_get_exception()) {
2086  return NULL;
2087  }
2088 
2089  /* get manifest object */
2090 
2092  Utf8String::from_utf8("getManifest"),
2093  Utf8String::from_utf8("()Ljava/util/jar/Manifest;"),
2095  true);
2096 
2097  if (m == NULL) {
2099  return NULL;
2100  }
2101 
2102  o = vm_call_method(m, o);
2103 
2104  if (o == NULL) {
2105  fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2106  return NULL;
2107  }
2108 
2109 
2110  /* get Main Attributes */
2111 
2112  LLNI_class_get(o, c);
2113 
2115  Utf8String::from_utf8("getMainAttributes"),
2116  Utf8String::from_utf8("()Ljava/util/jar/Attributes;"),
2118  true);
2119 
2120  if (m == NULL) {
2122  return NULL;
2123  }
2124 
2125  o = vm_call_method(m, o);
2126 
2127  if (o == NULL) {
2128  fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2129  return NULL;
2130  }
2131 
2132 
2133  /* get property Main-Class */
2134 
2135  LLNI_class_get(o, c);
2136 
2138  Utf8String::from_utf8("getValue"),
2139  Utf8String::from_utf8("(Ljava/lang/String;)Ljava/lang/String;"),
2141  true);
2142 
2143  if (m == NULL) {
2145  return NULL;
2146  }
2147 
2148  s = JavaString::from_utf8("Main-Class");
2149 
2150  o = vm_call_method(m, o, s);
2151 
2152  if (o == NULL) {
2153  fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2154  fprintf(stderr, "%s\n", mainname);
2155  return NULL;
2156  }
2157 
2158  return JavaString(o).to_chars();
2159 }
2160 
2161 
2162 /* vm_compile_all **************************************************************
2163 
2164  Compile all methods found in the bootclasspath.
2165 
2166 *******************************************************************************/
2167 
2168 #if !defined(NDEBUG)
2169 static void vm_compile_all(void)
2170 {
2171  classinfo *c;
2172  methodinfo *m;
2173  u4 slot;
2174  classcache_name_entry *nmen;
2175  classcache_class_entry *clsen;
2176  s4 i;
2177 
2178  /* create all classes found in the bootclasspath */
2179  /* XXX currently only works with zip/jar's */
2180 
2182 
2183  /* link all classes */
2184 
2185  for (slot = 0; slot < hashtable_classcache.size; slot++) {
2187 
2188  for (; nmen; nmen = nmen->hashlink) {
2189  /* iterate over all class entries */
2190 
2191  for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2192  c = clsen->classobj;
2193 
2194  if (c == NULL)
2195  continue;
2196 
2197  if (!(c->state & CLASS_LINKED)) {
2198  if (!link_class(c)) {
2199  fprintf(stderr, "Error linking: ");
2201  fprintf(stderr, "\n");
2202 
2203  /* print out exception and cause */
2204 
2206 
2207  /* goto next class */
2208 
2209  continue;
2210  }
2211  }
2212 
2213  /* compile all class methods */
2214 
2215  for (i = 0; i < c->methodscount; i++) {
2216  m = &(c->methods[i]);
2217 
2218  if (m->jcode != NULL) {
2219  if (!jit_compile(m)) {
2220  fprintf(stderr, "Error compiling: ");
2222  fprintf(stderr, ".");
2223  utf_fprint_printable_ascii(stderr, m->name);
2225  fprintf(stderr, "\n");
2226 
2227  /* print out exception and cause */
2228 
2230  }
2231  }
2232  }
2233  }
2234  }
2235  }
2236 }
2237 #endif /* !defined(NDEBUG) */
2238 
2239 
2240 /* vm_compile_method ***********************************************************
2241 
2242  Compile a specific method.
2243 
2244 *******************************************************************************/
2245 
2246 RT_REGISTER_TIMER(compiler_method,"compiler-all","compiler overall")
2247 
2248 #if defined(COMPILE_METHOD)
2249 
2250 #if defined(ENABLE_COMPILER2)
2252 #endif
2253 
2254 static void vm_compile_method(char* mainname)
2255 {
2256  methodinfo *m;
2257 
2258  if (opt_jar == true) {
2259  /* open jar file with java.util.jar.JarFile */
2260 
2261  mainname = vm_get_mainclass_from_jar(mainname);
2262 
2263  if (mainname == NULL)
2264  vm_exit(1);
2265  }
2266 
2267  /* load the main class */
2268 
2269  Utf8String mainutf = Utf8String::from_utf8(mainname);
2270 
2272 
2273  /* error loading class */
2274 
2276 
2277  if ((e != NULL) || (mainclass == NULL)) {
2280  vm_exit(1);
2281  }
2282 
2283  if (!link_class(mainclass)) {
2285  vm_exit(1);
2286  }
2287 
2288  if (opt_CompileSignature != NULL) {
2289  m = class_resolveclassmethod(mainclass,
2292  mainclass,
2293  false);
2294  }
2295  else {
2296  m = class_resolveclassmethod(mainclass,
2298  NULL,
2299  mainclass,
2300  false);
2301  }
2302 
2303  if (m == NULL)
2304  os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2306 
2307  RT_TIMER_START(compiler_method);
2308 #if defined(ENABLE_COMPILER2)
2311  } else
2312 #endif
2313  {
2314  jit_compile(m);
2315  }
2316  RT_TIMER_STOP(compiler_method);
2317 }
2318 #endif /* !defined(NDEBUG) */
2319 
2320 
2321 /* vm_call_array ***************************************************************
2322 
2323  Calls a Java method with a variable number of arguments, passed via
2324  an argument array.
2325 
2326  ATTENTION: This function has to be used outside the nativeworld.
2327 
2328 *******************************************************************************/
2329 
2330 #define VM_CALL_ARRAY(name, type) \
2331 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2332 { \
2333  methoddesc *md; \
2334  void *pv; \
2335  type value; \
2336  \
2337  assert(m->code != NULL); \
2338  \
2339  md = m->parseddesc; \
2340  pv = m->code->entrypoint; \
2341  \
2342  STATISTICS(count_calls_native_to_java++); \
2343  \
2344  value = asm_vm_call_method##name(pv, array, md->memuse); \
2345  \
2346  return value; \
2347 }
2348 
2349 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2350 {
2351  methoddesc *md;
2352  void *pv;
2353  java_object_t *o;
2354 
2355  assert(m->code != NULL);
2356 
2357  md = m->parseddesc;
2358  pv = m->code->entrypoint;
2359 
2360  STATISTICS(count_calls_native_to_java++);
2361 
2362  o = asm_vm_call_method(pv, array, md->memuse);
2363 
2364  if (md->returntype.type == TYPE_VOID)
2365  o = NULL;
2366 
2367  return LLNI_WRAP(o);
2368 }
2369 
2370 VM_CALL_ARRAY(_int, int32_t)
2371 VM_CALL_ARRAY(_long, int64_t)
2372 VM_CALL_ARRAY(_float, float)
2373 VM_CALL_ARRAY(_double, double)
2374 
2375 
2376 /* vm_call_method **************************************************************
2377 
2378  Calls a Java method with a variable number of arguments.
2379 
2380 *******************************************************************************/
2381 
2382 #define VM_CALL_METHOD(name, type) \
2383 type vm_call_##name(methodinfo *m, java_handle_t *o, ...) \
2384 { \
2385  va_list ap; \
2386  type value; \
2387  \
2388  va_start(ap, o); \
2389  value = vm_call_##name##_valist(m, o, ap); \
2390  va_end(ap); \
2391  \
2392  return value; \
2393 }
2394 
2396 VM_CALL_METHOD(method_int, int32_t)
2397 VM_CALL_METHOD(method_long, int64_t)
2398 VM_CALL_METHOD(method_float, float)
2399 VM_CALL_METHOD(method_double, double)
2400 
2401 
2402 /* vm_call_method_valist *******************************************************
2403 
2404  Calls a Java method with a variable number of arguments, passed via
2405  a va_list.
2406 
2407 *******************************************************************************/
2408 
2409 #define VM_CALL_METHOD_VALIST(name, type) \
2410 type vm_call_method##name##valist(methodinfo *m, java_handle_t *o, \
2411  va_list ap) \
2412 { \
2413  uint64_t *array; \
2414  type value; \
2415  \
2416  if (m->code == NULL) \
2417  if (!jit_compile(m)) \
2418  return 0; \
2419  \
2420  THREAD_NATIVEWORLD_EXIT; \
2421  \
2422  DumpMemoryArea dma; \
2423  \
2424  array = argument_vmarray_from_valist(m, o, ap); \
2425  value = vm_call##name##array(m, array); \
2426  \
2427  THREAD_NATIVEWORLD_ENTER; \
2428  \
2429  return value; \
2430 }
2431 
2433 VM_CALL_METHOD_VALIST(_int_, int32_t)
2434 VM_CALL_METHOD_VALIST(_long_, int64_t)
2435 VM_CALL_METHOD_VALIST(_float_, float)
2436 VM_CALL_METHOD_VALIST(_double_, double)
2437 
2438 
2439 /* vm_call_method_jvalue *******************************************************
2440 
2441  Calls a Java method with a variable number of arguments, passed via
2442  a jvalue array.
2443 
2444 *******************************************************************************/
2445 
2446 #define VM_CALL_METHOD_JVALUE(name, type) \
2447 type vm_call_method##name##jvalue(methodinfo *m, java_handle_t *o, \
2448  const jvalue *args) \
2449 { \
2450  uint64_t *array; \
2451  type value; \
2452  \
2453  if (m->code == NULL) \
2454  if (!jit_compile(m)) \
2455  return 0; \
2456  \
2457  THREAD_NATIVEWORLD_EXIT; \
2458  \
2459  DumpMemoryArea dma; \
2460  \
2461  array = argument_vmarray_from_jvalue(m, o, args); \
2462  value = vm_call##name##array(m, array); \
2463  \
2464  THREAD_NATIVEWORLD_ENTER; \
2465  \
2466  return value; \
2467 }
2468 
2470 VM_CALL_METHOD_JVALUE(_int_, int32_t)
2471 VM_CALL_METHOD_JVALUE(_long_, int64_t)
2472 VM_CALL_METHOD_JVALUE(_float_, float)
2473 VM_CALL_METHOD_JVALUE(_double_, double)
2474 
2475 
2476 /* vm_call_method_objectarray **************************************************
2477 
2478  Calls a Java method with a variable number if arguments, passed via
2479  an objectarray of boxed values. Returns a boxed value.
2480 
2481 *******************************************************************************/
2482 
2484  java_handle_objectarray_t *params)
2485 {
2486  uint64_t *array;
2488  java_handle_t *ro;
2489  imm_union value;
2490 
2491  /* Prevent compiler warnings. */
2492 
2493  ro = NULL;
2494 
2495  /* compile methods which are not yet compiled */
2496 
2497  if (m->code == NULL)
2498  if (!jit_compile(m))
2499  return NULL;
2500 
2501  /* leave the nativeworld */
2502 
2504 
2505  // Create new dump memory area.
2506  DumpMemoryArea dma;
2507 
2508  /* Fill the argument array from a object-array. */
2509 
2510  array = argument_vmarray_from_objectarray(m, o, params);
2511 
2512  if (array == NULL) {
2513  /* enter the nativeworld again */
2514 
2516 
2518 
2519  return NULL;
2520  }
2521 
2522  switch (m->parseddesc->returntype.primitivetype) {
2523  case PRIMITIVETYPE_VOID:
2524  value.a = vm_call_array(m, array);
2525  break;
2526 
2527  case PRIMITIVETYPE_BOOLEAN:
2528  case PRIMITIVETYPE_BYTE:
2529  case PRIMITIVETYPE_CHAR:
2530  case PRIMITIVETYPE_SHORT:
2531  case PRIMITIVETYPE_INT:
2532  value.i = vm_call_int_array(m, array);
2533  break;
2534 
2535  case PRIMITIVETYPE_LONG:
2536  value.l = vm_call_long_array(m, array);
2537  break;
2538 
2539  case PRIMITIVETYPE_FLOAT:
2540  value.f = vm_call_float_array(m, array);
2541  break;
2542 
2543  case PRIMITIVETYPE_DOUBLE:
2544  value.d = vm_call_double_array(m, array);
2545  break;
2546 
2547  case TYPE_ADR:
2548  ro = vm_call_array(m, array);
2549  break;
2550 
2551  default:
2552  os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2553  }
2554 
2555  /* enter the nativeworld again */
2556 
2558 
2559  /* box the return value if necesarry */
2560 
2561  if (m->parseddesc->returntype.primitivetype != (PrimitiveType) TYPE_ADR)
2562  ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2563 
2564  /* check for an exception */
2565 
2566  xptr = exceptions_get_exception();
2567 
2568  if (xptr != NULL) {
2569  /* clear exception pointer, we are calling JIT code again */
2570 
2572 
2574  }
2575 
2576  return ro;
2577 }
2578 
2579 
2580 /* Legacy C interface *********************************************************/
2581 
2582 extern "C" {
2583 
2585 
2586 void vm_abort(const char* text, ...)
2587 {
2588  va_list ap;
2589 
2590  log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2591 
2592  // Print the log message.
2593  log_start();
2594 
2595  va_start(ap, text);
2596  log_vprint(text, ap);
2597  va_end(ap);
2598 
2599  log_finish();
2600 
2601  // Print a backtrace.
2603 
2604  // Now abort the VM.
2605  os::abort();
2606 }
2607 
2608 }
2609 
2610 
2611 /*
2612  * These are local overrides for various environment variables in Emacs.
2613  * Please do not remove this and leave it at the end of the file, where
2614  * Emacs will automagically detect them.
2615  * ---------------------------------------------------------------------
2616  * Local variables:
2617  * mode: c++
2618  * indent-tabs-mode: t
2619  * c-basic-offset: 4
2620  * tab-width: 4
2621  * End:
2622  * vim:noexpandtab:sw=4:ts=4:
2623  */
bool opt_foo
Definition: options.cpp:49
void exceptions_throw_illegalargumentexception(void)
mutex_t dbgcomlock
Definition: jvmti.c:79
#define dolog
Definition: logging.hpp:171
Utf8String name
Definition: method.hpp:71
bool localref_table_init(void)
Definition: localref.cpp:81
jlong jlong jlong jlong jint jmethodID jint slot
Definition: jvmti.h:497
char * opt_arg
Definition: options.cpp:47
#define pv
Definition: md-asm.hpp:65
static void write_logfiles()
Definition: vm.cpp:1944
bool opt_showdisassemble
Definition: options.cpp:85
static void usage(void)
Definition: vm.cpp:382
#define GCMNEW(type, num)
Definition: memory.hpp:118
void linker_init(void)
Definition: linker.cpp:166
float f
Definition: global.hpp:56
Definition: vm.cpp:158
#define STATISTICS(x)
Wrapper for statistics only code.
Definition: statistics.hpp:975
#define JAVA_VERSION
Definition: global.hpp:145
methodinfo * class_resolveclassmethod(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer, bool throwexception)
Definition: class.cpp:1211
void exceptions_print_stacktrace(void)
const JNIInvokeInterface_ _Jv_JNIInvokeInterface
Definition: jni.cpp:3841
void jvmti_cacaodbgserver_quit()
Definition: cacaodbg.c:211
s4 vms
Definition: vm.cpp:104
double d
Definition: global.hpp:57
void gc_init(u4 heapmaxsize, u4 heapstartsize)
Definition: gc.c:75
void threads_preinit(void)
Definition: thread.cpp:84
java_object_t * asm_vm_call_method(void *pv, uint64_t *array, int32_t stackargs)
#define RT_TIMER_STOP(var)
Stop the timer var.
Definition: rt-timing.hpp:695
u1 * disassinstr(u1 *code)
Definition: disass.cpp:48
void lock_init(void)
Definition: lock.cpp:154
#define MSET(ptr, byte, type, num)
Definition: memory.hpp:104
methodinfo * methods
Definition: class.hpp:113
void vm_exit_handler(void)
Definition: vm.cpp:1903
Definition: vm.cpp:147
void jvmti_set_phase(jvmtiPhase p)
Definition: jvmti.c:4386
void linker_preinit(void)
Definition: linker.cpp:131
int opt_ProfileGCMemoryUsage
Definition: options.cpp:199
void nativevm_preinit(void)
Definition: nativevm.cpp:61
void code_init(void)
Definition: code.cpp:46
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
void method_init(void)
Definition: method.cpp:99
classinfo * load_class_from_sysloader(Utf8String name)
Definition: loader.cpp:1012
virtual java_handle_array_t * get_handle() const
Definition: array.hpp:103
void exceptions_throw_nosuchmethoderror(classinfo *c, Utf8String name, Utf8String desc)
Definition: exceptions.cpp:889
Definition: vm.cpp:186
#define HEAP_STARTSIZE
Definition: vm.cpp:118
bool builtin_init(void)
Definition: builtin.cpp:251
void * a
Definition: global.hpp:58
Definition: vm.cpp:129
JNIEnv * get_jnienv()
Definition: vm.hpp:106
static JavaString from_utf8(Utf8String)
Definition: string.cpp:184
Definition: vm.cpp:148
int opt_ProfileMemoryUsage
Definition: options.cpp:200
bool jvmti
Definition: cacaodbg.h:114
void initialize_init(void)
Definition: initialize.cpp:63
bool thread_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
Attaches the current thread to the VM.
Definition: thread.cpp:495
classcache_class_entry * next
Definition: classcache.hpp:103
Definition: vm.cpp:135
static void initialize()
Definition: utf8.cpp:110
FILE * log_get_logfile()
Definition: logging.cpp:90
s4 state
Definition: class.hpp:115
#define THREAD_NATIVEWORLD_EXIT
Definition: thread.hpp:209
bool signal_init(void)
Definition: signal.cpp:59
static void fullversion(void)
Definition: vm.cpp:553
bool opt_intrp
Definition: options.cpp:55
Actual implementation of access class for Java Object arrays.
Definition: array.hpp:381
static void print_backtrace()
Print a C backtrace.
Definition: os.cpp:252
void jobjects_register_dyn_offsets()
void loader_init(void)
Definition: loader.cpp:184
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
_Jv_JavaVM JavaVM
Definition: jni.hpp:114
bool initverbose
Definition: options.cpp:71
bool jni_init(void)
Definition: jni.cpp:190
u1 * jit_compile(methodinfo *m)
Definition: jit.cpp:274
bool VM_create(JavaVM **p_vm, void **p_env, void *vm_args)
C wrapper for VM::create.
Definition: vm.cpp:626
hashtable hashtable_classcache
Definition: classcache.cpp:223
s4 opt_heapstartsize
Definition: options.cpp:64
#define RT_TIMER_START(var)
Start the timer var.
Definition: rt-timing.hpp:694
static java_handle_t * vm_call_array(methodinfo *m, uint64_t *array)
Definition: vm.cpp:2349
void finalizer_join_thread()
Definition: finalizer.cpp:215
MachineCode * compile(methodinfo *m)
Definition: Compiler.cpp:123
classinfo * load_class_bootstrap(Utf8String name)
Definition: loader.cpp:1276
void trap_init(void)
Mmap the first memory page to support hardware exceptions and check the maximum hardware trap displac...
Definition: trap.cpp:68
JNIEnv * VM_get_jnienv()
Definition: vm.cpp:2584
Definition: vm.cpp:239
void utf_fprint_printable_ascii_classname(FILE *file, Utf8String u)
Definition: utf8.cpp:665
char * opt_CompileSignature
Definition: options.cpp:167
static void vm_compile_method(char *mainname)
Definition: vm.cpp:2254
java_handle_t * vm_call_method(methodinfo *m, java_handle_t *o,...)
static java_handle_t * box(int type, imm_union value)
Box a primitive of the given type.
Definition: primitive.cpp:393
uint8_t u1
Definition: types.hpp:40
Definition: vm.cpp:145
Definition: vm.cpp:188
Definition: vm.cpp:125
void assertion_ea_da(const char *name, bool enabled)
Definition: assertion.cpp:55
void set_element(int32_t index, T value)
Definition: array.hpp:255
int vm_destroy(JavaVM *vm)
Definition: vm.cpp:1771
classinfo * class_java_lang_Object
Definition: globals.cpp:28
char * opt_CompileMethod
Definition: options.cpp:166
void vm_preinit()
Hook point before the VM is initialized.
Definition: hook.hpp:155
Second stage compiler class.
void log_finish(void)
Definition: logging.cpp:117
void log_println(const char *text,...)
Definition: logging.cpp:193
#define VM_CALL_METHOD_VALIST(name, type)
Definition: vm.cpp:2409
const char * opt_filter_show_method
Definition: options.cpp:145
void vm_shutdown()
Hook point before the VM is actually destroyed.
Definition: hook.hpp:168
s4 opt_heapmaxsize
Definition: options.cpp:63
Definition: vm.cpp:189
bool opt_ifconv
Definition: options.cpp:118
const char * opt_filter_verbosecall_exclude
Definition: options.cpp:144
opt_struct opts[]
Definition: vm.cpp:243
java_handle_t * builtin_new(classinfo *c)
Definition: builtin.cpp:816
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
bool assertion_user_enabled
Definition: assertion.cpp:45
bool opt_debugcolor
Definition: options.cpp:68
#define LLNI_class_get(obj, variable)
Definition: llni.hpp:60
#define VM_CALL_METHOD_JVALUE(name, type)
Definition: vm.cpp:2446
void codememory_init(void)
Definition: codememory.cpp:56
JNINativeInterface_ _Jv_JNINativeInterface
Definition: jni.cpp:3856
void methodtree_init(void)
Definition: methodtree.cpp:64
char * to_chars() const
Definition: string.cpp:413
#define OPT_DONE
Definition: options.hpp:43
JNIEnv jthread jmethodID jlocation jobject exception
Definition: jvmti.h:272
PrimitiveType
JVM types.
Definition: primitive.hpp:55
Definition: vm.cpp:143
Utf8String descriptor
Definition: method.hpp:72
void options_xx(JavaVMInitArgs *vm_args)
Definition: options.cpp:552
#define RT_REGISTER_TIMER(var, name, description)
Register a new (toplevel) timer.
Definition: rt-timing.hpp:681
#define LLNI_WRAP(obj)
Definition: llni.hpp:51
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
Definition: vm.cpp:1588
static void print_build_time_config()
Print build-time (default) VM configuration.
Definition: vm.cpp:1464
Definition: vm.cpp:131
bool opt_showddatasegment
Definition: options.cpp:86
classcache_class_entry * classes
Definition: classcache.hpp:95
bool opt_verbosejni
Definition: options.cpp:75
JNIEnv jthread jmethodID method
Definition: jvmti.h:207
void exceptions_print_current_exception(void)
Dump memory area.
Definition: dumpmemory.hpp:90
bool nativevm_init(void)
Definition: nativevm.cpp:175
bool compileverbose
Definition: options.cpp:82
bool checkbounds
Definition: options.cpp:89
OptionPrefix & root()
Definition: Option.cpp:34
static void initialize_table()
Fill the primitive type table with the primitive-type classes, array-classes and wrapper classes...
Definition: primitive.cpp:94
static void version(bool opt_exit)
Definition: vm.cpp:529
Option< bool > enabled("DebugCompiler2","compiler with compiler2", false, option::xx_root())
Definition: Compiler.hpp:112
This file contains the statistics framework.
uint64_t u8
Definition: types.hpp:49
Utf8String name
Definition: class.hpp:91
bool checksync
Definition: options.cpp:90
#define STAT_REGISTER_GROUP_VAR(type, var, init, name, description, group)
Register an statistics variable and add it to a group.
Definition: statistics.hpp:967
#define VM_CALL_ARRAY(name, type)
Definition: vm.cpp:2330
void class_showconstantpool(classinfo *c)
Definition: class.cpp:2342
Simple stream class for formatted output.
Definition: OStream.hpp:141
#define OPT_IGNORE
Definition: options.hpp:45
void ** ptr
Definition: hashtable.hpp:781
void vm_exit(s4 status)
Definition: vm.cpp:1807
void profile_printstats(void)
Prints profiling statistics gathered during runtime.
Definition: profile.cpp:209
void log_vprint(const char *text, va_list ap)
Definition: logging.cpp:135
Definition: vm.cpp:172
void jit_init(void)
Definition: jit.cpp:151
bool finalizer_start_thread()
Definition: finalizer.cpp:203
Properties & get_properties()
Definition: vm.hpp:113
void log_start(void)
Definition: logging.cpp:106
Definition: vm.cpp:173
#define exceptions_get_and_clear_exception
Definition: md-asm.hpp:98
void loader_load_all_classes(void)
Definition: loader.cpp:439
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
bool showmethods
Definition: options.cpp:78
static classinfo * mainclass
Definition: vm.cpp:107
u1 * jcode
Definition: method.hpp:86
MIIterator i
void log_init(const char *fname)
Definition: logging.cpp:75
typedesc returntype
Definition: descriptor.hpp:166
bool opt_verbosegc
Definition: options.cpp:74
void threads_join_all_threads()
void print_run_time_config()
Print run-time VM configuration.
Definition: vm.cpp:1507
classinfo * class_java_lang_System
Definition: globals.cpp:40
int32_t s4
Definition: types.hpp:45
Definition: vm.cpp:132
s4 opt_index
Definition: options.cpp:46
OStream & OS
static void abort()
Definition: os.hpp:196
bool classcache_init(void)
Definition: classcache.cpp:247
int opt_PrintConfig
Definition: options.cpp:197
bool thread_detach_current_thread(void)
Detaches the current thread from the VM.
Definition: thread-none.cpp:86
codeinfo * code
Definition: method.hpp:103
int32_t methodscount
Definition: class.hpp:112
void threads_init(void)
Definition: thread.cpp:164
Definition: vm.cpp:144
bool opt_verify
Definition: options.cpp:103
void jvmti_agentunload()
Definition: jvmti.c:4533
int options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
Definition: options.cpp:400
Definition: vm.cpp:154
This file contains the real-time timing utilities.
void utf_fprint_printable_ascii(FILE *file, Utf8String u)
Definition: utf8.cpp:650
MIIterator e
static void Xusage(void)
Definition: vm.cpp:432
Definition: vm.cpp:153
static char * vm_get_mainclass_from_jar(char *mainstring)
Definition: vm.cpp:2042
uint32_t u4
Definition: types.hpp:46
bool opt_verboseclass
Definition: options.cpp:73
java_handle_t * vm_call_method_objectarray(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params)
Definition: vm.cpp:2483
bool finalizer_init()
Definition: finalizer.cpp:151
bool opt_jar
Definition: options.cpp:51
s4 opt_stacksize
Definition: options.cpp:65
classinfo * class_java_lang_String
Definition: globals.cpp:39
methoddesc * parseddesc
Definition: method.hpp:78
void vm_init()
Hook point after the VM is initialized.
Definition: hook.hpp:145
bool opt_showintermediate
Definition: options.cpp:87
void class_showmethods(classinfo *c)
Definition: class.cpp:2439
bool memory_start_thread(void)
Definition: memory.cpp:217
void loader_preinit(void)
Definition: loader.cpp:141
#define pc
Definition: md-asm.hpp:56
#define MNEW(type, num)
Definition: memory.hpp:96
bool opt_jit
Definition: options.cpp:54
bool makeinitializations
Definition: options.cpp:95
bool profile_init(void)
Definition: profile.cpp:60
static void post_initialize_table()
Finish the primitive-type table initialization.
Definition: primitive.cpp:204
bool assertion_system_enabled
Definition: assertion.cpp:46
Definition: classcache.hpp:98
classinfo * link_class(classinfo *c)
Definition: linker.cpp:378
#define STAT_DECLARE_GROUP(var)
Declare an external group (or subgroup).
Definition: statistics.hpp:970
bool showutf
Definition: options.cpp:80
int opt_CompileAll
Definition: options.cpp:165
void exceptions_clear_exception(void)
Definition: exceptions.cpp:127
uint64_t * argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params)
Definition: argument.cpp:548
bool opt_run
Definition: options.cpp:61
static void initialize()
Definition: string.cpp:95
static void vm_compile_all(void)
Definition: vm.cpp:2169
java_handle_t * exceptions_get_exception(void)
Definition: exceptions.cpp:76
void exceptions_throw_noclassdeffounderror_cause(java_handle_t *cause)
Definition: exceptions.cpp:713
static bool create(JavaVM **p_vm, void **p_env, void *vm_args)
Implementation for JNI_CreateJavaVM.
Definition: vm.cpp:591
s8 builtin_currenttimemillis(void)
Definition: builtin.cpp:2063
bool showconstantpool
Definition: options.cpp:79
bool loadverbose
Definition: options.cpp:70
void vm_abort_disassemble(void *pc, int count, const char *text,...)
Definition: vm.cpp:2001
void exceptions_throw_invocationtargetexception(java_handle_t *cause)
#define STACK_SIZE
Definition: vm.cpp:119
#define MREALLOC(ptr, type, num1, num2)
Definition: memory.hpp:99
classcache_name_entry * hashlink
Definition: classcache.hpp:94
const char * opt_filter_verbosecall_include
Definition: options.cpp:143
s4 flags
Definition: method.hpp:70
#define VM_CALL_METHOD(name, type)
Definition: vm.cpp:2382
bool start_runtime_agents()
Start runtime agents which are provided by the JRE but need to be started explicitly by the VM...
Definition: vm.cpp:1531
bool jni_version_check(int version)
Definition: jni.cpp:282
bool is_null() const
Definition: array.hpp:203
VM(JavaVMInitArgs *)
VM constructor.
Definition: vm.cpp:636
#define THREAD_NATIVEWORLD_ENTER
Definition: thread.hpp:208
bool signal_start_thread(void)
Definition: signal.cpp:331
#define HEAP_MAXSIZE
Definition: vm.cpp:117
Nl nl
Definition: OStream.cpp:56
#define log_text(s)
Definition: logging.hpp:170
Definition: vm.cpp:225
cacaodbgcommunication * dbgcom
Definition: cacaodbg.h:112
#define PRINTF_INTPTR_NUM_HEXDIGITS
Definition: global.hpp:80
classinfo * classobj
Definition: classcache.hpp:100
#define MFREE(ptr, type, num)
Definition: memory.hpp:97
static void put(java_handle_t *p, const char *key, const char *value)
Add the given property to the given Java system properties.
Definition: properties.cpp:531
Represent an instance of a VM.
Definition: vm.hpp:56
Definition: classcache.hpp:91
#define printf(...)
Definition: ssa2.cpp:40
void typeinfo_test()
Definition: typeinfo.cpp:2101
static VM * get_current()
Definition: vm.hpp:99
u1 * entrypoint
Definition: code.hpp:84
bool opt_verbose
Definition: options.cpp:67
#define xptr
Definition: md-asm.hpp:50