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
31 $Id: VMRuntime.c 873 2004-01-11 20:59:29Z twisti $
39 #include <sys/utsname.h>
47 #include "toolbox/loging.h"
48 #include "toolbox/memory.h"
49 #include "java_io_File.h"
50 #include "java_lang_String.h"
51 #include "java_lang_Process.h"
52 #include "java_util_Properties.h" /* needed for java_lang_Runtime.h */
53 #include "java_lang_Runtime.h"
60 static int activeprops = 19;
62 static char *proplist[MAXPROPS][2] = {
63 { "java.class.path", NULL },
64 { "java.home", NULL },
65 { "user.home", NULL },
66 { "user.name", NULL },
71 { "os.version", NULL },
73 { "java.class.version", "45.3" },
74 { "java.version", PACKAGE":"VERSION },
75 { "java.vendor", "CACAO Team" },
76 { "java.vendor.url", "http://www.complang.tuwien.ac.at/java/cacao/" },
77 { "java.vm.name", "CACAO"},
78 { "java.tmpdir", "/tmp/"},
79 { "java.io.tmpdir", "/tmp/"},
81 { "path.separator", ":" },
82 { "file.separator", "/" },
83 { "line.separator", "\n" },
84 { "java.protocol.handler.pkgs", "gnu.java.net.protocol"}
89 * Class: java_lang_Runtime
90 * Method: execInternal
91 * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
93 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)
95 log_text("Java_java_lang_Runtime_execInternal called");
102 * Class: java/lang/Runtime
103 * Method: exitInternal
106 JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal(JNIEnv *env, java_lang_Runtime *this, s4 par1)
108 cacao_shutdown(par1);
113 * Class: java/lang/Runtime
117 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_freeMemory(JNIEnv *env, java_lang_Runtime *this)
119 log_text ("java_lang_Runtime_freeMemory called");
121 return builtin_i2l(0);
126 * Class: java/lang/Runtime
130 JNIEXPORT void JNICALL Java_java_lang_Runtime_gc(JNIEnv *env, java_lang_Runtime *this)
137 * Class: java/lang/Runtime
138 * Method: runFinalization
141 JNIEXPORT void JNICALL Java_java_lang_Runtime_runFinalization(JNIEnv *env, java_lang_Runtime *this)
148 * Class: java/lang/Runtime
149 * Method: runFinalizersOnExit
152 JNIEXPORT void JNICALL Java_java_lang_Runtime_runFinalizersOnExitInternal(JNIEnv *env, jclass clazz, s4 par1)
154 log_text("Java_java_lang_Runtime_runFinalizersOnExit0 called");
159 * Class: java/lang/Runtime
160 * Method: totalMemory
163 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_totalMemory(JNIEnv *env, java_lang_Runtime *this)
165 log_text ("java_lang_Runtime_totalMemory called");
167 return builtin_i2l(0);
172 * Class: java/lang/Runtime
173 * Method: traceInstructions
176 JNIEXPORT void JNICALL Java_java_lang_Runtime_traceInstructions(JNIEnv *env, java_lang_Runtime *this, s4 par1)
178 log_text("Java_java_lang_Runtime_traceInstructions called");
183 * Class: java/lang/Runtime
184 * Method: traceMethodCalls
187 JNIEXPORT void JNICALL Java_java_lang_Runtime_traceMethodCalls(JNIEnv *env, java_lang_Runtime *this, s4 par1)
189 log_text("Java_java_lang_Runtime_traceMethodCalls called");
194 * Class: java_lang_Runtime
195 * Method: availableProcessors
198 JNIEXPORT s4 JNICALL Java_java_lang_Runtime_availableProcessors(JNIEnv *env, java_lang_Runtime *this)
200 log_text("Java_java_lang_Runtime_availableProcessors called, returning hardcoded 1");
207 * Class: java_lang_Runtime
209 * Signature: (Ljava/lang/String;)I
211 JNIEXPORT s4 JNICALL Java_java_lang_Runtime_nativeLoad(JNIEnv *env, java_lang_Runtime *this, java_lang_String *par1)
218 data = javastring_toutf(par1, 0);
221 log_text("nativeLoad: Error: empty string");
225 buffer_len = utf_strlen(data) + 40;
228 buffer = MNEW(char, buffer_len);
230 strcpy(buffer, "Java_java_lang_Runtime_nativeLoad:");
231 utf_sprint(buffer + strlen((char *) data), data);
234 MFREE(buffer, char, buffer_len);
236 log_text("Java_java_lang_Runtime_nativeLoad");
243 * Class: java_lang_Runtime
244 * Method: nativeGetLibname
245 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
247 JNIEXPORT java_lang_String* JNICALL Java_java_lang_Runtime_nativeGetLibname(JNIEnv *env, jclass clazz, java_lang_String *par1, java_lang_String *par2)
254 data = javastring_toutf(par2, 0);
257 log_text("nativeGetLibName: Error: empty string");
261 buffer_len = utf_strlen(data) + 40;
263 buffer = MNEW(char, buffer_len);
265 strcpy(buffer, "Java_java_lang_Runtime_nativeGetLibname:");
266 utf_sprint(buffer + strlen((char *) data), data);
269 MFREE(buffer, char, buffer_len);
271 log_text("Java_java_lang_Runtime_nativeGetLibname");
278 * Class: java_lang_Runtime
279 * Method: insertSystemProperties
280 * Signature: (Ljava/util/Properties;)V
282 JNIEXPORT void JNICALL Java_java_lang_Runtime_insertSystemProperties(JNIEnv *env, jclass clazz, java_util_Properties *p)
285 #define BUFFERSIZE 200
288 char buffer[BUFFERSIZE];
289 struct utsname utsnamebuf;
291 proplist[0][1] = classpath;
292 proplist[1][1] = getenv("JAVA_HOME");
293 proplist[2][1] = getenv("HOME");
294 proplist[3][1] = getenv("USER");
295 proplist[4][1] = getcwd(buffer, BUFFERSIZE);
297 /* get properties from system */
299 proplist[5][1] = utsnamebuf.machine;
300 proplist[6][1] = utsnamebuf.sysname;
301 proplist[7][1] = utsnamebuf.release;
304 panic("Java_java_lang_Runtime_insertSystemProperties called with NULL-Argument");
306 /* search for method to add properties */
307 m = class_resolvemethod(p->header.vftbl->class,
309 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")
313 panic("Can not find method 'put' for class Properties");
315 /* add the properties */
316 for (i = 0; i < activeprops; i++) {
318 if (proplist[i][1] == NULL) proplist[i][1] = "";
320 asm_calljavafunction(m,
322 javastring_new_char(proplist[i][0]),
323 javastring_new_char(proplist[i][1]),
333 * Class: java_lang_Runtime
337 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_maxMemory(JNIEnv *env, java_lang_Runtime *this)
339 log_text("Java_java_lang_Runtime_maxMemory");
346 * These are local overrides for various environment variables in Emacs.
347 * Please do not remove this and leave it at the end of the file, where
348 * Emacs will automagically detect them.
349 * ---------------------------------------------------------------------
352 * indent-tabs-mode: t