1 /* src/native/vm/java_lang_VMRuntime.c
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: java_lang_VMRuntime.c 7246 2007-01-29 18:49:05Z twisti $
32 #if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
38 #include "mm/gc-common.h"
40 #include "native/jni.h"
41 #include "native/native.h"
43 #include "native/include/java_lang_String.h"
45 #include "toolbox/logging.h"
47 #include "vm/exceptions.h"
48 #include "vm/stringlocal.h"
51 #include "vmcore/options.h"
54 /* should we run all finalizers on exit? */
55 static bool finalizeOnExit = false;
59 * Class: java/lang/Runtime
60 * Method: exitInternal
63 void _Jv_java_lang_Runtime_exit(s4 status)
73 * Class: java/lang/Runtime
77 s8 _Jv_java_lang_Runtime_freeMemory(void)
79 return gc_get_free_bytes();
84 * Class: java/lang/Runtime
88 s8 _Jv_java_lang_Runtime_totalMemory(void)
90 return gc_get_heap_size();
95 * Class: java/lang/Runtime
99 void _Jv_java_lang_Runtime_gc(void)
106 * Class: java/lang/Runtime
107 * Method: loadLibrary
108 * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)I
110 #if defined(ENABLE_JNI)
111 s4 _Jv_java_lang_Runtime_loadLibrary(JNIEnv *env, java_lang_String *libname, classloader *cl)
113 s4 _Jv_java_lang_Runtime_loadLibrary(java_lang_String *libname, classloader *cl)
116 #if defined(ENABLE_LTDL)
119 # if defined(ENABLE_JNI)
124 if (libname == NULL) {
125 exceptions_throw_nullpointerexception();
129 name = javastring_toutf((java_handle_t *) libname, false);
131 /* is the library already loaded? */
133 if (native_library_find(name, cl) != NULL)
136 /* open the library */
138 handle = native_library_open(name);
143 # if defined(ENABLE_JNI)
144 /* resolve JNI_OnLoad function */
146 onload = lt_dlsym(handle, "JNI_OnLoad");
148 if (onload != NULL) {
149 JNIEXPORT s4 (JNICALL *JNI_OnLoad) (JavaVM *, void *);
152 JNI_OnLoad = (JNIEXPORT s4 (JNICALL *)(JavaVM *, void *)) (ptrint) onload;
154 (*env)->GetJavaVM(env, &vm);
156 version = JNI_OnLoad(vm, NULL);
158 /* if the version is not 1.2 and not 1.4 the library cannot be loaded */
160 if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
168 /* insert the library name into the library hash */
170 native_library_add(name, cl, handle);
174 vm_abort("_Jv_java_lang_Runtime_loadLibrary: not available");
176 /* keep compiler happy */
183 #if defined(ENABLE_JAVASE)
186 * Class: java/lang/Runtime
187 * Method: runFinalizersOnExit
190 void _Jv_java_lang_Runtime_runFinalizersOnExit(s4 value)
194 finalizeOnExit = value;
201 * These are local overrides for various environment variables in Emacs.
202 * Please do not remove this and leave it at the end of the file, where
203 * Emacs will automagically detect them.
204 * ---------------------------------------------------------------------
207 * indent-tabs-mode: t
211 * vim:noexpandtab:sw=4:ts=4: