OLD | NEW |
(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 void SetCapacityAndMaxSerial(int32_t capacity, int32_t max_serial); |
| 39 |
| 40 ObjectIdRing(Isolate* isolate, int32_t capacity); |
| 41 Isolate* isolate_; |
| 42 RawObject** table_; |
| 43 int32_t max_serial_; |
| 44 int32_t capacity_; |
| 45 int32_t serial_num_; |
| 46 bool wrapped_; |
| 47 |
| 48 RawObject** table() { |
| 49 return table_; |
| 50 } |
| 51 int32_t table_size() { |
| 52 return capacity_; |
| 53 } |
| 54 |
| 55 int32_t NextSerial(); |
| 56 int32_t AllocateNewId(RawObject* object); |
| 57 int32_t IndexOfId(int32_t id); |
| 58 bool IsValidContiguous(int32_t id); |
| 59 bool IsValidId(int32_t id); |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(ObjectIdRing); |
| 62 }; |
| 63 |
| 64 } // namespace dart |
| 65 |
| 66 #endif // VM_OBJECT_ID_RING_H_ |
OLD | NEW |