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