This commit introduces C++ wrapper classes for Java heap objects.
[cacao.git] / src / vm / properties.c
index 5902ce28370703d07b9f0b5890a688e75b9bc408..599e05879ea0bb81a5ec30eef945aac3825c5417 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 
+#include <stdint.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/utsname.h>
 
-#include "vm/types.h"
-
 #include "mm/memory.h"
 
 #include "native/jni.h"
 #include "native/llni.h"
 
-#include "vm/global.h"                      /* required by java_lang_String.h */
-#include "native/include/java_lang_String.h"
-
 #include "toolbox/list.h"
 #include "toolbox/util.h"
 
+#include "vm/global.h"
 #include "vm/properties.h"
-#include "vm/stringlocal.h"
-#include "vm/vm.h"
+#include "vm/string.hpp"
+#include "vm/vm.hpp"
 
 #include "vm/jit/asmpart.h"
 
 #include "vmcore/class.h"
 #include "vmcore/method.h"
 #include "vmcore/options.h"
-#include "vmcore/system.h"
+#include "vmcore/os.hpp"
 
 
 /* internal property structure ************************************************/
@@ -62,8 +59,8 @@
 typedef struct list_properties_entry_t list_properties_entry_t;
 
 struct list_properties_entry_t {
-       char       *key;
-       char       *value;
+       const char* key;
+       const char* value;
        listnode_t  linkage;
 };
 
@@ -82,6 +79,8 @@ static list_t *list_properties = NULL;
 
 void properties_init(void)
 {
+       TRACESUBSYSTEMINITIALIZATION("properties_init");
+
        list_properties = list_create(OFFSET(list_properties_entry_t, linkage));
 }
 
@@ -106,7 +105,7 @@ void properties_set(void)
        char           *extdirs;
        char           *endorseddirs;
 
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
        char           *cwd;
        char           *env_user;
        char           *env_home;
@@ -119,7 +118,7 @@ void properties_set(void)
 # endif
 #endif
 
-#if defined(WITH_JRE_LAYOUT)
+#if defined(ENABLE_JRE_LAYOUT)
        /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
 
        p = MNEW(char, 4096);
@@ -137,10 +136,10 @@ void properties_set(void)
 
           Now let's strip two levels. */
 
-       p = system_dirname(p);
-       p = system_dirname(p);
+       p = os_dirname(p);
+       p = os_dirname(p);
 
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
 
        /* Set java.home. */
 
@@ -155,7 +154,7 @@ void properties_set(void)
        strcpy(boot_library_path, java_home);
        strcat(boot_library_path, "/lib/classpath");
 
-# elif defined(WITH_CLASSPATH_SUN)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
 
        /* Find correct java.home.  We check if there is a JRE
           co-located. */
@@ -175,7 +174,7 @@ void properties_set(void)
 
        /* Check if that libjvm.so exists. */
 
