summaryrefslogtreecommitdiffstats
path: root/runtime/jobject_comparator.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-01-22 17:02:27 -0800
committerMathieu Chartier <mathieuc@google.com>2015-01-23 10:59:28 -0800
commit4c4d609a3f1d67c76c855df13c2c1be9c315a6c9 (patch)
tree938783861d07d62b22fb161d9c645247720012cf /runtime/jobject_comparator.cc
parenta5f74e15c14b8d2caa49a350ca6b5aa9183e2f7e (diff)
downloadart-4c4d609a3f1d67c76c855df13c2c1be9c315a6c9.zip
art-4c4d609a3f1d67c76c855df13c2c1be9c315a6c9.tar.gz
art-4c4d609a3f1d67c76c855df13c2c1be9c315a6c9.tar.bz2
Fix compaction bugs related to IdentityHashCode
IdentityHashCode is a suspend point if monitor inflation occurs. Change-Id: I114021aed8b3f3437109ef622298de05e13b4e34
Diffstat (limited to 'runtime/jobject_comparator.cc')
-rw-r--r--runtime/jobject_comparator.cc31
1 files changed, 15 insertions, 16 deletions
diff --git a/runtime/jobject_comparator.cc b/runtime/jobject_comparator.cc
index 77f93ff..1f424b3 100644
--- a/runtime/jobject_comparator.cc
+++ b/runtime/jobject_comparator.cc
@@ -25,33 +25,32 @@ namespace art {
bool JobjectComparator::operator()(jobject jobj1, jobject jobj2) const {
// Ensure null references and cleared jweaks appear at the end.
- if (jobj1 == NULL) {
+ if (jobj1 == nullptr) {
return true;
- } else if (jobj2 == NULL) {
+ } else if (jobj2 == nullptr) {
return false;
}
ScopedObjectAccess soa(Thread::Current());
- mirror::Object* obj1 = soa.Decode<mirror::Object*>(jobj1);
- mirror::Object* obj2 = soa.Decode<mirror::Object*>(jobj2);
- if (obj1 == NULL) {
+ StackHandleScope<2> hs(soa.Self());
+ Handle<mirror::Object> obj1(hs.NewHandle(soa.Decode<mirror::Object*>(jobj1)));
+ Handle<mirror::Object> obj2(hs.NewHandle(soa.Decode<mirror::Object*>(jobj2)));
+ if (obj1.Get() == nullptr) {
return true;
- } else if (obj2 == NULL) {
+ } else if (obj2.Get() == nullptr) {
return false;
}
// Sort by class...
if (obj1->GetClass() != obj2->GetClass()) {
return obj1->GetClass()->IdentityHashCode() < obj2->GetClass()->IdentityHashCode();
- } else {
- // ...then by size...
- size_t count1 = obj1->SizeOf();
- size_t count2 = obj2->SizeOf();
- if (count1 != count2) {
- return count1 < count2;
- } else {
- // ...and finally by identity hash code.
- return obj1->IdentityHashCode() < obj2->IdentityHashCode();
- }
}
+ // ...then by size...
+ const size_t count1 = obj1->SizeOf();
+ const size_t count2 = obj2->SizeOf();
+ if (count1 != count2) {
+ return count1 < count2;
+ }
+ // ...and finally by identity hash code.
+ return obj1->IdentityHashCode() < obj2->IdentityHashCode();
}
} // namespace art