Skip to content
Permalink
Browse files
8253063: ScopedAccessError is sometimes thrown spuriously
Reviewed-by: eosterlund, psandoz
  • Loading branch information
mcimadamore committed Sep 14, 2020
1 parent 16f0b44 commit 1cc7a78a8d402fb18cf817f7482ff1bcabb538be
@@ -638,6 +638,7 @@ address Runtime1::exception_handler_for_pc(JavaThread* thread) {
{
// Enter VM mode by calling the helper
ResetNoHandleMark rnhm;
ExceptionHandlingMark ehm(thread);
continuation = exception_handler_for_pc_helper(thread, exception, pc, nm);
}
// Back in JAVA, use no oops DON'T safepoint
@@ -375,6 +375,7 @@ address JVMCIRuntime::exception_handler_for_pc(JavaThread* thread) {
{
// Enter VM mode by calling the helper
ResetNoHandleMark rnhm;
ExceptionHandlingMark ehm(thread);
continuation = exception_handler_for_pc_helper(thread, exception, pc, cm);
}
// Back in JAVA, use no oops DON'T safepoint
@@ -1420,6 +1420,7 @@ address OptoRuntime::handle_exception_C(JavaThread* thread) {
// Enter the VM

ResetNoHandleMark rnhm;
ExceptionHandlingMark ehm(thread);
handler_address = handle_exception_C_helper(thread, nm);
}

@@ -99,7 +99,7 @@ class CloseScopedMemoryClosure : public HandshakeClosure {
if (var->type() == T_OBJECT) {
if (var->get_obj() == JNIHandles::resolve(_deopt)) {
assert(depth < max_critical_stack_depth, "can't have more than %d critical frames", max_critical_stack_depth);
if (!thread->has_pending_exception()) {
if (!jt->is_exception_handling()) {
jt->install_async_exception(JNIHandles::resolve(_exception));
}
return;
@@ -160,7 +160,10 @@ JRT_BLOCK_ENTRY(Deoptimization::UnrollBlock*, Deoptimization::fetch_unroll_info(
}
thread->inc_in_deopt_handler();

return fetch_unroll_info_helper(thread, exec_mode);
UnrollBlock* result = fetch_unroll_info_helper(thread, exec_mode);
thread->check_and_handle_async_exceptions(true);

return result;
JRT_END

#if COMPILER2_OR_JVMCI
@@ -1712,6 +1712,7 @@ void JavaThread::initialize() {
set_exception_oop(oop());
_exception_pc = 0;
_exception_handler_pc = 0;
_is_exception_handling = false;
_is_method_handle_return = 0;
_jvmti_thread_state= NULL;
_should_post_on_exceptions_flag = JNI_FALSE;
@@ -1211,6 +1211,7 @@ class JavaThread: public Thread {
volatile address _exception_pc; // PC where exception happened
volatile address _exception_handler_pc; // PC for handler of exception
volatile int _is_method_handle_return; // true (== 1) if the current exception PC is a MethodHandle call site.
bool _is_exception_handling;

private:
// support for JNI critical regions
@@ -1589,6 +1590,9 @@ class JavaThread: public Thread {
void set_exception_handler_pc(address a) { _exception_handler_pc = a; }
void set_is_method_handle_return(bool value) { _is_method_handle_return = value ? 1 : 0; }

bool is_exception_handling() const { return _is_exception_handling; }
void set_is_exception_handling(bool val) { _is_exception_handling = val; }

void clear_exception_oop_and_pc() {
set_exception_oop(NULL);
set_exception_pc(NULL);
@@ -506,6 +506,16 @@ ExceptionMark::~ExceptionMark() {
}
}

// Implementation of ExceptionHandlingMark

ExceptionHandlingMark::ExceptionHandlingMark(JavaThread* jt) : _jt(jt) {
jt->set_is_exception_handling(true);
}

ExceptionHandlingMark::~ExceptionHandlingMark() {
_jt->set_is_exception_handling(false);
}

// ----------------------------------------------------------------------------------------

// caller frees value_string if necessary
@@ -52,6 +52,7 @@ class Thread;
class Handle;
class Symbol;
class JavaCallArguments;
class JavaThread;
class methodHandle;

// The ThreadShadow class is a helper class to access the _pending_exception
@@ -322,6 +323,15 @@ class ExceptionMark {
};


class ExceptionHandlingMark {
private:
JavaThread* _jt;

public:
ExceptionHandlingMark(JavaThread* jt);
~ExceptionHandlingMark();
};


// Use an EXCEPTION_MARK for 'local' exceptions. EXCEPTION_MARK makes sure that no
// pending exception exists upon entering its scope and tests that no pending exception
@@ -28,6 +28,7 @@
* @run testng/othervm TestHandshake
* @run testng/othervm -Xint TestHandshake
* @run testng/othervm -XX:TieredStopAtLevel=1 TestHandshake
* @run testng/othervm -XX:-TieredCompilation TestHandshake
*/

import jdk.incubator.foreign.MemoryAccess;
@@ -49,9 +50,9 @@

public class TestHandshake {

static final int ITERATIONS = 5;
static final int ITERATIONS = 10;
static final int SEGMENT_SIZE = 1_000_000;
static final int MAX_DELAY_MILLIS = 2000;
static final int MAX_DELAY_MILLIS = 500;
static final int MAX_EXECUTOR_WAIT_SECONDS = 10;

@Test(dataProvider = "accessors")
@@ -60,7 +61,7 @@ public void testHandshake(Function<MemorySegment, Runnable> accessorFactory) thr
MemorySegment segment = MemorySegment.allocateNative(SEGMENT_SIZE).withOwnerThread(null);
System.err.println("ITERATION " + it);
ExecutorService accessExecutor = Executors.newCachedThreadPool();
for (int i = 0; i < ThreadLocalRandom.current().nextInt(Runtime.getRuntime().availableProcessors()); i++) {
for (int i = 0; i < Runtime.getRuntime().availableProcessors() ; i++) {
accessExecutor.execute(accessorFactory.apply(segment));
}
Thread.sleep(ThreadLocalRandom.current().nextInt(MAX_DELAY_MILLIS));
@@ -119,6 +120,24 @@ public void run() {
}
}

static class SegmentFillAccessor implements Runnable {

final MemorySegment segment;

SegmentFillAccessor(MemorySegment segment) {
this.segment = segment;
}

@Override
public void run() {
try {
segment.fill((byte)ThreadLocalRandom.current().nextInt(10));
} catch (IllegalStateException ex) {
// do nothing
}
}
}

static class SegmentMismatchAccessor implements Runnable {

final MemorySegment segment;
@@ -215,6 +234,7 @@ public void run() {
{ (Function<MemorySegment, Runnable>)SegmentAccessor::new },
{ (Function<MemorySegment, Runnable>)SegmentCopyAccessor::new },
{ (Function<MemorySegment, Runnable>)SegmentMismatchAccessor::new },
{ (Function<MemorySegment, Runnable>)SegmentFillAccessor::new },
{ (Function<MemorySegment, Runnable>)BufferAccessor::new },
{ (Function<MemorySegment, Runnable>)BufferHandleAccessor::new }
};

0 comments on commit 1cc7a78

Please sign in to comment.