* src/vm/properties.h: Likewise.
* src/vm/properties.cpp: New file.
* src/vm/properties.hpp: Likewise.
* src/native/vm/cldc1.1/java_lang_System.cpp,
src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp,
src/native/vm/nativevm.c,
src/native/vm/openjdk/hpi.c,
src/native/vm/openjdk/jvm.cpp,
src/vm/Makefile.am,
src/vm/suck.c,
src/vm/vm.cpp,
src/vm/vm.hpp: Related changes.
--HG--
rename : src/vm/properties.c => src/vm/properties.cpp
rename : src/vm/properties.h => src/vm/properties.hpp
#endif
#include "vm/jit/builtin.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/string.hpp"
+#include "vm/vm.hpp"
// Native functions are exported as C functions.
/* get the property from the internal table */
- value = properties_get(key);
+ value = VM::get_current()->get_properties().get(key);
/* release the memory allocated in javastring_tochar */
#endif
#include "vm/exceptions.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/vm.hpp"
return;
}
- /* fill the java.util.Properties object */
-
- properties_system_add_all(p);
+ // Fill the java.util.Properties object.
+ VM::get_current()->get_properties().fill(p);
}
/* XXX when we do it that way, we can't set these properties on
commandline */
- java_home = properties_get("java.home");
+ java_home = VM::get_current()->get_properties().get("java.home");
- properties_system_add(p, "gnu.classpath.home", java_home);
+ Properties::put(p, "gnu.classpath.home", java_home);
len =
strlen("file://") +
strcat(path, java_home);
strcat(path, "/lib");
- properties_system_add(p, "gnu.classpath.home.url", path);
+ Properties::put(p, "gnu.classpath.home.url", path);
MFREE(path, char, len);
#endif
# include "native/vm/openjdk/hpi.h"
# include "vm/globals.hpp"
-# include "vm/properties.h"
+# include "vm/properties.hpp"
# include "vm/utf8.h"
# include "vm/vm.hpp"
#endif
/* Load libjava.so */
- boot_library_path = properties_get("sun.boot.library.path");
+ boot_library_path = Properties_get("sun.boot.library.path");
len =
os_strlen(boot_library_path) +
#include "vm/options.h"
#include "vm/os.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/utf8.h"
#include "vm/vm.hpp"
/* Load libhpi.so */
- boot_library_path = properties_get("sun.boot.library.path");
+ boot_library_path = Properties_get("sun.boot.library.path");
len =
os_strlen(boot_library_path) +
#include "vm/os.hpp"
#include "vm/package.hpp"
#include "vm/primitive.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/resolve.h"
#include "vm/signallocal.h"
#include "vm/string.hpp"
-D option, as requested. */
jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
- properties_add("sun.nio.MaxDirectMemorySize", buf);
+ VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
- /* Add all properties. */
-
- properties_system_add_all(h);
+ // Fill the java.util.Properties object.
+ VM::get_current()->get_properties().fill(h);
return properties;
}
package.hpp \
primitive.cpp \
primitive.hpp \
- properties.c \
- properties.h \
+ properties.cpp \
+ properties.hpp \
references.h \
resolve.c \
resolve.h \
+++ /dev/null
-/* src/vm/properties.c - handling commandline properties
-
- Copyright (C) 1996-2005, 2006, 2007, 2008
- CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
-*/
-
-
-#include "config.h"
-
-#include <stdint.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/utsname.h>
-
-#include "mm/memory.h"
-
-#include "native/llni.h"
-
-#include "toolbox/list.h"
-#include "toolbox/util.h"
-
-#include "vm/class.h"
-#include "vm/global.h"
-#include "vm/method.h"
-#include "vm/options.h"
-#include "vm/os.hpp"
-#include "vm/properties.h"
-#include "vm/string.hpp"
-#include "vm/vm.hpp"
-
-#include "vm/jit/asmpart.h"
-
-
-/* internal property structure ************************************************/
-
-typedef struct list_properties_entry_t list_properties_entry_t;
-
-struct list_properties_entry_t {
- const char* key;
- const char* value;
- listnode_t linkage;
-};
-
-
-/* global variables ***********************************************************/
-
-static list_t *list_properties = NULL;
-
-
-/* properties_init *************************************************************
-
- Initialize the properties list and fill the list with default
- values.
-
-*******************************************************************************/
-
-void properties_init(void)
-{
- TRACESUBSYSTEMINITIALIZATION("properties_init");
-
- list_properties = list_create(OFFSET(list_properties_entry_t, linkage));
-}
-
-
-/* properties_set **************************************************************
-
- Fill the properties list with default values.
-
-*******************************************************************************/
-
-void properties_set(void)
-{
- int len;
- char *p;
-
- char *java_home;
- char *boot_class_path;
-
-#if defined(ENABLE_JAVASE)
- char *class_path;
- char *boot_library_path;
- char *extdirs;
- char *endorseddirs;
-
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- char *cwd;
- char *env_user;
- char *env_home;
- char *env_lang;
- char *lang;
- char *country;
- struct utsname *utsnamebuf;
-
- char *java_library_path;
-# endif
-#endif
-
-#if defined(ENABLE_JRE_LAYOUT)
- /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
-
- p = MNEW(char, 4096);
-
- if (readlink("/proc/self/exe", p, 4095) == -1)
- vm_abort("properties_set: readlink failed: %s\n", strerror(errno));
-
- /* We have a path like:
-
- /path/to/executable/bin/java
-
- or
-
- /path/to/executeable/jre/bin/java
-
- Now let's strip two levels. */
-
- p = os_dirname(p);
- p = os_dirname(p);
-
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-
- /* Set java.home. */
-
- java_home = strdup(p);
-
- /* Set the path to Java core native libraries. */
-
- len = strlen(java_home) + strlen("/lib/classpath") + strlen("0");
-
- boot_library_path = MNEW(char, len);
-
- strcpy(boot_library_path, java_home);
- strcat(boot_library_path, "/lib/classpath");
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-
- /* Find correct java.home. We check if there is a JRE
- co-located. */
-
- /* NOTE: We use the server VM here as it should be available on
- all architectures. */
-
- len =
- strlen(p) +
- strlen("/jre/lib/"JAVA_ARCH"/server/libjvm.so") +
- strlen("0");
-
- java_home = MNEW(char, len);
-
- strcpy(java_home, p);
- strcat(java_home, "/jre/lib/"JAVA_ARCH"/server/libjvm.so");
-
- /* Check if that libjvm.so exists. */
-
- if (os_access(java_home, F_OK) == 0) {
- /* Yes, we add /jre to java.home. */
-
- strcpy(java_home, p);
- strcat(java_home, "/jre");
- }
- else {
- /* No, java.home is parent directory. */
-
- strcpy(java_home, p);
- }
-
- /* Set the path to Java core native libraries. */
-
- len = strlen(java_home) + strlen("/lib/"JAVA_ARCH) + strlen("0");
-
- boot_library_path = MNEW(char, len);
-
- strcpy(boot_library_path, java_home);
- strcat(boot_library_path, "/lib/"JAVA_ARCH);
-
-# else
-# error unknown classpath configuration
-# endif
-
- /* Free path. */
-
- MFREE(p, char, len);
-
-#else
- java_home = CACAO_PREFIX;
-
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-
- boot_library_path = JAVA_RUNTIME_LIBRARY_LIBDIR"/classpath";
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-
- boot_library_path = JAVA_RUNTIME_LIBRARY_LIBDIR;
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
-
- /* No boot_library_path required. */
-
-# else
-# error unknown classpath configuration
-# endif
-#endif
-
- properties_add("java.home", java_home);
-
- /* Set the bootclasspath. */
-
- p = getenv("BOOTCLASSPATH");
-
- if (p != NULL) {
- boot_class_path = MNEW(char, strlen(p) + strlen("0"));
- strcpy(boot_class_path, p);
- }
- else {
-#if defined(ENABLE_JRE_LAYOUT)
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-
- len =
- strlen(java_home) + strlen("/share/cacao/vm.zip:") +
- strlen(java_home) + strlen("/share/classpath/glibj.zip") +
- strlen("0");
-
- boot_class_path = MNEW(char, len);
-
- strcpy(boot_class_path, java_home);
- strcat(boot_class_path, "/share/cacao/vm.zip");
- strcat(boot_class_path, ":");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/share/classpath/glibj.zip");
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-
- /* This is the bootclasspath taken from HotSpot (see
- hotspot/src/share/vm/runtime/os.cpp
- (os::set_boot_path)). */
-
- len =
- strlen(java_home) + strlen("/lib/resources.jar:") +
- strlen(java_home) + strlen("/lib/rt.jar:") +
- strlen(java_home) + strlen("/lib/sunrsasign.jar:") +
- strlen(java_home) + strlen("/lib/jsse.jar:") +
- strlen(java_home) + strlen("/lib/jce.jar:") +
- strlen(java_home) + strlen("/lib/charsets.jar:") +
- strlen(java_home) + strlen("/classes") +
- strlen("0");
-
- boot_class_path = MNEW(char, len);
-
- strcpy(boot_class_path, java_home);
- strcat(boot_class_path, "/lib/resources.jar:");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/lib/rt.jar:");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/lib/sunrsasign.jar:");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/lib/jsse.jar:");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/lib/jce.jar:");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/lib/charsets.jar:");
- strcat(boot_class_path, java_home);
- strcat(boot_class_path, "/classes");
-
-# else
-# error unknown classpath configuration
-# endif
-#else
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-
- len =
- strlen(CACAO_VM_ZIP) +
- strlen(":") +
- strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
- strlen("0");
-
- boot_class_path = MNEW(char, len);
-
- strcpy(boot_class_path, CACAO_VM_ZIP);
- strcat(boot_class_path, ":");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_CLASSES);
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-
- /* This is the bootclasspath taken from HotSpot (see
- hotspot/src/share/vm/runtime/os.cpp
- (os::set_boot_path)). */
-
- len =
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/resources.jar:") +
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/rt.jar:") +
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/sunrsasign.jar:") +
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jsse.jar:") +
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jce.jar:") +
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/charsets.jar:") +
- strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/classes") +
- strlen("0");
-
- boot_class_path = MNEW(char, len);
-
- strcpy(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/resources.jar:");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/rt.jar:");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/sunrsasign.jar:");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jsse.jar:");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jce.jar:");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/charsets.jar:");
- strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/classes");
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
-
- len =
- strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
- strlen("0");
-
- boot_class_path = MNEW(char, len);
-
- strcpy(boot_class_path, JAVA_RUNTIME_LIBRARY_CLASSES);
-
-# else
-# error unknown classpath configuration
-# endif
-#endif
- }
-
- properties_add("sun.boot.class.path", boot_class_path);
- properties_add("java.boot.class.path", boot_class_path);
-
-#if defined(ENABLE_JAVASE)
-
- /* Set the classpath. */
-
- p = getenv("CLASSPATH");
-
- if (p != NULL) {
- class_path = MNEW(char, strlen(p) + strlen("0"));
- strcpy(class_path, p);
- }
- else {
- class_path = MNEW(char, strlen(".") + strlen("0"));
- strcpy(class_path, ".");
- }
-
- properties_add("java.class.path", class_path);
-
- /* Add java.vm properties. */
-
- properties_add("java.vm.specification.version", "1.0");
- properties_add("java.vm.specification.vendor", "Sun Microsystems Inc.");
- properties_add("java.vm.specification.name", "Java Virtual Machine Specification");
- properties_add("java.vm.version", VERSION);
- properties_add("java.vm.vendor", "CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
- properties_add("java.vm.name", "CACAO");
-
-# if defined(ENABLE_INTRP)
- if (opt_intrp) {
- /* XXX We don't support java.lang.Compiler */
-/* properties_add("java.compiler", "cacao.intrp"); */
- properties_add("java.vm.info", "interpreted mode");
- }
- else
-# endif
- {
- /* XXX We don't support java.lang.Compiler */
-/* properties_add("java.compiler", "cacao.jit"); */
- properties_add("java.vm.info", "JIT mode");
- }
-
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-
- /* Get properties from system. */
-
- cwd = _Jv_getcwd();
-
- env_user = getenv("USER");
- env_home = getenv("HOME");
- env_lang = getenv("LANG");
-
- utsnamebuf = NEW(struct utsname);
-
- uname(utsnamebuf);
-
- properties_add("java.runtime.version", VERSION);
- properties_add("java.runtime.name", "CACAO");
-
- properties_add("java.specification.version", "1.5");
- properties_add("java.specification.vendor", "Sun Microsystems Inc.");
- properties_add("java.specification.name", "Java Platform API Specification");
-
- properties_add("java.version", JAVA_VERSION);
- properties_add("java.vendor", "GNU Classpath");
- properties_add("java.vendor.url", "http://www.gnu.org/software/classpath/");
-
- properties_add("java.class.version", CLASS_VERSION);
-
- properties_add("gnu.classpath.boot.library.path", boot_library_path);
-
- /* Get and set java.library.path. */
-
- java_library_path = getenv("LD_LIBRARY_PATH");
-
- if (java_library_path == NULL)
- java_library_path = "";
-
- properties_add("java.library.path", java_library_path);
-
- properties_add("java.io.tmpdir", "/tmp");
-
-# if defined(ENABLE_INTRP)
- if (opt_intrp) {
- properties_add("gnu.java.compiler.name", "cacao.intrp");
- }
- else
-# endif
- {
- properties_add("gnu.java.compiler.name", "cacao.jit");
- }
-
- /* Set the java.ext.dirs property. */
-
- len = strlen(java_home) + strlen("/jre/lib/ext") + strlen("0");
-
- extdirs = MNEW(char, len);
-
- sprintf(extdirs, "%s/jre/lib/ext", java_home);
-
- properties_add("java.ext.dirs", extdirs);
-
- /* Set the java.ext.endorsed property. */
-
- len = strlen(java_home) + strlen("/jre/lib/endorsed") + strlen("0");
-
- endorseddirs = MNEW(char, len);
-
- sprintf(endorseddirs, "%s/jre/lib/endorsed", java_home);
-
- properties_add("java.endorsed.dirs", endorseddirs);
-
-# if defined(DISABLE_GC)
- /* When we disable the GC, we mmap the whole heap to a specific
- address, so we can compare call traces. For this reason we have
- to add the same properties on different machines, otherwise
- more memory may be allocated (e.g. strlen("i386")
- vs. strlen("alpha"). */
-
- properties_add("os.arch", "unknown");
- properties_add("os.name", "unknown");
- properties_add("os.version", "unknown");
-# else
- properties_add("os.arch", JAVA_ARCH);
- properties_add("os.name", utsnamebuf->sysname);
- properties_add("os.version", utsnamebuf->release);
-# endif
-
-# if WORDS_BIGENDIAN == 1
- properties_add("gnu.cpu.endian", "big");
-# else
- properties_add("gnu.cpu.endian", "little");
-# endif
-
- properties_add("file.separator", "/");
- properties_add("path.separator", ":");
- properties_add("line.separator", "\n");
-
- properties_add("user.name", env_user ? env_user : "null");
- properties_add("user.home", env_home ? env_home : "null");
- properties_add("user.dir", cwd ? cwd : "null");
-
- /* get locale */
-
- if (env_lang != NULL) {
- /* get the local stuff from the environment */
-
- if (strlen(env_lang) <= 2) {
- properties_add("user.language", env_lang);
- }
- else {
- if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
- lang = MNEW(char, 3);
- strncpy(lang, (char *) &env_lang[0], 2);
- lang[2] = '\0';
-
- country = MNEW(char, 3);
- strncpy(country, (char *) &env_lang[3], 2);
- country[2] = '\0';
-
- properties_add("user.language", lang);
- properties_add("user.country", country);
- }
- }
- }
- else {
- /* if no default locale was specified, use `en_US' */
-
- properties_add("user.language", "en");
- properties_add("user.country", "US");
- }
-
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-
- /* Actually this property is set by OpenJDK, but we need it in
- nativevm_preinit(). */
-
- properties_add("sun.boot.library.path", boot_library_path);
-
- /* Set the java.ext.dirs property. */
-
- len =
- strlen(java_home) + strlen("/lib/ext") +
- strlen(":") +
- strlen("/usr/java/packages/lib/ext") +
- strlen("0");
-
- extdirs = MNEW(char, len);
-
- sprintf(extdirs, "%s/lib/ext:/usr/java/packages/lib/ext", java_home);
-
- properties_add("java.ext.dirs", extdirs);
-
- /* Set the java.ext.endorsed property. */
-
- len = strlen(java_home) + strlen("/lib/endorsed") + strlen("0");
-
- endorseddirs = MNEW(char, len);
-
- sprintf(endorseddirs, "%s/lib/endorsed", java_home);
-
- properties_add("java.endorsed.dirs", endorseddirs);
-
-# else
-
-# error unknown classpath configuration
-
-# endif
-
-#elif defined(ENABLE_JAVAME_CLDC1_1)
-
- properties_add("microedition.configuration", "CLDC-1.1");
- properties_add("microedition.platform", "generic");
- properties_add("microedition.encoding", "ISO8859_1");
- properties_add("microedition.profiles", "");
-
-#else
-
-# error unknown Java configuration
-
-#endif
-}
-
-
-/* properties_add **************************************************************
-
- Adds a property entry to the internal property list. If there's
- already an entry with the same key, replace it.
-
-*******************************************************************************/
-
-void properties_add(const char *key, const char *value)
-{
- list_properties_entry_t *pe;
-
- /* search for the entry */
-
- for (pe = list_first(list_properties); pe != NULL;
- pe = list_next(list_properties, pe)) {
- if (strcmp(pe->key, key) == 0) {
- /* entry was found, replace the value */
-
-#if !defined(NDEBUG)
- if (opt_DebugProperties) {
- printf("[properties_add: key=%s, old value=%s, new value=%s]\n",
- key, pe->value, value);
- }
-#endif
-
- pe->value = value;
-
- return;
- }
- }
-
- /* entry was not found, insert a new one */
-
-#if !defined(NDEBUG)
- if (opt_DebugProperties) {
- printf("[properties_add: key=%s, value=%s]\n", key, value);
- }
-#endif
-
- pe = NEW(list_properties_entry_t);
-
- pe->key = key;
- pe->value = value;
-
- list_add_last(list_properties, pe);
-}
-
-
-/* properties_get **************************************************************
-
- Get a property entry from the internal property list.
-
-*******************************************************************************/
-
-const char *properties_get(const char *key)
-{
- list_properties_entry_t *pe;
-
- for (pe = list_first(list_properties); pe != NULL;
- pe = list_next(list_properties, pe)) {
- if (strcmp(pe->key, key) == 0)
- return pe->value;
- }
-
- return NULL;
-}
-
-
-/* properties_system_add *******************************************************
-
- Adds a given property to the Java system properties.
-
-*******************************************************************************/
-
-void properties_system_add(java_handle_t *p, const char *key, const char *value)
-{
- classinfo *c;
- methodinfo *m;
- java_handle_t *k;
- java_handle_t *v;
-
- /* search for method to add properties */
-
- LLNI_class_get(p, c);
-
- m = class_resolveclassmethod(c,
- utf_put,
- utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
- NULL,
- true);
-
- if (m == NULL)
- return;
-
- /* add to the Java system properties */
-
- k = javastring_new_from_utf_string(key);
- v = javastring_new_from_utf_string(value);
-
- (void) vm_call_method(m, p, k, v);
-}
-
-
-/* properties_system_add_all ***************************************************
-
- Adds all properties from the properties list to the Java system
- properties.
-
- ARGUMENTS:
- p.... is actually a java_util_Properties structure
-
-*******************************************************************************/
-
-#if defined(ENABLE_JAVASE)
-void properties_system_add_all(java_handle_t *p)
-{
- list_properties_entry_t *pe;
- classinfo *c;
- methodinfo *m;
- java_handle_t *key;
- java_handle_t *value;
-
- /* search for method to add properties */
-
- LLNI_class_get(p, c);
-
- m = class_resolveclassmethod(c,
- utf_put,
- utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
- NULL,
- true);
-
- if (m == NULL)
- return;
-
- /* process all properties stored in the internal table */
-
- for (pe = list_first(list_properties); pe != NULL;
- pe = list_next(list_properties, pe)) {
- /* add to the Java system properties */
-
- key = javastring_new_from_utf_string(pe->key);
- value = javastring_new_from_utf_string(pe->value);
-
- (void) vm_call_method(m, (java_handle_t *) p, key, value);
- }
-}
-#endif /* defined(ENABLE_JAVASE) */
-
-
-/* properties_dump *************************************************************
-
- Dump all property entries.
-
-*******************************************************************************/
-
-void properties_dump(void)
-{
- list_t *l;
- list_properties_entry_t *pe;
-
- /* For convenience. */
-
- l = list_properties;
-
- for (pe = list_first(l); pe != NULL; pe = list_next(l, pe)) {
- log_println("[properties_dump: key=%s, value=%s]", pe->key, pe->value);
- }
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
--- /dev/null
+/* src/vm/properties.cpp - handling commandline properties
+
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+
+#include "mm/memory.h"
+
+#include "native/llni.h"
+
+#include "toolbox/util.h"
+
+#include "vm/class.h"
+#include "vm/global.h"
+#include "vm/method.h"
+#include "vm/options.h"
+#include "vm/os.hpp"
+#include "vm/properties.hpp"
+#include "vm/string.hpp"
+#include "vm/vm.hpp"
+
+#include "vm/jit/asmpart.h"
+
+
+/**
+ * Constructor fills the properties list with default values.
+ */
+Properties::Properties()
+{
+ int len;
+ char *p;
+
+ char *boot_class_path;
+
+#if defined(ENABLE_JAVASE)
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ struct utsname *utsnamebuf;
+# endif
+#endif
+
+#if defined(ENABLE_JRE_LAYOUT)
+ /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
+
+ p = MNEW(char, 4096);
+
+ if (os::readlink("/proc/self/exe", p, 4095) == -1)
+ VM::get->current()->abort_errno("readlink failed");
+
+ /* We have a path like:
+
+ /path/to/executable/bin/java
+
+ or
+
+ /path/to/executeable/jre/bin/java
+
+ Now let's strip two levels. */
+
+ p = os::dirname(p);
+ p = os::dirname(p);
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+ /* Set java.home. */
+
+ const char* java_home = strdup(p);
+
+ /* Set the path to Java core native libraries. */
+
+ len = strlen(java_home) + strlen("/lib/classpath") + strlen("0");
+
+ const char* boot_library_path = MNEW(char, len);
+
+ strcpy(boot_library_path, java_home);
+ strcat(boot_library_path, "/lib/classpath");
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ /* Find correct java.home. We check if there is a JRE
+ co-located. */
+
+ /* NOTE: We use the server VM here as it should be available on
+ all architectures. */
+
+ len =
+ strlen(p) +
+ strlen("/jre/lib/"JAVA_ARCH"/server/libjvm.so") +
+ strlen("0");
+
+ const char* java_home = MNEW(char, len);
+
+ strcpy(java_home, p);
+ strcat(java_home, "/jre/lib/"JAVA_ARCH"/server/libjvm.so");
+
+ /* Check if that libjvm.so exists. */
+
+ if (os_access(java_home, F_OK) == 0) {
+ /* Yes, we add /jre to java.home. */
+
+ strcpy(java_home, p);
+ strcat(java_home, "/jre");
+ }
+ else {
+ /* No, java.home is parent directory. */
+
+ strcpy(java_home, p);
+ }
+
+ /* Set the path to Java core native libraries. */
+
+ len = strlen(java_home) + strlen("/lib/"JAVA_ARCH) + strlen("0");
+
+ const char* boot_library_path = MNEW(char, len);
+
+ strcpy(boot_library_path, java_home);
+ strcat(boot_library_path, "/lib/"JAVA_ARCH);
+
+# else
+# error unknown classpath configuration
+# endif
+
+ /* Free path. */
+
+ MFREE(p, char, len);
+
+#else
+ const char* java_home = CACAO_PREFIX;
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+ const char* boot_library_path = JAVA_RUNTIME_LIBRARY_LIBDIR"/classpath";
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ const char* boot_library_path = JAVA_RUNTIME_LIBRARY_LIBDIR;
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
+
+ // No boot_library_path required.
+
+# else
+# error unknown classpath configuration
+# endif
+#endif
+
+ put("java.home", java_home);
+
+ /* Set the bootclasspath. */
+
+ p = os::getenv("BOOTCLASSPATH");
+
+ if (p != NULL) {
+ boot_class_path = MNEW(char, strlen(p) + strlen("0"));
+ strcpy(boot_class_path, p);
+ }
+ else {
+#if defined(ENABLE_JRE_LAYOUT)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+ len =
+ strlen(java_home) + strlen("/share/cacao/vm.zip:") +
+ strlen(java_home) + strlen("/share/classpath/glibj.zip") +
+ strlen("0");
+
+ boot_class_path = MNEW(char, len);
+
+ strcpy(boot_class_path, java_home);
+ strcat(boot_class_path, "/share/cacao/vm.zip");
+ strcat(boot_class_path, ":");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/share/classpath/glibj.zip");
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ /* This is the bootclasspath taken from HotSpot (see
+ hotspot/src/share/vm/runtime/os.cpp
+ (os::set_boot_path)). */
+
+ len =
+ strlen(java_home) + strlen("/lib/resources.jar:") +
+ strlen(java_home) + strlen("/lib/rt.jar:") +
+ strlen(java_home) + strlen("/lib/sunrsasign.jar:") +
+ strlen(java_home) + strlen("/lib/jsse.jar:") +
+ strlen(java_home) + strlen("/lib/jce.jar:") +
+ strlen(java_home) + strlen("/lib/charsets.jar:") +
+ strlen(java_home) + strlen("/classes") +
+ strlen("0");
+
+ boot_class_path = MNEW(char, len);
+
+ strcpy(boot_class_path, java_home);
+ strcat(boot_class_path, "/lib/resources.jar:");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/lib/rt.jar:");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/lib/sunrsasign.jar:");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/lib/jsse.jar:");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/lib/jce.jar:");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/lib/charsets.jar:");
+ strcat(boot_class_path, java_home);
+ strcat(boot_class_path, "/classes");
+
+# else
+# error unknown classpath configuration
+# endif
+#else
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+ len =
+ strlen(CACAO_VM_ZIP) +
+ strlen(":") +
+ strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
+ strlen("0");
+
+ boot_class_path = MNEW(char, len);
+
+ strcpy(boot_class_path, CACAO_VM_ZIP);
+ strcat(boot_class_path, ":");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_CLASSES);
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ /* This is the bootclasspath taken from HotSpot (see
+ hotspot/src/share/vm/runtime/os.cpp
+ (os::set_boot_path)). */
+
+ len =
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/resources.jar:") +
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/rt.jar:") +
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/sunrsasign.jar:") +
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jsse.jar:") +
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jce.jar:") +
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/lib/charsets.jar:") +
+ strlen(JAVA_RUNTIME_LIBRARY_PREFIX"/classes") +
+ strlen("0");
+
+ boot_class_path = MNEW(char, len);
+
+ strcpy(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/resources.jar:");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/rt.jar:");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/sunrsasign.jar:");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jsse.jar:");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/jce.jar:");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/lib/charsets.jar:");
+ strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_PREFIX"/classes");
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
+
+ len =
+ strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
+ strlen("0");
+
+ boot_class_path = MNEW(char, len);
+
+ strcpy(boot_class_path, JAVA_RUNTIME_LIBRARY_CLASSES);
+
+# else
+# error unknown classpath configuration
+# endif
+#endif
+ }
+
+ put("sun.boot.class.path", boot_class_path);
+ put("java.boot.class.path", boot_class_path);
+
+#if defined(ENABLE_JAVASE)
+
+ /* Set the classpath. */
+
+ p = os::getenv("CLASSPATH");
+
+ char* class_path;
+
+ if (p != NULL) {
+ class_path = MNEW(char, strlen(p) + strlen("0"));
+ strcpy(class_path, p);
+ }
+ else {
+ class_path = MNEW(char, strlen(".") + strlen("0"));
+ strcpy(class_path, ".");
+ }
+
+ put("java.class.path", class_path);
+
+ // Add java.vm properties.
+ put("java.vm.specification.version", "1.0");
+ put("java.vm.specification.vendor", "Sun Microsystems Inc.");
+ put("java.vm.specification.name", "Java Virtual Machine Specification");
+ put("java.vm.version", VERSION);
+ put("java.vm.vendor", "CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
+ put("java.vm.name", "CACAO");
+
+# if defined(ENABLE_INTRP)
+ if (opt_intrp) {
+ /* XXX We don't support java.lang.Compiler */
+/* put("java.compiler", "cacao.intrp"); */
+ put("java.vm.info", "interpreted mode");
+ }
+ else
+# endif
+ {
+ /* XXX We don't support java.lang.Compiler */
+/* put("java.compiler", "cacao.jit"); */
+ put("java.vm.info", "JIT mode");
+ }
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+ /* Get properties from system. */
+
+ char* cwd = _Jv_getcwd();
+
+ char* env_user = os::getenv("USER");
+ char* env_home = os::getenv("HOME");
+ char* env_lang = os::getenv("LANG");
+
+ utsnamebuf = NEW(struct utsname);
+
+ uname(utsnamebuf);
+
+ put("java.runtime.version", VERSION);
+ put("java.runtime.name", "CACAO");
+
+ put("java.specification.version", "1.5");
+ put("java.specification.vendor", "Sun Microsystems Inc.");
+ put("java.specification.name", "Java Platform API Specification");
+
+ put("java.version", JAVA_VERSION);
+ put("java.vendor", "GNU Classpath");
+ put("java.vendor.url", "http://www.gnu.org/software/classpath/");
+
+ put("java.class.version", CLASS_VERSION);
+
+ put("gnu.classpath.boot.library.path", boot_library_path);
+
+ // Get and set java.library.path.
+ const char* java_library_path = os::getenv("LD_LIBRARY_PATH");
+
+ if (java_library_path == NULL)
+ java_library_path = "";
+
+ put("java.library.path", java_library_path);
+
+ put("java.io.tmpdir", "/tmp");
+
+# if defined(ENABLE_INTRP)
+ if (opt_intrp) {
+ put("gnu.java.compiler.name", "cacao.intrp");
+ }
+ else
+# endif
+ {
+ put("gnu.java.compiler.name", "cacao.jit");
+ }
+
+ /* Set the java.ext.dirs property. */
+
+ len = strlen(java_home) + strlen("/jre/lib/ext") + strlen("0");
+
+ char* extdirs = MNEW(char, len);
+
+ sprintf(extdirs, "%s/jre/lib/ext", java_home);
+
+ put("java.ext.dirs", extdirs);
+
+ /* Set the java.ext.endorsed property. */
+
+ len = strlen(java_home) + strlen("/jre/lib/endorsed") + strlen("0");
+
+ char* endorseddirs = MNEW(char, len);
+
+ sprintf(endorseddirs, "%s/jre/lib/endorsed", java_home);
+
+ put("java.endorsed.dirs", endorseddirs);
+
+# if defined(DISABLE_GC)
+ /* When we disable the GC, we mmap the whole heap to a specific
+ address, so we can compare call traces. For this reason we have
+ to add the same properties on different machines, otherwise
+ more memory may be allocated (e.g. strlen("i386")
+ vs. strlen("alpha"). */
+
+ put("os.arch", "unknown");
+ put("os.name", "unknown");
+ put("os.version", "unknown");
+# else
+ put("os.arch", JAVA_ARCH);
+ put("os.name", utsnamebuf->sysname);
+ put("os.version", utsnamebuf->release);
+# endif
+
+# if WORDS_BIGENDIAN == 1
+ put("gnu.cpu.endian", "big");
+# else
+ put("gnu.cpu.endian", "little");
+# endif
+
+ put("file.separator", "/");
+ put("path.separator", ":");
+ put("line.separator", "\n");
+
+ put("user.name", env_user ? env_user : "null");
+ put("user.home", env_home ? env_home : "null");
+ put("user.dir", cwd ? cwd : "null");
+
+ /* get locale */
+
+ if (env_lang != NULL) {
+ /* get the local stuff from the environment */
+
+ if (strlen(env_lang) <= 2) {
+ put("user.language", env_lang);
+ }
+ else {
+ if ((env_lang[2] == '_') && (strlen(env_lang) >= 5)) {
+ char* lang = MNEW(char, 3);
+ strncpy(lang, (char*) &env_lang[0], 2);
+ lang[2] = '\0';
+
+ char* country = MNEW(char, 3);
+ strncpy(country, (char*) &env_lang[3], 2);
+ country[2] = '\0';
+
+ put("user.language", lang);
+ put("user.country", country);
+ }
+ }
+ }
+ else {
+ /* if no default locale was specified, use `en_US' */
+
+ put("user.language", "en");
+ put("user.country", "US");
+ }
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ /* Actually this property is set by OpenJDK, but we need it in
+ nativevm_preinit(). */
+
+ put("sun.boot.library.path", boot_library_path);
+
+ // Set the java.ext.dirs property.
+ len =
+ strlen(java_home) + strlen("/lib/ext") +
+ strlen(":") +
+ strlen("/usr/java/packages/lib/ext") +
+ strlen("0");
+
+ char* extdirs = MNEW(char, len);
+
+ sprintf(extdirs, "%s/lib/ext:/usr/java/packages/lib/ext", java_home);
+
+ put("java.ext.dirs", extdirs);
+
+ // Set the java.ext.endorsed property.
+ len = strlen(java_home) + strlen("/lib/endorsed") + strlen("0");
+
+ char* endorseddirs = MNEW(char, len);
+
+ sprintf(endorseddirs, "%s/lib/endorsed", java_home);
+
+ put("java.endorsed.dirs", endorseddirs);
+
+# else
+
+# error unknown classpath configuration
+
+# endif
+
+#elif defined(ENABLE_JAVAME_CLDC1_1)
+
+ put("microedition.configuration", "CLDC-1.1");
+ put("microedition.platform", "generic");
+ put("microedition.encoding", "ISO8859_1");
+ put("microedition.profiles", "");
+
+#else
+
+# error unknown Java configuration
+
+#endif
+}
+
+
+/**
+ * Add the given property to the given Java system properties.
+ *
+ * @param p Java properties object.
+ * @param key Key.
+ * @param value Value.
+ */
+void Properties::put(java_handle_t* p, const char* key, const char* value)
+{
+ // Get Properties.put() method to add properties.
+ classinfo* c;
+ LLNI_class_get(p, c);
+
+ methodinfo* m = class_resolveclassmethod(c,
+ utf_put,
+ utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
+ NULL,
+ true);
+
+ if (m == NULL)
+ return;
+
+ // Add to the Java system properties.
+ java_handle_t* k = javastring_new_from_utf_string(key);
+ java_handle_t* v = javastring_new_from_utf_string(value);
+
+ (void) vm_call_method(m, p, k, v);
+}
+
+
+/**
+ * Put the given property into the internal property map. If there's
+ * already an entry with the same key, replace it.
+ *
+ * @param key Key.
+ * @param value Value.
+ */
+void Properties::put(const char* key, const char* value)
+{
+ // Try to find the key.
+ std::map<const char*, const char*>::iterator it = _properties.find(key);
+
+ // The key is already in the map.
+ if (it != _properties.end()) {
+#if !defined(NDEBUG)
+ if (opt_DebugProperties) {
+ printf("[Properties::put: key=%s, old value=%s, new value=%s]\n",
+ key, it->second, value);
+ }
+#endif
+
+ // Replace the value in the current entry.
+ it->second = value;
+
+ return;
+ }
+
+ // The key was not found, insert the pair.
+#if !defined(NDEBUG)
+ if (opt_DebugProperties) {
+ printf("[Properties::put: key=%s, value=%s]\n", key, value);
+ }
+#endif
+
+ _properties.insert(std::make_pair(key, value));
+}
+
+
+/**
+ * Get a property entry from the internal property map.
+ *
+ * @param key Key.
+ *
+ * @return Value associated with the key or NULL when not found.
+ */
+const char* Properties::get(const char* key)
+{
+ // Try to find the key.
+ std::map<const char*, const char*>::iterator it = _properties.find(key);
+
+ // The key is not in the map.
+ if (it == _properties.end())
+ return NULL;
+
+ // Return the value.
+ return it->second;
+}
+
+
+/**
+ * Fill the given Java system properties with all properties from the
+ * internal properties map.
+ *
+ * @param p Java Properties object.
+ */
+#if defined(ENABLE_JAVASE)
+void Properties::fill(java_handle_t* p)
+{
+ // Get Properties.put() method to add properties.
+ classinfo* c;
+ LLNI_class_get(p, c);
+
+ methodinfo* m = class_resolveclassmethod(c,
+ utf_put,
+ utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
+ NULL,
+ true);
+
+ if (m == NULL)
+ return;
+
+ // Iterator over all properties.
+ for (std::map<const char*, const char*>::iterator it = _properties.begin(); it != _properties.end(); it++) {
+ // Put into the Java system properties.
+ java_handle_t* key = javastring_new_from_utf_string(it->first);
+ java_handle_t* value = javastring_new_from_utf_string(it->second);
+
+ (void) vm_call_method(m, p, key, value);
+ }
+}
+#endif
+
+
+/**
+ * Dump all property entries.
+ */
+#if !defined(NDEBUG)
+void Properties::dump()
+{
+ for (std::map<const char*, const char*>::iterator it = _properties.begin(); it != _properties.end(); it++) {
+ log_println("[Properties::dump: key=%s, value=%s]", it->first, it->second);
+ }
+}
+#endif
+
+
+// Legacy C interface.
+extern "C" {
+ void Properties_put(const char *key, const char *value) { VM::get_current()->get_properties().put(key, value); }
+ const char *Properties_get(const char *key) { return VM::get_current()->get_properties().get(key); }
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
+++ /dev/null
-/* src/vm/properties.h - handling commandline properties
-
- Copyright (C) 1996-2005, 2006, 2007, 2008
- CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
-*/
-
-
-#ifndef _PROPERTIES_H
-#define _PROPERTIES_H
-
-#include "config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdint.h>
-
-#include "vm/global.h"
-
-
-/* function prototypes ********************************************************/
-
-void properties_init(void);
-void properties_set(void);
-
-void properties_add(const char *key, const char *value);
-const char *properties_get(const char *key);
-
-void properties_system_add(java_handle_t *p, const char *key, const char *value);
-
-#if defined(ENABLE_JAVASE)
-void properties_system_add_all(java_handle_t *p);
-#endif
-
-void properties_dump(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _PROPERTIES_H */
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- */
--- /dev/null
+/* src/vm/properties.hpp - handling commandline properties
+
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _PROPERTIES_HPP
+#define _PROPERTIES_HPP
+
+#include "config.h"
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+
+#include <map>
+
+#include "vm/os.hpp"
+
+
+class ltstr {
+public:
+ bool operator()(const char* s1, const char* s2) const
+ {
+ return os::strcmp(s1, s2) < 0;
+ }
+};
+
+
+/**
+ * Commandline properties.
+ */
+class Properties {
+private:
+ std::map<const char*, const char*, ltstr> _properties;
+
+public:
+ Properties();
+
+ // Static function.
+ void put(java_handle_t* p, const char* key, const char* value);
+
+ void put(const char* key, const char* value);
+ const char* get(const char* key);
+ void fill(java_handle_t* p);
+#if !defined(NDEBUG)
+ void dump();
+#endif
+};
+
+#else
+
+typedef struct Properties Properties;
+
+void Properties_put(const char *key, const char *value);
+const char *Properties_get(const char *key);
+
+#endif
+
+#endif // _PROPERTIES_HPP
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
#include "vm/loader.hpp"
#include "vm/options.h"
#include "vm/os.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/suck.h"
#include "vm/vm.hpp"
#include "vm/zip.h"
/* get the property value */
- value = properties_get(key);
+ value = Properties_get(key);
if (value == NULL)
return;
/* Allocate memory for bootclasspath. */
// FIXME Make boot_class_path const char*.
- boot_class_path = (char*) properties_get("sun.boot.class.path");
+ boot_class_path = (char*) Properties_get("sun.boot.class.path");
p = MNEW(char,
pathlen + strlen("/") + namlen +
strcat(p, ":");
strcat(p, boot_class_path);
- properties_add("sun.boot.class.path", p);
- properties_add("java.boot.class.path", p);
+ Properties_put("sun.boot.class.path", p);
+ Properties_put("java.boot.class.path", p);
MFREE(boot_class_path, char, strlen(boot_class_path));
#include "vm/options.h"
#include "vm/os.hpp"
#include "vm/primitive.hpp"
-#include "vm/properties.h"
+#include "vm/properties.hpp"
#include "vm/signallocal.h"
#include "vm/statistics.h"
#include "vm/string.hpp"
opt_heapstartsize = HEAP_STARTSIZE;
opt_stacksize = STACK_SIZE;
- /* Initialize the properties list before command-line handling.
- Otherwise -XX:+PrintConfig crashes. */
-
- properties_init();
-
// First of all, parse the -XX options.
#if defined(ENABLE_VMLOG)
jvmti = false;
#endif
- /* Fill the properties before command-line handling. */
-
- properties_set();
-
/* iterate over all passed options */
while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
classpath. */
// FIXME Make class_path const char*.
- class_path = (char*) properties_get("java.class.path");
+ class_path = (char*) _properties.get("java.class.path");
p = MNEW(char, strlen(opt_arg) + strlen("0"));
strcpy(p, opt_arg);
#if defined(ENABLE_JAVASE)
- properties_add("java.class.path", p);
+ _properties.put("java.class.path", p);
#endif
MFREE(class_path, char, strlen(class_path));
for (unsigned int i = 0; i < strlen(opt_arg); i++) {
if (opt_arg[i] == '=') {
opt_arg[i] = '\0';
- properties_add(opt_arg, opt_arg + i + 1);
+ _properties.put(opt_arg, opt_arg + i + 1);
goto opt_d_done;
}
}
/* if no '=' is given, just create an empty property */
- properties_add(opt_arg, "");
+ _properties.put(opt_arg, "");
opt_d_done:
break;
new boot classpath. */
// FIXME Make boot_class_path const char*.
- boot_class_path = (char*) properties_get("sun.boot.class.path");
+ boot_class_path = (char*) _properties.get("sun.boot.class.path");
p = MNEW(char, strlen(opt_arg) + strlen("0"));
strcpy(p, opt_arg);
- properties_add("sun.boot.class.path", p);
- properties_add("java.boot.class.path", p);
+ _properties.put("sun.boot.class.path", p);
+ _properties.put("java.boot.class.path", p);
MFREE(boot_class_path, char, strlen(boot_class_path));
break;
/* Append to bootclasspath. */
// FIXME Make boot_class_path const char*.
- boot_class_path = (char*) properties_get("sun.boot.class.path");
+ boot_class_path = (char*) _properties.get("sun.boot.class.path");
len = strlen(boot_class_path);
strcat(p, ":");
strcat(p, opt_arg);
- properties_add("sun.boot.class.path", p);
- properties_add("java.boot.class.path", p);
+ _properties.put("sun.boot.class.path", p);
+ _properties.put("java.boot.class.path", p);
break;
case OPT_BOOTCLASSPATH_P:
/* Prepend to bootclasspath. */
// FIXME Make boot_class_path const char*.
- boot_class_path = (char*) properties_get("sun.boot.class.path");
+ boot_class_path = (char*) _properties.get("sun.boot.class.path");
len = strlen(boot_class_path);
strcat(p, ":");
strcat(p, boot_class_path);
- properties_add("sun.boot.class.path", p);
- properties_add("java.boot.class.path", p);
+ _properties.put("sun.boot.class.path", p);
+ _properties.put("java.boot.class.path", p);
MFREE(boot_class_path, char, len);
break;
classes. */
// FIXME Make boot_class_path const char*.
- boot_class_path = (char*) properties_get("sun.boot.class.path");
+ boot_class_path = (char*) _properties.get("sun.boot.class.path");
len =
strlen(CACAO_VM_ZIP) +
strcat(p, ":");
strcat(p, opt_arg);
- properties_add("sun.boot.class.path", p);
- properties_add("java.boot.class.path", p);
+ _properties.put("sun.boot.class.path", p);
+ _properties.put("java.boot.class.path", p);
MFREE(boot_class_path, char, strlen(boot_class_path));
break;
/* AFTER: utf8_init */
// FIXME Make boot_class_path const char*.
- boot_class_path = (char*) properties_get("sun.boot.class.path");
+ boot_class_path = (char*) _properties.get("sun.boot.class.path");
suck_add(boot_class_path);
/* initialize the classcache hashtable stuff: lock, hashtable
/**
* Print run-time VM configuration.
*/
-void VM::print_run_time_config(void)
+void VM::print_run_time_config()
{
puts("Run-time variables:\n");
printf(" maximum heap size : %d\n", opt_heapmaxsize);
printf(" stack size : %d\n", opt_stacksize);
#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
+ printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
+ printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
#endif
- printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
- printf(" java.class.path : %s\n", properties_get("java.class.path"));
+ printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
+ printf(" java.class.path : %s\n", _properties.get("java.class.path"));
puts("");
}
strcpy(p, mainname);
#if defined(ENABLE_JAVASE)
- properties_add("java.class.path", p);
+ VM::get_current()->get_properties().put("java.class.path", p);
#endif
}
else {
// We need the JNI types for the VM class.
#include "native/jni.hpp"
+#include "vm/properties.hpp"
+
+
#ifdef __cplusplus
/**
bool _exiting;
int64_t _starttime;
+ // Subsystems.
+ Properties _properties; ///< Commandline properties.
+
public:
// Constructor, Destructor.
VM(JavaVMInitArgs*);
// Static methods.
static bool create(JavaVM** p_vm, void** p_env, void* vm_args);
static VM* get_current() { return _vm; }
+
static void print_build_time_config();
- static void print_run_time_config();
+ void print_run_time_config();
// Getters for private members.
JavaVM* get_javavm() { return _javavm; }
bool is_exiting() { return _exiting; }
int64_t get_starttime() { return _starttime; }
+ Properties& get_properties() { return _properties; }
+
// Instance functions.
void abort(const char* text, ...);
void abort_errnum(int errnum, const char* text, ...);