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

Side by Side Diff: runtime/vm/object_id_ring.cc

Issue 501583007: Treat null like the object it is in the Observatory and Service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
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 or any of the psuedo-nulls because the are
30 // used as sentinel values for expired and reclaimed entries.
31 ASSERT(!object->IsNullOrPseudoNull());
turnidge 2014/08/27 16:13:56 Technically we could allow null to be inserted now
rmacnak 2014/08/27 18:09:59 No, the regular null is how we know an entry was c
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) {
37 *kind = kValid;
34 int32_t index = IndexOfId(id); 38 int32_t index = IndexOfId(id);
35 if (index == kInvalidId) { 39 if (index == kInvalidId) {
36 // Return sentinel to allow caller to distinguish expired ids. 40 *kind = kExpired;
37 return Object::sentinel().raw(); 41 return Object::null();
38 } 42 }
39 ASSERT(index >= 0); 43 ASSERT(index >= 0);
40 ASSERT(index < capacity_); 44 ASSERT(index < capacity_);
45 if (table_[index] == Object::null()) {
46 *kind = kCollected;
47 }
41 return table_[index]; 48 return table_[index];
42 } 49 }
43 50
44 51
45 void ObjectIdRing::VisitPointers(ObjectPointerVisitor* visitor) { 52 void ObjectIdRing::VisitPointers(ObjectPointerVisitor* visitor) {
46 ASSERT(table_ != NULL); 53 ASSERT(table_ != NULL);
47 visitor->VisitPointers(table_, capacity_); 54 visitor->VisitPointers(table_, capacity_);
48 } 55 }
49 56
50 57
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 const int32_t max_serial_num = max_serial_; 166 const int32_t max_serial_num = max_serial_;
160 const int32_t bottom = max_serial_num - (capacity_ - serial_num_); 167 const int32_t bottom = max_serial_num - (capacity_ - serial_num_);
161 return id >= bottom && bottom < max_serial_num; 168 return id >= bottom && bottom < max_serial_num;
162 } 169 }
163 } 170 }
164 ASSERT(wrapped_ == false); 171 ASSERT(wrapped_ == false);
165 return IsValidContiguous(id); 172 return IsValidContiguous(id);
166 } 173 }
167 174
168 } // namespace dart 175 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698