Seans workaround for comments in the policy file JEP-230-microbenchmarks-branch
authorecaspole
Fri, 05 Oct 2018 17:01:07 -0400
branchJEP-230-microbenchmarks-branch
changeset 56936 923f1356c5ea
parent 56930 079075866d11
child 56944 96ecae6d8049
Seans workaround for comments in the policy file
test/micro/classes/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java
--- a/test/micro/classes/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java	Fri Oct 05 18:24:15 2018 +0200
+++ b/test/micro/classes/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java	Fri Oct 05 17:01:07 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -36,23 +36,17 @@
 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
+ *
+ * @author sfriberg
  */
 @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();
 
@@ -60,8 +54,7 @@
         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);
+            writer.println(line);
         }
         reader.close();
         writer.close();
@@ -70,10 +63,4 @@
         Policy.setPolicy(policy);
         System.setSecurityManager(new SecurityManager());
     }
-
-    @TearDown
-    public void tearDown() {
-        Policy.setPolicy(originalPolicy);
-        System.setSecurityManager(originalSM);
-    }
 }