v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zone-inl.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_ZONE_INL_H_
29 #define V8_ZONE_INL_H_
30 
31 #include "zone.h"
32 
33 #ifdef V8_USE_ADDRESS_SANITIZER
34  #include <sanitizer/asan_interface.h>
35 #else
36  #define ASAN_UNPOISON_MEMORY_REGION(start, size) ((void) 0)
37 #endif
38 
39 #include "counters.h"
40 #include "isolate.h"
41 #include "utils.h"
42 #include "v8-counters.h"
43 
44 namespace v8 {
45 namespace internal {
46 
47 
48 static const int kASanRedzoneBytes = 24; // Must be a multiple of 8.
49 
50 
51 inline void* Zone::New(int size) {
52  // Round up the requested size to fit the alignment.
53  size = RoundUp(size, kAlignment);
54 
55  // If the allocation size is divisible by 8 then we return an 8-byte aligned
56  // address.
57  if (kPointerSize == 4 && kAlignment == 4) {
58  position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4);
59  } else {
60  ASSERT(kAlignment >= kPointerSize);
61  }
62 
63  // Check if the requested size is available without expanding.
64  Address result = position_;
65 
66  int size_with_redzone =
67 #ifdef V8_USE_ADDRESS_SANITIZER
68  size + kASanRedzoneBytes;
69 #else
70  size;
71 #endif
72 
73  if (size_with_redzone > limit_ - position_) {
74  result = NewExpand(size_with_redzone);
75  } else {
76  position_ += size_with_redzone;
77  }
78 
79 #ifdef V8_USE_ADDRESS_SANITIZER
80  Address redzone_position = result + size;
81  ASSERT(redzone_position + kASanRedzoneBytes == position_);
82  ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
83 #endif
84 
85  // Check that the result has the proper alignment and return it.
86  ASSERT(IsAddressAligned(result, kAlignment, 0));
87  allocation_size_ += size;
88  return reinterpret_cast<void*>(result);
89 }
90 
91 
92 template <typename T>
93 T* Zone::NewArray(int length) {
94  CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > length);
95  return static_cast<T*>(New(length * sizeof(T)));
96 }
97 
98 
100  return segment_bytes_allocated_ > kExcessLimit;
101 }
102 
103 
105  segment_bytes_allocated_ += delta;
106  isolate_->counters()->zone_segment_bytes()->Set(segment_bytes_allocated_);
107 }
108 
109 
110 template <typename Config>
112  // Reset the root to avoid unneeded iteration over all tree nodes
113  // in the destructor. For a zone-allocated tree, nodes will be
114  // freed by the Zone.
116 }
117 
118 
119 void* ZoneObject::operator new(size_t size, Zone* zone) {
120  return zone->New(static_cast<int>(size));
121 }
122 
123 inline void* ZoneAllocationPolicy::New(size_t size) {
124  ASSERT(zone_);
125  return zone_->New(static_cast<int>(size));
126 }
127 
128 
129 template <typename T>
130 void* ZoneList<T>::operator new(size_t size, Zone* zone) {
131  return zone->New(static_cast<int>(size));
132 }
133 
134 
135 template <typename T>
136 void* ZoneSplayTree<T>::operator new(size_t size, Zone* zone) {
137  return zone->New(static_cast<int>(size));
138 }
139 
140 
141 } } // namespace v8::internal
142 
143 #endif // V8_ZONE_INL_H_
byte * Address
Definition: globals.h:186
bool IsAddressAligned(Address addr, intptr_t alignment, int offset=0)
Definition: utils.h:217
bool excess_allocation()
Definition: zone-inl.h:99
#define ASSERT(condition)
Definition: checks.h:329
#define CHECK(condition)
Definition: checks.h:75
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
Definition: flags.cc:211
const int kPointerSize
Definition: globals.h:268
T RoundUp(T x, intptr_t m)
Definition: utils.h:144
void adjust_segment_bytes_allocated(int delta)
Definition: zone-inl.h:104
T * NewArray(int length)
Definition: zone-inl.h:93
#define T(name, string, precedence)
Definition: token.cc:48
Counters * counters()
Definition: isolate.h:859
void * New(int size)
Definition: zone-inl.h:51