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 | 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 | |
| 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 | Runtime* runtime; |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 47 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 48 | bool check_jni; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 49 | bool verbose_jni; |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 50 | |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 51 | // Used to hold references to pinned primitive arrays. |
| 52 | ReferenceTable pin_table; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 53 | |
| 54 | // JNI global references. |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 55 | Mutex* globals_lock; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 56 | IndirectReferenceTable globals; |
| 57 | |
| 58 | // JNI weak global references. |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 59 | Mutex* weak_globals_lock; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 60 | IndirectReferenceTable weak_globals; |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 61 | |
| 62 | std::map<std::string, SharedLibrary*> libraries; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Elliott Hughes | 69f5bc6 | 2011-08-24 09:26:14 -0700 | [diff] [blame] | 65 | struct JNIEnvExt : public JNIEnv { |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 66 | JNIEnvExt(Thread* self, bool check_jni); |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 67 | |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 68 | Thread* self; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 69 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 70 | bool check_jni; |
| 71 | |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 72 | // Are we in a "critical" JNI call? |
| 73 | bool critical; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 74 | |
Elliott Hughes | bbd7671 | 2011-08-17 10:25:24 -0700 | [diff] [blame] | 75 | // Entered JNI monitors, for bulk exit on thread detach. |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 76 | ReferenceTable monitors; |
| 77 | |
| 78 | // JNI local references. |
| 79 | IndirectReferenceTable locals; |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 82 | } // namespace art |
Carl Shapiro | ea4dca8 | 2011-08-01 13:45:38 -0700 | [diff] [blame] | 83 | |
Elliott Hughes | b465ab0 | 2011-08-24 11:21:21 -0700 | [diff] [blame^] | 84 | std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs); |
| 85 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 86 | #endif // ART_SRC_JNI_INTERNAL_H_ |