OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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_OBJECT_ID_RING_H_ | 5 #ifndef VM_OBJECT_ID_RING_H_ |
6 #define VM_OBJECT_ID_RING_H_ | 6 #define VM_OBJECT_ID_RING_H_ |
7 | 7 |
8 namespace dart { | 8 namespace dart { |
9 | 9 |
10 // Forward declarations. | 10 // Forward declarations. |
11 class RawObject; | 11 class RawObject; |
12 class Isolate; | 12 class Isolate; |
13 class ObjectPointerVisitor; | 13 class ObjectPointerVisitor; |
14 | 14 |
15 // A ring buffer of object pointers that have been given an id. An object | 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 | 16 // may be pointed to by multiple ids. Objects contained in the ring will |
17 // be preserved across scavenges but not old space collections. | 17 // be preserved across scavenges but not old space collections. |
18 // When the ring buffer wraps around older objects will be replaced and their | 18 // When the ring buffer wraps around older objects will be replaced and their |
19 // ids will be invalidated. | 19 // ids will be invalidated. |
20 class ObjectIdRing { | 20 class ObjectIdRing { |
21 public: | 21 public: |
| 22 enum LookupResult { |
| 23 kValid = 0, |
| 24 kInvalid, // Malformed ring id (used in service.cc). |
| 25 kCollected, // Entry was reclaimed due to a full GC (entries are weak). |
| 26 kExpired, // Entry was evicted during an insertion into a full ring. |
| 27 }; |
| 28 |
22 static const int32_t kMaxId = 0x3FFFFFFF; | 29 static const int32_t kMaxId = 0x3FFFFFFF; |
23 static const int32_t kInvalidId = -1; | 30 static const int32_t kInvalidId = -1; |
24 static const int32_t kDefaultCapacity = 1024; | 31 static const int32_t kDefaultCapacity = 1024; |
25 | 32 |
26 static void Init(Isolate* isolate, int32_t capacity = kDefaultCapacity); | 33 static void Init(Isolate* isolate, int32_t capacity = kDefaultCapacity); |
27 | 34 |
28 ~ObjectIdRing(); | 35 ~ObjectIdRing(); |
29 | 36 |
| 37 // Adds the argument to the ring and returns its id. Note we do not allow |
| 38 // adding Object::null(). |
30 int32_t GetIdForObject(RawObject* raw_obj); | 39 int32_t GetIdForObject(RawObject* raw_obj); |
31 | 40 |
32 // Returns Object::sentinel() when the id is not valid. | 41 // Returns Object::null() when the result is not kValid. |
33 RawObject* GetObjectForId(int32_t id); | 42 RawObject* GetObjectForId(int32_t id, LookupResult* kind); |
34 | 43 |
35 void VisitPointers(ObjectPointerVisitor* visitor); | 44 void VisitPointers(ObjectPointerVisitor* visitor); |
36 | 45 |
37 private: | 46 private: |
38 friend class ObjectIdRingTestHelper; | 47 friend class ObjectIdRingTestHelper; |
39 | 48 |
40 void SetCapacityAndMaxSerial(int32_t capacity, int32_t max_serial); | 49 void SetCapacityAndMaxSerial(int32_t capacity, int32_t max_serial); |
41 | 50 |
42 ObjectIdRing(Isolate* isolate, int32_t capacity); | 51 ObjectIdRing(Isolate* isolate, int32_t capacity); |
43 Isolate* isolate_; | 52 Isolate* isolate_; |
(...skipping 15 matching lines...) Expand all Loading... |
59 int32_t IndexOfId(int32_t id); | 68 int32_t IndexOfId(int32_t id); |
60 bool IsValidContiguous(int32_t id); | 69 bool IsValidContiguous(int32_t id); |
61 bool IsValidId(int32_t id); | 70 bool IsValidId(int32_t id); |
62 | 71 |
63 DISALLOW_COPY_AND_ASSIGN(ObjectIdRing); | 72 DISALLOW_COPY_AND_ASSIGN(ObjectIdRing); |
64 }; | 73 }; |
65 | 74 |
66 } // namespace dart | 75 } // namespace dart |
67 | 76 |
68 #endif // VM_OBJECT_ID_RING_H_ | 77 #endif // VM_OBJECT_ID_RING_H_ |
OLD | NEW |