JDK-8130289 : SecurityManager being mutable impedes the optimization of Class.getClassLoader
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2015-07-01
  • Updated: 2017-11-09
  • Resolved: 2017-11-09
Related Reports
Duplicate :  
Relates :  
Class.getClassLoader() can't be trivially intrinsified because of the SecurityManager.

This issue is to track the idea that Christian Thalinger has (see JDK-6642881) to replace the System.security field with a VolatileCallSite.  Combined with intrinsification of Class.getClassLoader() (or better moving the class loader field up into Java) we could constant fold two security related checks. 

Attachd patch [1] is not working properly yet because of bootstrapping issues but the idea is that CallSite optimizations in the JIT compilers can constant fold the System.getSecurityManager() call. 

[1] https://bugs.openjdk.java.net/secure/attachment/18729/system-getsecuritymanager.patch
A better approach is proposed and so close this as a dup of JDK-8191053.

I guess I could fabricate one but I don't have one, no. In theory if the JVM is run without a security manager and the check can be folded by the compiler performance for methods that do have a security manager check should perform better.

[~twisti] can you please provide a benchmark that shows this patch improve the peak performance as you expected? Startup performance is also critical and the startup regression has to be justified.

I'm sure there is a startup overhead but the motivation for this optimization is not to improve startup performance but peak performance.

I have prototyped the use of VolatileCallSite: http://cr.openjdk.java.net/~mchung/jdk10/webrevs/8130289/webrev.00/ This initializes the VolatileCallSite before the module system initialization (it should be separated from initPhase2 but this version temporarily does it for performance measurement purpose). The thought behind is that after the compiler starts up, VolatileCallSite with null target can help JIT to optimize the code (that may help the module system initialization). However the first time constructing VolatileCallSite object starts java.lang.invoke and java.lang.ref.Cleaner machinery that causes 58 additional classes to be loaded. This startup overhead impacts all applications and does not seem to give a big enough gain to offset the startup cost.

Btw. JDK-6642881 moved the class loader field into Java so implementing this Enhancement would be much easier now.