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

Side by Side Diff: src/zone-inl.h

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.cc ('k') | no next file » | 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 #ifndef V8_ZONE_INL_H_ 5 #ifndef V8_ZONE_INL_H_
6 #define V8_ZONE_INL_H_ 6 #define V8_ZONE_INL_H_
7 7
8 #include "src/zone.h" 8 #include "src/zone.h"
9 9
10 #ifdef V8_USE_ADDRESS_SANITIZER 10 #ifdef V8_USE_ADDRESS_SANITIZER
11 #include <sanitizer/asan_interface.h> 11 #include <sanitizer/asan_interface.h>
12 #else 12 #else
13 #define ASAN_UNPOISON_MEMORY_REGION(start, size) ((void) 0) 13 #define ASAN_UNPOISON_MEMORY_REGION(start, size) ((void) 0)
14 #endif 14 #endif
15 15
16 #include "src/counters.h" 16 #include "src/counters.h"
17 #include "src/isolate.h" 17 #include "src/isolate.h"
18 #include "src/utils.h" 18 #include "src/utils.h"
19 19
20 namespace v8 { 20 namespace v8 {
21 namespace internal { 21 namespace internal {
22 22
23 23
24 static const int kASanRedzoneBytes = 24; // Must be a multiple of 8. 24 static const int kASanRedzoneBytes = 24; // Must be a multiple of 8.
25 25
26 26
27 inline void* Zone::New(int size) {
28 // Round up the requested size to fit the alignment.
29 size = RoundUp(size, kAlignment);
30
31 // If the allocation size is divisible by 8 then we return an 8-byte aligned
32 // address.
33 if (kPointerSize == 4 && kAlignment == 4) {
34 position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4);
35 } else {
36 DCHECK(kAlignment >= kPointerSize);
37 }
38
39 // Check if the requested size is available without expanding.
40 Address result = position_;
41
42 int size_with_redzone =
43 #ifdef V8_USE_ADDRESS_SANITIZER
44 size + kASanRedzoneBytes;
45 #else
46 size;
47 #endif
48
49 if (size_with_redzone > limit_ - position_) {
50 result = NewExpand(size_with_redzone);
51 } else {
52 position_ += size_with_redzone;
53 }
54
55 #ifdef V8_USE_ADDRESS_SANITIZER
56 Address redzone_position = result + size;
57 DCHECK(redzone_position + kASanRedzoneBytes == position_);
58 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
59 #endif
60
61 // Check that the result has the proper alignment and return it.
62 DCHECK(IsAddressAligned(result, kAlignment, 0));
63 allocation_size_ += size;
64 return reinterpret_cast<void*>(result);
65 }
66
67
68 template <typename T>
69 T* Zone::NewArray(int length) {
70 CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > length);
71 return static_cast<T*>(New(length * sizeof(T)));
72 }
73
74
75 bool Zone::excess_allocation() { 27 bool Zone::excess_allocation() {
76 return segment_bytes_allocated_ > kExcessLimit; 28 return segment_bytes_allocated_ > kExcessLimit;
77 } 29 }
78 30
79 31
80 void Zone::adjust_segment_bytes_allocated(int delta) { 32 void Zone::adjust_segment_bytes_allocated(int delta) {
81 segment_bytes_allocated_ += delta; 33 segment_bytes_allocated_ += delta;
82 isolate_->counters()->zone_segment_bytes()->Set(segment_bytes_allocated_); 34 isolate_->counters()->zone_segment_bytes()->Set(segment_bytes_allocated_);
83 } 35 }
84 36
(...skipping 25 matching lines...) Expand all
110 62
111 template <typename T> 63 template <typename T>
112 void* ZoneSplayTree<T>::operator new(size_t size, Zone* zone) { 64 void* ZoneSplayTree<T>::operator new(size_t size, Zone* zone) {
113 return zone->New(static_cast<int>(size)); 65 return zone->New(static_cast<int>(size));
114 } 66 }
115 67
116 68
117 } } // namespace v8::internal 69 } } // namespace v8::internal
118 70
119 #endif // V8_ZONE_INL_H_ 71 #endif // V8_ZONE_INL_H_
OLDNEW
« no previous file with comments | « src/zone.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698