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

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

Issue 1221503004: Reclaim the CreatedFromSnapshot bit and use it to indicate VM Heap object (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address-code-review-comments Created 5 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
« no previous file with comments | « runtime/vm/object.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/atomic.h" 9 #include "vm/atomic.h"
10 #include "vm/globals.h" 10 #include "vm/globals.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // class_ field not all raw objects are allocated in the heap and thus cannot 229 // class_ field not all raw objects are allocated in the heap and thus cannot
230 // be dereferenced (e.g. RawSmi). 230 // be dereferenced (e.g. RawSmi).
231 class RawObject { 231 class RawObject {
232 public: 232 public:
233 // The tags field which is a part of the object header uses the following 233 // The tags field which is a part of the object header uses the following
234 // bit fields for storing tags. 234 // bit fields for storing tags.
235 enum TagBits { 235 enum TagBits {
236 kWatchedBit = 0, 236 kWatchedBit = 0,
237 kMarkBit = 1, 237 kMarkBit = 1,
238 kCanonicalBit = 2, 238 kCanonicalBit = 2,
239 kFromSnapshotBit = 3, 239 kVMHeapObjectBit = 3,
240 kRememberedBit = 4, 240 kRememberedBit = 4,
241 #if defined(ARCH_IS_32_BIT) 241 #if defined(ARCH_IS_32_BIT)
242 kReservedTagPos = 5, // kReservedBit{100K,1M,10M} 242 kReservedTagPos = 5, // kReservedBit{100K,1M,10M}
243 kReservedTagSize = 3, 243 kReservedTagSize = 3,
244 kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8 244 kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8
245 kSizeTagSize = 8, 245 kSizeTagSize = 8,
246 kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16 246 kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16
247 kClassIdTagSize = 16, 247 kClassIdTagSize = 16,
248 #elif defined(ARCH_IS_64_BIT) 248 #elif defined(ARCH_IS_64_BIT)
249 kReservedTagPos = 5, // kReservedBit{100K,1M,10M} 249 kReservedTagPos = 5, // kReservedBit{100K,1M,10M}
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ASSERT(IsHeapObject()); 308 ASSERT(IsHeapObject());
309 uword addr = reinterpret_cast<uword>(this); 309 uword addr = reinterpret_cast<uword>(this);
310 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; 310 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset;
311 } 311 }
312 // Assumes this is a heap object. 312 // Assumes this is a heap object.
313 bool IsOldObject() const { 313 bool IsOldObject() const {
314 ASSERT(IsHeapObject()); 314 ASSERT(IsHeapObject());
315 uword addr = reinterpret_cast<uword>(this); 315 uword addr = reinterpret_cast<uword>(this);
316 return (addr & kNewObjectAlignmentOffset) == kOldObjectAlignmentOffset; 316 return (addr & kNewObjectAlignmentOffset) == kOldObjectAlignmentOffset;
317 } 317 }
318 // Assumes this is a heap object.
319 bool IsVMHeapObject() const;
320 318
321 // Like !IsHeapObject() || IsOldObject(), but compiles to a single branch. 319 // Like !IsHeapObject() || IsOldObject(), but compiles to a single branch.
322 bool IsSmiOrOldObject() const { 320 bool IsSmiOrOldObject() const {
323 ASSERT(IsWellFormed()); 321 ASSERT(IsWellFormed());
324 COMPILE_ASSERT(kHeapObjectTag == 1); 322 COMPILE_ASSERT(kHeapObjectTag == 1);
325 COMPILE_ASSERT(kNewObjectAlignmentOffset == kWordSize); 323 COMPILE_ASSERT(kNewObjectAlignmentOffset == kWordSize);
326 static const uword kNewObjectBits = 324 static const uword kNewObjectBits =
327 (kNewObjectAlignmentOffset | kHeapObjectTag); 325 (kNewObjectAlignmentOffset | kHeapObjectTag);
328 const uword addr = reinterpret_cast<uword>(this); 326 const uword addr = reinterpret_cast<uword>(this);
329 return (addr & kNewObjectBits) != kNewObjectBits; 327 return (addr & kNewObjectBits) != kNewObjectBits;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Support for object tags. 363 // Support for object tags.
366 bool IsCanonical() const { 364 bool IsCanonical() const {
367 return CanonicalObjectTag::decode(ptr()->tags_); 365 return CanonicalObjectTag::decode(ptr()->tags_);
368 } 366 }
369 void SetCanonical() { 367 void SetCanonical() {
370 UpdateTagBit<CanonicalObjectTag>(true); 368 UpdateTagBit<CanonicalObjectTag>(true);
371 } 369 }
372 void ClearCanonical() { 370 void ClearCanonical() {
373 UpdateTagBit<CanonicalObjectTag>(false); 371 UpdateTagBit<CanonicalObjectTag>(false);
374 } 372 }
375 bool IsCreatedFromSnapshot() const { 373 bool IsVMHeapObject() const {
376 return CreatedFromSnapshotTag::decode(ptr()->tags_); 374 return VMHeapObjectTag::decode(ptr()->tags_);
377 } 375 }
378 void SetCreatedFromSnapshot() { 376 void SetVMHeapObject() {
379 UpdateTagBit<CreatedFromSnapshotTag>(true); 377 UpdateTagBit<VMHeapObjectTag>(true);
380 } 378 }
381 379
382 // Support for GC remembered bit. 380 // Support for GC remembered bit.
383 bool IsRemembered() const { 381 bool IsRemembered() const {
384 return RememberedBit::decode(ptr()->tags_); 382 return RememberedBit::decode(ptr()->tags_);
385 } 383 }
386 void SetRememberedBit() { 384 void SetRememberedBit() {
387 ASSERT(!IsRemembered()); 385 ASSERT(!IsRemembered());
388 UpdateTagBit<RememberedBit>(true); 386 UpdateTagBit<RememberedBit>(true);
389 } 387 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 static RawObject* FromAddr(uword addr) { 436 static RawObject* FromAddr(uword addr) {
439 // We expect the untagged address here. 437 // We expect the untagged address here.
440 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); 438 ASSERT((addr & kSmiTagMask) != kHeapObjectTag);
441 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); 439 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag);
442 } 440 }
443 441
444 static uword ToAddr(const RawObject* raw_obj) { 442 static uword ToAddr(const RawObject* raw_obj) {
445 return reinterpret_cast<uword>(raw_obj->ptr()); 443 return reinterpret_cast<uword>(raw_obj->ptr());
446 } 444 }
447 445
448 static bool IsCreatedFromSnapshot(intptr_t value) { 446 static bool IsVMHeapObject(intptr_t value) {
449 return CreatedFromSnapshotTag::decode(value); 447 return VMHeapObjectTag::decode(value);
450 } 448 }
451 449
452 static bool IsCanonical(intptr_t value) { 450 static bool IsCanonical(intptr_t value) {
453 return CanonicalObjectTag::decode(value); 451 return CanonicalObjectTag::decode(value);
454 } 452 }
455 453
456 // Class Id predicates. 454 // Class Id predicates.
457 static bool IsErrorClassId(intptr_t index); 455 static bool IsErrorClassId(intptr_t index);
458 static bool IsNumberClassId(intptr_t index); 456 static bool IsNumberClassId(intptr_t index);
459 static bool IsIntegerClassId(intptr_t index); 457 static bool IsIntegerClassId(intptr_t index);
(...skipping 15 matching lines...) Expand all
475 uword tags_; // Various object tags (bits). 473 uword tags_; // Various object tags (bits).
476 474
477 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; 475 class WatchedBit : public BitField<bool, kWatchedBit, 1> {};
478 476
479 class MarkBit : public BitField<bool, kMarkBit, 1> {}; 477 class MarkBit : public BitField<bool, kMarkBit, 1> {};
480 478
481 class RememberedBit : public BitField<bool, kRememberedBit, 1> {}; 479 class RememberedBit : public BitField<bool, kRememberedBit, 1> {};
482 480
483 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; 481 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {};
484 482
485 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; 483 class VMHeapObjectTag : public BitField<bool, kVMHeapObjectBit, 1> {};
486 484
487 class ReservedBits : public 485 class ReservedBits : public
488 BitField<intptr_t, kReservedTagPos, kReservedTagSize> {}; // NOLINT 486 BitField<intptr_t, kReservedTagPos, kReservedTagSize> {}; // NOLINT
489 487
490 // TODO(koda): After handling tags_, return const*, like Object::raw_ptr(). 488 // TODO(koda): After handling tags_, return const*, like Object::raw_ptr().
491 RawObject* ptr() const { 489 RawObject* ptr() const {
492 ASSERT(IsHeapObject()); 490 ASSERT(IsHeapObject());
493 return reinterpret_cast<RawObject*>( 491 return reinterpret_cast<RawObject*>(
494 reinterpret_cast<uword>(this) - kHeapObjectTag); 492 reinterpret_cast<uword>(this) - kHeapObjectTag);
495 } 493 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 941
944 Dart_NativeEntryResolver native_entry_resolver_; // Resolves natives. 942 Dart_NativeEntryResolver native_entry_resolver_; // Resolves natives.
945 Dart_NativeEntrySymbol native_entry_symbol_resolver_; 943 Dart_NativeEntrySymbol native_entry_symbol_resolver_;
946 classid_t index_; // Library id number. 944 classid_t index_; // Library id number.
947 classid_t num_anonymous_; // Number of entries in anonymous_classes_. 945 classid_t num_anonymous_; // Number of entries in anonymous_classes_.
948 uint16_t num_imports_; // Number of entries in imports_. 946 uint16_t num_imports_; // Number of entries in imports_.
949 int8_t load_state_; // Of type LibraryState. 947 int8_t load_state_; // Of type LibraryState.
950 bool corelib_imported_; 948 bool corelib_imported_;
951 bool is_dart_scheme_; 949 bool is_dart_scheme_;
952 bool debuggable_; // True if debugger can stop in library. 950 bool debuggable_; // True if debugger can stop in library.
951 bool is_in_fullsnapshot_; // True if library is in a full snapshot.
953 952
953 friend class Class;
954 friend class Isolate; 954 friend class Isolate;
955 }; 955 };
956 956
957 957
958 class RawNamespace : public RawObject { 958 class RawNamespace : public RawObject {
959 RAW_HEAP_OBJECT_IMPLEMENTATION(Namespace); 959 RAW_HEAP_OBJECT_IMPLEMENTATION(Namespace);
960 960
961 RawObject** from() { 961 RawObject** from() {
962 return reinterpret_cast<RawObject**>(&ptr()->library_); 962 return reinterpret_cast<RawObject**>(&ptr()->library_);
963 } 963 }
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == 2194 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid ==
2195 kTypedDataInt8ArrayViewCid + 15); 2195 kTypedDataInt8ArrayViewCid + 15);
2196 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); 2196 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14);
2197 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); 2197 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1);
2198 return (kNullCid - kTypedDataInt8ArrayCid); 2198 return (kNullCid - kTypedDataInt8ArrayCid);
2199 } 2199 }
2200 2200
2201 } // namespace dart 2201 } // namespace dart
2202 2202
2203 #endif // VM_RAW_OBJECT_H_ 2203 #endif // VM_RAW_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698