Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_VMRuntime.c 7246 2007-01-29 18:49:05Z twisti $
-
*/
#include <assert.h>
#include <string.h>
+#include <stdint.h>
#include <stdlib.h>
+#include <unistd.h>
#include <sys/utsname.h>
-#if !defined(WITH_STATIC_CLASSPATH)
-# include <ltdl.h>
-#endif
-
#if defined(__DARWIN__)
# define OS_INLINE /* required for <libkern/ppc/OSByteOrder.h> */
# include <mach/mach.h>
#endif
-#include "vm/types.h"
-
#include "mm/gc-common.h"
#include "mm/memory.h"
#include "native/jni.h"
#include "native/native.h"
+
#include "native/include/java_io_File.h"
#include "native/include/java_lang_ClassLoader.h"
#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Process.h"
-#include "toolbox/logging.h"
+#include "native/include/java_lang_VMRuntime.h"
+
+#include "native/vm/java_lang_Runtime.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/stringlocal.h"
#include "vm/vm.h"
-#include "vmcore/options.h"
+#include "vmcore/utf8.h"
/* this should work on BSD */
*/
-/* should we run all finalizers on exit? */
-static bool finalizeOnExit = false;
+/* native methods implemented by this file ************************************/
+
+static JNINativeMethod methods[] = {
+ { "exit", "(I)V", (void *) (intptr_t) &Java_java_lang_VMRuntime_exit },
+ { "freeMemory", "()J", (void *) (intptr_t) &Java_java_lang_VMRuntime_freeMemory },
+ { "totalMemory", "()J", (void *) (intptr_t) &Java_java_lang_VMRuntime_totalMemory },
+ { "maxMemory", "()J", (void *) (intptr_t) &Java_java_lang_VMRuntime_maxMemory },
+ { "gc", "()V", (void *) (intptr_t) &Java_java_lang_VMRuntime_gc },
+ { "runFinalization", "()V", (void *) (intptr_t) &Java_java_lang_VMRuntime_runFinalization },
+ { "runFinalizersOnExit", "(Z)V", (void *) (intptr_t) &Java_java_lang_VMRuntime_runFinalizersOnExit },
+ { "runFinalizationForExit", "()V", (void *) (intptr_t) &Java_java_lang_VMRuntime_runFinalizationForExit },
+ { "traceInstructions", "(Z)V", (void *) (intptr_t) &Java_java_lang_VMRuntime_traceInstructions },
+ { "traceMethodCalls", "(Z)V", (void *) (intptr_t) &Java_java_lang_VMRuntime_traceMethodCalls },
+ { "availableProcessors", "()I", (void *) (intptr_t) &Java_java_lang_VMRuntime_availableProcessors },
+ { "nativeLoad", "(Ljava/lang/String;Ljava/lang/ClassLoader;)I", (void *) (intptr_t) &Java_java_lang_VMRuntime_nativeLoad },
+ { "mapLibraryName", "(Ljava/lang/String;)Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_VMRuntime_mapLibraryName },
+};
+
+
+/* _Jv_java_lang_VMRuntime_init ************************************************
+
+ Register native functions.
+
+*******************************************************************************/
+
+void _Jv_java_lang_VMRuntime_init(void)
+{
+ utf *u;
+
+ u = utf_new_char("java/lang/VMRuntime");
+
+ native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
/*
* Class: java/lang/VMRuntime
- * Method: exitInternal
+ * Method: exit
* Signature: (I)V
*/
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, s4 par1)
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, int32_t status)
{
- if (finalizeOnExit)
- gc_finalize_all();
-
- vm_shutdown(par1);
+ _Jv_java_lang_Runtime_exit(status);
}
* Method: freeMemory
* Signature: ()J
*/
-JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz)
+JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz)
{
- return gc_get_free_bytes();
+ return _Jv_java_lang_Runtime_freeMemory();
}
* Method: totalMemory
* Signature: ()J
*/
-JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz)
+JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz)
{
- return gc_get_heap_size();
+ return _Jv_java_lang_Runtime_totalMemory();
}
* Method: maxMemory
* Signature: ()J
*/
-JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass clazz)
+JNIEXPORT int64_t JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass clazz)
{
return gc_get_max_heap_size();
}
*/
JNIEXPORT void JNICALL Java_java_lang_VMRuntime_gc(JNIEnv *env, jclass clazz)
{
- gc_call();
+ _Jv_java_lang_Runtime_gc();
}
* Method: runFinalizersOnExit
* Signature: (Z)V
*/
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, s4 value)
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, int32_t value)
{
- /* XXX threading */
-
- finalizeOnExit = value;
+ _Jv_java_lang_Runtime_runFinalizersOnExit(value);
}
* Method: traceInstructions
* Signature: (Z)V
*/
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, jclass clazz, s4 par1)
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceInstructions(JNIEnv *env, jclass clazz, int32_t par1)
{
/* not supported */
}
* Method: traceMethodCalls
* Signature: (Z)V
*/
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jclass clazz, s4 par1)
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jclass clazz, int32_t par1)
{
/* not supported */
}
* Method: availableProcessors
* Signature: ()I
*/
-JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz)
+JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz)
{
#if defined(_SC_NPROC_ONLN)
- return (s4) sysconf(_SC_NPROC_ONLN);
+ return (int32_t) sysconf(_SC_NPROC_ONLN);
#elif defined(_SC_NPROCESSORS_ONLN)
- return (s4) sysconf(_SC_NPROCESSORS_ONLN);
+ return (int32_t) sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(__DARWIN__)
/* this should work in BSD */
len = sizeof(ncpu);
rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
- return (s4) ncpu;
+ return (int32_t) ncpu;
*/
host_basic_info_data_t hinfo;
return -1;
}
- return (s4) hinfo.avail_cpus;
+ return (int32_t) hinfo.avail_cpus;
#else
return 1;
* Method: nativeLoad
* Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)I
*/
-JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, java_lang_String *filename, java_lang_ClassLoader *loader)
+JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, java_lang_String *libname, java_lang_ClassLoader *loader)
{
-#if !defined(WITH_STATIC_CLASSPATH)
- utf *name;
- lt_dlhandle handle;
- lt_ptr onload;
- s4 version;
-#endif
+ classloader *cl;
- if (filename == NULL) {
- exceptions_throw_nullpointerexception();
- return 0;
- }
+ cl = (classloader *) loader;
-#if defined(WITH_STATIC_CLASSPATH)
- return 1;
-#else /* defined(WITH_STATIC_CLASSPATH) */
- name = javastring_toutf(filename, 0);
-
- /* is the library already loaded? */
-
- if (native_hashtable_library_find(name, (java_objectheader *) loader))
- return 1;
-
- /* try to open the library */
-
- if (!(handle = lt_dlopen(name->text))) {
- if (opt_verbose) {
- log_start();
- log_print("Java_java_lang_VMRuntime_nativeLoad: ");
- log_print(lt_dlerror());
- log_finish();
- }
-
- return 0;
- }
-
- /* resolve JNI_OnLoad function */
-
- if ((onload = lt_dlsym(handle, "JNI_OnLoad"))) {
- JNIEXPORT s4 (JNICALL *JNI_OnLoad) (JavaVM *, void *);
- JavaVM *vm;
-
- JNI_OnLoad = (JNIEXPORT s4 (JNICALL *)(JavaVM *, void *)) (ptrint) onload;
-
- (*env)->GetJavaVM(env, &vm);
-
- version = JNI_OnLoad(vm, NULL);
-
- /* if the version is not 1.2 and not 1.4 the library cannot be loaded */
-
- if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
- lt_dlclose(handle);
-
- return 0;
- }
- }
-
- /* insert the library name into the library hash */
-
- native_hashtable_library_add(name, (java_objectheader *) loader, handle);
-
- return 1;
-#endif /* defined(WITH_STATIC_CLASSPATH) */
+#if defined(ENABLE_JNI)
+ return _Jv_java_lang_Runtime_loadLibrary(env, libname, cl);
+#else
+ return _Jv_java_lang_Runtime_loadLibrary(libname, cl);
+#endif
}
*/
JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, jclass clazz, java_lang_String *libname)
{
- utf *u;
- char *buffer;
- s4 buffer_len;
- s4 dumpsize;
- java_lang_String *s;
+ utf *u;
+ char *buffer;
+ int32_t buffer_len;
+ int32_t dumpsize;
+ java_handle_t *o;
- if (!libname) {
+ if (libname == NULL) {
exceptions_throw_nullpointerexception();
return NULL;
}
- u = javastring_toutf(libname, 0);
+ u = javastring_toutf((java_handle_t *) libname, false);
/* calculate length of library name */
strcat(buffer, ".so");
#endif
- s = javastring_new_from_utf_string(buffer);
+ o = javastring_new_from_utf_string(buffer);
/* release memory */
dump_release(dumpsize);
- return s;
+ return (java_lang_String *) o;
}