src/share/vm/utilities/preserveException.hpp

Print this page


   1 /*
   2  * Copyright (c) 1998, 2006, 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 // 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;


  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);


   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;


  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