How to run a benchmark with SecurityManager?
Staffan Friberg
staffan.friberg at oracle.com
Tue Jan 27 18:34:32 UTC 2015
Hi,
I have done a couple of benchmarks where I wanted to compare the
performance with and without a security manager.
Since I wanted to compare I create a class with all benchmarks, which I
then sub-classed and in the sub-class I added the following setup method.
If you only care to run the benchmark with a security manager you can
probably skip the sub-class part and simply add the setup method.
@Setup
public void setup() throws IOException, NoSuchAlgorithmException {
File policyFile = File.createTempFile("security", ".policy");
policyFile.deleteOnExit();
try (PrintWriter writer = new PrintWriter(policyFile);
BufferedReader reader = new BufferedReader(new
InputStreamReader(
this.getclass().getResourceAsStream("security.policy")))) {
for (String line = reader.readLine(); line != null; line =
reader.readLine()) {
writer.write(line);
}
}
Policy policy = Policy.getInstance("JavaPolicy", new
URIParameter(policyFile.toURI()));
Policy.setPolicy(policy);
System.setSecurityManager(new SecurityManager());
}
//Staffan
On 01/27/2015 07:50 AM, Weijun Wang wrote:
> Yes, it works. See my push at
> http://sca00bkv.us.oracle.com:8000/jdk9/secperf/jdk/rev/603dd9f84399212a7d48fc3d7589d98e85dec820.
>
> But the worst thing now is that system properties must be provided on
> the command line and it means we cannot run multiple benchmark methods
> in one command. (Suppose the other methods must run without a security
> manager).
>
> --Max
>
> On 1/27/2015 20:53, Sean Mullan wrote:
>> Have you tried granting the permissions that jmh needs in your policy
>> file?
>>
>> --Sean
>>
>> On 01/27/2015 05:52 AM, Wang Weijun wrote:
>>> Hi All
>>>
>>> I'm trying to benchmark a method that works differently when a
>>> SecurityManager is on (and with different policy files). I've tried
>>> adding -Djava.security.manager on the command line or calling
>>> System.setSecurityManager(new SecurityManager()) inside a @Setup
>>> method, but seems jmh itself cannot run correctly (because it needs
>>> reflection and thread group manipulation).
>>>
>>> Is there anyway to do it? Since JM itself and the benchmark is
>>> compiled into one jar, I cannot grant AllPermission to jmh and less
>>> permission on my own code.
>>>
>>> Thanks
>>> Max
>>>
More information about the jmh-dev
mailing list