OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 // Creating a Unique<T> requires first dereferencing the handle to obtain | 25 // Creating a Unique<T> requires first dereferencing the handle to obtain |
26 // the address of the object, which is used as the hashcode and the basis for | 26 // the address of the object, which is used as the hashcode and the basis for |
27 // comparison. The object can be moved later by the GC, but comparison | 27 // comparison. The object can be moved later by the GC, but comparison |
28 // and hashing use the old address of the object, without dereferencing it. | 28 // and hashing use the old address of the object, without dereferencing it. |
29 // | 29 // |
30 // Careful! Comparison of two Uniques is only correct if both were created | 30 // Careful! Comparison of two Uniques is only correct if both were created |
31 // in the same "era" of GC or if at least one is a non-movable object. | 31 // in the same "era" of GC or if at least one is a non-movable object. |
32 template <typename T> | 32 template <typename T> |
33 class Unique { | 33 class Unique { |
34 public: | 34 public: |
| 35 Unique<T>() : raw_address_(NULL) {} |
| 36 |
35 // TODO(titzer): make private and introduce a uniqueness scope. | 37 // TODO(titzer): make private and introduce a uniqueness scope. |
36 explicit Unique(Handle<T> handle) { | 38 explicit Unique(Handle<T> handle) { |
37 if (handle.is_null()) { | 39 if (handle.is_null()) { |
38 raw_address_ = NULL; | 40 raw_address_ = NULL; |
39 } else { | 41 } else { |
40 // This is a best-effort check to prevent comparing Unique<T>'s created | 42 // 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 | 43 // in different GC eras; we require heap allocation to be disallowed at |
42 // creation time. | 44 // creation time. |
43 // NOTE: we currently consider maps to be non-movable, so no special | 45 // NOTE: we currently consider maps to be non-movable, so no special |
44 // assurance is required for creating a Unique<Map>. | 46 // assurance is required for creating a Unique<Map>. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 115 |
114 static Unique<T> CreateImmovable(Handle<T> handle) { | 116 static Unique<T> CreateImmovable(Handle<T> handle) { |
115 return Unique<T>(reinterpret_cast<Address>(*handle), handle); | 117 return Unique<T>(reinterpret_cast<Address>(*handle), handle); |
116 } | 118 } |
117 | 119 |
118 friend class UniqueSet<T>; // Uses internal details for speed. | 120 friend class UniqueSet<T>; // Uses internal details for speed. |
119 template <class U> | 121 template <class U> |
120 friend class Unique; // For comparing raw_address values. | 122 friend class Unique; // For comparing raw_address values. |
121 | 123 |
122 protected: | 124 protected: |
123 Unique<T>() : raw_address_(NULL) { } | |
124 | |
125 Address raw_address_; | 125 Address raw_address_; |
126 Handle<T> handle_; | 126 Handle<T> handle_; |
127 | 127 |
128 friend class SideEffectsTracker; | 128 friend class SideEffectsTracker; |
129 }; | 129 }; |
130 | 130 |
131 | 131 |
132 template <typename T> | 132 template <typename T> |
133 class UniqueSet FINAL : public ZoneObject { | 133 class UniqueSet FINAL : public ZoneObject { |
134 public: | 134 public: |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 capacity_ = new_capacity; | 339 capacity_ = new_capacity; |
340 array_ = new_array; | 340 array_ = new_array; |
341 } | 341 } |
342 } | 342 } |
343 }; | 343 }; |
344 | 344 |
345 } } // namespace v8::internal | 345 } } // namespace v8::internal |
346 | 346 |
347 #endif // V8_HYDROGEN_UNIQUE_H_ | 347 #endif // V8_HYDROGEN_UNIQUE_H_ |
OLD | NEW |