Blame jdk8206406-pr3610-rh1597825-tubcodedesc_constructor_publishes_partially_constructed_objects_on_stubCodeDesc_list.patch

baf0cab
# HG changeset patch
baf0cab
# User aph
baf0cab
# Date 1531146945 -3600
baf0cab
#      Mon Jul 09 15:35:45 2018 +0100
baf0cab
# Node ID 95b72537801cc9946c27ad27f07e3f0790a21b08
baf0cab
# Parent  f6341f4635dacb56678264d29a88cd052b74036b
baf0cab
8206406, PR3610, RH1597825: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
baf0cab
Reviewed-by: dholmes
baf0cab
baf0cab
diff --git openjdk.orig/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
baf0cab
--- openjdk.orig/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
baf0cab
+++ openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
baf0cab
@@ -34,12 +34,12 @@
baf0cab
 
baf0cab
 // Implementation of StubCodeDesc
baf0cab
 
baf0cab
-StubCodeDesc* StubCodeDesc::_list = NULL;
baf0cab
-int           StubCodeDesc::_count = 0;
baf0cab
+StubCodeDesc* volatile StubCodeDesc::_list = NULL;
baf0cab
+int                    StubCodeDesc::_count = 0;
baf0cab
 
baf0cab
 
baf0cab
 StubCodeDesc* StubCodeDesc::desc_for(address pc) {
baf0cab
-  StubCodeDesc* p = _list;
baf0cab
+  StubCodeDesc* p = (StubCodeDesc*)OrderAccess::load_ptr_acquire(&_list);
baf0cab
   while (p != NULL && !p->contains(pc)) p = p->_next;
baf0cab
   // p == NULL || p->contains(pc)
baf0cab
   return p;
baf0cab
@@ -47,7 +47,7 @@
baf0cab
 
baf0cab
 
baf0cab
 StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
baf0cab
-  StubCodeDesc* p = _list;
baf0cab
+  StubCodeDesc* p = (StubCodeDesc*)OrderAccess::load_ptr_acquire(&_list);
baf0cab
   while (p != NULL && p->index() != index) p = p->_next;
baf0cab
   return p;
baf0cab
 }
baf0cab
diff --git openjdk.orig/hotspot/src/share/vm/runtime/stubCodeGenerator.hpp openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.hpp
baf0cab
--- openjdk.orig/hotspot/src/share/vm/runtime/stubCodeGenerator.hpp
baf0cab
+++ openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.hpp
baf0cab
@@ -38,7 +38,7 @@
baf0cab
 
baf0cab
 class StubCodeDesc: public CHeapObj<mtCode> {
baf0cab
  protected:
baf0cab
-  static StubCodeDesc* _list;                  // the list of all descriptors
baf0cab
+  static StubCodeDesc* volatile _list;         // the list of all descriptors
baf0cab
   static int           _count;                 // length of list
baf0cab
 
baf0cab
   StubCodeDesc*        _next;                  // the next element in the linked list
baf0cab
@@ -69,13 +69,13 @@
baf0cab
 
baf0cab
   StubCodeDesc(const char* group, const char* name, address begin) {
baf0cab
     assert(name != NULL, "no name specified");
baf0cab
-    _next           = _list;
baf0cab
+    _next           = (StubCodeDesc*)OrderAccess::load_ptr_acquire(&_list);
baf0cab
     _group          = group;
baf0cab
     _name           = name;
baf0cab
     _index          = ++_count; // (never zero)
baf0cab
     _begin          = begin;
baf0cab
     _end            = NULL;
baf0cab
-    _list           = this;
baf0cab
+    OrderAccess::release_store_ptr(&_list, this);
baf0cab
   };
baf0cab
 
baf0cab
   const char* group() const                      { return _group; }