summaryrefslogtreecommitdiff
path: root/runtime/java_vm_ext.cc
diff options
context:
space:
mode:
author Hiroshi Yamauchi <yamauchi@google.com> 2015-09-16 21:11:44 -0700
committer Hiroshi Yamauchi <yamauchi@google.com> 2015-09-17 11:34:14 -0700
commit498b160f0cb61ea4756d8ce859ae73c522366458 (patch)
treef582bfd38bc7e6fbbfd8fffc4a7f5449a962e7d5 /runtime/java_vm_ext.cc
parentfe9a1b05ea5a21b6d9a2e9e5081f5e80ff8a1ba2 (diff)
Allow null self only in DecodeWeakGlobalDuringShutdown().
To follow up CL 169855, allow a null current thread only in DecodeWeakGlobalDuringShutdown() as a special case rather than DecodeWeakGlobal(). This is to prevent a bug where null is accidentally passed to DecodeWeakGlobal(). Bug: 23897251 Change-Id: I5e7bb78ec739b8bfcf77284ed321d507737ee33e
Diffstat (limited to 'runtime/java_vm_ext.cc')
-rw-r--r--runtime/java_vm_ext.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc
index 63e8887ff3..531e03926a 100644
--- a/runtime/java_vm_ext.cc
+++ b/runtime/java_vm_ext.cc
@@ -580,12 +580,10 @@ inline bool JavaVMExt::MayAccessWeakGlobals(Thread* self) const {
}
inline bool JavaVMExt::MayAccessWeakGlobalsUnlocked(Thread* self) const {
- if (kUseReadBarrier) {
- // self can be null during a runtime shutdown. ~Runtime()->~ClassLinker()->DecodeWeakGlobal().
- return self != nullptr ? self->GetWeakRefAccessEnabled() : true;
- } else {
- return allow_accessing_weak_globals_.LoadSequentiallyConsistent();
- }
+ DCHECK(self != nullptr);
+ return kUseReadBarrier ?
+ self->GetWeakRefAccessEnabled() :
+ allow_accessing_weak_globals_.LoadSequentiallyConsistent();
}
mirror::Object* JavaVMExt::DecodeWeakGlobal(Thread* self, IndirectRef ref) {
@@ -613,6 +611,19 @@ mirror::Object* JavaVMExt::DecodeWeakGlobalLocked(Thread* self, IndirectRef ref)
return weak_globals_.Get(ref);
}
+mirror::Object* JavaVMExt::DecodeWeakGlobalDuringShutdown(Thread* self, IndirectRef ref) {
+ DCHECK_EQ(GetIndirectRefKind(ref), kWeakGlobal);
+ DCHECK(Runtime::Current()->IsShuttingDown(self));
+ if (self != nullptr) {
+ return DecodeWeakGlobal(self, ref);
+ }
+ // self can be null during a runtime shutdown. ~Runtime()->~ClassLinker()->DecodeWeakGlobal().
+ if (!kUseReadBarrier) {
+ DCHECK(allow_accessing_weak_globals_.LoadSequentiallyConsistent());
+ }
+ return weak_globals_.SynchronizedGet(ref);
+}
+
void JavaVMExt::UpdateWeakGlobal(Thread* self, IndirectRef ref, mirror::Object* result) {
MutexLock mu(self, weak_globals_lock_);
weak_globals_.Update(ref, result);