1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/preserveException.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,85 @@ 1.4 +/* 1.5 + * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// This file provides more support for exception handling; see also exceptions.hpp 1.29 +class PreserveExceptionMark { 1.30 + private: 1.31 + Thread* _thread; 1.32 + Handle _preserved_exception_oop; 1.33 + int _preserved_exception_line; 1.34 + const char* _preserved_exception_file; 1.35 + 1.36 + public: 1.37 + PreserveExceptionMark(Thread*& thread); 1.38 + ~PreserveExceptionMark(); 1.39 +}; 1.40 + 1.41 + 1.42 +// This is a clone of PreserveExceptionMark which asserts instead 1.43 +// of failing when what it wraps generates a pending exception. 1.44 +// It also addresses bug 6431341. 1.45 +class CautiouslyPreserveExceptionMark { 1.46 + private: 1.47 + Thread* _thread; 1.48 + Handle _preserved_exception_oop; 1.49 + int _preserved_exception_line; 1.50 + const char* _preserved_exception_file; 1.51 + 1.52 + public: 1.53 + CautiouslyPreserveExceptionMark(Thread* thread); 1.54 + ~CautiouslyPreserveExceptionMark(); 1.55 +}; 1.56 + 1.57 + 1.58 +// Like PreserveExceptionMark but allows new exceptions to be generated in 1.59 +// the body of the mark. If a new exception is generated then the original one 1.60 +// is discarded. 1.61 +class WeakPreserveExceptionMark { 1.62 +private: 1.63 + Thread* _thread; 1.64 + Handle _preserved_exception_oop; 1.65 + int _preserved_exception_line; 1.66 + const char* _preserved_exception_file; 1.67 + 1.68 + void preserve(); 1.69 + void restore(); 1.70 + 1.71 + public: 1.72 + WeakPreserveExceptionMark(Thread* pThread) : _thread(pThread), _preserved_exception_oop() { 1.73 + if (pThread->has_pending_exception()) { 1.74 + preserve(); 1.75 + } 1.76 + } 1.77 + ~WeakPreserveExceptionMark() { 1.78 + if (_preserved_exception_oop.not_null()) { 1.79 + restore(); 1.80 + } 1.81 + } 1.82 +}; 1.83 + 1.84 + 1.85 + 1.86 +// use global exception mark when allowing pending exception to be set and 1.87 +// saving and restoring them 1.88 +#define PRESERVE_EXCEPTION_MARK Thread* THREAD; PreserveExceptionMark __em(THREAD);