#include "config.h"
-#include <assert.h>
-
#if defined(ENABLE_JRE_LAYOUT)
# include <errno.h>
# include <libgen.h>
# include <unistd.h>
#endif
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#if defined(ENABLE_JVMTI)
-# include "native/jvmti/jvmti.h"
-# include "native/jvmti/cacaodbg.h"
-#endif
-
-#include "vmcore/system.h"
+#include "native/jni.hpp"
+#include "native/native.hpp"
+#include "vm/os.hpp"
#include "vm/vm.hpp"
int main(int argc, char **argv)
{
#if defined(ENABLE_LIBJVM)
- const char* path;
+ char* path;
# if defined(ENABLE_JRE_LAYOUT)
int len;
void* libjvm_vm_run;
const char* lterror;
- bool (*VM_create)(JavaVM **, void **, void *);
- void (*vm_run)(JavaVM *, JavaVMInitArgs *);
+ bool (*VM_create)(JavaVM**, void**, void*);
+ void (*vm_run)(JavaVM*, JavaVMInitArgs*);
#endif
- JavaVM *vm; /* denotes a Java VM */
- JNIEnv *env;
- JavaVMInitArgs *vm_args;
-
- /* prepare the options */
-
- vm_args = prepare_options(argc, argv);
+ // Prepare the options.
+ JavaVMInitArgs* vm_args = prepare_options(argc, argv);
/* load and initialize a Java VM, return a JNI interface pointer in env */
# if defined(ENABLE_JRE_LAYOUT)
/* SUN also uses a buffer of 4096-bytes (strace is your friend). */
- path = malloc(sizeof(char) * 4096);
+ path = (char*) os::malloc(sizeof(char) * 4096);
if (readlink("/proc/self/exe", path, 4095) == -1) {
- fprintf(stderr, "main: readlink failed: %s\n", system_strerror(errno));
- system_abort();
+ fprintf(stderr, "main: readlink failed: %s\n", strerror(errno));
+ os::abort();
}
/* get the path of the current executable */
- path = dirname(path);
- len = system_strlen(path) + system_strlen("/../lib/"LIBJVM_NAME) + system_strlen("0");
+ path = os::dirname(path);
+ len = os::strlen(path) + os::strlen("/../lib/"LIBJVM_NAME) + os::strlen("0");
if (len > 4096) {
fprintf(stderr, "main: libjvm name to long for buffer\n");
- system_abort();
+ os::abort();
}
- /* concatinate the library name */
+ /* concatenate the library name */
strcat(path, "/../lib/"LIBJVM_NAME);
# else
- path = CACAO_LIBDIR"/"LIBJVM_NAME;
+ path = (char*) CACAO_LIBDIR"/"LIBJVM_NAME;
# endif
/* First try to open where dlopen searches, e.g. LD_LIBRARY_PATH.
If not found, try the absolute path. */
- libjvm_handle = system_dlopen(LIBJVM_NAME, RTLD_NOW);
+ libjvm_handle = os::dlopen(LIBJVM_NAME, RTLD_NOW);
if (libjvm_handle == NULL) {
/* save the error message */
- lterror = strdup(system_dlerror());
+ lterror = strdup(os::dlerror());
- libjvm_handle = system_dlopen(path, RTLD_NOW);
+ libjvm_handle = os::dlopen(path, RTLD_NOW);
if (libjvm_handle == NULL) {
/* print the first error message too */
- fprintf(stderr, "main: system_dlopen failed: %s\n", lterror);
+ fprintf(stderr, "main: os::dlopen failed: %s\n", lterror);
/* and now the current one */
- fprintf(stderr, "main: system_dlopen failed: %s\n",
- system_dlerror());
- system_abort();
+ fprintf(stderr, "main: os::dlopen failed: %s\n", os::dlerror());
+ os::abort();
}
- /* free the error string */
-
- free((void *) lterror);
+ // Free the error string.
+ os::free((void*) lterror);
}
- libjvm_VM_create = system_dlsym(libjvm_handle, "VM_create");
+ libjvm_VM_create = os::dlsym(libjvm_handle, "VM_create");
if (libjvm_VM_create == NULL) {
- fprintf(stderr, "main: lt_dlsym failed: %s\n", system_dlerror());
- system_abort();
+ fprintf(stderr, "main: lt_dlsym failed: %s\n", os::dlerror());
+ os::abort();
}
- VM_create =
- (bool (*)(JavaVM **, void **, void *)) (ptrint) libjvm_VM_create;
+ VM_create = (bool (*)(JavaVM**, void**, void*)) (uintptr_t) libjvm_VM_create;
#endif
- /* create the Java VM */
-
- (void) VM_create(&vm, (void**) &env, vm_args);
+ // Create the Java VM.
+ JavaVM* vm;
+ void* env; // We use a void* instead of a JNIEnv* here to prevent a compiler warning.
-#if defined(ENABLE_JVMTI)
-# error This should be a JVMTI function.
- Mutex_init(&dbgcomlock);
- if (jvmti) jvmti_set_phase(JVMTI_PHASE_START);
-#endif
+ (void) VM_create(&vm, &env, vm_args);
#if defined(ENABLE_LIBJVM)
- libjvm_vm_run = system_dlsym(libjvm_handle, "vm_run");
+ libjvm_vm_run = os::dlsym(libjvm_handle, "vm_run");
if (libjvm_vm_run == NULL) {
- fprintf(stderr, "main: system_dlsym failed: %s\n", system_dlerror());
- system_abort();
+ fprintf(stderr, "main: os::dlsym failed: %s\n", os::dlerror());
+ os::abort();
}
- vm_run = (void (*)(JavaVM *, JavaVMInitArgs *)) (ptrint) libjvm_vm_run;
+ vm_run = (void (*)(JavaVM*, JavaVMInitArgs*)) (uintptr_t) libjvm_vm_run;
#endif
- /* run the VM */
-
+ // Run the VM.
vm_run(vm, vm_args);
- /* keep compiler happy */
-
+ // Keep compiler happy.
return 0;
}