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 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/dart_api_state.h" | 6 #include "vm/dart_api_state.h" |
7 #include "vm/object_id_ring.h" | 7 #include "vm/object_id_ring.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
11 void ObjectIdRing::Init(Isolate* isolate, int32_t capacity) { | 11 void ObjectIdRing::Init(Isolate* isolate, int32_t capacity) { |
12 ObjectIdRing* ring = new ObjectIdRing(isolate, capacity); | 12 ObjectIdRing* ring = new ObjectIdRing(isolate, capacity); |
13 isolate->set_object_id_ring(ring); | 13 isolate->set_object_id_ring(ring); |
14 } | 14 } |
15 | 15 |
16 | 16 |
17 ObjectIdRing::~ObjectIdRing() { | 17 ObjectIdRing::~ObjectIdRing() { |
18 ASSERT(table_ != NULL); | 18 ASSERT(table_ != NULL); |
19 free(table_); | 19 free(table_); |
20 table_ = NULL; | 20 table_ = NULL; |
21 if (isolate_ != NULL) { | 21 if (isolate_ != NULL) { |
22 isolate_->set_object_id_ring(NULL); | 22 isolate_->set_object_id_ring(NULL); |
23 isolate_ = NULL; | 23 isolate_ = NULL; |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 int32_t ObjectIdRing::GetIdForObject(RawObject* object) { | 28 int32_t ObjectIdRing::GetIdForObject(RawObject* object) { |
| 29 // We do not allow inserting null because null is how we detect as entry was |
| 30 // reclaimed by the GC. |
| 31 ASSERT(object != Object::null()); |
29 return AllocateNewId(object); | 32 return AllocateNewId(object); |
30 } | 33 } |
31 | 34 |
32 | 35 |
33 RawObject* ObjectIdRing::GetObjectForId(int32_t id) { | 36 RawObject* ObjectIdRing::GetObjectForId(int32_t id, LookupResult* kind) { |
34 int32_t index = IndexOfId(id); | 37 int32_t index = IndexOfId(id); |
35 if (index == kInvalidId) { | 38 if (index == kInvalidId) { |
36 // Return sentinel to allow caller to distinguish expired ids. | 39 *kind = kExpired; |
37 return Object::sentinel().raw(); | 40 return Object::null(); |
38 } | 41 } |
39 ASSERT(index >= 0); | 42 ASSERT(index >= 0); |
40 ASSERT(index < capacity_); | 43 ASSERT(index < capacity_); |
| 44 if (table_[index] == Object::null()) { |
| 45 *kind = kCollected; |
| 46 return Object::null(); |
| 47 } |
| 48 *kind = kValid; |
41 return table_[index]; | 49 return table_[index]; |
42 } | 50 } |
43 | 51 |
44 | 52 |
45 void ObjectIdRing::VisitPointers(ObjectPointerVisitor* visitor) { | 53 void ObjectIdRing::VisitPointers(ObjectPointerVisitor* visitor) { |
46 ASSERT(table_ != NULL); | 54 ASSERT(table_ != NULL); |
47 visitor->VisitPointers(table_, capacity_); | 55 visitor->VisitPointers(table_, capacity_); |
48 } | 56 } |
49 | 57 |
50 | 58 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const int32_t max_serial_num = max_serial_; | 167 const int32_t max_serial_num = max_serial_; |
160 const int32_t bottom = max_serial_num - (capacity_ - serial_num_); | 168 const int32_t bottom = max_serial_num - (capacity_ - serial_num_); |
161 return id >= bottom && bottom < max_serial_num; | 169 return id >= bottom && bottom < max_serial_num; |
162 } | 170 } |
163 } | 171 } |
164 ASSERT(wrapped_ == false); | 172 ASSERT(wrapped_ == false); |
165 return IsValidContiguous(id); | 173 return IsValidContiguous(id); |
166 } | 174 } |
167 | 175 |
168 } // namespace dart | 176 } // namespace dart |
OLD | NEW |