Index: runtime/vm/zone.cc |
diff --git a/runtime/vm/zone.cc b/runtime/vm/zone.cc |
index 9bbc8eb6b3ebabc8d4fc8fb39cd2e77035c970f7..a5b6a7d312d3f12a9e87f3fdb20481f5521645d4 100644 |
--- a/runtime/vm/zone.cc |
+++ b/runtime/vm/zone.cc |
@@ -20,10 +20,10 @@ namespace dart { |
class Zone::Segment { |
public: |
Segment* next() const { return next_; } |
- intptr_t size() const { return size_; } |
+ intptr_t size() const { return memory_->size(); } |
uword start() { return address(sizeof(Segment)); } |
- uword end() { return address(size_); } |
+ uword end() { return address(size()); } |
zra
2017/06/26 20:30:00
Should this be address(size() - sizeof(Segment))?
rmacnak
2017/06/26 20:44:43
Hm, the size() calculate should exclude the Segeme
|
// Allocate or delete individual segments. |
static Segment* New(intptr_t size, Segment* next); |
@@ -32,13 +32,13 @@ class Zone::Segment { |
static void DecrementMemoryCapacity(uintptr_t size); |
private: |
+ VirtualMemory* memory_; |
Segment* next_; |
- intptr_t size_; |
// Computes the address of the nth byte in this segment. |
uword address(int n) { return reinterpret_cast<uword>(this) + n; } |
- static void Delete(Segment* segment) { free(segment); } |
+ static void Delete(Segment* segment) { delete segment->memory_; } |
DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); |
}; |
@@ -46,17 +46,20 @@ class Zone::Segment { |
Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { |
ASSERT(size >= 0); |
- Segment* result = reinterpret_cast<Segment*>(malloc(size)); |
- if (result == NULL) { |
+ size = Utils::RoundUp(size, VirtualMemory::PageSize()); |
+ VirtualMemory* memory = VirtualMemory::Reserve(size); |
+ const bool kNotExecutable = false; |
+ if ((memory == NULL) || !memory->Commit(kNotExecutable, "dart-zone")) { |
OUT_OF_MEMORY(); |
} |
+ Segment* result = reinterpret_cast<Segment*>(memory->address()); |
ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); |
#ifdef DEBUG |
// Zap the entire allocated segment (including the header). |
memset(result, kZapUninitializedByte, size); |
#endif |
+ result->memory_ = memory; |
result->next_ = next; |
- result->size_ = size; |
IncrementMemoryCapacity(size); |
return result; |
} |
@@ -67,10 +70,6 @@ void Zone::Segment::DeleteSegmentList(Segment* head) { |
while (current != NULL) { |
DecrementMemoryCapacity(current->size()); |
Segment* next = current->next(); |
-#ifdef DEBUG |
- // Zap the entire current segment (including the header). |
- memset(current, kZapDeletedByte, current->size()); |
-#endif |
Segment::Delete(current); |
current = next; |
} |