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 |
| 14 // A ring buffer of object pointers that have been given an id. An object |
| 15 // may be pointed to by multiple ids. Objects contained in the ring will |
| 16 // be preserved across scavenges but not old space collections. |
| 17 // When the ring buffer wraps around older objects will be replaced and their |
| 18 // ids will be invalidated. |
| 19 class ObjectIdRing { |
| 20 public: |
| 21 static const intptr_t kInvalidId = -1; |
| 22 static const intptr_t kDefaultCapacity = 1024; |
| 23 |
| 24 static void Init(Isolate* isolate, intptr_t capacity = kDefaultCapacity); |
| 25 |
| 26 ~ObjectIdRing(); |
| 27 |
| 28 intptr_t GetIdForObject(RawObject* raw_obj); |
| 29 RawObject* GetObjectForId(intptr_t id); |
| 30 |
| 31 private: |
| 32 friend class Isolate; |
| 33 friend class ObjectIdRingTestHelper; |
| 34 |
| 35 ObjectIdRing(Isolate* isolate, intptr_t capacity); |
| 36 Isolate* isolate_; |
| 37 RawObject** table_; |
| 38 intptr_t max_serial_; |
| 39 intptr_t capacity_; |
| 40 intptr_t serial_num_; |
| 41 bool wrapped_; |
| 42 |
| 43 intptr_t NextSerial(); |
| 44 intptr_t AllocateNewId(RawObject* object); |
| 45 intptr_t IndexOfId(intptr_t id); |
| 46 bool IsValidContiguous(intptr_t id); |
| 47 bool IsValidId(intptr_t id); |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(ObjectIdRing); |
| 50 }; |
| 51 |
| 52 } // namespace dart |
| 53 |
| 54 #endif // VM_OBJECT_ID_RING_H_ |
OLD | NEW |