Reorganize micro sources (classes/resources), add tests using resources as a PoC JEP-230-microbenchmarks-branch
authorredestad
Fri, 05 Oct 2018 18:24:15 +0200
branchJEP-230-microbenchmarks-branch
changeset 56930 079075866d11
parent 56929 b8756e94db7a
child 56936 923f1356c5ea
Reorganize micro sources (classes/resources), add tests using resources as a PoC
make/autoconf/lib-tests.m4
make/test/BuildMicrobenchmark.gmk
test/micro/classes/org/openjdk/bench/java/lang/ArrayCopy.java
test/micro/classes/org/openjdk/bench/java/lang/reflect/Clazz.java
test/micro/classes/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java
test/micro/org/openjdk/bench/java/lang/ArrayCopy.java
test/micro/org/openjdk/bench/java/lang/reflect/Clazz.java
test/micro/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java
test/micro/resources/org/openjdk/bench/java/security/security.policy
--- a/make/autoconf/lib-tests.m4	Fri Oct 05 15:14:31 2018 +0200
+++ b/make/autoconf/lib-tests.m4	Fri Oct 05 18:24:15 2018 +0200
@@ -69,7 +69,7 @@
     AC_MSG_RESULT([no, disabled])
   elif test "x$with_jmh" = xyes; then
     AC_MSG_RESULT([no, error])
-    AC_MSG_ERROR([--with-jmh-home requires a directory containing all jars needed by JMH])
+    AC_MSG_ERROR([--with-jmh requires a directory containing all jars needed by JMH])
   else
     # Path specified
     JMH_HOME="$with_jmh"
--- a/make/test/BuildMicrobenchmark.gmk	Fri Oct 05 15:14:31 2018 +0200
+++ b/make/test/BuildMicrobenchmark.gmk	Fri Oct 05 18:24:15 2018 +0200
@@ -38,7 +38,8 @@
 
 #### Variables
 
-MICROBENCHMARK_SRC := $(TOPDIR)/test/micro
+MICROBENCHMARK_SRC := $(TOPDIR)/test/micro/classes
+MICROBENCHMARK_RES := $(TOPDIR)/test/micro/resources
 MICROBENCHMARK_JAR := $(IMAGES_OUTPUTDIR)/test/micro/microbenchmarks.jar
 
 MICROBENCHMARK_OUTPUT := $(SUPPORT_OUTPUTDIR)/test/micro
