Please sign in to comment.
rework VM exception handling; throw OOMEs when appropriate
This rather large commit modifies the VM to use non-local returns to throw exceptions instead of simply setting Thread::exception and returning frame-by-frame as it used to. This has several benefits: * Functions no longer need to check Thread::exception after each call which might throw an exception (which would be especially tedious and error-prone now that any function which allocates objects directly or indirectly might throw an OutOfMemoryError) * There's no need to audit the code for calls to functions which previously did not throw exceptions but later do * Performance should be improved slightly due to both the reduced need for conditionals and because undwinding now occurs in a single jump instead of a series of returns The main disadvantages are: * Slightly higher overhead for entering and leaving the VM via the JNI and JDK methods * Non-local returns can make the code harder to read * We must be careful to register destructors for stack-allocated resources with the Thread so they can be called prior to a non-local return The non-local return implementation is similar to setjmp/longjmp, except it uses continuation-passing style to avoid the need for cooperation from the C/C++ compiler. Native C++ exceptions would have also been an option, but that would introduce a dependence on libstdc++, which we're trying to avoid for portability reasons. Finally, this commit ensures that the VM throws an OutOfMemoryError instead of aborting when it reaches its memory ceiling. Currently, we treat the ceiling as a soft limit and temporarily exceed it as necessary to allow garbage collection and certain internal allocations to succeed, but refuse to allocate any Java objects until the heap size drops back below the ceiling.
- Loading branch information...
Showing with 2,148 additions and 1,288 deletions.
- +32 −14 src/bootimage.cpp
- +11 −20 src/builtin.cpp
- +24 −24 src/classpath-avian.cpp
- +16 −15 src/classpath-common.h
- +513 −311 src/classpath-openjdk.cpp
- +2 −2 src/compile-x86.S
- +230 −318 src/compile.cpp
- +8 −8 src/continuations-x86.S
- +23 −8 src/heap.cpp
- +1 −0 src/heap.h
- +122 −143 src/interpret.cpp
- +443 −178 src/jnienv.cpp
- +213 −156 src/machine.cpp
- +314 −76 src/machine.h
- +7 −14 src/process.cpp
- +127 −1 src/x86.S
- +62 −0 test/OutOfMemory.java
Oops, something went wrong.