# HG changeset patch # User aph # Date 1530625340 -3600 # Tue Jul 03 14:42:20 2018 +0100 # Branch JDK-8206267 # Node ID 1f6e92bc0a9969d28198a45c8cc55a234d2c39c4 # Parent 79baec7d831e4654989b7c63c1f4cd3103169e6d 8206267: Unsafe publication of StubCodeDesc leads to crashes Reviewed-by: kvn diff --git a/src/hotspot/share/runtime/stubCodeGenerator.cpp b/src/hotspot/share/runtime/stubCodeGenerator.cpp --- a/src/hotspot/share/runtime/stubCodeGenerator.cpp +++ b/src/hotspot/share/runtime/stubCodeGenerator.cpp @@ -34,8 +34,8 @@ // Implementation of StubCodeDesc -StubCodeDesc* StubCodeDesc::_list = NULL; -bool StubCodeDesc::_frozen = false; +StubCodeDesc *volatile StubCodeDesc::_list = NULL; +bool StubCodeDesc::_frozen = false; StubCodeDesc* StubCodeDesc::desc_for(address pc) { StubCodeDesc* p = _list; diff --git a/src/hotspot/share/runtime/stubCodeGenerator.hpp b/src/hotspot/share/runtime/stubCodeGenerator.hpp --- a/src/hotspot/share/runtime/stubCodeGenerator.hpp +++ b/src/hotspot/share/runtime/stubCodeGenerator.hpp @@ -27,6 +27,7 @@ #include "asm/assembler.hpp" #include "memory/allocation.hpp" +#include "runtime/orderAccess.hpp" // All the basic framework for stub code generation/debugging/printing. @@ -38,14 +39,14 @@ class StubCodeDesc: public CHeapObj { private: - static StubCodeDesc* _list; // the list of all descriptors - static bool _frozen; // determines whether _list modifications are allowed + static StubCodeDesc *volatile _list; // the list of all descriptors + static bool _frozen; // determines whether _list modifications are allowed - StubCodeDesc* _next; // the next element in the linked list - const char* _group; // the group to which the stub code belongs - const char* _name; // the name assigned to the stub code - address _begin; // points to the first byte of the stub code (included) - address _end; // points to the first byte after the stub code (excluded) + StubCodeDesc* _next; // the next element in the linked list + const char* _group; // the group to which the stub code belongs + const char* _name; // the name assigned to the stub code + address _begin; // points to the first byte of the stub code (included) + address _end; // points to the first byte after the stub code (excluded) void set_end(address end) { assert(_begin <= end, "begin & end not properly ordered"); @@ -76,7 +77,7 @@ _name = name; _begin = begin; _end = end; - _list = this; + OrderAccess::release_store(&_list, this); }; static void freeze();