blob: a4362d334203d778bcd341f78ff0fe9195263aae [file] [log] [blame]
Ian Rogersdf20fe02011-07-20 20:34:16 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_JNI_INTERNAL_H_
4#define ART_SRC_JNI_INTERNAL_H_
5
6#include "jni.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007
Elliott Hughes6c1a3942011-08-17 15:00:06 -07008#include "indirect_reference_table.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07009#include "macros.h"
Elliott Hughesbbd76712011-08-17 10:25:24 -070010#include "reference_table.h"
Ian Rogersdf20fe02011-07-20 20:34:16 -070011
Elliott Hughes0af55432011-08-17 18:37:28 -070012#include <string>
13
Ian Rogersdf20fe02011-07-20 20:34:16 -070014namespace art {
15
Elliott Hughes814e4032011-08-23 12:07:56 -070016class ClassLoader;
Elliott Hughes79082e32011-08-25 12:07:32 -070017class Libraries;
18class Method;
Elliott Hughes18c07532011-08-18 15:50:51 -070019class Mutex;
Elliott Hughesf2682d52011-08-15 16:37:04 -070020class Runtime;
Elliott Hughes18c07532011-08-18 15:50:51 -070021class Thread;
Ian Rogersdf20fe02011-07-20 20:34:16 -070022
Elliott Hughesa2501992011-08-26 19:39:54 -070023void JniAbort(const char* jni_function_name);
24
Elliott Hughes69f5bc62011-08-24 09:26:14 -070025struct JavaVMExt : public JavaVM {
Elliott Hughes0af55432011-08-17 18:37:28 -070026 JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni);
Elliott Hughesde69d7f2011-08-18 16:49:37 -070027 ~JavaVMExt();
Elliott Hughes0af55432011-08-17 18:37:28 -070028
Elliott Hughes75770752011-08-24 17:52:38 -070029 /**
30 * Loads the given shared library. 'path' is an absolute pathname.
Elliott Hughes0af55432011-08-17 18:37:28 -070031 *
Elliott Hughes75770752011-08-24 17:52:38 -070032 * Returns 'true' on success. On failure, sets 'detail' to a
33 * human-readable description of the error.
Elliott Hughes0af55432011-08-17 18:37:28 -070034 */
Elliott Hughes75770752011-08-24 17:52:38 -070035 bool LoadNativeLibrary(const std::string& path, ClassLoader* class_loader, std::string& detail);
Elliott Hughesbbd76712011-08-17 10:25:24 -070036
Elliott Hughes79082e32011-08-25 12:07:32 -070037 /**
38 * Returns a pointer to the code for the native method 'm', found
39 * using dlsym(3) on every native library that's been loaded so far.
40 */
41 void* FindCodeForNativeMethod(Method* m);
42
Elliott Hughesf2682d52011-08-15 16:37:04 -070043 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070044
Elliott Hughesa2501992011-08-26 19:39:54 -070045 // Used for testing. By default, we'll LOG(FATAL) the reason.
46 void (*check_jni_abort_hook)(const std::string& reason);
47
Elliott Hughes515a5bc2011-08-17 11:08:34 -070048 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070049 bool verbose_jni;
Elliott Hughesa2501992011-08-26 19:39:54 -070050 bool force_copy;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070051
Elliott Hughesbbd76712011-08-17 10:25:24 -070052 // Used to hold references to pinned primitive arrays.
Elliott Hughes75770752011-08-24 17:52:38 -070053 Mutex* pins_lock;
Elliott Hughesbbd76712011-08-17 10:25:24 -070054 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070055
56 // JNI global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070057 Mutex* globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070058 IndirectReferenceTable globals;
59
60 // JNI weak global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070061 Mutex* weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070062 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070063
Elliott Hughes79082e32011-08-25 12:07:32 -070064 Mutex* libraries_lock;
65 Libraries* libraries;
Elliott Hughesa2501992011-08-26 19:39:54 -070066
67 // Used by -Xcheck:jni.
68 const JNIInvokeInterface* unchecked_functions;
Elliott Hughesf2682d52011-08-15 16:37:04 -070069};
70
Elliott Hughes69f5bc62011-08-24 09:26:14 -070071struct JNIEnvExt : public JNIEnv {
Elliott Hughes75770752011-08-24 17:52:38 -070072 JNIEnvExt(Thread* self, JavaVMExt* vm);
Elliott Hughesc1674ed2011-08-25 18:09:09 -070073 ~JNIEnvExt();
Elliott Hughesbbd76712011-08-17 10:25:24 -070074
Elliott Hughes40ef99e2011-08-11 17:44:34 -070075 Thread* self;
Elliott Hughes75770752011-08-24 17:52:38 -070076 JavaVMExt* vm;
Carl Shapiroea4dca82011-08-01 13:45:38 -070077
Elliott Hughes515a5bc2011-08-17 11:08:34 -070078 bool check_jni;
79
Elliott Hughesa2501992011-08-26 19:39:54 -070080 // How many nested "critical" JNI calls are we in?
81 int critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070082
Elliott Hughesbbd76712011-08-17 10:25:24 -070083 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070084 ReferenceTable monitors;
85
86 // JNI local references.
87 IndirectReferenceTable locals;
Elliott Hughesa2501992011-08-26 19:39:54 -070088
89 // Used by -Xcheck:jni.
90 const JNINativeInterface* unchecked_functions;
Carl Shapiroea4dca82011-08-01 13:45:38 -070091};
92
Elliott Hughesa2501992011-08-26 19:39:54 -070093const JNINativeInterface* GetCheckJniNativeInterface();
94const JNIInvokeInterface* GetCheckJniInvokeInterface();
95
Ian Rogersdf20fe02011-07-20 20:34:16 -070096} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070097
Elliott Hughesb465ab02011-08-24 11:21:21 -070098std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
99
Ian Rogersdf20fe02011-07-20 20:34:16 -0700100#endif // ART_SRC_JNI_INTERNAL_H_