changeset 316:5938d81bff44

Generators: trap subclasses should use hierarchy trick instead of @Contended to dodge Jigsaw protections for sun.misc.
author shade
date Fri, 16 Sep 2016 12:37:26 +0200
parents 1558a1741344
children 162fe8f8a34c
files jcstress-core/pom.xml jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java jcstress-core/src/main/java/org/openjdk/jcstress/util/Paddings.java tests-chapter-1a/pom.xml tests-chapter-1b/pom.xml tests-chapter-1c/pom.xml
diffstat 6 files changed, 73 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/pom.xml	Mon Sep 05 21:19:51 2016 +0300
+++ b/jcstress-core/pom.xml	Fri Sep 16 12:37:26 2016 +0200
@@ -52,13 +52,12 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>2.4</version>
                 <configuration>
                     <proc>none</proc>
-                    <compilerArguments>
-                        <Xlint:all/>
-                        <Werror/>
-                    </compilerArguments>
+                    <compilerArgs>
+                        <arg>-Xlint:all</arg>
+                        <arg>-Werror</arg>
+                    </compilerArgs>
                 </configuration>
             </plugin>
             <plugin>
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Mon Sep 05 21:19:51 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Fri Sep 16 12:37:26 2016 +0200
@@ -595,13 +595,21 @@
             return;
         }
 
+        // We have to use the hierarchy trick here, and not @Contended, because Jigsaw prevents us
+        // from accessing sun.misc packages.
         pw.println("package " + getPackageName(el) + ";");
-        pw.println("public class " + name + " extends " + el.getQualifiedName() + "{ ");
-        pw.println("    @sun.misc.Contended");
-        pw.println("    @jdk.internal.vm.annotation.Contended");
+        pw.println("class " + name + "_c2 extends " + el.getQualifiedName() + " {");
+        Paddings.padding(pw);
+        pw.println("}");
+
+        pw.println("class " + name + "_c1 extends " + name + "_c2 {");
         pw.println("    public int trap;");
         pw.println("}");
 
+        pw.println("public class " + name + " extends " + name + "_c1 {");
+        Paddings.padding(pw);
+        pw.println("}");
+
         pw.close();
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/Paddings.java	Fri Sep 16 12:37:26 2016 +0200
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.util;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Paddings {
+
+    private static final List<String> PADDING_CACHE;
+
+    static {
+        PADDING_CACHE = new ArrayList<>();
+        for (int p = 0; p < 16; p++) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("    ");
+            sb.append(String.format("boolean p%03d", p * 16 + 0));
+            for (int q = 1; q < 16; q++) {
+                sb.append(String.format(", p%03d", p * 16 + q));
+            }
+            sb.append(";");
+            PADDING_CACHE.add(sb.toString());
+        }
+    }
+
+    public static void padding(List<String> lines) {
+        lines.addAll(PADDING_CACHE);
+    }
+
+    public static void padding(PrintWriter writer) {
+        for (String s : PADDING_CACHE) {
+            writer.println(s);
+        }
+    }
+}
--- a/tests-chapter-1a/pom.xml	Mon Sep 05 21:19:51 2016 +0300
+++ b/tests-chapter-1a/pom.xml	Fri Sep 16 12:37:26 2016 +0200
@@ -57,14 +57,6 @@
                     <debug>false</debug>
                     <meminitial>4096</meminitial>
                     <fork>true</fork>
-                    <compilerArgs>
-                        <!--
-                            No, compiler, we need that sun.misc.Contended here.
-                            Stop complaining sun.misc package is invisible. You can't?
-                            Huh, I guess no module access checks for you then:
-                        -->
-                        <arg>-Xmodule:jdk.unsupported</arg>
-                    </compilerArgs>
                 </configuration>
             </plugin>
             <plugin>
--- a/tests-chapter-1b/pom.xml	Mon Sep 05 21:19:51 2016 +0300
+++ b/tests-chapter-1b/pom.xml	Fri Sep 16 12:37:26 2016 +0200
@@ -57,14 +57,6 @@
                     <debug>false</debug>
                     <meminitial>4096</meminitial>
                     <fork>true</fork>
-                    <compilerArgs>
-                        <!--
-                            No, compiler, we need that sun.misc.Contended here.
-                            Stop complaining sun.misc package is invisible. You can't?
-                            Huh, I guess no module access checks for you then:
-                        -->
-                        <arg>-Xmodule:jdk.unsupported</arg>
-                    </compilerArgs>
                 </configuration>
             </plugin>
             <plugin>
--- a/tests-chapter-1c/pom.xml	Mon Sep 05 21:19:51 2016 +0300
+++ b/tests-chapter-1c/pom.xml	Fri Sep 16 12:37:26 2016 +0200
@@ -57,14 +57,6 @@
                     <debug>false</debug>
                     <meminitial>4096</meminitial>
                     <fork>true</fork>
-                    <compilerArgs>
-                        <!--
-                            No, compiler, we need that sun.misc.Contended here.
-                            Stop complaining sun.misc package is invisible. You can't?
-                            Huh, I guess no module access checks for you then:
-                        -->
-                        <arg>-Xmodule:jdk.unsupported</arg>
-                    </compilerArgs>
                 </configuration>
             </plugin>
             <plugin>