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

Unified Diff: runtime/vm/object_id_ring.h

Issue 18259014: Object ID Ring with tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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/object_id_ring.h
diff --git a/runtime/vm/object_id_ring.h b/runtime/vm/object_id_ring.h
new file mode 100644
index 0000000000000000000000000000000000000000..f03097cfb10cd71e5bd47c4443d71d7618f46aa1
--- /dev/null
+++ b/runtime/vm/object_id_ring.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef VM_OBJECT_ID_RING_H_
+#define VM_OBJECT_ID_RING_H_
+
+namespace dart {
+
+// Forward declarations.
+class RawObject;
+class Isolate;
+
+// A ring buffer of object pointers that have been given an id. An object
+// may be pointed to by multiple ids. Objects contained in the ring will
+// be preserved across scavenges but not old space collections.
+// When the ring buffer wraps around older objects will be replaced and their
+// ids will be invalidated.
+class ObjectIdRing {
+ public:
+ static const intptr_t kInvalidId = -1;
+ static const intptr_t kDefaultCapacity = 1024;
+
+ static void Init(Isolate* isolate, intptr_t capacity = kDefaultCapacity);
+
+ ~ObjectIdRing();
+
+ intptr_t GetIdForObject(RawObject* raw_obj);
+ RawObject* GetObjectForId(intptr_t id);
+
+ private:
+ friend class Isolate;
+ friend class ObjectIdRingTestHelper;
+
+ ObjectIdRing(Isolate* isolate, intptr_t capacity);
+ Isolate* isolate_;
+ RawObject** table_;
+ intptr_t max_serial_;
+ intptr_t capacity_;
+ intptr_t serial_num_;
+ bool wrapped_;
+
+ intptr_t NextSerial();
+ intptr_t AllocateNewId(RawObject* object);
+ intptr_t IndexOfId(intptr_t id);
+ bool IsValidContiguous(intptr_t id);
+ bool IsValidId(intptr_t id);
+
+ DISALLOW_COPY_AND_ASSIGN(ObjectIdRing);
+};
+
+} // namespace dart
+
+#endif // VM_OBJECT_ID_RING_H_

Powered by Google App Engine
This is Rietveld 408576698