-       if (access(java_home, F_OK) == 0) {
+       if (os_access(java_home, F_OK) == 0) {
                /* Yes, we add /jre to java.home. */
 
                strcpy(java_home, p);
@@ -207,15 +206,15 @@ void properties_set(void)
 #else
        java_home         = CACAO_PREFIX;
 
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
 
-       boot_library_path = CLASSPATH_LIBDIR"/classpath";
+       boot_library_path = JAVA_RUNTIME_LIBRARY_LIBDIR"/classpath";
 
-# elif defined(WITH_CLASSPATH_SUN)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
 
-       boot_library_path = CLASSPATH_LIBDIR;
+       boot_library_path = JAVA_RUNTIME_LIBRARY_LIBDIR;
 
-# elif defined(WITH_CLASSPATH_CLDC1_1)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
 
        /* No boot_library_path required. */
 
@@ -235,8 +234,8 @@ void properties_set(void)
                strcpy(boot_class_path, p);
        }
        else {
-#if defined(WITH_JRE_LAYOUT)
-# if defined(WITH_CLASSPATH_GNU)
+#if defined(ENABLE_JRE_LAYOUT)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
 
                len =
                        strlen(java_home) + strlen("/share/cacao/vm.zip:") +
@@ -251,7 +250,7 @@ void properties_set(void)
                strcat(boot_class_path, java_home);
                strcat(boot_class_path, "/share/classpath/glibj.zip");
 
-# elif defined(WITH_CLASSPATH_SUN)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
 
                /* This is the bootclasspath taken from HotSpot (see
                   hotspot/src/share/vm/runtime/os.cpp
@@ -288,55 +287,55 @@ void properties_set(void)
 #  error unknown classpath configuration
 # endif
 #else
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
 
                len =
                        strlen(CACAO_VM_ZIP) +
                        strlen(":") +
-                       strlen(CLASSPATH_CLASSES) +
+                       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, CLASSPATH_CLASSES);
+               strcat(boot_class_path, JAVA_RUNTIME_LIBRARY_CLASSES);
 
-# elif defined(WITH_CLASSPATH_SUN)
+# 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(CLASSPATH_PREFIX"/lib/resources.jar:") +
-                       strlen(CLASSPATH_PREFIX"/lib/rt.jar:") +
-                       strlen(CLASSPATH_PREFIX"/lib/sunrsasign.jar:") +
-                       strlen(CLASSPATH_PREFIX"/lib/jsse.jar:") +
-                       strlen(CLASSPATH_PREFIX"/lib/jce.jar:") +
-                       strlen(CLASSPATH_PREFIX"/lib/charsets.jar:") +
-                       strlen(CLASSPATH_PREFIX"/classes") +
+                       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, CLASSPATH_PREFIX"/lib/resources.jar:");
-               strcat(boot_class_path, CLASSPATH_PREFIX"/lib/rt.jar:");
-               strcat(boot_class_path, CLASSPATH_PREFIX"/lib/sunrsasign.jar:");
-               strcat(boot_class_path, CLASSPATH_PREFIX"/lib/jsse.jar:");
-               strcat(boot_class_path, CLASSPATH_PREFIX"/lib/jce.jar:");
-               strcat(boot_class_path, CLASSPATH_PREFIX"/lib/charsets.jar:");
-               strcat(boot_class_path, CLASSPATH_PREFIX"/classes");
+               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_CLASSPATH_CLDC1_1)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
 
                len =
-                       strlen(CLASSPATH_CLASSES) +
+                       strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
                        strlen("0");
 
                boot_class_path = MNEW(char, len);
 
-               strcpy(boot_class_path, CLASSPATH_CLASSES);
+               strcpy(boot_class_path, JAVA_RUNTIME_LIBRARY_CLASSES);
 
 # else
 #  error unknown classpath configuration
@@ -370,7 +369,7 @@ void properties_set(void)
        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", "CACAO Team");
+       properties_add("java.vm.vendor", "CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
        properties_add("java.vm.name", "CACAO");
 
 # if defined(ENABLE_INTRP)
@@ -387,7 +386,7 @@ void properties_set(void)
                properties_add("java.vm.info", "JIT mode");
        }
 
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
 
        /* Get properties from system. */
 
@@ -517,7 +516,7 @@ void properties_set(void)
                properties_add("user.country", "US");
        }
 
-# elif defined(WITH_CLASSPATH_SUN)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
 
        /* Actually this property is set by OpenJDK, but we need it in
           nativevm_preinit(). */
@@ -576,14 +575,14 @@ void properties_set(void)
 
 *******************************************************************************/
 
-void properties_add(char *key, char *value)
+void properties_add(const char *key, const char *value)
 {
        list_properties_entry_t *pe;
 
        /* search for the entry */
 
-       for (pe = list_first_unsynced(list_properties); pe != NULL;
-                pe = list_next_unsynced(list_properties, pe)) {
+       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 */
 
@@ -613,7 +612,7 @@ void properties_add(char *key, char *value)
        pe->key   = key;
        pe->value = value;
 
-       list_add_last_unsynced(list_properties, pe);
+       list_add_last(list_properties, pe);
 }
 
 
@@ -623,12 +622,12 @@ void properties_add(char *key, char *value)
 
 *******************************************************************************/
 
-char *properties_get(char *key)
+const char *properties_get(const char *key)
 {
        list_properties_entry_t *pe;
 
-       for (pe = list_first_unsynced(list_properties); pe != NULL;
-                pe = list_next_unsynced(list_properties, pe)) {
+       for (pe = list_first(list_properties); pe != NULL;
+                pe = list_next(list_properties, pe)) {
                if (strcmp(pe->key, key) == 0)
                        return pe->value;
        }
@@ -643,7 +642,7 @@ char *properties_get(char *key)
 
 *******************************************************************************/
 
-void properties_system_add(java_handle_t *p, char *key, char *value)
+void properties_system_add(java_handle_t *p, const char *key, const char *value)
 {
        classinfo     *c;
        methodinfo    *m;
@@ -730,10 +729,11 @@ void properties_dump(void)
        list_t                  *l;
        list_properties_entry_t *pe;
 
+       /* For convenience. */
+
        l = list_properties;
 
-       for (pe = list_first_unsynced(l); pe != NULL;
-                pe = list_next_unsynced(l, pe)) {
+       for (pe = list_first(l); pe != NULL; pe = list_next(l, pe)) {
                log_println("[properties_dump: key=%s, value=%s]", pe->key, pe->value);
        }
 }