28 #ifndef V8_HYDROGEN_UNIQUE_H_
29 #define V8_HYDROGEN_UNIQUE_H_
68 ASSERT(!AllowHeapAllocation::IsAllowed() || handle->IsMap());
69 raw_address_ =
reinterpret_cast<Address>(*handle);
77 : raw_address_(raw_address), handle_(handle) { }
81 template <
class S>
Unique(Unique<S> uniq) {
88 raw_address_ = uniq.raw_address_;
89 handle_ = uniq.handle_;
94 ASSERT(IsInitialized() && other.IsInitialized());
95 return raw_address_ == other.raw_address_;
100 ASSERT(IsInitialized() && other.IsInitialized());
101 return raw_address_ != other.raw_address_;
106 return reinterpret_cast<intptr_t
>(raw_address_);
111 return raw_address_ ==
NULL;
116 return raw_address_ ==
reinterpret_cast<Address>(global);
123 template <
class S>
static Unique<T>
cast(Unique<S> that) {
128 return raw_address_ !=
NULL || handle_.is_null();
133 return Unique<T>(
reinterpret_cast<Address>(
NULL), handle);
137 return Unique<T>(
reinterpret_cast<Address>(*handle),
handle);
145 Unique<T>() : raw_address_(
NULL) { }
150 friend class SideEffectsTracker;
154 template <
typename T>
155 class UniqueSet
V8_FINAL :
public ZoneObject {
162 ASSERT(uniq.IsInitialized());
164 for (
int i = 0; i < size_; i++) {
165 if (array_[i] == uniq)
return;
166 if (array_[i].raw_address_ > uniq.raw_address_) {
168 Grow(size_ + 1, zone);
169 for (
int j = size_ - 1; j >= i; j--) array_[j + 1] = array_[j];
176 Grow(size_ + 1, zone);
177 array_[size_++] = uniq;
182 for (
int i = 0; i < size_; i++) {
183 if (array_[i] == uniq) {
184 while (++i < size_) array_[i - 1] = array_[i];
193 if (that->size_ != this->size_)
return false;
194 for (
int i = 0; i < this->size_; i++) {
195 if (this->array_[i] != that->array_[i])
return false;
202 template <
typename U>
204 for (
int i = 0; i < size_; i++) {
205 if (this->array_[i] == elem)
return true;
212 if (that->size_ < this->size_)
return false;
214 for (
int i = 0; i < this->size_; i++) {
215 Unique<T> sought = this->array_[i];
217 if (sought == that->array_[j++])
break;
219 if ((this->size_ - i) > (that->size_ - j))
return false;
228 if (that->size_ == 0 || this->size_ == 0)
return new(zone)
UniqueSet<T>();
231 out->Grow(
Min(this->size_, that->size_), zone);
233 int i = 0, j = 0, k = 0;
234 while (i < this->size_ && j < that->size_) {
235 Unique<T> a = this->array_[i];
236 Unique<T> b = that->array_[j];
238 out->array_[k++] = a;
241 }
else if (a.raw_address_ < b.raw_address_) {
255 if (that->size_ == 0)
return this->Copy(zone);
256 if (this->size_ == 0)
return that->Copy(zone);
259 out->Grow(this->size_ + that->size_, zone);
261 int i = 0, j = 0, k = 0;
262 while (i < this->size_ && j < that->size_) {
263 Unique<T> a = this->array_[i];
264 Unique<T> b = that->array_[j];
266 out->array_[k++] = a;
269 }
else if (a.raw_address_ < b.raw_address_) {
270 out->array_[k++] = a;
273 out->array_[k++] = b;
278 while (i < this->size_) out->array_[k++] = this->array_[i++];
279 while (j < that->size_) out->array_[k++] = that->array_[j++];
288 copy->size_ = this->size_;
289 copy->capacity_ = this->size_;
290 copy->array_ = zone->
NewArray<Unique<T> >(this->size_);
291 memcpy(copy->array_, this->array_, this->size_ *
sizeof(Unique<T>));
303 inline Unique<T>
at(
int index)
const {
304 ASSERT(index >= 0 && index < size_);
305 return array_[index];
311 static const int kMaxCapacity = 65535;
319 CHECK(size < kMaxCapacity);
320 if (capacity_ < size) {
321 int new_capacity = 2 * capacity_ +
size;
322 if (new_capacity > kMaxCapacity) new_capacity = kMaxCapacity;
323 Unique<T>* new_array = zone->
NewArray<Unique<T> >(new_capacity);
325 memcpy(new_array, array_, size_ *
sizeof(Unique<T>));
327 capacity_ = new_capacity;
336 #endif // V8_HYDROGEN_UNIQUE_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
UniqueSet< T > * Copy(Zone *zone) const
Unique(Address raw_address, Handle< T > handle)
void Remove(Unique< T > uniq)
static Unique< T > CreateImmovable(Handle< T > handle)
bool IsSubset(UniqueSet< T > *that) const
static Handle< T > cast(Handle< S > that)
Handle< T > handle() const
#define ASSERT(condition)
static Unique< T > cast(Unique< S > that)
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
bool operator==(const Unique< U > &other) const
#define T(name, string, precedence)
UniqueSet< T > * Union(UniqueSet< T > *that, Zone *zone) const
bool IsKnownGlobal(void *global) const
Handle< T > handle(T *t, Isolate *isolate)
bool operator!=(const Unique< U > &other) const
bool Equals(UniqueSet< T > *that) const
#define ASSERT_NE(v1, v2)
bool Contains(Unique< U > elem) const
static Unique< T > CreateUninitialized(Handle< T > handle)
Unique(Handle< T > handle)
intptr_t Hashcode() const
UniqueSet< T > * Intersect(UniqueSet< T > *that, Zone *zone) const
Unique< T > at(int index) const
void Add(Unique< T > uniq, Zone *zone)
bool IsInitialized() const