45 #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
125 template <
typename T>
127 return x -
static_cast<T>(0);
134 template <
typename T>
136 return static_cast<T>(
static_cast<T>(0) + x);
141 template <
typename T>
149 template <
typename T>
151 return RoundDown<T>(
static_cast<T>(x + m - 1), m);
155 template <
typename T>
166 template <
typename T>
168 return Compare<T>(*a, *b);
175 template<
typename T>
class Handle;
176 template <
typename T>
178 return Compare<T*>(*(*a), *(*b));
200 if (rounded_up > x)
return rounded_up >> 1;
205 template <
typename T,
typename U>
207 return (value & (alignment - 1)) == 0;
221 template <
typename T>
223 return a < b ? b : a;
228 template <
typename T>
230 return a < b ? a : b;
235 size_t length = strlen(
string);
236 ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
237 return static_cast<int>(length);
244 template<
class T,
int shift,
int size>
250 static const uint32_t
kMask = ((1
U << shift) << size) - (1
U << shift);
253 static const T kMax =
static_cast<T>((1
U << size) - 1);
257 return (static_cast<uint32_t>(value) & ~static_cast<uint32_t>(
kMax)) == 0;
263 return static_cast<uint32_t
>(value) << shift;
267 static uint32_t
update(uint32_t previous,
T value) {
273 return static_cast<T>((value &
kMask) >> shift);
281 static const uint32_t kZeroHashSeed = 0;
288 hash = ~hash + (hash << 15);
289 hash = hash ^ (hash >> 12);
290 hash = hash + (hash << 2);
291 hash = hash ^ (hash >> 4);
293 hash = hash ^ (hash >> 16);
300 hash = ~hash + (hash << 18);
301 hash = hash ^ (hash >> 31);
303 hash = hash ^ (hash >> 11);
304 hash = hash + (hash << 6);
305 hash = hash ^ (hash >> 22);
306 return (uint32_t) hash;
312 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr)),
313 v8::internal::kZeroHashSeed);
323 template <
typename T>
329 template <
typename S>
friend class Access;
336 template <
typename T>
340 : resource_(resource)
341 , instance_(&resource->instance_) {
342 ASSERT(!resource->is_reserved_);
343 resource->is_reserved_ =
true;
347 resource_->is_reserved_ =
false;
361 template <
typename T>
366 ASSERT(length == 0 || (length > 0 && data !=
NULL));
393 ASSERT(0 <= index && index < length_);
394 return start_[index];
401 T&
last() {
return start_[length_ - 1]; }
405 T* result = NewArray<T>(length_);
406 for (
int i = 0; i < length_; i++) result[i] = start_[i];
410 void Sort(
int (*cmp)(
const T*,
const T*)) {
411 typedef int (*RawComparer)(
const void*,
const void*);
415 reinterpret_cast<RawComparer>(cmp));
419 Sort(PointerValueCompare<T>);
423 ASSERT(length <= length_);
437 return Vector<T>(start_ + offset, length_ - offset);
446 input.
length() *
sizeof(
S) /
sizeof(
T));
481 template <
typename T,
int kSize>
487 for (
int i = 0; i < kSize; ++i) {
488 buffer_[i] = initial_value;
495 memcpy(buffer_, rhs.buffer_,
sizeof(
T) * kSize);
500 if (
this == &rhs)
return *
this;
502 memcpy(buffer_, rhs.buffer_,
sizeof(
T) * kSize);
512 template <
typename T>
535 return Vector<char>(data, (length < max) ? length : max);
548 template <
typename T,
int growth_factor = 2,
int max_growth = 1 * MB>
559 for (
int i =
chunks_.length() - 1; i >= 0; i--) {
586 for (
int i = 0; i <
size; i++) {
587 position[i] = initial_value;
604 for (
int i = 0; i < source.
length(); i++) {
605 position[i] = source[i];
615 for (
int i = 0; i <
chunks_.length(); i++) {
617 for (
int j = 0; j < chunk.
length(); j++) {
618 destination[position] = chunk[j];
622 for (
int i = 0; i <
index_; i++) {
639 virtual void Reset();
653 ASSERT(growth_factor > 1);
658 new_capacity = min_capacity * growth_factor;
661 int growth = current_length * (growth_factor - 1);
662 if (growth > max_growth) {
665 new_capacity = current_length + growth;
666 if (new_capacity < min_capacity) {
667 new_capacity = min_capacity + growth;
700 template <
typename T,
int growth_factor = 2,
int max_growth = 1 * MB>
704 :
Collector<
T, growth_factor, max_growth>(initial_capacity),
705 sequence_start_(kNoSequence) { }
710 ASSERT(sequence_start_ == kNoSequence);
711 sequence_start_ = this->
index_;
715 ASSERT(sequence_start_ != kNoSequence);
716 int sequence_start = sequence_start_;
717 sequence_start_ = kNoSequence;
724 ASSERT(sequence_start_ != kNoSequence);
725 int sequence_length = this->
index_ - sequence_start_;
726 this->
index_ = sequence_start_;
727 this->
size_ -= sequence_length;
728 sequence_start_ = kNoSequence;
732 sequence_start_ = kNoSequence;
737 static const int kNoSequence = -1;
741 virtual void NewChunk(
int new_capacity) {
742 if (sequence_start_ == kNoSequence) {
747 int sequence_length = this->
index_ - sequence_start_;
748 Vector<T> new_chunk =
Vector<T>::New(sequence_length + new_capacity);
749 ASSERT(sequence_length < new_chunk.length());
750 for (
int i = 0; i < sequence_length; i++) {
753 if (sequence_start_ > 0) {
759 this->
index_ = sequence_length;
766 template <
typename l
char,
typename r
char>
767 inline int CompareChars(
const lchar* lhs,
const rchar* rhs,
int chars) {
768 const lchar* limit = lhs + chars;
769 #ifdef V8_HOST_CAN_READ_UNALIGNED
770 if (
sizeof(*lhs) ==
sizeof(*rhs)) {
772 static const int kStepSize =
sizeof(uintptr_t) /
sizeof(*lhs);
773 while (lhs <= limit - kStepSize) {
774 if (*reinterpret_cast<const uintptr_t*>(lhs) !=
775 *
reinterpret_cast<const uintptr_t*
>(rhs)) {
783 while (lhs < limit) {
784 int r =
static_cast<int>(*lhs) -
static_cast<int>(*rhs);
785 if (r != 0)
return r;
798 for (
int i = 1; i < exponent; i++) answer *= 10;
831 template <
class Dest,
class Source>
835 INLINE(
static Dest cast(
const Source& source)) {
837 memcpy(&dest, &source,
sizeof(dest));
842 template <
class Dest,
class Source>
844 INLINE(
static Dest cast(Source* source)) {
846 cast(reinterpret_cast<uintptr_t>(source));
850 template <
class Dest,
class Source>
853 template <
class Dest,
class Source>
859 template<
typename ElementType,
int NumElements>
871 ElementType elems_[NumElements];
875 template<
typename ElementType>
881 static ElementType t = 0;
954 template <
class E,
class T =
int>
959 bool Contains(E element)
const {
return (bits_ & Mask(element)) != 0; }
961 return (bits_ & set.bits_) != 0;
963 void Add(E element) { bits_ |= Mask(element); }
965 void Remove(E element) { bits_ &= ~Mask(element); }
973 T Mask(E element)
const {
976 ASSERT(element < static_cast<int>(
sizeof(
T) * CHAR_BIT));
985 #endif // V8_UTILS_H_
const DivMagicNumbers DivMagicNumberFor625
ElementType & operator[](int i)
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)
const DivMagicNumbers DivMagicNumberFor(int32_t divisor)
void AddString(const char *s)
void Sort(int(*cmp)(const T *, const T *))
const DivMagicNumbers DivMagicNumberFor3
static uint32_t encode(T value)
const DivMagicNumbers DivMagicNumberFor5
virtual ~SequenceCollector()
Vector< char > MutableCStrVector(char *data)
const DivMagicNumbers DivMagicNumberFor9
Access(StaticResource< T > *resource)
void Grow(int min_capacity)
Vector< T > SubVector(int from, int to)
SimpleStringBuilder(char *buffer, int size)
static const uint32_t kMask
#define ASSERT(condition)
T & operator[](int index) 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)
static uint32_t update(uint32_t previous, T value)
int HandleObjectPointerCompare(const Handle< T > *a, const Handle< T > *b)
SequenceCollector(int initial_capacity)
uint32_t ComputePointerHash(void *ptr)
INLINE(static Dest cast(Source *source))
Vector< T > AddBlock(int size, T initial_value)
EmbeddedVector(T initial_value)
bool is_finalized() const
T * NewArray(size_t size)
int Compare(const T &a, const T &b)
bool IsAligned(T value, U alignment)
INLINE(static Dest cast(const Source &source))
static T decode(uint32_t value)
EmbeddedVector(const EmbeddedVector &rhs)
void Intersect(const EnumSet &set)
T RoundUp(T x, intptr_t m)
const DivMagicNumbers DivMagicNumberFor125
void Remove(const EnumSet &set)
int CompareChars(const lchar *lhs, const rchar *rhs, int chars)
int TenToThe(int exponent)
void Truncate(int length)
static Vector< T > New(int length)
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)
const DivMagicNumbers DivMagicNumberFor11
Vector< T > EndSequence()
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)
const DivMagicNumbers DivMagicNumberFor25
#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)
Collector(int initial_capacity=kMinCapacity)
#define ASSERT_EQ(v1, v2)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
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
static bool is_valid(T value)
void WriteTo(Vector< T > destination)
Dest BitCast(const Source &source)
void DeleteArray(T *array)
const DivMagicNumbers InvalidDivMagicNumber
uint32_t RoundUpToPowerOf2(uint32_t x)
EmbeddedVector & operator=(const EmbeddedVector &rhs)
const DivMagicNumbers DivMagicNumberFor7