I have some empirical evidence to contribute here, after implementing the security manager question:
A java SecurityManager that is identical to NO security manager except for a single check adjustment for System.exit
The performance impact with this anonymous inner class was HUGE:
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
return; // no security manager behaviour
}
@Override
public void checkPermission(Permission perm, Object context) {
return; // no security manager behaviour
}
@Override
public void checkExit(int status) {
Thread.dumpStack();
super.checkExit(status);
}
});
My experience after launching my application in Eclipse was that it was visibly slower and I confirmed the same in a colleague's PC.
So I feel that 'negligible' may be an understatement (and my use case does not even actually perform any checks!). Consider this as an anecdote that this is not the case.
As another side note: I created a final class with do-nothing checks for ALL methods to avoid instantiating permission objects and such (end encourage the jit compiler to hot-wire it). Using this approach, the performance impact was indeed minimal. So, for people that simply want to add a couple of specific checks (and not rely on java policies) this actually does have negligible impact:
public final class SystemExitTraceSecurityManager extends SecurityManager {
@Override
public final void checkAccept(String host, int port) {
}
@Override
public final void checkAccess(Thread t) {
}
@Override
public final void checkAccess(ThreadGroup g) {
}
@Override
public final void checkAwtEventQueueAccess() {
}
@Override
public final void checkConnect(String host, int port) {
}
@Override
public final void checkConnect(String host, int port, Object context) {
}
@Override
public final void checkCreateClassLoader() {
}
public final void checkDelete(String file) {
};
@Override
public final void checkExec(String cmd) {
}
public final void checkExit(int status) {
Thread.dumpStack();
};
@Override
public final void checkLink(String lib) {
}
@Override
public final void checkListen(int port) {
}
@Override
public final void checkMemberAccess(Class<?> clazz, int which) {
}
@Override
public final void checkMulticast(InetAddress maddr) {
}
@Override
public final void checkMulticast(InetAddress maddr, byte ttl) {
}
@Override
public final void checkPackageAccess(String pkg) {
}
@Override
public final void checkPackageDefinition(String pkg) {
}
@Override
public final void checkPermission(Permission perm) {
}
@Override
public final void checkPermission(Permission perm, Object context) {
}
@Override
public final void checkPrintJobAccess() {
}
@Override
public final void checkPropertiesAccess() {
}
public final void checkPropertyAccess(String key) {
};
@Override
public final void checkRead(FileDescriptor fd) {
}
@Override
public final void checkRead(String file) {
}
@Override
public final void checkRead(String file, Object context) {
}
@Override
public final void checkSecurityAccess(String target) {
}
@Override
public final void checkSetFactory() {
}
@Override
public final void checkSystemClipboardAccess() {
}
@Override
public final boolean checkTopLevelWindow(Object window) {
return true;
}
@Override
public final void checkWrite(FileDescriptor fd) {
}
@Override
public final void checkWrite(String file) {
}
}