blob: b3837c409dd4708e692ac027c69f4c97a796e0c6 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ian Rogersdf20fe02011-07-20 20:34:16 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_JNI_INTERNAL_H_
18#define ART_RUNTIME_JNI_INTERNAL_H_
Ian Rogersdf20fe02011-07-20 20:34:16 -070019
Ian Rogers68d8b422014-07-17 11:09:10 -070020#include <jni.h>
Elliott Hughesae80b492012-04-24 10:43:17 -070021#include <iosfwd>
Elliott Hughes0af55432011-08-17 18:37:28 -070022
Andreas Gampe13b27842016-11-07 16:48:23 -080023#include "base/macros.h"
24
Elliott Hugheseac76672012-05-24 21:56:51 -070025#ifndef NATIVE_METHOD
26#define NATIVE_METHOD(className, functionName, signature) \
27 { #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) }
28#endif
Narayan Kamath0dd8c392016-02-01 13:22:18 +000029
30// TODO: Can we do a better job of supporting overloading ?
31#ifndef OVERLOADED_NATIVE_METHOD
32#define OVERLOADED_NATIVE_METHOD(className, functionName, signature, identifier) \
33 { #functionName, signature, reinterpret_cast<void*>(className ## _ ## identifier) }
34#endif
35
Elliott Hugheseac76672012-05-24 21:56:51 -070036#define REGISTER_NATIVE_METHODS(jni_class_name) \
37 RegisterNativeMethods(env, jni_class_name, gMethods, arraysize(gMethods))
38
Ian Rogersdf20fe02011-07-20 20:34:16 -070039namespace art {
Ian Rogersdf20fe02011-07-20 20:34:16 -070040
Andreas Gampe08883de2016-11-08 13:20:52 -080041class ArtField;
Andreas Gampe13b27842016-11-07 16:48:23 -080042class ArtMethod;
43
Ian Rogers68d8b422014-07-17 11:09:10 -070044const JNINativeInterface* GetJniNativeInterface();
Mathieu Chartier4d87df62016-01-07 15:14:19 -080045const JNINativeInterface* GetRuntimeShutdownNativeInterface();
Ian Rogers68d8b422014-07-17 11:09:10 -070046
47// Similar to RegisterNatives except its passed a descriptor for a class name and failures are
48// fatal.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070049void RegisterNativeMethods(JNIEnv* env, const char* jni_class_name, const JNINativeMethod* methods,
Ian Rogersabd7be92013-08-15 10:26:54 -070050 jint method_count);
Elliott Hughesa2501992011-08-26 19:39:54 -070051
Elliott Hughesa4f94742012-05-29 16:28:38 -070052int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobject cause);
53
Andreas Gampe13b27842016-11-07 16:48:23 -080054namespace jni {
55
56ALWAYS_INLINE
Andreas Gampe08883de2016-11-08 13:20:52 -080057static inline ArtField* DecodeArtField(jfieldID fid) {
58 return reinterpret_cast<ArtField*>(fid);
59}
60
61ALWAYS_INLINE
62static inline jfieldID EncodeArtField(ArtField* field) {
63 return reinterpret_cast<jfieldID>(field);
64}
65
66ALWAYS_INLINE
Andreas Gampe13b27842016-11-07 16:48:23 -080067static inline jmethodID EncodeArtMethod(ArtMethod* art_method) {
68 return reinterpret_cast<jmethodID>(art_method);
69}
70
71ALWAYS_INLINE
72static inline ArtMethod* DecodeArtMethod(jmethodID method_id) {
73 return reinterpret_cast<ArtMethod*>(method_id);
74}
75
76} // namespace jni
Ian Rogersdf20fe02011-07-20 20:34:16 -070077} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070078
Elliott Hughesb465ab02011-08-24 11:21:21 -070079std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
Ian Rogers68d8b422014-07-17 11:09:10 -070080
Brian Carlstromfc0e3212013-07-17 14:40:12 -070081#endif // ART_RUNTIME_JNI_INTERNAL_H_