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

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

Issue 320463003: Make unused semispace available to other isolates. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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_SCAVENGER_H_ 5 #ifndef VM_SCAVENGER_H_
6 #define VM_SCAVENGER_H_ 6 #define VM_SCAVENGER_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
11 #include "vm/flags.h" 11 #include "vm/flags.h"
12 #include "vm/globals.h" 12 #include "vm/globals.h"
13 #include "vm/raw_object.h" 13 #include "vm/raw_object.h"
14 #include "vm/spaces.h" 14 #include "vm/spaces.h"
15 #include "vm/virtual_memory.h" 15 #include "vm/virtual_memory.h"
16 #include "vm/visitor.h" 16 #include "vm/visitor.h"
17 17
18 namespace dart { 18 namespace dart {
19 19
20 // Forward declarations. 20 // Forward declarations.
21 class Heap; 21 class Heap;
22 class Isolate; 22 class Isolate;
23 class JSONObject; 23 class JSONObject;
24 class ScavengerVisitor; 24 class ScavengerVisitor;
25 25
26 DECLARE_FLAG(bool, gc_at_alloc); 26 DECLARE_FLAG(bool, gc_at_alloc);
27 27
28
29 // Wrapper around VirtualMemory that adds caching and handles the empty case.
30 class SemiSpace {
31 public:
Ivan Posva 2014/06/05 22:27:29 Please use vertical space for easier reading.
koda 2014/06/05 23:04:23 Done.
32 static void InitOnce();
33 // Get a space of the given size. Returns NULL on out of memory. If size is 0,
34 // returns an empty space: pointer(), start() and end() all return NULL/0.
35 static SemiSpace* New(intptr_t size);
36 // Hand back an unused space. Safe to call on NULL.
Ivan Posva 2014/06/05 22:27:29 Why would we ever want to call Delete on NULL?
koda 2014/06/05 23:04:23 Allowing NULL keeps it consistent with the 'delete
koda 2014/06/05 23:08:29 Actually, the commit failure check in this very CL
37 void Delete();
38 void* pointer() const { return region_.pointer(); }
39 uword start() const { return region_.start(); }
40 uword end() const { return region_.end(); }
41 intptr_t size() const { return static_cast<intptr_t>(region_.size()); }
42 bool Contains(uword address) const { return region_.Contains(address); }
43 // Set write protection mode for this space. The space must not be protected
44 // when Delete is called.
45 // TODO(koda): Remember protection mode in VirtualMemory and assert this.
46 void WriteProtect(bool read_only);
Ivan Posva 2014/06/05 22:27:29 Do we ever write protect a new gen?
koda 2014/06/05 23:04:23 Heap::WriteProtect includes new gen, but it's curr
47 private:
48 explicit SemiSpace(VirtualMemory* reserved);
49 ~SemiSpace();
50 VirtualMemory* reserved_; // NULL for an emtpy space.
51 MemoryRegion region_;
52 static SemiSpace* cache_;
53 static Mutex* mutex_;
54 };
55
56
28 class Scavenger { 57 class Scavenger {
29 public: 58 public:
30 Scavenger(Heap* heap, intptr_t max_capacity_in_words, uword object_alignment); 59 Scavenger(Heap* heap, intptr_t max_capacity_in_words, uword object_alignment);
31 ~Scavenger(); 60 ~Scavenger();
32 61
33 // Check whether this Scavenger contains this address. 62 // Check whether this Scavenger contains this address.
34 // During scavenging both the to and from spaces contain "legal" objects. 63 // During scavenging both the to and from spaces contain "legal" objects.
35 // During a scavenge this function only returns true for addresses that will 64 // During a scavenge this function only returns true for addresses that will
36 // be part of the surviving objects. 65 // be part of the surviving objects.
37 bool Contains(uword addr) const { 66 bool Contains(uword addr) const {
38 // No reasonable algorithm should be checking for objects in from space. At 67 // No reasonable algorithm should be checking for objects in from space. At
39 // least unless it is debugging code. This might need to be relaxed later, 68 // least unless it is debugging code. This might need to be relaxed later,
40 // but currently it helps prevent dumb bugs. 69 // but currently it helps prevent dumb bugs.
41 ASSERT(!from_->Contains(addr)); 70 ASSERT(from_ == NULL || !from_->Contains(addr));
42 return to_->Contains(addr); 71 return to_->Contains(addr);
43 } 72 }
44 73
45 RawObject* FindObject(FindObjectVisitor* visitor) const; 74 RawObject* FindObject(FindObjectVisitor* visitor) const;
46 75
47 uword TryAllocate(intptr_t size) { 76 uword TryAllocate(intptr_t size) {
48 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 77 ASSERT(Utils::IsAligned(size, kObjectAlignment));
49 ASSERT(heap_ != Dart::vm_isolate()->heap()); 78 ASSERT(heap_ != Dart::vm_isolate()->heap());
50 #if defined(DEBUG) 79 #if defined(DEBUG)
51 if (FLAG_gc_at_alloc && !scavenging_) { 80 if (FLAG_gc_at_alloc && !scavenging_) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ASSERT(end_ <= to_->end()); 205 ASSERT(end_ <= to_->end());
177 return result; 206 return result;
178 } 207 }
179 bool PromotedStackHasMore() const { 208 bool PromotedStackHasMore() const {
180 ASSERT(scavenging_); 209 ASSERT(scavenging_);
181 return end_ < to_->end(); 210 return end_ < to_->end();
182 } 211 }
183 212
184 void ProcessWeakTables(); 213 void ProcessWeakTables();
185 214
186 VirtualMemory* space_; 215 SemiSpace* from_;
187 MemoryRegion* to_; 216 SemiSpace* to_;
188 MemoryRegion* from_;
189 217
190 Heap* heap_; 218 Heap* heap_;
191 219
192 // Current allocation top and end. These values are being accessed directly 220 // Current allocation top and end. These values are being accessed directly
193 // from generated code. 221 // from generated code.
194 uword top_; 222 uword top_;
195 uword end_; 223 uword end_;
196 224
197 // A pointer to the first unscanned object. Scanning completes when 225 // A pointer to the first unscanned object. Scanning completes when
198 // this value meets the allocation top. 226 // this value meets the allocation top.
(...skipping 16 matching lines...) Expand all
215 243
216 friend class ScavengerVisitor; 244 friend class ScavengerVisitor;
217 friend class ScavengerWeakVisitor; 245 friend class ScavengerWeakVisitor;
218 246
219 DISALLOW_COPY_AND_ASSIGN(Scavenger); 247 DISALLOW_COPY_AND_ASSIGN(Scavenger);
220 }; 248 };
221 249
222 } // namespace dart 250 } // namespace dart
223 251
224 #endif // VM_SCAVENGER_H_ 252 #endif // VM_SCAVENGER_H_
OLDNEW
« no previous file with comments | « runtime/vm/memory_region.h ('k') | runtime/vm/scavenger.cc » ('j') | runtime/vm/scavenger.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698