Add more read barriers for JNI roots.
To make it possible to concurrently scan the JNI global roots (that
is, the roots visited by JavaVMExt::VisitRoots()), add read barriers
to the indirect reference table and the reference table.
Also, add read barriers to the jmethodID/jfieldID decode routines
(ScopedObjectAccessAlreadyRunnable::DecodeField/DecodeMethod) so that
we can concurrently handle (encoded) fields and methods.
Bug: 12687968
Change-Id: I3df4e4e622a572ff0ea8d44b2dc70a4d6b3ba058
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index fc5d590..17a5592 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -359,8 +359,9 @@
jni_on_load_result_(kPending) {
}
- mirror::Object* GetClassLoader() {
- return class_loader_;
+ mirror::Object* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ mirror::Object** root = &class_loader_;
+ return ReadBarrier::BarrierForRoot<mirror::Object, kWithReadBarrier>(root);
}
std::string GetPath() {
@@ -3160,9 +3161,7 @@
while (UNLIKELY(!allow_new_weak_globals_)) {
weak_globals_add_condition_.WaitHoldingLocks(self);
}
- // The weak globals do need a read barrier as they are weak roots.
- mirror::Object* obj = weak_globals_.Get<kWithReadBarrier>(ref);
- return obj;
+ return weak_globals_.Get(ref);
}
void JavaVMExt::DumpReferenceTables(std::ostream& os) {