#include "native/vm/nativevm.h"
-#include "threads/threads-common.h"
+#include "threads/lock-common.h"
+#include "threads/mutex.h"
+#include "threads/threadlist.h"
+#include "threads/thread.h"
#include "toolbox/logging.h"
#include "vm/jit/argument.h"
#include "vm/jit/asmpart.h"
+#include "vm/jit/code.h"
#if defined(ENABLE_DISASSEMBLER)
# include "vm/jit/disass.h"
#endif
#include "vm/jit/jit.h"
+#include "vm/jit/methodtree.h"
#if defined(ENABLE_PROFILING)
# include "vm/jit/optimizing/profile.h"
# include "vm/jit/python.h"
#endif
+#include "vm/jit/trap.h"
+
#include "vmcore/classcache.h"
#include "vmcore/options.h"
#include "vmcore/statistics.h"
s4 vms = 0; /* number of VMs created */
bool vm_initializing = false;
-bool vm_exiting = false;
+bool vm_created = false;
+bool vm_exiting = false;
char *mainstring = NULL;
classinfo *mainclass = NULL;
OPT_LSRA,
#endif
-#if defined(ENABLE_INLINING)
- OPT_INLINING,
-#if !defined(NDEBUG)
- OPT_INLINE_LOG,
-#endif
-#if defined(ENABLE_INLINING_DEBUG)
- OPT_INLINE_DEBUG_ALL,
- OPT_INLINE_DEBUG_END,
- OPT_INLINE_DEBUG_MIN,
- OPT_INLINE_DEBUG_MAX,
-#endif /* defined(ENABLE_INLINING_DEBUG) */
-#endif /* defined(ENABLE_INLINING) */
-
#if defined(ENABLE_INTRP)
/* interpreter options */
{ "Xprof", false, OPT_PROF },
#endif
- /* inlining options */
-
-#if defined(ENABLE_INLINING)
-#if defined(ENABLE_INLINING_DEBUG)
- { "ia", false, OPT_INLINE_DEBUG_ALL },
- { "ii", true, OPT_INLINE_DEBUG_MIN },
- { "im", true, OPT_INLINE_DEBUG_MAX },
- { "ie", true, OPT_INLINE_DEBUG_END },
-#endif /* defined(ENABLE_INLINING_DEBUG) */
-#if !defined(NDEBUG)
- { "il", false, OPT_INLINE_LOG },
-#endif
- { "i", false, OPT_INLINING },
-#endif /* defined(ENABLE_INLINING) */
-
/* keep these at the end of the list */
#if !defined(NDEBUG)
#endif
puts(" (d)atasegment data segment listing");
-#if defined(ENABLE_INLINING)
- puts(" -i activate inlining");
-#if !defined(NDEBUG)
- puts(" -il log inlining");
-#endif
-#if defined(ENABLE_INLINING_DEBUG)
- puts(" -ia use inlining for all methods");
- puts(" -ii <size> set minimum size for inlined result");
- puts(" -im <size> set maximum size for inlined result");
- puts(" -ie <number> stop inlining after the given number of roots");
-#endif /* defined(ENABLE_INLINING_DEBUG) */
-#endif /* defined(ENABLE_INLINING) */
-
#if defined(ENABLE_IFCONV)
puts(" -ifconv use if-conversion");
#endif
printf(" initial heap size : %d\n", HEAP_STARTSIZE);
printf(" stack size : %d\n", STACK_SIZE);
-#if defined(WITH_JRE_LAYOUT)
+#if defined(ENABLE_JRE_LAYOUT)
/* When we're building with JRE-layout, the default paths are the
same as the runtime paths. */
#else
break;
#endif
-#if defined(ENABLE_INLINING)
-#if defined(ENABLE_INLINING_DEBUG)
- case OPT_INLINE_DEBUG_ALL:
- opt_inline_debug_all = true;
- break;
- case OPT_INLINE_DEBUG_END:
- opt_inline_debug_end_counter = atoi(opt_arg);
- break;
- case OPT_INLINE_DEBUG_MIN:
- opt_inline_debug_min_size = atoi(opt_arg);
- break;
- case OPT_INLINE_DEBUG_MAX:
- opt_inline_debug_max_size = atoi(opt_arg);
- break;
-#endif /* defined(ENABLE_INLINING_DEBUG) */
-#if !defined(NDEBUG)
- case OPT_INLINE_LOG:
- opt_inline_debug_log = true;
- break;
-#endif /* !defined(NDEBUG) */
-
- case OPT_INLINING:
- opt_inlining = true;
- break;
-#endif /* defined(ENABLE_INLINING) */
-
#if defined(ENABLE_IFCONV)
case OPT_IFCONV:
opt_ifconv = true;
gc_init(opt_heapmaxsize, opt_heapstartsize);
#if defined(ENABLE_THREADS)
+ /* BEFORE: threads_preinit */
+
+ threadlist_init();
+
/* AFTER: gc_init (directly after, as this initializes the
stopworldlock lock */
threads_preinit();
+ lock_init();
+ critical_init();
#endif
/* install architecture dependent signal handlers */
/* AFTER: threads_preinit */
- if (!utf8_init())
- vm_abort("vm_create: utf8_init failed");
+ utf8_init();
/* AFTER: thread_preinit */
if (!finalizer_init())
vm_abort("vm_create: finalizer_init failed");
- /* initializes jit compiler */
+ /* Initialize the JIT compiler. */
jit_init();
+ code_init();
+ methodtree_init();
#if defined(ENABLE_PYTHON)
pythonpass_init();
/* AFTER: loader_init, linker_init */
primitive_postinit();
+ method_init();
- exceptions_init();
+#if defined(ENABLE_JIT)
+ trap_init();
+#endif
if (!builtin_init())
vm_abort("vm_create: builtin_init failed");
/* Register the native methods implemented in the VM. */
/* BEFORE: threads_init */
- if (!nativevm_preinit())
- vm_abort("vm_create: nativevm_preinit failed");
+ nativevm_preinit();
#if defined(ENABLE_JNI)
/* Initialize the JNI subsystem (must be done _before_
vm_abort("vm_create: localref_table_init failed");
#endif
+ /* Iinitialize some important system classes. */
+ /* BEFORE: threads_init */
+
+ initialize_init();
+
#if defined(ENABLE_THREADS)
- if (!threads_init())
- vm_abort("vm_create: threads_init failed");
+ threads_init();
#endif
/* Initialize the native VM subsystem. */
/* AFTER: threads_init (at least for SUN's classes) */
- if (!nativevm_init())
- vm_abort("vm_create: nativevm_init failed");
+ nativevm_init();
#if defined(ENABLE_PROFILING)
/* initialize profiling */
}
#endif
- /* increment the number of VMs */
+ /* Increment the number of VMs. */
vms++;
- /* initialization is done */
+ /* Initialization is done, VM is created.. */
+ vm_created = true;
vm_initializing = false;
-#if !defined(NDEBUG)
/* Print the VM configuration after all stuff is set and the VM is
initialized. */
if (opt_PrintConfig)
vm_printconfig();
-#endif
/* everything's ok */
s4 oalength;
utf *u;
java_handle_t *s;
- s4 status;
- s4 i;
+ int status;
+ int i;
+
+#if defined(ENABLE_THREADS)
+ threadobject *t;
+#endif
#if !defined(NDEBUG)
if (compileall) {
status = 1;
}
- /* unload the JavaVM */
+#if defined(ENABLE_THREADS)
+ /* Detach the main thread so that it appears to have ended when
+ the application's main method exits. */
+
+ t = thread_get_current();
+
+ if (!threads_detach_thread(t))
+ vm_abort("vm_run: Could not detach main thread.");
+#endif
+
+ /* Destroy the JavaVM. */
(void) vm_destroy(vm);
- /* and exit */
+ /* And exit. */
vm_exit(status);
}
*******************************************************************************/
-s4 vm_destroy(JavaVM *vm)
+int vm_destroy(JavaVM *vm)
{
#if defined(ENABLE_THREADS)
+ /* Create a a trivial new Java waiter thread called
+ "DestroyJavaVM". */
+
+ JavaVMAttachArgs args;
+
+ args.name = "DestroyJavaVM";
+ args.group = NULL;
+
+ if (!threads_attach_current_thread(&args, false))
+ return 1;
+
+ /* Wait until we are the last non-daemon thread. */
+
threads_join_all_threads();
#endif
- /* everything's ok */
+ /* VM is gone. */
+
+ vm_created = false;
+
+ /* Everything is ok. */
return 0;
}
#if defined(ENABLE_JVMTI)
/* terminate cacaodbgserver */
if (dbgcom!=NULL) {
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
dbgcom->running=1;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
jvmti_cacaodbgserver_quit();
}
#endif
o = vm_call_method(m, o, s);
if (o == NULL) {
- exceptions_print_stacktrace();
+ fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
+ fprintf(stderr, "%s\n", mainstring);
return NULL;
}