PR162: Make class init protection aware of multiple threads.
authorStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 28 Nov 2011 20:21:32 +0000 (21:21 +0100)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 28 Nov 2011 20:21:32 +0000 (21:21 +0100)
* src/vm/initialize.cpp: Store the initializing thread into a new field for
discrimination of recursive calls versus concurrent calls.
* src/vm/class.cpp, src/vm/class.hpp: Added the new field, adapted test macros.

src/vm/class.cpp
src/vm/class.hpp
src/vm/initialize.cpp

index 066bcfdcf4d220ef2401e4b321045c20b13ed4d4..8491efa889913e6c6a03544ffd777d02bd3b870c 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/class.cpp - class related 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.
@@ -2211,6 +2211,15 @@ int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib)
 }
 
 
+/**
+ * Helper function for the CLASS_IS_OR_ALMOST_INITIALIZED macro.
+ */
+bool class_initializing_thread_is_self(classinfo *c)
+{
+    threadobject *t = thread_get_current();
+    return t == c->initializing_thread;
+}
+
 /* class_get_signature *********************************************************
 
    Return the signature of the given class.  For array and primitive
index 85f05618cafb5f6d2ec4e552bfa051bf6d2cbd2d..5b0c41c2e94846a23d54be3b8729523ef19f2205 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/class.hpp - class related functions header
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -67,7 +67,7 @@ typedef struct extra_classref extra_classref;
 /* some macros ****************************************************************/
 
 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
-    (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
+    (((c)->state & CLASS_INITIALIZED) || ((c)->state & CLASS_INITIALIZING && class_initializing_thread_is_self((c))))
 
 
 /* classinfo ******************************************************************/
@@ -90,6 +90,8 @@ typedef struct {
 #endif
 } dummy_java_lang_Class;
 
+struct threadobject;
+
 struct classinfo {                /* class structure                          */
        dummy_java_lang_Class object;
 
@@ -124,6 +126,7 @@ struct classinfo {                /* class structure                          */
                                      /* (interfaces)                             */
        s4          instancesize;     /* size of an instance of this class        */
 
+       struct threadobject *initializing_thread;
        vftbl_t    *vftbl;            /* pointer to virtual function table        */
 
        methodinfo *finalizer;        /* finalizer method                         */
@@ -424,6 +427,8 @@ java_handle_t             *class_get_name(classinfo *c);
 utf                       *class_get_signature(classinfo *c);
 #endif
 
+bool class_initializing_thread_is_self(classinfo *c);
+
 /* some debugging functions */
 
 #if !defined(NDEBUG)
@@ -457,5 +462,6 @@ void class_showconstantpool(classinfo *c);
  * indent-tabs-mode: t
  * c-basic-offset: 4
  * tab-width: 4
+ * vim:noexpandtab:sw=4:ts=4:
  * End:
  */
index f602073acc171c980f98ae5cea4b98ecf3487560..6435807769de1d8003df647849feeddcfcd87756 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/initialize.cpp - static class initializer functions
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -136,6 +136,7 @@ bool initialize_class(classinfo *c)
 
        /* this initalizing run begins NOW */
 
+       c->initializing_thread = thread_get_current();
        c->state |= CLASS_INITIALIZING;
 
        /* call the internal function */
@@ -280,5 +281,6 @@ static bool initialize_class_intern(classinfo *c)
  * indent-tabs-mode: t
  * c-basic-offset: 4
  * tab-width: 4
+ * vim:noexpandtab:sw=4:ts=4:
  * End:
  */