8223177: Data race on JvmtiEnvBase::_tag_map in double-checked locking

Tue, 30 Apr 2019 18:44:41 -0700

author
manc
date
Tue, 30 Apr 2019 18:44:41 -0700
changeset 9733
c61a86859323
parent 9732
bfac16f18d92
child 9734
25738d7267c3

8223177: Data race on JvmtiEnvBase::_tag_map in double-checked locking
Summary: Add memory fences on accesses to JvmtiEnvBase::_tag_map
Reviewed-by: dholmes, jcbeyler, sspitsyn

src/share/vm/prims/jvmtiEnvBase.hpp file | annotate | diff | comparison | revisions
src/share/vm/prims/jvmtiTagMap.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/prims/jvmtiEnvBase.hpp	Thu Aug 15 02:51:03 2019 +0100
     1.2 +++ b/src/share/vm/prims/jvmtiEnvBase.hpp	Tue Apr 30 18:44:41 2019 -0700
     1.3 @@ -32,6 +32,7 @@
     1.4  #include "runtime/fieldDescriptor.hpp"
     1.5  #include "runtime/frame.hpp"
     1.6  #include "runtime/handles.inline.hpp"
     1.7 +#include "runtime/orderAccess.hpp"
     1.8  #include "runtime/thread.hpp"
     1.9  #include "runtime/vm_operations.hpp"
    1.10  #include "utilities/growableArray.hpp"
    1.11 @@ -97,7 +98,7 @@
    1.12    const void *_env_local_storage;     // per env agent allocated data.
    1.13    jvmtiEventCallbacks _event_callbacks;
    1.14    jvmtiExtEventCallbacks _ext_event_callbacks;
    1.15 -  JvmtiTagMap* _tag_map;
    1.16 +  JvmtiTagMap* volatile _tag_map;
    1.17    JvmtiEnvEventEnable _env_event_enable;
    1.18    jvmtiCapabilities _current_capabilities;
    1.19    jvmtiCapabilities _prohibited_capabilities;
    1.20 @@ -251,6 +252,13 @@
    1.21      return _tag_map;
    1.22    }
    1.23  
    1.24 +  JvmtiTagMap* acquire_tag_map() {
    1.25 +    return (JvmtiTagMap*)OrderAccess::load_ptr_acquire(&_tag_map);
    1.26 +  }
    1.27 +
    1.28 +  void release_set_tag_map(JvmtiTagMap* tag_map) {
    1.29 +    OrderAccess::release_store_ptr(&_tag_map, tag_map);
    1.30 +  }
    1.31  
    1.32    // return true if event is enabled globally or for any thread
    1.33    // True only if there is a callback for it.
     2.1 --- a/src/share/vm/prims/jvmtiTagMap.cpp	Thu Aug 15 02:51:03 2019 +0100
     2.2 +++ b/src/share/vm/prims/jvmtiTagMap.cpp	Tue Apr 30 18:44:41 2019 -0700
     2.3 @@ -430,7 +430,7 @@
     2.4    _hashmap = new JvmtiTagHashmap();
     2.5  
     2.6    // finally add us to the environment
     2.7 -  ((JvmtiEnvBase *)env)->set_tag_map(this);
     2.8 +  ((JvmtiEnvBase *)env)->release_set_tag_map(this);
     2.9  }
    2.10  
    2.11  
    2.12 @@ -499,7 +499,7 @@
    2.13  // returns the tag map for the given environments. If the tag map
    2.14  // doesn't exist then it is created.
    2.15  JvmtiTagMap* JvmtiTagMap::tag_map_for(JvmtiEnv* env) {
    2.16 -  JvmtiTagMap* tag_map = ((JvmtiEnvBase*)env)->tag_map();
    2.17 +  JvmtiTagMap* tag_map = ((JvmtiEnvBase*)env)->acquire_tag_map();
    2.18    if (tag_map == NULL) {
    2.19      MutexLocker mu(JvmtiThreadState_lock);
    2.20      tag_map = ((JvmtiEnvBase*)env)->tag_map();
    2.21 @@ -3282,7 +3282,7 @@
    2.22    if (JvmtiEnv::environments_might_exist()) {
    2.23      JvmtiEnvIterator it;
    2.24      for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
    2.25 -      JvmtiTagMap* tag_map = env->tag_map();
    2.26 +      JvmtiTagMap* tag_map = env->acquire_tag_map();
    2.27        if (tag_map != NULL && !tag_map->is_empty()) {
    2.28          tag_map->do_weak_oops(is_alive, f);
    2.29        }

mercurial