From 0ca91e2ee7bc3a48a2c6703a391941f564205f60 Mon Sep 17 00:00:00 2001 From: Christian Thalinger Date: Sun, 16 Sep 2007 18:47:08 +0200 Subject: [PATCH] * src/cacaoh/dummy.c (package_add): New function. * 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 | 9 +++ src/native/vm/sun/jvm.c | 19 ++++- src/vm/Makefile.am | 2 + src/vm/package.c | 170 ++++++++++++++++++++++++++++++++++++++++ src/vm/package.h | 64 +++++++++++++++ src/vm/vm.c | 7 +- src/vmcore/loader.c | 18 +++-- src/vmcore/options.c | 7 ++ src/vmcore/options.h | 1 + 9 files changed, 286 insertions(+), 11 deletions(-) create mode 100644 src/vm/package.c create mode 100644 src/vm/package.h diff --git a/src/cacaoh/dummy.c b/src/cacaoh/dummy.c index 16e9b3a82..8cc300932 100644 --- a/src/cacaoh/dummy.c +++ b/src/cacaoh/dummy.c @@ -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) diff --git a/src/native/vm/sun/jvm.c b/src/native/vm/sun/jvm.c index c76c0cfae..92f770376 100644 --- a/src/native/vm/sun/jvm.c +++ b/src/native/vm/sun/jvm.c @@ -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; } diff --git a/src/vm/Makefile.am b/src/vm/Makefile.am index 34cdc2a2c..bdc79e4f8 100644 --- a/src/vm/Makefile.am +++ b/src/vm/Makefile.am @@ -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 index 000000000..88e532c85 --- /dev/null +++ b/src/vm/package.c @@ -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 + +#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 index 000000000..95fcd54e9 --- /dev/null +++ b/src/vm/package.h @@ -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 + +#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: + */ diff --git a/src/vm/vm.c b/src/vm/vm.c index 24c239b59..991ee4a4a 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -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(); diff --git a/src/vmcore/loader.c b/src/vmcore/loader.c index d6dd087dc..f83b68c58 100644 --- a/src/vmcore/loader.c +++ b/src/vmcore/loader.c @@ -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; } diff --git a/src/vmcore/options.c b/src/vmcore/options.c index 396fd3bb6..71a94838b 100644 --- a/src/vmcore/options.c +++ b/src/vmcore/options.c @@ -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; diff --git a/src/vmcore/options.h b/src/vmcore/options.h index 59ccbb664..bd289bd53 100644 --- a/src/vmcore/options.h +++ b/src/vmcore/options.h @@ -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; -- 2.25.1