PR156: Preparation
authorStefan Ring <stefan@complang.tuwien.ac.at>
Wed, 2 Mar 2011 18:49:19 +0000 (19:49 +0100)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Wed, 2 Mar 2011 18:49:19 +0000 (19:49 +0100)
* 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
src/vm/Makefile.am
src/vm/hook.cpp [new file with mode: 0644]
src/vm/hook.hpp
src/vm/javaobjects.cpp
src/vm/javaobjects.hpp
src/vm/linker.cpp
src/vm/linker.hpp
src/vm/vm.cpp

index 0c34db63f5a48678c23d07917938b1a9718da08c..439f9964ff0824279170c4161940580638df08a3 100644 (file)
@@ -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 <tr1/unordered_map>
 
 
index 93778b11e762e2cc439599978f2f8b38141f66cb..2d4f2c48dd93f03f2562f6e170c788e287ac0a35 100644 (file)
@@ -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 (file)
index 0000000..b1dce8c
--- /dev/null
@@ -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:
+ */
index e86d052b98ab16cf88b9419fe4b9a37edd51d5a0..db7c97b94ec3f922f5ad0246093aa02df2057d20 100644 (file)
@@ -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)
index 2bd0a19ddd81ea35dd496ab2af783328283015b8..4f63d89a5117b0828c9e7599acf699a83458eb50 100644 (file)
@@ -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 <map>
 
 #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<classinfo *, DynOffsetEntry *> 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:
  */
index 199fa8b612ebbb9cc17520f9e29a7230d226ef91..d4463d33f7562da5e868d420b6fb6366e21cf35e 100644 (file)
@@ -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:
  */
index 4cede0109c4a7c2c99e9bbeb9114e892f04ee48b..0d389dc345c8dfc657a0d6809a6b5598c51ae04b 100644 (file)
@@ -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;
 }
index 0d578be501a0eed9e18211f34f1a8e7a1cb89861..9aa4a6714a075779f1c6bb853ccb2a42137a5ee1 100644 (file)
@@ -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:
  */
index ef1e93dbcdba2d659f596b7ee0872a423f06820c..3209a88a4124c0986323071e7eced48b1aa5cc78 100644 (file)
@@ -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