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

Unified Diff: runtime/vm/zone.cc

Issue 2955493002: Allocate the profiler sample buffer and zone segments with virtual memory instead of malloc. (Closed)
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/profiler.cc ('K') | « runtime/vm/virtual_memory_fuchsia.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« runtime/vm/profiler.cc ('K') | « runtime/vm/virtual_memory_fuchsia.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698