1 /* nat/Runtime.c - java/lang/Runtime
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
32 $Id: VMRuntime.c 1042 2004-04-26 17:12:47Z twisti $
40 #include <sys/utsname.h>
48 #include "toolbox/loging.h"
49 #include "toolbox/memory.h"
50 #include "java_io_File.h"
51 #include "java_lang_String.h"
52 #include "java_lang_Process.h"
53 #include "java_util_Properties.h" /* needed for java_lang_Runtime.h */
54 #include "java_lang_Runtime.h"
61 static int activeprops = 19;
63 static char *proplist[MAXPROPS][2] = {
64 { "java.class.path", NULL },
65 { "java.home", NULL },
66 { "user.home", NULL },
67 { "user.name", NULL },
72 { "os.version", NULL },
74 { "java.class.version", "45.3" },
75 { "java.version", PACKAGE":"VERSION },
76 { "java.vendor", "CACAO Team" },
77 { "java.vendor.url", "http://www.complang.tuwien.ac.at/java/cacao/" },
78 { "java.vm.name", "CACAO"},
79 { "java.tmpdir", "/tmp/"},
80 { "java.io.tmpdir", "/tmp/"},
82 { "path.separator", ":" },
83 { "file.separator", "/" },
84 { "line.separator", "\n" },
85 { "java.protocol.handler.pkgs", "gnu.java.net.protocol"}
88 void attach_property(char *name, char *value)
90 if (activeprops >= MAXPROPS) panic("Too many properties defined");
91 proplist[activeprops][0] = name;
92 proplist[activeprops][1] = value;
96 * Class: java_lang_Runtime
97 * Method: execInternal
98 * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
100 JNIEXPORT java_lang_Process* JNICALL Java_java_lang_Runtime_execInternal(JNIEnv *env, java_lang_Runtime *this, java_objectarray *cmd, java_objectarray *shellenv, java_io_File *workingdir)
102 log_text("Java_java_lang_Runtime_execInternal called");
109 * Class: java/lang/Runtime
110 * Method: exitInternal
113 JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal(JNIEnv *env, java_lang_Runtime *this, s4 par1)
115 cacao_shutdown(par1);
120 * Class: java/lang/Runtime
124 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_freeMemory(JNIEnv *env, java_lang_Runtime *this)
126 return gc_get_free_bytes();
131 * Class: java/lang/Runtime
135 JNIEXPORT void JNICALL Java_java_lang_Runtime_gc(JNIEnv *env, java_lang_Runtime *this)
142 * Class: java/lang/Runtime
143 * Method: runFinalization
146 JNIEXPORT void JNICALL Java_java_lang_Runtime_runFinalization(JNIEnv *env, java_lang_Runtime *this)
153 * Class: java/lang/Runtime
154 * Method: runFinalizersOnExit
157 JNIEXPORT void JNICALL Java_java_lang_Runtime_runFinalizersOnExitInternal(JNIEnv *env, jclass clazz, s4 par1)
159 log_text("Java_java_lang_Runtime_runFinalizersOnExit0 called");
164 * Class: java/lang/Runtime
165 * Method: totalMemory
168 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_totalMemory(JNIEnv *env, java_lang_Runtime *this)
170 return gc_get_heap_size();
175 * Class: java/lang/Runtime
176 * Method: traceInstructions
179 JNIEXPORT void JNICALL Java_java_lang_Runtime_traceInstructions(JNIEnv *env, java_lang_Runtime *this, s4 par1)
186 * Class: java/lang/Runtime
187 * Method: traceMethodCalls
190 JNIEXPORT void JNICALL Java_java_lang_Runtime_traceMethodCalls(JNIEnv *env, java_lang_Runtime *this, s4 par1)
197 * Class: java_lang_Runtime
198 * Method: availableProcessors
201 JNIEXPORT s4 JNICALL Java_java_lang_Runtime_availableProcessors(JNIEnv *env, java_lang_Runtime *this)
203 #if defined(_SC_NPROC_ONLN)
204 return (s4) sysconf(_SC_NPROC_ONLN);
206 #elif defined(_SC_NPROCESSORS_ONLN)
207 return (s4) sysconf(_SC_NPROCESSORS_ONLN);
216 * Class: java_lang_Runtime
218 * Signature: (Ljava/lang/String;)I
220 JNIEXPORT s4 JNICALL Java_java_lang_Runtime_nativeLoad(JNIEnv *env, java_lang_Runtime *this, java_lang_String *par1)
227 data = javastring_toutf(par1, 0);
230 log_text("nativeLoad: Error: empty string");
234 buffer_len = utf_strlen(data) + 40;
237 buffer = MNEW(char, buffer_len);
239 strcpy(buffer, "Java_java_lang_Runtime_nativeLoad:");
240 utf_sprint(buffer + strlen((char *) data), data);
243 MFREE(buffer, char, buffer_len);
245 log_text("Java_java_lang_Runtime_nativeLoad");
252 * Class: java_lang_Runtime
253 * Method: nativeGetLibname
254 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
256 JNIEXPORT java_lang_String* JNICALL Java_java_lang_Runtime_nativeGetLibname(JNIEnv *env, jclass clazz, java_lang_String *par1, java_lang_String *par2)
263 data = javastring_toutf(par2, 0);
266 log_text("nativeGetLibName: Error: empty string");
270 buffer_len = utf_strlen(data) + 40;
272 buffer = MNEW(char, buffer_len);
274 strcpy(buffer, "Java_java_lang_Runtime_nativeGetLibname:");
275 utf_sprint(buffer + strlen((char *) data), data);
278 MFREE(buffer, char, buffer_len);
280 log_text("Java_java_lang_Runtime_nativeGetLibname");
287 * Class: java_lang_Runtime
288 * Method: insertSystemProperties
289 * Signature: (Ljava/util/Properties;)V
291 JNIEXPORT void JNICALL Java_java_lang_Runtime_insertSystemProperties(JNIEnv *env, jclass clazz, java_util_Properties *p)
294 #define BUFFERSIZE 200
297 char buffer[BUFFERSIZE];
298 struct utsname utsnamebuf;
300 proplist[0][1] = classpath;
301 proplist[1][1] = getenv("JAVA_HOME");
302 proplist[2][1] = getenv("HOME");
303 proplist[3][1] = getenv("USER");
304 proplist[4][1] = getcwd(buffer, BUFFERSIZE);
306 /* get properties from system */
308 proplist[5][1] = utsnamebuf.machine;
309 proplist[6][1] = utsnamebuf.sysname;
310 proplist[7][1] = utsnamebuf.release;
313 *exceptionptr = new_exception(string_java_lang_NullPointerException);
317 /* search for method to add properties */
318 m = class_resolvemethod(p->header.vftbl->class,
320 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")
324 *exceptionptr = new_exception_message(string_java_lang_NoSuchMethodError,
325 "java.lang.Properties.put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;)");
329 /* add the properties */
330 for (i = 0; i < activeprops; i++) {
332 if (proplist[i][1] == NULL) proplist[i][1] = "";
334 asm_calljavafunction(m,
336 javastring_new_char(proplist[i][0]),
337 javastring_new_char(proplist[i][1]),
347 * Class: java_lang_Runtime
351 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_maxMemory(JNIEnv *env, java_lang_Runtime *this)
353 return gc_get_max_heap_size();
358 * These are local overrides for various environment variables in Emacs.
359 * Please do not remove this and leave it at the end of the file, where
360 * Emacs will automagically detect them.
361 * ---------------------------------------------------------------------
364 * indent-tabs-mode: t