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

Side by Side Diff: src/unique.h

Issue 24243005: Use Unique<Map> in CompareMap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Simplify Unique tests and disallow allocation during creation of unique in tests. Created 7 years, 3 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/mips/lithium-mips.h ('k') | src/x64/lithium-x64.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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_HYDROGEN_UNIQUE_H_ 28 #ifndef V8_HYDROGEN_UNIQUE_H_
29 #define V8_HYDROGEN_UNIQUE_H_ 29 #define V8_HYDROGEN_UNIQUE_H_
30 30
31 #include "handles.h" 31 #include "handles.h"
32 #include "objects.h"
32 #include "utils.h" 33 #include "utils.h"
33 #include "zone.h" 34 #include "zone.h"
34 35
35 namespace v8 { 36 namespace v8 {
36 namespace internal { 37 namespace internal {
37 38
38 39
39 template <typename T> 40 template <typename T>
40 class UniqueSet; 41 class UniqueSet;
41 42
42 43
43 // Represents a handle to an object on the heap, but with the additional 44 // Represents a handle to an object on the heap, but with the additional
44 // ability of checking for equality and hashing without accessing the heap. 45 // ability of checking for equality and hashing without accessing the heap.
45 // 46 //
46 // Creating a Unique<T> requires first dereferencing the handle to obtain 47 // Creating a Unique<T> requires first dereferencing the handle to obtain
47 // the address of the object, which is used as the hashcode and the basis for 48 // the address of the object, which is used as the hashcode and the basis for
48 // comparison. The object can be moved later by the GC, but comparison 49 // comparison. The object can be moved later by the GC, but comparison
49 // and hashing use the old address of the object, without dereferencing it. 50 // and hashing use the old address of the object, without dereferencing it.
50 // 51 //
51 // Careful! Comparison of two Uniques is only correct if both were created 52 // Careful! Comparison of two Uniques is only correct if both were created
52 // in the same "era" of GC or if at least one is a non-movable object. 53 // in the same "era" of GC or if at least one is a non-movable object.
53 template <typename T> 54 template <typename T>
54 class Unique V8_FINAL { 55 class Unique V8_FINAL {
55 public: 56 public:
56 // TODO(titzer): make private and introduce some builder/owner class. 57 // TODO(titzer): make private and introduce a factory.
57 explicit Unique(Handle<T> handle) { 58 explicit Unique(Handle<T> handle) {
58 if (handle.is_null()) { 59 if (handle.is_null()) {
59 raw_address_ = NULL; 60 raw_address_ = NULL;
60 } else { 61 } else {
62 // This is a best-effort check to prevent comparing Unique<T>'s created
63 // in different GC eras; we require heap allocation to be disallowed at
64 // creation time.
65 // NOTE: we currently consider maps to be non-movable, so no special
66 // assurance is required for creating a Unique<Map>.
67 // TODO(titzer): other immortable immovable objects are also fine.
68 ASSERT(!AllowHeapAllocation::IsAllowed() || handle->IsMap());
61 raw_address_ = reinterpret_cast<Address>(*handle); 69 raw_address_ = reinterpret_cast<Address>(*handle);
62 ASSERT_NE(raw_address_, NULL); 70 ASSERT_NE(raw_address_, NULL); // Non-null should imply non-zero address.
63 } 71 }
64 handle_ = handle; 72 handle_ = handle;
65 } 73 }
66 74
67 // TODO(titzer): this is a hack to migrate to Unique<T> incrementally. 75 // TODO(titzer): this is a hack to migrate to Unique<T> incrementally.
68 Unique(Address raw_address, Handle<T> handle) 76 Unique(Address raw_address, Handle<T> handle)
69 : raw_address_(raw_address), handle_(handle) { } 77 : raw_address_(raw_address), handle_(handle) { }
70 78
71 // Constructor for handling automatic up casting. 79 // Constructor for handling automatic up casting.
72 // Ex. Unique<JSFunction> can be passed when Unique<Object> is expected. 80 // Eg. Unique<JSFunction> can be passed when Unique<Object> is expected.
73 template <class S> Unique(Unique<S> uniq) { 81 template <class S> Unique(Unique<S> uniq) {
74 #ifdef DEBUG 82 #ifdef DEBUG
75 T* a = NULL; 83 T* a = NULL;
76 S* b = NULL; 84 S* b = NULL;
77 a = b; // Fake assignment to enforce type checks. 85 a = b; // Fake assignment to enforce type checks.
78 USE(a); 86 USE(a);
79 #endif 87 #endif
80 raw_address_ = uniq.raw_address_; 88 raw_address_ = uniq.raw_address_;
81 handle_ = uniq.handle_; // Creates a new handle sharing the same location. 89 handle_ = uniq.handle_;
82 } 90 }
83 91
84 template <typename U> 92 template <typename U>
85 bool operator==(const Unique<U>& other) const { 93 bool operator==(const Unique<U>& other) const {
86 ASSERT(IsInitialized() && other.IsInitialized()); 94 ASSERT(IsInitialized() && other.IsInitialized());
87 return raw_address_ == other.raw_address_; 95 return raw_address_ == other.raw_address_;
88 } 96 }
89 97
90 template <typename U> 98 template <typename U>
91 bool operator!=(const Unique<U>& other) const { 99 bool operator!=(const Unique<U>& other) const {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 capacity_ = new_capacity; 296 capacity_ = new_capacity;
289 array_ = new_array; 297 array_ = new_array;
290 } 298 }
291 } 299 }
292 }; 300 };
293 301
294 302
295 } } // namespace v8::internal 303 } } // namespace v8::internal
296 304
297 #endif // V8_HYDROGEN_UNIQUE_H_ 305 #endif // V8_HYDROGEN_UNIQUE_H_
OLDNEW
« no previous file with comments | « src/mips/lithium-mips.h ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698