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

Unified Diff: runtime/vm/freelist.h

Issue 10538022: Do not reuse tags_ field to store next_ pointer of FreeListElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allocate a real class for a free list element. Created 8 years, 6 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/freelist.h
diff --git a/runtime/vm/freelist.h b/runtime/vm/freelist.h
index 4c48c5390dc9faba65aeff86af401294a211e669..812afd1f82a76b27d3237f205f1664b281c1c99a 100644
--- a/runtime/vm/freelist.h
+++ b/runtime/vm/freelist.h
@@ -11,39 +11,50 @@
namespace dart {
-// FreeListElement describes a freelist element that has the same size
-// as the smallest raw object. It uses the class_ field to point to a fake map
-// to enable basic traversing of the heap and to identify the type of freelist
-// element. It reuses the second word of the raw object to keep a next_
+// FreeListElement describes a freelist element. Smallest FreeListElement is
+// two words in size. Second word of the raw object is used to keep a next_
// pointer to chain elements of the list together. For objects larger than the
-// minimal object size, the size of the element is embedded in the element at
-// the address following the next_ field.
+// object size encodable in tags field, the size of the element is embedded in
+// the element at the address following the next_ field.
class FreeListElement {
public:
FreeListElement* next() const {
- // Clear the FreeBit.
- ASSERT((next_ & 1) == 1);
- return reinterpret_cast<FreeListElement*>(next_ ^ 1);
+ return next_;
}
+
void set_next(FreeListElement* next) {
- // Set the FreeBit.
- uword addr = reinterpret_cast<uword>(next);
- ASSERT((addr & 1) == 0);
- next_ = addr | 1;
+ next_ = next;
}
- intptr_t size() const {
- return size_;
+ intptr_t Size() {
+ intptr_t size = RawObject::SizeTag::decode(tags_);
+ if (size != 0) return size;
+ return *SizeAddress();
}
static FreeListElement* AsElement(uword addr, intptr_t size);
static void InitOnce();
+ // Used to allocate class for free list elements in Object::InitOnce.
+ class FakeInstance {
+ public:
+ static cpp_vtable vtable() { return 0; }
+ static intptr_t InstanceSize() { return 0; }
+ static const ObjectKind kInstanceKind = kFreeListElement;
+ static bool IsInstance() { return true; }
Ivan Posva 2012/06/08 12:50:20 private: DISALLOW_ALLOCATION(); DISALLOW_IMPLI
Vyacheslav Egorov (Google) 2012/06/08 12:58:27 Did private: DISALLOW_ALLOCATION(); DISALLOW_
+ };
+
private:
// This layout mirrors the layout of RawObject.
- uword next_;
- intptr_t size_;
+ uword tags_;
+ FreeListElement* next_;
+
+ // Returns the address of the embedded size.
+ intptr_t* SizeAddress() const {
+ uword addr = reinterpret_cast<uword>(&next_) + kWordSize;
+ return reinterpret_cast<intptr_t*>(addr);
+ }
// FreeListElements cannot be allocated. Instead references to them are
// created using the AsElement factory method.
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/freelist.cc » ('j') | runtime/vm/raw_object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698