RFC: add RuntimePermission("explicitGC")
rocketraman at fastmail.fm
Sun Dec 7 15:54:54 UTC 2008
Currently, it is possible for code to request scheduling GC via the
Runtime.getRuntime().gc() or System.gc() method.
This method is often not desirable to execute on modern JVMs with
sophisticated GC algorithms, and so explicit GC is often disabled by
customers via the "-XX:+DisableExplicitGC" JVM flag.
See the following bug report for some background:
While I agree with the evaluation in the report that the
DisableExplicitGC behavior cannot be made the default, the reality is
there are still libraries that call this method unnecessarily and
perhaps even at undocumented times.
There is also code that has valid reasons to call it:
- test suites (mentioned in 6200079)
- distributed RMI GC
- application code scheduling GC at off-peak times
and so forth.
Therefore, I propose a simple change. Add a RuntimePermission called
"explicitGC". Check this permission before calling the VM's gc method.
Optionally, modify the signature of Runtime.getRuntime().gc() and
System.gc() to return a boolean to indicate to the user whether the gc
method was successfully called or not. This API change would add
feedback on the results of the permission check while being backward
compatible (though binary compatibility would be broken so this likely
cannot be done).
The default permissions file distributed with the JDK/JRE would give
all code access to gc(), thereby not changing the current behavior for
any existing installations.
Thank you for your feedback.
More information about the core-libs-dev