jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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_UTILS_H_ |
| 29 | #define V8_UTILS_H_ |
| 30 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 31 | #include <stdlib.h> |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 32 | #include <string.h> |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 33 | #include <climits> |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 34 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 35 | #include "globals.h" |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 36 | #include "checks.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 37 | #include "allocation.h" |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 38 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | // General helper functions |
| 44 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 45 | #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0) |
| 46 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 47 | // Returns true iff x is a power of 2 (or zero). Cannot be used with the |
| 48 | // maximally negative value of the type T (the -1 overflows). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 50 | inline bool IsPowerOf2(T x) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 51 | return IS_POWER_OF_TWO(x); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 55 | // X must be a power of 2. Returns the number of trailing zeros. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 56 | inline int WhichPowerOf2(uint32_t x) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 57 | ASSERT(IsPowerOf2(x)); |
| 58 | ASSERT(x != 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 59 | int bits = 0; |
| 60 | #ifdef DEBUG |
| 61 | int original_x = x; |
| 62 | #endif |
| 63 | if (x >= 0x10000) { |
| 64 | bits += 16; |
| 65 | x >>= 16; |
| 66 | } |
| 67 | if (x >= 0x100) { |
| 68 | bits += 8; |
| 69 | x >>= 8; |
| 70 | } |
| 71 | if (x >= 0x10) { |
| 72 | bits += 4; |
| 73 | x >>= 4; |
| 74 | } |
| 75 | switch (x) { |
| 76 | default: UNREACHABLE(); |
| 77 | case 8: bits++; // Fall through. |
| 78 | case 4: bits++; // Fall through. |
| 79 | case 2: bits++; // Fall through. |
| 80 | case 1: break; |
| 81 | } |
| 82 | ASSERT_EQ(1 << bits, original_x); |
| 83 | return bits; |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 88 | // Magic numbers for integer division. |
| 89 | // These are kind of 2's complement reciprocal of the divisors. |
| 90 | // Details and proofs can be found in: |
| 91 | // - Hacker's Delight, Henry S. Warren, Jr. |
| 92 | // - The PowerPC Compiler Writer’s Guide |
| 93 | // and probably many others. |
| 94 | // See details in the implementation of the algorithm in |
| 95 | // lithium-codegen-arm.cc : LCodeGen::TryEmitSignedIntegerDivisionByConstant(). |
| 96 | struct DivMagicNumbers { |
| 97 | unsigned M; |
| 98 | unsigned s; |
| 99 | }; |
| 100 | |
| 101 | const DivMagicNumbers InvalidDivMagicNumber= {0, 0}; |
| 102 | const DivMagicNumbers DivMagicNumberFor3 = {0x55555556, 0}; |
| 103 | const DivMagicNumbers DivMagicNumberFor5 = {0x66666667, 1}; |
| 104 | const DivMagicNumbers DivMagicNumberFor7 = {0x92492493, 2}; |
| 105 | const DivMagicNumbers DivMagicNumberFor9 = {0x38e38e39, 1}; |
| 106 | const DivMagicNumbers DivMagicNumberFor11 = {0x2e8ba2e9, 1}; |
| 107 | const DivMagicNumbers DivMagicNumberFor25 = {0x51eb851f, 3}; |
| 108 | const DivMagicNumbers DivMagicNumberFor125 = {0x10624dd3, 3}; |
| 109 | const DivMagicNumbers DivMagicNumberFor625 = {0x68db8bad, 8}; |
| 110 | |
| 111 | const DivMagicNumbers DivMagicNumberFor(int32_t divisor); |
| 112 | |
| 113 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 114 | // The C++ standard leaves the semantics of '>>' undefined for |
| 115 | // negative signed operands. Most implementations do the right thing, |
| 116 | // though. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 117 | inline int ArithmeticShiftRight(int x, int s) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | return x >> s; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | // Compute the 0-relative offset of some absolute value x of type T. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 123 | // This allows conversion of Addresses and integral types into |
| 124 | // 0-relative int offsets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 126 | inline intptr_t OffsetFrom(T x) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | return x - static_cast<T>(0); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | // Compute the absolute value of type T for some 0-relative offset x. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 132 | // This allows conversion of 0-relative int offsets into Addresses and |
| 133 | // integral types. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 135 | inline T AddressFrom(intptr_t x) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 136 | return static_cast<T>(static_cast<T>(0) + x); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
| 140 | // Return the largest multiple of m which is <= x. |
| 141 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 142 | inline T RoundDown(T x, intptr_t m) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | ASSERT(IsPowerOf2(m)); |
| 144 | return AddressFrom<T>(OffsetFrom(x) & -m); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | // Return the smallest multiple of m which is >= x. |
| 149 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 150 | inline T RoundUp(T x, intptr_t m) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 151 | return RoundDown<T>(static_cast<T>(x + m - 1), m); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 155 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 156 | int Compare(const T& a, const T& b) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 157 | if (a == b) |
| 158 | return 0; |
| 159 | else if (a < b) |
| 160 | return -1; |
| 161 | else |
| 162 | return 1; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 167 | int PointerValueCompare(const T* a, const T* b) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 168 | return Compare<T>(*a, *b); |
| 169 | } |
| 170 | |
| 171 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 172 | // Compare function to compare the object pointer value of two |
| 173 | // handlified objects. The handles are passed as pointers to the |
| 174 | // handles. |
| 175 | template<typename T> class Handle; // Forward declaration. |
| 176 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 177 | int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 178 | return Compare<T*>(*(*a), *(*b)); |
| 179 | } |
| 180 | |
| 181 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 182 | // Returns the smallest power of two which is >= x. If you pass in a |
| 183 | // number that is already a power of two, it is returned as is. |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 184 | // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., |
| 185 | // figure 3-3, page 48, where the function is called clp2. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 186 | inline uint32_t RoundUpToPowerOf2(uint32_t x) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 187 | ASSERT(x <= 0x80000000u); |
| 188 | x = x - 1; |
| 189 | x = x | (x >> 1); |
| 190 | x = x | (x >> 2); |
| 191 | x = x | (x >> 4); |
| 192 | x = x | (x >> 8); |
| 193 | x = x | (x >> 16); |
| 194 | return x + 1; |
| 195 | } |
| 196 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 197 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 198 | inline uint32_t RoundDownToPowerOf2(uint32_t x) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 199 | uint32_t rounded_up = RoundUpToPowerOf2(x); |
| 200 | if (rounded_up > x) return rounded_up >> 1; |
| 201 | return rounded_up; |
| 202 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 203 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 204 | |
| 205 | template <typename T, typename U> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 206 | inline bool IsAligned(T value, U alignment) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | return (value & (alignment - 1)) == 0; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | // Returns true if (addr + offset) is aligned. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 212 | inline bool IsAddressAligned(Address addr, |
| 213 | intptr_t alignment, |
| 214 | int offset = 0) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 215 | intptr_t offs = OffsetFrom(addr + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | return IsAligned(offs, alignment); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | // Returns the maximum of the two parameters. |
| 221 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 222 | T Max(T a, T b) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | return a < b ? b : a; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | // Returns the minimum of the two parameters. |
| 228 | template <typename T> |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 229 | T Min(T a, T b) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | return a < b ? a : b; |
| 231 | } |
| 232 | |
| 233 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 234 | inline int StrLength(const char* string) { |
| 235 | size_t length = strlen(string); |
| 236 | ASSERT(length == static_cast<size_t>(static_cast<int>(length))); |
| 237 | return static_cast<int>(length); |
| 238 | } |
| 239 | |
| 240 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | // ---------------------------------------------------------------------------- |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 242 | // BitField is a help template for encoding and decode bitfield with |
| 243 | // unsigned content. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | template<class T, int shift, int size> |
| 245 | class BitField { |
| 246 | public: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 247 | // A uint32_t mask of bit field. To use all bits of a uint32 in a |
| 248 | // bitfield without compiler warnings we have to compute 2^32 without |
| 249 | // using a shift count of 32. |
| 250 | static const uint32_t kMask = ((1U << shift) << size) - (1U << shift); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 251 | static const uint32_t kShift = shift; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 252 | static const uint32_t kSize = size; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 253 | |
| 254 | // Value for the field with all bits set. |
| 255 | static const T kMax = static_cast<T>((1U << size) - 1); |
| 256 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | // Tells whether the provided value fits into the bit field. |
| 258 | static bool is_valid(T value) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 259 | return (static_cast<uint32_t>(value) & ~static_cast<uint32_t>(kMax)) == 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // Returns a uint32_t with the bit field value encoded. |
| 263 | static uint32_t encode(T value) { |
| 264 | ASSERT(is_valid(value)); |
| 265 | return static_cast<uint32_t>(value) << shift; |
| 266 | } |
| 267 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 268 | // Returns a uint32_t with the bit field value updated. |
| 269 | static uint32_t update(uint32_t previous, T value) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 270 | return (previous & ~kMask) | encode(value); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 271 | } |
| 272 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 273 | // Extracts the bit field from the value. |
| 274 | static T decode(uint32_t value) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 275 | return static_cast<T>((value & kMask) >> shift); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 276 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | |
| 280 | // ---------------------------------------------------------------------------- |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 281 | // Hash function. |
| 282 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 283 | static const uint32_t kZeroHashSeed = 0; |
| 284 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 285 | // Thomas Wang, Integer Hash Functions. |
| 286 | // http://www.concentric.net/~Ttwang/tech/inthash.htm |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 287 | inline uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 288 | uint32_t hash = key; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 289 | hash = hash ^ seed; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 290 | hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; |
| 291 | hash = hash ^ (hash >> 12); |
| 292 | hash = hash + (hash << 2); |
| 293 | hash = hash ^ (hash >> 4); |
| 294 | hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11); |
| 295 | hash = hash ^ (hash >> 16); |
| 296 | return hash; |
| 297 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 298 | |
| 299 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 300 | inline uint32_t ComputeLongHash(uint64_t key) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 301 | uint64_t hash = key; |
| 302 | hash = ~hash + (hash << 18); // hash = (hash << 18) - hash - 1; |
| 303 | hash = hash ^ (hash >> 31); |
| 304 | hash = hash * 21; // hash = (hash + (hash << 2)) + (hash << 4); |
| 305 | hash = hash ^ (hash >> 11); |
| 306 | hash = hash + (hash << 6); |
| 307 | hash = hash ^ (hash >> 22); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 308 | return static_cast<uint32_t>(hash); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 312 | inline uint32_t ComputePointerHash(void* ptr) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 313 | return ComputeIntegerHash( |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 314 | static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr)), |
| 315 | v8::internal::kZeroHashSeed); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 319 | // ---------------------------------------------------------------------------- |
| 320 | // Miscellaneous |
| 321 | |
| 322 | // A static resource holds a static instance that can be reserved in |
| 323 | // a local scope using an instance of Access. Attempts to re-reserve |
| 324 | // the instance will cause an error. |
| 325 | template <typename T> |
| 326 | class StaticResource { |
| 327 | public: |
| 328 | StaticResource() : is_reserved_(false) {} |
| 329 | |
| 330 | private: |
| 331 | template <typename S> friend class Access; |
| 332 | T instance_; |
| 333 | bool is_reserved_; |
| 334 | }; |
| 335 | |
| 336 | |
| 337 | // Locally scoped access to a static resource. |
| 338 | template <typename T> |
| 339 | class Access { |
| 340 | public: |
| 341 | explicit Access(StaticResource<T>* resource) |
| 342 | : resource_(resource) |
| 343 | , instance_(&resource->instance_) { |
| 344 | ASSERT(!resource->is_reserved_); |
| 345 | resource->is_reserved_ = true; |
| 346 | } |
| 347 | |
| 348 | ~Access() { |
| 349 | resource_->is_reserved_ = false; |
| 350 | resource_ = NULL; |
| 351 | instance_ = NULL; |
| 352 | } |
| 353 | |
| 354 | T* value() { return instance_; } |
| 355 | T* operator -> () { return instance_; } |
| 356 | |
| 357 | private: |
| 358 | StaticResource<T>* resource_; |
| 359 | T* instance_; |
| 360 | }; |
| 361 | |
| 362 | |
| 363 | template <typename T> |
| 364 | class Vector { |
| 365 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 366 | Vector() : start_(NULL), length_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 367 | Vector(T* data, int length) : start_(data), length_(length) { |
| 368 | ASSERT(length == 0 || (length > 0 && data != NULL)); |
| 369 | } |
| 370 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 371 | static Vector<T> New(int length) { |
| 372 | return Vector<T>(NewArray<T>(length), length); |
| 373 | } |
| 374 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 375 | // Returns a vector using the same backing storage as this one, |
| 376 | // spanning from and including 'from', to but not including 'to'. |
| 377 | Vector<T> SubVector(int from, int to) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 378 | ASSERT(to <= length_); |
| 379 | ASSERT(from < to); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 380 | ASSERT(0 <= from); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 381 | return Vector<T>(start() + from, to - from); |
| 382 | } |
| 383 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 384 | // Returns the length of the vector. |
| 385 | int length() const { return length_; } |
| 386 | |
| 387 | // Returns whether or not the vector is empty. |
| 388 | bool is_empty() const { return length_ == 0; } |
| 389 | |
| 390 | // Returns the pointer to the start of the data in the vector. |
| 391 | T* start() const { return start_; } |
| 392 | |
| 393 | // Access individual vector elements - checks bounds in debug mode. |
| 394 | T& operator[](int index) const { |
| 395 | ASSERT(0 <= index && index < length_); |
| 396 | return start_[index]; |
| 397 | } |
| 398 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 399 | const T& at(int index) const { return operator[](index); } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 400 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 401 | T& first() { return start_[0]; } |
| 402 | |
| 403 | T& last() { return start_[length_ - 1]; } |
| 404 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | // Returns a clone of this vector with a new backing store. |
| 406 | Vector<T> Clone() const { |
| 407 | T* result = NewArray<T>(length_); |
| 408 | for (int i = 0; i < length_; i++) result[i] = start_[i]; |
| 409 | return Vector<T>(result, length_); |
| 410 | } |
| 411 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 412 | void Sort(int (*cmp)(const T*, const T*)) { |
| 413 | typedef int (*RawComparer)(const void*, const void*); |
| 414 | qsort(start(), |
| 415 | length(), |
| 416 | sizeof(T), |
| 417 | reinterpret_cast<RawComparer>(cmp)); |
| 418 | } |
| 419 | |
| 420 | void Sort() { |
| 421 | Sort(PointerValueCompare<T>); |
| 422 | } |
| 423 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 424 | void Truncate(int length) { |
| 425 | ASSERT(length <= length_); |
| 426 | length_ = length; |
| 427 | } |
| 428 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | // Releases the array underlying this vector. Once disposed the |
| 430 | // vector is empty. |
| 431 | void Dispose() { |
| 432 | DeleteArray(start_); |
| 433 | start_ = NULL; |
| 434 | length_ = 0; |
| 435 | } |
| 436 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 437 | inline Vector<T> operator+(int offset) { |
| 438 | ASSERT(offset < length_); |
| 439 | return Vector<T>(start_ + offset, length_ - offset); |
| 440 | } |
| 441 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 442 | // Factory method for creating empty vectors. |
| 443 | static Vector<T> empty() { return Vector<T>(NULL, 0); } |
| 444 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 445 | template<typename S> |
| 446 | static Vector<T> cast(Vector<S> input) { |
| 447 | return Vector<T>(reinterpret_cast<T*>(input.start()), |
| 448 | input.length() * sizeof(S) / sizeof(T)); |
| 449 | } |
| 450 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 451 | protected: |
| 452 | void set_start(T* start) { start_ = start; } |
| 453 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | private: |
| 455 | T* start_; |
| 456 | int length_; |
| 457 | }; |
| 458 | |
| 459 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 460 | // A pointer that can only be set once and doesn't allow NULL values. |
| 461 | template<typename T> |
| 462 | class SetOncePointer { |
| 463 | public: |
| 464 | SetOncePointer() : pointer_(NULL) { } |
| 465 | |
| 466 | bool is_set() const { return pointer_ != NULL; } |
| 467 | |
| 468 | T* get() const { |
| 469 | ASSERT(pointer_ != NULL); |
| 470 | return pointer_; |
| 471 | } |
| 472 | |
| 473 | void set(T* value) { |
| 474 | ASSERT(pointer_ == NULL && value != NULL); |
| 475 | pointer_ = value; |
| 476 | } |
| 477 | |
| 478 | private: |
| 479 | T* pointer_; |
| 480 | }; |
| 481 | |
| 482 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 483 | template <typename T, int kSize> |
| 484 | class EmbeddedVector : public Vector<T> { |
| 485 | public: |
| 486 | EmbeddedVector() : Vector<T>(buffer_, kSize) { } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 487 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 488 | explicit EmbeddedVector(T initial_value) : Vector<T>(buffer_, kSize) { |
| 489 | for (int i = 0; i < kSize; ++i) { |
| 490 | buffer_[i] = initial_value; |
| 491 | } |
| 492 | } |
| 493 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 494 | // When copying, make underlying Vector to reference our buffer. |
| 495 | EmbeddedVector(const EmbeddedVector& rhs) |
| 496 | : Vector<T>(rhs) { |
| 497 | memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize); |
| 498 | set_start(buffer_); |
| 499 | } |
| 500 | |
| 501 | EmbeddedVector& operator=(const EmbeddedVector& rhs) { |
| 502 | if (this == &rhs) return *this; |
| 503 | Vector<T>::operator=(rhs); |
| 504 | memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 505 | this->set_start(buffer_); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 506 | return *this; |
| 507 | } |
| 508 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 509 | private: |
| 510 | T buffer_[kSize]; |
| 511 | }; |
| 512 | |
| 513 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 514 | template <typename T> |
| 515 | class ScopedVector : public Vector<T> { |
| 516 | public: |
| 517 | explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { } |
| 518 | ~ScopedVector() { |
| 519 | DeleteArray(this->start()); |
| 520 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 521 | |
| 522 | private: |
| 523 | DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedVector); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 524 | }; |
| 525 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 526 | #define STATIC_ASCII_VECTOR(x) \ |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 527 | v8::internal::Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(x), \ |
| 528 | ARRAY_SIZE(x)-1) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 529 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 530 | inline Vector<const char> CStrVector(const char* data) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 531 | return Vector<const char>(data, StrLength(data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | } |
| 533 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 534 | inline Vector<const uint8_t> OneByteVector(const char* data, int length) { |
| 535 | return Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), length); |
| 536 | } |
| 537 | |
| 538 | inline Vector<const uint8_t> OneByteVector(const char* data) { |
| 539 | return OneByteVector(data, StrLength(data)); |
| 540 | } |
| 541 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 542 | inline Vector<char> MutableCStrVector(char* data) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 543 | return Vector<char>(data, StrLength(data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 544 | } |
| 545 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 546 | inline Vector<char> MutableCStrVector(char* data, int max) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 547 | int length = StrLength(data); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 548 | return Vector<char>(data, (length < max) ? length : max); |
| 549 | } |
| 550 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 551 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 552 | /* |
| 553 | * A class that collects values into a backing store. |
| 554 | * Specialized versions of the class can allow access to the backing store |
| 555 | * in different ways. |
| 556 | * There is no guarantee that the backing store is contiguous (and, as a |
| 557 | * consequence, no guarantees that consecutively added elements are adjacent |
| 558 | * in memory). The collector may move elements unless it has guaranteed not |
| 559 | * to. |
| 560 | */ |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 561 | template <typename T, int growth_factor = 2, int max_growth = 1 * MB> |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 562 | class Collector { |
| 563 | public: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 564 | explicit Collector(int initial_capacity = kMinCapacity) |
| 565 | : index_(0), size_(0) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 566 | current_chunk_ = Vector<T>::New(initial_capacity); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | virtual ~Collector() { |
| 570 | // Free backing store (in reverse allocation order). |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 571 | current_chunk_.Dispose(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 572 | for (int i = chunks_.length() - 1; i >= 0; i--) { |
| 573 | chunks_.at(i).Dispose(); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | // Add a single element. |
| 578 | inline void Add(T value) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 579 | if (index_ >= current_chunk_.length()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 580 | Grow(1); |
| 581 | } |
| 582 | current_chunk_[index_] = value; |
| 583 | index_++; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 584 | size_++; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | // Add a block of contiguous elements and return a Vector backed by the |
| 588 | // memory area. |
| 589 | // A basic Collector will keep this vector valid as long as the Collector |
| 590 | // is alive. |
| 591 | inline Vector<T> AddBlock(int size, T initial_value) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 592 | ASSERT(size > 0); |
| 593 | if (size > current_chunk_.length() - index_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 594 | Grow(size); |
| 595 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 596 | T* position = current_chunk_.start() + index_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 597 | index_ += size; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 598 | size_ += size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 599 | for (int i = 0; i < size; i++) { |
| 600 | position[i] = initial_value; |
| 601 | } |
| 602 | return Vector<T>(position, size); |
| 603 | } |
| 604 | |
| 605 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 606 | // Add a contiguous block of elements and return a vector backed |
| 607 | // by the added block. |
| 608 | // A basic Collector will keep this vector valid as long as the Collector |
| 609 | // is alive. |
| 610 | inline Vector<T> AddBlock(Vector<const T> source) { |
| 611 | if (source.length() > current_chunk_.length() - index_) { |
| 612 | Grow(source.length()); |
| 613 | } |
| 614 | T* position = current_chunk_.start() + index_; |
| 615 | index_ += source.length(); |
| 616 | size_ += source.length(); |
| 617 | for (int i = 0; i < source.length(); i++) { |
| 618 | position[i] = source[i]; |
| 619 | } |
| 620 | return Vector<T>(position, source.length()); |
| 621 | } |
| 622 | |
| 623 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 624 | // Write the contents of the collector into the provided vector. |
| 625 | void WriteTo(Vector<T> destination) { |
| 626 | ASSERT(size_ <= destination.length()); |
| 627 | int position = 0; |
| 628 | for (int i = 0; i < chunks_.length(); i++) { |
| 629 | Vector<T> chunk = chunks_.at(i); |
| 630 | for (int j = 0; j < chunk.length(); j++) { |
| 631 | destination[position] = chunk[j]; |
| 632 | position++; |
| 633 | } |
| 634 | } |
| 635 | for (int i = 0; i < index_; i++) { |
| 636 | destination[position] = current_chunk_[i]; |
| 637 | position++; |
| 638 | } |
| 639 | } |
| 640 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 641 | // Allocate a single contiguous vector, copy all the collected |
| 642 | // elements to the vector, and return it. |
| 643 | // The caller is responsible for freeing the memory of the returned |
| 644 | // vector (e.g., using Vector::Dispose). |
| 645 | Vector<T> ToVector() { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 646 | Vector<T> new_store = Vector<T>::New(size_); |
| 647 | WriteTo(new_store); |
| 648 | return new_store; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // Resets the collector to be empty. |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 652 | virtual void Reset(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 653 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 654 | // Total number of elements added to collector so far. |
| 655 | inline int size() { return size_; } |
| 656 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 657 | protected: |
| 658 | static const int kMinCapacity = 16; |
| 659 | List<Vector<T> > chunks_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 660 | Vector<T> current_chunk_; // Block of memory currently being written into. |
| 661 | int index_; // Current index in current chunk. |
| 662 | int size_; // Total number of elements in collector. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 663 | |
| 664 | // Creates a new current chunk, and stores the old chunk in the chunks_ list. |
| 665 | void Grow(int min_capacity) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 666 | ASSERT(growth_factor > 1); |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 667 | int new_capacity; |
| 668 | int current_length = current_chunk_.length(); |
| 669 | if (current_length < kMinCapacity) { |
| 670 | // The collector started out as empty. |
| 671 | new_capacity = min_capacity * growth_factor; |
| 672 | if (new_capacity < kMinCapacity) new_capacity = kMinCapacity; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 673 | } else { |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 674 | int growth = current_length * (growth_factor - 1); |
| 675 | if (growth > max_growth) { |
| 676 | growth = max_growth; |
| 677 | } |
| 678 | new_capacity = current_length + growth; |
| 679 | if (new_capacity < min_capacity) { |
| 680 | new_capacity = min_capacity + growth; |
| 681 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 682 | } |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 683 | NewChunk(new_capacity); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 684 | ASSERT(index_ + min_capacity <= current_chunk_.length()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | // Before replacing the current chunk, give a subclass the option to move |
| 688 | // some of the current data into the new chunk. The function may update |
| 689 | // the current index_ value to represent data no longer in the current chunk. |
| 690 | // Returns the initial index of the new chunk (after copied data). |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 691 | virtual void NewChunk(int new_capacity) { |
| 692 | Vector<T> new_chunk = Vector<T>::New(new_capacity); |
| 693 | if (index_ > 0) { |
| 694 | chunks_.Add(current_chunk_.SubVector(0, index_)); |
| 695 | } else { |
| 696 | current_chunk_.Dispose(); |
| 697 | } |
| 698 | current_chunk_ = new_chunk; |
| 699 | index_ = 0; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 700 | } |
| 701 | }; |
| 702 | |
| 703 | |
| 704 | /* |
| 705 | * A collector that allows sequences of values to be guaranteed to |
| 706 | * stay consecutive. |
| 707 | * If the backing store grows while a sequence is active, the current |
| 708 | * sequence might be moved, but after the sequence is ended, it will |
| 709 | * not move again. |
| 710 | * NOTICE: Blocks allocated using Collector::AddBlock(int) can move |
| 711 | * as well, if inside an active sequence where another element is added. |
| 712 | */ |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 713 | template <typename T, int growth_factor = 2, int max_growth = 1 * MB> |
| 714 | class SequenceCollector : public Collector<T, growth_factor, max_growth> { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 715 | public: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 716 | explicit SequenceCollector(int initial_capacity) |
| 717 | : Collector<T, growth_factor, max_growth>(initial_capacity), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 718 | sequence_start_(kNoSequence) { } |
| 719 | |
| 720 | virtual ~SequenceCollector() {} |
| 721 | |
| 722 | void StartSequence() { |
| 723 | ASSERT(sequence_start_ == kNoSequence); |
| 724 | sequence_start_ = this->index_; |
| 725 | } |
| 726 | |
| 727 | Vector<T> EndSequence() { |
| 728 | ASSERT(sequence_start_ != kNoSequence); |
| 729 | int sequence_start = sequence_start_; |
| 730 | sequence_start_ = kNoSequence; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 731 | if (sequence_start == this->index_) return Vector<T>(); |
| 732 | return this->current_chunk_.SubVector(sequence_start, this->index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | // Drops the currently added sequence, and all collected elements in it. |
| 736 | void DropSequence() { |
| 737 | ASSERT(sequence_start_ != kNoSequence); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 738 | int sequence_length = this->index_ - sequence_start_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 739 | this->index_ = sequence_start_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 740 | this->size_ -= sequence_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 741 | sequence_start_ = kNoSequence; |
| 742 | } |
| 743 | |
| 744 | virtual void Reset() { |
| 745 | sequence_start_ = kNoSequence; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 746 | this->Collector<T, growth_factor, max_growth>::Reset(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | private: |
| 750 | static const int kNoSequence = -1; |
| 751 | int sequence_start_; |
| 752 | |
| 753 | // Move the currently active sequence to the new chunk. |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 754 | virtual void NewChunk(int new_capacity) { |
| 755 | if (sequence_start_ == kNoSequence) { |
| 756 | // Fall back on default behavior if no sequence has been started. |
| 757 | this->Collector<T, growth_factor, max_growth>::NewChunk(new_capacity); |
| 758 | return; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 759 | } |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 760 | int sequence_length = this->index_ - sequence_start_; |
| 761 | Vector<T> new_chunk = Vector<T>::New(sequence_length + new_capacity); |
| 762 | ASSERT(sequence_length < new_chunk.length()); |
| 763 | for (int i = 0; i < sequence_length; i++) { |
| 764 | new_chunk[i] = this->current_chunk_[sequence_start_ + i]; |
| 765 | } |
| 766 | if (sequence_start_ > 0) { |
| 767 | this->chunks_.Add(this->current_chunk_.SubVector(0, sequence_start_)); |
| 768 | } else { |
| 769 | this->current_chunk_.Dispose(); |
| 770 | } |
| 771 | this->current_chunk_ = new_chunk; |
| 772 | this->index_ = sequence_length; |
| 773 | sequence_start_ = 0; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 774 | } |
| 775 | }; |
| 776 | |
| 777 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 778 | // Compare ASCII/16bit chars to ASCII/16bit chars. |
| 779 | template <typename lchar, typename rchar> |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 780 | inline int CompareCharsUnsigned(const lchar* lhs, |
| 781 | const rchar* rhs, |
| 782 | int chars) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 783 | const lchar* limit = lhs + chars; |
| 784 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 785 | if (sizeof(*lhs) == sizeof(*rhs)) { |
| 786 | // Number of characters in a uintptr_t. |
| 787 | static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT |
| 788 | while (lhs <= limit - kStepSize) { |
| 789 | if (*reinterpret_cast<const uintptr_t*>(lhs) != |
| 790 | *reinterpret_cast<const uintptr_t*>(rhs)) { |
| 791 | break; |
| 792 | } |
| 793 | lhs += kStepSize; |
| 794 | rhs += kStepSize; |
| 795 | } |
| 796 | } |
| 797 | #endif |
| 798 | while (lhs < limit) { |
| 799 | int r = static_cast<int>(*lhs) - static_cast<int>(*rhs); |
| 800 | if (r != 0) return r; |
| 801 | ++lhs; |
| 802 | ++rhs; |
| 803 | } |
| 804 | return 0; |
| 805 | } |
| 806 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 807 | template<typename lchar, typename rchar> |
| 808 | inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { |
| 809 | ASSERT(sizeof(lchar) <= 2); |
| 810 | ASSERT(sizeof(rchar) <= 2); |
| 811 | if (sizeof(lchar) == 1) { |
| 812 | if (sizeof(rchar) == 1) { |
| 813 | return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(lhs), |
| 814 | reinterpret_cast<const uint8_t*>(rhs), |
| 815 | chars); |
| 816 | } else { |
| 817 | return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(lhs), |
| 818 | reinterpret_cast<const uint16_t*>(rhs), |
| 819 | chars); |
| 820 | } |
| 821 | } else { |
| 822 | if (sizeof(rchar) == 1) { |
| 823 | return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(lhs), |
| 824 | reinterpret_cast<const uint8_t*>(rhs), |
| 825 | chars); |
| 826 | } else { |
| 827 | return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(lhs), |
| 828 | reinterpret_cast<const uint16_t*>(rhs), |
| 829 | chars); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 834 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 835 | // Calculate 10^exponent. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 836 | inline int TenToThe(int exponent) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 837 | ASSERT(exponent <= 9); |
| 838 | ASSERT(exponent >= 1); |
| 839 | int answer = 10; |
| 840 | for (int i = 1; i < exponent; i++) answer *= 10; |
| 841 | return answer; |
| 842 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 843 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 844 | |
| 845 | // The type-based aliasing rule allows the compiler to assume that pointers of |
| 846 | // different types (for some definition of different) never alias each other. |
| 847 | // Thus the following code does not work: |
| 848 | // |
| 849 | // float f = foo(); |
| 850 | // int fbits = *(int*)(&f); |
| 851 | // |
| 852 | // The compiler 'knows' that the int pointer can't refer to f since the types |
| 853 | // don't match, so the compiler may cache f in a register, leaving random data |
| 854 | // in fbits. Using C++ style casts makes no difference, however a pointer to |
| 855 | // char data is assumed to alias any other pointer. This is the 'memcpy |
| 856 | // exception'. |
| 857 | // |
| 858 | // Bit_cast uses the memcpy exception to move the bits from a variable of one |
| 859 | // type of a variable of another type. Of course the end result is likely to |
| 860 | // be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005) |
| 861 | // will completely optimize BitCast away. |
| 862 | // |
| 863 | // There is an additional use for BitCast. |
| 864 | // Recent gccs will warn when they see casts that may result in breakage due to |
| 865 | // the type-based aliasing rule. If you have checked that there is no breakage |
| 866 | // you can use BitCast to cast one pointer type to another. This confuses gcc |
| 867 | // enough that it can no longer see that you have cast one pointer type to |
| 868 | // another thus avoiding the warning. |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 869 | |
| 870 | // We need different implementations of BitCast for pointer and non-pointer |
| 871 | // values. We use partial specialization of auxiliary struct to work around |
| 872 | // issues with template functions overloading. |
| 873 | template <class Dest, class Source> |
| 874 | struct BitCastHelper { |
| 875 | STATIC_ASSERT(sizeof(Dest) == sizeof(Source)); |
| 876 | |
| 877 | INLINE(static Dest cast(const Source& source)) { |
| 878 | Dest dest; |
| 879 | memcpy(&dest, &source, sizeof(dest)); |
| 880 | return dest; |
| 881 | } |
| 882 | }; |
| 883 | |
| 884 | template <class Dest, class Source> |
| 885 | struct BitCastHelper<Dest, Source*> { |
| 886 | INLINE(static Dest cast(Source* source)) { |
| 887 | return BitCastHelper<Dest, uintptr_t>:: |
| 888 | cast(reinterpret_cast<uintptr_t>(source)); |
| 889 | } |
| 890 | }; |
| 891 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 892 | template <class Dest, class Source> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 893 | INLINE(Dest BitCast(const Source& source)); |
| 894 | |
| 895 | template <class Dest, class Source> |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 896 | inline Dest BitCast(const Source& source) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 897 | return BitCastHelper<Dest, Source>::cast(source); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 898 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 899 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 900 | |
| 901 | template<typename ElementType, int NumElements> |
| 902 | class EmbeddedContainer { |
| 903 | public: |
| 904 | EmbeddedContainer() : elems_() { } |
| 905 | |
jkummerow@chromium.org | c195667 | 2012-10-11 15:57:38 +0000 | [diff] [blame] | 906 | int length() const { return NumElements; } |
| 907 | const ElementType& operator[](int i) const { |
| 908 | ASSERT(i < length()); |
| 909 | return elems_[i]; |
| 910 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 911 | ElementType& operator[](int i) { |
| 912 | ASSERT(i < length()); |
| 913 | return elems_[i]; |
| 914 | } |
| 915 | |
| 916 | private: |
| 917 | ElementType elems_[NumElements]; |
| 918 | }; |
| 919 | |
| 920 | |
| 921 | template<typename ElementType> |
| 922 | class EmbeddedContainer<ElementType, 0> { |
| 923 | public: |
jkummerow@chromium.org | c195667 | 2012-10-11 15:57:38 +0000 | [diff] [blame] | 924 | int length() const { return 0; } |
| 925 | const ElementType& operator[](int i) const { |
| 926 | UNREACHABLE(); |
| 927 | static ElementType t = 0; |
| 928 | return t; |
| 929 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 930 | ElementType& operator[](int i) { |
| 931 | UNREACHABLE(); |
| 932 | static ElementType t = 0; |
| 933 | return t; |
| 934 | } |
| 935 | }; |
| 936 | |
| 937 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 938 | // Helper class for building result strings in a character buffer. The |
| 939 | // purpose of the class is to use safe operations that checks the |
| 940 | // buffer bounds on all operations in debug mode. |
| 941 | // This simple base class does not allow formatted output. |
| 942 | class SimpleStringBuilder { |
| 943 | public: |
| 944 | // Create a string builder with a buffer of the given size. The |
| 945 | // buffer is allocated through NewArray<char> and must be |
| 946 | // deallocated by the caller of Finalize(). |
| 947 | explicit SimpleStringBuilder(int size); |
| 948 | |
| 949 | SimpleStringBuilder(char* buffer, int size) |
| 950 | : buffer_(buffer, size), position_(0) { } |
| 951 | |
| 952 | ~SimpleStringBuilder() { if (!is_finalized()) Finalize(); } |
| 953 | |
| 954 | int size() const { return buffer_.length(); } |
| 955 | |
| 956 | // Get the current position in the builder. |
| 957 | int position() const { |
| 958 | ASSERT(!is_finalized()); |
| 959 | return position_; |
| 960 | } |
| 961 | |
| 962 | // Reset the position. |
| 963 | void Reset() { position_ = 0; } |
| 964 | |
| 965 | // Add a single character to the builder. It is not allowed to add |
| 966 | // 0-characters; use the Finalize() method to terminate the string |
| 967 | // instead. |
| 968 | void AddCharacter(char c) { |
| 969 | ASSERT(c != '\0'); |
| 970 | ASSERT(!is_finalized() && position_ < buffer_.length()); |
| 971 | buffer_[position_++] = c; |
| 972 | } |
| 973 | |
| 974 | // Add an entire string to the builder. Uses strlen() internally to |
| 975 | // compute the length of the input string. |
| 976 | void AddString(const char* s); |
| 977 | |
| 978 | // Add the first 'n' characters of the given string 's' to the |
| 979 | // builder. The input string must have enough characters. |
| 980 | void AddSubstring(const char* s, int n); |
| 981 | |
| 982 | // Add character padding to the builder. If count is non-positive, |
| 983 | // nothing is added to the builder. |
| 984 | void AddPadding(char c, int count); |
| 985 | |
| 986 | // Add the decimal representation of the value. |
| 987 | void AddDecimalInteger(int value); |
| 988 | |
| 989 | // Finalize the string by 0-terminating it and returning the buffer. |
| 990 | char* Finalize(); |
| 991 | |
| 992 | protected: |
| 993 | Vector<char> buffer_; |
| 994 | int position_; |
| 995 | |
| 996 | bool is_finalized() const { return position_ < 0; } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 997 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 998 | private: |
| 999 | DISALLOW_IMPLICIT_CONSTRUCTORS(SimpleStringBuilder); |
| 1000 | }; |
| 1001 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1002 | |
| 1003 | // A poor man's version of STL's bitset: A bit set of enums E (without explicit |
| 1004 | // values), fitting into an integral type T. |
| 1005 | template <class E, class T = int> |
| 1006 | class EnumSet { |
| 1007 | public: |
| 1008 | explicit EnumSet(T bits = 0) : bits_(bits) {} |
| 1009 | bool IsEmpty() const { return bits_ == 0; } |
| 1010 | bool Contains(E element) const { return (bits_ & Mask(element)) != 0; } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1011 | bool ContainsAnyOf(const EnumSet& set) const { |
| 1012 | return (bits_ & set.bits_) != 0; |
| 1013 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1014 | void Add(E element) { bits_ |= Mask(element); } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1015 | void Add(const EnumSet& set) { bits_ |= set.bits_; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1016 | void Remove(E element) { bits_ &= ~Mask(element); } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1017 | void Remove(const EnumSet& set) { bits_ &= ~set.bits_; } |
| 1018 | void RemoveAll() { bits_ = 0; } |
| 1019 | void Intersect(const EnumSet& set) { bits_ &= set.bits_; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1020 | T ToIntegral() const { return bits_; } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1021 | bool operator==(const EnumSet& set) { return bits_ == set.bits_; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1022 | |
| 1023 | private: |
| 1024 | T Mask(E element) const { |
| 1025 | // The strange typing in ASSERT is necessary to avoid stupid warnings, see: |
| 1026 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680 |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1027 | ASSERT(static_cast<int>(element) < static_cast<int>(sizeof(T) * CHAR_BIT)); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1028 | return 1 << element; |
| 1029 | } |
| 1030 | |
| 1031 | T bits_; |
| 1032 | }; |
| 1033 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1034 | |
| 1035 | class TypeFeedbackId { |
| 1036 | public: |
| 1037 | explicit TypeFeedbackId(int id) : id_(id) { } |
| 1038 | int ToInt() const { return id_; } |
| 1039 | |
| 1040 | static TypeFeedbackId None() { return TypeFeedbackId(kNoneId); } |
| 1041 | bool IsNone() const { return id_ == kNoneId; } |
| 1042 | |
| 1043 | private: |
| 1044 | static const int kNoneId = -1; |
| 1045 | |
| 1046 | int id_; |
| 1047 | }; |
| 1048 | |
| 1049 | |
| 1050 | class BailoutId { |
| 1051 | public: |
| 1052 | explicit BailoutId(int id) : id_(id) { } |
| 1053 | int ToInt() const { return id_; } |
| 1054 | |
| 1055 | static BailoutId None() { return BailoutId(kNoneId); } |
| 1056 | static BailoutId FunctionEntry() { return BailoutId(kFunctionEntryId); } |
| 1057 | static BailoutId Declarations() { return BailoutId(kDeclarationsId); } |
| 1058 | static BailoutId FirstUsable() { return BailoutId(kFirstUsableId); } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1059 | static BailoutId StubEntry() { return BailoutId(kStubEntryId); } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1060 | |
| 1061 | bool IsNone() const { return id_ == kNoneId; } |
| 1062 | bool operator==(const BailoutId& other) const { return id_ == other.id_; } |
| 1063 | |
| 1064 | private: |
| 1065 | static const int kNoneId = -1; |
| 1066 | |
| 1067 | // Using 0 could disguise errors. |
| 1068 | static const int kFunctionEntryId = 2; |
| 1069 | |
| 1070 | // This AST id identifies the point after the declarations have been visited. |
| 1071 | // We need it to capture the environment effects of declarations that emit |
| 1072 | // code (function declarations). |
| 1073 | static const int kDeclarationsId = 3; |
| 1074 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1075 | // Every FunctionState starts with this id. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1076 | static const int kFirstUsableId = 4; |
| 1077 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1078 | // Every compiled stub starts with this id. |
| 1079 | static const int kStubEntryId = 5; |
| 1080 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1081 | int id_; |
| 1082 | }; |
| 1083 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1084 | } } // namespace v8::internal |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1085 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1086 | #endif // V8_UTILS_H_ |