From 0775e531232398c8363a68846224bd86e859e322 Mon Sep 17 00:00:00 2001 From: Stefan Ring Date: Wed, 2 Mar 2011 19:49:19 +0100 Subject: [PATCH] PR156: Preparation * src/vm/javaobjects.cpp: Added a facility for registering dynamic field offsets. * src/vm/javaobjects.hpp (jobjects_register_dyn_offsets, jobjects_run_dynoffsets_hook): Added. * src/vm/hook.cpp: Added because of non-inline function. * src/vm/hook.hpp (class_linked): Changed signature because of exception handling. (class_linked_dynoffsets): Added & call it. * src/vm/linker.cpp: Adapted to new signatures. * src/vm/linker.hpp: Cleanup only. * src/vm/Makefile.am: Added hook.cpp. * src/vm/vm.cpp: Call new dynamic offset hook. * src/toolbox/hashtable.hpp: Cleanup only. --- src/toolbox/hashtable.hpp | 5 +--- src/vm/Makefile.am | 1 + src/vm/hook.cpp | 52 +++++++++++++++++++++++++++++++++++++++ src/vm/hook.hpp | 11 ++++++--- src/vm/javaobjects.cpp | 45 +++++++++++++++++++++++++++++++++ src/vm/javaobjects.hpp | 5 ++++ src/vm/linker.cpp | 7 +++--- src/vm/linker.hpp | 5 ++-- src/vm/vm.cpp | 2 ++ 9 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 src/vm/hook.cpp diff --git a/src/toolbox/hashtable.hpp b/src/toolbox/hashtable.hpp index 0c34db63f..439f9964f 100644 --- a/src/toolbox/hashtable.hpp +++ b/src/toolbox/hashtable.hpp @@ -1,6 +1,6 @@ /* src/toolbox/hashtable.hpp - hashtable classes - Copyright (C) 2009 + Copyright (C) 2009, 2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO Copyright (C) 2009 Theobroma Systems Ltd. @@ -31,9 +31,6 @@ #if __cplusplus -// XXX This is a TR1 header and not (yet) part of the C++ standard, so we -// should not use it. The solution is to implement the below stuff -// ourselves. This will be done, sometimes, soon, I hope ... #include diff --git a/src/vm/Makefile.am b/src/vm/Makefile.am index 93778b11e..2d4f2c48d 100644 --- a/src/vm/Makefile.am +++ b/src/vm/Makefile.am @@ -99,6 +99,7 @@ libvm_la_SOURCES = \ finalizer.hpp \ globals.cpp \ globals.hpp \ + hook.cpp \ hook.hpp \ initialize.cpp \ initialize.hpp \ diff --git a/src/vm/hook.cpp b/src/vm/hook.cpp new file mode 100644 index 000000000..b1dce8ca3 --- /dev/null +++ b/src/vm/hook.cpp @@ -0,0 +1,52 @@ +/* src/vm/hook.cpp - hook points inside the VM + + Copyright (C) 2009, 2011 + 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 "vm/global.h" +#include "vm/globals.hpp" + +#include "mm/memory.hpp" +#include "vm/hook.hpp" +#include "vm/javaobjects.hpp" + +bool Hook::class_linked_dynoffsets(classinfo *c) +{ + return jobjects_run_dynoffsets_hook(c); +} + + +/* + * 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/hook.hpp b/src/vm/hook.hpp index e86d052b9..db7c97b94 100644 --- a/src/vm/hook.hpp +++ b/src/vm/hook.hpp @@ -1,6 +1,6 @@ /* src/vm/hook.hpp - hook points inside the VM - Copyright (C) 2009, 2010 + Copyright (C) 2009, 2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -43,7 +43,7 @@ */ namespace Hook { void breakpoint (Breakpoint *bp); - void class_linked (classinfo *c); + bool class_linked (classinfo *c); void class_loaded (classinfo *c); void jit_generated (methodinfo *m, codeinfo *code); void jit_recycled (methodinfo *m, codeinfo *code); @@ -56,6 +56,9 @@ namespace Hook { void vm_init (); void vm_preinit (); void vm_shutdown (); + + // Non-inline functions + bool class_linked_dynoffsets(classinfo *c); } @@ -70,10 +73,12 @@ inline void Hook::breakpoint(Breakpoint *bp) #endif } -inline void Hook::class_linked(classinfo *c) +inline bool Hook::class_linked(classinfo *c) { if (c == class_java_lang_String) linker_initialize_deferred_strings(); + + return class_linked_dynoffsets(c); } inline void Hook::class_loaded(classinfo *c) diff --git a/src/vm/javaobjects.cpp b/src/vm/javaobjects.cpp index 2bd0a19dd..4f63d89a5 100644 --- a/src/vm/javaobjects.cpp +++ b/src/vm/javaobjects.cpp @@ -1,5 +1,7 @@ /* src/vm/javaobjects.cpp - functions to create and access Java objects + Copyright (C) 2010, 2011 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO Copyright (C) 2008, 2009 Theobroma Systems Ltd. This file is part of CACAO. @@ -35,6 +37,7 @@ #include "vm/initialize.hpp" #include "vm/javaobjects.hpp" +#include #if defined(ENABLE_JAVASE) @@ -188,6 +191,47 @@ java_handle_t* java_lang_reflect_Method::invoke(java_handle_t* o, java_handle_ob return result; } +struct DynOffsetEntry { + void (*setter)(int32_t); + const char *name; +}; + +typedef std::map RegisteredDynMap; +static RegisteredDynMap dynEntryMap; + +static void register_dyn_entry_table(classinfo *c, DynOffsetEntry *entries) +{ + dynEntryMap.insert(std::make_pair(c, entries)); +} + +static bool runAllSetters(classinfo *c, DynOffsetEntry entries[]) +{ + do { + fieldinfo *fi = class_findfield_by_name(c, utf_new_char(entries->name)); + if (!fi) + return false; + entries->setter(fi->offset); + } while ((++entries)->setter); + return true; +} + +bool jobjects_run_dynoffsets_hook(classinfo *c) +{ + RegisteredDynMap::const_iterator it = dynEntryMap.find(c); + if (it == dynEntryMap.end()) + return true; + + if (!runAllSetters(c, it->second)) + return false; + + return true; +} + + +void jobjects_register_dyn_offsets() +{ +} + #endif // ENABLE_JAVASE @@ -202,4 +246,5 @@ java_handle_t* java_lang_reflect_Method::invoke(java_handle_t* o, java_handle_ob * c-basic-offset: 4 * tab-width: 4 * End: + * vim:noexpandtab:sw=4:ts=4: */ diff --git a/src/vm/javaobjects.hpp b/src/vm/javaobjects.hpp index 199fa8b61..d4463d33f 100644 --- a/src/vm/javaobjects.hpp +++ b/src/vm/javaobjects.hpp @@ -1,5 +1,7 @@ /* src/vm/javaobjects.hpp - functions to create and access Java objects + Copyright (C) 2010, 2011 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO Copyright (C) 2008, 2009 Theobroma Systems Ltd. This file is part of CACAO. @@ -569,6 +571,8 @@ inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value) #endif // ENABLE_JAVASE +void jobjects_register_dyn_offsets(); +bool jobjects_run_dynoffsets_hook(classinfo *c); #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) @@ -2918,4 +2922,5 @@ inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value) * c-basic-offset: 4 * tab-width: 4 * End: + * vim:noexpandtab:sw=4:ts=4: */ diff --git a/src/vm/linker.cpp b/src/vm/linker.cpp index 4cede0109..0d389dc34 100644 --- a/src/vm/linker.cpp +++ b/src/vm/linker.cpp @@ -1,6 +1,6 @@ /* src/vm/linker.cpp - class linker functions - Copyright (C) 1996-2005, 2006, 2007, 2008, 2010 + Copyright (C) 1996, 2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -383,7 +383,7 @@ classinfo *link_class(classinfo *c) if (c == NULL) { exceptions_throw_nullpointerexception(); - return NULL; + return 0; } LOCK_MONITOR_ENTER(c); @@ -433,7 +433,8 @@ classinfo *link_class(classinfo *c) RT_TIMING_TIME_DIFF(time_start,time_end,RT_TIMING_LINK_TOTAL); // Hook point just after a class was linked. - Hook::class_linked(r); + if (!Hook::class_linked(r)) + return 0; return r; } diff --git a/src/vm/linker.hpp b/src/vm/linker.hpp index 0d578be50..9aa4a6714 100644 --- a/src/vm/linker.hpp +++ b/src/vm/linker.hpp @@ -1,6 +1,6 @@ -/* src/vm/linker.h - class linker header +/* src/vm/linker.hpp - class linker header - Copyright (C) 1996-2005, 2006, 2007, 2008, 2010 + Copyright (C) 1996, 2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -111,4 +111,5 @@ void linker_initialize_deferred_strings(); * c-basic-offset: 4 * tab-width: 4 * End: + * vim:noexpandtab:sw=4:ts=4: */ diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index ef1e93dbc..3209a88a4 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -71,6 +71,7 @@ #include "vm/globals.hpp" #include "vm/hook.hpp" #include "vm/initialize.hpp" +#include "vm/javaobjects.hpp" #include "vm/options.h" #include "vm/os.hpp" #include "vm/primitive.hpp" @@ -1347,6 +1348,7 @@ VM::VM(JavaVMInitArgs* vm_args) Primitive::initialize_table(); loader_init(); + jobjects_register_dyn_offsets(); linker_init(); // AFTER: loader_init, linker_init -- 2.25.1