Mon, 02 Jul 2012 13:11:28 -0400
Merge
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 */
25 #ifndef SHARE_VM_UTILITIES_PRESERVEEXCEPTION_HPP
26 #define SHARE_VM_UTILITIES_PRESERVEEXCEPTION_HPP
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 #ifdef TARGET_OS_FAMILY_bsd
39 # include "thread_bsd.inline.hpp"
40 #endif
42 // This file provides more support for exception handling; see also exceptions.hpp
43 class PreserveExceptionMark {
44 private:
45 Thread* _thread;
46 Handle _preserved_exception_oop;
47 int _preserved_exception_line;
48 const char* _preserved_exception_file;
50 public:
51 PreserveExceptionMark(Thread*& thread);
52 ~PreserveExceptionMark();
53 };
56 // This is a clone of PreserveExceptionMark which asserts instead
57 // of failing when what it wraps generates a pending exception.
58 // It also addresses bug 6431341.
59 class CautiouslyPreserveExceptionMark {
60 private:
61 Thread* _thread;
62 Handle _preserved_exception_oop;
63 int _preserved_exception_line;
64 const char* _preserved_exception_file;
66 public:
67 CautiouslyPreserveExceptionMark(Thread* thread);
68 ~CautiouslyPreserveExceptionMark();
69 };
72 // Like PreserveExceptionMark but allows new exceptions to be generated in
73 // the body of the mark. If a new exception is generated then the original one
74 // is discarded.
75 class WeakPreserveExceptionMark {
76 private:
77 Thread* _thread;
78 Handle _preserved_exception_oop;
79 int _preserved_exception_line;
80 const char* _preserved_exception_file;
82 void preserve();
83 void restore();
85 public:
86 WeakPreserveExceptionMark(Thread* pThread) : _thread(pThread), _preserved_exception_oop() {
87 if (pThread->has_pending_exception()) {
88 preserve();
89 }
90 }
91 ~WeakPreserveExceptionMark() {
92 if (_preserved_exception_oop.not_null()) {
93 restore();
94 }
95 }
96 };
100 // use global exception mark when allowing pending exception to be set and
101 // saving and restoring them
102 #define PRESERVE_EXCEPTION_MARK Thread* THREAD; PreserveExceptionMark __em(THREAD);
104 #endif // SHARE_VM_UTILITIES_PRESERVEEXCEPTION_HPP