blob: 2b3529cef235a758cd565b567be5c64a0bc4cdf2 [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 <map>
13#include <string>
14
Ian Rogersdf20fe02011-07-20 20:34:16 -070015namespace art {
16
Elliott Hughes814e4032011-08-23 12:07:56 -070017class ClassLoader;
Elliott Hughes18c07532011-08-18 15:50:51 -070018class Mutex;
Elliott Hughesf2682d52011-08-15 16:37:04 -070019class Runtime;
Elliott Hughes0af55432011-08-17 18:37:28 -070020class SharedLibrary;
Elliott Hughes18c07532011-08-18 15:50:51 -070021class Thread;
Ian Rogersdf20fe02011-07-20 20:34:16 -070022
Elliott Hughes69f5bc62011-08-24 09:26:14 -070023struct JavaVMExt : public JavaVM {
Elliott Hughes0af55432011-08-17 18:37:28 -070024 JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni);
Elliott Hughesde69d7f2011-08-18 16:49:37 -070025 ~JavaVMExt();
Elliott Hughes0af55432011-08-17 18:37:28 -070026
Elliott Hughes75770752011-08-24 17:52:38 -070027 /**
28 * Loads the given shared library. 'path' is an absolute pathname.
Elliott Hughes0af55432011-08-17 18:37:28 -070029 *
Elliott Hughes75770752011-08-24 17:52:38 -070030 * Returns 'true' on success. On failure, sets 'detail' to a
31 * human-readable description of the error.
Elliott Hughes0af55432011-08-17 18:37:28 -070032 */
Elliott Hughes75770752011-08-24 17:52:38 -070033 bool LoadNativeLibrary(const std::string& path, ClassLoader* class_loader, std::string& detail);
Elliott Hughesbbd76712011-08-17 10:25:24 -070034
Elliott Hughesf2682d52011-08-15 16:37:04 -070035 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070036
Elliott Hughes515a5bc2011-08-17 11:08:34 -070037 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070038 bool verbose_jni;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070039
Elliott Hughesbbd76712011-08-17 10:25:24 -070040 // Used to hold references to pinned primitive arrays.
Elliott Hughes75770752011-08-24 17:52:38 -070041 Mutex* pins_lock;
Elliott Hughesbbd76712011-08-17 10:25:24 -070042 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070043
44 // JNI global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070045 Mutex* globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070046 IndirectReferenceTable globals;
47
48 // JNI weak global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070049 Mutex* weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070050 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070051
52 std::map<std::string, SharedLibrary*> libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070053};
54
Elliott Hughes69f5bc62011-08-24 09:26:14 -070055struct JNIEnvExt : public JNIEnv {
Elliott Hughes75770752011-08-24 17:52:38 -070056 JNIEnvExt(Thread* self, JavaVMExt* vm);
Elliott Hughesbbd76712011-08-17 10:25:24 -070057
Elliott Hughes40ef99e2011-08-11 17:44:34 -070058 Thread* self;
Elliott Hughes75770752011-08-24 17:52:38 -070059 JavaVMExt* vm;
Carl Shapiroea4dca82011-08-01 13:45:38 -070060
Elliott Hughes515a5bc2011-08-17 11:08:34 -070061 bool check_jni;
62
Elliott Hughes40ef99e2011-08-11 17:44:34 -070063 // Are we in a "critical" JNI call?
64 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070065
Elliott Hughesbbd76712011-08-17 10:25:24 -070066 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070067 ReferenceTable monitors;
68
69 // JNI local references.
70 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070071};
72
Ian Rogersdf20fe02011-07-20 20:34:16 -070073} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070074
Elliott Hughesb465ab02011-08-24 11:21:21 -070075std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
76
Ian Rogersdf20fe02011-07-20 20:34:16 -070077#endif // ART_SRC_JNI_INTERNAL_H_