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

Side by Side Diff: runtime/vm/raw_object.h

Issue 10832199: Add a weak property type to the virtual machine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address final review comments Created 8 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 | « runtime/vm/object_test.cc ('k') | runtime/vm/raw_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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_RAW_OBJECT_H_ 5 #ifndef VM_RAW_OBJECT_H_
6 #define VM_RAW_OBJECT_H_ 6 #define VM_RAW_OBJECT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/token.h" 10 #include "vm/token.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 V(ExternalInt16Array) \ 82 V(ExternalInt16Array) \
83 V(ExternalUint16Array) \ 83 V(ExternalUint16Array) \
84 V(ExternalInt32Array) \ 84 V(ExternalInt32Array) \
85 V(ExternalUint32Array) \ 85 V(ExternalUint32Array) \
86 V(ExternalInt64Array) \ 86 V(ExternalInt64Array) \
87 V(ExternalUint64Array) \ 87 V(ExternalUint64Array) \
88 V(ExternalFloat32Array) \ 88 V(ExternalFloat32Array) \
89 V(ExternalFloat64Array) \ 89 V(ExternalFloat64Array) \
90 V(Stacktrace) \ 90 V(Stacktrace) \
91 V(JSRegExp) \ 91 V(JSRegExp) \
92 V(WeakProperty) \
92 V(Closure) \ 93 V(Closure) \
93 94
94 #define CLASS_LIST(V) \ 95 #define CLASS_LIST(V) \
95 V(Object) \ 96 V(Object) \
96 CLASS_LIST_NO_OBJECT(V) 97 CLASS_LIST_NO_OBJECT(V)
97 98
98 99
99 // Forward declarations. 100 // Forward declarations.
100 class Isolate; 101 class Isolate;
101 #define DEFINE_FORWARD_DECLARATION(clazz) \ 102 #define DEFINE_FORWARD_DECLARATION(clazz) \
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // be dereferenced (e.g. RawSmi). 184 // be dereferenced (e.g. RawSmi).
184 class RawObject { 185 class RawObject {
185 public: 186 public:
186 // The tags field which is a part of the object header uses the following 187 // The tags field which is a part of the object header uses the following
187 // bit fields for storing tags. 188 // bit fields for storing tags.
188 enum TagBits { 189 enum TagBits {
189 kFreeBit = 0, 190 kFreeBit = 0,
190 kMarkBit = 1, 191 kMarkBit = 1,
191 kCanonicalBit = 2, 192 kCanonicalBit = 2,
192 kFromSnapshotBit = 3, 193 kFromSnapshotBit = 3,
193 kReservedTagBit = 4, // kReservedBit{10K,100K,1M,10M} 194 kWatchedBit = 4,
194 kReservedTagSize = 4, 195 kReservedTagBit = 5, // kReservedBit{10K,100K,1M,10M}
196 kReservedTagSize = 3,
195 kSizeTagBit = 8, 197 kSizeTagBit = 8,
196 kSizeTagSize = 8, 198 kSizeTagSize = 8,
197 kClassIdTagBit = kSizeTagBit + kSizeTagSize, 199 kClassIdTagBit = kSizeTagBit + kSizeTagSize,
198 kClassIdTagSize = 16 200 kClassIdTagSize = 16
199 }; 201 };
200 202
201 // Encodes the object size in the tag in units of object alignment. 203 // Encodes the object size in the tag in units of object alignment.
202 class SizeTag { 204 class SizeTag {
203 public: 205 public:
204 static const intptr_t kMaxSizeTag = 206 static const intptr_t kMaxSizeTag =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 ASSERT(!IsMarked()); 257 ASSERT(!IsMarked());
256 uword tags = ptr()->tags_; 258 uword tags = ptr()->tags_;
257 ptr()->tags_ = MarkBit::update(true, tags); 259 ptr()->tags_ = MarkBit::update(true, tags);
258 } 260 }
259 void ClearMarkBit() { 261 void ClearMarkBit() {
260 ASSERT(IsMarked()); 262 ASSERT(IsMarked());
261 uword tags = ptr()->tags_; 263 uword tags = ptr()->tags_;
262 ptr()->tags_ = MarkBit::update(false, tags); 264 ptr()->tags_ = MarkBit::update(false, tags);
263 } 265 }
264 266
267 // Support for GC watched bit.
268 bool IsWatched() const {
269 return WatchedBit::decode(ptr()->tags_);
270 }
271 void SetWatchedBit() {
272 ASSERT(!IsWatched());
273 uword tags = ptr()->tags_;
274 ptr()->tags_ = WatchedBit::update(true, tags);
275 }
276 void ClearWatchedBit() {
277 ASSERT(IsWatched());
278 uword tags = ptr()->tags_;
279 ptr()->tags_ = WatchedBit::update(false, tags);
280 }
281
265 // Support for object tags. 282 // Support for object tags.
266 bool IsCanonical() const { 283 bool IsCanonical() const {
267 return CanonicalObjectTag::decode(ptr()->tags_); 284 return CanonicalObjectTag::decode(ptr()->tags_);
268 } 285 }
269 void SetCanonical() { 286 void SetCanonical() {
270 uword tags = ptr()->tags_; 287 uword tags = ptr()->tags_;
271 ptr()->tags_ = CanonicalObjectTag::update(true, tags); 288 ptr()->tags_ = CanonicalObjectTag::update(true, tags);
272 } 289 }
273 bool IsCreatedFromSnapshot() const { 290 bool IsCreatedFromSnapshot() const {
274 return CreatedFromSnapshotTag::decode(ptr()->tags_); 291 return CreatedFromSnapshotTag::decode(ptr()->tags_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 static bool IsByteArrayClassId(intptr_t index); 341 static bool IsByteArrayClassId(intptr_t index);
325 342
326 protected: 343 protected:
327 uword tags_; // Various object tags (bits). 344 uword tags_; // Various object tags (bits).
328 345
329 private: 346 private:
330 class FreeBit : public BitField<bool, kFreeBit, 1> {}; 347 class FreeBit : public BitField<bool, kFreeBit, 1> {};
331 348
332 class MarkBit : public BitField<bool, kMarkBit, 1> {}; 349 class MarkBit : public BitField<bool, kMarkBit, 1> {};
333 350
351 class WatchedBit : public BitField<bool, kWatchedBit, 1> {};
352
334 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; 353 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {};
335 354
336 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; 355 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {};
337 356
338 class ReservedBits : public BitField<intptr_t, 357 class ReservedBits : public BitField<intptr_t,
339 kReservedTagBit, 358 kReservedTagBit,
340 kReservedTagSize> {}; // NOLINT 359 kReservedTagSize> {}; // NOLINT
341 360
342 RawObject* ptr() const { 361 RawObject* ptr() const {
343 ASSERT(IsHeapObject()); 362 ASSERT(IsHeapObject());
344 return reinterpret_cast<RawObject*>( 363 return reinterpret_cast<RawObject*>(
345 reinterpret_cast<uword>(this) - kHeapObjectTag); 364 reinterpret_cast<uword>(this) - kHeapObjectTag);
346 } 365 }
347 366
348 intptr_t SizeFromClass() const; 367 intptr_t SizeFromClass() const;
349 368
350 intptr_t GetClassId() const { 369 intptr_t GetClassId() const {
351 uword tags = ptr()->tags_; 370 uword tags = ptr()->tags_;
352 return ClassIdTag::decode(tags); 371 return ClassIdTag::decode(tags);
353 } 372 }
354 373
355 friend class Api; 374 friend class Api;
356 friend class Array; 375 friend class Array;
357 friend class FreeListElement; 376 friend class FreeListElement;
377 friend class GCMarker;
358 friend class Heap; 378 friend class Heap;
359 friend class HeapProfiler; 379 friend class HeapProfiler;
360 friend class HeapProfilerRootVisitor; 380 friend class HeapProfilerRootVisitor;
361 friend class MarkingVisitor; 381 friend class MarkingVisitor;
362 friend class Object; 382 friend class Object;
363 friend class RawInstructions; 383 friend class RawInstructions;
364 friend class RawInstance; 384 friend class RawInstance;
385 friend class Scavenger;
365 friend class SnapshotReader; 386 friend class SnapshotReader;
366 friend class SnapshotWriter; 387 friend class SnapshotWriter;
367 388
368 DISALLOW_ALLOCATION(); 389 DISALLOW_ALLOCATION();
369 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); 390 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject);
370 }; 391 };
371 392
372 393
373 class RawClass : public RawObject { 394 class RawClass : public RawObject {
374 public: 395 public:
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 return reinterpret_cast<RawObject**>(&ptr()->pattern_); 1446 return reinterpret_cast<RawObject**>(&ptr()->pattern_);
1426 } 1447 }
1427 1448
1428 intptr_t type_; // Uninitialized, simple or complex. 1449 intptr_t type_; // Uninitialized, simple or complex.
1429 intptr_t flags_; // Represents global/local, case insensitive, multiline. 1450 intptr_t flags_; // Represents global/local, case insensitive, multiline.
1430 1451
1431 // Variable length data follows here. 1452 // Variable length data follows here.
1432 uint8_t data_[0]; 1453 uint8_t data_[0];
1433 }; 1454 };
1434 1455
1456 class RawWeakProperty : public RawInstance {
1457 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty);
1458
1459 RawObject** from() {
1460 return reinterpret_cast<RawObject**>(&ptr()->key_);
1461 }
1462 RawObject* key_;
1463 RawObject* value_;
1464 RawObject** to() {
1465 return reinterpret_cast<RawObject**>(&ptr()->value_);
1466 }
1467
1468 friend class GCMarker;
1469 friend class MarkingVisitor;
1470 friend class Scavenger;
1471 friend class ScavengerVisitor;
1472 };
1473
1435 // Class Id predicates. 1474 // Class Id predicates.
1436 1475
1437 inline bool RawObject::IsErrorClassId(intptr_t index) { 1476 inline bool RawObject::IsErrorClassId(intptr_t index) {
1438 // Make sure this function is updated when new Error types are added. 1477 // Make sure this function is updated when new Error types are added.
1439 ASSERT(kApiErrorCid == kErrorCid + 1 && 1478 ASSERT(kApiErrorCid == kErrorCid + 1 &&
1440 kLanguageErrorCid == kErrorCid + 2 && 1479 kLanguageErrorCid == kErrorCid + 2 &&
1441 kUnhandledExceptionCid == kErrorCid + 3 && 1480 kUnhandledExceptionCid == kErrorCid + 3 &&
1442 kUnwindErrorCid == kErrorCid + 4 && 1481 kUnwindErrorCid == kErrorCid + 4 &&
1443 kInstanceCid == kErrorCid + 5); 1482 kInstanceCid == kErrorCid + 5);
1444 return (index >= kErrorCid && index < kInstanceCid); 1483 return (index >= kErrorCid && index < kInstanceCid);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 kExternalUint64ArrayCid == kByteArrayCid + 18 && 1587 kExternalUint64ArrayCid == kByteArrayCid + 18 &&
1549 kExternalFloat32ArrayCid == kByteArrayCid + 19 && 1588 kExternalFloat32ArrayCid == kByteArrayCid + 19 &&
1550 kExternalFloat64ArrayCid == kByteArrayCid + 20 && 1589 kExternalFloat64ArrayCid == kByteArrayCid + 20 &&
1551 kStacktraceCid == kByteArrayCid + 21); 1590 kStacktraceCid == kByteArrayCid + 21);
1552 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); 1591 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid);
1553 } 1592 }
1554 1593
1555 } // namespace dart 1594 } // namespace dart
1556 1595
1557 #endif // VM_RAW_OBJECT_H_ 1596 #endif // VM_RAW_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/raw_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698