src/java.instrument/share/native/libinstrument/JavaExceptions.h
author stuefe
Tue, 29 Oct 2019 12:10:57 +0100
branchstuefe-new-metaspace-branch
changeset 58840 7678903a348f
parent 47216 71c04702a3d5
permissions -rw-r--r--
Add workaround for 8233019
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Copyright 2003 Wily Technology, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#ifndef _JAVAEXCEPTIONS_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#define _JAVAEXCEPTIONS_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include    <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include    <jvmti.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This module contains utility routines for manipulating Java throwables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * and JNIEnv throwable state from native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Set up static state. Needs java, must be called at or after VMInit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Returns true if it succeeds, false if it fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
extern jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
initializeFallbackError(JNIEnv* jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *  Mapping support. Allows different clients to map checked exceptions in different ways.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
typedef jthrowable (*CheckedExceptionMapper)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    (   JNIEnv *    jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        jthrowable  throwableToMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/* Default mapper. Map everything checked to InternalError; can return null if error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
extern jthrowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
mapAllCheckedToInternalErrorMapper( JNIEnv *    jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                    jthrowable  throwableToMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *  Exception-helper routines that do not modify the JNIEnv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *  They require a clean JNIEnv on entry, and they guarantee a clean JNIEnv on exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/* creates a throwable from the supplied parameters; can return null if error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
extern jthrowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
createThrowable(    JNIEnv*     jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    const char* className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    jstring     message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/* creates a java.lang.InternalError; can return null if error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
extern jthrowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
createInternalError(JNIEnv * jnienv, jstring message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
/* creates the appropriate java Throwable based on the error code; can return null if error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
extern jthrowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
createThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/* fetches the message string out of the supplied throwable, null if there is none, null if error   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
extern jstring
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
getMessageFromThrowable(    JNIEnv*     jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                            jthrowable  exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
/* true if the supplied throwable is unchecked. null will return true.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
extern jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
isUnchecked(    JNIEnv*     jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                jthrowable  exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/* true if the env contains a thrown exception */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
extern jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
checkForThrowable(  JNIEnv*     jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
/* true if the env is clean for JNI calls */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
extern jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
isSafeForJNICalls(  JNIEnv * jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * Logs the outstanding throwable, if one exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * This call assumes an outstanding exception, but does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * modify the JNIEnv outstanding Throwable state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
extern void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
logThrowable(   JNIEnv * jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *  These routines do modify the JNIEnv outstanding Throwable state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
/* Throws the supplied throwable. always sets the JNIEnv throwable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
extern void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
throwThrowable(     JNIEnv *    jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    jthrowable  exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
/* returns current throwable. always clears the JNIEnv exception */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
extern jthrowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
preserveThrowable(JNIEnv * jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
/* undoes preserveThrowable (Throws the supplied throwable). always sets the JNIEnv throwable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
extern void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
restoreThrowable(   JNIEnv *    jnienv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    jthrowable  preservedException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
/* always clears the JNIEnv throwable. returns true if an exception was pending on entry. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
extern jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
checkForAndClearThrowable(  JNIEnv *    jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
/* creates the appropriate java Throwable based on the error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * does the very best it can to make sure an exception ends up installed; uses fallback if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * always sets the JNIEnv exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
extern void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
createAndThrowThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
/* creates a java.lang.InternalError and installs it into the JNIEnv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * does the very best it can to make sure an exception ends up installed; uses fallback if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * always sets the JNIEnv exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
extern void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
createAndThrowInternalError(JNIEnv * jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
/* If no throwable is outstanding, do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * If a throwable is outstanding, make sure it is of a legal type according to the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * mapping function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * Leaves the "thrown" state the same (none on exit if none on entry, thrown on exit if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * thrown on entry); may change the type of the thrown exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
extern void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
mapThrownThrowableIfNecessary(JNIEnv * jnienv, CheckedExceptionMapper mapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#endif /* __cplusplus */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#endif