Skip to content

Commit 535f2da

Browse files
committed
8259486: Replace PreserveExceptionMark with implementation for CautiouslyPreserveExceptionMark
Reviewed-by: dholmes, sspitsyn
1 parent ce94512 commit 535f2da

File tree

14 files changed

+48
-97
lines changed

14 files changed

+48
-97
lines changed

src/hotspot/cpu/arm/methodHandles_arm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -511,14 +511,15 @@ void trace_method_handle_stub(const char* adaptername,
511511
{
512512
// dump last frame (from JavaThread::print_frame_layout)
513513

514-
// Note: code is robust but the dumped informationm may not be
514+
// Note: code is robust but the dumped information may not be
515515
// 100% correct, particularly with respect to the dumped
516516
// "unextended_sp". Getting it right for all trace_method_handle
517517
// call paths is not worth the complexity/risk. The correct slot
518518
// will be identified by *Rsender_sp anyway in the dump.
519519
JavaThread* p = JavaThread::active();
520520

521-
PRESERVE_EXCEPTION_MARK;
521+
// may not be needed by safer and unexpensive here
522+
PreserveExceptionMark pem(Thread::current());
522523
FrameValues values;
523524

524525
intptr_t* dump_fp = (intptr_t *) saved_bp;

src/hotspot/cpu/ppc/methodHandles_ppc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012, 2017 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -519,7 +519,8 @@ void trace_method_handle_stub(const char* adaptername,
519519

520520
JavaThread* p = JavaThread::active();
521521

522-
PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here
522+
// may not be needed by safer and unexpensive here
523+
PreserveExceptionMark pem(Thread::current());
523524
FrameValues values;
524525

525526
// Note: We want to allow trace_method_handle from any call site.

src/hotspot/cpu/s390/methodHandles_s390.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2016, 2017 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -568,7 +568,8 @@ void trace_method_handle_stub(const char* adaptername,
568568
LogStream ls(lt);
569569
JavaThread* p = JavaThread::active();
570570

571-
PRESERVE_EXCEPTION_MARK; // May not be needed by safer and unexpensive here.
571+
// may not be needed by safer and unexpensive here
572+
PreserveExceptionMark pem(Thread::current());
572573
FrameValues values;
573574

574575
// Note: We want to allow trace_method_handle from any call site.

src/hotspot/cpu/x86/methodHandles_x86.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -549,7 +549,8 @@ void trace_method_handle_stub(const char* adaptername,
549549

550550
JavaThread* p = JavaThread::active();
551551

552-
PRESERVE_EXCEPTION_MARK; // may not be needed but safer and inexpensive here
552+
// may not be needed by safer and unexpensive here
553+
PreserveExceptionMark pem(Thread::current());
553554
FrameValues values;
554555

555556
// Current C frame

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1997,7 +1997,7 @@ oop java_lang_Throwable::message(oop throwable) {
19971997

19981998
// Return Symbol for detailed_message or NULL
19991999
Symbol* java_lang_Throwable::detail_message(oop throwable) {
2000-
PRESERVE_EXCEPTION_MARK; // Keep original exception
2000+
PreserveExceptionMark pm(Thread::current());
20012001
oop detailed_message = java_lang_Throwable::message(throwable);
20022002
if (detailed_message != NULL) {
20032003
return java_lang_String::as_symbol(detailed_message);
@@ -2187,7 +2187,7 @@ class BacktraceBuilder: public StackObj {
21872187
_index++;
21882188
}
21892189

2190-
void set_has_hidden_top_frame(TRAPS) {
2190+
void set_has_hidden_top_frame() {
21912191
if (!_has_hidden_top_frame) {
21922192
// It would be nice to add java/lang/Boolean::TRUE here
21932193
// to indicate that this backtrace has a hidden top frame.
@@ -2525,7 +2525,7 @@ void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHand
25252525
if (skip_hidden) {
25262526
if (total_count == 0) {
25272527
// The top frame will be hidden from the stack trace.
2528-
bt.set_has_hidden_top_frame(CHECK);
2528+
bt.set_has_hidden_top_frame();
25292529
}
25302530
continue;
25312531
}
@@ -2552,11 +2552,12 @@ void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHand
25522552
return;
25532553
}
25542554

2555-
PRESERVE_EXCEPTION_MARK;
2555+
JavaThread* THREAD = JavaThread::current();
2556+
PreserveExceptionMark pm(THREAD);
25562557

2557-
JavaThread* thread = JavaThread::active();
2558-
fill_in_stack_trace(throwable, method, thread);
2559-
// ignore exceptions thrown during stack trace filling
2558+
fill_in_stack_trace(throwable, method, THREAD);
2559+
// Ignore exceptions thrown during stack trace filling (OOM) and reinstall the
2560+
// original exception via the PreserveExceptionMark destructor.
25602561
CLEAR_PENDING_EXCEPTION;
25612562
}
25622563

src/hotspot/share/jfr/recorder/service/jfrRecorderThread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@ bool JfrRecorderThread::start(JfrCheckpointManager* cp_manager, JfrPostBox* post
113113
remove_thread_args.set_signature(vmSymbols::thread_void_signature());
114114
remove_thread_args.set_receiver(Universe::system_thread_group());
115115
remove_thread_args.push_oop(h_thread_oop());
116-
CautiouslyPreserveExceptionMark cpe(THREAD);
116+
PreserveExceptionMark cpe(THREAD);
117117
JfrJavaSupport::call_special(&remove_thread_args, THREAD);
118118
return false;
119119
}

src/hotspot/share/prims/jvmtiEnter.xsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<!--
3-
Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
44
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
66
This code is free software; you can redistribute it and/or modify it
@@ -442,7 +442,7 @@ struct jvmtiInterface_1_ jvmti</xsl:text>
442442
<xsl:text>debug_only(VMNativeEntryWrapper __vew;)</xsl:text>
443443
<xsl:if test="count(@callbacksafe)=0 or not(contains(@callbacksafe,'safe'))">
444444
<xsl:value-of select="$space"/>
445-
<xsl:text>CautiouslyPreserveExceptionMark __em(this_thread);</xsl:text>
445+
<xsl:text>PreserveExceptionMark __em(this_thread);</xsl:text>
446446
</xsl:if>
447447
</xsl:if>
448448
</xsl:template>

src/hotspot/share/runtime/deoptimization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -739,7 +739,7 @@ JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_m
739739
if (VerifyStack) {
740740
ResourceMark res_mark;
741741
// Clear pending exception to not break verification code (restored afterwards)
742-
PRESERVE_EXCEPTION_MARK;
742+
PreserveExceptionMark pm(thread);
743743

744744
thread->validate_frame_layout();
745745

src/hotspot/share/runtime/handshake.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -420,7 +420,7 @@ void HandshakeState::process_by_self() {
420420
void HandshakeState::process_self_inner() {
421421
while (should_process()) {
422422
HandleMark hm(_handshakee);
423-
CautiouslyPreserveExceptionMark pem(_handshakee);
423+
PreserveExceptionMark pem(_handshakee);
424424
MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag);
425425
HandshakeOperation* op = pop_for_self();
426426
if (op != NULL) {

src/hotspot/share/runtime/thread.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,12 +1859,6 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
18591859
Handle threadObj(this, this->threadObj());
18601860
assert(threadObj.not_null(), "Java thread object should be created");
18611861

1862-
// FIXIT: This code should be moved into else part, when reliable 1.2/1.3 check is in place
1863-
{
1864-
EXCEPTION_MARK;
1865-
1866-
CLEAR_PENDING_EXCEPTION;
1867-
}
18681862
if (!destroy_vm) {
18691863
if (uncaught_exception.not_null()) {
18701864
EXCEPTION_MARK;
@@ -3023,7 +3017,7 @@ class PrintAndVerifyOopClosure: public OopClosure {
30233017
// Print or validate the layout of stack frames
30243018
void JavaThread::print_frame_layout(int depth, bool validate_only) {
30253019
ResourceMark rm;
3026-
PRESERVE_EXCEPTION_MARK;
3020+
PreserveExceptionMark pm(this);
30273021
FrameValues values;
30283022
int frame_no = 0;
30293023
for (StackFrameStream fst(this, false /* update */, true /* process_frames */); !fst.is_done(); fst.next()) {

0 commit comments

Comments
 (0)