|
39 | 39 | #include "runtime/thread.hpp" |
40 | 40 | #include "runtime/threadSMR.hpp" |
41 | 41 | #include "runtime/vmThread.hpp" |
| 42 | +#include "utilities/debug.hpp" |
42 | 43 |
|
43 | 44 | static size_t mmtk_start_the_world_count = 0; |
44 | 45 |
|
@@ -131,6 +132,25 @@ static void mmtk_block_for_gc() { |
131 | 132 | log_debug(gc)("Thread (id=%d) resumed after GC finished.", Thread::current()->osthread()->thread_id()); |
132 | 133 | } |
133 | 134 |
|
| 135 | +static void mmtk_out_of_memory(void* tls, MMTkAllocationError err_kind) { |
| 136 | + switch (err_kind) { |
| 137 | + case HeapOutOfMemory : |
| 138 | + // Note that we have to do nothing for the case that the Java heap is too small. Since mmtk-core already |
| 139 | + // returns a nullptr back to the JVM, it automatically triggers an OOM exception since the JVM checks for |
| 140 | + // OOM every (slowpath) allocation [1]. In fact, if we report and throw an OOM exception here, the VM will |
| 141 | + // complain since a pending exception bit was already set when it was trying to check for OOM [2]. Hence, |
| 142 | + // it is best to let the JVM take care of reporting OOM itself. |
| 143 | + // |
| 144 | + // [1]: https://github.com/mmtk/openjdk/blob/e4dbe9909fa5c21685a20a1bc541fcc3b050dac4/src/hotspot/share/gc/shared/memAllocator.cpp#L83 |
| 145 | + // [2]: https://github.com/mmtk/openjdk/blob/e4dbe9909fa5c21685a20a1bc541fcc3b050dac4/src/hotspot/share/gc/shared/memAllocator.cpp#L117 |
| 146 | + break; |
| 147 | + case MmapOutOfMemory : |
| 148 | + // Abort the VM immediately due to insufficient system resources. |
| 149 | + vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "MMTk: Unable to acquire more memory from the OS. Out of system resources."); |
| 150 | + break; |
| 151 | + } |
| 152 | +} |
| 153 | + |
134 | 154 | static void* mmtk_get_mmtk_mutator(void* tls) { |
135 | 155 | return (void*) &((Thread*) tls)->third_party_heap_mutator; |
136 | 156 | } |
@@ -304,6 +324,7 @@ OpenJDK_Upcalls mmtk_upcalls = { |
304 | 324 | mmtk_resume_mutators, |
305 | 325 | mmtk_spawn_collector_thread, |
306 | 326 | mmtk_block_for_gc, |
| 327 | + mmtk_out_of_memory, |
307 | 328 | mmtk_get_next_mutator, |
308 | 329 | mmtk_reset_mutator_iterator, |
309 | 330 | mmtk_compute_static_roots, |
|
0 commit comments