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

Side by Side 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, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 #ifndef VM_OBJECT_ID_RING_H_
6 #define VM_OBJECT_ID_RING_H_
7
8 namespace dart {
9
10 // Forward declarations.
11 class RawObject;
12 class Isolate;
13 class ObjectPointerVisitor;
14
15 // A ring buffer of object pointers that have been given an id. An object
16 // may be pointed to by multiple ids. Objects contained in the ring will
17 // be preserved across scavenges but not old space collections.
18 // When the ring buffer wraps around older objects will be replaced and their
19 // ids will be invalidated.
20 class ObjectIdRing {
21 public:
22 static const int32_t kMaxId = 0x3FFFFFFF;
23 static const int32_t kInvalidId = -1;
24 static const int32_t kDefaultCapacity = 1024;
25
26 static void Init(Isolate* isolate, int32_t capacity = kDefaultCapacity);
27
28 ~ObjectIdRing();
29
30 int32_t GetIdForObject(RawObject* raw_obj);
31 RawObject* GetObjectForId(int32_t id);
32
33 void VisitPointers(ObjectPointerVisitor* visitor);
34
35 private:
36 friend class ObjectIdRingTestHelper;
37
38 ObjectIdRing(Isolate* isolate, int32_t capacity);
39 Isolate* isolate_;
40 RawObject** table_;
41 int32_t max_serial_;
42 int32_t capacity_;
43 int32_t serial_num_;
44 bool wrapped_;
45
46 RawObject** table() {
47 return table_;
48 }
49 int32_t table_size() {
50 return capacity_;
51 }
52
53 int32_t NextSerial();
54 int32_t AllocateNewId(RawObject* object);
55 int32_t IndexOfId(int32_t id);
56 bool IsValidContiguous(int32_t id);
57 bool IsValidId(int32_t id);
58
59 DISALLOW_COPY_AND_ASSIGN(ObjectIdRing);
60 };
61
62 } // namespace dart
63
64 #endif // VM_OBJECT_ID_RING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698