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 <map> |
| 13 | #include <string> |
| 14 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 15 | namespace art { |
| 16 | |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame^] | 17 | class ClassLoader; |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 18 | class Mutex; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 19 | class Runtime; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 20 | class SharedLibrary; |
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 | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 23 | struct JavaVMExt { |
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 | |
| 27 | /* |
| 28 | * Load native code from the specified absolute pathname. Per the spec, |
| 29 | * if we've already loaded a library with the specified pathname, we |
| 30 | * return without doing anything. |
| 31 | * |
| 32 | * TODO: for better results we should canonicalize the pathname. For fully |
| 33 | * correct results we should stat to get the inode and compare that. The |
| 34 | * existing implementation is fine so long as everybody is using |
| 35 | * System.loadLibrary. |
| 36 | * |
| 37 | * The library will be associated with the specified class loader. The JNI |
| 38 | * spec says we can't load the same library into more than one class loader. |
| 39 | * |
| 40 | * Returns true on success. On failure, returns false and sets *detail to a |
| 41 | * human-readable description of the error or NULL if no detail is |
| 42 | * available; ownership of the string is transferred to the caller. |
| 43 | */ |
Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame^] | 44 | bool LoadNativeLibrary(const std::string& path, ClassLoader* class_loader, char** detail); |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 45 | |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 46 | // Must be first to correspond with JNIEnv. |
| 47 | const struct JNIInvokeInterface* fns; |
| 48 | |
| 49 | Runtime* runtime; |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 50 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 51 | bool check_jni; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 52 | bool verbose_jni; |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 53 | |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 54 | // Used to hold references to pinned primitive arrays. |
| 55 | ReferenceTable pin_table; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 56 | |
| 57 | // JNI global references. |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 58 | Mutex* globals_lock; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 59 | IndirectReferenceTable globals; |
| 60 | |
| 61 | // JNI weak global references. |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 62 | Mutex* weak_globals_lock; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 63 | IndirectReferenceTable weak_globals; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 64 | |
| 65 | std::map<std::string, SharedLibrary*> libraries; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 68 | struct JNIEnvExt { |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 69 | JNIEnvExt(Thread* self, bool check_jni); |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 70 | |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 71 | // Must be first to correspond with JavaVM. |
| 72 | const struct JNINativeInterface* fns; |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 73 | |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 74 | Thread* self; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 75 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 76 | bool check_jni; |
| 77 | |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 78 | // Are we in a "critical" JNI call? |
| 79 | bool critical; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 80 | |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 81 | // Entered JNI monitors, for bulk exit on thread detach. |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 82 | ReferenceTable monitors; |
| 83 | |
| 84 | // JNI local references. |
| 85 | IndirectReferenceTable locals; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 88 | } // namespace art |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 89 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 90 | #endif // ART_SRC_JNI_INTERNAL_H_ |