@@ -98,7 +99,7 @@
 # Create benchmarks JAR file with benchmarks for both the old and new JDK
 $(eval $(call SetupJarArchive, BUILD_JDK_JAR, \
     DEPENDENCIES := $(BUILD_JDK_MICROBENCHMARK) $(JMH_UNPACKED_JARS_DONE), \
-    SRCS := $(MICROBENCHMARK_CLASSES) $(JMH_UNPACKED_DIR), \
+    SRCS := $(MICROBENCHMARK_CLASSES) $(JMH_UNPACKED_DIR) $(MICROBENCHMARK_RES), \
     BIN := $(MICROBENCHMARK_JAR_BIN), \
     SUFFIXES := .*, \
     EXCLUDE_FILES:= _the.BUILD_JDK_MICROBENCHMARK_batch \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/classes/org/openjdk/bench/java/lang/ArrayCopy.java	Fri Oct 05 18:24:15 2018 +0200
@@ -0,0 +1,182 @@
+/*
+ * 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.bench.java.lang;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OperationsPerInvocation;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Benchmark measuring System.arraycopy in different ways.
+ */
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+public class ArrayCopy {
+
+    private static final byte[] TEST_BYTES = "HTTP/1.0".getBytes();
+    private static final char[] TEST_CHARS = new char[46];
+    private static final Object[] TEST_OBJECTS = new Object[200];  // Uses a minimum of 160 internal positions for internal copying
+
+    // a length which the compiler cannot prove is a constant
+    public static int nonConstCharLength = TEST_CHARS.length;
+    public static int nonConstByteLength = TEST_BYTES.length;
+    public static int nonConstObjectLength = TEST_OBJECTS.length;
+
+    // Use this array to copy objects in.
+    public char[] dummyCharArray = new char[TEST_CHARS.length];
+    public byte[] dummyByteArray = new byte[TEST_BYTES.length];
+    public Object[] dummyObjectArray = new Object[TEST_OBJECTS.length];
+
+    @Setup
+    public void setup() {
+        for (int i = 0; i < TEST_OBJECTS.length; i++) {
+            TEST_OBJECTS[i] = new Object();
+            dummyObjectArray[i] = new Object();
+        }
+    }
+
+    /**
+     * This test case do the same work as testArrayCopy. We should make sure
+     * testArrayCopy is equally fast or better. Compare the two and you measure
+     * the system call versus explicit copy for-loop.
+     */
+    @Benchmark
+    public void copyLoop() {
+        for (int j = 0; j < dummyByteArray.length; j++) {
+            dummyByteArray[j] = TEST_BYTES[j];
+        }
+    }
+
+    /**
+     * Test that we can optimize away the code since it should not have any side
+     * effects
+     */
+    @Benchmark
+    public void copyLoopLocalArray() {
+        byte[] localDummyByteArray = new byte[TEST_BYTES.length];
+        for (int j = 0; j < localDummyByteArray.length; j++) {
+            localDummyByteArray[j] = TEST_BYTES[j];
+        }
+    }
+
+    /**
+     * This test case do the same work as testArrayCopy. We should make sure
+     * testArrayCopy is equally fast or better. Compare the two and you measure
+     * the system call versus explicit copy for-loop.
+     * <p/>
+     * Uses non-provable constant length.
+     */
+    @Benchmark
+    public void copyLoopNonConst() {
+        for (int i = 0; i < nonConstByteLength; i++) {
+            dummyByteArray[i] = TEST_BYTES[i];
+        }
+    }
+
+    /**
+     * This test case do the same work as testCopyLoop. We should make sure
+     * testArrayCopy is equally fast or better. Compare the two and you measure
+     * the system call versus explicit copy for-loop.
+     */
+    @Benchmark
+    public void arrayCopy() {
+        System.arraycopy(TEST_BYTES, 0, dummyByteArray, 0, dummyByteArray.length);
+    }
+
+    /**
+     * Test that we can optimize away the code since it should not have any side
+     * effects
+     */
+    @Benchmark
+    public void arrayCopyLocalArray() {
+        byte[] localDummyByteArray = new byte[TEST_BYTES.length];
+        System.arraycopy(TEST_BYTES, 0, localDummyByteArray, 0, localDummyByteArray.length);
+    }
+
+    /**
+     * This test case do the same work as testCopyLoop. We should make sure
+     * testArrayCopy is equally fast or better. Compare the two and you measure
+     * the system call versus explicit copy for-loop.
+     * <p/>
+     * Uses non-provable constant length.
+     */
+    @Benchmark
+    public void arrayCopyNonConst() {
+        System.arraycopy(TEST_BYTES, 0, dummyByteArray, 0, nonConstByteLength);
+    }
+
+    @Benchmark
+    public void arrayCopyChar() {
+        System.arraycopy(TEST_CHARS, 0, dummyCharArray, 0, dummyCharArray.length);
+    }
+
+    @Benchmark
+    public void arrayCopyCharNonConst() {
+        System.arraycopy(TEST_CHARS, 0, dummyCharArray, 0, nonConstCharLength);
+    }
+
+    @Benchmark
+    public void arrayCopyObject() {
+        System.arraycopy(TEST_OBJECTS, 0, dummyObjectArray, 0, dummyObjectArray.length);
+    }
+
+    @Benchmark
+    public void arrayCopyObjectNonConst() {
+        System.arraycopy(TEST_OBJECTS, 0, dummyObjectArray, 0, nonConstObjectLength);
+    }
+
+    /**
+     * This test copies inside a object array, that is same source array as dest
+     * array. Copies backwards in the array.
+     */
+    @Benchmark
+    @OperationsPerInvocation(40)
+    public void arrayCopyObjectSameArraysBackward() {
+        for (int i = 0; i < 40; i++) {
+            System.arraycopy(dummyObjectArray, i, dummyObjectArray, i + 40, 80);
+        }
+    }
+
+    /**
+     * This test copies inside a object array, that is same source array as dest
+     * array. Copies forward in the array. There is a special version for this
+     * in JRockit.
+     */
+    @Benchmark
+    @OperationsPerInvocation(40)
+    public void arrayCopyObjectSameArraysForward() {
+        for (int i = 0; i < 40; i++) {
+            System.arraycopy(dummyObjectArray, i + 40, dummyObjectArray, i, 80);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/classes/org/openjdk/bench/java/lang/reflect/Clazz.java	Fri Oct 05 18:24:15 2018 +0200
@@ -0,0 +1,84 @@
+/*
+ * 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.bench.java.lang.reflect;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+public class Clazz {
+
+    /**
+     * Get constructor for this class through reflection
+     *
+     * @return
+     * @throws NoSuchMethodException
+     */
+    @Benchmark
+    public Constructor getConstructor() throws NoSuchMethodException {
+        return Clazz.class.getConstructor();
+    }
+
+    /**
+     * Get constructor for the String class through reflection, forcing full
+     * security check
+     *
+     * @return
+     * @throws NoSuchMethodException
+     */
+    @Benchmark
+    public Constructor getConstructorDifferentClassLoader() throws NoSuchMethodException {
+        return String.class.getConstructor();
+    }
+
+    /**
+     * Get the toString method through reflection on Clazz
+     *
+     * @return
+     */
+    @Benchmark
+    public Method getMethod() throws NoSuchMethodException {
+        return Clazz.class.getMethod("toString");
+    }
+
+    /**
+     * Get the toString method through reflection on String, forcing full
+     * security check
+     *
+     * @return
+     * @throws NoSuchMethodException
+     */
+    @Benchmark
+    public Method getMethodDifferentClassLoader() throws NoSuchMethodException {
+        return String.class.getMethod("toString");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/classes/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java	Fri Oct 05 18:24:15 2018 +0200
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2014, 2018 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.bench.java.lang.reflect;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.security.NoSuchAlgorithmException;
+import java.security.Policy;
+import java.security.URIParameter;
+
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/**
+ * Reflection benchmark
+ */
+@State(Scope.Benchmark)
+public class ClazzWithSecurityManager extends Clazz {
+
+    private static Policy originalPolicy;
+    private static SecurityManager originalSM;
+
+    @Setup
+    public void setup() throws IOException, NoSuchAlgorithmException {
+
+        originalPolicy = Policy.getPolicy();
+        originalSM = System.getSecurityManager();
+
+        File policyFile = File.createTempFile("security", "policy");
+        policyFile.deleteOnExit();
+
+        PrintWriter writer = new PrintWriter(policyFile);
+        BufferedReader reader = new BufferedReader(new InputStreamReader(
+                ClazzWithSecurityManager.class.getResourceAsStream("/org/openjdk/bench/java/security/security.policy")));
+        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+            System.out.println("Adding " + line);
+            writer.write(line);
+        }
+        reader.close();
+        writer.close();
+
+        Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI()));
+        Policy.setPolicy(policy);
+        System.setSecurityManager(new SecurityManager());
+    }
+
+    @TearDown
+    public void tearDown() {
+        Policy.setPolicy(originalPolicy);
+        System.setSecurityManager(originalSM);
+    }
+}
--- a/test/micro/org/openjdk/bench/java/lang/ArrayCopy.java	Fri Oct 05 15:14:31 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +0,0 @@
-/*
- * 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.bench.java.lang;
-
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OperationsPerInvocation;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Benchmark measuring System.arraycopy in different ways.
- */
-@BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.NANOSECONDS)
-@State(Scope.Thread)
-public class ArrayCopy {
-
-    private static final byte[] TEST_BYTES = "HTTP/1.0".getBytes();
-    private static final char[] TEST_CHARS = new char[46];
-    private static final Object[] TEST_OBJECTS = new Object[200];  // Uses a minimum of 160 internal positions for internal copying
-
-    // a length which the compiler cannot prove is a constant
-    public static int nonConstCharLength = TEST_CHARS.length;
-    public static int nonConstByteLength = TEST_BYTES.length;
-    public static int nonConstObjectLength = TEST_OBJECTS.length;
-
-    // Use this array to copy objects in.
-    public char[] dummyCharArray = new char[TEST_CHARS.length];
-    public byte[] dummyByteArray = new byte[TEST_BYTES.length];
-    public Object[] dummyObjectArray = new Object[TEST_OBJECTS.length];
-
-    @Setup
-    public void setup() {
-        for (int i = 0; i < TEST_OBJECTS.length; i++) {
-            TEST_OBJECTS[i] = new Object();
-            dummyObjectArray[i] = new Object();
-        }
-    }
-
-    /**
-     * This test case do the same work as testArrayCopy. We should make sure
-     * testArrayCopy is equally fast or better. Compare the two and you measure
-     * the system call versus explicit copy for-loop.
-     */
-    @Benchmark
-    public void copyLoop() {
-        for (int j = 0; j < dummyByteArray.length; j++) {
-            dummyByteArray[j] = TEST_BYTES[j];
-        }
-    }
-
-    /**
-     * Test that we can optimize away the code since it should not have any side
-     * effects
-     */
-    @Benchmark
-    public void copyLoopLocalArray() {
-        byte[] localDummyByteArray = new byte[TEST_BYTES.length];
-        for (int j = 0; j < localDummyByteArray.length; j++) {
-            localDummyByteArray[j] = TEST_BYTES[j];
-        }
-    }
-
-    /**
-     * This test case do the same work as testArrayCopy. We should make sure
-     * testArrayCopy is equally fast or better. Compare the two and you measure
-     * the system call versus explicit copy for-loop.
-     * <p/>
-     * Uses non-provable constant length.
-     */
-    @Benchmark
-    public void copyLoopNonConst() {
-        for (int i = 0; i < nonConstByteLength; i++) {
-            dummyByteArray[i] = TEST_BYTES[i];
-        }
-    }
-
-    /**
-     * This test case do the same work as testCopyLoop. We should make sure
-     * testArrayCopy is equally fast or better. Compare the two and you measure
-     * the system call versus explicit copy for-loop.
-     */
-    @Benchmark
-    public void arrayCopy() {
-        System.arraycopy(TEST_BYTES, 0, dummyByteArray, 0, dummyByteArray.length);
-    }
-
-    /**
-     * Test that we can optimize away the code since it should not have any side
-     * effects
-     */
-    @Benchmark
-    public void arrayCopyLocalArray() {
-        byte[] localDummyByteArray = new byte[TEST_BYTES.length];
-        System.arraycopy(TEST_BYTES, 0, localDummyByteArray, 0, localDummyByteArray.length);
-    }
-
-    /**
-     * This test case do the same work as testCopyLoop. We should make sure
-     * testArrayCopy is equally fast or better. Compare the two and you measure
-     * the system call versus explicit copy for-loop.
-     * <p/>
-     * Uses non-provable constant length.
-     */
-    @Benchmark
-    public void arrayCopyNonConst() {
-        System.arraycopy(TEST_BYTES, 0, dummyByteArray, 0, nonConstByteLength);
-    }
-
-    @Benchmark
-    public void arrayCopyChar() {
-        System.arraycopy(TEST_CHARS, 0, dummyCharArray, 0, dummyCharArray.length);
-    }
-
-    @Benchmark
-    public void arrayCopyCharNonConst() {
-        System.arraycopy(TEST_CHARS, 0, dummyCharArray, 0, nonConstCharLength);
-    }
-
-    @Benchmark
-    public void arrayCopyObject() {
-        System.arraycopy(TEST_OBJECTS, 0, dummyObjectArray, 0, dummyObjectArray.length);
-    }
-
-    @Benchmark
-    public void arrayCopyObjectNonConst() {
-        System.arraycopy(TEST_OBJECTS, 0, dummyObjectArray, 0, nonConstObjectLength);
-    }
-
-    /**
-     * This test copies inside a object array, that is same source array as dest
-     * array. Copies backwards in the array.
-     */
-    @Benchmark
-    @OperationsPerInvocation(40)
-    public void arrayCopyObjectSameArraysBackward() {
-        for (int i = 0; i < 40; i++) {
-            System.arraycopy(dummyObjectArray, i, dummyObjectArray, i + 40, 80);
-        }
-    }
-
-    /**
-     * This test copies inside a object array, that is same source array as dest
-     * array. Copies forward in the array. There is a special version for this
-     * in JRockit.
-     */
-    @Benchmark
-    @OperationsPerInvocation(40)
-    public void arrayCopyObjectSameArraysForward() {
-        for (int i = 0; i < 40; i++) {
-            System.arraycopy(dummyObjectArray, i + 40, dummyObjectArray, i, 80);
-        }
-    }
-}
--- a/test/micro/org/openjdk/bench/java/lang/reflect/Clazz.java	Fri Oct 05 15:14:31 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/*
- * 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.bench.java.lang.reflect;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.concurrent.TimeUnit;
-
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-
-@BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.NANOSECONDS)
-public class Clazz {
-
-    /**
-     * Get constructor for this class through reflection
-     *
-     * @return
-     * @throws NoSuchMethodException
-     */
-    @Benchmark
-    public Constructor getConstructor() throws NoSuchMethodException {
-        return Clazz.class.getConstructor();
-    }
-
-    /**
-     * Get constructor for the String class through reflection, forcing full
-     * security check
-     *
-     * @return
-     * @throws NoSuchMethodException
-     */
-    @Benchmark
-    public Constructor getConstructorDifferentClassLoader() throws NoSuchMethodException {
-        return String.class.getConstructor();
-    }
-
-    /**
-     * Get the toString method through reflection on Clazz
-     *
-     * @return
-     */
-    @Benchmark
-    public Method getMethod() throws NoSuchMethodException {
-        return Clazz.class.getMethod("toString");
-    }
-
-    /**
-     * Get the toString method through reflection on String, forcing full
-     * security check
-     *
-     * @return
-     * @throws NoSuchMethodException
-     */
-    @Benchmark
-    public Method getMethodDifferentClassLoader() throws NoSuchMethodException {
-        return String.class.getMethod("toString");
-    }
-}
--- a/test/micro/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java	Fri Oct 05 15:14:31 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*
- * 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.bench.java.lang.reflect;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.security.NoSuchAlgorithmException;
-import java.security.Policy;
-import java.security.URIParameter;
-
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-
-/**
- * Reflection benchmark
- *
- * @author sfriberg
- */
-@State(Scope.Benchmark)
-public class ClazzWithSecurityManager extends Clazz {
-
-    @Setup
-    public void setup() throws IOException, NoSuchAlgorithmException {
-        File policyFile = File.createTempFile("security", "policy");
-        policyFile.deleteOnExit();
-
-        PrintWriter writer = new PrintWriter(policyFile);
-        BufferedReader reader = new BufferedReader(new InputStreamReader(
-                ClazzWithSecurityManager.class.getResourceAsStream("/org/openjdk/bench/java/security/security.policy")));
-        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
-            writer.write(line);
-        }
-        reader.close();
-        writer.close();
-
-        Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI()));
-        Policy.setPolicy(policy);
-        System.setSecurityManager(new SecurityManager());
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/resources/org/openjdk/bench/java/security/security.policy	Fri Oct 05 18:24:15 2018 +0200
@@ -0,0 +1,37 @@
+//    Copyright (c) 2014, 2017 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.
+grant {
+    permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
+    permission java.lang.RuntimePermission "accessDeclaredMembers";
+    permission java.lang.RuntimePermission "createSecurityManager";
+    permission java.lang.RuntimePermission "getProtectionDomain";
+    permission java.lang.RuntimePermission "modifyThread";
+    permission java.lang.RuntimePermission "setSecurityManager";
+    permission java.security.SecurityPermission "createPolicy.JavaPolicy";
+    permission java.security.SecurityPermission "setPolicy";
+    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,delete";
+    permission java.net.SocketPermission "*", "connect,resolve,accept,listen";
+};
\ No newline at end of file