| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_JNI_JAVA_VM_EXT_H_ |
| 18 | #define ART_RUNTIME_JNI_JAVA_VM_EXT_H_ |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 19 | |
| 20 | #include "jni.h" |
| 21 | |
| 22 | #include "base/macros.h" |
| 23 | #include "base/mutex.h" |
| 24 | #include "indirect_reference_table.h" |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 25 | #include "obj_ptr.h" |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 26 | #include "reference_table.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | namespace mirror { |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 31 | class Array; |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 32 | } // namespace mirror |
| 33 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 34 | class ArtMethod; |
| Andreas Gampe | 57cf00b | 2017-06-05 17:15:32 -0700 | [diff] [blame] | 35 | class IsMarkedVisitor; |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 36 | class Libraries; |
| 37 | class ParsedOptions; |
| 38 | class Runtime; |
| Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 39 | struct RuntimeArgumentMap; |
| Vladimir Marko | 17491ac | 2020-12-01 12:02:29 +0000 | [diff] [blame] | 40 | class ScopedObjectAccess; |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 41 | |
| Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 42 | class JavaVMExt; |
| 43 | // Hook definition for runtime plugins. |
| 44 | using GetEnvHook = jint (*)(JavaVMExt* vm, /*out*/void** new_env, jint version); |
| 45 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 46 | class JavaVMExt : public JavaVM { |
| 47 | public: |
| Richard Uhler | da0a69e | 2016-10-11 15:06:38 +0100 | [diff] [blame] | 48 | // Creates a new JavaVMExt object. |
| 49 | // Returns nullptr on error, in which case error_msg is set to a message |
| 50 | // describing the error. |
| 51 | static std::unique_ptr<JavaVMExt> Create(Runtime* runtime, |
| 52 | const RuntimeArgumentMap& runtime_options, |
| 53 | std::string* error_msg); |
| 54 | |
| 55 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 56 | ~JavaVMExt(); |
| 57 | |
| 58 | bool ForceCopy() const { |
| 59 | return force_copy_; |
| 60 | } |
| 61 | |
| 62 | bool IsCheckJniEnabled() const { |
| 63 | return check_jni_; |
| 64 | } |
| 65 | |
| 66 | bool IsTracingEnabled() const { |
| 67 | return tracing_enabled_; |
| 68 | } |
| 69 | |
| 70 | Runtime* GetRuntime() const { |
| 71 | return runtime_; |
| 72 | } |
| 73 | |
| 74 | void SetCheckJniAbortHook(void (*hook)(void*, const std::string&), void* data) { |
| 75 | check_jni_abort_hook_ = hook; |
| 76 | check_jni_abort_hook_data_ = data; |
| 77 | } |
| 78 | |
| 79 | // Aborts execution unless there is an abort handler installed in which case it will return. Its |
| 80 | // therefore important that callers return after aborting as otherwise code following the abort |
| 81 | // will be executed in the abort handler case. |
| 82 | void JniAbort(const char* jni_function_name, const char* msg); |
| 83 | |
| 84 | void JniAbortV(const char* jni_function_name, const char* fmt, va_list ap); |
| 85 | |
| 86 | void JniAbortF(const char* jni_function_name, const char* fmt, ...) |
| 87 | __attribute__((__format__(__printf__, 3, 4))); |
| 88 | |
| 89 | // If both "-Xcheck:jni" and "-Xjnitrace:" are enabled, we print trace messages |
| 90 | // when a native method that matches the -Xjnitrace argument calls a JNI function |
| 91 | // such as NewByteArray. |
| 92 | // If -verbose:third-party-jni is on, we want to log any JNI function calls |
| 93 | // made by a third-party native method. |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 94 | bool ShouldTrace(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Loads the given shared library. 'path' is an absolute pathname. |
| 98 | * |
| Dmitriy Ivanov | f5a3099 | 2015-11-11 14:18:55 -0800 | [diff] [blame] | 99 | * Returns 'true' on success. On failure, sets 'error_msg' to a |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 100 | * human-readable description of the error. |
| 101 | */ |
| Dimitry Ivanov | 942dc298 | 2016-02-24 13:33:33 -0800 | [diff] [blame] | 102 | bool LoadNativeLibrary(JNIEnv* env, |
| 103 | const std::string& path, |
| 104 | jobject class_loader, |
| Nicolas Geoffray | 96259f1 | 2019-01-18 10:04:51 +0000 | [diff] [blame] | 105 | jclass caller_class, |
| Dimitry Ivanov | d5bbadf | 2015-12-15 14:08:18 -0800 | [diff] [blame] | 106 | std::string* error_msg); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 107 | |
| Mathieu Chartier | 598302a | 2015-09-23 14:52:39 -0700 | [diff] [blame] | 108 | // Unload native libraries with cleared class loaders. |
| 109 | void UnloadNativeLibraries() |
| 110 | REQUIRES(!Locks::jni_libraries_lock_) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 111 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Mathieu Chartier | 598302a | 2015-09-23 14:52:39 -0700 | [diff] [blame] | 112 | |
| Nicolas Geoffray | 21b6568 | 2019-03-12 00:49:45 +0000 | [diff] [blame] | 113 | // Unload all boot classpath native libraries. |
| 114 | void UnloadBootNativeLibraries() |
| 115 | REQUIRES(!Locks::jni_libraries_lock_) |
| 116 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 117 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 118 | /** |
| 119 | * Returns a pointer to the code for the native method 'm', found |
| 120 | * using dlsym(3) on every native library that's been loaded so far. |
| 121 | */ |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 122 | void* FindCodeForNativeMethod(ArtMethod* m) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 123 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 124 | |
| 125 | void DumpForSigQuit(std::ostream& os) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 126 | REQUIRES(!Locks::jni_libraries_lock_, |
| 127 | !Locks::jni_globals_lock_, |
| 128 | !Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 129 | |
| 130 | void DumpReferenceTables(std::ostream& os) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 131 | REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 8a2a1fc | 2017-09-29 17:53:18 -0700 | [diff] [blame] | 132 | REQUIRES(!Locks::jni_globals_lock_, |
| 133 | !Locks::jni_weak_globals_lock_, |
| 134 | !Locks::alloc_tracker_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 135 | |
| 136 | bool SetCheckJniEnabled(bool enabled); |
| 137 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 138 | void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 139 | REQUIRES(!Locks::jni_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 140 | |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 141 | void DisallowNewWeakGlobals() |
| 142 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 143 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| 144 | void AllowNewWeakGlobals() |
| 145 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 146 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| 147 | void BroadcastForNewWeakGlobals() |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 148 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 149 | |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 150 | jobject AddGlobalRef(Thread* self, ObjPtr<mirror::Object> obj) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 151 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 152 | REQUIRES(!Locks::jni_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 153 | |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 154 | jweak AddWeakGlobalRef(Thread* self, ObjPtr<mirror::Object> obj) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 155 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 156 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 157 | |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 158 | void DeleteGlobalRef(Thread* self, jobject obj) REQUIRES(!Locks::jni_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 159 | |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 160 | void DeleteWeakGlobalRef(Thread* self, jweak obj) REQUIRES(!Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 161 | |
| Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 162 | void SweepJniWeakGlobals(IsMarkedVisitor* visitor) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 163 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 164 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 165 | |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 166 | ObjPtr<mirror::Object> DecodeGlobal(IndirectRef ref) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 167 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 168 | |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 169 | void UpdateGlobal(Thread* self, IndirectRef ref, ObjPtr<mirror::Object> result) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 170 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 171 | REQUIRES(!Locks::jni_globals_lock_); |
| Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 172 | |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 173 | ObjPtr<mirror::Object> DecodeWeakGlobal(Thread* self, IndirectRef ref) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 174 | REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 175 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 176 | |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 177 | ObjPtr<mirror::Object> DecodeWeakGlobalLocked(Thread* self, IndirectRef ref) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 178 | REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 179 | REQUIRES(Locks::jni_weak_globals_lock_); |
| Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 180 | |
| Hiroshi Yamauchi | 498b160 | 2015-09-16 21:11:44 -0700 | [diff] [blame] | 181 | // Like DecodeWeakGlobal() but to be used only during a runtime shutdown where self may be |
| 182 | // null. |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 183 | ObjPtr<mirror::Object> DecodeWeakGlobalDuringShutdown(Thread* self, IndirectRef ref) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 184 | REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 185 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Hiroshi Yamauchi | 498b160 | 2015-09-16 21:11:44 -0700 | [diff] [blame] | 186 | |
| Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 187 | // Checks if the weak global ref has been cleared by the GC without decode (read barrier.) |
| 188 | bool IsWeakGlobalCleared(Thread* self, IndirectRef ref) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 189 | REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 190 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 191 | |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 192 | void UpdateWeakGlobal(Thread* self, IndirectRef ref, ObjPtr<mirror::Object> result) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 193 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 194 | REQUIRES(!Locks::jni_weak_globals_lock_); |
| Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 195 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 196 | const JNIInvokeInterface* GetUncheckedFunctions() const { |
| 197 | return unchecked_functions_; |
| 198 | } |
| 199 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 200 | void TrimGlobals() REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 201 | REQUIRES(!Locks::jni_globals_lock_); |
| Mathieu Chartier | 91c2f0c | 2014-11-26 11:21:15 -0800 | [diff] [blame] | 202 | |
| Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 203 | jint HandleGetEnv(/*out*/void** env, jint version); |
| 204 | |
| 205 | void AddEnvironmentHook(GetEnvHook hook); |
| 206 | |
| 207 | static bool IsBadJniVersion(int version); |
| 208 | |
| Andreas Gampe | 473191c | 2017-12-28 16:55:31 -0800 | [diff] [blame] | 209 | // Return the library search path for the given classloader, if the classloader is of a |
| 210 | // well-known type. The jobject will be a local reference and is expected to be managed by the |
| 211 | // caller. |
| 212 | static jstring GetLibrarySearchPath(JNIEnv* env, jobject class_loader); |
| 213 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 214 | private: |
| Richard Uhler | da0a69e | 2016-10-11 15:06:38 +0100 | [diff] [blame] | 215 | // The constructor should not be called directly. It may leave the object in |
| 216 | // an erroneous state, and the result needs to be checked. |
| 217 | JavaVMExt(Runtime* runtime, const RuntimeArgumentMap& runtime_options, std::string* error_msg); |
| 218 | |
| Mathieu Chartier | 30b5e27 | 2015-09-01 11:14:34 -0700 | [diff] [blame] | 219 | // Return true if self can currently access weak globals. |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | bool MayAccessWeakGlobalsUnlocked(Thread* self) const REQUIRES_SHARED(Locks::mutator_lock_); |
| Mathieu Chartier | 30b5e27 | 2015-09-01 11:14:34 -0700 | [diff] [blame] | 221 | bool MayAccessWeakGlobals(Thread* self) const |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 222 | REQUIRES_SHARED(Locks::mutator_lock_) |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 223 | REQUIRES(Locks::jni_weak_globals_lock_); |
| Mathieu Chartier | 30b5e27 | 2015-09-01 11:14:34 -0700 | [diff] [blame] | 224 | |
| Hans Boehm | d7b4161 | 2021-06-17 18:31:14 -0700 | [diff] [blame] | 225 | void WaitForWeakGlobalsAccess(Thread* self) |
| 226 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 227 | REQUIRES(Locks::jni_weak_globals_lock_); |
| 228 | |
| Andreas Gampe | 1b35b46 | 2017-09-29 18:52:15 -0700 | [diff] [blame] | 229 | void CheckGlobalRefAllocationTracking(); |
| 230 | |
| Hans Boehm | 592bcea | 2021-07-02 22:20:52 -0700 | [diff] [blame] | 231 | inline void MaybeTraceGlobals() REQUIRES(Locks::jni_globals_lock_); |
| 232 | inline void MaybeTraceWeakGlobals() REQUIRES(Locks::jni_weak_globals_lock_); |
| 233 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 234 | Runtime* const runtime_; |
| 235 | |
| 236 | // Used for testing. By default, we'll LOG(FATAL) the reason. |
| 237 | void (*check_jni_abort_hook_)(void* data, const std::string& reason); |
| 238 | void* check_jni_abort_hook_data_; |
| 239 | |
| 240 | // Extra checking. |
| 241 | bool check_jni_; |
| Ian Rogers | ac4d45a | 2018-02-15 11:19:01 -0800 | [diff] [blame] | 242 | const bool force_copy_; |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 243 | const bool tracing_enabled_; |
| 244 | |
| 245 | // Extra diagnostics. |
| 246 | const std::string trace_; |
| 247 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 248 | // Not guarded by globals_lock since we sometimes use SynchronizedGet in Thread::DecodeJObject. |
| 249 | IndirectReferenceTable globals_; |
| 250 | |
| Mathieu Chartier | 598302a | 2015-09-23 14:52:39 -0700 | [diff] [blame] | 251 | // No lock annotation since UnloadNativeLibraries is called on libraries_ but locks the |
| 252 | // jni_libraries_lock_ internally. |
| 253 | std::unique_ptr<Libraries> libraries_; |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 254 | |
| 255 | // Used by -Xcheck:jni. |
| 256 | const JNIInvokeInterface* const unchecked_functions_; |
| 257 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 258 | // Since weak_globals_ contain weak roots, be careful not to |
| 259 | // directly access the object references in it. Use Get() with the |
| 260 | // read barrier enabled. |
| Mathieu Chartier | 30b5e27 | 2015-09-01 11:14:34 -0700 | [diff] [blame] | 261 | // Not guarded by weak_globals_lock since we may use SynchronizedGet in DecodeWeakGlobal. |
| 262 | IndirectReferenceTable weak_globals_; |
| 263 | // Not guarded by weak_globals_lock since we may use SynchronizedGet in DecodeWeakGlobal. |
| 264 | Atomic<bool> allow_accessing_weak_globals_; |
| Andreas Gampe | 05a364c | 2016-10-14 13:27:12 -0700 | [diff] [blame] | 265 | ConditionVariable weak_globals_add_condition_ GUARDED_BY(Locks::jni_weak_globals_lock_); |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 266 | |
| Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 267 | // TODO Maybe move this to Runtime. |
| 268 | std::vector<GetEnvHook> env_hooks_; |
| 269 | |
| Andreas Gampe | 1b35b46 | 2017-09-29 18:52:15 -0700 | [diff] [blame] | 270 | size_t enable_allocation_tracking_delta_; |
| 271 | std::atomic<bool> allocation_tracking_enabled_; |
| 272 | std::atomic<bool> old_allocation_tracking_state_; |
| 273 | |
| Hans Boehm | 592bcea | 2021-07-02 22:20:52 -0700 | [diff] [blame] | 274 | // We report the number of global references after every kGlobalRefReportInterval changes. |
| 275 | static constexpr uint32_t kGlobalRefReportInterval = 17; |
| 276 | uint32_t weak_global_ref_report_counter_ GUARDED_BY(Locks::jni_weak_globals_lock_) |
| 277 | = kGlobalRefReportInterval; |
| 278 | uint32_t global_ref_report_counter_ GUARDED_BY(Locks::jni_globals_lock_) |
| 279 | = kGlobalRefReportInterval; |
| 280 | |
| 281 | |
| Vladimir Marko | 17491ac | 2020-12-01 12:02:29 +0000 | [diff] [blame] | 282 | friend IndirectReferenceTable* GetIndirectReferenceTable(ScopedObjectAccess& soa, |
| 283 | IndirectRefKind kind); |
| 284 | |
| Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 285 | DISALLOW_COPY_AND_ASSIGN(JavaVMExt); |
| 286 | }; |
| 287 | |
| 288 | } // namespace art |
| 289 | |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 290 | #endif // ART_RUNTIME_JNI_JAVA_VM_EXT_H_ |