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

Side by Side Diff: vm/object.h

Issue 8879063: Changes to set up the object tag bits (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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 | « no previous file | vm/object.cc » ('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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/globals.h" 10 #include "vm/globals.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } \ 90 } \
91 } \ 91 } \
92 /* Disallow allocation, copy constructors and override super assignment. */ \ 92 /* Disallow allocation, copy constructors and override super assignment. */ \
93 void* operator new(size_t size); \ 93 void* operator new(size_t size); \
94 object(const object& value); \ 94 object(const object& value); \
95 void operator=(Raw##super* value); \ 95 void operator=(Raw##super* value); \
96 void operator=(const object& value); \ 96 void operator=(const object& value); \
97 void operator=(const super& value); \ 97 void operator=(const super& value); \
98 98
99 #define SNAPSHOT_READER_SUPPORT(object) \ 99 #define SNAPSHOT_READER_SUPPORT(object) \
100 static Raw##object* ReadFrom( \ 100 static Raw##object* ReadFrom(SnapshotReader* reader, \
101 SnapshotReader* reader, intptr_t object_id, Snapshot::Kind); \ 101 intptr_t object_id, \
102 intptr_t tags, \
103 Snapshot::Kind); \
102 friend class SnapshotReader; \ 104 friend class SnapshotReader; \
103 105
104 #define HEAP_OBJECT_IMPLEMENTATION(object, super) \ 106 #define HEAP_OBJECT_IMPLEMENTATION(object, super) \
105 OBJECT_IMPLEMENTATION(object, super); \ 107 OBJECT_IMPLEMENTATION(object, super); \
106 Raw##object* raw_ptr() const { \ 108 Raw##object* raw_ptr() const { \
107 ASSERT(raw() != null()); \ 109 ASSERT(raw() != null()); \
108 return raw()->ptr(); \ 110 return raw()->ptr(); \
109 } \ 111 } \
110 SNAPSHOT_READER_SUPPORT(object) \ 112 SNAPSHOT_READER_SUPPORT(object) \
111 113
(...skipping 30 matching lines...) Expand all
142 kApiErrorClass, 144 kApiErrorClass,
143 kMaxId, 145 kMaxId,
144 kInvalidIndex = -1, 146 kInvalidIndex = -1,
145 }; 147 };
146 148
147 virtual ~Object() { } 149 virtual ~Object() { }
148 150
149 RawObject* raw() const { return raw_; } 151 RawObject* raw() const { return raw_; }
150 void operator=(RawObject* value) { SetRaw(value); } 152 void operator=(RawObject* value) { SetRaw(value); }
151 153
154 void set_tags(intptr_t tags) {
155 ASSERT(!IsNull());
156 raw()->ptr()->tags_ = tags;
157 }
158 void SetCreatedFromSnapshot() const {
159 ASSERT(!IsNull());
160 raw()->SetCreatedFromSnapshot();
161 }
162 bool IsCanonical() const {
163 ASSERT(!IsNull());
164 return raw()->IsCanonical();
165 }
166 void SetCanonical() const {
167 ASSERT(!IsNull());
168 raw()->SetCanonical();
169 }
170
152 inline RawClass* clazz() const; 171 inline RawClass* clazz() const;
153 static intptr_t class_offset() { return OFFSET_OF(RawObject, class_); } 172 static intptr_t class_offset() { return OFFSET_OF(RawObject, class_); }
154 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); } 173 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); }
155 174
156 // Class testers. 175 // Class testers.
157 #define DEFINE_CLASS_TESTER(clazz) \ 176 #define DEFINE_CLASS_TESTER(clazz) \
158 virtual bool Is##clazz() const { return false; } 177 virtual bool Is##clazz() const { return false; }
159 CLASS_LIST_NO_OBJECT(DEFINE_CLASS_TESTER); 178 CLASS_LIST_NO_OBJECT(DEFINE_CLASS_TESTER);
160 #undef DEFINE_CLASS_TESTER 179 #undef DEFINE_CLASS_TESTER
161 180
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 return OFFSET_OF(RawTypeArguments, length_); 1049 return OFFSET_OF(RawTypeArguments, length_);
1031 } 1050 }
1032 1051
1033 static intptr_t InstanceSize() { 1052 static intptr_t InstanceSize() {
1034 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_)); 1053 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_));
1035 return 0; 1054 return 0;
1036 } 1055 }
1037 1056
1038 static intptr_t InstanceSize(intptr_t len) { 1057 static intptr_t InstanceSize(intptr_t len) {
1039 // Ensure that the types_ is not adding to the object length. 1058 // Ensure that the types_ is not adding to the object length.
1040 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (2 * kWordSize))); 1059 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (1 * kWordSize)));
1041 return RoundedAllocationSize(sizeof(RawTypeArguments) + (len * kWordSize)); 1060 return RoundedAllocationSize(sizeof(RawTypeArguments) + (len * kWordSize));
1042 } 1061 }
1043 1062
1044 static RawTypeArguments* New(intptr_t len); 1063 static RawTypeArguments* New(intptr_t len);
1045 1064
1046 private: 1065 private:
1047 bool is_canonical() const;
1048 void set_is_canonical(bool value) const;
1049
1050 // Make sure that the array size cannot wrap around. 1066 // Make sure that the array size cannot wrap around.
1051 static const intptr_t kMaxTypes = 512 * 1024 * 1024; 1067 static const intptr_t kMaxTypes = 512 * 1024 * 1024;
1052 RawAbstractType** TypeAddr(intptr_t index) const; 1068 RawAbstractType** TypeAddr(intptr_t index) const;
1053 void SetLength(intptr_t value); 1069 void SetLength(intptr_t value);
1054 1070
1055 HEAP_OBJECT_IMPLEMENTATION(TypeArguments, AbstractTypeArguments); 1071 HEAP_OBJECT_IMPLEMENTATION(TypeArguments, AbstractTypeArguments);
1056 friend class Class; 1072 friend class Class;
1057 }; 1073 };
1058 1074
1059 1075
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 bool Equals(const uint32_t* characters, intptr_t len) const; 2485 bool Equals(const uint32_t* characters, intptr_t len) const;
2470 2486
2471 virtual bool Equals(const Instance& other) const; 2487 virtual bool Equals(const Instance& other) const;
2472 2488
2473 intptr_t CompareTo(const String& other) const; 2489 intptr_t CompareTo(const String& other) const;
2474 2490
2475 bool StartsWith(const String& other) const; 2491 bool StartsWith(const String& other) const;
2476 2492
2477 virtual RawInstance* Canonicalize() const; 2493 virtual RawInstance* Canonicalize() const;
2478 2494
2479 bool IsSymbol() const; 2495 bool IsSymbol() const { return raw()->IsCanonical(); }
2480 2496
2481 virtual bool IsExternal() const { return false; } 2497 virtual bool IsExternal() const { return false; }
2482 virtual void* GetPeer() const { 2498 virtual void* GetPeer() const {
2483 UNREACHABLE(); 2499 UNREACHABLE();
2484 return NULL; 2500 return NULL;
2485 } 2501 }
2486 2502
2487 static RawString* New(const char* str, Heap::Space space = Heap::kNew); 2503 static RawString* New(const char* str, Heap::Space space = Heap::kNew);
2488 static RawString* New(const uint8_t* characters, 2504 static RawString* New(const uint8_t* characters,
2489 intptr_t len, 2505 intptr_t len,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 2591
2576 void SetHash(intptr_t value) const { 2592 void SetHash(intptr_t value) const {
2577 // This is only safe because we create a new Smi, which does not cause 2593 // This is only safe because we create a new Smi, which does not cause
2578 // heap allocation. 2594 // heap allocation.
2579 raw_ptr()->hash_ = Smi::New(value); 2595 raw_ptr()->hash_ = Smi::New(value);
2580 } 2596 }
2581 2597
2582 template<typename HandleType, typename ElementType> 2598 template<typename HandleType, typename ElementType>
2583 static RawString* ReadFromImpl(SnapshotReader* reader, 2599 static RawString* ReadFromImpl(SnapshotReader* reader,
2584 intptr_t object_id, 2600 intptr_t object_id,
2601 intptr_t tags,
2585 Snapshot::Kind kind); 2602 Snapshot::Kind kind);
2586 2603
2587 HEAP_OBJECT_IMPLEMENTATION(String, Instance); 2604 HEAP_OBJECT_IMPLEMENTATION(String, Instance);
2588 }; 2605 };
2589 2606
2590 2607
2591 class OneByteString : public String { 2608 class OneByteString : public String {
2592 public: 2609 public:
2593 virtual int32_t CharAt(intptr_t index) const { 2610 virtual int32_t CharAt(intptr_t index) const {
2594 return *CharAddr(index); 2611 return *CharAddr(index);
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
3272 } 3289 }
3273 3290
3274 3291
3275 void Context::SetAt(intptr_t index, const Instance& value) const { 3292 void Context::SetAt(intptr_t index, const Instance& value) const {
3276 StorePointer(InstanceAddr(index), value.raw()); 3293 StorePointer(InstanceAddr(index), value.raw());
3277 } 3294 }
3278 3295
3279 } // namespace dart 3296 } // namespace dart
3280 3297
3281 #endif // VM_OBJECT_H_ 3298 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698