Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 1 | // 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 Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 7 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 8 | #include "indirect_reference_table.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 9 | #include "macros.h" |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 10 | #include "reference_table.h" |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 11 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 12 | #include <string> |
13 | |||||
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 14 | namespace art { |
15 | |||||
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame] | 16 | class ClassLoader; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 17 | class Libraries; |
18 | class Method; | ||||
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 19 | class Mutex; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 20 | class Runtime; |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 21 | class Thread; |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 22 | |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 23 | struct JavaVMExt : public JavaVM { |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 24 | JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni); |
Elliott Hughes | de69d7f | 2011-08-18 16:49:37 -0700 | [diff] [blame] | 25 | ~JavaVMExt(); |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 26 | |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 27 | /** |
28 | * Loads the given shared library. 'path' is an absolute pathname. | ||||
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 29 | * |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 30 | * Returns 'true' on success. On failure, sets 'detail' to a |
31 | * human-readable description of the error. | ||||
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 32 | */ |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 33 | bool LoadNativeLibrary(const std::string& path, ClassLoader* class_loader, std::string& detail); |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 34 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 35 | /** |
36 | * Returns a pointer to the code for the native method 'm', found | ||||
37 | * using dlsym(3) on every native library that's been loaded so far. | ||||
38 | */ | ||||
39 | void* FindCodeForNativeMethod(Method* m); | ||||
40 | |||||
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 41 | Runtime* runtime; |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 42 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 43 | bool check_jni; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 44 | bool verbose_jni; |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 45 | |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 46 | // Used to hold references to pinned primitive arrays. |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 47 | Mutex* pins_lock; |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 48 | ReferenceTable pin_table; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 49 | |
50 | // JNI global references. | ||||
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 51 | Mutex* globals_lock; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 52 | IndirectReferenceTable globals; |
53 | |||||
54 | // JNI weak global references. | ||||
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 55 | Mutex* weak_globals_lock; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 56 | IndirectReferenceTable weak_globals; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 57 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 58 | Mutex* libraries_lock; |
59 | Libraries* libraries; | ||||
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 60 | }; |
61 | |||||
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 62 | struct JNIEnvExt : public JNIEnv { |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 63 | JNIEnvExt(Thread* self, JavaVMExt* vm); |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame^] | 64 | ~JNIEnvExt(); |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 65 | |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 66 | Thread* self; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 67 | JavaVMExt* vm; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 68 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 69 | bool check_jni; |
70 | |||||
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 71 | // Are we in a "critical" JNI call? |
72 | bool critical; | ||||
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 73 | |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 74 | // Entered JNI monitors, for bulk exit on thread detach. |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 75 | ReferenceTable monitors; |
76 | |||||
77 | // JNI local references. | ||||
78 | IndirectReferenceTable locals; | ||||
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 79 | }; |
80 | |||||
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 81 | } // namespace art |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 82 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame] | 83 | std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs); |
84 | |||||
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 85 | #endif // ART_SRC_JNI_INTERNAL_H_ |