hotspot/src/share/vm/utilities/preserveException.hpp
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
equal deleted inserted replaced
0:fd16c54261b3 1:489c9b5090e2
       
     1 /*
       
     2  * Copyright 1998-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 // This file provides more support for exception handling; see also exceptions.hpp
       
    26 class PreserveExceptionMark {
       
    27  private:
       
    28   Thread*     _thread;
       
    29   Handle      _preserved_exception_oop;
       
    30   int         _preserved_exception_line;
       
    31   const char* _preserved_exception_file;
       
    32 
       
    33  public:
       
    34   PreserveExceptionMark(Thread*& thread);
       
    35   ~PreserveExceptionMark();
       
    36 };
       
    37 
       
    38 
       
    39 // This is a clone of PreserveExceptionMark which asserts instead
       
    40 // of failing when what it wraps generates a pending exception.
       
    41 // It also addresses bug 6431341.
       
    42 class CautiouslyPreserveExceptionMark {
       
    43  private:
       
    44   Thread*     _thread;
       
    45   Handle      _preserved_exception_oop;
       
    46   int         _preserved_exception_line;
       
    47   const char* _preserved_exception_file;
       
    48 
       
    49  public:
       
    50   CautiouslyPreserveExceptionMark(Thread* thread);
       
    51   ~CautiouslyPreserveExceptionMark();
       
    52 };
       
    53 
       
    54 
       
    55 // Like PreserveExceptionMark but allows new exceptions to be generated in
       
    56 // the body of the mark. If a new exception is generated then the original one
       
    57 // is discarded.
       
    58 class WeakPreserveExceptionMark {
       
    59 private:
       
    60   Thread*     _thread;
       
    61   Handle      _preserved_exception_oop;
       
    62   int         _preserved_exception_line;
       
    63   const char* _preserved_exception_file;
       
    64 
       
    65   void        preserve();
       
    66   void        restore();
       
    67 
       
    68   public:
       
    69     WeakPreserveExceptionMark(Thread* pThread) :  _thread(pThread), _preserved_exception_oop()  {
       
    70       if (pThread->has_pending_exception()) {
       
    71         preserve();
       
    72       }
       
    73     }
       
    74     ~WeakPreserveExceptionMark() {
       
    75       if (_preserved_exception_oop.not_null()) {
       
    76         restore();
       
    77       }
       
    78     }
       
    79 };
       
    80 
       
    81 
       
    82 
       
    83 // use global exception mark when allowing pending exception to be set and
       
    84 // saving and restoring them
       
    85 #define PRESERVE_EXCEPTION_MARK                    Thread* THREAD; PreserveExceptionMark __em(THREAD);