1 /* 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_UTILITIES_PRESERVEEXCEPTION_HPP 26 #define SHARE_VM_UTILITIES_PRESERVEEXCEPTION_HPP 27 28 #include "runtime/handles.hpp" 29 #ifdef TARGET_OS_FAMILY_linux 30 # include "thread_linux.inline.hpp" 31 #endif 32 #ifdef TARGET_OS_FAMILY_solaris 33 # include "thread_solaris.inline.hpp" 34 #endif 35 #ifdef TARGET_OS_FAMILY_windows 36 # include "thread_windows.inline.hpp" 37 #endif 38 39 // This file provides more support for exception handling; see also exceptions.hpp 40 class PreserveExceptionMark { 41 private: 42 Thread* _thread; 43 Handle _preserved_exception_oop; 44 int _preserved_exception_line; 45 const char* _preserved_exception_file; 46 47 public: 48 PreserveExceptionMark(Thread*& thread); 49 ~PreserveExceptionMark(); 50 }; 51 52 53 // This is a clone of PreserveExceptionMark which asserts instead 54 // of failing when what it wraps generates a pending exception. 55 // It also addresses bug 6431341. 56 class CautiouslyPreserveExceptionMark { 57 private: 58 Thread* _thread; 59 Handle _preserved_exception_oop; 60 int _preserved_exception_line; 61 const char* _preserved_exception_file; 62 63 public: 64 CautiouslyPreserveExceptionMark(Thread* thread); 65 ~CautiouslyPreserveExceptionMark(); 66 }; 67 68 69 // Like PreserveExceptionMark but allows new exceptions to be generated in 70 // the body of the mark. If a new exception is generated then the original one 71 // is discarded. 72 class WeakPreserveExceptionMark { 73 private: 74 Thread* _thread; 75 Handle _preserved_exception_oop; 76 int _preserved_exception_line; 77 const char* _preserved_exception_file; 78 79 void preserve(); 80 void restore(); 81 82 public: 83 WeakPreserveExceptionMark(Thread* pThread) : _thread(pThread), _preserved_exception_oop() { 84 if (pThread->has_pending_exception()) { 85 preserve(); 86 } 87 } 88 ~WeakPreserveExceptionMark() { 89 if (_preserved_exception_oop.not_null()) { 90 restore(); 91 } 92 } 93 }; 94 95 96 97 // use global exception mark when allowing pending exception to be set and 98 // saving and restoring them 99 #define PRESERVE_EXCEPTION_MARK Thread* THREAD; PreserveExceptionMark __em(THREAD); 100 101 #endif // SHARE_VM_UTILITIES_PRESERVEEXCEPTION_HPP