From 535f2da5e2f58e92b5b788faac25c53acb3750b8 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Wed, 13 Jan 2021 14:32:52 +0000 Subject: [PATCH] 8259486: Replace PreserveExceptionMark with implementation for CautiouslyPreserveExceptionMark Reviewed-by: dholmes, sspitsyn --- src/hotspot/cpu/arm/methodHandles_arm.cpp | 7 +-- src/hotspot/cpu/ppc/methodHandles_ppc.cpp | 5 +- src/hotspot/cpu/s390/methodHandles_s390.cpp | 5 +- src/hotspot/cpu/x86/methodHandles_x86.cpp | 5 +- src/hotspot/share/classfile/javaClasses.cpp | 17 ++++--- .../recorder/service/jfrRecorderThread.cpp | 4 +- src/hotspot/share/prims/jvmtiEnter.xsl | 4 +- src/hotspot/share/runtime/deoptimization.cpp | 4 +- src/hotspot/share/runtime/handshake.cpp | 4 +- src/hotspot/share/runtime/thread.cpp | 8 +-- src/hotspot/share/utilities/exceptions.cpp | 4 +- src/hotspot/share/utilities/exceptions.hpp | 4 +- .../share/utilities/preserveException.cpp | 49 +++++-------------- .../share/utilities/preserveException.hpp | 31 ++---------- 14 files changed, 51 insertions(+), 100 deletions(-) diff --git a/src/hotspot/cpu/arm/methodHandles_arm.cpp b/src/hotspot/cpu/arm/methodHandles_arm.cpp index 34415c70d03..8e585d72628 100644 --- a/src/hotspot/cpu/arm/methodHandles_arm.cpp +++ b/src/hotspot/cpu/arm/methodHandles_arm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * 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, { // dump last frame (from JavaThread::print_frame_layout) - // Note: code is robust but the dumped informationm may not be + // Note: code is robust but the dumped information may not be // 100% correct, particularly with respect to the dumped // "unextended_sp". Getting it right for all trace_method_handle // call paths is not worth the complexity/risk. The correct slot // will be identified by *Rsender_sp anyway in the dump. JavaThread* p = JavaThread::active(); - PRESERVE_EXCEPTION_MARK; + // may not be needed by safer and unexpensive here + PreserveExceptionMark pem(Thread::current()); FrameValues values; intptr_t* dump_fp = (intptr_t *) saved_bp; diff --git a/src/hotspot/cpu/ppc/methodHandles_ppc.cpp b/src/hotspot/cpu/ppc/methodHandles_ppc.cpp index b204a4ad721..eb6ed2e5cf6 100644 --- a/src/hotspot/cpu/ppc/methodHandles_ppc.cpp +++ b/src/hotspot/cpu/ppc/methodHandles_ppc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2017 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -519,7 +519,8 @@ void trace_method_handle_stub(const char* adaptername, JavaThread* p = JavaThread::active(); - PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here + // may not be needed by safer and unexpensive here + PreserveExceptionMark pem(Thread::current()); FrameValues values; // Note: We want to allow trace_method_handle from any call site. diff --git a/src/hotspot/cpu/s390/methodHandles_s390.cpp b/src/hotspot/cpu/s390/methodHandles_s390.cpp index f75cfe8e487..73fee789350 100644 --- a/src/hotspot/cpu/s390/methodHandles_s390.cpp +++ b/src/hotspot/cpu/s390/methodHandles_s390.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -568,7 +568,8 @@ void trace_method_handle_stub(const char* adaptername, LogStream ls(lt); JavaThread* p = JavaThread::active(); - PRESERVE_EXCEPTION_MARK; // May not be needed by safer and unexpensive here. + // may not be needed by safer and unexpensive here + PreserveExceptionMark pem(Thread::current()); FrameValues values; // Note: We want to allow trace_method_handle from any call site. diff --git a/src/hotspot/cpu/x86/methodHandles_x86.cpp b/src/hotspot/cpu/x86/methodHandles_x86.cpp index 23f23d3c68d..d72f9cc00f9 100644 --- a/src/hotspot/cpu/x86/methodHandles_x86.cpp +++ b/src/hotspot/cpu/x86/methodHandles_x86.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * 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, JavaThread* p = JavaThread::active(); - PRESERVE_EXCEPTION_MARK; // may not be needed but safer and inexpensive here + // may not be needed by safer and unexpensive here + PreserveExceptionMark pem(Thread::current()); FrameValues values; // Current C frame diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 506ad1db731..536201f5345 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1997,7 +1997,7 @@ oop java_lang_Throwable::message(oop throwable) { // Return Symbol for detailed_message or NULL Symbol* java_lang_Throwable::detail_message(oop throwable) { - PRESERVE_EXCEPTION_MARK; // Keep original exception + PreserveExceptionMark pm(Thread::current()); oop detailed_message = java_lang_Throwable::message(throwable); if (detailed_message != NULL) { return java_lang_String::as_symbol(detailed_message); @@ -2187,7 +2187,7 @@ class BacktraceBuilder: public StackObj { _index++; } - void set_has_hidden_top_frame(TRAPS) { + void set_has_hidden_top_frame() { if (!_has_hidden_top_frame) { // It would be nice to add java/lang/Boolean::TRUE here // 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 if (skip_hidden) { if (total_count == 0) { // The top frame will be hidden from the stack trace. - bt.set_has_hidden_top_frame(CHECK); + bt.set_has_hidden_top_frame(); } continue; } @@ -2552,11 +2552,12 @@ void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHand return; } - PRESERVE_EXCEPTION_MARK; + JavaThread* THREAD = JavaThread::current(); + PreserveExceptionMark pm(THREAD); - JavaThread* thread = JavaThread::active(); - fill_in_stack_trace(throwable, method, thread); - // ignore exceptions thrown during stack trace filling + fill_in_stack_trace(throwable, method, THREAD); + // Ignore exceptions thrown during stack trace filling (OOM) and reinstall the + // original exception via the PreserveExceptionMark destructor. CLEAR_PENDING_EXCEPTION; } diff --git a/src/hotspot/share/jfr/recorder/service/jfrRecorderThread.cpp b/src/hotspot/share/jfr/recorder/service/jfrRecorderThread.cpp index b76018b649a..6f44021abc1 100644 --- a/src/hotspot/share/jfr/recorder/service/jfrRecorderThread.cpp +++ b/src/hotspot/share/jfr/recorder/service/jfrRecorderThread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * 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 remove_thread_args.set_signature(vmSymbols::thread_void_signature()); remove_thread_args.set_receiver(Universe::system_thread_group()); remove_thread_args.push_oop(h_thread_oop()); - CautiouslyPreserveExceptionMark cpe(THREAD); + PreserveExceptionMark cpe(THREAD); JfrJavaSupport::call_special(&remove_thread_args, THREAD); return false; } diff --git a/src/hotspot/share/prims/jvmtiEnter.xsl b/src/hotspot/share/prims/jvmtiEnter.xsl index 2ed29d5cb6f..d45e705cc81 100644 --- a/src/hotspot/share/prims/jvmtiEnter.xsl +++ b/src/hotspot/share/prims/jvmtiEnter.xsl @@ -1,6 +1,6 @@