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);
254 static const T kMax =
static_cast<T>((1
U << size) - 1);
258 return (static_cast<uint32_t>(value) & ~static_cast<uint32_t>(
kMax)) == 0;
264 return static_cast<uint32_t
>(value) << shift;
268 static uint32_t
update(uint32_t previous,
T value) {
274 return static_cast<T>((value &
kMask) >> shift);
282 static const uint32_t kZeroHashSeed = 0;
289 hash = ~hash + (hash << 15);
290 hash = hash ^ (hash >> 12);
291 hash = hash + (hash << 2);
292 hash = hash ^ (hash >> 4);
294 hash = hash ^ (hash >> 16);
301 hash = ~hash + (hash << 18);
302 hash = hash ^ (hash >> 31);
304 hash = hash ^ (hash >> 11);
305 hash = hash + (hash << 6);
306 hash = hash ^ (hash >> 22);
307 return (uint32_t) hash;
313 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr)),
314 v8::internal::kZeroHashSeed);
324 template <
typename T>
330 template <
typename S>
friend class Access;
337 template <
typename T>
341 : resource_(resource)
342 , instance_(&resource->instance_) {
343 ASSERT(!resource->is_reserved_);
344 resource->is_reserved_ =
true;
348 resource_->is_reserved_ =
false;
362 template <
typename T>
367 ASSERT(length == 0 || (length > 0 && data !=
NULL));
394 ASSERT(0 <= index && index < length_);
395 return start_[index];
402 T&
last() {
return start_[length_ - 1]; }
406 T* result = NewArray<T>(length_);
407 for (
int i = 0; i < length_; i++) result[i] = start_[i];
411 void Sort(
int (*cmp)(
const T*,
const T*)) {
412 typedef int (*RawComparer)(
const void*,
const void*);
416 reinterpret_cast<RawComparer>(cmp));
420 Sort(PointerValueCompare<T>);
424 ASSERT(length <= length_);
438 return Vector<T>(start_ + offset, length_ - offset);
447 input.
length() *
sizeof(
S) /
sizeof(
T));
482 template <
typename T,
int kSize>
488 for (
int i = 0; i < kSize; ++i) {
489 buffer_[i] = initial_value;
496 memcpy(buffer_, rhs.buffer_,
sizeof(
T) * kSize);
501 if (
this == &rhs)
return *
this;
503 memcpy(buffer_, rhs.buffer_,
sizeof(
T) * kSize);
513 template <
typename T>
536 return Vector<char>(data, (length < max) ? length : max);
549 template <
typename T,
int growth_factor = 2,
int max_growth = 1 * MB>
560 for (
int i =
chunks_.length() - 1; i >= 0; i--) {
587 for (
int i = 0; i <
size; i++) {
588 position[i] = initial_value;
605 for (
int i = 0; i < source.
length(); i++) {
606 position[i] = source[i];
616 for (
int i = 0; i <
chunks_.length(); i++) {
618 for (
int j = 0; j < chunk.
length(); j++) {
619 destination[position] = chunk[j];
623 for (
int i = 0; i <
index_; i++) {
640 virtual void Reset();
654 ASSERT(growth_factor > 1);
659 new_capacity = min_capacity * growth_factor;
662 int growth = current_length * (growth_factor - 1);
663 if (growth > max_growth) {
666 new_capacity = current_length + growth;
667 if (new_capacity < min_capacity) {
668 new_capacity = min_capacity + growth;
701 template <
typename T,
int growth_factor = 2,
int max_growth = 1 * MB>
705 :
Collector<
T, growth_factor, max_growth>(initial_capacity),
706 sequence_start_(kNoSequence) { }
711 ASSERT(sequence_start_ == kNoSequence);
712 sequence_start_ = this->
index_;
716 ASSERT(sequence_start_ != kNoSequence);
717 int sequence_start = sequence_start_;
718 sequence_start_ = kNoSequence;
725 ASSERT(sequence_start_ != kNoSequence);
726 int sequence_length = this->
index_ - sequence_start_;
727 this->
index_ = sequence_start_;
728 this->
size_ -= sequence_length;
729 sequence_start_ = kNoSequence;
733 sequence_start_ = kNoSequence;
738 static const int kNoSequence = -1;
742 virtual void NewChunk(
int new_capacity) {
743 if (sequence_start_ == kNoSequence) {
748 int sequence_length = this->
index_ - sequence_start_;
749 Vector<T> new_chunk =
Vector<T>::New(sequence_length + new_capacity);
750 ASSERT(sequence_length < new_chunk.length());
751 for (
int i = 0; i < sequence_length; i++) {
754 if (sequence_start_ > 0) {
760 this->
index_ = sequence_length;
767 template <
typename l
char,
typename r
char>
768 inline int CompareChars(
const lchar* lhs,
const rchar* rhs,
int chars) {
769 const lchar* limit = lhs + chars;
770 #ifdef V8_HOST_CAN_READ_UNALIGNED
771 if (
sizeof(*lhs) ==
sizeof(*rhs)) {
773 static const int kStepSize =
sizeof(uintptr_t) /
sizeof(*lhs);
774 while (lhs <= limit - kStepSize) {
775 if (*reinterpret_cast<const uintptr_t*>(lhs) !=
776 *
reinterpret_cast<const uintptr_t*
>(rhs)) {
784 while (lhs < limit) {
785 int r =
static_cast<int>(*lhs) -
static_cast<int>(*rhs);
786 if (r != 0)
return r;
799 for (
int i = 1; i < exponent; i++) answer *= 10;
832 template <
class Dest,
class Source>
836 INLINE(
static Dest cast(
const Source& source)) {
838 memcpy(&dest, &source,
sizeof(dest));
843 template <
class Dest,
class Source>
845 INLINE(
static Dest cast(Source* source)) {
847 cast(reinterpret_cast<uintptr_t>(source));
851 template <
class Dest,
class Source>
854 template <
class Dest,
class Source>
860 template<
typename ElementType,
int NumElements>
865 int length()
const {
return NumElements; }
876 ElementType elems_[NumElements];
880 template<
typename ElementType>
886 static ElementType t = 0;
891 static ElementType t = 0;
964 template <
class E,
class T =
int>
969 bool Contains(E element)
const {
return (bits_ & Mask(element)) != 0; }
971 return (bits_ & set.bits_) != 0;
973 void Add(E element) { bits_ |= Mask(element); }
975 void Remove(E element) { bits_ &= ~Mask(element); }
983 T Mask(E element)
const {
986 ASSERT(static_cast<int>(element) < static_cast<int>(
sizeof(
T) * CHAR_BIT));
1000 bool IsNone()
const {
return id_ == kNoneId; }
1003 static const int kNoneId = -1;
1019 bool IsNone()
const {
return id_ == kNoneId; }
1023 static const int kNoneId = -1;
1026 static const int kFunctionEntryId = 2;
1031 static const int kDeclarationsId = 3;
1034 static const int kFirstUsableId = 4;
1041 #endif // V8_UTILS_H_
const DivMagicNumbers DivMagicNumberFor625
bool operator==(const BailoutId &other) const
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)
static TypeFeedbackId None()
const DivMagicNumbers DivMagicNumberFor5
virtual ~SequenceCollector()
const ElementType & operator[](int i) const
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
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)
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)
static const uint32_t kShift
EmbeddedVector(T initial_value)
bool is_finalized() const
static BailoutId Declarations()
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 BailoutId FunctionEntry()
static Vector< T > New(int length)
activate correct semantics for inheriting readonliness false
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()
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)
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)
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)
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra 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 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
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