Publish configuration using volatile instread fence JEP-349-branch
authoregahlin
Thu, 29 Aug 2019 19:38:54 +0200
branchJEP-349-branch
changeset 57948 59ad17a19e24
parent 57947 5c8039344562
child 57949 74a38c0b5054
Publish configuration using volatile instread fence
src/jdk.jfr/share/classes/jdk/jfr/consumer/AbstractEventStream.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/AbstractEventStream.java	Thu Aug 29 19:31:57 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/AbstractEventStream.java	Thu Aug 29 19:38:54 2019 +0200
@@ -330,7 +330,7 @@
     protected final Runnable flushOperation = () -> runFlushActions();
 
     // Updated by updateConfiguration()
-    protected StreamConfiguration configuration = new StreamConfiguration();
+    protected volatile StreamConfiguration configuration = new StreamConfiguration();
 
     // Cache the last event type and dispatch.
     private EventType lastEventType;
@@ -501,16 +501,13 @@
 
 
     protected boolean updateConfiguration(StreamConfiguration newConfiguration) {
-        // Changes to the configuration must be serialized, so make
+        // Changes to the configuration must happen one at a time, so make
         // sure that we have the monitor
         Thread.holdsLock(this);
         if (newConfiguration.hasChanged()) {
-            // Publish objects indirectly held by new configuration object
+            // Publish objects held by configuration object
             VarHandle.releaseFence();
             configuration = newConfiguration;
-            // Publish the field reference. Making the field volatile
-            // would be an alternative, but it is repeatedly read.
-            VarHandle.releaseFence();
             return true;
         }
         return false;