changeset 39:1802ea51fea7

Better @Contended detection.
author shade
date Wed, 07 Aug 2013 15:13:56 +0400
parents 4bc0cc31b700
children 38e70041b24b
files harness/src/main/java/org/openjdk/jcstress/Main.java harness/src/main/java/org/openjdk/jcstress/util/VMSupport.java harness/src/main/java/sun/misc/Contended.java
diffstat 3 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/harness/src/main/java/org/openjdk/jcstress/Main.java	Wed Aug 07 13:15:40 2013 +0400
+++ b/harness/src/main/java/org/openjdk/jcstress/Main.java	Wed Aug 07 15:13:56 2013 +0400
@@ -57,8 +57,17 @@
                 System.out.println(test.getName());
             }
         } else {
+            if (!VMSupport.tryContended()) {
+                System.out.println("Non-fatal: VM support for @Contended is not enabled. Possible reasons are:\n" +
+                        "  1) unsupported JDK, only JDK 8+ is supported; \n" +
+                        "  2) -XX:-RestrictContended is missing; \n" +
+                        "  3) the jcstress JAR is not added to -Xbootclasspath/a\n");
+            } else {
+                System.out.println("@Contended is in use.\n");
+            }
+
             if (!VMSupport.tryInit()) {
-                System.out.println("Non-fatal: VM support is not enabled. Possible reasons are:\n" +
+                System.out.println("Non-fatal: VM support for online deoptimization is not enabled. Possible reasons are:\n" +
                         "  1) unsupported JDK, only JDK 8+ is supported; \n" +
                         "  2) -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI VM options are missing; \n" +
                         "  3) the jcstress JAR is not added to -Xbootclasspath/a\n");
--- a/harness/src/main/java/org/openjdk/jcstress/util/VMSupport.java	Wed Aug 07 13:15:40 2013 +0400
+++ b/harness/src/main/java/org/openjdk/jcstress/util/VMSupport.java	Wed Aug 07 15:13:56 2013 +0400
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jcstress.util;
 
+import org.openjdk.jcstress.infra.results.IntResult2;
 import sun.hotspot.WhiteBox;
 
 import java.io.IOException;
@@ -94,4 +95,15 @@
         }
     }
 
+    public static boolean tryContended() {
+        try {
+            long o1 = UnsafeHolder.U.objectFieldOffset(IntResult2.class.getField("r1"));
+            long o2 = UnsafeHolder.U.objectFieldOffset(IntResult2.class.getField("r2"));
+
+            return Math.abs(o2 - o1) >= 64;
+        } catch (NoSuchFieldException e) {
+            throw new IllegalStateException();
+        }
+    }
+
 }
--- a/harness/src/main/java/sun/misc/Contended.java	Wed Aug 07 13:15:40 2013 +0400
+++ b/harness/src/main/java/sun/misc/Contended.java	Wed Aug 07 15:13:56 2013 +0400
@@ -24,5 +24,12 @@
  */
 package sun.misc;
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.TYPE})
 public @interface Contended {
 }