2 ms·
The JEP has an appendix with code implementing a Java agent (code that intercepts the JVM whenever it tries to load any class; it may simply inspect the class,
by akoboldfrying 2y ago
The JEP has an appendix with code implementing a Java agent (code that intercepts the JVM whenever it tries to load any class; it may simply inspect the class, but can optionally transform it or even generate bytecode on the fly) that modifies classes to replace calls to System::exit() with exceptions: https://openjdk.org/jeps/486#Appendix https://openjdk.org/jeps/486#Appendix. This could be generalised to create a sandbox.
That code (which I haven't read) uses some new system library to manipulate the bytecode, though the asm library would be my choice.
It will be some work. The main thing is to make sure you detect all the ways the methods can be called -- directly (this may be via the invokedynamic instruction, or not), or using reflection.
(Or maybe someone has already had this idea and implemented it!)