changeset 379:6dacea0912f4

Runners: trim down StateHolder instance size, cutting down allocation pressure in many tests.
author shade
date Thu, 02 Mar 2017 18:04:55 +0100
parents bb24b81cbe3c
children 03b52bedec8e
files jcstress-core/src/main/java/jdk/internal/vm/annotation/Contended.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/StateHolder.java jcstress-core/src/main/java/sun/misc/Contended.java
diffstat 3 files changed, 40 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/jdk/internal/vm/annotation/Contended.java	Thu Mar 02 16:28:02 2017 +0100
+++ b/jcstress-core/src/main/java/jdk/internal/vm/annotation/Contended.java	Thu Mar 02 18:04:55 2017 +0100
@@ -32,4 +32,5 @@
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.FIELD, ElementType.TYPE})
 public @interface Contended {
+    String value() default ""; // tag
 }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/StateHolder.java	Thu Mar 02 16:28:02 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/StateHolder.java	Thu Mar 02 18:04:55 2017 +0100
@@ -31,22 +31,52 @@
  * @author Aleksey Shipilev (aleksey.shipilev@oracle.com)
  */
 public class StateHolder<P> {
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
+
+    // ------------------ Final, read-only fields ---------------------
+
+    @sun.misc.Contended("finals")
+    @jdk.internal.vm.annotation.Contended("finals")
     public final boolean stopped;
 
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
+    @sun.misc.Contended("finals")
+    @jdk.internal.vm.annotation.Contended("finals")
     public final P[] pairs;
 
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
+    @sun.misc.Contended("finals")
+    @jdk.internal.vm.annotation.Contended("finals")
     public final int countWorkers;
 
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
+    @sun.misc.Contended("finals")
+    @jdk.internal.vm.annotation.Contended("finals")
     public final SpinLoopStyle spinStyle;
 
+    // --------------------- Write-once fields ------------------------
+    // Threads are busy-waiting on these, let them do it undisturbed.
+
+    @sun.misc.Contended("flags")
+    @jdk.internal.vm.annotation.Contended("flags")
+    private volatile boolean notAllStarted;
+
+    @sun.misc.Contended("flags")
+    @jdk.internal.vm.annotation.Contended("flags")
+    private volatile boolean notAllReady;
+
+    @sun.misc.Contended("flags")
+    @jdk.internal.vm.annotation.Contended("flags")
+    private volatile boolean notAllFinished;
+
+    @sun.misc.Contended("flags")
+    @jdk.internal.vm.annotation.Contended("flags")
+    private volatile boolean notUpdated;
+
+    @sun.misc.Contended("flags")
+    @jdk.internal.vm.annotation.Contended("flags")
+    public volatile boolean updateStride;
+
+    // --------------------- Write-frequent fields ------------------------
+    // Threads are updating them frequently, and they need them completely
+    // separate. Otherwise there are warmup/warmdown lags.
+
     @sun.misc.Contended
     @jdk.internal.vm.annotation.Contended
     private volatile int started;
@@ -63,26 +93,6 @@
     @jdk.internal.vm.annotation.Contended
     private volatile int consumed;
 
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
-    private volatile boolean notAllStarted;
-
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
-    private volatile boolean notAllReady;
-
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
-    private volatile boolean notAllFinished;
-
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
-    private volatile boolean notUpdated;
-
-    @sun.misc.Contended
-    @jdk.internal.vm.annotation.Contended
-    public volatile boolean updateStride;
-
     static final AtomicIntegerFieldUpdater<StateHolder> UPDATER_STARTED  = AtomicIntegerFieldUpdater.newUpdater(StateHolder.class, "started");
     static final AtomicIntegerFieldUpdater<StateHolder> UPDATER_READY    = AtomicIntegerFieldUpdater.newUpdater(StateHolder.class, "ready");
     static final AtomicIntegerFieldUpdater<StateHolder> UPDATER_FINISHED = AtomicIntegerFieldUpdater.newUpdater(StateHolder.class, "finished");
--- a/jcstress-core/src/main/java/sun/misc/Contended.java	Thu Mar 02 16:28:02 2017 +0100
+++ b/jcstress-core/src/main/java/sun/misc/Contended.java	Thu Mar 02 18:04:55 2017 +0100
@@ -32,4 +32,5 @@
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.FIELD, ElementType.TYPE})
 public @interface Contended {
+    String value() default ""; // tag
 }