changeset 1108:cc769fa31055

7901282: Tighten up the JMH security policies
author shade
date Thu, 29 Jan 2015 13:05:43 +0300
parents ceb8cfe4701d
children 7894c6a321d8
files jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinJVMArgsSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinRunnerSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinJVMArgsSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinRunnerSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinJVMArgsSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinRunnerSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinSecurityManagerTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadSecurityManagerTest.java jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedMain.java jmh-core/src/main/resources/jmh-minimal-runner-security.policy jmh-core/src/main/resources/jmh-minimal-security.policy jmh-core/src/main/resources/jmh-security-minimal.policy jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_33_SecurityManager.java
diffstat 17 files changed, 490 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinJVMArgsSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,71 @@
+/*
+ * 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.jmh.it.security;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Benchmark)
+public class BenchmarkMinJVMArgsSecurityManagerTest {
+
+    @Benchmark
+    @BenchmarkMode(Mode.All)
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
+    @Fork(1)
+    public void test() {
+        Fixtures.work();
+    }
+
+    @Test
+    public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException {
+        URI policyFile = BenchmarkMinJVMArgsSecurityManagerTest.class.getResource("/jmh-minimal-runner-security.policy").toURI();
+
+        Options opts = new OptionsBuilder()
+                .include(Fixtures.getTestMask(this.getClass()))
+                .shouldFailOnError(true)
+                .jvmArgsAppend("-Djava.security.manager", "-Djava.security.policy=" + policyFile.toString())
+                .build();
+        new Runner(opts).run();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinRunnerSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,78 @@
+/*
+ * 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.jmh.it.security;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Policy;
+import java.security.URIParameter;
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Benchmark)
+public class BenchmarkMinRunnerSecurityManagerTest {
+
+    @Benchmark
+    @BenchmarkMode(Mode.All)
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
+    @Fork(1)
+    public void test() {
+        Fixtures.work();
+    }
+
+    @Test
+    public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException {
+        URI policyFile = BenchmarkMinRunnerSecurityManagerTest.class.getResource("/jmh-minimal-runner-security.policy").toURI();
+        Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
+        System.setSecurityManager(new SecurityManager());
+
+        try {
+            Options opts = new OptionsBuilder()
+                    .include(Fixtures.getTestMask(this.getClass()))
+                    .shouldFailOnError(true)
+                    .build();
+            new Runner(opts).run();
+        } finally {
+            System.setSecurityManager(null);
+        }
+    }
+
+}
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinSecurityManagerTest.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkMinSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -54,7 +54,8 @@
 
     @Setup
     public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
-        URI policyFile = BenchmarkMinSecurityManagerTest.class.getResource("/jmh-security-minimal.policy").toURI();
+        Fixtures.work();
+        URI policyFile = BenchmarkMinSecurityManagerTest.class.getResource("/jmh-minimal-security.policy").toURI();
         Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
         System.setSecurityManager(new SecurityManager());
     }
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkSecurityManagerTest.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/BenchmarkSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -54,6 +54,7 @@
 
     @Setup
     public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
+        Fixtures.work();
         URI policyFile = BenchmarkSecurityManagerTest.class.getResource("/jmh-security.policy").toURI();
         Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
         System.setSecurityManager(new SecurityManager());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinJVMArgsSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,75 @@
+/*
+ * 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.jmh.it.security;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Group;
+import org.openjdk.jmh.annotations.GroupThreads;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Group)
+public class GroupMinJVMArgsSecurityManagerTest {
+
+    @Benchmark
+    @BenchmarkMode(Mode.All)
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
+    @Fork(1)
+    @Group("group1")
+    @GroupThreads(2)
+    public void test() {
+        Fixtures.work();
+    }
+
+    @Test
+    public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException {
+        URI policyFile = GroupMinJVMArgsSecurityManagerTest.class.getResource("/jmh-minimal-runner-security.policy").toURI();
+
+        Options opts = new OptionsBuilder()
+                .include(Fixtures.getTestMask(this.getClass()))
+                .shouldFailOnError(true)
+                .jvmArgsAppend("-Djava.security.manager", "-Djava.security.policy=" + policyFile.toString())
+                .build();
+        new Runner(opts).run();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinRunnerSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,82 @@
+/*
+ * 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.jmh.it.security;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Group;
+import org.openjdk.jmh.annotations.GroupThreads;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Policy;
+import java.security.URIParameter;
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Group)
+public class GroupMinRunnerSecurityManagerTest {
+
+    @Benchmark
+    @BenchmarkMode(Mode.All)
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
+    @Fork(1)
+    @Group("group1")
+    @GroupThreads(2)
+    public void test1() {
+        Fixtures.work();
+    }
+
+    @Test
+    public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException {
+        URI policyFile = GroupMinRunnerSecurityManagerTest.class.getResource("/jmh-minimal-runner-security.policy").toURI();
+        Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
+        System.setSecurityManager(new SecurityManager());
+
+        try {
+            Options opts = new OptionsBuilder()
+                    .include(Fixtures.getTestMask(this.getClass()))
+                    .shouldFailOnError(true)
+                    .build();
+            new Runner(opts).run();
+        } finally {
+            System.setSecurityManager(null);
+        }
+    }
+
+}
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinSecurityManagerTest.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupMinSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -56,7 +56,8 @@
 
     @Setup
     public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
-        URI policyFile = GroupMinSecurityManagerTest.class.getResource("/jmh-security-minimal.policy").toURI();
+        Fixtures.work();
+        URI policyFile = GroupMinSecurityManagerTest.class.getResource("/jmh-minimal-security.policy").toURI();
         Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
         System.setSecurityManager(new SecurityManager());
     }
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupSecurityManagerTest.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/GroupSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -56,6 +56,7 @@
 
     @Setup
     public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
+        Fixtures.work();
         URI policyFile = GroupSecurityManagerTest.class.getResource("/jmh-security.policy").toURI();
         Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
         System.setSecurityManager(new SecurityManager());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinJVMArgsSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,71 @@
+/*
+ * 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.jmh.it.security;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Thread)
+public class ThreadMinJVMArgsSecurityManagerTest {
+
+    @Benchmark
+    @BenchmarkMode(Mode.All)
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
+    @Fork(1)
+    public void test() {
+        Fixtures.work();
+    }
+
+    @Test
+    public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException {
+        URI policyFile = ThreadMinJVMArgsSecurityManagerTest.class.getResource("/jmh-minimal-runner-security.policy").toURI();
+
+        Options opts = new OptionsBuilder()
+                .include(Fixtures.getTestMask(this.getClass()))
+                .shouldFailOnError(true)
+                .jvmArgsAppend("-Djava.security.manager", "-Djava.security.policy=" + policyFile.toString())
+                .build();
+        new Runner(opts).run();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinRunnerSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,78 @@
+/*
+ * 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.jmh.it.security;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.it.Fixtures;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Policy;
+import java.security.URIParameter;
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Thread)
+public class ThreadMinRunnerSecurityManagerTest {
+
+    @Benchmark
+    @BenchmarkMode(Mode.All)
+    @Warmup(iterations = 0)
+    @Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
+    @Fork(1)
+    public void test() {
+        Fixtures.work();
+    }
+
+    @Test
+    public void invokeAPI() throws RunnerException, URISyntaxException, NoSuchAlgorithmException {
+        URI policyFile = ThreadMinRunnerSecurityManagerTest.class.getResource("/jmh-minimal-runner-security.policy").toURI();
+        Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
+        System.setSecurityManager(new SecurityManager());
+
+        try {
+            Options opts = new OptionsBuilder()
+                    .include(Fixtures.getTestMask(this.getClass()))
+                    .shouldFailOnError(true)
+                    .build();
+            new Runner(opts).run();
+        } finally {
+            System.setSecurityManager(null);
+        }
+    }
+
+}
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinSecurityManagerTest.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadMinSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -54,7 +54,8 @@
 
     @Setup
     public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
-        URI policyFile = ThreadMinSecurityManagerTest.class.getResource("/jmh-security-minimal.policy").toURI();
+        Fixtures.work();
+        URI policyFile = ThreadMinSecurityManagerTest.class.getResource("/jmh-minimal-security.policy").toURI();
         Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
         System.setSecurityManager(new SecurityManager());
     }
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadSecurityManagerTest.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/security/ThreadSecurityManagerTest.java	Thu Jan 29 13:05:43 2015 +0300
@@ -54,6 +54,7 @@
 
     @Setup
     public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
+        Fixtures.work();
         URI policyFile = ThreadSecurityManagerTest.class.getResource("/jmh-security.policy").toURI();
         Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
         System.setSecurityManager(new SecurityManager());
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedMain.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedMain.java	Thu Jan 29 13:05:43 2015 +0300
@@ -57,6 +57,9 @@
             // arm the hangup thread
             Runtime.getRuntime().addShutdownHook(new HangupThread());
 
+            // init the shutdown thread
+            ShutdownTimeoutThread shutdownThread = new ShutdownTimeoutThread();
+
             try {
                 // This assumes the exact order of arguments:
                 //   1) host name to back-connect
@@ -85,7 +88,7 @@
                 gracefullyFinished = false;
             } finally {
                 // arm the shutdown timer
-                new ShutdownTimeoutThread().start();
+                shutdownThread.start();
             }
 
             if (!gracefullyFinished) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/resources/jmh-minimal-runner-security.policy	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,13 @@
+grant {
+    permission java.lang.RuntimePermission "accessDeclaredMembers";
+    permission java.lang.RuntimePermission "modifyThread";
+    permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
+    permission java.lang.RuntimePermission "setSecurityManager";
+    permission java.lang.RuntimePermission "shutdownHooks";
+    permission java.lang.RuntimePermission "setIO";
+    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
+    permission java.util.PropertyPermission "*", "read";
+    permission java.lang.management.ManagementPermission "monitor";
+    permission java.io.FilePermission "/-", "read,write,execute,delete";
+    permission java.net.SocketPermission "*", "connect,resolve,accept,listen";
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/resources/jmh-minimal-security.policy	Thu Jan 29 13:05:43 2015 +0300
@@ -0,0 +1,4 @@
+grant {
+    permission java.lang.RuntimePermission "modifyThread";
+    permission java.lang.RuntimePermission "setSecurityManager";
+};
\ No newline at end of file
--- a/jmh-core/src/main/resources/jmh-security-minimal.policy	Wed Jan 28 20:46:53 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-grant {
-    permission java.lang.RuntimePermission "accessDeclaredMembers";
-    permission java.lang.RuntimePermission "modifyThread";
-    permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
-    permission java.lang.RuntimePermission "setSecurityManager";
-    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
-    permission java.util.PropertyPermission "*", "read, write";
-    permission java.lang.management.ManagementPermission "monitor";
-    permission java.io.FilePermission "/-", "read,write,execute";
-    permission java.net.SocketPermission "*", "connect,resolve,accept,listen";
-};
\ No newline at end of file
--- a/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_33_SecurityManager.java	Wed Jan 28 20:46:53 2015 +0300
+++ b/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_33_SecurityManager.java	Thu Jan 29 13:05:43 2015 +0300
@@ -69,9 +69,12 @@
      * the SecurityManager is not installed.
      *
      * If you need a restricted security policy for the tests, you are advised to
-     * get /jmh-security-minimal.policy, that contains the minimal permissions
-     * required for JMH to run, merge the new permissions there, produce new
+     * get /jmh-minimal-security.policy, that contains the minimal permissions
+     * required for JMH benchmark to run, merge the new permissions there, produce new
      * policy file in a temporary location, and load that policy file instead.
+     * There is also /jmh-minimal-runner-security.policy, that contains the minimal
+     * permissions for the JMH harness to run, if you want to use JVM args to arm
+     * the SecurityManager.
      */
 
     @State(Scope.Benchmark)