diff -r fd16c54261b3 -r 90ce3da70b43 jdk/src/share/instrument/JavaExceptions.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/instrument/JavaExceptions.h Sat Dec 01 00:00:00 2007 +0000 @@ -0,0 +1,162 @@ +/* + * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * Copyright 2003 Wily Technology, Inc. + */ + +#ifndef _JAVAEXCEPTIONS_H_ +#define _JAVAEXCEPTIONS_H_ + +#include +#include + +/** + * This module contains utility routines for manipulating Java throwables + * and JNIEnv throwable state from native code. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Set up static state. Needs java, must be called at or after VMInit. + * Returns true if it succeeds, false if it fails. + */ +extern jboolean +initializeFallbackError(JNIEnv* jnienv); + +/* + * Mapping support. Allows different clients to map checked exceptions in different ways. + */ +typedef jthrowable (*CheckedExceptionMapper) + ( JNIEnv * jnienv, + jthrowable throwableToMap); + +/* Default mapper. Map everything checked to InternalError; can return null if error */ +extern jthrowable +mapAllCheckedToInternalErrorMapper( JNIEnv * jnienv, + jthrowable throwableToMap); + + + +/* + * Exception-helper routines that do not modify the JNIEnv. + * They require a clean JNIEnv on entry, and they guarantee a clean JNIEnv on exit. + */ + +/* creates a throwable from the supplied parameters; can return null if error */ +extern jthrowable +createThrowable( JNIEnv* jnienv, + const char* className, + jstring message); + +/* creates a java.lang.InternalError; can return null if error */ +extern jthrowable +createInternalError(JNIEnv * jnienv, jstring message); + +/* creates the appropriate java Throwable based on the error code; can return null if error */ +extern jthrowable +createThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode); + +/* fetches the message string out of the supplied throwable, null if there is none, null if error */ +extern jstring +getMessageFromThrowable( JNIEnv* jnienv, + jthrowable exception); + +/* true if the supplied throwable is unchecked. null will return true. */ +extern jboolean +isUnchecked( JNIEnv* jnienv, + jthrowable exception); + +/* true if the env contains a thrown exception */ +extern jboolean +checkForThrowable( JNIEnv* jnienv); + +/* true if the env is clean for JNI calls */ +extern jboolean +isSafeForJNICalls( JNIEnv * jnienv); + +/* + * Logs the outstanding throwable, if one exists. + * This call assumes an outstanding exception, but does not + * modify the JNIEnv outstanding Throwable state. + */ +extern void +logThrowable( JNIEnv * jnienv); + + +/* + * These routines do modify the JNIEnv outstanding Throwable state. + */ + +/* Throws the supplied throwable. always sets the JNIEnv throwable */ +extern void +throwThrowable( JNIEnv * jnienv, + jthrowable exception); + +/* returns current throwable. always clears the JNIEnv exception */ +extern jthrowable +preserveThrowable(JNIEnv * jnienv); + +/* undoes preserveThrowable (Throws the supplied throwable). always sets the JNIEnv throwable */ +extern void +restoreThrowable( JNIEnv * jnienv, + jthrowable preservedException); + +/* always clears the JNIEnv throwable. returns true if an exception was pending on entry. */ +extern jboolean +checkForAndClearThrowable( JNIEnv * jnienv); + +/* creates the appropriate java Throwable based on the error code + * does the very best it can to make sure an exception ends up installed; uses fallback if necessary + * always sets the JNIEnv exception + */ +extern void +createAndThrowThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode); + +/* creates a java.lang.InternalError and installs it into the JNIEnv. + * does the very best it can to make sure an exception ends up installed; uses fallback if necessary + * always sets the JNIEnv exception + */ +extern void +createAndThrowInternalError(JNIEnv * jnienv); + +/* If no throwable is outstanding, do nothing. + * If a throwable is outstanding, make sure it is of a legal type according to the supplied + * mapping function. + * Leaves the "thrown" state the same (none on exit if none on entry, thrown on exit if + * thrown on entry); may change the type of the thrown exception. + */ +extern void +mapThrownThrowableIfNecessary(JNIEnv * jnienv, CheckedExceptionMapper mapper); + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + + +#endif