--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp Tue May 07 16:18:21 2019 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp Wed May 15 22:45:54 2019 +0200
@@ -54,6 +54,7 @@
#include "gc/shenandoah/shenandoahPacer.inline.hpp"
#include "gc/shenandoah/shenandoahRootProcessor.hpp"
#include "gc/shenandoah/shenandoahStringDedup.hpp"
+#include "gc/shenandoah/shenandoahTaskqueue.hpp"
#include "gc/shenandoah/shenandoahUtils.hpp"
#include "gc/shenandoah/shenandoahVerifier.hpp"
#include "gc/shenandoah/shenandoahCodeRoots.hpp"
@@ -186,6 +187,18 @@
assert((((size_t) base()) & ShenandoahHeapRegion::region_size_bytes_mask()) == 0,
"Misaligned heap: " PTR_FORMAT, p2i(base()));
+#if SHENANDOAH_OPTIMIZED_OBJTASK
+ // The optimized ObjArrayChunkedTask takes some bits away from the full object bits.
+ // Fail if we ever attempt to address more than we can.
+ if ((uintptr_t)heap_rs.end() >= ObjArrayChunkedTask::max_addressable()) {
+ FormatBuffer<512> buf("Shenandoah reserved [" PTR_FORMAT ", " PTR_FORMAT") for the heap, \n"
+ "but max object address is " PTR_FORMAT ". Try to reduce heap size, or try other \n"
+ "VM options that allocate heap at lower addresses (HeapBaseMinAddress, AllocateHeapAt, etc).",
+ p2i(heap_rs.base()), p2i(heap_rs.end()), ObjArrayChunkedTask::max_addressable());
+ vm_exit_during_initialization("Fatal Error", buf);
+ }
+#endif
+
ReservedSpace sh_rs = heap_rs.first_part(max_byte_size);
if (!_heap_region_special) {
os::commit_memory_or_exit(sh_rs.base(), _initial_size, heap_alignment, false,