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

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

Issue 2912863006: Inline instance object hash code into object header on 64 bit. (Closed)
Patch Set: Add assembler tests and other feedback from Ryan Created 3 years, 6 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
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/simulator_arm64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "vm/raw_object.h" 5 #include "vm/raw_object.h"
6 6
7 #include "vm/become.h" 7 #include "vm/become.h"
8 #include "vm/class_table.h" 8 #include "vm/class_table.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/freelist.h" 10 #include "vm/freelist.h"
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 // All Smi values are valid. 24 // All Smi values are valid.
25 if (!IsHeapObject()) { 25 if (!IsHeapObject()) {
26 return; 26 return;
27 } 27 }
28 // Slightly more readable than a segfault. 28 // Slightly more readable than a segfault.
29 if (this == reinterpret_cast<RawObject*>(kHeapObjectTag)) { 29 if (this == reinterpret_cast<RawObject*>(kHeapObjectTag)) {
30 FATAL("RAW_NULL encountered"); 30 FATAL("RAW_NULL encountered");
31 } 31 }
32 // Validate that the tags_ field is sensible. 32 // Validate that the tags_ field is sensible.
33 uword tags = ptr()->tags_; 33 uint32_t tags = ptr()->tags_;
34 intptr_t reserved = ReservedBits::decode(tags); 34 intptr_t reserved = ReservedBits::decode(tags);
35 if (reserved != 0) { 35 if (reserved != 0) {
36 FATAL1("Invalid tags field encountered %#" Px "\n", tags); 36 FATAL1("Invalid tags field encountered %x\n", tags);
37 } 37 }
38 intptr_t class_id = ClassIdTag::decode(tags); 38 intptr_t class_id = ClassIdTag::decode(tags);
39 if (!isolate->class_table()->IsValidIndex(class_id)) { 39 if (!isolate->class_table()->IsValidIndex(class_id)) {
40 FATAL1("Invalid class id encountered %" Pd "\n", class_id); 40 FATAL1("Invalid class id encountered %" Pd "\n", class_id);
41 } 41 }
42 if ((class_id == kNullCid) && 42 if ((class_id == kNullCid) &&
43 (isolate->class_table()->At(class_id) == NULL)) { 43 (isolate->class_table()->At(class_id) == NULL)) {
44 // Null class not yet initialized; skip. 44 // Null class not yet initialized; skip.
45 return; 45 return;
46 } 46 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 break; 178 break;
179 } 179 }
180 default: { 180 default: {
181 // Get the (constant) instance size out of the class object. 181 // Get the (constant) instance size out of the class object.
182 // TODO(koda): Add Size(ClassTable*) interface to allow caching in loops. 182 // TODO(koda): Add Size(ClassTable*) interface to allow caching in loops.
183 Isolate* isolate = Isolate::Current(); 183 Isolate* isolate = Isolate::Current();
184 #if defined(DEBUG) 184 #if defined(DEBUG)
185 ClassTable* class_table = isolate->class_table(); 185 ClassTable* class_table = isolate->class_table();
186 if (!class_table->IsValidIndex(class_id) || 186 if (!class_table->IsValidIndex(class_id) ||
187 !class_table->HasValidClassAt(class_id)) { 187 !class_table->HasValidClassAt(class_id)) {
188 FATAL2("Invalid class id: %" Pd " from tags %" Px "\n", class_id, 188 FATAL2("Invalid class id: %" Pd " from tags %x\n", class_id,
189 ptr()->tags_); 189 ptr()->tags_);
190 } 190 }
191 #endif // DEBUG 191 #endif // DEBUG
192 RawClass* raw_class = isolate->GetClassForHeapWalkAt(class_id); 192 RawClass* raw_class = isolate->GetClassForHeapWalkAt(class_id);
193 instance_size = raw_class->ptr()->instance_size_in_words_ 193 instance_size = raw_class->ptr()->instance_size_in_words_
194 << kWordSizeLog2; 194 << kWordSizeLog2;
195 } 195 }
196 } 196 }
197 ASSERT(instance_size != 0); 197 ASSERT(instance_size != 0);
198 #if defined(DEBUG) 198 #if defined(DEBUG)
199 uword tags = ptr()->tags_; 199 uint32_t tags = ptr()->tags_;
200 intptr_t tags_size = SizeTag::decode(tags); 200 intptr_t tags_size = SizeTag::decode(tags);
201 if ((class_id == kArrayCid) && (instance_size > tags_size && tags_size > 0)) { 201 if ((class_id == kArrayCid) && (instance_size > tags_size && tags_size > 0)) {
202 // TODO(22501): Array::MakeArray could be in the process of shrinking 202 // TODO(22501): Array::MakeArray could be in the process of shrinking
203 // the array (see comment therein), having already updated the tags but not 203 // the array (see comment therein), having already updated the tags but not
204 // yet set the new length. Wait a millisecond and try again. 204 // yet set the new length. Wait a millisecond and try again.
205 int retries_remaining = 1000; // ... but not forever. 205 int retries_remaining = 1000; // ... but not forever.
206 do { 206 do {
207 OS::Sleep(1); 207 OS::Sleep(1);
208 const RawArray* raw_array = reinterpret_cast<const RawArray*>(this); 208 const RawArray* raw_array = reinterpret_cast<const RawArray*>(this);
209 intptr_t array_length = Smi::Value(raw_array->ptr()->length_); 209 intptr_t array_length = Smi::Value(raw_array->ptr()->length_);
210 instance_size = Array::InstanceSize(array_length); 210 instance_size = Array::InstanceSize(array_length);
211 } while ((instance_size > tags_size) && (--retries_remaining > 0)); 211 } while ((instance_size > tags_size) && (--retries_remaining > 0));
212 } 212 }
213 if ((instance_size != tags_size) && (tags_size != 0)) { 213 if ((instance_size != tags_size) && (tags_size != 0)) {
214 FATAL3("Size mismatch: %" Pd " from class vs %" Pd " from tags %" Px "\n", 214 FATAL3("Size mismatch: %" Pd " from class vs %" Pd " from tags %x\n",
215 instance_size, tags_size, tags); 215 instance_size, tags_size, tags);
216 } 216 }
217 #endif // DEBUG 217 #endif // DEBUG
218 return instance_size; 218 return instance_size;
219 } 219 }
220 220
221 221
222 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { 222 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) {
223 intptr_t size = 0; 223 intptr_t size = 0;
224 224
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 522
523 523
524 intptr_t RawNamespace::VisitNamespacePointers(RawNamespace* raw_obj, 524 intptr_t RawNamespace::VisitNamespacePointers(RawNamespace* raw_obj,
525 ObjectPointerVisitor* visitor) { 525 ObjectPointerVisitor* visitor) {
526 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 526 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
527 return Namespace::InstanceSize(); 527 return Namespace::InstanceSize();
528 } 528 }
529 529
530 530
531 bool RawCode::ContainsPC(RawObject* raw_obj, uword pc) { 531 bool RawCode::ContainsPC(RawObject* raw_obj, uword pc) {
532 uword tags = raw_obj->ptr()->tags_; 532 uint32_t tags = raw_obj->ptr()->tags_;
533 if (RawObject::ClassIdTag::decode(tags) == kCodeCid) { 533 if (RawObject::ClassIdTag::decode(tags) == kCodeCid) {
534 RawCode* raw_code = reinterpret_cast<RawCode*>(raw_obj); 534 RawCode* raw_code = reinterpret_cast<RawCode*>(raw_obj);
535 return RawInstructions::ContainsPC(raw_code->ptr()->instructions_, pc); 535 return RawInstructions::ContainsPC(raw_code->ptr()->instructions_, pc);
536 } 536 }
537 return false; 537 return false;
538 } 538 }
539 539
540 540
541 intptr_t RawCode::VisitCodePointers(RawCode* raw_obj, 541 intptr_t RawCode::VisitCodePointers(RawCode* raw_obj,
542 ObjectPointerVisitor* visitor) { 542 ObjectPointerVisitor* visitor) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 ObjectPointerVisitor* visitor) { 735 ObjectPointerVisitor* visitor) {
736 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 736 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
737 return UnwindError::InstanceSize(); 737 return UnwindError::InstanceSize();
738 } 738 }
739 739
740 740
741 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj, 741 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj,
742 ObjectPointerVisitor* visitor) { 742 ObjectPointerVisitor* visitor) {
743 // Make sure that we got here with the tagged pointer as this. 743 // Make sure that we got here with the tagged pointer as this.
744 ASSERT(raw_obj->IsHeapObject()); 744 ASSERT(raw_obj->IsHeapObject());
745 uword tags = raw_obj->ptr()->tags_; 745 uint32_t tags = raw_obj->ptr()->tags_;
746 intptr_t instance_size = SizeTag::decode(tags); 746 intptr_t instance_size = SizeTag::decode(tags);
747 if (instance_size == 0) { 747 if (instance_size == 0) {
748 RawClass* cls = 748 RawClass* cls =
749 visitor->isolate()->GetClassForHeapWalkAt(raw_obj->GetClassId()); 749 visitor->isolate()->GetClassForHeapWalkAt(raw_obj->GetClassId());
750 instance_size = cls->ptr()->instance_size_in_words_ << kWordSizeLog2; 750 instance_size = cls->ptr()->instance_size_in_words_ << kWordSizeLog2;
751 } 751 }
752 752
753 // Calculate the first and last raw object pointer fields. 753 // Calculate the first and last raw object pointer fields.
754 uword obj_addr = RawObject::ToAddr(raw_obj); 754 uword obj_addr = RawObject::ToAddr(raw_obj);
755 uword from = obj_addr + sizeof(RawObject); 755 uword from = obj_addr + sizeof(RawObject);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 intptr_t RawUserTag::VisitUserTagPointers(RawUserTag* raw_obj, 1008 intptr_t RawUserTag::VisitUserTagPointers(RawUserTag* raw_obj,
1009 ObjectPointerVisitor* visitor) { 1009 ObjectPointerVisitor* visitor) {
1010 // Make sure that we got here with the tagged pointer as this. 1010 // Make sure that we got here with the tagged pointer as this.
1011 ASSERT(raw_obj->IsHeapObject()); 1011 ASSERT(raw_obj->IsHeapObject());
1012 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 1012 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
1013 return UserTag::InstanceSize(); 1013 return UserTag::InstanceSize();
1014 } 1014 }
1015 1015
1016 1016
1017 } // namespace dart 1017 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/simulator_arm64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698