1 /* src/vm/properties.c - handling commandline properties
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
29 $Id: properties.c 6249 2006-12-27 23:00:59Z twisti $
38 #include <sys/utsname.h>
43 #include "mm/memory.h"
45 #include "vm/global.h"
46 #include "native/include/java_lang_String.h"
48 #if defined(ENABLE_JAVASE)
49 # include "native/include/java_util_Properties.h"
52 #include "toolbox/list.h"
53 #include "toolbox/util.h"
54 #include "vm/method.h"
55 #include "vm/options.h"
56 #include "vm/properties.h"
57 #include "vm/stringlocal.h"
59 #include "vm/jit/asmpart.h"
62 /* internal property structure ************************************************/
64 typedef struct list_properties_entry list_properties_entry;
66 struct list_properties_entry {
73 /* global variables ***********************************************************/
75 static list *list_properties = NULL;
78 /* properties_init *************************************************************
80 Initialize the properties list and fill the list with default
83 *******************************************************************************/
85 bool properties_init(void)
87 #if defined(ENABLE_JAVASE)
97 struct utsname *utsnamebuf;
101 /* create the properties list */
103 list_properties = list_create(OFFSET(list_properties_entry, linkage));
105 #if defined(ENABLE_JAVASE)
106 /* get properties from system */
109 env_java_home = getenv("JAVA_HOME");
110 env_user = getenv("USER");
111 env_home = getenv("HOME");
112 env_lang = getenv("LANG");
114 utsnamebuf = NEW(struct utsname);
118 /* set JAVA_HOME to default prefix if not defined */
120 if (env_java_home == NULL)
121 env_java_home = cacao_prefix;
123 /* fill in system properties */
125 properties_add("java.version", JAVA_VERSION);
126 properties_add("java.vendor", "GNU Classpath");
127 properties_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
129 /* add /jre to java.home property */
131 len = strlen(env_java_home) + strlen("/jre") + strlen("0");
133 java_home = MNEW(char, len);
135 strcpy(java_home, env_java_home);
136 strcat(java_home, "/jre");
138 properties_add("java.home", java_home);
140 properties_add("java.vm.specification.version", "1.0");
141 properties_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
142 properties_add("java.vm.specification.name", "Java Virtual Machine Specification");
143 properties_add("java.vm.version", VERSION);
144 properties_add("java.vm.vendor", "CACAO Team");
145 properties_add("java.vm.name", "CACAO");
146 properties_add("java.specification.version", "1.5");
147 properties_add("java.specification.vendor", "Sun Microsystems Inc.");
148 properties_add("java.specification.name", "Java Platform API Specification");
149 properties_add("java.class.version", CLASS_VERSION);
150 properties_add("java.class.path", _Jv_classpath);
152 properties_add("java.runtime.version", VERSION);
153 properties_add("java.runtime.name", "CACAO");
155 /* Set bootclasspath properties. One for GNU classpath and the
156 other for compatibility with Sun (required by most
159 properties_add("java.boot.class.path", _Jv_bootclasspath);
160 properties_add("sun.boot.class.path", _Jv_bootclasspath);
162 #if defined(WITH_STATIC_CLASSPATH)
163 properties_add("gnu.classpath.boot.library.path", ".");
164 properties_add("java.library.path" , ".");
166 /* fill gnu.classpath.boot.library.path with GNU Classpath library
169 properties_add("gnu.classpath.boot.library.path", classpath_libdir);
170 properties_add("java.library.path", _Jv_java_library_path);
173 properties_add("java.io.tmpdir", "/tmp");
175 #if defined(ENABLE_INTRP)
177 /* XXX We don't support java.lang.Compiler */
178 /* properties_add("java.compiler", "cacao.intrp"); */
179 properties_add("java.vm.info", "interpreted mode");
180 properties_add("gnu.java.compiler.name", "cacao.intrp");
185 /* XXX We don't support java.lang.Compiler */
186 /* properties_add("java.compiler", "cacao.jit"); */
187 properties_add("java.vm.info", "JIT mode");
188 properties_add("gnu.java.compiler.name", "cacao.jit");
191 /* set the java.ext.dirs property */
193 len = strlen(env_java_home) + strlen("/jre/lib/ext") + strlen("0");
195 extdirs = MNEW(char, len);
197 strcpy(extdirs, env_java_home);
198 strcat(extdirs, "/jre/lib/ext");
200 properties_add("java.ext.dirs", extdirs);
202 properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
204 #if defined(DISABLE_GC)
205 /* When we disable the GC, we mmap the whole heap to a specific
206 address, so we can compare call traces. For this reason we have
207 to add the same properties on different machines, otherwise
208 more memory may be allocated (e.g. strlen("i386")
209 vs. strlen("alpha"). */
211 properties_add("os.arch", "unknown");
212 properties_add("os.name", "unknown");
213 properties_add("os.version", "unknown");
215 /* We need to set the os.arch hardcoded to be compatible with SUN. */
217 # if defined(__I386__)
218 /* map all x86 architectures (i386, i486, i686) to i386 */
220 properties_add("os.arch", "i386");
221 # elif defined(__POWERPC__)
222 properties_add("os.arch", "ppc");
223 # elif defined(__X86_64__)
224 properties_add("os.arch", "amd64");
226 /* default to what uname returns */
228 properties_add("os.arch", utsnamebuf->machine);
231 properties_add("os.name", utsnamebuf->sysname);
232 properties_add("os.version", utsnamebuf->release);
235 properties_add("file.separator", "/");
236 properties_add("path.separator", ":");
237 properties_add("line.separator", "\n");
238 properties_add("user.name", env_user ? env_user : "null");
239 properties_add("user.home", env_home ? env_home : "null");
240 properties_add("user.dir", cwd ? cwd : "null");
242 #if defined(WITH_STATIC_CLASSPATH)
243 /* This is just for debugging purposes and can cause troubles in
246 properties_add("gnu.cpu.endian", "unknown");
248 # if WORDS_BIGENDIAN == 1
249 properties_add("gnu.cpu.endian", "big");
251 properties_add("gnu.cpu.endian", "little");
257 if (env_lang != NULL) {
258 /* get the local stuff from the environment */
260 if (strlen(env_lang) <= 2) {
261 properties_add("user.language", env_lang);
264 if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
265 lang = MNEW(char, 3);
266 strncpy(lang, (char *) &env_lang[0], 2);
269 country = MNEW(char, 3);
270 strncpy(country, (char *) &env_lang[3], 2);
273 properties_add("user.language", lang);
274 properties_add("user.country", country);
279 /* if no default locale was specified, use `en_US' */
281 properties_add("user.language", "en");
282 properties_add("user.country", "US");
284 #elif defined(ENABLE_JAVAME_CLDC1_1)
285 properties_add("microedition.configuration", "CLDC-1.1");
286 properties_add("microedition.platform", "generic");
287 properties_add("microedition.encoding", "ISO8859_1");
288 properties_add("microedition.profiles", "");
290 #error unknown Java configuration
293 /* everything's ok */
299 /* properties_postinit *********************************************************
301 Re-set some properties that may have changed during command-line
304 *******************************************************************************/
306 bool properties_postinit(void)
308 #if defined(ENABLE_JAVASE)
309 properties_add("java.class.path", _Jv_classpath);
310 properties_add("java.boot.class.path", _Jv_bootclasspath);
311 properties_add("sun.boot.class.path", _Jv_bootclasspath);
314 /* everything's ok */
320 /* properties_add **************************************************************
322 Adds a property entry to the internal property list. If there's
323 already an entry with the same key, replace it.
325 *******************************************************************************/
327 void properties_add(char *key, char *value)
329 list_properties_entry *pe;
331 /* search for the entry */
333 for (pe = list_first_unsynced(list_properties); pe != NULL;
334 pe = list_next_unsynced(list_properties, pe)) {
335 if (strcmp(pe->key, key) == 0) {
336 /* entry was found, replace the value */
344 /* entry was not found, insert a new one */
346 pe = NEW(list_properties_entry);
351 list_add_last_unsynced(list_properties, pe);
355 /* properties_get **************************************************************
357 Get a property entry from the internal property list.
359 *******************************************************************************/
361 char *properties_get(char *key)
363 list_properties_entry *pe;
365 /* We search backwards, so we get the newest entry for a key, as
366 the list may contain more than one entry for a specific key. */
368 for (pe = list_last_unsynced(list_properties); pe != NULL;
369 pe = list_prev_unsynced(list_properties, pe)) {
370 if (strcmp(pe->key, key) == 0)
378 /* properties_system_add_all ***************************************************
380 Adds all properties from the properties list to the Java system
383 *******************************************************************************/
385 #if defined(ENABLE_JAVASE)
386 void properties_system_add_all(java_util_Properties *p)
388 list_properties_entry *pe;
390 java_lang_String *key;
391 java_lang_String *value;
393 /* search for method to add properties */
395 m = class_resolveclassmethod(p->header.vftbl->class,
397 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
404 /* process all properties stored in the internal table */
406 for (pe = list_first(list_properties); pe != NULL;
407 pe = list_next(list_properties, pe)) {
408 /* add to the Java system properties */
410 key = javastring_new_from_utf_string(pe->key);
411 value = javastring_new_from_utf_string(pe->value);
413 (void) vm_call_method(m, (java_objectheader *) p, key, value);
416 #endif /* defined(ENABLE_JAVASE) */
420 * These are local overrides for various environment variables in Emacs.
421 * Please do not remove this and leave it at the end of the file, where
422 * Emacs will automagically detect them.
423 * ---------------------------------------------------------------------
426 * indent-tabs-mode: t