Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: src/unique.h

Issue 430503007: Rename ASSERT* to DCHECK*. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE and fixes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/unicode-inl.h ('k') | src/uri.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HYDROGEN_UNIQUE_H_ 5 #ifndef V8_HYDROGEN_UNIQUE_H_
6 #define V8_HYDROGEN_UNIQUE_H_ 6 #define V8_HYDROGEN_UNIQUE_H_
7 7
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 #include "src/string-stream.h" 10 #include "src/string-stream.h"
(...skipping 25 matching lines...) Expand all
36 explicit Unique(Handle<T> handle) { 36 explicit Unique(Handle<T> handle) {
37 if (handle.is_null()) { 37 if (handle.is_null()) {
38 raw_address_ = NULL; 38 raw_address_ = NULL;
39 } else { 39 } else {
40 // This is a best-effort check to prevent comparing Unique<T>'s created 40 // This is a best-effort check to prevent comparing Unique<T>'s created
41 // in different GC eras; we require heap allocation to be disallowed at 41 // in different GC eras; we require heap allocation to be disallowed at
42 // creation time. 42 // creation time.
43 // NOTE: we currently consider maps to be non-movable, so no special 43 // NOTE: we currently consider maps to be non-movable, so no special
44 // assurance is required for creating a Unique<Map>. 44 // assurance is required for creating a Unique<Map>.
45 // TODO(titzer): other immortable immovable objects are also fine. 45 // TODO(titzer): other immortable immovable objects are also fine.
46 ASSERT(!AllowHeapAllocation::IsAllowed() || handle->IsMap()); 46 DCHECK(!AllowHeapAllocation::IsAllowed() || handle->IsMap());
47 raw_address_ = reinterpret_cast<Address>(*handle); 47 raw_address_ = reinterpret_cast<Address>(*handle);
48 ASSERT_NE(raw_address_, NULL); // Non-null should imply non-zero address. 48 DCHECK_NE(raw_address_, NULL); // Non-null should imply non-zero address.
49 } 49 }
50 handle_ = handle; 50 handle_ = handle;
51 } 51 }
52 52
53 // TODO(titzer): this is a hack to migrate to Unique<T> incrementally. 53 // TODO(titzer): this is a hack to migrate to Unique<T> incrementally.
54 Unique(Address raw_address, Handle<T> handle) 54 Unique(Address raw_address, Handle<T> handle)
55 : raw_address_(raw_address), handle_(handle) { } 55 : raw_address_(raw_address), handle_(handle) { }
56 56
57 // Constructor for handling automatic up casting. 57 // Constructor for handling automatic up casting.
58 // Eg. Unique<JSFunction> can be passed when Unique<Object> is expected. 58 // Eg. Unique<JSFunction> can be passed when Unique<Object> is expected.
59 template <class S> Unique(Unique<S> uniq) { 59 template <class S> Unique(Unique<S> uniq) {
60 #ifdef DEBUG 60 #ifdef DEBUG
61 T* a = NULL; 61 T* a = NULL;
62 S* b = NULL; 62 S* b = NULL;
63 a = b; // Fake assignment to enforce type checks. 63 a = b; // Fake assignment to enforce type checks.
64 USE(a); 64 USE(a);
65 #endif 65 #endif
66 raw_address_ = uniq.raw_address_; 66 raw_address_ = uniq.raw_address_;
67 handle_ = uniq.handle_; 67 handle_ = uniq.handle_;
68 } 68 }
69 69
70 template <typename U> 70 template <typename U>
71 inline bool operator==(const Unique<U>& other) const { 71 inline bool operator==(const Unique<U>& other) const {
72 ASSERT(IsInitialized() && other.IsInitialized()); 72 DCHECK(IsInitialized() && other.IsInitialized());
73 return raw_address_ == other.raw_address_; 73 return raw_address_ == other.raw_address_;
74 } 74 }
75 75
76 template <typename U> 76 template <typename U>
77 inline bool operator!=(const Unique<U>& other) const { 77 inline bool operator!=(const Unique<U>& other) const {
78 ASSERT(IsInitialized() && other.IsInitialized()); 78 DCHECK(IsInitialized() && other.IsInitialized());
79 return raw_address_ != other.raw_address_; 79 return raw_address_ != other.raw_address_;
80 } 80 }
81 81
82 inline intptr_t Hashcode() const { 82 inline intptr_t Hashcode() const {
83 ASSERT(IsInitialized()); 83 DCHECK(IsInitialized());
84 return reinterpret_cast<intptr_t>(raw_address_); 84 return reinterpret_cast<intptr_t>(raw_address_);
85 } 85 }
86 86
87 inline bool IsNull() const { 87 inline bool IsNull() const {
88 ASSERT(IsInitialized()); 88 DCHECK(IsInitialized());
89 return raw_address_ == NULL; 89 return raw_address_ == NULL;
90 } 90 }
91 91
92 inline bool IsKnownGlobal(void* global) const { 92 inline bool IsKnownGlobal(void* global) const {
93 ASSERT(IsInitialized()); 93 DCHECK(IsInitialized());
94 return raw_address_ == reinterpret_cast<Address>(global); 94 return raw_address_ == reinterpret_cast<Address>(global);
95 } 95 }
96 96
97 inline Handle<T> handle() const { 97 inline Handle<T> handle() const {
98 return handle_; 98 return handle_;
99 } 99 }
100 100
101 template <class S> static Unique<T> cast(Unique<S> that) { 101 template <class S> static Unique<T> cast(Unique<S> that) {
102 return Unique<T>(that.raw_address_, Handle<T>::cast(that.handle_)); 102 return Unique<T>(that.raw_address_, Handle<T>::cast(that.handle_));
103 } 103 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 template <typename T> 198 template <typename T>
199 class UniqueSet V8_FINAL : public ZoneObject { 199 class UniqueSet V8_FINAL : public ZoneObject {
200 public: 200 public:
201 // Constructor. A new set will be empty. 201 // Constructor. A new set will be empty.
202 UniqueSet() : size_(0), capacity_(0), array_(NULL) { } 202 UniqueSet() : size_(0), capacity_(0), array_(NULL) { }
203 203
204 // Capacity constructor. A new set will be empty. 204 // Capacity constructor. A new set will be empty.
205 UniqueSet(int capacity, Zone* zone) 205 UniqueSet(int capacity, Zone* zone)
206 : size_(0), capacity_(capacity), 206 : size_(0), capacity_(capacity),
207 array_(zone->NewArray<Unique<T> >(capacity)) { 207 array_(zone->NewArray<Unique<T> >(capacity)) {
208 ASSERT(capacity <= kMaxCapacity); 208 DCHECK(capacity <= kMaxCapacity);
209 } 209 }
210 210
211 // Singleton constructor. 211 // Singleton constructor.
212 UniqueSet(Unique<T> uniq, Zone* zone) 212 UniqueSet(Unique<T> uniq, Zone* zone)
213 : size_(1), capacity_(1), array_(zone->NewArray<Unique<T> >(1)) { 213 : size_(1), capacity_(1), array_(zone->NewArray<Unique<T> >(1)) {
214 array_[0] = uniq; 214 array_[0] = uniq;
215 } 215 }
216 216
217 // Add a new element to this unique set. Mutates this set. O(|this|). 217 // Add a new element to this unique set. Mutates this set. O(|this|).
218 void Add(Unique<T> uniq, Zone* zone) { 218 void Add(Unique<T> uniq, Zone* zone) {
219 ASSERT(uniq.IsInitialized()); 219 DCHECK(uniq.IsInitialized());
220 // Keep the set sorted by the {raw_address} of the unique elements. 220 // Keep the set sorted by the {raw_address} of the unique elements.
221 for (int i = 0; i < size_; i++) { 221 for (int i = 0; i < size_; i++) {
222 if (array_[i] == uniq) return; 222 if (array_[i] == uniq) return;
223 if (array_[i].raw_address_ > uniq.raw_address_) { 223 if (array_[i].raw_address_ > uniq.raw_address_) {
224 // Insert in the middle. 224 // Insert in the middle.
225 Grow(size_ + 1, zone); 225 Grow(size_ + 1, zone);
226 for (int j = size_ - 1; j >= i; j--) array_[j + 1] = array_[j]; 226 for (int j = size_ - 1; j >= i; j--) array_[j + 1] = array_[j];
227 array_[i] = uniq; 227 array_[i] = uniq;
228 size_++; 228 size_++;
229 return; 229 return;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 void Clear() { 373 void Clear() {
374 size_ = 0; 374 size_ = 0;
375 } 375 }
376 376
377 inline int size() const { 377 inline int size() const {
378 return size_; 378 return size_;
379 } 379 }
380 380
381 inline Unique<T> at(int index) const { 381 inline Unique<T> at(int index) const {
382 ASSERT(index >= 0 && index < size_); 382 DCHECK(index >= 0 && index < size_);
383 return array_[index]; 383 return array_[index];
384 } 384 }
385 385
386 private: 386 private:
387 // These sets should be small, since operations are implemented with simple 387 // These sets should be small, since operations are implemented with simple
388 // linear algorithms. Enforce a maximum size. 388 // linear algorithms. Enforce a maximum size.
389 static const int kMaxCapacity = 65535; 389 static const int kMaxCapacity = 65535;
390 390
391 uint16_t size_; 391 uint16_t size_;
392 uint16_t capacity_; 392 uint16_t capacity_;
(...skipping 11 matching lines...) Expand all
404 } 404 }
405 capacity_ = new_capacity; 405 capacity_ = new_capacity;
406 array_ = new_array; 406 array_ = new_array;
407 } 407 }
408 } 408 }
409 }; 409 };
410 410
411 } } // namespace v8::internal 411 } } // namespace v8::internal
412 412
413 #endif // V8_HYDROGEN_UNIQUE_H_ 413 #endif // V8_HYDROGEN_UNIQUE_H_
OLDNEW
« no previous file with comments | « src/unicode-inl.h ('k') | src/uri.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698