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

Unified Diff: runtime/vm/raw_object.cc

Issue 10450014: Request for comments on overall approach. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix scavenger and freelist handling Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/raw_object.cc
diff --git a/runtime/vm/raw_object.cc b/runtime/vm/raw_object.cc
index 649d6e69e7cc7784f7886b5a92958728dac7e1aa..0e45a773f9c9930d8ad04c574f5ac08d61cb2891 100644
--- a/runtime/vm/raw_object.cc
+++ b/runtime/vm/raw_object.cc
@@ -13,6 +13,18 @@
namespace dart {
+
+
+RawClass* RawObject::GetClass(uword tags) {
+ if (FreeBit::decode(tags)) {
+ return FreeListElement::freelist_class();
+ } else {
+ return Isolate::Current()->class_table()->At(
+ ClassTag::decode(tags));
+ }
+}
+
+
void RawObject::Validate(Isolate* isolate) const {
// Validation only happens in DEBUG builds.
#if defined(DEBUG)
@@ -25,19 +37,13 @@ void RawObject::Validate(Isolate* isolate) const {
if (!IsHeapObject()) {
return;
}
- // Validate that the class_ field is sensible.
- RawClass* raw_class = ptr()->class_;
- ASSERT(raw_class->IsHeapObject());
- RawClass* raw_class_class = raw_class->ptr()->class_;
- ASSERT(raw_class_class->IsHeapObject());
- ASSERT(raw_class_class->ptr()->instance_kind_ == kClass);
// Validate that the tags_ field is sensible.
uword tags = ptr()->tags_;
ASSERT((tags & 0x000000f0) == 0);
intptr_t cid = ClassTag::decode(tags);
- RawClass* tag_class = isolate->class_table()->At(cid);
- ASSERT(tag_class == raw_class);
+ RawClass* raw_class = isolate->class_table()->At(cid);
+ ASSERT(raw_class->IsHeapObject());
#endif
}
@@ -48,7 +54,7 @@ intptr_t RawObject::SizeFromClass() const {
// Only reasonable to be called on heap objects.
ASSERT(IsHeapObject());
- RawClass* raw_class = ptr()->class_;
+ RawClass* raw_class = GetClass();
intptr_t instance_size = raw_class->ptr()->instance_size_;
ObjectKind instance_kind = raw_class->ptr()->instance_kind_;
@@ -238,7 +244,7 @@ intptr_t RawObject::SizeFromClass() const {
ASSERT(FreeBit::decode(ptr()->tags_));
uword addr = RawObject::ToAddr(const_cast<RawObject*>(this));
FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
- instance_size = element->Size();
+ instance_size = element->size();
break;
}
default:
@@ -262,13 +268,10 @@ intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) {
// Only reasonable to be called on heap objects.
ASSERT(IsHeapObject());
- // Read the necessary data out of the class before visting the class itself.
- RawClass* raw_class = ptr()->class_;
+ // Read the necessary data out of the class before visiting the class itself.
+ RawClass* raw_class = GetClass();
Ivan Posva 2012/05/26 04:34:46 The ObjectKind is equivalent to the instance_kind_
ObjectKind kind = raw_class->ptr()->instance_kind_;
- // Visit the class before visting the fields.
- visitor->VisitPointer(reinterpret_cast<RawObject**>(&ptr()->class_));
-
switch (kind) {
#define RAW_VISITPOINTERS(clazz) \
case clazz::kInstanceKind: { \
@@ -283,7 +286,7 @@ intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) {
// Nothing to visit for free list elements.
uword addr = RawObject::ToAddr(this);
FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
- size = element->Size();
+ size = element->size();
break;
}
default:
@@ -439,7 +442,7 @@ intptr_t RawInstructions::VisitInstructionsPointers(
bool RawInstructions::ContainsPC(RawObject* raw_obj, uword pc) {
- RawClass* raw_class = raw_obj->ptr()->class_;
+ RawClass* raw_class = raw_obj->GetClass();
ObjectKind instance_kind = raw_class->ptr()->instance_kind_;
if (instance_kind == kInstructions) {
Ivan Posva 2012/05/26 04:34:46 Just use the class id field here.
RawInstructions* raw_instr = reinterpret_cast<RawInstructions*>(raw_obj);
@@ -564,9 +567,9 @@ intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj,
ObjectPointerVisitor* visitor) {
// Make sure that we got here with the tagged pointer as this.
ASSERT(raw_obj->IsHeapObject());
- RawInstance* obj = raw_obj->ptr();
- intptr_t instance_size = obj->class_->ptr()->instance_size_;
- intptr_t num_native_fields = obj->class_->ptr()->num_native_fields_;
+ RawClass* raw_class = raw_obj->GetClass();
+ intptr_t instance_size = raw_class->ptr()->instance_size_;
+ intptr_t num_native_fields = raw_class->ptr()->num_native_fields_;
// Calculate the first and last raw object pointer fields.
uword obj_addr = RawObject::ToAddr(raw_obj);

Powered by Google App Engine
This is Rietveld 408576698