Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: runtime/vm/heap.h

Issue 1212943010: Safer interface for heap iteration. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_HEAP_H_ 5 #ifndef VM_HEAP_H_
6 #define VM_HEAP_H_ 6 #define VM_HEAP_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/flags.h" 10 #include "vm/flags.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Move external size from new to old space. Does not by itself trigger GC. 98 // Move external size from new to old space. Does not by itself trigger GC.
99 void PromoteExternal(intptr_t size); 99 void PromoteExternal(intptr_t size);
100 100
101 // Heap contains the specified address. 101 // Heap contains the specified address.
102 bool Contains(uword addr) const; 102 bool Contains(uword addr) const;
103 bool NewContains(uword addr) const; 103 bool NewContains(uword addr) const;
104 bool OldContains(uword addr) const; 104 bool OldContains(uword addr) const;
105 bool CodeContains(uword addr) const; 105 bool CodeContains(uword addr) const;
106 bool StubCodeContains(uword addr) const; 106 bool StubCodeContains(uword addr) const;
107 107
108 // Visit all pointers. Caller must ensure concurrent sweeper is not running, 108 void IterateObjects(ObjectVisitor* visitor) const;
109 // and the visitor must not allocate (see issue 21620). 109 void IterateOldObjects(ObjectVisitor* visitor) const;
110 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; 110 void IterateObjectPointers(ObjectVisitor* visitor) const;
111
112 // Visit all objects, including FreeListElement "objects". Caller must ensure
113 // concurrent sweeper is not running, and the visitor must not allocate (see
114 // issue 21620).
115 void VisitObjects(ObjectVisitor* visitor) const;
116 111
117 // Find an object by visiting all pointers in the specified heap space, 112 // Find an object by visiting all pointers in the specified heap space,
118 // the 'visitor' is used to determine if an object is found or not. 113 // the 'visitor' is used to determine if an object is found or not.
119 // The 'visitor' function should be set up to return true if the 114 // The 'visitor' function should be set up to return true if the
120 // object is found, traversal through the heap space stops at that 115 // object is found, traversal through the heap space stops at that
121 // point. 116 // point.
122 // The 'visitor' function should return false if the object is not found, 117 // The 'visitor' function should return false if the object is not found,
123 // traversal through the heap space continues. 118 // traversal through the heap space continues.
124 // Returns null object if nothing is found. Must be called within a 119 // Returns null object if nothing is found.
125 // NoSafepointScope.
126 RawInstructions* FindObjectInCodeSpace(FindObjectVisitor* visitor) const; 120 RawInstructions* FindObjectInCodeSpace(FindObjectVisitor* visitor) const;
127 RawObject* FindOldObject(FindObjectVisitor* visitor) const; 121 RawObject* FindOldObject(FindObjectVisitor* visitor) const;
128 RawObject* FindNewObject(FindObjectVisitor* visitor) const; 122 RawObject* FindNewObject(FindObjectVisitor* visitor) const;
129 RawObject* FindObject(FindObjectVisitor* visitor) const; 123 RawObject* FindObject(FindObjectVisitor* visitor) const;
130 124
131 void CollectGarbage(Space space); 125 void CollectGarbage(Space space);
132 void CollectGarbage(Space space, ApiCallbacks api_callbacks, GCReason reason); 126 void CollectGarbage(Space space, ApiCallbacks api_callbacks, GCReason reason);
133 void CollectAllGarbage(); 127 void CollectAllGarbage();
134 128
135 // Enables growth control on the page space heaps. This should be 129 // Enables growth control on the page space heaps. This should be
(...skipping 16 matching lines...) Expand all
152 146
153 // Initialize the heap and register it with the isolate. 147 // Initialize the heap and register it with the isolate.
154 static void Init(Isolate* isolate, 148 static void Init(Isolate* isolate,
155 intptr_t max_new_gen_words, 149 intptr_t max_new_gen_words,
156 intptr_t max_old_gen_words, 150 intptr_t max_old_gen_words,
157 intptr_t max_external_words); 151 intptr_t max_external_words);
158 152
159 // Verify that all pointers in the heap point to the heap. 153 // Verify that all pointers in the heap point to the heap.
160 bool Verify(MarkExpectation mark_expectation = kForbidMarked) const; 154 bool Verify(MarkExpectation mark_expectation = kForbidMarked) const;
161 155
156 // Like Verify, but does not wait for concurrent sweeper, so caller must
157 // ensure thread-safety.
158 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const;
siva 2015/07/07 18:10:24 Can this be a private function?
koda 2015/07/07 22:46:39 Done.
159
162 // Print heap sizes. 160 // Print heap sizes.
163 void PrintSizes() const; 161 void PrintSizes() const;
164 162
165 // Return amount of memory used and capacity in a space, excluding external. 163 // Return amount of memory used and capacity in a space, excluding external.
166 intptr_t UsedInWords(Space space) const; 164 intptr_t UsedInWords(Space space) const;
167 intptr_t CapacityInWords(Space space) const; 165 intptr_t CapacityInWords(Space space) const;
168 intptr_t ExternalInWords(Space space) const; 166 intptr_t ExternalInWords(Space space) const;
169 // Return the amount of GCing in microseconds. 167 // Return the amount of GCing in microseconds.
170 int64_t GCTimeInMicros(Space space) const; 168 int64_t GCTimeInMicros(Space space) const;
171 169
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 275
278 Heap(Isolate* isolate, 276 Heap(Isolate* isolate,
279 intptr_t max_new_gen_semi_words, // Max capacity of new semi-space. 277 intptr_t max_new_gen_semi_words, // Max capacity of new semi-space.
280 intptr_t max_old_gen_words, 278 intptr_t max_old_gen_words,
281 intptr_t max_external_words); 279 intptr_t max_external_words);
282 280
283 uword AllocateNew(intptr_t size); 281 uword AllocateNew(intptr_t size);
284 uword AllocateOld(intptr_t size, HeapPage::PageType type); 282 uword AllocateOld(intptr_t size, HeapPage::PageType type);
285 uword AllocatePretenured(intptr_t size); 283 uword AllocatePretenured(intptr_t size);
286 284
285 // Visit all pointers. Caller must ensure concurrent sweeper is not running,
286 // and the visitor must not allocate.
287 void VisitObjectPointers(ObjectPointerVisitor* visitor) const;
288
289 // Visit all objects, including FreeListElement "objects". Caller must ensure
290 // concurrent sweeper is not running, and the visitor must not allocate.
291 void VisitObjects(ObjectVisitor* visitor) const;
292
287 // GC stats collection. 293 // GC stats collection.
288 void RecordBeforeGC(Space space, GCReason reason); 294 void RecordBeforeGC(Space space, GCReason reason);
289 void RecordAfterGC(); 295 void RecordAfterGC();
290 void PrintStats(); 296 void PrintStats();
291 void UpdateClassHeapStatsBeforeGC(Heap::Space space); 297 void UpdateClassHeapStatsBeforeGC(Heap::Space space);
292 void UpdatePretenurePolicy(); 298 void UpdatePretenurePolicy();
293 299
294 // If this heap is non-empty, updates start and end to the smallest range that 300 // If this heap is non-empty, updates start and end to the smallest range that
295 // contains both the original [start, end) and the [lowest, highest) addresses 301 // contains both the original [start, end) and the [lowest, highest) addresses
296 // of this heap. 302 // of this heap.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 #else // defined(DEBUG) 341 #else // defined(DEBUG)
336 class NoSafepointScope : public ValueObject { 342 class NoSafepointScope : public ValueObject {
337 public: 343 public:
338 NoSafepointScope() {} 344 NoSafepointScope() {}
339 private: 345 private:
340 DISALLOW_COPY_AND_ASSIGN(NoSafepointScope); 346 DISALLOW_COPY_AND_ASSIGN(NoSafepointScope);
341 }; 347 };
342 #endif // defined(DEBUG) 348 #endif // defined(DEBUG)
343 349
344 350
351 class HeapIterationScope : public StackResource {
352 public:
353 HeapIterationScope();
354 ~HeapIterationScope();
355 private:
356 NoSafepointScope no_safepoint_scope_;
357 PageSpace* old_space_;
358
359 DISALLOW_COPY_AND_ASSIGN(HeapIterationScope);
360 };
361
362
345 class NoHeapGrowthControlScope : public StackResource { 363 class NoHeapGrowthControlScope : public StackResource {
346 public: 364 public:
347 NoHeapGrowthControlScope(); 365 NoHeapGrowthControlScope();
348 ~NoHeapGrowthControlScope(); 366 ~NoHeapGrowthControlScope();
349 private: 367 private:
350 bool current_growth_controller_state_; 368 bool current_growth_controller_state_;
351 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); 369 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope);
352 }; 370 };
353 371
354 } // namespace dart 372 } // namespace dart
355 373
356 #endif // VM_HEAP_H_ 374 #endif // VM_HEAP_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/heap.cc » ('j') | runtime/vm/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698