* src/cacaoh/dummy.c (package_add): New function.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Sun, 16 Sep 2007 16:47:08 +0000 (18:47 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Sun, 16 Sep 2007 16:47:08 +0000 (18:47 +0200)
* src/native/vm/sun/jvm.c (vm/package.h): Added.
(JVM_GetSystemPackage): Implemented.

* src/vm/Makefile.am (libvm_la_SOURCES): Added package.[ch].

* src/vm/package.c: New file.
* src/vm/package.h: Likewise.

* src/vm/vm.c (vm/package.h): Added.
(vm_create): Call package_init.

* src/vmcore/loader.c (vm/package.h): Added.
(load_class_bootstrap): Call package_add.

* src/vmcore/options.c (opt_DebugPackage): Added.
(options_xx): Likewise.
* src/vmcore/options.h (opt_DebugPackage): Added.

src/cacaoh/dummy.c
src/native/vm/sun/jvm.c
src/vm/Makefile.am
src/vm/package.c [new file with mode: 0644]
src/vm/package.h [new file with mode: 0644]
src/vm/vm.c
src/vmcore/loader.c
src/vmcore/options.c
src/vmcore/options.h

index 16e9b3a825d106e9eb53119578571703c80ccf06..8cc3009322d0deb0bb4ecfd364d77884cc58c7e4 100644 (file)
@@ -573,6 +573,15 @@ int32_t dump_size(void)
 }
 
 
+/* package ********************************************************************/
+
+/* void package_add(java_handle_t *packagename) */
+void package_add(utf *packagename)
+{
+       /* Do nothing. */
+}
+
+
 /* primitive ******************************************************************/
 
 classinfo *primitive_arrayclass_get_by_type(int type)
index c76c0cfae219b047ca1314e337ad0ca0664ac053..92f7703763caa26ae73a181902dc9d90f5e2d492 100644 (file)
@@ -91,6 +91,7 @@
 #include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/initialize.h"
+#include "vm/package.h"
 #include "vm/primitive.h"
 #include "vm/properties.h"
 #include "vm/resolve.h"
@@ -2207,11 +2208,21 @@ jint JVM_ClassLoaderDepth(JNIEnv *env)
 
 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
 {
-       log_println("JVM_GetSystemPackage(env=%p, name=%p)");
-       javastring_print((java_handle_t *) name);
-       printf("\n");
+       java_handle_t *s;
+       utf *u;
+       utf *result;
 
-       return NULL;
+       TRACEJVMCALLS("JVM_GetSystemPackage(env=%p, name=%p)", env, name);
+
+/*     s = package_find(name); */
+       u = javastring_toutf(name, false);
+       result = package_find(u);
+       if (result != NULL)
+               s = javastring_new(result);
+       else
+               s = NULL;
+
+       return (jstring) s;
 }
 
 
index 34cdc2a2cceb332bcb0fbead6721eb69d5d193d8..bdc79e4f8426bc0833e0ea80d2aa1d6f401bc296 100644 (file)
@@ -59,6 +59,8 @@ libvm_la_SOURCES = \
        initialize.c \
        initialize.h \
        jit_interface.h \
+       package.c \
+       package.h \
        primitive.c \
        primitive.h \
        properties.c \
