Path: blob/master/src/java.instrument/share/native/libinstrument/JavaExceptions.h
41149 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Copyright 2003 Wily Technology, Inc.27*/2829#ifndef _JAVAEXCEPTIONS_H_30#define _JAVAEXCEPTIONS_H_3132#include <jni.h>33#include <jvmti.h>3435/**36* This module contains utility routines for manipulating Java throwables37* and JNIEnv throwable state from native code.38*/3940#ifdef __cplusplus41extern "C" {42#endif4344/*45* Set up static state. Needs java, must be called at or after VMInit.46* Returns true if it succeeds, false if it fails.47*/48extern jboolean49initializeFallbackError(JNIEnv* jnienv);5051/*52* Mapping support. Allows different clients to map checked exceptions in different ways.53*/54typedef jthrowable (*CheckedExceptionMapper)55( JNIEnv * jnienv,56jthrowable throwableToMap);5758/* Default mapper. Map everything checked to InternalError; can return null if error */59extern jthrowable60mapAllCheckedToInternalErrorMapper( JNIEnv * jnienv,61jthrowable throwableToMap);62636465/*66* Exception-helper routines that do not modify the JNIEnv.67* They require a clean JNIEnv on entry, and they guarantee a clean JNIEnv on exit.68*/6970/* creates a throwable from the supplied parameters; can return null if error */71extern jthrowable72createThrowable( JNIEnv* jnienv,73const char* className,74jstring message);7576/* creates a java.lang.InternalError; can return null if error */77extern jthrowable78createInternalError(JNIEnv * jnienv, jstring message);7980/* creates the appropriate java Throwable based on the error code; can return null if error */81extern jthrowable82createThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode);8384/* fetches the message string out of the supplied throwable, null if there is none, null if error */85extern jstring86getMessageFromThrowable( JNIEnv* jnienv,87jthrowable exception);8889/* true if the supplied throwable is unchecked. null will return true. */90extern jboolean91isUnchecked( JNIEnv* jnienv,92jthrowable exception);9394/* true if the env contains a thrown exception */95extern jboolean96checkForThrowable( JNIEnv* jnienv);9798/* true if the env is clean for JNI calls */99extern jboolean100isSafeForJNICalls( JNIEnv * jnienv);101102/*103* Logs the outstanding throwable, if one exists.104* This call assumes an outstanding exception, but does not105* modify the JNIEnv outstanding Throwable state.106*/107extern void108logThrowable( JNIEnv * jnienv);109110111/*112* These routines do modify the JNIEnv outstanding Throwable state.113*/114115/* Throws the supplied throwable. always sets the JNIEnv throwable */116extern void117throwThrowable( JNIEnv * jnienv,118jthrowable exception);119120/* returns current throwable. always clears the JNIEnv exception */121extern jthrowable122preserveThrowable(JNIEnv * jnienv);123124/* undoes preserveThrowable (Throws the supplied throwable). always sets the JNIEnv throwable */125extern void126restoreThrowable( JNIEnv * jnienv,127jthrowable preservedException);128129/* always clears the JNIEnv throwable. returns true if an exception was pending on entry. */130extern jboolean131checkForAndClearThrowable( JNIEnv * jnienv);132133/* creates the appropriate java Throwable based on the error code134* does the very best it can to make sure an exception ends up installed; uses fallback if necessary135* always sets the JNIEnv exception136*/137extern void138createAndThrowThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode);139140/* creates a java.lang.InternalError and installs it into the JNIEnv.141* does the very best it can to make sure an exception ends up installed; uses fallback if necessary142* always sets the JNIEnv exception143*/144extern void145createAndThrowInternalError(JNIEnv * jnienv);146147/* If no throwable is outstanding, do nothing.148* If a throwable is outstanding, make sure it is of a legal type according to the supplied149* mapping function.150* Leaves the "thrown" state the same (none on exit if none on entry, thrown on exit if151* thrown on entry); may change the type of the thrown exception.152*/153extern void154mapThrownThrowableIfNecessary(JNIEnv * jnienv, CheckedExceptionMapper mapper);155156#ifdef __cplusplus157} /* extern "C" */158#endif /* __cplusplus */159160161#endif162163164