Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: vm.c 8295 2007-08-11 17:57:24Z michi $
-
*/
#include <stdint.h>
#include <stdlib.h>
-#if defined(WITH_JRE_LAYOUT)
-# include <libgen.h>
-# include <unistd.h>
-#endif
-
#include "vm/types.h"
#include "arch.h"
#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_Byte.h"
-#include "native/include/java_lang_Character.h"
-#include "native/include/java_lang_Short.h"
-#include "native/include/java_lang_Integer.h"
-#include "native/include/java_lang_Boolean.h"
-#include "native/include/java_lang_Long.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Double.h"
-
#include "native/vm/nativevm.h"
#include "threads/threads-common.h"
bool vm_initializing = false;
bool vm_exiting = false;
-char *cacao_prefix = NULL;
-char *cacao_libjvm = NULL;
-char *classpath_libdir = NULL;
-
-char *_Jv_bootclasspath; /* contains the boot classpath */
-char *_Jv_classpath; /* contains the classpath */
-char *_Jv_java_library_path;
-
char *mainstring = NULL;
classinfo *mainclass = NULL;
-char *specificmethodname = NULL;
-char *specificsignature = NULL;
-
-bool startit = true;
-
#if defined(ENABLE_INTRP)
u1 *intrp_main_stack = NULL;
#endif
{ "noasyncgc", false, OPT_IGNORE },
#if defined(ENABLE_VERIFIER)
{ "noverify", false, OPT_NOVERIFY },
+ { "Xverify:none", false, OPT_NOVERIFY },
#endif
{ "v", false, OPT_VERBOSE1 },
{ "verbose:", true, OPT_VERBOSE },
}
+#if 0
static void XXusage(void)
{
puts(" -v write state-information");
exit(1);
}
+#endif
/* version *********************************************************************
printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
printf(" initial heap size : %d\n", HEAP_STARTSIZE);
printf(" stack size : %d\n", STACK_SIZE);
-#if defined(WITH_CLASSPATH_GNU)
- puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
+
+#if defined(WITH_JRE_LAYOUT)
+ /* When we're building with JRE-layout, the default paths are the
+ same as the runtime paths. */
#else
- puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
+# if defined(WITH_CLASSPATH_GNU)
+ puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
+ puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
+# elif defined(WITH_CLASSPATH_SUN)
+ puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
+ puts(" java.boot.class.path : "CLASSPATH_CLASSES);
+# endif
#endif
- puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
+
+ puts("");
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(" libjvm.so : %s\n", cacao_libjvm);
- printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
- printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
- printf(" java.class.path : %s\n", _Jv_classpath);
+
+#if defined(WITH_CLASSPATH_GNU)
+ printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
+#elif defined(WITH_CLASSPATH_SUN)
+ printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
+#endif
+
+ printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
+ printf(" java.class.path : %s\n", properties_get("java.class.path"));
}
#if defined(ENABLE_JNI)
/* setup the local ref table (must be created after vm_create) */
- if (!jni_init_localref_table())
+ if (!localref_table_init())
goto error;
#endif
bool vm_create(JavaVMInitArgs *vm_args)
{
- char *cp;
- s4 len;
- s4 opt;
- s4 i, j;
+ int len;
+ char *p;
+ char *boot_class_path;
+ char *class_path;
+ int opt;
+ int i, j;
bool opt_version;
bool opt_exit;
_Jv_jvm->starttime = builtin_currenttimemillis();
- /* get stuff from the environment *****************************************/
-
-#if defined(WITH_JRE_LAYOUT)
- /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
-
- cacao_prefix = MNEW(char, 4096);
-
- if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
- vm_abort("readlink failed: %s\n", strerror(errno));
-
- /* get the path of the current executable */
-
- cacao_prefix = dirname(cacao_prefix);
-
- if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
- vm_abort("libjvm name to long for buffer\n");
-
- /* concatenate the library name */
-
- strcat(cacao_prefix, "/..");
-
- /* now set path to libjvm.so */
-
- len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
-
- cacao_libjvm = MNEW(char, len);
- strcpy(cacao_libjvm, cacao_prefix);
- strcat(cacao_libjvm, "/lib/libjvm");
-
- /* and finally set the path to GNU Classpath libraries */
-
- len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
-
- classpath_libdir = MNEW(char, len);
- strcpy(classpath_libdir, cacao_prefix);
- strcat(classpath_libdir, "/lib/classpath");
-#else
- cacao_prefix = CACAO_PREFIX;
- cacao_libjvm = CACAO_LIBDIR"/libjvm";
-
-# if defined(WITH_CLASSPATH_GNU)
- classpath_libdir = CLASSPATH_LIBDIR"/classpath";
-# else
- classpath_libdir = CLASSPATH_LIBDIR;
-# endif
-#endif
-
- /* set the bootclasspath */
-
- cp = getenv("BOOTCLASSPATH");
-
- if (cp != NULL) {
- _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
- strcpy(_Jv_bootclasspath, cp);
- }
- else {
-#if defined(WITH_JRE_LAYOUT)
- len =
-# if defined(WITH_CLASSPATH_GNU)
- strlen(cacao_prefix) +
- strlen("/share/cacao/vm.zip") +
- strlen(":") +
-# endif
- strlen(cacao_prefix) +
- strlen("/share/classpath/glibj.zip") +
- strlen("0");
-
- _Jv_bootclasspath = MNEW(char, len);
-# if defined(WITH_CLASSPATH_GNU)
- strcat(_Jv_bootclasspath, cacao_prefix);
- strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
- strcat(_Jv_bootclasspath, ":");
-# endif
- strcat(_Jv_bootclasspath, cacao_prefix);
- strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
-#else
-# if defined(WITH_CLASSPATH_GNU)
- len =
- strlen(CACAO_VM_ZIP) +
- strlen(":") +
- strlen(CLASSPATH_CLASSES) +
- strlen("0");
-# elif defined(WITH_CLASSPATH_SUN)
- /* This is the bootclasspath taken from HotSpot (see
- hotspot/src/share/vm/runtime/os.cpp
- (os::set_boot_path)). */
-
- len =
- strlen(CLASSPATH_PREFIX"/lib/resources.jar:"
- CLASSPATH_PREFIX"/lib/rt.jar:"
- CLASSPATH_PREFIX"/lib/sunrsasign.jar:"
- CLASSPATH_PREFIX"/lib/jsse.jar:"
- CLASSPATH_PREFIX"/lib/jce.jar:"
- CLASSPATH_PREFIX"/lib/charsets.jar:"
- CLASSPATH_PREFIX"/classes") +
- strlen("0");
-# elif defined(WITH_CLASSPATH_CLDC1_1)
- len =
- strlen(CLASSPATH_CLASSES) +
- strlen("0");
-# else
-# error unknown classpath configuration
-# endif
-
- _Jv_bootclasspath = MNEW(char, len);
-
-# if defined(WITH_CLASSPATH_GNU)
- strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
- strcat(_Jv_bootclasspath, ":");
- strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
-# elif defined(WITH_CLASSPATH_SUN)
- strcpy(_Jv_bootclasspath,
- CLASSPATH_PREFIX"/lib/resources.jar:"
- CLASSPATH_PREFIX"/lib/rt.jar:"
- CLASSPATH_PREFIX"/lib/sunrsasign.jar:"
- CLASSPATH_PREFIX"/lib/jsse.jar:"
- CLASSPATH_PREFIX"/lib/jce.jar:"
- CLASSPATH_PREFIX"/lib/charsets.jar:"
- CLASSPATH_PREFIX"/classes");
-# elif defined(WITH_CLASSPATH_CLDC1_1)
- strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
-# else
-# error unknown classpath configuration
-# endif
-#endif
- }
-
- /* set the classpath */
-
- cp = getenv("CLASSPATH");
-
- if (cp != NULL) {
- _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
- strcat(_Jv_classpath, cp);
- }
- else {
- _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
- strcpy(_Jv_classpath, ".");
- }
-
- /* Get and set java.library.path. */
-
- _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
-
- if (_Jv_java_library_path == NULL)
- _Jv_java_library_path = "";
-
/* interpret the options **************************************************/
opt_version = false;
/* Initialize and fill properties before command-line handling. */
- if (!properties_init())
- vm_abort("vm_create: properties_init failed");
-
- /* Set the classpath properties. */
-
-#if defined(ENABLE_JAVASE)
- properties_add("java.boot.class.path", _Jv_bootclasspath);
- properties_add("sun.boot.class.path", _Jv_bootclasspath);
- properties_add("java.class.path", _Jv_classpath);
-#endif
+ properties_init();
+ properties_set();
/* iterate over all passed options */
break;
case OPT_CLASSPATH:
- /* forget old classpath and set the argument as new classpath */
- MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
+ /* Forget old classpath and set the argument as new
+ classpath. */
+
+ class_path = properties_get("java.class.path");
+
+ p = MNEW(char, strlen(opt_arg) + strlen("0"));
- _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
- strcpy(_Jv_classpath, opt_arg);
+ strcpy(p, opt_arg);
#if defined(ENABLE_JAVASE)
- properties_add("java.class.path", _Jv_classpath);
+ properties_add("java.class.path", p);
#endif
+
+ MFREE(class_path, char, strlen(class_path));
break;
case OPT_D:
/* Forget default bootclasspath and set the argument as
new boot classpath. */
- MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
+ boot_class_path = properties_get("sun.boot.class.path");
- _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
- strcpy(_Jv_bootclasspath, opt_arg);
+ p = MNEW(char, strlen(opt_arg) + strlen("0"));
-#if defined(ENABLE_JAVASE)
- properties_add("java.boot.class.path", _Jv_bootclasspath);
- properties_add("sun.boot.class.path", _Jv_bootclasspath);
-#endif
+ strcpy(p, opt_arg);
+
+ properties_add("sun.boot.class.path", p);
+ properties_add("java.boot.class.path", p);
+
+ MFREE(boot_class_path, char, strlen(boot_class_path));
break;
case OPT_BOOTCLASSPATH_A:
- /* append to end of bootclasspath */
+ /* Append to bootclasspath. */
- len = strlen(_Jv_bootclasspath);
+ boot_class_path = properties_get("sun.boot.class.path");
- _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
- char,
- len + strlen("0"),
- len + strlen(":") +
- strlen(opt_arg) + strlen("0"));
+ len = strlen(boot_class_path);
- strcat(_Jv_bootclasspath, ":");
- strcat(_Jv_bootclasspath, opt_arg);
+ p = MREALLOC(boot_class_path,
+ char,
+ len + strlen("0"),
+ len + strlen(":") +
+ strlen(opt_arg) + strlen("0"));
-#if defined(ENABLE_JAVASE)
- properties_add("java.boot.class.path", _Jv_bootclasspath);
- properties_add("sun.boot.class.path", _Jv_bootclasspath);
-#endif
+ strcat(p, ":");
+ strcat(p, opt_arg);
+
+ properties_add("sun.boot.class.path", p);
+ properties_add("java.boot.class.path", p);
break;
case OPT_BOOTCLASSPATH_P:
- /* prepend in front of bootclasspath */
+ /* Prepend to bootclasspath. */
- cp = _Jv_bootclasspath;
- len = strlen(cp);
+ boot_class_path = properties_get("sun.boot.class.path");
- _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
- len + strlen("0"));
+ len = strlen(boot_class_path);
- strcpy(_Jv_bootclasspath, opt_arg);
- strcat(_Jv_bootclasspath, ":");
- strcat(_Jv_bootclasspath, cp);
+ p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
- MFREE(cp, char, len);
+ strcpy(p, opt_arg);
+ strcat(p, ":");
+ strcat(p, boot_class_path);
-#if defined(ENABLE_JAVASE)
- properties_add("java.boot.class.path", _Jv_bootclasspath);
- properties_add("sun.boot.class.path", _Jv_bootclasspath);
-#endif
+ properties_add("sun.boot.class.path", p);
+ properties_add("java.boot.class.path", p);
+
+ MFREE(boot_class_path, char, len);
break;
case OPT_BOOTCLASSPATH_C:
- /* use as Java core library, but prepend VM interface classes */
+ /* Use as Java core library, but prepend VM interface
+ classes. */
- MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
+ boot_class_path = properties_get("sun.boot.class.path");
- len = strlen(CACAO_VM_ZIP) +
+ len =
+ strlen(CACAO_VM_ZIP) +
strlen(":") +
strlen(opt_arg) +
strlen("0");
- _Jv_bootclasspath = MNEW(char, len);
+ p = MNEW(char, len);
- strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
- strcat(_Jv_bootclasspath, ":");
- strcat(_Jv_bootclasspath, opt_arg);
+ strcpy(p, CACAO_VM_ZIP);
+ strcat(p, ":");
+ strcat(p, opt_arg);
-#if defined(ENABLE_JAVASE)
- properties_add("java.boot.class.path", _Jv_bootclasspath);
- properties_add("sun.boot.class.path", _Jv_bootclasspath);
-#endif
+ properties_add("sun.boot.class.path", p);
+ properties_add("java.boot.class.path", p);
+
+ MFREE(boot_class_path, char, strlen(boot_class_path));
break;
#if defined(ENABLE_JVMTI)
if (opt_jar == true) {
/* free old classpath */
- MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
+/* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
/* put jarfile into classpath */
- _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
+ p = MNEW(char, strlen(mainstring) + strlen("0"));
- strcpy(_Jv_classpath, mainstring);
+ strcpy(p, mainstring);
#if defined(ENABLE_JAVASE)
- properties_add("java.class.path", _Jv_classpath);
+ properties_add("java.class.path", p);
#endif
}
else {
/* AFTER: utf8_init */
- suck_add(_Jv_bootclasspath);
+ boot_class_path = properties_get("sun.boot.class.path");
+ suck_add(boot_class_path);
/* initialize the classcache hashtable stuff: lock, hashtable
(must be done _after_ threads_preinit) */
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
{
- utf *mainutf;
- classinfo *mainclass;
- java_handle_t *e;
- methodinfo *m;
- java_objectarray *oa;
- s4 oalength;
- utf *u;
- java_handle_t *s;
- s4 status;
- s4 i;
+ utf *mainutf;
+ classinfo *mainclass;
+ java_handle_t *e;
+ methodinfo *m;
+ java_handle_objectarray_t *oa;
+ s4 oalength;
+ utf *u;
+ java_handle_t *s;
+ s4 status;
+ s4 i;
#if !defined(NDEBUG)
if (compileall) {
u = utf_new_char(vm_args->options[opt_index + i].optionString);
s = javastring_new(u);
- oa->data[i] = s;
+ LLNI_objectarray_element_set(oa, i, s);
}
#ifdef TYPEINFO_DEBUG_TEST
#else
index = INT_ARG_CNT + pd->index;
#endif
-#if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__)
+#if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
array[index] = value >> 32;
#else
array[index] = value;
*******************************************************************************/
uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
- java_objectarray *params)
+ java_handle_objectarray_t *params)
{
methoddesc *md;
paramdesc *pd;
typedesc *td;
uint64_t *array;
- java_object_t *param;
+ java_handle_t *param;
classinfo *c;
+ int type;
int32_t i;
int32_t j;
imm_union value;
}
for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
- param = params->data[j];
+ LLNI_objectarray_element_get(params, j, param);
switch (td->type) {
case TYPE_INT:
/* convert the value according to its declared type */
- c = param->vftbl->class;
+ c = param->vftbl->class;
+ type = primitive_type_get_by_wrapperclass(c);
switch (td->decltype) {
case PRIMITIVETYPE_BOOLEAN:
- if (c == class_java_lang_Boolean)
- LLNI_field_get_val((java_lang_Boolean *) param, value, value.i);
- else
+ switch (type) {
+ case PRIMITIVETYPE_BOOLEAN:
+ /* This type is OK. */
+ break;
+ default:
goto illegal_arg;
+ }
break;
case PRIMITIVETYPE_BYTE:
- if (c == class_java_lang_Byte)
- LLNI_field_get_val((java_lang_Byte *) param, value, value.i);
- else
+ switch (type) {
+ case PRIMITIVETYPE_BYTE:
+ /* This type is OK. */
+ break;
+ default:
goto illegal_arg;
+ }
break;
case PRIMITIVETYPE_CHAR:
- if (c == class_java_lang_Character)
- LLNI_field_get_val((java_lang_Character *) param, value, value.i);
- else
+ switch (type) {
+ case PRIMITIVETYPE_CHAR:
+ /* This type is OK. */
+ break;
+ default:
goto illegal_arg;
+ }
break;
case PRIMITIVETYPE_SHORT:
- if (c == class_java_lang_Short)
- LLNI_field_get_val((java_lang_Short *) param, value, value.i);
- else if (c == class_java_lang_Byte)
- LLNI_field_get_val((java_lang_Byte *) param, value, value.i);
- else
+ switch (type) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_SHORT:
+ /* These types are OK. */
+ break;
+ default:
goto illegal_arg;
+ }
break;
case PRIMITIVETYPE_INT:
- if (c == class_java_lang_Integer)
- LLNI_field_get_val((java_lang_Integer *) param, value, value.i);
- else if (c == class_java_lang_Short)
- LLNI_field_get_val((java_lang_Short *) param, value, value.i);
- else if (c == class_java_lang_Byte)
- LLNI_field_get_val((java_lang_Byte *) param, value, value.i);
- else
+ switch (type) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ /* These types are OK. */
+ break;
+ default:
goto illegal_arg;
+ }
break;
default:
- goto illegal_arg;
+ vm_abort("vm_array_from_objectarray: invalid type %d",
+ td->decltype);
}
+ value = primitive_unbox(param);
vm_array_store_int(array, pd, value.i);
break;
if (param == NULL)
goto illegal_arg;
- /* convert the value according to its declared type */
+ c = param->vftbl->class;
+ type = primitive_type_get_by_wrapperclass(c);
- c = param->vftbl->class;
+ assert(td->decltype == PRIMITIVETYPE_LONG);
- switch (td->decltype) {
+ switch (type) {
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
case PRIMITIVETYPE_LONG:
- if (c == class_java_lang_Long)
- LLNI_field_get_val((java_lang_Long *) param, value, value.l);
- else if (c == class_java_lang_Integer)
- value.l = (int64_t) LLNI_field_direct(((java_lang_Integer *) param), value);
- else if (c == class_java_lang_Short)
- value.l = (int64_t) LLNI_field_direct(((java_lang_Short *) param), value);
- else if (c == class_java_lang_Byte)
- value.l = (int64_t) LLNI_field_direct(((java_lang_Byte *) param), value);
- else
- goto illegal_arg;
+ /* These types are OK. */
break;
-
default:
goto illegal_arg;
}
+ value = primitive_unbox(param);
vm_array_store_lng(array, pd, value.l);
break;
if (param == NULL)
goto illegal_arg;
- /* convert the value according to its declared type */
+ c = param->vftbl->class;
+ type = primitive_type_get_by_wrapperclass(c);
- c = param->vftbl->class;
+ assert(td->decltype == PRIMITIVETYPE_FLOAT);
- switch (td->decltype) {
+ switch (type) {
case PRIMITIVETYPE_FLOAT:
- if (c == class_java_lang_Float)
- LLNI_field_get_val((java_lang_Float *) param, value, value.f);
- else
- goto illegal_arg;
+ /* This type is OK. */
break;
-
default:
goto illegal_arg;
}
+ value = primitive_unbox(param);
vm_array_store_flt(array, pd, value.l);
break;
if (param == NULL)
goto illegal_arg;
- /* convert the value according to its declared type */
+ c = param->vftbl->class;
+ type = primitive_type_get_by_wrapperclass(c);
- c = param->vftbl->class;
+ assert(td->decltype == PRIMITIVETYPE_DOUBLE);
- switch (td->decltype) {
+ switch (type) {
+ case PRIMITIVETYPE_FLOAT:
case PRIMITIVETYPE_DOUBLE:
- if (c == class_java_lang_Double)
- LLNI_field_get_val((java_lang_Double *) param, value, value.d);
- else if (c == class_java_lang_Float)
- LLNI_field_get_val((java_lang_Float *) param, value, value.f);
- else
- goto illegal_arg;
+ /* These types are OK. */
break;
-
default:
goto illegal_arg;
}
+ value = primitive_unbox(param);
vm_array_store_dbl(array, pd, value.l);
break;
break;
default:
- goto illegal_arg;
+ vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
}
}