src/windows/native/sun/windows/alloc.h

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef _ALLOC_H_
  27 #define _ALLOC_H_
  28 





  29 #include "stdhdrs.h"
  30 
  31 // By defining std::bad_alloc in a local header file instead of including
  32 // the Standard C++ <new> header file, we avoid making awt.dll dependent
  33 // on msvcp50.dll. This reduces the size of the JRE by 500kb.
  34 namespace std {
  35     class bad_alloc {};
  36 }
  37 
  38 class awt_toolkit_shutdown {};
  39 
  40 // Disable "C++ Exception Specification ignored" warnings.
  41 // These warnings are generated because VC++ 5.0 allows, but does not enforce,
  42 // exception specifications. This #pragma can be safely removed when VC++
  43 // is updated to enforce exception specifications.
  44 #pragma warning(disable : 4290)
  45 
  46 #ifdef TRY
  47 #error Multiple definitions of TRY
  48 #endif


 110 // This function throws awt_toolkit_shutdown if the Toolkit is not active
 111 void throw_if_shutdown(void) throw (awt_toolkit_shutdown);
 112 
 113 // This function is called when a std::bad_alloc exception is caught
 114 void handle_bad_alloc(void);
 115 
 116 // Uncomment to nondeterministically test OutOfMemory errors
 117 // #define OUTOFMEM_TEST
 118 
 119 #ifdef OUTOFMEM_TEST
 120     void *safe_Malloc_outofmem(size_t size, const char *, int)
 121         throw (std::bad_alloc);
 122     void *safe_Calloc_outofmem(size_t num, size_t size, const char *, int)
 123         throw (std::bad_alloc);
 124     void *safe_Realloc_outofmem(void *memblock, size_t size, const char *, int)
 125         throw (std::bad_alloc);
 126     void * CDECL operator new(size_t size, const char *, int)
 127         throw (std::bad_alloc);
 128 
 129     #define safe_Malloc(size) \
 130         safe_Malloc_outofmem(size, __FILE__, __LINE__)
 131     #define safe_Calloc(num, size) \
 132         safe_Calloc_outofmem(num, size, __FILE__, __LINE__)
 133     #define safe_Realloc(memblock, size) \
 134         safe_Realloc_outofmem(memblock, size, __FILE__, __LINE__)
 135     #define new new(__FILE__, __LINE__)
 136 #endif /* OUTOFMEM_TEST */
 137 
 138 #define TRY \
 139     try { \
 140         entry_point(); \
 141         hang_if_shutdown();
 142 // The _NO_HANG version of TRY causes the AWT native code to return to Java
 143 // immediately if the Toolkit is not active. Normal AWT operations should
 144 // never use this macro. It should only be used for cleanup routines where:
 145 // (1) Hanging is not a valid option, because the method is called during
 146 // execution of runFinalizersOnExit; and, (2) Execution of the method would
 147 // generate a NullPointerException or other Exception.
 148 #define TRY_NO_HANG \
 149     try { \
 150         entry_point(); \
 151         throw_if_shutdown();
 152 // The _NO_VERIFY version of TRY does not verify that the Toolkit is still
 153 // active before proceeding. Normal AWT operations should never use this
 154 // macro. It should only be used for cleanup routines which can safely
 155 // execute after the Toolkit is disposed, and then only with caution. Users




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef _ALLOC_H_
  27 #define _ALLOC_H_
  28 
  29 /* Use THIS_FILE when it is available. */
  30 #ifndef THIS_FILE
  31     #define THIS_FILE __FILE__
  32 #endif
  33 
  34 #include "stdhdrs.h"
  35 
  36 // By defining std::bad_alloc in a local header file instead of including
  37 // the Standard C++ <new> header file, we avoid making awt.dll dependent
  38 // on msvcp50.dll. This reduces the size of the JRE by 500kb.
  39 namespace std {
  40     class bad_alloc {};
  41 }
  42 
  43 class awt_toolkit_shutdown {};
  44 
  45 // Disable "C++ Exception Specification ignored" warnings.
  46 // These warnings are generated because VC++ 5.0 allows, but does not enforce,
  47 // exception specifications. This #pragma can be safely removed when VC++
  48 // is updated to enforce exception specifications.
  49 #pragma warning(disable : 4290)
  50 
  51 #ifdef TRY
  52 #error Multiple definitions of TRY
  53 #endif


 115 // This function throws awt_toolkit_shutdown if the Toolkit is not active
 116 void throw_if_shutdown(void) throw (awt_toolkit_shutdown);
 117 
 118 // This function is called when a std::bad_alloc exception is caught
 119 void handle_bad_alloc(void);
 120 
 121 // Uncomment to nondeterministically test OutOfMemory errors
 122 // #define OUTOFMEM_TEST
 123 
 124 #ifdef OUTOFMEM_TEST
 125     void *safe_Malloc_outofmem(size_t size, const char *, int)
 126         throw (std::bad_alloc);
 127     void *safe_Calloc_outofmem(size_t num, size_t size, const char *, int)
 128         throw (std::bad_alloc);
 129     void *safe_Realloc_outofmem(void *memblock, size_t size, const char *, int)
 130         throw (std::bad_alloc);
 131     void * CDECL operator new(size_t size, const char *, int)
 132         throw (std::bad_alloc);
 133 
 134     #define safe_Malloc(size) \
 135         safe_Malloc_outofmem(size, THIS_FILE, __LINE__)
 136     #define safe_Calloc(num, size) \
 137         safe_Calloc_outofmem(num, size, THIS_FILE, __LINE__)
 138     #define safe_Realloc(memblock, size) \
 139         safe_Realloc_outofmem(memblock, size, THIS_FILE, __LINE__)
 140     #define new new(THIS_FILE, __LINE__)
 141 #endif /* OUTOFMEM_TEST */
 142 
 143 #define TRY \
 144     try { \
 145         entry_point(); \
 146         hang_if_shutdown();
 147 // The _NO_HANG version of TRY causes the AWT native code to return to Java
 148 // immediately if the Toolkit is not active. Normal AWT operations should
 149 // never use this macro. It should only be used for cleanup routines where:
 150 // (1) Hanging is not a valid option, because the method is called during
 151 // execution of runFinalizersOnExit; and, (2) Execution of the method would
 152 // generate a NullPointerException or other Exception.
 153 #define TRY_NO_HANG \
 154     try { \
 155         entry_point(); \
 156         throw_if_shutdown();
 157 // The _NO_VERIFY version of TRY does not verify that the Toolkit is still
 158 // active before proceeding. Normal AWT operations should never use this
 159 // macro. It should only be used for cleanup routines which can safely
 160 // execute after the Toolkit is disposed, and then only with caution. Users