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 5991 2006-11-15 18:26:40Z twisti $
38 #include <sys/utsname.h>
43 #include "mm/memory.h"
45 #include "vm/global.h"
46 #include "native/include/java_lang_String.h"
47 #include "native/include/java_util_Properties.h"
48 #include "toolbox/list.h"
49 #include "toolbox/util.h"
50 #include "vm/method.h"
51 #include "vm/options.h"
52 #include "vm/properties.h"
53 #include "vm/stringlocal.h"
55 #include "vm/jit/asmpart.h"
58 /* internal property structure ************************************************/
60 typedef struct list_properties_entry list_properties_entry;
62 struct list_properties_entry {
69 /* global variables ***********************************************************/
71 static list *list_properties = NULL;
74 /* properties_init *************************************************************
76 Initialize the properties list and fill the list with default
79 *******************************************************************************/
81 bool properties_init(void)
83 #if defined(ENABLE_JAVASE)
93 struct utsname *utsnamebuf;
97 /* create the properties list */
99 list_properties = list_create(OFFSET(list_properties_entry, linkage));
101 #if defined(ENABLE_JAVASE)
102 /* get properties from system */
105 env_java_home = getenv("JAVA_HOME");
106 env_user = getenv("USER");
107 env_home = getenv("HOME");
108 env_lang = getenv("LANG");
110 utsnamebuf = NEW(struct utsname);
114 /* set JAVA_HOME to default prefix if not defined */
116 if (env_java_home == NULL)
117 env_java_home = cacao_prefix;
119 /* fill in system properties */
121 properties_add("java.version", JAVA_VERSION);
122 properties_add("java.vendor", "GNU Classpath");
123 properties_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
125 /* add /jre to java.home property */
127 len = strlen(env_java_home) + strlen("/jre") + strlen("0");
129 java_home = MNEW(char, len);
131 strcpy(java_home, env_java_home);
132 strcat(java_home, "/jre");
134 properties_add("java.home", java_home);
136 properties_add("java.vm.specification.version", "1.0");
137 properties_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
138 properties_add("java.vm.specification.name", "Java Virtual Machine Specification");
139 properties_add("java.vm.version", VERSION);
140 properties_add("java.vm.vendor", "CACAO Team");
141 properties_add("java.vm.name", "CACAO");
142 properties_add("java.specification.version", "1.4");
143 properties_add("java.specification.vendor", "Sun Microsystems Inc.");
144 properties_add("java.specification.name", "Java Platform API Specification");
145 properties_add("java.class.version", CLASS_VERSION);
146 properties_add("java.class.path", _Jv_classpath);
148 properties_add("java.runtime.version", VERSION);
149 properties_add("java.runtime.name", "CACAO");
151 /* Set bootclasspath properties. One for GNU classpath and the
152 other for compatibility with Sun (required by most
155 properties_add("java.boot.class.path", _Jv_bootclasspath);
156 properties_add("sun.boot.class.path", _Jv_bootclasspath);
158 #if defined(WITH_STATIC_CLASSPATH)
159 properties_add("gnu.classpath.boot.library.path", ".");
160 properties_add("java.library.path" , ".");
162 /* fill gnu.classpath.boot.library.path with GNU Classpath library
165 properties_add("gnu.classpath.boot.library.path", classpath_libdir);
166 properties_add("java.library.path", _Jv_java_library_path);
169 properties_add("java.io.tmpdir", "/tmp");
171 #if defined(ENABLE_INTRP)
173 /* XXX We don't support java.lang.Compiler */
174 /* properties_add("java.compiler", "cacao.intrp"); */
175 properties_add("java.vm.info", "interpreted mode");
176 properties_add("gnu.java.compiler.name", "cacao.intrp");
181 /* XXX We don't support java.lang.Compiler */
182 /* properties_add("java.compiler", "cacao.jit"); */
183 properties_add("java.vm.info", "JIT mode");
184 properties_add("gnu.java.compiler.name", "cacao.jit");
187 /* set the java.ext.dirs property */
189 len = strlen(env_java_home) + strlen("/jre/lib/ext") + strlen("0");
191 extdirs = MNEW(char, len);
193 strcpy(extdirs, env_java_home);
194 strcat(extdirs, "/jre/lib/ext");
196 properties_add("java.ext.dirs", extdirs);
198 properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
200 #if defined(DISABLE_GC)
201 /* When we disable the GC, we mmap the whole heap to a specific
202 address, so we can compare call traces. For this reason we have
203 to add the same properties on different machines, otherwise
204 more memory may be allocated (e.g. strlen("i386")
205 vs. strlen("alpha"). */
207 properties_add("os.arch", "unknown");
208 properties_add("os.name", "unknown");
209 properties_add("os.version", "unknown");
211 /* We need to set the os.arch hardcoded to be compatible with SUN. */
213 # if defined(__I386__)
214 /* map all x86 architectures (i386, i486, i686) to i386 */
216 properties_add("os.arch", "i386");
217 # elif defined(__POWERPC__)
218 properties_add("os.arch", "ppc");
219 # elif defined(__X86_64__)
220 properties_add("os.arch", "amd64");
222 /* default to what uname returns */
224 properties_add("os.arch", utsnamebuf->machine);
227 properties_add("os.name", utsnamebuf->sysname);
228 properties_add("os.version", utsnamebuf->release);
231 properties_add("file.separator", "/");
232 properties_add("path.separator", ":");
233 properties_add("line.separator", "\n");
234 properties_add("user.name", env_user ? env_user : "null");
235 properties_add("user.home", env_home ? env_home : "null");
236 properties_add("user.dir", cwd ? cwd : "null");
238 #if defined(WITH_STATIC_CLASSPATH)
239 /* This is just for debugging purposes and can cause troubles in
242 properties_add("gnu.cpu.endian", "unknown");
244 # if WORDS_BIGENDIAN == 1
245 properties_add("gnu.cpu.endian", "big");
247 properties_add("gnu.cpu.endian", "little");
253 if (env_lang != NULL) {
254 /* get the local stuff from the environment */
256 if (strlen(env_lang) <= 2) {
257 properties_add("user.language", env_lang);
260 if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
261 lang = MNEW(char, 3);
262 strncpy(lang, (char *) &env_lang[0], 2);
265 country = MNEW(char, 3);
266 strncpy(country, (char *) &env_lang[3], 2);
269 properties_add("user.language", lang);
270 properties_add("user.country", country);
275 /* if no default locale was specified, use `en_US' */
277 properties_add("user.language", "en");
278 properties_add("user.country", "US");
280 #elif defined(ENABLE_JAVAME_CLDC1_1)
281 properties_add("microedition.configuration", "CLDC-1.1");
282 properties_add("microedition.platform", "PowerPC");
283 properties_add("microedition.encoding", "ISO-8859-1");
284 properties_add("microedition.profiles", "");
286 #error unknown Java configuration
289 /* everything's ok */
295 /* properties_postinit *********************************************************
297 Re-set some properties that may have changed during command-line
300 *******************************************************************************/
302 bool properties_postinit(void)
304 #if defined(ENABLE_JAVASE)
305 properties_add("java.class.path", _Jv_classpath);
306 properties_add("java.boot.class.path", _Jv_bootclasspath);
307 properties_add("sun.boot.class.path", _Jv_bootclasspath);
310 /* everything's ok */
316 /* properties_add **************************************************************
318 Adds a property entry to the internal property list.
320 *******************************************************************************/
322 void properties_add(char *key, char *value)
324 list_properties_entry *p;
326 p = NEW(list_properties_entry);
331 list_add_last_unsynced(list_properties, p);
335 /* properties_get **************************************************************
337 Get a property entry from the internal property list.
339 *******************************************************************************/
341 char *properties_get(char *key)
343 list_properties_entry *pe;
345 /* We search backwards, so we get the newest entry for a key, as
346 the list may contain more than one entry for a specific key. */
348 for (pe = list_last(list_properties); pe != NULL;
349 pe = list_prev(list_properties, pe)) {
350 if (strcmp(pe->key, key) == 0)
358 /* properties_system_add_all ***************************************************
360 Adds all properties from the properties list to the Java system
363 *******************************************************************************/
365 #if defined(ENABLE_JAVASE)
366 void properties_system_add_all(java_util_Properties *p)
368 list_properties_entry *pe;
370 java_lang_String *key;
371 java_lang_String *value;
373 /* search for method to add properties */
375 m = class_resolveclassmethod(p->header.vftbl->class,
377 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
384 /* process all properties stored in the internal table */
386 for (pe = list_first(list_properties); pe != NULL;
387 pe = list_next(list_properties, pe)) {
388 /* add to the Java system properties */
390 key = javastring_new_from_utf_string(pe->key);
391 value = javastring_new_from_utf_string(pe->value);
393 (void) vm_call_method(m, (java_objectheader *) p, key, value);
396 #endif /* defined(ENABLE_JAVASE) */
400 * These are local overrides for various environment variables in Emacs.
401 * Please do not remove this and leave it at the end of the file, where
402 * Emacs will automagically detect them.
403 * ---------------------------------------------------------------------
406 * indent-tabs-mode: t