ThreadPoolExecutor corePoolSize <= maxPoolSize

Pavel Rappo pavel.rappo at oracle.com
Mon May 5 18:53:10 UTC 2014


Hello everyone,

here is the patch that adds a test that explores all possible interleavings between concurrent updates of corePoolSize and maxPoolSize properties of j.u.c.ThreadPoolExecutor (bonus: 1 typo fix)

diff -r 39a1c4786c47 jcstress-core/src/main/java/org/openjdk/jcstress/annotations/State.java
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/annotations/State.java	Mon Apr 14 00:58:18 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/annotations/State.java	Mon May 05 19:41:32 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -34,7 +34,8 @@
  * <p/>
  * Important invariants:
  *   - State classes should have a default constructor;
- *   - All initializations in constructors and instance intializers are visible to all actors;
+ *   - All initializations in constructors and instance initializers are
+ *     visible to all actors;
  */
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
diff -r 39a1c4786c47 tests-custom/src/main/java/org/openjdk/jcstress/tests/executors/ThreadPoolSizesTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/executors/ThreadPoolSizesTest.java	Mon May 05 19:41:32 2014 +0100
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2014, 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.tests.executors;
+
+import org.openjdk.jcstress.annotations.Actor;
+import org.openjdk.jcstress.annotations.Arbiter;
+import org.openjdk.jcstress.annotations.JCStressTest;
+import org.openjdk.jcstress.annotations.State;
+import org.openjdk.jcstress.infra.results.IntResult2;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+ at JCStressTest
+ at State
+public class ThreadPoolSizesTest {
+
+    public final ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 4, 0L,
+            TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(4));
+
+    @Actor
+    public void actor1() {
+        pool.setCorePoolSize(3);
+    }
+
+    @Actor
+    public void actor2() {
+        try {
+            pool.setMaximumPoolSize(2);
+        } catch (IllegalArgumentException ignore) {}
+    }
+
+    @Arbiter
+    public void actor3(IntResult2 r) {
+        r.r1 = pool.getCorePoolSize();
+        r.r2 = pool.getMaximumPoolSize();
+    }
+}
diff -r 39a1c4786c47 tests-custom/src/main/resources/org/openjdk/jcstress/desc/executors.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests-custom/src/main/resources/org/openjdk/jcstress/desc/executors.xml	Mon May 05 19:41:32 2014 +0100
@@ -0,0 +1,58 @@
+<!--
+
+    Copyright (c) 2014, 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.
+
+-->
+<testsuite>
+
+    <test name="org.openjdk.jcstress.tests.executors.ThreadPoolSizesTest">
+        <contributed-by>Pavel Rappo (pavel.rappo at oracle.com)</contributed-by>
+        <description>
+            Tests if ThreadPoolExecutor invariant can be violated:
+            corePoolSize ≤ maxPoolSize
+        </description>
+        <case>
+            <match>[3, 4]</match>
+            <expect>ACCEPTABLE</expect>
+            <description>
+                corePoolSize had changed, and maxPoolSize failed to change.
+            </description>
+        </case>
+        <case>
+            <match>[3, 2]</match>
+            <expect>ACCEPTABLE_INTERESTING</expect>
+            <description>
+                The update under race can break the (core ≤ maxPool) invariant.
+            </description>
+        </case>
+        <unmatched>
+            <expect>FORBIDDEN</expect>
+            <description>
+                This case is not expected.
+            </description>
+        </unmatched>
+    </test>
+
+
+</testsuite>

-Pavel


More information about the jcstress-dev mailing list