diff --git a/src/vm/package.c b/src/vm/package.c
new file mode 100644 (file)
index 0000000..88e532c
--- /dev/null
@@ -0,0 +1,170 @@
+/* src/vm/package.c - Java boot-package functions
+
+   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
+
+   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 "toolbox/list.h"
+
+#include "mm/memory.h"
+
+#include "native/jni.h"
+
+#include "native/include/java_lang_String.h"
+
+#include "vm/package.h"
+#include "vm/stringlocal.h"
+
+#include "vmcore/options.h"
+#include "vmcore/utf8.h"
+
+
+/* internal property structure ************************************************/
+
+typedef struct list_package_entry_t list_package_entry_t;
+
+struct list_package_entry_t {
+/*     java_string_t *packagename; */
+       utf           *packagename;
+       listnode_t     linkage;
+};
+
+
+/* global variables ***********************************************************/
+
+static list_t *list_package = NULL;
+
+
+/* package_init ****************************************************************
+
+   Initialize the package list.
+
+*******************************************************************************/
+
+void package_init(void)
+{
+       /* create the properties list */
+
+       list_package = list_create(OFFSET(list_package_entry_t, linkage));
+}
+
+
+/* package_add *****************************************************************
+
+   Add a package to the boot-package list.
+
+   IN:
+       packagename....package name as Java string
+
+*******************************************************************************/
+
+/* void package_add(java_handle_t *packagename) */
+void package_add(utf *packagename)
+{
+/*     java_string_t        *s; */
+       list_package_entry_t *lpe;
+
+       /* Intern the Java string to get a unique address. */
+
+/*     s = javastring_intern(packagename); */
+
+       /* Check if the package is already stored. */
+
+       if (package_find(packagename) != NULL)
+               return;
+
+       /* Add the package. */
+
+#if !defined(NDEBUG)
+       if (opt_DebugPackage) {
+               log_start();
+               log_print("[package_add: packagename=");
+               utf_display_printable_ascii(packagename);
+               log_print("]");
+               log_finish();
+       }
+#endif
+
+       lpe = NEW(list_package_entry_t);
+
+       lpe->packagename = packagename;
+
+       list_add_last(list_package, lpe);
+}
+
+
+/* package_find ****************************************************************
+
+   Find a package in the list.
+
+   IN:
+       packagename....package name as Java string
+
+   OUT:
+       package name as Java string
+
+*******************************************************************************/
+
+/* java_handle_t *package_find(java_handle_t *packagename) */
+utf *package_find(utf *packagename)
+{
+/*     java_string_t        *s; */
+       list_t               *l;
+       list_package_entry_t *lpe;
+
+       /* Intern the Java string to get a unique address. */
+
+/*     s = javastring_intern(packagename); */
+
+       /* For convenience. */
+
+       l = list_package;
+
+       for (lpe = list_first(l); lpe != NULL; lpe = list_next(l, lpe)) {
+/*             if (lpe->packagename == s) */
+               if (lpe->packagename == packagename)
+                       return lpe->packagename;
+       }
+
+       return NULL;
+}
+
+
+/*
+ * 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:
+ */
diff --git a/src/vm/package.h b/src/vm/package.h
new file mode 100644 (file)
index 0000000..95fcd54
--- /dev/null
@@ -0,0 +1,64 @@
+/* src/vm/package.c - Java boot-package functions
+
+   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
+
+   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 _VM_PACKAGE_H
+#define _VM_PACKAGE_H
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/jni.h"
+
+#include "vm/global.h"
+
+
+/* function prototypes ********************************************************/
+
+void           package_init(void);
+
+/* void           package_add(java_handle_t *packagename); */
+void           package_add(utf *packagename);
+/* java_handle_t *package_find(java_handle_t *packagename); */
+utf           *package_find(utf *packagename);
+
+#endif /* _VM_PACKAGE_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:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
index 24c239b59748cf34fd3ce293991dcca79d79d50e..991ee4a4ad0c6383be0158f482e1d58e5deeab1c 100644 (file)
@@ -67,6 +67,7 @@
 #include "vm/finalizer.h"
 #include "vm/global.h"
 #include "vm/initialize.h"
+#include "vm/package.h"
 #include "vm/primitive.h"
 #include "vm/properties.h"
 #include "vm/signallocal.h"
@@ -122,7 +123,7 @@ u1 *intrp_main_stack = NULL;
 
 #define HEAP_MAXSIZE      128 * 1024 * 1024 /* default 128MB                  */
 #define HEAP_STARTSIZE      2 * 1024 * 1024 /* default 2MB                    */
-#define STACK_SIZE                64 * 1024 /* default 64kB                   */
+#define STACK_SIZE               128 * 1024 /* default 64kB                   */
 
 
 /* define command line options ************************************************/
