Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [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 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "mark_sweep.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 18 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 19 | #include <climits> |
| 20 | #include <vector> |
| 21 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 22 | #include "card_table.h" |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 23 | #include "class_loader.h" |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 24 | #include "dex_cache.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 25 | #include "heap.h" |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 26 | #include "indirect_reference_table.h" |
| 27 | #include "intern_table.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 28 | #include "jni_internal.h" |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 29 | #include "large_object_space.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 30 | #include "logging.h" |
| 31 | #include "macros.h" |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 32 | #include "monitor.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 33 | #include "object.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 34 | #include "runtime.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 35 | #include "space.h" |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 36 | #include "timing_logger.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 37 | #include "thread.h" |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 38 | #include "thread_list.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 39 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 40 | static const bool kUseMarkStackPrefetch = true; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 41 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 42 | namespace art { |
| 43 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 44 | class SetFingerVisitor { |
| 45 | public: |
| 46 | SetFingerVisitor(MarkSweep* const mark_sweep) : mark_sweep_(mark_sweep) { |
| 47 | |
| 48 | } |
| 49 | |
| 50 | void operator ()(void* finger) const { |
| 51 | mark_sweep_->SetFinger(reinterpret_cast<Object*>(finger)); |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | MarkSweep* const mark_sweep_; |
| 56 | }; |
| 57 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 58 | MarkSweep::MarkSweep(ObjectStack* mark_stack) |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 59 | : current_mark_bitmap_(NULL), |
| 60 | mark_stack_(mark_stack), |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 61 | heap_(NULL), |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 62 | finger_(NULL), |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 63 | immune_begin_(NULL), |
| 64 | immune_end_(NULL), |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 65 | soft_reference_list_(NULL), |
| 66 | weak_reference_list_(NULL), |
| 67 | finalizer_reference_list_(NULL), |
| 68 | phantom_reference_list_(NULL), |
| 69 | cleared_reference_list_(NULL), |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 70 | freed_bytes_(0), freed_objects_(0), |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 71 | class_count_(0), array_count_(0), other_count_(0) { |
| 72 | DCHECK(mark_stack_ != NULL); |
| 73 | } |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 74 | |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 75 | void MarkSweep::Init() { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 76 | heap_ = Runtime::Current()->GetHeap(); |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 77 | mark_stack_->Reset(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 78 | // TODO: C++0x auto |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 79 | FindDefaultMarkBitmap(); |
buzbee | 0d966cf | 2011-09-08 17:34:58 -0700 | [diff] [blame] | 80 | // TODO: if concurrent, enable card marking in compiler |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 81 | // TODO: check that the mark bitmap is entirely clear. |
Mathieu Chartier | 9ebae1f | 2012-10-15 17:38:16 -0700 | [diff] [blame] | 82 | // Mark any concurrent roots as dirty since we need to scan them at least once during this GC. |
| 83 | Runtime::Current()->DirtyRoots(); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 86 | void MarkSweep::FindDefaultMarkBitmap() { |
| 87 | const Spaces& spaces = heap_->GetSpaces(); |
| 88 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 89 | if ((*it)->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect) { |
| 90 | current_mark_bitmap_ = (*it)->GetMarkBitmap(); |
| 91 | CHECK(current_mark_bitmap_ != NULL); |
| 92 | return; |
| 93 | } |
| 94 | } |
| 95 | GetHeap()->DumpSpaces(); |
| 96 | LOG(FATAL) << "Could not find a default mark bitmap"; |
| 97 | } |
| 98 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 99 | inline void MarkSweep::MarkObject0(const Object* obj, bool check_finger) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 100 | DCHECK(obj != NULL); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 101 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 102 | if (obj >= immune_begin_ && obj < immune_end_) { |
| 103 | DCHECK(IsMarked(obj)); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 104 | return; |
| 105 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 106 | |
| 107 | // Try to take advantage of locality of references within a space, failing this find the space |
| 108 | // the hard way. |
Ian Rogers | 506de0c | 2012-09-17 15:39:06 -0700 | [diff] [blame] | 109 | if (UNLIKELY(!current_mark_bitmap_->HasAddress(obj))) { |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 110 | SpaceBitmap* new_bitmap = heap_->GetMarkBitmap()->GetSpaceBitmap(obj); |
| 111 | if (new_bitmap != NULL) { |
| 112 | current_mark_bitmap_ = new_bitmap; |
| 113 | } else { |
| 114 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 115 | SpaceSetMap* large_objects = large_object_space->GetMarkObjects(); |
| 116 | if (!large_objects->Test(obj)) { |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 117 | if (!large_object_space->Contains(obj)) { |
| 118 | LOG(ERROR) << "Tried to mark " << obj << " not contained by any spaces"; |
| 119 | LOG(ERROR) << "Attempting see if it's a bad root"; |
| 120 | VerifyRoots(); |
| 121 | LOG(FATAL) << "Can't mark bad root"; |
| 122 | } |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 123 | large_objects->Set(obj); |
| 124 | // Don't need to check finger since large objects never have any object references. |
| 125 | } |
| 126 | // TODO: Improve clarity of control flow in this function? |
| 127 | return; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 128 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 131 | // This object was not previously marked. |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 132 | if (!current_mark_bitmap_->Test(obj)) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 133 | current_mark_bitmap_->Set(obj); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 134 | if (check_finger && obj < finger_) { |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 135 | // Do we need to expand the mark stack? |
| 136 | if (UNLIKELY(mark_stack_->Size() >= mark_stack_->Capacity())) { |
| 137 | std::vector<Object*> temp; |
| 138 | temp.insert(temp.begin(), mark_stack_->Begin(), mark_stack_->End()); |
| 139 | mark_stack_->Resize(mark_stack_->Capacity() * 2); |
| 140 | for (size_t i = 0; i < temp.size(); ++i) { |
| 141 | mark_stack_->PushBack(temp[i]); |
| 142 | } |
| 143 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 144 | // The object must be pushed on to the mark stack. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 145 | mark_stack_->PushBack(const_cast<Object*>(obj)); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Used to mark objects when recursing. Recursion is done by moving |
| 151 | // the finger across the bitmaps in address order and marking child |
| 152 | // objects. Any newly-marked objects whose addresses are lower than |
| 153 | // the finger won't be visited by the bitmap scan, so those objects |
| 154 | // need to be added to the mark stack. |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 155 | void MarkSweep::MarkObject(const Object* obj) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 156 | if (obj != NULL) { |
| 157 | MarkObject0(obj, true); |
| 158 | } |
| 159 | } |
| 160 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 161 | void MarkSweep::MarkObjectVisitor(const Object* root, void* arg) { |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 162 | DCHECK(root != NULL); |
| 163 | DCHECK(arg != NULL); |
| 164 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 165 | mark_sweep->MarkObject0(root, false); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 168 | void MarkSweep::ReMarkObjectVisitor(const Object* root, void* arg) { |
| 169 | DCHECK(root != NULL); |
| 170 | DCHECK(arg != NULL); |
| 171 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
| 172 | mark_sweep->MarkObject0(root, true); |
| 173 | } |
| 174 | |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 175 | void MarkSweep::VerifyRootCallback(const Object* root, void* arg, size_t vreg, |
| 176 | const AbstractMethod* method) { |
| 177 | reinterpret_cast<MarkSweep*>(arg)->VerifyRoot(root, vreg, method); |
| 178 | } |
| 179 | |
| 180 | void MarkSweep::VerifyRoot(const Object* root, size_t vreg, const AbstractMethod* method) { |
| 181 | // See if the root is on any space bitmap. |
Mathieu Chartier | 128c52c | 2012-10-16 14:12:41 -0700 | [diff] [blame^] | 182 | if (GetHeap()->GetLiveBitmap()->GetSpaceBitmap(root) == NULL) { |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 183 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 184 | if (large_object_space->Contains(root)) { |
| 185 | LOG(ERROR) << "Found invalid root: " << root; |
| 186 | LOG(ERROR) << "VReg / Shadow frame offset: " << vreg; |
| 187 | if (method != NULL) { |
| 188 | LOG(ERROR) << "In method " << PrettyMethod(method, true); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void MarkSweep::VerifyRoots() { |
| 195 | Runtime::Current()->GetThreadList()->VerifyRoots(VerifyRootCallback, this); |
| 196 | } |
| 197 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 198 | // Marks all objects in the root set. |
| 199 | void MarkSweep::MarkRoots() { |
Mathieu Chartier | 9ebae1f | 2012-10-15 17:38:16 -0700 | [diff] [blame] | 200 | Runtime::Current()->VisitNonConcurrentRoots(MarkObjectVisitor, this); |
| 201 | } |
| 202 | |
| 203 | void MarkSweep::MarkConcurrentRoots() { |
| 204 | Runtime::Current()->VisitConcurrentRoots(MarkObjectVisitor, this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 207 | class CheckObjectVisitor { |
| 208 | public: |
| 209 | CheckObjectVisitor(MarkSweep* const mark_sweep) |
| 210 | : mark_sweep_(mark_sweep) { |
| 211 | |
| 212 | } |
| 213 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 214 | void operator ()(const Object* obj, const Object* ref, MemberOffset offset, bool is_static) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 215 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, |
| 216 | Locks::mutator_lock_) { |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 217 | mark_sweep_->CheckReference(obj, ref, offset, is_static); |
| 218 | } |
| 219 | |
| 220 | private: |
| 221 | MarkSweep* const mark_sweep_; |
| 222 | }; |
| 223 | |
| 224 | void MarkSweep::CheckObject(const Object* obj) { |
| 225 | DCHECK(obj != NULL); |
| 226 | CheckObjectVisitor visitor(this); |
| 227 | VisitObjectReferences(obj, visitor); |
| 228 | } |
| 229 | |
| 230 | void MarkSweep::VerifyImageRootVisitor(Object* root, void* arg) { |
| 231 | DCHECK(root != NULL); |
| 232 | DCHECK(arg != NULL); |
| 233 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 234 | DCHECK(mark_sweep->heap_->GetMarkBitmap()->Test(root)); |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 235 | mark_sweep->CheckObject(root); |
| 236 | } |
| 237 | |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 238 | void MarkSweep::CopyMarkBits(ContinuousSpace* space) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 239 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 240 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
| 241 | mark_bitmap->CopyFrom(live_bitmap); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 244 | void MarkSweep::BindLiveToMarkBitmap(ContinuousSpace* space) { |
| 245 | CHECK(space->IsAllocSpace()); |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 246 | DlMallocSpace* alloc_space = space->AsAllocSpace(); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 247 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 248 | SpaceBitmap* mark_bitmap = alloc_space->mark_bitmap_.release(); |
| 249 | GetHeap()->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap); |
| 250 | alloc_space->temp_bitmap_.reset(mark_bitmap); |
| 251 | alloc_space->mark_bitmap_.reset(live_bitmap); |
| 252 | } |
| 253 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 254 | class ScanImageRootVisitor { |
| 255 | public: |
| 256 | ScanImageRootVisitor(MarkSweep* const mark_sweep) : mark_sweep_(mark_sweep) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 259 | void operator ()(const Object* root) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 260 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 261 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 262 | DCHECK(root != NULL); |
| 263 | mark_sweep_->ScanObject(root); |
| 264 | } |
| 265 | |
| 266 | private: |
| 267 | MarkSweep* const mark_sweep_; |
| 268 | }; |
| 269 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 270 | void MarkSweep::ScanGrayObjects(bool update_finger) { |
| 271 | const Spaces& spaces = heap_->GetSpaces(); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 272 | CardTable* card_table = heap_->GetCardTable(); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 273 | ScanImageRootVisitor image_root_visitor(this); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 274 | SetFingerVisitor finger_visitor(this); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 275 | // TODO: C++ 0x auto |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 276 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 277 | ContinuousSpace* space = *it; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 278 | byte* begin = space->Begin(); |
| 279 | byte* end = space->End(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 280 | // Image spaces are handled properly since live == marked for them. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 281 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
| 282 | if (update_finger) { |
| 283 | card_table->Scan(mark_bitmap, begin, end, image_root_visitor, finger_visitor); |
| 284 | } else { |
| 285 | card_table->Scan(mark_bitmap, begin, end, image_root_visitor, IdentityFunctor()); |
| 286 | } |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 290 | class CheckBitmapVisitor { |
| 291 | public: |
| 292 | CheckBitmapVisitor(MarkSweep* mark_sweep) : mark_sweep_(mark_sweep) { |
| 293 | |
| 294 | } |
| 295 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 296 | void operator ()(const Object* obj) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 297 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, |
| 298 | Locks::mutator_lock_) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 299 | DCHECK(obj != NULL); |
| 300 | mark_sweep_->CheckObject(obj); |
| 301 | } |
| 302 | |
| 303 | private: |
| 304 | MarkSweep* mark_sweep_; |
| 305 | }; |
| 306 | |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 307 | void MarkSweep::VerifyImageRoots() { |
| 308 | // Verify roots ensures that all the references inside the image space point |
| 309 | // objects which are either in the image space or marked objects in the alloc |
| 310 | // space |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 311 | CheckBitmapVisitor visitor(this); |
| 312 | const Spaces& spaces = heap_->GetSpaces(); |
| 313 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 314 | if ((*it)->IsImageSpace()) { |
| 315 | ImageSpace* space = (*it)->AsImageSpace(); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 316 | uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin()); |
| 317 | uintptr_t end = reinterpret_cast<uintptr_t>(space->End()); |
| 318 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 319 | DCHECK(live_bitmap != NULL); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 320 | live_bitmap->VisitMarkedRange(begin, end, visitor, IdentityFunctor()); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 325 | class ScanObjectVisitor { |
| 326 | public: |
| 327 | ScanObjectVisitor(MarkSweep* const mark_sweep) : mark_sweep_(mark_sweep) { |
| 328 | |
| 329 | } |
| 330 | |
| 331 | void operator ()(const Object* obj) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 332 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 333 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 334 | mark_sweep_->ScanObject(obj); |
| 335 | } |
| 336 | |
| 337 | private: |
| 338 | MarkSweep* const mark_sweep_; |
| 339 | }; |
| 340 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 341 | // Populates the mark stack based on the set of marked objects and |
| 342 | // recursively marks until the mark stack is emptied. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 343 | void MarkSweep::RecursiveMark(bool partial, TimingLogger& timings) { |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 344 | // RecursiveMark will build the lists of known instances of the Reference classes. |
| 345 | // See DelayReferenceReferent for details. |
| 346 | CHECK(soft_reference_list_ == NULL); |
| 347 | CHECK(weak_reference_list_ == NULL); |
| 348 | CHECK(finalizer_reference_list_ == NULL); |
| 349 | CHECK(phantom_reference_list_ == NULL); |
| 350 | CHECK(cleared_reference_list_ == NULL); |
| 351 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 352 | const Spaces& spaces = heap_->GetSpaces(); |
| 353 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 354 | SetFingerVisitor set_finger_visitor(this); |
| 355 | ScanObjectVisitor scan_visitor(this); |
| 356 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 357 | ContinuousSpace* space = *it; |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 358 | if (space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect || |
| 359 | (!partial && space->GetGcRetentionPolicy() == kGcRetentionPolicyFullCollect) |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 360 | ) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 361 | current_mark_bitmap_ = space->GetMarkBitmap(); |
| 362 | if (current_mark_bitmap_ == NULL) { |
| 363 | GetHeap()->DumpSpaces(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 364 | LOG(FATAL) << "invalid bitmap"; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 365 | } |
| 366 | // This function does not handle heap end increasing, so we must use the space end. |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 367 | uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin()); |
| 368 | uintptr_t end = reinterpret_cast<uintptr_t>(space->End()); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 369 | current_mark_bitmap_->VisitMarkedRange(begin, end, scan_visitor, set_finger_visitor); |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 370 | } |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 371 | } |
| 372 | finger_ = reinterpret_cast<Object*>(~0); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 373 | timings.AddSplit("RecursiveMark"); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 374 | // TODO: tune the frequency of emptying the mark stack |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 375 | ProcessMarkStack(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 376 | timings.AddSplit("ProcessMarkStack"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 379 | void MarkSweep::RecursiveMarkCards(CardTable* card_table, const std::vector<byte*>& cards, |
| 380 | TimingLogger& timings) { |
| 381 | ScanImageRootVisitor image_root_visitor(this); |
| 382 | SetFingerVisitor finger_visitor(this); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 383 | const size_t card_count = cards.size(); |
| 384 | SpaceBitmap* active_bitmap = NULL; |
| 385 | for (size_t i = 0;i < card_count;) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 386 | Object* start_obj = reinterpret_cast<Object*>(card_table->AddrFromCard(cards[i])); |
| 387 | uintptr_t begin = reinterpret_cast<uintptr_t>(start_obj); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 388 | uintptr_t end = begin + CardTable::kCardSize; |
| 389 | for (++i; reinterpret_cast<uintptr_t>(cards[i]) == end && i < card_count; ++i) { |
| 390 | end += CardTable::kCardSize; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 391 | } |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 392 | if (active_bitmap == NULL || !active_bitmap->HasAddress(start_obj)) { |
| 393 | active_bitmap = heap_->GetMarkBitmap()->GetSpaceBitmap(start_obj); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 394 | #ifndef NDEBUG |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 395 | if (active_bitmap == NULL) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 396 | GetHeap()->DumpSpaces(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 397 | LOG(FATAL) << "Object " << reinterpret_cast<const void*>(start_obj); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 398 | } |
| 399 | #endif |
| 400 | } |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 401 | active_bitmap->VisitMarkedRange(begin, end, image_root_visitor, finger_visitor); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 402 | } |
| 403 | timings.AddSplit("RecursiveMarkCards"); |
| 404 | ProcessMarkStack(); |
| 405 | timings.AddSplit("ProcessMarkStack"); |
| 406 | } |
| 407 | |
| 408 | bool MarkSweep::IsMarkedCallback(const Object* object, void* arg) { |
| 409 | return |
| 410 | reinterpret_cast<MarkSweep*>(arg)->IsMarked(object) || |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 411 | !reinterpret_cast<MarkSweep*>(arg)->GetHeap()->GetLiveBitmap()->Test(object); |
| 412 | } |
| 413 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 414 | void MarkSweep::RecursiveMarkDirtyObjects(bool update_finger) { |
| 415 | ScanGrayObjects(update_finger); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 416 | ProcessMarkStack(); |
| 417 | } |
| 418 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 419 | void MarkSweep::ReMarkRoots() { |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 420 | Runtime::Current()->VisitRoots(ReMarkObjectVisitor, this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 423 | void MarkSweep::SweepJniWeakGlobals(Heap::IsMarkedTester is_marked, void* arg) { |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 424 | JavaVMExt* vm = Runtime::Current()->GetJavaVM(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 425 | MutexLock mu(Thread::Current(), vm->weak_globals_lock); |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 426 | IndirectReferenceTable* table = &vm->weak_globals; |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 427 | typedef IndirectReferenceTable::iterator It; // TODO: C++0x auto |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 428 | for (It it = table->begin(), end = table->end(); it != end; ++it) { |
| 429 | const Object** entry = *it; |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 430 | if (!is_marked(*entry, arg)) { |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 431 | *entry = kClearedJniWeakGlobal; |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 436 | struct ArrayMarkedCheck { |
| 437 | ObjectStack* live_stack; |
| 438 | MarkSweep* mark_sweep; |
| 439 | }; |
| 440 | |
| 441 | // Either marked or not live. |
| 442 | bool MarkSweep::IsMarkedArrayCallback(const Object* object, void* arg) { |
| 443 | ArrayMarkedCheck* array_check = reinterpret_cast<ArrayMarkedCheck*>(arg); |
| 444 | if (array_check->mark_sweep->IsMarked(object)) { |
| 445 | return true; |
| 446 | } |
| 447 | ObjectStack* live_stack = array_check->live_stack; |
| 448 | return std::find(live_stack->Begin(), live_stack->End(), object) == live_stack->End(); |
| 449 | } |
| 450 | |
| 451 | void MarkSweep::SweepSystemWeaksArray(ObjectStack* allocations) { |
Mathieu Chartier | 46a2363 | 2012-08-07 18:44:40 -0700 | [diff] [blame] | 452 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 453 | // The callbacks check |
| 454 | // !is_marked where is_marked is the callback but we want |
| 455 | // !IsMarked && IsLive |
| 456 | // So compute !(!IsMarked && IsLive) which is equal to (IsMarked || !IsLive). |
| 457 | // Or for swapped (IsLive || !IsMarked). |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 458 | |
| 459 | ArrayMarkedCheck visitor; |
| 460 | visitor.live_stack = allocations; |
| 461 | visitor.mark_sweep = this; |
| 462 | runtime->GetInternTable()->SweepInternTableWeaks(IsMarkedArrayCallback, &visitor); |
| 463 | runtime->GetMonitorList()->SweepMonitorList(IsMarkedArrayCallback, &visitor); |
| 464 | SweepJniWeakGlobals(IsMarkedArrayCallback, &visitor); |
| 465 | } |
| 466 | |
| 467 | void MarkSweep::SweepSystemWeaks() { |
| 468 | Runtime* runtime = Runtime::Current(); |
| 469 | // The callbacks check |
| 470 | // !is_marked where is_marked is the callback but we want |
| 471 | // !IsMarked && IsLive |
| 472 | // So compute !(!IsMarked && IsLive) which is equal to (IsMarked || !IsLive). |
| 473 | // Or for swapped (IsLive || !IsMarked). |
| 474 | runtime->GetInternTable()->SweepInternTableWeaks(IsMarkedCallback, this); |
| 475 | runtime->GetMonitorList()->SweepMonitorList(IsMarkedCallback, this); |
| 476 | SweepJniWeakGlobals(IsMarkedCallback, this); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 479 | bool MarkSweep::VerifyIsLiveCallback(const Object* obj, void* arg) { |
| 480 | reinterpret_cast<MarkSweep*>(arg)->VerifyIsLive(obj); |
| 481 | // We don't actually want to sweep the object, so lets return "marked" |
| 482 | return true; |
| 483 | } |
| 484 | |
| 485 | void MarkSweep::VerifyIsLive(const Object* obj) { |
| 486 | Heap* heap = GetHeap(); |
| 487 | if (!heap->GetLiveBitmap()->Test(obj)) { |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 488 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 489 | if (!large_object_space->GetLiveObjects()->Test(obj)) { |
| 490 | if (std::find(heap->allocation_stack_->Begin(), heap->allocation_stack_->End(), obj) == |
| 491 | heap->allocation_stack_->End()) { |
| 492 | // Object not found! |
| 493 | heap->DumpSpaces(); |
| 494 | LOG(FATAL) << "Found dead object " << obj; |
| 495 | } |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | void MarkSweep::VerifySystemWeaks() { |
| 501 | Runtime* runtime = Runtime::Current(); |
| 502 | // Verify system weaks, uses a special IsMarked callback which always returns true. |
| 503 | runtime->GetInternTable()->SweepInternTableWeaks(VerifyIsLiveCallback, this); |
| 504 | runtime->GetMonitorList()->SweepMonitorList(VerifyIsLiveCallback, this); |
| 505 | |
| 506 | JavaVMExt* vm = runtime->GetJavaVM(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 507 | MutexLock mu(Thread::Current(), vm->weak_globals_lock); |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 508 | IndirectReferenceTable* table = &vm->weak_globals; |
| 509 | typedef IndirectReferenceTable::iterator It; // TODO: C++0x auto |
| 510 | for (It it = table->begin(), end = table->end(); it != end; ++it) { |
| 511 | const Object** entry = *it; |
| 512 | VerifyIsLive(*entry); |
| 513 | } |
| 514 | } |
| 515 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 516 | struct SweepCallbackContext { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 517 | MarkSweep* mark_sweep; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 518 | AllocSpace* space; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 519 | Thread* self; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 520 | }; |
| 521 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 522 | void MarkSweep::SweepCallback(size_t num_ptrs, Object** ptrs, void* arg) { |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 523 | size_t freed_objects = num_ptrs; |
| 524 | size_t freed_bytes = 0; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 525 | SweepCallbackContext* context = static_cast<SweepCallbackContext*>(arg); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 526 | MarkSweep* mark_sweep = context->mark_sweep; |
| 527 | Heap* heap = mark_sweep->GetHeap(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 528 | AllocSpace* space = context->space; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 529 | Thread* self = context->self; |
| 530 | Locks::heap_bitmap_lock_->AssertExclusiveHeld(self); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 531 | // Use a bulk free, that merges consecutive objects before freeing or free per object? |
| 532 | // Documentation suggests better free performance with merging, but this may be at the expensive |
| 533 | // of allocation. |
| 534 | // TODO: investigate performance |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 535 | static const bool kUseFreeList = true; |
| 536 | if (kUseFreeList) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 537 | // AllocSpace::FreeList clears the value in ptrs, so perform after clearing the live bit |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 538 | freed_bytes += space->FreeList(self, num_ptrs, ptrs); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 539 | } else { |
| 540 | for (size_t i = 0; i < num_ptrs; ++i) { |
| 541 | Object* obj = static_cast<Object*>(ptrs[i]); |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 542 | freed_bytes += space->Free(self, obj); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 543 | } |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 544 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 545 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 546 | heap->RecordFree(freed_objects, freed_bytes); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 547 | mark_sweep->freed_objects_ += freed_objects; |
| 548 | mark_sweep->freed_bytes_ += freed_bytes; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 551 | void MarkSweep::ZygoteSweepCallback(size_t num_ptrs, Object** ptrs, void* arg) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 552 | SweepCallbackContext* context = static_cast<SweepCallbackContext*>(arg); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 553 | Locks::heap_bitmap_lock_->AssertExclusiveHeld(context->self); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 554 | Heap* heap = context->mark_sweep->GetHeap(); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 555 | // We don't free any actual memory to avoid dirtying the shared zygote pages. |
| 556 | for (size_t i = 0; i < num_ptrs; ++i) { |
| 557 | Object* obj = static_cast<Object*>(ptrs[i]); |
| 558 | heap->GetLiveBitmap()->Clear(obj); |
| 559 | heap->GetCardTable()->MarkCard(obj); |
| 560 | } |
| 561 | } |
| 562 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 563 | void MarkSweep::SweepArray(TimingLogger& logger, ObjectStack* allocations, bool swap_bitmaps) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 564 | size_t freed_bytes = 0; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 565 | DlMallocSpace* space = heap_->GetAllocSpace(); |
Elliott Hughes | 2da5036 | 2011-10-10 16:57:08 -0700 | [diff] [blame] | 566 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 567 | // If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark |
| 568 | // bitmap, resulting in occasional frees of Weaks which are still in use. |
| 569 | // TODO: Fix when sweeping weaks works properly with mutators unpaused + allocation list. |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 570 | SweepSystemWeaksArray(allocations); |
| 571 | logger.AddSplit("SweepSystemWeaks"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 572 | |
| 573 | // Newly allocated objects MUST be in the alloc space and those are the only objects which we are |
| 574 | // going to free. |
| 575 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 576 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 577 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 578 | SpaceSetMap* large_live_objects = large_object_space->GetLiveObjects(); |
| 579 | SpaceSetMap* large_mark_objects = large_object_space->GetMarkObjects(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 580 | if (swap_bitmaps) { |
| 581 | std::swap(live_bitmap, mark_bitmap); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 582 | std::swap(large_live_objects, large_mark_objects); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 585 | size_t freed_large_objects = 0; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 586 | size_t count = allocations->Size(); |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 587 | Object** objects = const_cast<Object**>(allocations->Begin()); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 588 | Object** out = objects; |
| 589 | |
| 590 | // Empty the allocation stack. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 591 | Thread* self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 592 | for (size_t i = 0;i < count;++i) { |
| 593 | Object* obj = objects[i]; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 594 | // There should only be objects in the AllocSpace/LargeObjectSpace in the allocation stack. |
| 595 | if (LIKELY(mark_bitmap->HasAddress(obj))) { |
| 596 | if (!mark_bitmap->Test(obj)) { |
| 597 | // Don't bother un-marking since we clear the mark bitmap anyways. |
| 598 | *(out++) = obj; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 599 | } |
| 600 | } else if (!large_mark_objects->Test(obj)) { |
| 601 | ++freed_large_objects; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 602 | freed_bytes += large_object_space->Free(self, obj); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | logger.AddSplit("Process allocation stack"); |
| 606 | |
| 607 | size_t freed_objects = out - objects; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 608 | freed_bytes += space->FreeList(self, freed_objects, objects); |
Mathieu Chartier | 40e978b | 2012-09-07 11:38:36 -0700 | [diff] [blame] | 609 | VLOG(heap) << "Freed " << freed_objects << "/" << count |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 610 | << " objects with size " << PrettySize(freed_bytes); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 611 | heap_->RecordFree(freed_objects + freed_large_objects, freed_bytes); |
Mathieu Chartier | 40e978b | 2012-09-07 11:38:36 -0700 | [diff] [blame] | 612 | freed_objects_ += freed_objects; |
| 613 | freed_bytes_ += freed_bytes; |
| 614 | logger.AddSplit("FreeList"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 615 | allocations->Reset(); |
| 616 | logger.AddSplit("Reset stack"); |
| 617 | } |
| 618 | |
| 619 | void MarkSweep::Sweep(bool partial, bool swap_bitmaps) { |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 620 | DCHECK(mark_stack_->IsEmpty()); |
| 621 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 622 | // If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark |
| 623 | // bitmap, resulting in occasional frees of Weaks which are still in use. |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 624 | SweepSystemWeaks(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 625 | |
Mathieu Chartier | 46a2363 | 2012-08-07 18:44:40 -0700 | [diff] [blame] | 626 | const Spaces& spaces = heap_->GetSpaces(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 627 | SweepCallbackContext scc; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 628 | scc.mark_sweep = this; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 629 | scc.self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 630 | // TODO: C++0x auto |
| 631 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 632 | ContinuousSpace* space = *it; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 633 | if ( |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 634 | space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect || |
| 635 | (!partial && space->GetGcRetentionPolicy() == kGcRetentionPolicyFullCollect) |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 636 | ) { |
| 637 | uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin()); |
| 638 | uintptr_t end = reinterpret_cast<uintptr_t>(space->End()); |
| 639 | scc.space = space->AsAllocSpace(); |
| 640 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 641 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 642 | if (swap_bitmaps) { |
| 643 | std::swap(live_bitmap, mark_bitmap); |
| 644 | } |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 645 | if (space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 646 | // Bitmaps are pre-swapped for optimization which enables sweeping with the heap unlocked. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 647 | SpaceBitmap::SweepWalk(*live_bitmap, *mark_bitmap, begin, end, |
| 648 | &SweepCallback, reinterpret_cast<void*>(&scc)); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 649 | } else { |
| 650 | // Zygote sweep takes care of dirtying cards and clearing live bits, does not free actual memory. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 651 | SpaceBitmap::SweepWalk(*live_bitmap, *mark_bitmap, begin, end, |
| 652 | &ZygoteSweepCallback, reinterpret_cast<void*>(&scc)); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 653 | } |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 658 | void MarkSweep::SweepLargeObjects(bool swap_bitmaps) { |
| 659 | // Sweep large objects |
| 660 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 661 | SpaceSetMap* large_live_objects = large_object_space->GetLiveObjects(); |
| 662 | SpaceSetMap* large_mark_objects = large_object_space->GetMarkObjects(); |
| 663 | if (swap_bitmaps) { |
| 664 | std::swap(large_live_objects, large_mark_objects); |
| 665 | } |
| 666 | SpaceSetMap::Objects& live_objects = large_live_objects->GetObjects(); |
| 667 | // O(n*log(n)) but hopefully there are not too many large objects. |
| 668 | size_t freed_objects = 0; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 669 | size_t freed_bytes = 0; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 670 | // TODO: C++0x |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 671 | Thread* self = Thread::Current(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 672 | for (SpaceSetMap::Objects::iterator it = live_objects.begin(); it != live_objects.end(); ++it) { |
| 673 | if (!large_mark_objects->Test(*it)) { |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 674 | freed_bytes += large_object_space->Free(self, const_cast<Object*>(*it)); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 675 | ++freed_objects; |
| 676 | } |
| 677 | } |
| 678 | freed_objects_ += freed_objects; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 679 | freed_bytes_ += freed_bytes; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 680 | // Large objects don't count towards bytes_allocated. |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 681 | GetHeap()->RecordFree(freed_objects, freed_bytes); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 684 | // Scans instance fields. |
Elliott Hughes | b066311 | 2011-10-19 18:16:37 -0700 | [diff] [blame] | 685 | inline void MarkSweep::ScanInstanceFields(const Object* obj) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 686 | DCHECK(obj != NULL); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 687 | Class* klass = obj->GetClass(); |
| 688 | DCHECK(klass != NULL); |
Elliott Hughes | 2da5036 | 2011-10-10 16:57:08 -0700 | [diff] [blame] | 689 | ScanFields(obj, klass->GetReferenceInstanceOffsets(), false); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | // Scans static storage on a Class. |
Elliott Hughes | b066311 | 2011-10-19 18:16:37 -0700 | [diff] [blame] | 693 | inline void MarkSweep::ScanStaticFields(const Class* klass) { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 694 | DCHECK(klass != NULL); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 695 | ScanFields(klass, klass->GetReferenceStaticOffsets(), true); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Elliott Hughes | b066311 | 2011-10-19 18:16:37 -0700 | [diff] [blame] | 698 | inline void MarkSweep::ScanFields(const Object* obj, uint32_t ref_offsets, bool is_static) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 699 | if (ref_offsets != CLASS_WALK_SUPER) { |
| 700 | // Found a reference offset bitmap. Mark the specified offsets. |
| 701 | while (ref_offsets != 0) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 702 | const size_t right_shift = CLZ(ref_offsets); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 703 | MemberOffset byte_offset = CLASS_OFFSET_FROM_CLZ(right_shift); |
| 704 | const Object* ref = obj->GetFieldObject<const Object*>(byte_offset, false); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 705 | MarkObject(ref); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 706 | ref_offsets ^= CLASS_HIGH_BIT >> right_shift; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 707 | } |
| 708 | } else { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 709 | // There is no reference offset bitmap. In the non-static case, |
| 710 | // walk up the class inheritance hierarchy and find reference |
| 711 | // offsets the hard way. In the static case, just consider this |
| 712 | // class. |
| 713 | for (const Class* klass = is_static ? obj->AsClass() : obj->GetClass(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 714 | klass != NULL; |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 715 | klass = is_static ? NULL : klass->GetSuperClass()) { |
| 716 | size_t num_reference_fields = (is_static |
| 717 | ? klass->NumReferenceStaticFields() |
| 718 | : klass->NumReferenceInstanceFields()); |
| 719 | for (size_t i = 0; i < num_reference_fields; ++i) { |
| 720 | Field* field = (is_static |
| 721 | ? klass->GetStaticField(i) |
| 722 | : klass->GetInstanceField(i)); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 723 | MemberOffset field_offset = field->GetOffset(); |
| 724 | const Object* ref = obj->GetFieldObject<const Object*>(field_offset, false); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 725 | MarkObject(ref); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 731 | void MarkSweep::CheckReference(const Object* obj, const Object* ref, MemberOffset offset, bool is_static) { |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 732 | const Spaces& spaces = heap_->GetSpaces(); |
| 733 | // TODO: C++0x auto |
| 734 | for (Spaces::const_iterator cur = spaces.begin(); cur != spaces.end(); ++cur) { |
| 735 | if ((*cur)->IsAllocSpace() && (*cur)->Contains(ref)) { |
| 736 | DCHECK(IsMarked(obj)); |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 737 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 738 | bool is_marked = IsMarked(ref); |
| 739 | if (!is_marked) { |
| 740 | LOG(INFO) << **cur; |
| 741 | LOG(WARNING) << (is_static ? "Static ref'" : "Instance ref'") << PrettyTypeOf(ref) |
| 742 | << "' (" << reinterpret_cast<const void*>(ref) << ") in '" << PrettyTypeOf(obj) |
| 743 | << "' (" << reinterpret_cast<const void*>(obj) << ") at offset " |
| 744 | << reinterpret_cast<void*>(offset.Int32Value()) << " wasn't marked"; |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 745 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 746 | const Class* klass = is_static ? obj->AsClass() : obj->GetClass(); |
| 747 | DCHECK(klass != NULL); |
| 748 | const ObjectArray<Field>* fields = is_static ? klass->GetSFields() : klass->GetIFields(); |
| 749 | DCHECK(fields != NULL); |
| 750 | bool found = false; |
| 751 | for (int32_t i = 0; i < fields->GetLength(); ++i) { |
| 752 | const Field* cur = fields->Get(i); |
| 753 | if (cur->GetOffset().Int32Value() == offset.Int32Value()) { |
| 754 | LOG(WARNING) << "Field referencing the alloc space was " << PrettyField(cur); |
| 755 | found = true; |
| 756 | break; |
| 757 | } |
| 758 | } |
| 759 | if (!found) { |
| 760 | LOG(WARNING) << "Could not find field in object alloc space with offset " << offset.Int32Value(); |
| 761 | } |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 762 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 763 | bool obj_marked = heap_->GetCardTable()->IsDirty(obj); |
| 764 | if (!obj_marked) { |
| 765 | LOG(WARNING) << "Object '" << PrettyTypeOf(obj) << "' " |
| 766 | << "(" << reinterpret_cast<const void*>(obj) << ") contains references to " |
| 767 | << "the alloc space, but wasn't card marked"; |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 768 | } |
| 769 | } |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 770 | } |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 771 | break; |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 775 | // Scans the header, static field references, and interface pointers |
| 776 | // of a class object. |
Elliott Hughes | b066311 | 2011-10-19 18:16:37 -0700 | [diff] [blame] | 777 | inline void MarkSweep::ScanClass(const Object* obj) { |
Elliott Hughes | 352a424 | 2011-10-31 15:15:21 -0700 | [diff] [blame] | 778 | #ifndef NDEBUG |
| 779 | ++class_count_; |
| 780 | #endif |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 781 | ScanInstanceFields(obj); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 782 | ScanStaticFields(obj->AsClass()); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // Scans the header of all array objects. If the array object is |
| 786 | // specialized to a reference type, scans the array data as well. |
Elliott Hughes | b066311 | 2011-10-19 18:16:37 -0700 | [diff] [blame] | 787 | inline void MarkSweep::ScanArray(const Object* obj) { |
Elliott Hughes | 352a424 | 2011-10-31 15:15:21 -0700 | [diff] [blame] | 788 | #ifndef NDEBUG |
| 789 | ++array_count_; |
| 790 | #endif |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 791 | MarkObject(obj->GetClass()); |
| 792 | if (obj->IsObjectArray()) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 793 | const ObjectArray<Object>* array = obj->AsObjectArray<Object>(); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 794 | for (int32_t i = 0; i < array->GetLength(); ++i) { |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 795 | const Object* element = array->GetWithoutChecks(i); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 796 | MarkObject(element); |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 801 | // Process the "referent" field in a java.lang.ref.Reference. If the |
| 802 | // referent has not yet been marked, put it on the appropriate list in |
| 803 | // the gcHeap for later processing. |
| 804 | void MarkSweep::DelayReferenceReferent(Object* obj) { |
| 805 | DCHECK(obj != NULL); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 806 | Class* klass = obj->GetClass(); |
| 807 | DCHECK(klass != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 808 | DCHECK(klass->IsReferenceClass()); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 809 | Object* pending = obj->GetFieldObject<Object*>(heap_->GetReferencePendingNextOffset(), false); |
| 810 | Object* referent = heap_->GetReferenceReferent(obj); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 811 | if (pending == NULL && referent != NULL && !IsMarked(referent)) { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 812 | Object** list = NULL; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 813 | if (klass->IsSoftReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 814 | list = &soft_reference_list_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 815 | } else if (klass->IsWeakReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 816 | list = &weak_reference_list_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 817 | } else if (klass->IsFinalizerReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 818 | list = &finalizer_reference_list_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 819 | } else if (klass->IsPhantomReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 820 | list = &phantom_reference_list_; |
| 821 | } |
Brian Carlstrom | 0796af0 | 2011-10-12 14:31:45 -0700 | [diff] [blame] | 822 | DCHECK(list != NULL) << PrettyClass(klass) << " " << std::hex << klass->GetAccessFlags(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 823 | heap_->EnqueuePendingReference(obj, list); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
| 827 | // Scans the header and field references of a data object. If the |
| 828 | // scanned object is a reference subclass, it is scheduled for later |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 829 | // processing. |
Elliott Hughes | b066311 | 2011-10-19 18:16:37 -0700 | [diff] [blame] | 830 | inline void MarkSweep::ScanOther(const Object* obj) { |
Elliott Hughes | 352a424 | 2011-10-31 15:15:21 -0700 | [diff] [blame] | 831 | #ifndef NDEBUG |
| 832 | ++other_count_; |
| 833 | #endif |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 834 | ScanInstanceFields(obj); |
Elliott Hughes | 352a424 | 2011-10-31 15:15:21 -0700 | [diff] [blame] | 835 | if (obj->GetClass()->IsReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 836 | DelayReferenceReferent(const_cast<Object*>(obj)); |
| 837 | } |
| 838 | } |
| 839 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 840 | void MarkSweep::ScanRoot(const Object* obj) { |
| 841 | ScanObject(obj); |
| 842 | } |
| 843 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 844 | // Scans an object reference. Determines the type of the reference |
| 845 | // and dispatches to a specialized scanning routine. |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 846 | void MarkSweep::ScanObject(const Object* obj) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 847 | DCHECK(obj != NULL); |
| 848 | DCHECK(obj->GetClass() != NULL); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 849 | #ifndef NDEBUG |
| 850 | if (!IsMarked(obj)) { |
| 851 | heap_->DumpSpaces(); |
| 852 | LOG(FATAL) << "Scanning unmarked object " << reinterpret_cast<const void*>(obj); |
| 853 | } |
| 854 | #endif |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 855 | if (obj->IsClass()) { |
| 856 | ScanClass(obj); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 857 | } else if (obj->IsArrayInstance()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 858 | ScanArray(obj); |
| 859 | } else { |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 860 | ScanOther(obj); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 864 | // Scan anything that's on the mark stack. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 865 | void MarkSweep::ProcessMarkStack() { |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 866 | if (kUseMarkStackPrefetch) { |
| 867 | const size_t fifo_size = 4; |
| 868 | const size_t fifo_mask = fifo_size - 1; |
| 869 | const Object* fifo[fifo_size]; |
| 870 | for (size_t i = 0;i < fifo_size;++i) { |
| 871 | fifo[i] = NULL; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 872 | } |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 873 | size_t fifo_pos = 0; |
| 874 | size_t fifo_count = 0; |
| 875 | for (;;) { |
| 876 | const Object* obj = fifo[fifo_pos & fifo_mask]; |
| 877 | if (obj != NULL) { |
| 878 | ScanObject(obj); |
| 879 | fifo[fifo_pos & fifo_mask] = NULL; |
| 880 | --fifo_count; |
| 881 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 882 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 883 | if (!mark_stack_->IsEmpty()) { |
| 884 | const Object* obj = mark_stack_->PopBack(); |
| 885 | DCHECK(obj != NULL); |
| 886 | fifo[fifo_pos & fifo_mask] = obj; |
| 887 | __builtin_prefetch(obj); |
| 888 | fifo_count++; |
| 889 | } |
| 890 | fifo_pos++; |
| 891 | |
| 892 | if (!fifo_count) { |
| 893 | CHECK(mark_stack_->IsEmpty()) << mark_stack_->Size(); |
| 894 | break; |
| 895 | } |
| 896 | } |
| 897 | } else { |
| 898 | while (!mark_stack_->IsEmpty()) { |
| 899 | const Object* obj = mark_stack_->PopBack(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 900 | DCHECK(obj != NULL); |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 901 | ScanObject(obj); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 902 | } |
| 903 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 906 | // Walks the reference list marking any references subject to the |
| 907 | // reference clearing policy. References with a black referent are |
| 908 | // removed from the list. References with white referents biased |
| 909 | // toward saving are blackened and also removed from the list. |
| 910 | void MarkSweep::PreserveSomeSoftReferences(Object** list) { |
| 911 | DCHECK(list != NULL); |
| 912 | Object* clear = NULL; |
| 913 | size_t counter = 0; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 914 | |
| 915 | DCHECK(mark_stack_->IsEmpty()); |
| 916 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 917 | while (*list != NULL) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 918 | Object* ref = heap_->DequeuePendingReference(list); |
| 919 | Object* referent = heap_->GetReferenceReferent(ref); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 920 | if (referent == NULL) { |
| 921 | // Referent was cleared by the user during marking. |
| 922 | continue; |
| 923 | } |
| 924 | bool is_marked = IsMarked(referent); |
| 925 | if (!is_marked && ((++counter) & 1)) { |
| 926 | // Referent is white and biased toward saving, mark it. |
| 927 | MarkObject(referent); |
| 928 | is_marked = true; |
| 929 | } |
| 930 | if (!is_marked) { |
| 931 | // Referent is white, queue it for clearing. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 932 | heap_->EnqueuePendingReference(ref, &clear); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | *list = clear; |
| 936 | // Restart the mark with the newly black references added to the |
| 937 | // root set. |
| 938 | ProcessMarkStack(); |
| 939 | } |
| 940 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 941 | inline bool MarkSweep::IsMarked(const Object* object) const |
| 942 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { |
| 943 | if (object >= immune_begin_ && object < immune_end_) { |
| 944 | return true; |
| 945 | } |
| 946 | DCHECK(current_mark_bitmap_ != NULL); |
| 947 | if (current_mark_bitmap_->HasAddress(object)) { |
| 948 | return current_mark_bitmap_->Test(object); |
| 949 | } |
| 950 | return heap_->GetMarkBitmap()->Test(object); |
| 951 | } |
| 952 | |
| 953 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 954 | // Unlink the reference list clearing references objects with white |
| 955 | // referents. Cleared references registered to a reference queue are |
| 956 | // scheduled for appending by the heap worker thread. |
| 957 | void MarkSweep::ClearWhiteReferences(Object** list) { |
| 958 | DCHECK(list != NULL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 959 | while (*list != NULL) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 960 | Object* ref = heap_->DequeuePendingReference(list); |
| 961 | Object* referent = heap_->GetReferenceReferent(ref); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 962 | if (referent != NULL && !IsMarked(referent)) { |
| 963 | // Referent is white, clear it. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 964 | heap_->ClearReferenceReferent(ref); |
| 965 | if (heap_->IsEnqueuable(ref)) { |
| 966 | heap_->EnqueueReference(ref, &cleared_reference_list_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | } |
| 970 | DCHECK(*list == NULL); |
| 971 | } |
| 972 | |
| 973 | // Enqueues finalizer references with white referents. White |
| 974 | // referents are blackened, moved to the zombie field, and the |
| 975 | // referent field is cleared. |
| 976 | void MarkSweep::EnqueueFinalizerReferences(Object** list) { |
| 977 | DCHECK(list != NULL); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 978 | MemberOffset zombie_offset = heap_->GetFinalizerReferenceZombieOffset(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 979 | bool has_enqueued = false; |
| 980 | while (*list != NULL) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 981 | Object* ref = heap_->DequeuePendingReference(list); |
| 982 | Object* referent = heap_->GetReferenceReferent(ref); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 983 | if (referent != NULL && !IsMarked(referent)) { |
| 984 | MarkObject(referent); |
| 985 | // If the referent is non-null the reference must queuable. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 986 | DCHECK(heap_->IsEnqueuable(ref)); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 987 | ref->SetFieldObject(zombie_offset, referent, false); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 988 | heap_->ClearReferenceReferent(ref); |
| 989 | heap_->EnqueueReference(ref, &cleared_reference_list_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 990 | has_enqueued = true; |
| 991 | } |
| 992 | } |
| 993 | if (has_enqueued) { |
| 994 | ProcessMarkStack(); |
| 995 | } |
| 996 | DCHECK(*list == NULL); |
| 997 | } |
| 998 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 999 | // Process reference class instances and schedule finalizations. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1000 | void MarkSweep::ProcessReferences(Object** soft_references, bool clear_soft, |
| 1001 | Object** weak_references, |
| 1002 | Object** finalizer_references, |
| 1003 | Object** phantom_references) { |
| 1004 | DCHECK(soft_references != NULL); |
| 1005 | DCHECK(weak_references != NULL); |
| 1006 | DCHECK(finalizer_references != NULL); |
| 1007 | DCHECK(phantom_references != NULL); |
| 1008 | |
| 1009 | // Unless we are in the zygote or required to clear soft references |
| 1010 | // with white references, preserve some white referents. |
Ian Rogers | 2945e24 | 2012-06-03 14:45:16 -0700 | [diff] [blame] | 1011 | if (!clear_soft && !Runtime::Current()->IsZygote()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1012 | PreserveSomeSoftReferences(soft_references); |
| 1013 | } |
| 1014 | |
| 1015 | // Clear all remaining soft and weak references with white |
| 1016 | // referents. |
| 1017 | ClearWhiteReferences(soft_references); |
| 1018 | ClearWhiteReferences(weak_references); |
| 1019 | |
| 1020 | // Preserve all white objects with finalize methods and schedule |
| 1021 | // them for finalization. |
| 1022 | EnqueueFinalizerReferences(finalizer_references); |
| 1023 | |
| 1024 | // Clear all f-reachable soft and weak references with white |
| 1025 | // referents. |
| 1026 | ClearWhiteReferences(soft_references); |
| 1027 | ClearWhiteReferences(weak_references); |
| 1028 | |
| 1029 | // Clear all phantom references with white referents. |
| 1030 | ClearWhiteReferences(phantom_references); |
| 1031 | |
| 1032 | // At this point all reference lists should be empty. |
| 1033 | DCHECK(*soft_references == NULL); |
| 1034 | DCHECK(*weak_references == NULL); |
| 1035 | DCHECK(*finalizer_references == NULL); |
| 1036 | DCHECK(*phantom_references == NULL); |
| 1037 | } |
| 1038 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1039 | void MarkSweep::UnBindBitmaps() { |
| 1040 | const Spaces& spaces = heap_->GetSpaces(); |
| 1041 | // TODO: C++0x auto |
| 1042 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 1043 | Space* space = *it; |
| 1044 | if (space->IsAllocSpace()) { |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 1045 | DlMallocSpace* alloc_space = space->AsAllocSpace(); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1046 | if (alloc_space->temp_bitmap_.get() != NULL) { |
| 1047 | // At this point, the temp_bitmap holds our old mark bitmap. |
| 1048 | SpaceBitmap* new_bitmap = alloc_space->temp_bitmap_.release(); |
| 1049 | GetHeap()->GetMarkBitmap()->ReplaceBitmap(alloc_space->mark_bitmap_.get(), new_bitmap); |
| 1050 | CHECK_EQ(alloc_space->mark_bitmap_.release(), alloc_space->live_bitmap_.get()); |
| 1051 | alloc_space->mark_bitmap_.reset(new_bitmap); |
| 1052 | DCHECK(alloc_space->temp_bitmap_.get() == NULL); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1058 | MarkSweep::~MarkSweep() { |
Elliott Hughes | 352a424 | 2011-10-31 15:15:21 -0700 | [diff] [blame] | 1059 | #ifndef NDEBUG |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1060 | VLOG(heap) << "MarkSweep scanned classes=" << class_count_ << " arrays=" << array_count_ << " other=" << other_count_; |
Elliott Hughes | 352a424 | 2011-10-31 15:15:21 -0700 | [diff] [blame] | 1061 | #endif |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1062 | // Ensure that the mark stack is empty. |
| 1063 | CHECK(mark_stack_->IsEmpty()); |
| 1064 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1065 | // Clear all of the alloc spaces' mark bitmaps. |
| 1066 | const Spaces& spaces = heap_->GetSpaces(); |
| 1067 | // TODO: C++0x auto |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1068 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1069 | ContinuousSpace* space = *it; |
| 1070 | if (space->GetGcRetentionPolicy() != kGcRetentionPolicyNeverCollect) { |
| 1071 | space->GetMarkBitmap()->Clear(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 1074 | mark_stack_->Reset(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1075 | |
| 1076 | // Reset the marked large objects. |
| 1077 | LargeObjectSpace* large_objects = GetHeap()->GetLargeObjectsSpace(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1078 | large_objects->GetMarkObjects()->Clear(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | } // namespace art |