46 #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
90 static const int msb4[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
104 return nibble + msb4[x];
119 template <
typename T>
121 return x -
static_cast<T>(0);
128 template <
typename T>
130 return static_cast<T>(
static_cast<T>(0) + x);
135 template <
typename T>
143 template <
typename T>
145 return RoundDown<T>(
static_cast<T>(x + m - 1), m);
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));
160 template <
typename T>
171 template <
typename T>
173 return Compare<T>(*a, *b);
180 template<
typename T>
class Handle;
181 template <
typename T>
183 return Compare<T*>(*(*a), *(*b));
205 if (rounded_up > x)
return rounded_up >> 1;
210 template <
typename T,
typename U>
212 return (value & (alignment - 1)) == 0;
226 template <
typename T>
228 return a < b ? b : a;
233 template <
typename T>
235 return a < b ? a : b;
240 template <
typename T>
242 return a < 0 ? -a : a;
247 template <
typename T>
249 return a < 0 ? a : -a;
254 size_t length = strlen(
string);
255 ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
256 return static_cast<int>(length);
270 template<
class T,
int shift,
int size,
class U>
286 return (static_cast<U>(value) & ~static_cast<U>(
kMax)) == 0;
292 return static_cast<U>(value) <<
shift;
307 template<
class T,
int shift,
int size>
311 template<
class T,
int shift,
int size>
318 static const uint32_t kZeroHashSeed = 0;
325 hash = ~hash + (hash << 15);
326 hash = hash ^ (hash >> 12);
327 hash = hash + (hash << 2);
328 hash = hash ^ (hash >> 4);
330 hash = hash ^ (hash >> 16);
337 hash = ~hash + (hash << 18);
338 hash = hash ^ (hash >> 31);
340 hash = hash ^ (hash >> 11);
341 hash = hash + (hash << 6);
342 hash = hash ^ (hash >> 22);
343 return static_cast<uint32_t
>(hash);
349 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr)),
350 v8::internal::kZeroHashSeed);
360 template <
typename T>
366 template <
typename S>
friend class Access;
373 template <
typename T>
377 : resource_(resource)
378 , instance_(&resource->instance_) {
379 ASSERT(!resource->is_reserved_);
380 resource->is_reserved_ =
true;
384 resource_->is_reserved_ =
false;
398 template <
typename T>
403 ASSERT(length == 0 || (length > 0 && data !=
NULL));
430 ASSERT(0 <= index && index < length_);
431 return start_[index];
438 T&
last() {
return start_[length_ - 1]; }
442 T* result = NewArray<T>(length_);
443 for (
int i = 0; i < length_; i++) result[i] = start_[i];
447 void Sort(
int (*cmp)(
const T*,
const T*)) {
456 ASSERT(length <= length_);
470 return Vector<T>(start_ + offset, length_ - offset);
479 input.
length() *
sizeof(
S) /
sizeof(
T));
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;
497 int (*cmp_)(
const T*,
const T*);
525 template <
typename T,
int kSize>
531 for (
int i = 0; i < kSize; ++i) {
532 buffer_[i] = initial_value;
540 memcpy(buffer_, rhs.buffer_,
sizeof(
T) * kSize);
545 if (
this == &rhs)
return *
this;
548 memcpy(buffer_, rhs.buffer_,
sizeof(
T) * kSize);
558 template <
typename T>
570 #define STATIC_ASCII_VECTOR(x) \
571 v8::internal::Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(x), \
592 return Vector<char>(data, (length < max) ? length : max);
605 template <
typename T,
int growth_factor = 2,
int max_growth = 1 * MB>
616 for (
int i =
chunks_.length() - 1; i >= 0; i--) {
643 for (
int i = 0; i <
size; i++) {
644 position[i] = initial_value;
661 for (
int i = 0; i < source.
length(); i++) {
662 position[i] = source[i];
672 for (
int i = 0; i <
chunks_.length(); i++) {
674 for (
int j = 0; j < chunk.
length(); j++) {
675 destination[position] = chunk[j];
679 for (
int i = 0; i <
index_; i++) {
696 virtual void Reset();
710 ASSERT(growth_factor > 1);
715 new_capacity = min_capacity * growth_factor;
718 int growth = current_length * (growth_factor - 1);
719 if (growth > max_growth) {
722 new_capacity = current_length + growth;
723 if (new_capacity < min_capacity) {
724 new_capacity = min_capacity + growth;
757 template <
typename T,
int growth_factor = 2,
int max_growth = 1 * MB>
761 :
Collector<
T, growth_factor, max_growth>(initial_capacity),
762 sequence_start_(kNoSequence) { }
767 ASSERT(sequence_start_ == kNoSequence);
768 sequence_start_ = this->
index_;
772 ASSERT(sequence_start_ != kNoSequence);
773 int sequence_start = sequence_start_;
774 sequence_start_ = kNoSequence;
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;
789 sequence_start_ = kNoSequence;
794 static const int kNoSequence = -1;
798 virtual void NewChunk(
int new_capacity) {
799 if (sequence_start_ == kNoSequence) {
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++) {
810 if (sequence_start_ > 0) {
816 this->
index_ = sequence_length;
823 template <
typename l
char,
typename r
char>
827 const lchar* limit = lhs + chars;
828 #ifdef V8_HOST_CAN_READ_UNALIGNED
829 if (
sizeof(*lhs) ==
sizeof(*rhs)) {
831 static const int kStepSize =
sizeof(uintptr_t) /
sizeof(*lhs);
832 while (lhs <= limit - kStepSize) {
833 if (*reinterpret_cast<const uintptr_t*>(lhs) !=
834 *
reinterpret_cast<const uintptr_t*
>(rhs)) {
842 while (lhs < limit) {
843 int r =
static_cast<int>(*lhs) -
static_cast<int>(*rhs);
844 if (r != 0)
return r;
851 template<
typename l
char,
typename r
char>
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) {
858 reinterpret_cast<const uint8_t*>(rhs),
862 reinterpret_cast<const uint16_t*>(rhs),
866 if (
sizeof(rchar) == 1) {
868 reinterpret_cast<const uint8_t*>(rhs),
872 reinterpret_cast<const uint16_t*>(rhs),
884 for (
int i = 1; i < exponent; i++) answer *= 10;
917 template <
class Dest,
class Source>
921 INLINE(
static Dest cast(
const Source& source)) {
924 memcpy(&dest, &source,
sizeof(dest));
929 template <
class Dest,
class Source>
931 INLINE(
static Dest cast(Source* source)) {
933 cast(reinterpret_cast<uintptr_t>(source));
937 template <
class Dest,
class Source>
940 template <
class Dest,
class Source>
946 template<
typename ElementType,
int NumElements>
951 int length()
const {
return NumElements; }
962 ElementType elems_[NumElements];
966 template<
typename ElementType>
972 static ElementType t = 0;
977 static ElementType t = 0;
1050 template <
class E,
class T =
int>
1055 bool Contains(E element)
const {
return (bits_ & Mask(element)) != 0; }
1057 return (bits_ & set.bits_) != 0;
1059 void Add(E element) { bits_ |= Mask(element); }
1061 void Remove(E element) { bits_ &= ~Mask(element); }
1073 T Mask(E element)
const {
1076 ASSERT(static_cast<int>(element) < static_cast<int>(
sizeof(
T) * CHAR_BIT));
1077 return static_cast<T>(1) << element;
1085 return (x >> lsb) & ((1 << (1 + msb - lsb)) - 1);
1089 return (x >> lsb) & ((
static_cast<uint64_t
>(1) << (1 + msb - lsb)) - 1);
1093 return (x << (31 - msb)) >> (lsb + 31 - msb);
1098 return (x << (63 - msb)) >> (lsb + 63 - msb);
1103 ASSERT((0 < n) && (n < 64));
1104 int64_t limit =
static_cast<int64_t
>(1) << (n - 1);
1105 return (-limit <= x) && (x < limit);
1116 return (x & ((static_cast<T>(1) << n) - 1));
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)
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
1150 bool IsNone()
const {
return id_ == kNoneId; }
1153 static const int kNoneId = -1;
1170 bool IsNone()
const {
return id_ == kNoneId; }
1175 static const int kNoneId = -1;
1178 static const int kFunctionEntryId = 2;
1183 static const int kDeclarationsId = 3;
1186 static const int kFirstUsableId = 4;
1189 static const int kStubEntryId = 5;
1211 #endif // V8_UTILS_H_
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
reverse_iterator rbegin()
bool operator==(const BailoutId &other) const
ElementType & operator[](int i)
T truncate_to_intn(T x, unsigned n)
#define SLOW_ASSERT(condition)
Vector(T *data, int length)
bool IsAddressAligned(Address addr, intptr_t alignment, int offset=0)
Vector< T > AddBlock(Vector< const T > source)
ElementType & operator[](int i)
uint32_t RoundDownToPowerOf2(uint32_t x)
void AddString(const char *s)
int signed_bitextract_64(int msb, int lsb, int x)
void Sort(int(*cmp)(const T *, const T *))
bool operator!=(const EnumSet &set)
int CompareCharsUnsigned(const lchar *lhs, const rchar *rhs, int chars)
static TypeFeedbackId None()
#define DECLARE_IS_INT_N(N)
virtual ~SequenceCollector()
const ElementType & operator[](int i) const
ContainerPointerWrapper(C *container)
Vector< char > MutableCStrVector(char *data)
static BailoutId StubEntry()
Access(StaticResource< T > *resource)
void Grow(int min_capacity)
Vector< T > SubVector(int from, int to)
SimpleStringBuilder(char *buffer, int size)
#define ASSERT(condition)
T & operator[](int index) const
const ElementType & operator[](int i) const
STATIC_ASSERT(sizeof(Dest)==sizeof(Source))
bool ContainsAnyOf(const EnumSet &set) const
void Add(const EnumSet &set)
int WhichPowerOf2(uint32_t x)
SimpleStringBuilder(int size)
int HandleObjectPointerCompare(const Handle< T > *a, const Handle< T > *b)
C::reverse_iterator reverse_iterator
bool is_intn(int64_t x, unsigned n)
SequenceCollector(int initial_capacity)
uint32_t ComputePointerHash(void *ptr)
INLINE(static Dest cast(Source *source))
int32_t WhichPowerOf2Abs(int32_t x)
Vector< T > AddBlock(int size, T initial_value)
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
EmbeddedVector(T initial_value)
bool is_finalized() const
static U update(U previous, T value)
#define DECLARE_TRUNCATE_TO_INT_N(N)
static BailoutId Declarations()
T * NewArray(size_t size)
int Compare(const T &a, const T &b)
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
bool IsAligned(T value, U alignment)
INLINE(static Dest cast(const Source &source))
EmbeddedVector(const EmbeddedVector &rhs)
void Intersect(const EnumSet &set)
T RoundUp(T x, intptr_t m)
void Remove(const EnumSet &set)
T AlignUp(T pointer, size_t alignment)
int CompareChars(const lchar *lhs, const rchar *rhs, int chars)
int TenToThe(int exponent)
void Truncate(int length)
static BailoutId FunctionEntry()
static Vector< T > New(int length)
#define DECLARE_IS_UINT_N(N)
int32_t signed_bitextract_32(int msb, int lsb, int32_t x)
Vector< const char > CStrVector(const char *data)
int StrLength(const char *string)
List< Vector< T > > chunks_
#define T(name, string, precedence)
Vector< T > Clone() const
int PointerValueCompare(const T *a, const T *b)
int ArithmeticShiftRight(int x, int s)
Vector< const uint8_t > OneByteVector(const char *data, int length)
#define INT_1_TO_63_LIST(V)
Vector< T > EndSequence()
static BailoutId FirstUsable()
void AddSubstring(const char *s, int n)
uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed)
bool Contains(E element) const
void AddCharacter(char c)
#define IS_POWER_OF_TWO(x)
T AddressFrom(intptr_t x)
INLINE(static HeapObject *EnsureDoubleAligned(Heap *heap, HeapObject *object, int size))
static Vector< T > cast(Vector< S > input)
uint32_t ComputeLongHash(uint64_t key)
static bool is_valid(T value)
bool operator!=(const BailoutId &other) const
Collector(int initial_capacity=kMinCapacity)
#define ASSERT_EQ(v1, v2)
virtual void NewChunk(int new_capacity)
void AddDecimalInteger(int value)
T RoundDown(T x, intptr_t m)
Vector< T > current_chunk_
static Vector< T > empty()
Vector< T > operator+(int offset)
const T & at(int index) const
void AddPadding(char c, int count)
bool operator==(const EnumSet &set)
static const int kMinCapacity
void WriteTo(Vector< T > destination)
int MostSignificantBit(uint32_t x)
Dest BitCast(const Source &source)
void DeleteArray(T *array)
uint32_t unsigned_bitextract_32(int msb, int lsb, uint32_t x)
EnumSet< E, T > operator|(const EnumSet &set) const
uint32_t RoundUpToPowerOf2(uint32_t x)
EmbeddedVector & operator=(const EmbeddedVector &rhs)
uint64_t unsigned_bitextract_64(int msb, int lsb, uint64_t x)
bool is_uintn(int64_t x, unsigned n)