--- old/src/hotspot/share/runtime/interfaceSupport.cpp 2018-03-22 17:04:15.304830054 +0100 +++ new/src/hotspot/share/runtime/interfaceSupport.cpp 2018-03-22 17:04:15.100830061 +0100 @@ -35,6 +35,7 @@ #include "runtime/orderAccess.inline.hpp" #include "runtime/os.inline.hpp" #include "runtime/thread.inline.hpp" +#include "runtime/safepointVerifiers.hpp" #include "runtime/vframe.hpp" #include "runtime/vmThread.hpp" #include "utilities/preserveException.hpp" @@ -298,3 +299,40 @@ } #endif } + +#ifdef ASSERT +// JRT_LEAF rules: +// A JRT_LEAF method may not interfere with safepointing by +// 1) acquiring or blocking on a Mutex or JavaLock - checked +// 2) allocating heap memory - checked +// 3) executing a VM operation - checked +// 4) executing a system call (including malloc) that could block or grab a lock +// 5) invoking GC +// 6) reaching a safepoint +// 7) running too long +// Nor may any method it calls. +JRTLeafVerifier::JRTLeafVerifier() + : NoSafepointVerifier(true, JRTLeafVerifier::should_verify_GC()) +{ +} + +JRTLeafVerifier::~JRTLeafVerifier() +{ +} + +bool JRTLeafVerifier::should_verify_GC() { + switch (JavaThread::current()->thread_state()) { + case _thread_in_Java: + // is in a leaf routine, there must be no safepoint. + return true; + case _thread_in_native: + // A native thread is not subject to safepoints. + // Even while it is in a leaf routine, GC is ok + return false; + default: + // Leaf routines cannot be called from other contexts. + ShouldNotReachHere(); + return false; + } +} +#endif