-/* src/vm/finalizer.c - finalizer linked list and thread
+/* src/vm/vm.c - VM startup and shutdown functions
Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
Authors: Christian Thalinger
- Changes:
+ Changes: Martin Platter
- $Id: finalizer.c 4357 2006-01-22 23:33:38Z twisti $
+ $Id: vm.c 4357 2006-01-22 23:33:38Z twisti $
*/
#include "native/jni.h"
#include "native/native.h"
-#if defined(USE_THREADS)
-# if defined(NATIVE_THREADS)
-# include "threads/native/threads.h"
-# else
-# include "threads/green/threads.h"
-# include "threads/green/locks.h"
-# endif
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
#endif
#include "vm/classcache.h"
u1 *intrp_main_stack = NULL;
#endif
-void **stackbottom = NULL;
-
char *mainstring = NULL;
classinfo *mainclass = NULL;
/* define heap sizes **********************************************************/
-#define HEAP_MAXSIZE 64 * 1024 * 1024 /* default 64MB */
-#define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
-#define STACK_SIZE 128 * 1024 /* default 128kB */
+#define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
+#define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
+#define STACK_SIZE 64 * 1024 /* default 64kB */
/* define command line options ************************************************/
puts(" value is appended to the bootstrap class path");
puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
puts(" value is prepended to the bootstrap class path");
- puts(" -Xms<size> set the initial size of the heap (default: 2MB)");
- puts(" -Xmx<size> set the maximum size of the heap (default: 64MB)");
- puts(" -Xss<size> set the thread stack size (default: 128kB)");
+ printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
+ printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
+ printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
puts(" -Xprof[:bb] collect and print profiling data");
#if defined(ENABLE_JVMTI)
/* -Xdebug option depend on gnu classpath JDWP options. options:
#else
puts(" CC : "VERSION_CC"");
#endif
- puts(" CFLAGS : "VERSION_CFLAGS"");
+ puts(" CFLAGS : "VERSION_CFLAGS"\n");
+
+ puts("Default variables:\n");
+ printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
+ printf(" initial heap size : %d\n", HEAP_STARTSIZE);
+ printf(" stack size : %d\n", STACK_SIZE);
+ puts(" java.boot.class.path: "CACAO_VM_ZIP_PATH":"CLASSPATH_GLIBJ_ZIP_PATH"");
+ puts(" java.library.path : "CLASSPATH_LIBRARY_PATH"\n");
+
+ puts("Runtime variables:\n");
+ printf(" maximum heap size : %d\n", opt_heapmaxsize);
+ printf(" initial heap size : %d\n", opt_heapstartsize);
+ printf(" stack size : %d\n", opt_stacksize);
+ printf(" java.boot.class.path: %s\n", bootclasspath);
}
{
char *cp;
s4 cplen;
- u4 heapmaxsize;
- u4 heapstartsize;
s4 opt;
s4 i, j, k;
+
+#if defined(ENABLE_JVMTI)
+ lt_dlhandle handle;
+ char* libname;
+ bool agentbypath = false;;
+#endif
+
+
+
/* check the JNI version requested */
switch (vm_args->version) {
checknull = false;
opt_noieee = false;
- heapmaxsize = HEAP_MAXSIZE;
- heapstartsize = HEAP_STARTSIZE;
- opt_stacksize = STACK_SIZE;
+ opt_heapmaxsize = HEAP_MAXSIZE;
+ opt_heapstartsize = HEAP_STARTSIZE;
+ opt_stacksize = STACK_SIZE;
#if defined(ENABLE_JVMTI)
/* initialize JVMTI related **********************************************/
- jvmtibrkpt.brk=NULL;
- jvmtibrkpt.num=0;
- jvmtibrkpt.size=0;
- jdwp = jvmti = dbgprocess = false;
+ jdwp = jvmti = false;
#endif
/* initialize properties before commandline handling */
throw_cacao_exception_exit(string_java_lang_InternalError,
"Unable to init properties");
+ /* add some default properties */
+
+ properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
+
+
/* iterate over all passed options */
while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
/* if no '=' is given, just create an empty property */
properties_add(opt_arg, "");
-
+
didit:
break;
}
break;
+
case OPT_AGENTPATH:
+ agentbypath = true;
case OPT_AGENTLIB:
jvmti=true;
agentarg = opt_arg;
j = atoi(opt_arg);
if (opt == OPT_MX)
- heapmaxsize = j;
+ opt_heapmaxsize = j;
else if (opt == OPT_MS)
- heapstartsize = j;
+ opt_heapstartsize = j;
else
opt_stacksize = j;
}
}
#if defined(ENABLE_JVMTI)
- /* The fork has to occure before threads a created because threads are
- not forked correctly (see man pthread_atfork). Varibale dbgprocess
- stores information whether this is the debugger or debuggee process. */
- if (jvmti || jdwp) {
- set_jvmti_phase(JVMTI_PHASE_ONLOAD);
- dbgprocess = cacaodbgfork();
- }
-
- if (dbgprocess && jvmti) { /* is this the parent/debugger process ? */
- agentload(agentarg);
- set_jvmti_phase(JVMTI_PHASE_PRIMORDIAL);
+ if (jvmti) {
+ jvmti_set_phase(JVMTI_PHASE_ONLOAD);
+ jvmti_agentload(agentarg, agentbypath, &handle, &libname);
}
+ jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
#endif
/* initialize the garbage collector */
- gc_init(heapmaxsize, heapstartsize);
+ gc_init(opt_heapmaxsize, opt_heapstartsize);
#if defined(ENABLE_INTRP)
/* Allocate main thread stack on the Java heap. */
}
#endif
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
+#if defined(ENABLE_THREADS)
threads_preinit();
#endif
- initLocks();
-#endif
/* initialize the string hashtable stuff: lock (must be done
_after_ threads_preinit) */
/* initialize the loader subsystems (must be done _after_
classcache_init) */
- if (!loader_init((u1 *) stackbottom))
+ if (!loader_init())
throw_main_exception_exit();
if (!linker_init())
if (!builtin_init())
throw_main_exception_exit();
-#if defined(USE_THREADS)
- if (!threads_init((u1 *) stackbottom))
+ /* Initialize the JNI subsystem (must be done _before_
+ threads_init, as threads_init can call JNI methods
+ (e.g. NewGlobalRef). */
+
+ if (!jni_init())
+ throw_main_exception_exit();
+
+#if defined(ENABLE_THREADS)
+ if (!threads_init())
throw_main_exception_exit();
#endif
if (!initialize_class(class_java_lang_System))
throw_main_exception_exit();
- /* JNI init creates a Java object (this means running Java code) */
-
- if (!jni_init())
- throw_main_exception_exit();
-
#if defined(ENABLE_PROFILING)
/* initialize profiling */
throw_main_exception_exit();
#endif
-#if defined(USE_THREADS)
+#if defined(ENABLE_THREADS)
/* finally, start the finalizer thread */
if (!finalizer_start_thread())
/* throw_main_exception_exit(); */
#endif
+#if defined(ENABLE_JVMTI)
+ if (jvmti) {
+ /* add agent library to native library hashtable */
+ native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
+ }
+#endif
+
/* increment the number of VMs */
vms++;
s4 vm_destroy(JavaVM *vm)
{
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
- joinAllThreads();
-#else
- killThread(currentThread);
-#endif
+#if defined(ENABLE_THREADS)
+ threads_join_all_threads();
#endif
/* everything's ok */
assert(class_java_lang_System->state & CLASS_LOADED);
#if defined(ENABLE_JVMTI)
- if (dbgprocess) {
- set_jvmti_phase(JVMTI_PHASE_DEAD);
- if (jvmti) agentunload();
+ if (jvmti || (dbgcom!=NULL)) {
+ jvmti_set_phase(JVMTI_PHASE_DEAD);
+ if (jvmti) jvmti_agentunload();
}
#endif
void vm_shutdown(s4 status)
{
-#if defined(ENABLE_JVMTI)
- if (dbgprocess) {
- set_jvmti_phase(JVMTI_PHASE_DEAD);
- if (jvmti) agentunload();
- ipcrm();
- }
-#endif
if (opt_verbose
#if defined(ENABLE_STATISTICS)
|| opt_getcompilingtime || opt_stat
void vm_exit_handler(void)
{
-#if defined(ENABLE_JVMTI)
- if (jvmti && jdwp) set_jvmti_phase(JVMTI_PHASE_DEAD);
- if (jvmti) agentunload();
- ipcrm();
-#endif
-
#if !defined(NDEBUG)
if (showmethods)
class_showmethods(mainclass);
# endif
#endif /* !defined(NDEBUG) */
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
- clear_thread_flags(); /* restores standard file descriptor
- flags */
-#endif
-
#if defined(ENABLE_RT_TIMING)
rt_timing_print_time_stats(stderr);
#endif
}
+/* vm_abort ********************************************************************
+
+ Prints an error message and aborts the VM.
+
+*******************************************************************************/
+
+void vm_abort(const char *text, ...)
+{
+ va_list ap;
+
+ /* print the log message */
+
+ log_start();
+
+ va_start(ap, text);
+ log_vprint(text, ap);
+ va_end(ap);
+
+ log_finish();
+
+ /* now abort the VM */
+
+ abort();
+}
+
+
/* vm_vmargs_from_valist *******************************************************
XXX