1/*
2 * Copyright (c) 2017, 2019, 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_JVMCI_JVMCIEXCEPTIONS_HPP
26#define SHARE_JVMCI_JVMCIEXCEPTIONS_HPP
27
28class JVMCIEnv;
29
30// JVMCIEnv exception utility macros. Analagous to the regular CHECK, TRAP and THREAD macros.
31
32#define JVMCIENV __jvmci_env__
33#define JVMCI_TRAPS JVMCIEnv* JVMCIENV
34
35#define JNI_JVMCIENV(thread, env) \
36 JVMCIEnv __stack_jvmci_env__(thread, env, __FILE__, __LINE__); \
37 JVMCIEnv* JVMCIENV = &__stack_jvmci_env__
38
39#define THREAD_JVMCIENV(thread) \
40 JVMCIEnv __stack_jvmci_env__(thread, __FILE__, __LINE__); \
41 JVMCIEnv* JVMCIENV = &__stack_jvmci_env__
42
43#define JVMCI_PENDING_EXCEPTION (JVMCIENV->pending_exception())
44#define JVMCI_HAS_PENDING_EXCEPTION (JVMCIENV->has_pending_exception())
45#define JVMCI_CLEAR_PENDING_EXCEPTION (JVMCIENV->clear_pending_exception())
46
47#define JVMCI_CHECK JVMCIENV); if (JVMCI_HAS_PENDING_EXCEPTION) return ; (void)(0
48#define JVMCI_CHECK_(result) JVMCIENV); if (JVMCI_HAS_PENDING_EXCEPTION) return result; (void)(0
49#define JVMCI_CHECK_0 JVMCI_CHECK_(0)
50#define JVMCI_CHECK_NULL JVMCI_CHECK_(NULL)
51#define JVMCI_CHECK_false JVMCI_CHECK_(false)
52#define JVMCI_CHECK_OK JVMCI_CHECK_(JVMCI::ok)
53
54#define JVMCI_ERROR(...) \
55 { JVMCIENV->fthrow_error(__FILE__, __LINE__, __VA_ARGS__); return; }
56
57#define JVMCI_ERROR_(ret, ...) \
58 { JVMCIENV->fthrow_error( __FILE__, __LINE__, __VA_ARGS__); return ret; }
59
60#define JVMCI_ERROR_0(...) JVMCI_ERROR_(0, __VA_ARGS__)
61#define JVMCI_ERROR_NULL(...) JVMCI_ERROR_(NULL, __VA_ARGS__)
62#define JVMCI_ERROR_OK(...) JVMCI_ERROR_(JVMCI::ok, __VA_ARGS__)
63
64#define JVMCI_THROW(name) { JVMCIENV->throw_##name(); return; }
65#define JVMCI_THROW_NULL(name) { JVMCIENV->throw_##name(); return NULL; }
66#define JVMCI_THROW_0(name) { JVMCIENV->throw_##name(); return 0; }
67#define JVMCI_THROW_MSG_NULL(name, msg) { JVMCIENV->throw_##name(msg); return NULL; }
68#define JVMCI_THROW_MSG_(name, msg, value) { JVMCIENV->throw_##name(msg); return (value); }
69#define JVMCI_THROW_MSG_0(name, msg) { JVMCIENV->throw_##name(msg); return 0; }
70#define JVMCI_THROW_MSG(name, msg) { JVMCIENV->throw_##name(msg); return; }
71#define JVMCI_THROW_(name, value) { JVMCIENV->throw_##name(); return (value); }
72
73#define JVMCI_CATCH \
74 JVMCIENV); if (JVMCI_HAS_PENDING_EXCEPTION) { \
75 JVMCIENV->describe_pending_exception(true); \
76 ShouldNotReachHere(); \
77 } (void)(0
78
79#endif // SHARE_JVMCI_JVMCIEXCEPTIONS_HPP
80