jniCheck.hpp revision 3602:da91efe96a93
1198090Srdivacky/*
2198090Srdivacky * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3198090Srdivacky * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4198090Srdivacky *
5198090Srdivacky * This code is free software; you can redistribute it and/or modify it
6198090Srdivacky * under the terms of the GNU General Public License version 2 only, as
7198090Srdivacky * published by the Free Software Foundation.
8198090Srdivacky *
9198090Srdivacky * This code is distributed in the hope that it will be useful, but WITHOUT
10198090Srdivacky * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11198090Srdivacky * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12198090Srdivacky * version 2 for more details (a copy is included in the LICENSE file that
13198090Srdivacky * accompanied this code).
14198090Srdivacky *
15198090Srdivacky * You should have received a copy of the GNU General Public License version
16198090Srdivacky * 2 along with this work; if not, write to the Free Software Foundation,
17198090Srdivacky * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18198090Srdivacky *
19198090Srdivacky * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20198090Srdivacky * or visit www.oracle.com if you need additional information or have any
21198090Srdivacky * questions.
22198090Srdivacky *
23198090Srdivacky */
24198090Srdivacky
25198090Srdivacky#ifndef SHARE_VM_PRIMS_JNICHECK_HPP
26198090Srdivacky#define SHARE_VM_PRIMS_JNICHECK_HPP
27198090Srdivacky
28198090Srdivacky#ifndef KERNEL
29198090Srdivacky#include "runtime/thread.hpp"
30198090Srdivacky#endif
31198090Srdivacky
32198090Srdivackyextern "C" {
33198090Srdivacky  // Report a JNI failure caught by -Xcheck:jni.  Perform a core dump.
34198090Srdivacky  // Note: two variations -- one to be called when in VM state (e.g. when
35198090Srdivacky  // within IN_VM macro), one to be called when in NATIVE state.
36198090Srdivacky
37198090Srdivacky  // When in VM state:
38198090Srdivacky  static void ReportJNIFatalError(JavaThread* thr, const char *msg) {
39198090Srdivacky    tty->print_cr("FATAL ERROR in native method: %s", msg);
40198090Srdivacky    thr->print_stack();
41198090Srdivacky    os::abort(true);
42198090Srdivacky  }
43198090Srdivacky}
44198090Srdivacky
45198090Srdivacky//
46198090Srdivacky// Checked JNI routines that are useful for outside of checked JNI
47198090Srdivacky//
48198090Srdivacky
49198090Srdivackyclass jniCheck : public AllStatic {
50198090Srdivacky public:
51198090Srdivacky  static oop validate_handle(JavaThread* thr, jobject obj);
52198090Srdivacky  static oop validate_object(JavaThread* thr, jobject obj);
53198090Srdivacky  static Klass* validate_class(JavaThread* thr, jclass clazz, bool allow_primitive = false);
54198090Srdivacky  static void validate_class_descriptor(JavaThread* thr, const char* name);
55198090Srdivacky  static void validate_throwable_klass(JavaThread* thr, Klass* klass);
56198090Srdivacky  static void validate_call_object(JavaThread* thr, jobject obj, jmethodID method_id);
57198090Srdivacky  static void validate_call_class(JavaThread* thr, jclass clazz, jmethodID method_id);
58198090Srdivacky  static Method* validate_jmethod_id(JavaThread* thr, jmethodID method_id);
59198090Srdivacky};
60198090Srdivacky
61198090Srdivacky#endif // SHARE_VM_PRIMS_JNICHECK_HPP
62198090Srdivacky