@@ -1511,6 +1512,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
        intrp_md_init();
 #endif
 
+       /* BEFORE: loader_preinit */
+
+       package_init();
+
        /* AFTER: utf8_init, classcache_init */
 
        loader_preinit();
index d6dd087dc99b7d142eb35537af0007178cb7094d..f83b68c587e4e7e7a822e32682ef5124634f9cd2 100644 (file)
@@ -45,6 +45,7 @@
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/global.h"
+#include "vm/package.h"
 #include "vm/primitive.h"
 #include "vm/resolve.h"
 #include "vm/stringlocal.h"
@@ -1335,22 +1336,27 @@ classinfo *load_class_bootstrap(utf *name)
 
        RT_TIMING_GET_TIME(time_load);
        
-       if (!r) {
+       if (r == NULL) {
                /* the class could not be loaded, free the classinfo struct */
 
                class_free(c);
-
-       else {
+       }
+       else {
                /* Store this class in the loaded class cache this step also
-               checks the loading constraints. If the class has been loaded
-               before, the earlier loaded class is returned. */
+                  checks the loading constraints. If the class has been
+                  loaded before, the earlier loaded class is returned. */
 
                classinfo *res = classcache_store(NULL, c, true);
 
-               if (!res) {
+               if (res == NULL) {
                        /* exception */
                        class_free(c);
                }
+               else {
+                       /* Add the package name to the boot packages. */
+
+                       package_add(c->packagename);
+               }
 
                r = res;
        }
index 396fd3bb655da47af85c64612f7ec30f1ea75e49..71a94838b7bcdaa0e38f8123b3fe1f0b63edf2d0 100644 (file)
@@ -175,6 +175,7 @@ const char *opt_filter_show_method = 0;
 
 int      opt_DebugExceptions           = 0;
 int      opt_DebugLocks                = 0;
+int      opt_DebugPackage              = 0;
 int      opt_DebugPatcher              = 0;
 int      opt_DebugProperties           = 0;
 int32_t  opt_DebugStackFrameInfo       = 0;
@@ -210,6 +211,7 @@ enum {
 enum {
        OPT_DebugExceptions,
        OPT_DebugLocks,
+       OPT_DebugPackage,
        OPT_DebugPatcher,
        OPT_DebugProperties,
        OPT_DebugStackFrameInfo,
@@ -235,6 +237,7 @@ enum {
 option_t options_XX[] = {
        { "DebugExceptions",           OPT_DebugExceptions,           OPT_TYPE_BOOLEAN, "debug exceptions" },
        { "DebugLocks",                OPT_DebugLocks,                OPT_TYPE_BOOLEAN, "print debug information for locks" },
+       { "DebugPackage",              OPT_DebugPackage,              OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
        { "DebugPatcher",              OPT_DebugPatcher,              OPT_TYPE_BOOLEAN, "debug JIT code patching" },
        { "DebugProperties",           OPT_DebugProperties,           OPT_TYPE_BOOLEAN, "print debug information for properties" },
        { "DebugStackFrameInfo",       OPT_DebugStackFrameInfo,       OPT_TYPE_BOOLEAN, "TODO" },
@@ -522,6 +525,10 @@ void options_xx(JavaVMInitArgs *vm_args)
                        opt_DebugLocks = enable;
                        break;
 
+               case OPT_DebugPackage:
+                       opt_DebugPackage = enable;
+                       break;
+
                case OPT_DebugPatcher:
                        opt_DebugPatcher = enable;
                        break;
index 59ccbb6647cbe5e46d21f8b9231d29e888fc6b88..bd289bd53f0c995971b61c08b9c456ddd60ab0a4 100644 (file)
@@ -191,6 +191,7 @@ extern const char *opt_filter_show_method;
 extern int      opt_DebugExceptions;
 extern int      opt_DebugLocks;
 extern int      opt_DebugPatcher;
+extern int      opt_DebugPackage;
 extern int      opt_DebugProperties;
 extern int32_t  opt_DebugStackFrameInfo;
 extern int32_t  opt_DebugStackTrace;