1 /* src/vm/properties.c - handling commandline properties
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: properties.c 8351 2007-08-19 17:56:23Z twisti $
34 #include <sys/utsname.h>
39 #include "mm/memory.h"
41 #include "native/jni.h"
43 #include "vm/global.h" /* required by java_lang_String.h */
44 #include "native/include/java_lang_String.h"
46 #include "toolbox/list.h"
47 #include "toolbox/util.h"
49 #include "vm/properties.h"
50 #include "vm/stringlocal.h"
53 #include "vm/jit/asmpart.h"
55 #include "vmcore/method.h"
56 #include "vmcore/options.h"
59 /* internal property structure ************************************************/
61 typedef struct list_properties_entry list_properties_entry;
63 struct list_properties_entry {
70 /* global variables ***********************************************************/
72 static list_t *list_properties = NULL;
75 /* properties_init *************************************************************
77 Initialize the properties list and fill the list with default
80 *******************************************************************************/
82 bool properties_init(void)
84 #if defined(ENABLE_JAVASE)
89 # if defined(WITH_CLASSPATH_GNU)
97 struct utsname *utsnamebuf;
101 /* create the properties list */
103 list_properties = list_create(OFFSET(list_properties_entry, linkage));
105 #if defined(ENABLE_JAVASE)
107 /* get properties from system */
109 env_java_home = getenv("JAVA_HOME");
111 /* set JAVA_HOME to default prefix if not defined */
113 if (env_java_home == NULL)
114 env_java_home = cacao_prefix;
116 /* fill in system properties */
118 /* add /jre to java.home property */
120 len = strlen(env_java_home) + strlen("/jre") + strlen("0");
122 java_home = MNEW(char, len);
124 strcpy(java_home, env_java_home);
125 strcat(java_home, "/jre");
127 properties_add("java.home", java_home);
129 properties_add("java.vm.specification.version", "1.0");
130 properties_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
131 properties_add("java.vm.specification.name", "Java Virtual Machine Specification");
132 properties_add("java.vm.version", VERSION);
133 properties_add("java.vm.vendor", "CACAO Team");
134 properties_add("java.vm.name", "CACAO");
136 # if defined(ENABLE_INTRP)
138 /* XXX We don't support java.lang.Compiler */
139 /* properties_add("java.compiler", "cacao.intrp"); */
140 properties_add("java.vm.info", "interpreted mode");
145 /* XXX We don't support java.lang.Compiler */
146 /* properties_add("java.compiler", "cacao.jit"); */
147 properties_add("java.vm.info", "JIT mode");
150 # if defined(WITH_CLASSPATH_GNU)
152 /* get properties from system */
156 env_user = getenv("USER");
157 env_home = getenv("HOME");
158 env_lang = getenv("LANG");
160 utsnamebuf = NEW(struct utsname);
164 properties_add("java.runtime.version", VERSION);
165 properties_add("java.runtime.name", "CACAO");
167 properties_add("java.specification.version", "1.5");
168 properties_add("java.specification.vendor", "Sun Microsystems Inc.");
169 properties_add("java.specification.name", "Java Platform API Specification");
171 properties_add("java.version", JAVA_VERSION);
172 properties_add("java.vendor", "GNU Classpath");
173 properties_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
175 properties_add("java.class.path", _Jv_classpath);
176 properties_add("java.class.version", CLASS_VERSION);
178 /* Set bootclasspath properties. One for GNU classpath and the
179 other for compatibility with Sun (required by most
182 properties_add("java.boot.class.path", _Jv_bootclasspath);
183 properties_add("sun.boot.class.path", _Jv_bootclasspath);
185 # if defined(WITH_STATIC_CLASSPATH)
186 properties_add("gnu.classpath.boot.library.path", ".");
187 properties_add("java.library.path" , ".");
189 /* fill gnu.classpath.boot.library.path with GNU Classpath library
192 properties_add("gnu.classpath.boot.library.path", classpath_libdir);
193 properties_add("java.library.path", _Jv_java_library_path);
196 properties_add("java.io.tmpdir", "/tmp");
198 # if defined(ENABLE_INTRP)
200 properties_add("gnu.java.compiler.name", "cacao.intrp");
205 properties_add("gnu.java.compiler.name", "cacao.jit");
208 /* set the java.ext.dirs property */
210 len = strlen(env_java_home) + strlen("/jre/lib/ext") + strlen("0");
212 extdirs = MNEW(char, len);
214 strcpy(extdirs, env_java_home);
215 strcat(extdirs, "/jre/lib/ext");
217 properties_add("java.ext.dirs", extdirs);
219 properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
221 # if defined(DISABLE_GC)
222 /* When we disable the GC, we mmap the whole heap to a specific
223 address, so we can compare call traces. For this reason we have
224 to add the same properties on different machines, otherwise
225 more memory may be allocated (e.g. strlen("i386")
226 vs. strlen("alpha"). */
228 properties_add("os.arch", "unknown");
229 properties_add("os.name", "unknown");
230 properties_add("os.version", "unknown");
232 properties_add("os.arch", JAVA_ARCH);
233 properties_add("os.name", utsnamebuf->sysname);
234 properties_add("os.version", utsnamebuf->release);
237 # if defined(WITH_STATIC_CLASSPATH)
238 /* This is just for debugging purposes and can cause troubles in
241 properties_add("gnu.cpu.endian", "unknown");
243 # if WORDS_BIGENDIAN == 1
244 properties_add("gnu.cpu.endian", "big");
246 properties_add("gnu.cpu.endian", "little");
250 properties_add("file.separator", "/");
251 properties_add("path.separator", ":");
252 properties_add("line.separator", "\n");
254 properties_add("user.name", env_user ? env_user : "null");
255 properties_add("user.home", env_home ? env_home : "null");
256 properties_add("user.dir", cwd ? cwd : "null");
260 if (env_lang != NULL) {
261 /* get the local stuff from the environment */
263 if (strlen(env_lang) <= 2) {
264 properties_add("user.language", env_lang);
267 if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
268 lang = MNEW(char, 3);
269 strncpy(lang, (char *) &env_lang[0], 2);
272 country = MNEW(char, 3);
273 strncpy(country, (char *) &env_lang[3], 2);
276 properties_add("user.language", lang);
277 properties_add("user.country", country);
282 /* if no default locale was specified, use `en_US' */
284 properties_add("user.language", "en");
285 properties_add("user.country", "US");
288 # elif defined(WITH_CLASSPATH_SUN)
290 properties_add("sun.boot.library.path", classpath_libdir);
294 # error unknown classpath configuration
298 #elif defined(ENABLE_JAVAME_CLDC1_1)
300 properties_add("microedition.configuration", "CLDC-1.1");
301 properties_add("microedition.platform", "generic");
302 properties_add("microedition.encoding", "ISO8859_1");
303 properties_add("microedition.profiles", "");
307 # error unknown Java configuration
311 /* everything's ok */
317 /* properties_add **************************************************************
319 Adds a property entry to the internal property list. If there's
320 already an entry with the same key, replace it.
322 *******************************************************************************/
324 void properties_add(char *key, char *value)
326 list_properties_entry *pe;
328 /* search for the entry */
330 for (pe = list_first_unsynced(list_properties); pe != NULL;
331 pe = list_next_unsynced(list_properties, pe)) {
332 if (strcmp(pe->key, key) == 0) {
333 /* entry was found, replace the value */
341 /* entry was not found, insert a new one */
343 pe = NEW(list_properties_entry);
348 list_add_last_unsynced(list_properties, pe);
352 /* properties_get **************************************************************
354 Get a property entry from the internal property list.
356 *******************************************************************************/
358 char *properties_get(char *key)
360 list_properties_entry *pe;
362 for (pe = list_first_unsynced(list_properties); pe != NULL;
363 pe = list_next_unsynced(list_properties, pe)) {
364 if (strcmp(pe->key, key) == 0)
372 /* properties_system_add *******************************************************
374 Adds a given property to the Java system properties.
376 *******************************************************************************/
378 void properties_system_add(java_handle_t *p, char *key, char *value)
384 /* search for method to add properties */
386 m = class_resolveclassmethod(p->vftbl->class,
388 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
395 /* add to the Java system properties */
397 k = javastring_new_from_utf_string(key);
398 v = javastring_new_from_utf_string(value);
400 (void) vm_call_method(m, p, k, v);
404 /* properties_system_add_all ***************************************************
406 Adds all properties from the properties list to the Java system
410 p.... is actually a java_util_Properties structure
412 *******************************************************************************/
414 #if defined(ENABLE_JAVASE)
415 void properties_system_add_all(java_handle_t *p)
417 list_properties_entry *pe;
420 java_handle_t *value;
422 /* search for method to add properties */
424 m = class_resolveclassmethod(p->vftbl->class,
426 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
433 /* process all properties stored in the internal table */
435 for (pe = list_first(list_properties); pe != NULL;
436 pe = list_next(list_properties, pe)) {
437 /* add to the Java system properties */
439 key = javastring_new_from_utf_string(pe->key);
440 value = javastring_new_from_utf_string(pe->value);
442 (void) vm_call_method(m, (java_handle_t *) p, key, value);
445 #endif /* defined(ENABLE_JAVASE) */
449 * These are local overrides for various environment variables in Emacs.
450 * Please do not remove this and leave it at the end of the file, where
451 * Emacs will automagically detect them.
452 * ---------------------------------------------------------------------
455 * indent-tabs-mode: t