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

Side by Side Diff: src/zone.cc

Issue 7631020: Version 3.5.6. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 4 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
« no previous file with comments | « src/zone.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "zone-inl.h" 30 #include "zone-inl.h"
31 #include "splay-tree-inl.h" 31 #include "splay-tree-inl.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 36
37 Zone::Zone()
38 : zone_excess_limit_(256 * MB),
39 segment_bytes_allocated_(0),
40 position_(0),
41 limit_(0),
42 scope_nesting_(0),
43 segment_head_(NULL) {
44 }
45 unsigned Zone::allocation_size_ = 0;
46
47
48 ZoneScope::~ZoneScope() {
49 ASSERT_EQ(Isolate::Current(), isolate_);
50 if (ShouldDeleteOnExit()) isolate_->zone()->DeleteAll();
51 isolate_->zone()->scope_nesting_--;
52 }
53
54
55 // Segments represent chunks of memory: They have starting address 37 // Segments represent chunks of memory: They have starting address
56 // (encoded in the this pointer) and a size in bytes. Segments are 38 // (encoded in the this pointer) and a size in bytes. Segments are
57 // chained together forming a LIFO structure with the newest segment 39 // chained together forming a LIFO structure with the newest segment
58 // available as segment_head_. Segments are allocated using malloc() 40 // available as segment_head_. Segments are allocated using malloc()
59 // and de-allocated using free(). 41 // and de-allocated using free().
60 42
61 class Segment { 43 class Segment {
62 public: 44 public:
45 void Initialize(Segment* next, int size) {
46 next_ = next;
47 size_ = size;
48 }
49
63 Segment* next() const { return next_; } 50 Segment* next() const { return next_; }
64 void clear_next() { next_ = NULL; } 51 void clear_next() { next_ = NULL; }
65 52
66 int size() const { return size_; } 53 int size() const { return size_; }
67 int capacity() const { return size_ - sizeof(Segment); } 54 int capacity() const { return size_ - sizeof(Segment); }
68 55
69 Address start() const { return address(sizeof(Segment)); } 56 Address start() const { return address(sizeof(Segment)); }
70 Address end() const { return address(size_); } 57 Address end() const { return address(size_); }
71 58
72 private: 59 private:
73 // Computes the address of the nth byte in this segment. 60 // Computes the address of the nth byte in this segment.
74 Address address(int n) const { 61 Address address(int n) const {
75 return Address(this) + n; 62 return Address(this) + n;
76 } 63 }
77 64
78 Segment* next_; 65 Segment* next_;
79 int size_; 66 int size_;
67 };
80 68
81 friend class Zone; 69
82 }; 70 Zone::Zone()
71 : zone_excess_limit_(256 * MB),
72 segment_bytes_allocated_(0),
73 position_(0),
74 limit_(0),
75 scope_nesting_(0),
76 segment_head_(NULL) {
77 }
78 unsigned Zone::allocation_size_ = 0;
79
80 ZoneScope::~ZoneScope() {
81 ASSERT_EQ(Isolate::Current(), isolate_);
82 if (ShouldDeleteOnExit()) isolate_->zone()->DeleteAll();
83 isolate_->zone()->scope_nesting_--;
84 }
83 85
84 86
85 // Creates a new segment, sets it size, and pushes it to the front 87 // Creates a new segment, sets it size, and pushes it to the front
86 // of the segment chain. Returns the new segment. 88 // of the segment chain. Returns the new segment.
87 Segment* Zone::NewSegment(int size) { 89 Segment* Zone::NewSegment(int size) {
88 Segment* result = reinterpret_cast<Segment*>(Malloced::New(size)); 90 Segment* result = reinterpret_cast<Segment*>(Malloced::New(size));
89 adjust_segment_bytes_allocated(size); 91 adjust_segment_bytes_allocated(size);
90 if (result != NULL) { 92 if (result != NULL) {
91 result->next_ = segment_head_; 93 result->Initialize(segment_head_, size);
92 result->size_ = size;
93 segment_head_ = result; 94 segment_head_ = result;
94 } 95 }
95 return result; 96 return result;
96 } 97 }
97 98
98 99
99 // Deletes the given segment. Does not touch the segment chain. 100 // Deletes the given segment. Does not touch the segment chain.
100 void Zone::DeleteSegment(Segment* segment, int size) { 101 void Zone::DeleteSegment(Segment* segment, int size) {
101 adjust_segment_bytes_allocated(-size); 102 adjust_segment_bytes_allocated(-size);
102 Malloced::Delete(segment); 103 Malloced::Delete(segment);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 #endif 149 #endif
149 } else { 150 } else {
150 position_ = limit_ = 0; 151 position_ = limit_ = 0;
151 } 152 }
152 153
153 // Update the head segment to be the kept segment (if any). 154 // Update the head segment to be the kept segment (if any).
154 segment_head_ = keep; 155 segment_head_ = keep;
155 } 156 }
156 157
157 158
159 void Zone::DeleteKeptSegment() {
160 if (segment_head_ != NULL) {
161 DeleteSegment(segment_head_, segment_head_->size());
162 segment_head_ = NULL;
163 }
164 }
165
166
158 Address Zone::NewExpand(int size) { 167 Address Zone::NewExpand(int size) {
159 // Make sure the requested size is already properly aligned and that 168 // Make sure the requested size is already properly aligned and that
160 // there isn't enough room in the Zone to satisfy the request. 169 // there isn't enough room in the Zone to satisfy the request.
161 ASSERT(size == RoundDown(size, kAlignment)); 170 ASSERT(size == RoundDown(size, kAlignment));
162 ASSERT(position_ + size > limit_); 171 ASSERT(position_ + size > limit_);
163 172
164 // Compute the new segment size. We use a 'high water mark' 173 // Compute the new segment size. We use a 'high water mark'
165 // strategy, where we increase the segment size every time we expand 174 // strategy, where we increase the segment size every time we expand
166 // except that we employ a maximum segment size when we delete. This 175 // except that we employ a maximum segment size when we delete. This
167 // is to avoid excessive malloc() and free() overhead. 176 // is to avoid excessive malloc() and free() overhead.
(...skipping 19 matching lines...) Expand all
187 // Recompute 'top' and 'limit' based on the new segment. 196 // Recompute 'top' and 'limit' based on the new segment.
188 Address result = RoundUp(segment->start(), kAlignment); 197 Address result = RoundUp(segment->start(), kAlignment);
189 position_ = result + size; 198 position_ = result + size;
190 limit_ = segment->end(); 199 limit_ = segment->end();
191 ASSERT(position_ <= limit_); 200 ASSERT(position_ <= limit_);
192 return result; 201 return result;
193 } 202 }
194 203
195 204
196 } } // namespace v8::internal 205 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/zone.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698