diff --git a/src/hotspot/share/asm/assembler.cpp b/src/hotspot/share/asm/assembler.cpp index 18c7c6b..39337f1 100644 --- a/src/hotspot/share/asm/assembler.cpp +++ b/src/hotspot/share/asm/assembler.cpp @@ -26,6 +26,7 @@ #include "asm/codeBuffer.hpp" #include "asm/macroAssembler.hpp" #include "asm/macroAssembler.inline.hpp" +#include "gc/shared/collectedHeap.hpp" #include "runtime/atomic.hpp" #include "runtime/icache.hpp" #include "runtime/os.hpp" @@ -307,21 +308,25 @@ const char* AbstractAssembler::code_string(const char* str) { return NULL; } -bool MacroAssembler::needs_explicit_null_check(intptr_t offset) { +bool MacroAssembler::uses_implicit_null_check(void* address) { // Exception handler checks the nmethod's implicit null checks table // only when this method returns false. + intptr_t cell_header_size = Universe::heap()->cell_header_size(); + HeapWord* start = (HeapWord*)-cell_header_size; #ifdef _LP64 if (UseCompressedOops && Universe::narrow_oop_base() != NULL) { - assert (Universe::heap() != NULL, "java heap should be initialized"); // The first page after heap_base is unmapped and // the 'offset' is equal to [heap_base + offset] for // narrow oop implicit null checks. - uintptr_t base = (uintptr_t)Universe::narrow_oop_base(); - if ((uintptr_t)offset >= base) { - // Normalize offset for the next check. - offset = (intptr_t)(pointer_delta((void*)offset, (void*)base, 1)); - } + start += (uintptr_t)Universe::narrow_oop_base(); } #endif - return offset < 0 || os::vm_page_size() <= offset; + MemRegion implicit_null_range(start, (os::vm_page_size() + cell_header_size) / HeapWordSize); + return implicit_null_range.contains(address); +} + +bool MacroAssembler::needs_explicit_null_check(intptr_t offset) { + // Check if offset is outside of [-cell_header_size, os::vm_page_size) + return offset < -Universe::heap()->cell_header_size() || + offset >= os::vm_page_size(); }