1 /* src/native/vm/VMSystemProperties.c - gnu/classpath/VMSystemProperties
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: VMSystemProperties.c 4220 2006-01-17 16:58:13Z twisti $
40 #include <sys/utsname.h>
45 #include "mm/memory.h"
46 #include "native/jni.h"
47 #include "native/native.h"
48 #include "native/include/java_util_Properties.h"
49 #include "toolbox/logging.h"
50 #include "toolbox/util.h"
51 #include "vm/exceptions.h"
52 #include "vm/builtin.h"
53 #include "vm/loader.h"
54 #include "vm/options.h"
55 #include "vm/properties.h"
60 * Class: gnu/classpath/VMSystemProperties
62 * Signature: (Ljava/util/Properties;)V
64 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *p)
73 struct utsname utsnamebuf;
75 #if !defined(ENABLE_STATICVM)
76 char *ld_library_path;
82 exceptions_throw_nullpointerexception();
86 /* get properties from system */
89 java_home = getenv("JAVA_HOME");
90 user = getenv("USER");
91 home = getenv("HOME");
94 /* post-initialize the properties */
96 if (!properties_postinit(p))
99 properties_system_add("java.version", JAVA_VERSION);
100 properties_system_add("java.vendor", "GNU Classpath");
101 properties_system_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
102 properties_system_add("java.home", java_home ? java_home : CACAO_PREFIX);
103 properties_system_add("java.vm.specification.version", "1.0");
104 properties_system_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
105 properties_system_add("java.vm.specification.name", "Java Virtual Machine Specification");
106 properties_system_add("java.vm.version", VERSION);
107 properties_system_add("java.vm.vendor", "CACAO Team");
108 properties_system_add("java.vm.name", "CACAO");
109 properties_system_add("java.specification.version", "1.4");
110 properties_system_add("java.specification.vendor", "Sun Microsystems Inc.");
111 properties_system_add("java.specification.name", "Java Platform API Specification");
112 properties_system_add("java.class.version", CLASS_VERSION);
113 properties_system_add("java.class.path", classpath);
115 properties_system_add("java.runtime.version", VERSION);
116 properties_system_add("java.runtime.name", "CACAO");
118 /* Set bootclasspath properties. One for GNU classpath and the
119 other for compatibility with Sun (required by most
122 properties_system_add("java.boot.class.path", bootclasspath);
123 properties_system_add("sun.boot.class.path", bootclasspath);
125 #if defined(ENABLE_STATICVM)
126 properties_system_add("gnu.classpath.boot.library.path", ".");
127 properties_system_add("java.library.path" , ".");
128 #else /* defined(ENABLE_STATICVM) */
129 /* fill gnu.classpath.boot.library.path with GNU classpath library
132 libpathlen = strlen(CLASSPATH_LIBRARY_PATH) + strlen("0");
134 libpath = MNEW(char, libpathlen);
136 strcat(libpath, CLASSPATH_LIBRARY_PATH);
138 properties_system_add("gnu.classpath.boot.library.path", libpath);
140 MFREE(libpath, char, libpathlen);
143 /* now fill java.library.path */
145 ld_library_path = getenv("LD_LIBRARY_PATH");
147 if (ld_library_path) {
148 libpathlen = strlen(".:") + strlen(ld_library_path) + strlen("0");
150 libpath = MNEW(char, libpathlen);
152 strcpy(libpath, ".:");
153 strcat(libpath, ld_library_path);
155 properties_system_add("java.library.path", libpath);
157 MFREE(libpath, char, libpathlen);
160 properties_system_add("java.library.path", "");
162 #endif /* defined(ENABLE_STATICVM) */
164 properties_system_add("java.io.tmpdir", "/tmp");
166 #if defined(ENABLE_INTRP)
168 /* XXX We don't support java.lang.Compiler */
169 /* properties_system_add("java.compiler", "cacao.intrp"); */
170 properties_system_add("java.vm.info", "interpreted mode");
174 /* XXX We don't support java.lang.Compiler */
175 /* properties_system_add("java.compiler", "cacao.jit"); */
176 properties_system_add("java.vm.info", "JIT mode");
179 properties_system_add("java.ext.dirs", "");
181 #if defined(DISABLE_GC)
182 /* When we disable the GC, we mmap the whole heap to a specific
183 address, so we can compare call traces. For this reason we have
184 to add the same properties on different machines, otherwise
185 more memory may be allocated (e.g. strlen("i386")
186 vs. strlen("alpha"). */
188 properties_system_add("os.arch", "unknown");
189 properties_system_add("os.name", "unknown");
190 properties_system_add("os.version", "unknown");
192 /* We need to set the os.arch hardcoded to be compatible with SUN. */
194 #if defined(__I386__)
195 /* map all x86 architectures (i386, i486, i686) to i386 */
197 properties_system_add("os.arch", "i386");
198 #elif defined(__POWERPC__)
199 properties_system_add("os.arch", "ppc");
200 #elif defined(__X86_64__)
201 properties_system_add("os.arch", "amd64");
203 /* default to what uname returns */
205 properties_system_add("os.arch", utsnamebuf.machine);
208 properties_system_add("os.name", utsnamebuf.sysname);
209 properties_system_add("os.version", utsnamebuf.release);
212 properties_system_add("file.separator", "/");
213 properties_system_add("path.separator", ":");
214 properties_system_add("line.separator", "\n");
215 properties_system_add("user.name", user ? user : "null");
216 properties_system_add("user.home", home ? home : "null");
217 properties_system_add("user.dir", cwd ? cwd : "null");
219 /* Are we little or big endian? */
221 #if defined(ENABLE_STATICVM)
222 /* This is just for debugging purposes and can cause troubles in
225 properties_system_add("gnu.cpu.endian", "unknown");
227 # if WORDS_BIGENDIAN == 1
228 properties_system_add("gnu.cpu.endian", "big");
230 properties_system_add("gnu.cpu.endian", "little");
236 locale = getenv("LANG");
238 if (locale != NULL) {
239 /* get the local stuff from the environment */
241 if (strlen(locale) <= 2) {
242 properties_system_add("user.language", locale);
245 if ((locale[2] == '_') && (strlen(locale) >= 5)) {
246 lang = MNEW(char, 3);
247 strncpy(lang, (char *) &locale[0], 2);
250 country = MNEW(char, 3);
251 strncpy(country, (char *) &locale[3], 2);
254 properties_system_add("user.language", lang);
255 properties_system_add("user.country", country);
260 /* if no default locale was specified, use `en_US' */
262 properties_system_add("user.language", "en");
263 properties_system_add("user.country", "US");
267 /* Add remaining properties defined on commandline to the Java
268 system properties. */
270 properties_system_add_all();
279 * These are local overrides for various environment variables in Emacs.
280 * Please do not remove this and leave it at the end of the file, where
281 * Emacs will automagically detect them.
282 * ---------------------------------------------------------------------
285 * indent-tabs-mode: t