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

Side by Side Diff: src/zone.cc

Issue 456663002: Make Zone::New() and Zone::NewArray() usable w/o v8.h. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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') | src/zone-inl.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string.h> 5 #include <string.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 #include "src/zone-inl.h" 8 #include "src/zone-inl.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 56
57 Zone::~Zone() { 57 Zone::~Zone() {
58 DeleteAll(); 58 DeleteAll();
59 DeleteKeptSegment(); 59 DeleteKeptSegment();
60 60
61 DCHECK(segment_bytes_allocated_ == 0); 61 DCHECK(segment_bytes_allocated_ == 0);
62 } 62 }
63 63
64 64
65 void* Zone::New(int size) {
66 // Round up the requested size to fit the alignment.
67 size = RoundUp(size, kAlignment);
68
69 // If the allocation size is divisible by 8 then we return an 8-byte aligned
70 // address.
71 if (kPointerSize == 4 && kAlignment == 4) {
72 position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4);
73 } else {
74 DCHECK(kAlignment >= kPointerSize);
75 }
76
77 // Check if the requested size is available without expanding.
78 Address result = position_;
79
80 int size_with_redzone =
81 #ifdef V8_USE_ADDRESS_SANITIZER
82 size + kASanRedzoneBytes;
83 #else
84 size;
85 #endif
86
87 if (size_with_redzone > limit_ - position_) {
88 result = NewExpand(size_with_redzone);
89 } else {
90 position_ += size_with_redzone;
91 }
92
93 #ifdef V8_USE_ADDRESS_SANITIZER
94 Address redzone_position = result + size;
95 DCHECK(redzone_position + kASanRedzoneBytes == position_);
96 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
97 #endif
98
99 // Check that the result has the proper alignment and return it.
100 DCHECK(IsAddressAligned(result, kAlignment, 0));
101 allocation_size_ += size;
102 return reinterpret_cast<void*>(result);
103 }
104
105
65 void Zone::DeleteAll() { 106 void Zone::DeleteAll() {
66 #ifdef DEBUG 107 #ifdef DEBUG
67 // Constant byte value used for zapping dead memory in debug mode. 108 // Constant byte value used for zapping dead memory in debug mode.
68 static const unsigned char kZapDeadByte = 0xcd; 109 static const unsigned char kZapDeadByte = 0xcd;
69 #endif 110 #endif
70 111
71 // Find a segment with a suitable size to keep around. 112 // Find a segment with a suitable size to keep around.
72 Segment* keep = NULL; 113 Segment* keep = NULL;
73 // Traverse the chained list of segments, zapping (in debug mode) 114 // Traverse the chained list of segments, zapping (in debug mode)
74 // and freeing every segment except the one we wish to keep. 115 // and freeing every segment except the one we wish to keep.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 V8::FatalProcessOutOfMemory("Zone"); 250 V8::FatalProcessOutOfMemory("Zone");
210 return NULL; 251 return NULL;
211 } 252 }
212 limit_ = segment->end(); 253 limit_ = segment->end();
213 DCHECK(position_ <= limit_); 254 DCHECK(position_ <= limit_);
214 return result; 255 return result;
215 } 256 }
216 257
217 258
218 } } // namespace v8::internal 259 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/zone.h ('k') | src/zone-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698