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

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

Issue 15689012: More cleanup to avoid creation of redundant handles (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 cpp_vtable Object::handle_vtable_ = 0; 63 cpp_vtable Object::handle_vtable_ = 0;
64 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; 64 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 };
65 cpp_vtable Smi::handle_vtable_ = 0; 65 cpp_vtable Smi::handle_vtable_ = 0;
66 66
67 // These are initialized to a value that will force a illegal memory access if 67 // These are initialized to a value that will force a illegal memory access if
68 // they are being used. 68 // they are being used.
69 #if defined(RAW_NULL) 69 #if defined(RAW_NULL)
70 #error RAW_NULL should not be defined. 70 #error RAW_NULL should not be defined.
71 #endif 71 #endif
72 #define RAW_NULL kHeapObjectTag 72 #define RAW_NULL kHeapObjectTag
73 Object* Object::null_object_ = NULL;
73 Array* Object::empty_array_ = NULL; 74 Array* Object::empty_array_ = NULL;
74 Instance* Object::sentinel_ = NULL; 75 Instance* Object::sentinel_ = NULL;
75 Instance* Object::transition_sentinel_ = NULL; 76 Instance* Object::transition_sentinel_ = NULL;
76 Instance* Object::unknown_constant_ = NULL; 77 Instance* Object::unknown_constant_ = NULL;
77 Instance* Object::non_constant_ = NULL; 78 Instance* Object::non_constant_ = NULL;
78 Bool* Object::bool_true_ = NULL; 79 Bool* Object::bool_true_ = NULL;
79 Bool* Object::bool_false_ = NULL; 80 Bool* Object::bool_false_ = NULL;
81 Smi* Object::sentinel_smi_ = NULL;
80 LanguageError* Object::snapshot_writer_error_ = NULL; 82 LanguageError* Object::snapshot_writer_error_ = NULL;
81 83
82 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); 84 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL);
83 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 85 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
84 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 86 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
85 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 87 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
86 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 88 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
87 RawClass* Object::unresolved_class_class_ = 89 RawClass* Object::unresolved_class_class_ =
88 reinterpret_cast<RawClass*>(RAW_NULL); 90 reinterpret_cast<RawClass*>(RAW_NULL);
89 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 91 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 Object fake_object; 317 Object fake_object;
316 Smi fake_smi; 318 Smi fake_smi;
317 Object::handle_vtable_ = fake_object.vtable(); 319 Object::handle_vtable_ = fake_object.vtable();
318 Smi::handle_vtable_ = fake_smi.vtable(); 320 Smi::handle_vtable_ = fake_smi.vtable();
319 } 321 }
320 322
321 Isolate* isolate = Isolate::Current(); 323 Isolate* isolate = Isolate::Current();
322 Heap* heap = isolate->heap(); 324 Heap* heap = isolate->heap();
323 325
324 // Allocate the read only object handles here. 326 // Allocate the read only object handles here.
327 null_object_ = Array::ReadOnlyHandle();
325 empty_array_ = Array::ReadOnlyHandle(); 328 empty_array_ = Array::ReadOnlyHandle();
326 sentinel_ = Instance::ReadOnlyHandle(); 329 sentinel_ = Instance::ReadOnlyHandle();
327 transition_sentinel_ = Instance::ReadOnlyHandle(); 330 transition_sentinel_ = Instance::ReadOnlyHandle();
328 unknown_constant_ = Instance::ReadOnlyHandle(); 331 unknown_constant_ = Instance::ReadOnlyHandle();
329 non_constant_ = Instance::ReadOnlyHandle(); 332 non_constant_ = Instance::ReadOnlyHandle();
330 bool_true_ = Bool::ReadOnlyHandle(); 333 bool_true_ = Bool::ReadOnlyHandle();
331 bool_false_ = Bool::ReadOnlyHandle(); 334 bool_false_ = Bool::ReadOnlyHandle();
335 sentinel_smi_ = Smi::ReadOnlyHandle();
332 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); 336 snapshot_writer_error_ = LanguageError::ReadOnlyHandle();
333 337
334 // Allocate and initialize the null instance. 338 // Allocate and initialize the null instance.
335 // 'null_' must be the first object allocated as it is used in allocation to 339 // 'null_' must be the first object allocated as it is used in allocation to
336 // clear the object. 340 // clear the object.
337 { 341 {
338 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); 342 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld);
339 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); 343 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag);
340 // The call below is using 'null_' to initialize itself. 344 // The call below is using 'null_' to initialize itself.
341 InitializeObject(address, kNullCid, Instance::InstanceSize()); 345 InitializeObject(address, kNullCid, Instance::InstanceSize());
342 } 346 }
343 347
348 *null_object_ = null_;
349
344 // Initialize the empty array handle to null_ in order to be able to check 350 // Initialize the empty array handle to null_ in order to be able to check
345 // if the empty array was allocated (RAW_NULL is not available). 351 // if the empty array was allocated (RAW_NULL is not available).
346 *empty_array_ = Array::null(); 352 *empty_array_ = Array::null();
347 353
348 Class& cls = Class::Handle(); 354 Class& cls = Class::Handle();
349 355
350 // Allocate and initialize the class class. 356 // Allocate and initialize the class class.
351 { 357 {
352 intptr_t size = Class::InstanceSize(); 358 intptr_t size = Class::InstanceSize();
353 uword address = heap->Allocate(size, Heap::kOld); 359 uword address = heap->Allocate(size, Heap::kOld);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); 533 reinterpret_cast<RawArray*>(address + kHeapObjectTag));
528 empty_array_->raw()->ptr()->length_ = Smi::New(0); 534 empty_array_->raw()->ptr()->length_ = Smi::New(0);
529 } 535 }
530 536
531 // Allocate and initialize singleton true and false boolean objects. 537 // Allocate and initialize singleton true and false boolean objects.
532 cls = Class::New<Bool>(); 538 cls = Class::New<Bool>();
533 isolate->object_store()->set_bool_class(cls); 539 isolate->object_store()->set_bool_class(cls);
534 *bool_true_ = Bool::New(true); 540 *bool_true_ = Bool::New(true);
535 *bool_false_ = Bool::New(false); 541 *bool_false_ = Bool::New(false);
536 542
543 *sentinel_smi_ = Smi::New(kIllegalCid);
537 *snapshot_writer_error_ = 544 *snapshot_writer_error_ =
538 LanguageError::New(String::Handle(String::New("SnapshotWriter Error"))); 545 LanguageError::New(String::Handle(String::New("SnapshotWriter Error")));
539 546
547 ASSERT(!null_object_->IsSmi());
540 ASSERT(!empty_array_->IsSmi()); 548 ASSERT(!empty_array_->IsSmi());
541 ASSERT(empty_array_->IsArray()); 549 ASSERT(empty_array_->IsArray());
542 ASSERT(!sentinel_->IsSmi()); 550 ASSERT(!sentinel_->IsSmi());
543 ASSERT(sentinel_->IsInstance()); 551 ASSERT(sentinel_->IsInstance());
544 ASSERT(!transition_sentinel_->IsSmi()); 552 ASSERT(!transition_sentinel_->IsSmi());
545 ASSERT(transition_sentinel_->IsInstance()); 553 ASSERT(transition_sentinel_->IsInstance());
546 ASSERT(!unknown_constant_->IsSmi()); 554 ASSERT(!unknown_constant_->IsSmi());
547 ASSERT(unknown_constant_->IsInstance()); 555 ASSERT(unknown_constant_->IsInstance());
548 ASSERT(!non_constant_->IsSmi()); 556 ASSERT(!non_constant_->IsSmi());
549 ASSERT(non_constant_->IsInstance()); 557 ASSERT(non_constant_->IsInstance());
550 ASSERT(!bool_true_->IsSmi()); 558 ASSERT(!bool_true_->IsSmi());
551 ASSERT(bool_true_->IsBool()); 559 ASSERT(bool_true_->IsBool());
552 ASSERT(!bool_false_->IsSmi()); 560 ASSERT(!bool_false_->IsSmi());
553 ASSERT(bool_false_->IsBool()); 561 ASSERT(bool_false_->IsBool());
562 ASSERT(sentinel_smi_->IsSmi());
554 ASSERT(!snapshot_writer_error_->IsSmi()); 563 ASSERT(!snapshot_writer_error_->IsSmi());
555 ASSERT(snapshot_writer_error_->IsLanguageError()); 564 ASSERT(snapshot_writer_error_->IsLanguageError());
556 } 565 }
557 566
558 567
559 #define SET_CLASS_NAME(class_name, name) \ 568 #define SET_CLASS_NAME(class_name, name) \
560 cls = class_name##_class(); \ 569 cls = class_name##_class(); \
561 cls.set_name(Symbols::name()); \ 570 cls.set_name(Symbols::name()); \
562 571
563 void Object::RegisterSingletonClassNames() { 572 void Object::RegisterSingletonClassNames() {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 // Finish the initialization by compiling the bootstrap scripts containing the 1056 // Finish the initialization by compiling the bootstrap scripts containing the
1048 // base interfaces and the implementation of the internal classes. 1057 // base interfaces and the implementation of the internal classes.
1049 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts()); 1058 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts());
1050 if (!error.IsNull()) { 1059 if (!error.IsNull()) {
1051 return error.raw(); 1060 return error.raw();
1052 } 1061 }
1053 1062
1054 // Remove the Object superclass cycle by setting the super type to null (not 1063 // Remove the Object superclass cycle by setting the super type to null (not
1055 // to the type of null). 1064 // to the type of null).
1056 cls = object_store->object_class(); 1065 cls = object_store->object_class();
1057 cls.set_super_type(Type::Handle()); 1066 cls.set_super_type(Type::null_object());
1058 1067
1059 ClassFinalizer::VerifyBootstrapClasses(); 1068 ClassFinalizer::VerifyBootstrapClasses();
1060 MarkInvisibleFunctions(); 1069 MarkInvisibleFunctions();
1061 1070
1062 // Set up the intrinsic state of all functions (core, math and scalar list). 1071 // Set up the intrinsic state of all functions (core, math and scalar list).
1063 Intrinsifier::InitializeState(); 1072 Intrinsifier::InitializeState();
1064 1073
1065 return Error::null(); 1074 return Error::null();
1066 } 1075 }
1067 1076
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 // No field found. 2582 // No field found.
2574 return Field::null(); 2583 return Field::null();
2575 } 2584 }
2576 2585
2577 2586
2578 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { 2587 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const {
2579 Isolate* isolate = Isolate::Current(); 2588 Isolate* isolate = Isolate::Current();
2580 const Library& lib = Library::Handle(isolate, library()); 2589 const Library& lib = Library::Handle(isolate, library());
2581 const Object& obj = Object::Handle(isolate, lib.LookupLocalObject(name)); 2590 const Object& obj = Object::Handle(isolate, lib.LookupLocalObject(name));
2582 if (!obj.IsNull() && obj.IsLibraryPrefix()) { 2591 if (!obj.IsNull() && obj.IsLibraryPrefix()) {
2583 const LibraryPrefix& lib_prefix = LibraryPrefix::Cast(obj); 2592 return LibraryPrefix::Cast(obj).raw();
2584 return lib_prefix.raw();
2585 } 2593 }
2586 return LibraryPrefix::null(); 2594 return LibraryPrefix::null();
2587 } 2595 }
2588 2596
2589 2597
2590 const char* Class::ToCString() const { 2598 const char* Class::ToCString() const {
2591 const char* format = "%s Class: %s"; 2599 const char* format = "%s Class: %s";
2592 const Library& lib = Library::Handle(library()); 2600 const Library& lib = Library::Handle(library());
2593 const char* library_name = lib.IsNull() ? "" : lib.ToCString(); 2601 const char* library_name = lib.IsNull() ? "" : lib.ToCString();
2594 const char* class_name = String::Handle(Name()).ToCString(); 2602 const char* class_name = String::Handle(Name()).ToCString();
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 3164
3157 static void InsertIntoCanonicalTypeArguments(Isolate* isolate, 3165 static void InsertIntoCanonicalTypeArguments(Isolate* isolate,
3158 const Array& table, 3166 const Array& table,
3159 const TypeArguments& arguments, 3167 const TypeArguments& arguments,
3160 intptr_t index) { 3168 intptr_t index) {
3161 arguments.SetCanonical(); // Mark object as being canonical. 3169 arguments.SetCanonical(); // Mark object as being canonical.
3162 table.SetAt(index, arguments); // Remember the new element. 3170 table.SetAt(index, arguments); // Remember the new element.
3163 // Update used count. 3171 // Update used count.
3164 // Last element of the array is the number of used elements. 3172 // Last element of the array is the number of used elements.
3165 intptr_t table_size = table.Length() - 1; 3173 intptr_t table_size = table.Length() - 1;
3166 Smi& used = Smi::Handle(isolate); 3174 intptr_t used_elements = Smi::Value(Smi::RawCast(table.At(table_size))) + 1;
3167 used ^= table.At(table_size); 3175 const Smi& used = Smi::Handle(isolate, Smi::New(used_elements));
3168 intptr_t used_elements = used.Value() + 1;
3169 used = Smi::New(used_elements);
3170 table.SetAt(table_size, used); 3176 table.SetAt(table_size, used);
3171 3177
3172 // Rehash if table is 75% full. 3178 // Rehash if table is 75% full.
3173 if (used_elements > ((table_size / 4) * 3)) { 3179 if (used_elements > ((table_size / 4) * 3)) {
3174 GrowCanonicalTypeArguments(isolate, table); 3180 GrowCanonicalTypeArguments(isolate, table);
3175 } 3181 }
3176 } 3182 }
3177 3183
3178 3184
3179 static intptr_t FindIndexInCanonicalTypeArguments( 3185 static intptr_t FindIndexInCanonicalTypeArguments(
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
4864 bool is_static, 4870 bool is_static,
4865 bool is_final, 4871 bool is_final,
4866 bool is_const, 4872 bool is_const,
4867 const Class& owner, 4873 const Class& owner,
4868 intptr_t token_pos) { 4874 intptr_t token_pos) {
4869 ASSERT(!owner.IsNull()); 4875 ASSERT(!owner.IsNull());
4870 const Field& result = Field::Handle(Field::New()); 4876 const Field& result = Field::Handle(Field::New());
4871 result.set_name(name); 4877 result.set_name(name);
4872 result.set_is_static(is_static); 4878 result.set_is_static(is_static);
4873 if (is_static) { 4879 if (is_static) {
4874 result.set_value(Instance::Handle()); 4880 result.set_value(Instance::null_object());
4875 } else { 4881 } else {
4876 result.SetOffset(0); 4882 result.SetOffset(0);
4877 } 4883 }
4878 result.set_is_final(is_final); 4884 result.set_is_final(is_final);
4879 result.set_is_const(is_const); 4885 result.set_is_const(is_const);
4880 result.set_owner(owner); 4886 result.set_owner(owner);
4881 result.set_token_pos(token_pos); 4887 result.set_token_pos(token_pos);
4882 result.set_has_initializer(false); 4888 result.set_has_initializer(false);
4883 result.set_guarded_cid(kIllegalCid); 4889 result.set_guarded_cid(kIllegalCid);
4884 result.set_is_nullable(false); 4890 result.set_is_nullable(false);
4885 result.set_dependent_code(Array::Handle()); 4891 result.set_dependent_code(Array::null_object());
4886 return result.raw(); 4892 return result.raw();
4887 } 4893 }
4888 4894
4889 4895
4890 4896
4891 RawField* Field::Clone(const Class& new_owner) const { 4897 RawField* Field::Clone(const Class& new_owner) const {
4892 Field& clone = Field::Handle(); 4898 Field& clone = Field::Handle();
4893 clone ^= Object::Clone(*this, Heap::kOld); 4899 clone ^= Object::Clone(*this, Heap::kOld);
4894 const Class& owner = Class::Handle(this->owner()); 4900 const Class& owner = Class::Handle(this->owner());
4895 const PatchClass& clone_owner = 4901 const PatchClass& clone_owner =
4896 PatchClass::Handle(PatchClass::New(new_owner, owner)); 4902 PatchClass::Handle(PatchClass::New(new_owner, owner));
4897 clone.set_owner(clone_owner); 4903 clone.set_owner(clone_owner);
4898 clone.set_dependent_code(Array::Handle()); 4904 clone.set_dependent_code(Array::null_object());
4899 if (!clone.is_static()) { 4905 if (!clone.is_static()) {
4900 clone.SetOffset(0); 4906 clone.SetOffset(0);
4901 } 4907 }
4902 return clone.raw(); 4908 return clone.raw();
4903 } 4909 }
4904 4910
4905 4911
4906 RawString* Field::UserVisibleName() const { 4912 RawString* Field::UserVisibleName() const {
4907 const String& str = String::Handle(name()); 4913 const String& str = String::Handle(name());
4908 return IdentifierPrettyName(str); 4914 return IdentifierPrettyName(str);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4982 return false; 4988 return false;
4983 } 4989 }
4984 4990
4985 4991
4986 void Field::DeoptimizeDependentCode() const { 4992 void Field::DeoptimizeDependentCode() const {
4987 const Array& code_objects = Array::Handle(dependent_code()); 4993 const Array& code_objects = Array::Handle(dependent_code());
4988 4994
4989 if (code_objects.IsNull()) { 4995 if (code_objects.IsNull()) {
4990 return; 4996 return;
4991 } 4997 }
4992 set_dependent_code(Array::Handle()); 4998 set_dependent_code(Array::null_object());
4993 4999
4994 // Deoptimize all dependent code on the stack. 5000 // Deoptimize all dependent code on the stack.
4995 Code& code = Code::Handle(); 5001 Code& code = Code::Handle();
4996 { 5002 {
4997 DartFrameIterator iterator; 5003 DartFrameIterator iterator;
4998 StackFrame* frame = iterator.NextFrame(); 5004 StackFrame* frame = iterator.NextFrame();
4999 while (frame != NULL) { 5005 while (frame != NULL) {
5000 code = frame->LookupDartCode(); 5006 code = frame->LookupDartCode();
5001 if (IsDependentCode(code_objects, code)) { 5007 if (IsDependentCode(code_objects, code)) {
5002 DeoptimizeAt(code, frame->pc()); 5008 DeoptimizeAt(code, frame->pc());
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
5624 RawString* TokenStream::Iterator::MakeLiteralToken(const Object& obj) const { 5630 RawString* TokenStream::Iterator::MakeLiteralToken(const Object& obj) const {
5625 if (obj.IsString()) { 5631 if (obj.IsString()) {
5626 return reinterpret_cast<RawString*>(obj.raw()); 5632 return reinterpret_cast<RawString*>(obj.raw());
5627 } else if (obj.IsSmi()) { 5633 } else if (obj.IsSmi()) {
5628 Token::Kind kind = static_cast<Token::Kind>( 5634 Token::Kind kind = static_cast<Token::Kind>(
5629 Smi::Value(reinterpret_cast<RawSmi*>(obj.raw()))); 5635 Smi::Value(reinterpret_cast<RawSmi*>(obj.raw())));
5630 ASSERT(kind < Token::kNumTokens); 5636 ASSERT(kind < Token::kNumTokens);
5631 if (Token::IsPseudoKeyword(kind) || Token::IsKeyword(kind)) { 5637 if (Token::IsPseudoKeyword(kind) || Token::IsKeyword(kind)) {
5632 Isolate* isolate = Isolate::Current(); 5638 Isolate* isolate = Isolate::Current();
5633 ObjectStore* object_store = isolate->object_store(); 5639 ObjectStore* object_store = isolate->object_store();
5634 String& str = String::Handle(isolate, String::null());
5635 const Array& symbols = Array::Handle(isolate, 5640 const Array& symbols = Array::Handle(isolate,
5636 object_store->keyword_symbols()); 5641 object_store->keyword_symbols());
5637 ASSERT(!symbols.IsNull()); 5642 ASSERT(!symbols.IsNull());
5638 str ^= symbols.At(kind - Token::kFirstKeyword); 5643 ASSERT(symbols.At(kind - Token::kFirstKeyword) != String::null());
5639 ASSERT(!str.IsNull()); 5644 return String::RawCast(symbols.At(kind - Token::kFirstKeyword));
5640 return str.raw();
5641 } 5645 }
5642 return Symbols::New(Token::Str(kind)); 5646 return Symbols::New(Token::Str(kind));
5643 } else { 5647 } else {
5644 ASSERT(obj.IsLiteralToken()); // Must be a literal token. 5648 ASSERT(obj.IsLiteralToken()); // Must be a literal token.
5645 const LiteralToken& literal_token = LiteralToken::Cast(obj); 5649 const LiteralToken& literal_token = LiteralToken::Cast(obj);
5646 return literal_token.literal(); 5650 return literal_token.literal();
5647 } 5651 }
5648 } 5652 }
5649 5653
5650 5654
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
6014 Object& entry = Object::Handle(); 6018 Object& entry = Object::Handle();
6015 entry = dict.At(index); 6019 entry = dict.At(index);
6016 // An empty spot will be found because we keep the hash set at most 75% full. 6020 // An empty spot will be found because we keep the hash set at most 75% full.
6017 while (!entry.IsNull()) { 6021 while (!entry.IsNull()) {
6018 index = (index + 1) % dict_size; 6022 index = (index + 1) % dict_size;
6019 entry = dict.At(index); 6023 entry = dict.At(index);
6020 } 6024 }
6021 6025
6022 // Insert the object at the empty slot. 6026 // Insert the object at the empty slot.
6023 dict.SetAt(index, obj); 6027 dict.SetAt(index, obj);
6024 Smi& used = Smi::Handle(); 6028 // One more element added.
6025 used ^= dict.At(dict_size); 6029 intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) + 1;
6026 intptr_t used_elements = used.Value() + 1; // One more element added. 6030 const Smi& used = Smi::Handle(Smi::New(used_elements));
6027 used = Smi::New(used_elements);
6028 dict.SetAt(dict_size, used); // Update used count. 6031 dict.SetAt(dict_size, used); // Update used count.
6029 6032
6030 // Rehash if symbol_table is 75% full. 6033 // Rehash if symbol_table is 75% full.
6031 if (used_elements > ((dict_size / 4) * 3)) { 6034 if (used_elements > ((dict_size / 4) * 3)) {
6032 GrowDictionary(dict, dict_size); 6035 GrowDictionary(dict, dict_size);
6033 } 6036 }
6034 6037
6035 // Invalidate the cache of loaded scripts. 6038 // Invalidate the cache of loaded scripts.
6036 if (loaded_scripts() != Array::null()) { 6039 if (loaded_scripts() != Array::null()) {
6037 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); 6040 StorePointer(&raw_ptr()->loaded_scripts_, Array::null());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
6212 (name.CharAt(4) == '_' && 6215 (name.CharAt(4) == '_' &&
6213 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && 6216 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') &&
6214 name.CharAt(1) == 'e' && 6217 name.CharAt(1) == 'e' &&
6215 name.CharAt(2) == 't' && 6218 name.CharAt(2) == 't' &&
6216 name.CharAt(3) == ':')); 6219 name.CharAt(3) == ':'));
6217 } 6220 }
6218 6221
6219 6222
6220 RawField* Library::LookupFieldAllowPrivate(const String& name) const { 6223 RawField* Library::LookupFieldAllowPrivate(const String& name) const {
6221 // First check if name is found in the local scope of the library. 6224 // First check if name is found in the local scope of the library.
6222 Field& field = Field::Handle(LookupLocalField(name)); 6225 Object& obj = Object::Handle(LookupLocalField(name));
6223 if (!field.IsNull()) { 6226 if (!obj.IsNull()) {
6224 return field.raw(); 6227 return Field::Cast(obj).raw();
6225 } 6228 }
6226 6229
6227 // Do not look up private names in imported libraries. 6230 // Do not look up private names in imported libraries.
6228 if (ShouldBePrivate(name)) { 6231 if (ShouldBePrivate(name)) {
6229 return Field::null(); 6232 return Field::null();
6230 } 6233 }
6231 6234
6232 // Now check if name is found in any imported libs. 6235 // Now check if name is found in any imported libs.
6233 const Array& imports = Array::Handle(this->imports()); 6236 const Array& imports = Array::Handle(this->imports());
6234 Namespace& import = Namespace::Handle(); 6237 Namespace& import = Namespace::Handle();
6235 Object& obj = Object::Handle();
6236 for (intptr_t j = 0; j < this->num_imports(); j++) { 6238 for (intptr_t j = 0; j < this->num_imports(); j++) {
6237 import ^= imports.At(j); 6239 import ^= imports.At(j);
6238 obj = import.Lookup(name); 6240 obj = import.Lookup(name);
6239 if (!obj.IsNull() && obj.IsField()) { 6241 if (!obj.IsNull() && obj.IsField()) {
6240 field ^= obj.raw(); 6242 return Field::Cast(obj).raw();
6241 return field.raw();
6242 } 6243 }
6243 } 6244 }
6244 return Field::null(); 6245 return Field::null();
6245 } 6246 }
6246 6247
6247 6248
6248 RawField* Library::LookupLocalField(const String& name) const { 6249 RawField* Library::LookupLocalField(const String& name) const {
6249 Isolate* isolate = Isolate::Current(); 6250 Isolate* isolate = Isolate::Current();
6250 Field& field = Field::Handle(isolate, Field::null()); 6251 Field& field = Field::Handle(isolate, Field::null());
6251 Object& obj = Object::Handle(isolate, Object::null()); 6252 Object& obj = Object::Handle(isolate, Object::null());
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
6402 } 6403 }
6403 return import.library(); 6404 return import.library();
6404 } 6405 }
6405 6406
6406 6407
6407 RawNamespace* Library::ImportAt(intptr_t index) const { 6408 RawNamespace* Library::ImportAt(intptr_t index) const {
6408 if ((index < 0) || index >= num_imports()) { 6409 if ((index < 0) || index >= num_imports()) {
6409 return Namespace::null(); 6410 return Namespace::null();
6410 } 6411 }
6411 const Array& import_list = Array::Handle(imports()); 6412 const Array& import_list = Array::Handle(imports());
6412 Namespace& import = Namespace::Handle(); 6413 return Namespace::RawCast(import_list.At(index));
6413 import ^= import_list.At(index);
6414 return import.raw();
6415 } 6414 }
6416 6415
6417 6416
6418 bool Library::ImportsCorelib() const { 6417 bool Library::ImportsCorelib() const {
6419 Isolate* isolate = Isolate::Current(); 6418 Isolate* isolate = Isolate::Current();
6420 Library& imported = Library::Handle(isolate); 6419 Library& imported = Library::Handle(isolate);
6421 intptr_t count = num_imports(); 6420 intptr_t count = num_imports();
6422 for (int i = 0; i < count; i++) { 6421 for (int i = 0; i < count; i++) {
6423 imported = ImportLibraryAt(i); 6422 imported = ImportLibraryAt(i);
6424 if (imported.IsCoreLibrary()) { 6423 if (imported.IsCoreLibrary()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
6519 result.raw_ptr()->corelib_imported_ = true; 6518 result.raw_ptr()->corelib_imported_ = true;
6520 result.set_debuggable(false); 6519 result.set_debuggable(false);
6521 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 6520 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
6522 result.raw_ptr()->index_ = -1; 6521 result.raw_ptr()->index_ = -1;
6523 result.InitClassDictionary(); 6522 result.InitClassDictionary();
6524 result.InitImportList(); 6523 result.InitImportList();
6525 if (import_core_lib) { 6524 if (import_core_lib) {
6526 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 6525 const Library& core_lib = Library::Handle(Library::CoreLibrary());
6527 ASSERT(!core_lib.IsNull()); 6526 ASSERT(!core_lib.IsNull());
6528 const Namespace& ns = Namespace::Handle( 6527 const Namespace& ns = Namespace::Handle(
6529 Namespace::New(core_lib, Array::Handle(), Array::Handle())); 6528 Namespace::New(core_lib, Array::null_object(), Array::null_object()));
6530 result.AddImport(ns); 6529 result.AddImport(ns);
6531 } 6530 }
6532 return result.raw(); 6531 return result.raw();
6533 } 6532 }
6534 6533
6535 6534
6536 RawLibrary* Library::New(const String& url) { 6535 RawLibrary* Library::New(const String& url) {
6537 return NewLibraryHelper(url, false); 6536 return NewLibraryHelper(url, false);
6538 } 6537 }
6539 6538
6540 6539
6541 void Library::InitCoreLibrary(Isolate* isolate) { 6540 void Library::InitCoreLibrary(Isolate* isolate) {
6542 const String& core_lib_url = Symbols::DartCore(); 6541 const String& core_lib_url = Symbols::DartCore();
6543 const Library& core_lib = 6542 const Library& core_lib =
6544 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); 6543 Library::Handle(Library::NewLibraryHelper(core_lib_url, false));
6545 core_lib.Register(); 6544 core_lib.Register();
6546 isolate->object_store()->set_bootstrap_library(ObjectStore::kCore, core_lib); 6545 isolate->object_store()->set_bootstrap_library(ObjectStore::kCore, core_lib);
6547 isolate->object_store()->set_root_library(Library::Handle()); 6546 isolate->object_store()->set_root_library(Library::null_object());
6548 6547
6549 // Hook up predefined classes without setting their library pointers. These 6548 // Hook up predefined classes without setting their library pointers. These
6550 // classes are coming from the VM isolate, and are shared between multiple 6549 // classes are coming from the VM isolate, and are shared between multiple
6551 // isolates so setting their library pointers would be wrong. 6550 // isolates so setting their library pointers would be wrong.
6552 const Class& cls = Class::Handle(Object::dynamic_class()); 6551 const Class& cls = Class::Handle(Object::dynamic_class());
6553 core_lib.AddObject(cls, String::Handle(cls.Name())); 6552 core_lib.AddObject(cls, String::Handle(cls.Name()));
6554 } 6553 }
6555 6554
6556 6555
6557 void Library::InitNativeWrappersLibrary(Isolate* isolate) { 6556 void Library::InitNativeWrappersLibrary(Isolate* isolate) {
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
7730 7729
7731 intptr_t Code::Comments::Length() const { 7730 intptr_t Code::Comments::Length() const {
7732 if (comments_.IsNull()) { 7731 if (comments_.IsNull()) {
7733 return 0; 7732 return 0;
7734 } 7733 }
7735 return comments_.Length() / kNumberOfEntries; 7734 return comments_.Length() / kNumberOfEntries;
7736 } 7735 }
7737 7736
7738 7737
7739 intptr_t Code::Comments::PCOffsetAt(intptr_t idx) const { 7738 intptr_t Code::Comments::PCOffsetAt(intptr_t idx) const {
7740 Smi& result = Smi::Handle(); 7739 return Smi::Value(Smi::RawCast(
7741 result ^= comments_.At(idx * kNumberOfEntries + kPCOffsetEntry); 7740 comments_.At(idx * kNumberOfEntries + kPCOffsetEntry)));
7742 return result.Value();
7743 } 7741 }
7744 7742
7745 7743
7746 void Code::Comments::SetPCOffsetAt(intptr_t idx, intptr_t pc) { 7744 void Code::Comments::SetPCOffsetAt(intptr_t idx, intptr_t pc) {
7747 comments_.SetAt(idx * kNumberOfEntries + kPCOffsetEntry, 7745 comments_.SetAt(idx * kNumberOfEntries + kPCOffsetEntry,
7748 Smi::Handle(Smi::New(pc))); 7746 Smi::Handle(Smi::New(pc)));
7749 } 7747 }
7750 7748
7751 7749
7752 RawString* Code::Comments::CommentAt(intptr_t idx) const { 7750 RawString* Code::Comments::CommentAt(intptr_t idx) const {
7753 String& result = String::Handle(); 7751 return String::RawCast(comments_.At(idx * kNumberOfEntries + kCommentEntry));
7754 result ^= comments_.At(idx * kNumberOfEntries + kCommentEntry);
7755 return result.raw();
7756 } 7752 }
7757 7753
7758 7754
7759 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) { 7755 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) {
7760 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment); 7756 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment);
7761 } 7757 }
7762 7758
7763 7759
7764 Code::Comments::Comments(const Array& comments) 7760 Code::Comments::Comments(const Array& comments)
7765 : comments_(comments) { 7761 : comments_(comments) {
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
8312 return TestEntryLengthFor(num_args_tested()); 8308 return TestEntryLengthFor(num_args_tested());
8313 } 8309 }
8314 8310
8315 8311
8316 intptr_t ICData::NumberOfChecks() const { 8312 intptr_t ICData::NumberOfChecks() const {
8317 // Do not count the sentinel; 8313 // Do not count the sentinel;
8318 return (Array::Handle(ic_data()).Length() / TestEntryLength()) - 1; 8314 return (Array::Handle(ic_data()).Length() / TestEntryLength()) - 1;
8319 } 8315 }
8320 8316
8321 8317
8322 void ICData::WriteSentinel() const { 8318 void ICData::WriteSentinel(const Array& data) const {
8323 const Smi& sentinel_value = Smi::Handle(Smi::New(kIllegalCid));
8324 const Array& data = Array::Handle(ic_data());
8325 for (intptr_t i = 1; i <= TestEntryLength(); i++) { 8319 for (intptr_t i = 1; i <= TestEntryLength(); i++) {
8326 data.SetAt(data.Length() - i, sentinel_value); 8320 data.SetAt(data.Length() - i, sentinel_smi());
8327 } 8321 }
8328 } 8322 }
8329 8323
8330 8324
8331 #if defined(DEBUG) 8325 #if defined(DEBUG)
8332 // Used in asserts to verify that a check is not added twice. 8326 // Used in asserts to verify that a check is not added twice.
8333 bool ICData::HasCheck(const GrowableArray<intptr_t>& cids) const { 8327 bool ICData::HasCheck(const GrowableArray<intptr_t>& cids) const {
8334 const intptr_t len = NumberOfChecks(); 8328 const intptr_t len = NumberOfChecks();
8335 for (intptr_t i = 0; i < len; i++) { 8329 for (intptr_t i = 0; i < len; i++) {
8336 GrowableArray<intptr_t> class_ids; 8330 GrowableArray<intptr_t> class_ids;
(...skipping 18 matching lines...) Expand all
8355 void ICData::AddCheck(const GrowableArray<intptr_t>& class_ids, 8349 void ICData::AddCheck(const GrowableArray<intptr_t>& class_ids,
8356 const Function& target) const { 8350 const Function& target) const {
8357 DEBUG_ASSERT(!HasCheck(class_ids)); 8351 DEBUG_ASSERT(!HasCheck(class_ids));
8358 ASSERT(num_args_tested() > 1); // Otherwise use 'AddReceiverCheck'. 8352 ASSERT(num_args_tested() > 1); // Otherwise use 'AddReceiverCheck'.
8359 ASSERT(class_ids.length() == num_args_tested()); 8353 ASSERT(class_ids.length() == num_args_tested());
8360 const intptr_t old_num = NumberOfChecks(); 8354 const intptr_t old_num = NumberOfChecks();
8361 Array& data = Array::Handle(ic_data()); 8355 Array& data = Array::Handle(ic_data());
8362 const intptr_t new_len = data.Length() + TestEntryLength(); 8356 const intptr_t new_len = data.Length() + TestEntryLength();
8363 data = Array::Grow(data, new_len, Heap::kOld); 8357 data = Array::Grow(data, new_len, Heap::kOld);
8364 set_ic_data(data); 8358 set_ic_data(data);
8365 WriteSentinel(); 8359 WriteSentinel(data);
8366 intptr_t data_pos = old_num * TestEntryLength(); 8360 intptr_t data_pos = old_num * TestEntryLength();
8361 Smi& value = Smi::Handle();
8367 for (intptr_t i = 0; i < class_ids.length(); i++) { 8362 for (intptr_t i = 0; i < class_ids.length(); i++) {
8368 // kIllegalCid is used as terminating value, do not add it. 8363 // kIllegalCid is used as terminating value, do not add it.
8369 ASSERT(class_ids[i] != kIllegalCid); 8364 ASSERT(class_ids[i] != kIllegalCid);
8370 data.SetAt(data_pos++, Smi::Handle(Smi::New(class_ids[i]))); 8365 value = Smi::New(class_ids[i]);
8366 data.SetAt(data_pos++, value);
8371 } 8367 }
8372 ASSERT(!target.IsNull()); 8368 ASSERT(!target.IsNull());
8373 data.SetAt(data_pos++, target); 8369 data.SetAt(data_pos++, target);
8374 data.SetAt(data_pos, Smi::Handle(Smi::New(1))); 8370 value = Smi::New(1);
8371 data.SetAt(data_pos, value);
8375 } 8372 }
8376 8373
8377 8374
8378 void ICData::AddReceiverCheck(intptr_t receiver_class_id, 8375 void ICData::AddReceiverCheck(intptr_t receiver_class_id,
8379 const Function& target, 8376 const Function& target,
8380 intptr_t count) const { 8377 intptr_t count) const {
8381 #if defined(DEBUG) 8378 #if defined(DEBUG)
8382 GrowableArray<intptr_t> class_ids(1); 8379 GrowableArray<intptr_t> class_ids(1);
8383 class_ids.Add(receiver_class_id); 8380 class_ids.Add(receiver_class_id);
8384 ASSERT(!HasCheck(class_ids)); 8381 ASSERT(!HasCheck(class_ids));
8385 #endif // DEBUG 8382 #endif // DEBUG
8386 ASSERT(num_args_tested() == 1); // Otherwise use 'AddCheck'. 8383 ASSERT(num_args_tested() == 1); // Otherwise use 'AddCheck'.
8387 ASSERT(receiver_class_id != kIllegalCid); 8384 ASSERT(receiver_class_id != kIllegalCid);
8388 8385
8389 const intptr_t old_num = NumberOfChecks(); 8386 const intptr_t old_num = NumberOfChecks();
8390 Array& data = Array::Handle(ic_data()); 8387 Array& data = Array::Handle(ic_data());
8391 const intptr_t new_len = data.Length() + TestEntryLength(); 8388 const intptr_t new_len = data.Length() + TestEntryLength();
8392 data = Array::Grow(data, new_len, Heap::kOld); 8389 data = Array::Grow(data, new_len, Heap::kOld);
8393 set_ic_data(data); 8390 set_ic_data(data);
8394 WriteSentinel(); 8391 WriteSentinel(data);
8395 intptr_t data_pos = old_num * TestEntryLength(); 8392 intptr_t data_pos = old_num * TestEntryLength();
8396 if ((receiver_class_id == kSmiCid) && (data_pos > 0)) { 8393 if ((receiver_class_id == kSmiCid) && (data_pos > 0)) {
8397 ASSERT(GetReceiverClassIdAt(0) != kSmiCid); 8394 ASSERT(GetReceiverClassIdAt(0) != kSmiCid);
8398 // Move class occupying position 0 to the data_pos. 8395 // Move class occupying position 0 to the data_pos.
8399 for (intptr_t i = 0; i < TestEntryLength(); i++) { 8396 for (intptr_t i = 0; i < TestEntryLength(); i++) {
8400 data.SetAt(data_pos + i, Object::Handle(data.At(i))); 8397 data.SetAt(data_pos + i, Object::Handle(data.At(i)));
8401 } 8398 }
8402 // Insert kSmiCid in position 0. 8399 // Insert kSmiCid in position 0.
8403 data_pos = 0; 8400 data_pos = 0;
8404 } 8401 }
8405 data.SetAt(data_pos, Smi::Handle(Smi::New(receiver_class_id))); 8402 data.SetAt(data_pos, Smi::Handle(Smi::New(receiver_class_id)));
8406 data.SetAt(data_pos + 1, target); 8403 data.SetAt(data_pos + 1, target);
8407 data.SetAt(data_pos + 2, Smi::Handle(Smi::New(count))); 8404 data.SetAt(data_pos + 2, Smi::Handle(Smi::New(count)));
8408 } 8405 }
8409 8406
8410 8407
8411 void ICData::GetCheckAt(intptr_t index, 8408 void ICData::GetCheckAt(intptr_t index,
8412 GrowableArray<intptr_t>* class_ids, 8409 GrowableArray<intptr_t>* class_ids,
8413 Function* target) const { 8410 Function* target) const {
8414 ASSERT(index < NumberOfChecks()); 8411 ASSERT(index < NumberOfChecks());
8415 ASSERT(class_ids != NULL); 8412 ASSERT(class_ids != NULL);
8416 ASSERT(target != NULL); 8413 ASSERT(target != NULL);
8417 class_ids->Clear(); 8414 class_ids->Clear();
8418 const Array& data = Array::Handle(ic_data()); 8415 const Array& data = Array::Handle(ic_data());
8419 intptr_t data_pos = index * TestEntryLength(); 8416 intptr_t data_pos = index * TestEntryLength();
8420 Smi& smi = Smi::Handle();
8421 for (intptr_t i = 0; i < num_args_tested(); i++) { 8417 for (intptr_t i = 0; i < num_args_tested(); i++) {
8422 smi ^= data.At(data_pos++); 8418 class_ids->Add(Smi::Value(Smi::RawCast(data.At(data_pos++))));
8423 class_ids->Add(smi.Value());
8424 } 8419 }
8425 (*target) ^= data.At(data_pos++); 8420 (*target) ^= data.At(data_pos++);
8426 } 8421 }
8427 8422
8428 8423
8429 void ICData::GetOneClassCheckAt(intptr_t index, 8424 void ICData::GetOneClassCheckAt(intptr_t index,
8430 intptr_t* class_id, 8425 intptr_t* class_id,
8431 Function* target) const { 8426 Function* target) const {
8432 ASSERT(class_id != NULL); 8427 ASSERT(class_id != NULL);
8433 ASSERT(target != NULL); 8428 ASSERT(target != NULL);
8434 ASSERT(num_args_tested() == 1); 8429 ASSERT(num_args_tested() == 1);
8435 const Array& data = Array::Handle(ic_data()); 8430 const Array& data = Array::Handle(ic_data());
8436 intptr_t data_pos = index * TestEntryLength(); 8431 intptr_t data_pos = index * TestEntryLength();
8437 Smi& smi = Smi::Handle(); 8432 *class_id = Smi::Value(Smi::RawCast(data.At(data_pos)));
8438 smi ^= data.At(data_pos);
8439 *class_id = smi.Value();
8440 *target ^= data.At(data_pos + 1); 8433 *target ^= data.At(data_pos + 1);
8441 } 8434 }
8442 8435
8443 8436
8444 intptr_t ICData::GetClassIdAt(intptr_t index, intptr_t arg_nr) const { 8437 intptr_t ICData::GetClassIdAt(intptr_t index, intptr_t arg_nr) const {
8445 GrowableArray<intptr_t> class_ids; 8438 GrowableArray<intptr_t> class_ids;
8446 Function& target = Function::Handle(); 8439 Function& target = Function::Handle();
8447 GetCheckAt(index, &class_ids, &target); 8440 GetCheckAt(index, &class_ids, &target);
8448 return class_ids[arg_nr]; 8441 return class_ids[arg_nr];
8449 } 8442 }
8450 8443
8451 8444
8452 intptr_t ICData::GetReceiverClassIdAt(intptr_t index) const { 8445 intptr_t ICData::GetReceiverClassIdAt(intptr_t index) const {
8453 ASSERT(index < NumberOfChecks()); 8446 ASSERT(index < NumberOfChecks());
8454 const Array& data = Array::Handle(ic_data()); 8447 const Array& data = Array::Handle(ic_data());
8455 const intptr_t data_pos = index * TestEntryLength(); 8448 const intptr_t data_pos = index * TestEntryLength();
8456 Smi& smi = Smi::Handle(); 8449 return Smi::Value(Smi::RawCast(data.At(data_pos)));
8457 smi ^= data.At(data_pos);
8458 return smi.Value();
8459 } 8450 }
8460 8451
8461 8452
8462 RawFunction* ICData::GetTargetAt(intptr_t index) const { 8453 RawFunction* ICData::GetTargetAt(intptr_t index) const {
8463 const Array& data = Array::Handle(ic_data()); 8454 const Array& data = Array::Handle(ic_data());
8464 const intptr_t data_pos = index * TestEntryLength() + num_args_tested(); 8455 const intptr_t data_pos = index * TestEntryLength() + num_args_tested();
8465 ASSERT(Object::Handle(data.At(data_pos)).IsFunction()); 8456 ASSERT(Object::Handle(data.At(data_pos)).IsFunction());
8466 return reinterpret_cast<RawFunction*>(data.At(data_pos)); 8457 return reinterpret_cast<RawFunction*>(data.At(data_pos));
8467 } 8458 }
8468 8459
(...skipping 13 matching lines...) Expand all
8482 const intptr_t data_pos = index * TestEntryLength() + 8473 const intptr_t data_pos = index * TestEntryLength() +
8483 CountIndexFor(num_args_tested()); 8474 CountIndexFor(num_args_tested());
8484 data.SetAt(data_pos, Smi::Handle(Smi::New(value))); 8475 data.SetAt(data_pos, Smi::Handle(Smi::New(value)));
8485 } 8476 }
8486 8477
8487 8478
8488 intptr_t ICData::GetCountAt(intptr_t index) const { 8479 intptr_t ICData::GetCountAt(intptr_t index) const {
8489 const Array& data = Array::Handle(ic_data()); 8480 const Array& data = Array::Handle(ic_data());
8490 const intptr_t data_pos = index * TestEntryLength() + 8481 const intptr_t data_pos = index * TestEntryLength() +
8491 CountIndexFor(num_args_tested()); 8482 CountIndexFor(num_args_tested());
8492 Smi& smi = Smi::Handle(); 8483 return Smi::Value(Smi::RawCast(data.At(data_pos)));
8493 smi ^= data.At(data_pos);
8494 return smi.Value();
8495 } 8484 }
8496 8485
8497 8486
8498 intptr_t ICData::AggregateCount() const { 8487 intptr_t ICData::AggregateCount() const {
8499 const intptr_t len = NumberOfChecks(); 8488 const intptr_t len = NumberOfChecks();
8500 intptr_t count = 0; 8489 intptr_t count = 0;
8501 for (intptr_t i = 0; i < len; i++) { 8490 for (intptr_t i = 0; i < len; i++) {
8502 count += GetCountAt(i); 8491 count += GetCountAt(i);
8503 } 8492 }
8504 return count; 8493 return count;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
8639 result.set_target_name(target_name); 8628 result.set_target_name(target_name);
8640 result.set_deopt_id(deopt_id); 8629 result.set_deopt_id(deopt_id);
8641 result.set_num_args_tested(num_args_tested); 8630 result.set_num_args_tested(num_args_tested);
8642 result.set_deopt_reason(kDeoptUnknown); 8631 result.set_deopt_reason(kDeoptUnknown);
8643 result.set_is_closure_call(false); 8632 result.set_is_closure_call(false);
8644 // Number of array elements in one test entry. 8633 // Number of array elements in one test entry.
8645 intptr_t len = result.TestEntryLength(); 8634 intptr_t len = result.TestEntryLength();
8646 // IC data array must be null terminated (sentinel entry). 8635 // IC data array must be null terminated (sentinel entry).
8647 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); 8636 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld));
8648 result.set_ic_data(ic_data); 8637 result.set_ic_data(ic_data);
8649 result.WriteSentinel(); 8638 result.WriteSentinel(ic_data);
8650 return result.raw(); 8639 return result.raw();
8651 } 8640 }
8652 8641
8653 8642
8654 RawArray* MegamorphicCache::buckets() const { 8643 RawArray* MegamorphicCache::buckets() const {
8655 return raw_ptr()->buckets_; 8644 return raw_ptr()->buckets_;
8656 } 8645 }
8657 8646
8658 8647
8659 void MegamorphicCache::set_buckets(const Array& buckets) const { 8648 void MegamorphicCache::set_buckets(const Array& buckets) const {
(...skipping 27 matching lines...) Expand all
8687 RawMegamorphicCache* MegamorphicCache::New() { 8676 RawMegamorphicCache* MegamorphicCache::New() {
8688 MegamorphicCache& result = MegamorphicCache::Handle(); 8677 MegamorphicCache& result = MegamorphicCache::Handle();
8689 { RawObject* raw = Object::Allocate(MegamorphicCache::kClassId, 8678 { RawObject* raw = Object::Allocate(MegamorphicCache::kClassId,
8690 MegamorphicCache::InstanceSize(), 8679 MegamorphicCache::InstanceSize(),
8691 Heap::kOld); 8680 Heap::kOld);
8692 NoGCScope no_gc; 8681 NoGCScope no_gc;
8693 result ^= raw; 8682 result ^= raw;
8694 } 8683 }
8695 const intptr_t capacity = kInitialCapacity; 8684 const intptr_t capacity = kInitialCapacity;
8696 const Array& buckets = Array::Handle(Array::New(kEntryLength * capacity)); 8685 const Array& buckets = Array::Handle(Array::New(kEntryLength * capacity));
8697 const Smi& illegal = Smi::Handle(Smi::New(kIllegalCid));
8698 const Function& handler = Function::Handle( 8686 const Function& handler = Function::Handle(
8699 Isolate::Current()->megamorphic_cache_table()->miss_handler()); 8687 Isolate::Current()->megamorphic_cache_table()->miss_handler());
8700 for (intptr_t i = 0; i < capacity; ++i) { 8688 for (intptr_t i = 0; i < capacity; ++i) {
8701 SetEntry(buckets, i, illegal, handler); 8689 SetEntry(buckets, i, sentinel_smi(), handler);
8702 } 8690 }
8703 result.set_buckets(buckets); 8691 result.set_buckets(buckets);
8704 result.set_mask(capacity - 1); 8692 result.set_mask(capacity - 1);
8705 result.set_filled_entry_count(0); 8693 result.set_filled_entry_count(0);
8706 return result.raw(); 8694 return result.raw();
8707 } 8695 }
8708 8696
8709 8697
8710 void MegamorphicCache::EnsureCapacity() const { 8698 void MegamorphicCache::EnsureCapacity() const {
8711 intptr_t old_capacity = mask() + 1; 8699 intptr_t old_capacity = mask() + 1;
8712 double load_limit = kLoadFactor * static_cast<double>(old_capacity); 8700 double load_limit = kLoadFactor * static_cast<double>(old_capacity);
8713 if (static_cast<double>(filled_entry_count() + 1) > load_limit) { 8701 if (static_cast<double>(filled_entry_count() + 1) > load_limit) {
8714 const Array& old_buckets = Array::Handle(buckets()); 8702 const Array& old_buckets = Array::Handle(buckets());
8715 intptr_t new_capacity = old_capacity * 2; 8703 intptr_t new_capacity = old_capacity * 2;
8716 const Array& new_buckets = 8704 const Array& new_buckets =
8717 Array::Handle(Array::New(kEntryLength * new_capacity)); 8705 Array::Handle(Array::New(kEntryLength * new_capacity));
8718 8706
8719 Smi& class_id = Smi::Handle(Smi::New(kIllegalCid));
8720 Function& target = Function::Handle( 8707 Function& target = Function::Handle(
8721 Isolate::Current()->megamorphic_cache_table()->miss_handler()); 8708 Isolate::Current()->megamorphic_cache_table()->miss_handler());
8722 for (intptr_t i = 0; i < new_capacity; ++i) { 8709 for (intptr_t i = 0; i < new_capacity; ++i) {
8723 SetEntry(new_buckets, i, class_id, target); 8710 SetEntry(new_buckets, i, sentinel_smi(), target);
8724 } 8711 }
8725 set_buckets(new_buckets); 8712 set_buckets(new_buckets);
8726 set_mask(new_capacity - 1); 8713 set_mask(new_capacity - 1);
8727 set_filled_entry_count(0); 8714 set_filled_entry_count(0);
8728 8715
8729 // Rehash the valid entries. 8716 // Rehash the valid entries.
8717 Smi& class_id = Smi::Handle();
8730 for (intptr_t i = 0; i < old_capacity; ++i) { 8718 for (intptr_t i = 0; i < old_capacity; ++i) {
8731 class_id ^= GetClassId(old_buckets, i); 8719 class_id ^= GetClassId(old_buckets, i);
8732 if (class_id.Value() != kIllegalCid) { 8720 if (class_id.Value() != kIllegalCid) {
8733 target ^= GetTargetFunction(old_buckets, i); 8721 target ^= GetTargetFunction(old_buckets, i);
8734 Insert(class_id, target); 8722 Insert(class_id, target);
8735 } 8723 }
8736 } 8724 }
8737 } 8725 }
8738 } 8726 }
8739 8727
8740 8728
8741 void MegamorphicCache::Insert(const Smi& class_id, 8729 void MegamorphicCache::Insert(const Smi& class_id,
8742 const Function& target) const { 8730 const Function& target) const {
8743 ASSERT(static_cast<double>(filled_entry_count() + 1) <= 8731 ASSERT(static_cast<double>(filled_entry_count() + 1) <=
8744 (kLoadFactor * static_cast<double>(mask() + 1))); 8732 (kLoadFactor * static_cast<double>(mask() + 1)));
8745 const Array& backing_array = Array::Handle(buckets()); 8733 const Array& backing_array = Array::Handle(buckets());
8746 intptr_t id_mask = mask(); 8734 intptr_t id_mask = mask();
8747 intptr_t index = class_id.Value() & id_mask; 8735 intptr_t index = class_id.Value() & id_mask;
8748 Smi& probe = Smi::Handle();
8749 intptr_t i = index; 8736 intptr_t i = index;
8750 do { 8737 do {
8751 probe ^= GetClassId(backing_array, i); 8738 if (Smi::Value(Smi::RawCast(GetClassId(backing_array, i))) == kIllegalCid) {
8752 if (probe.Value() == kIllegalCid) {
8753 SetEntry(backing_array, i, class_id, target); 8739 SetEntry(backing_array, i, class_id, target);
8754 set_filled_entry_count(filled_entry_count() + 1); 8740 set_filled_entry_count(filled_entry_count() + 1);
8755 return; 8741 return;
8756 } 8742 }
8757 i = (i + 1) & id_mask; 8743 i = (i + 1) & id_mask;
8758 } while (i != index); 8744 } while (i != index);
8759 UNREACHABLE(); 8745 UNREACHABLE();
8760 } 8746 }
8761 8747
8762 8748
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
8815 8801
8816 8802
8817 void SubtypeTestCache::GetCheck( 8803 void SubtypeTestCache::GetCheck(
8818 intptr_t ix, 8804 intptr_t ix,
8819 intptr_t* instance_class_id, 8805 intptr_t* instance_class_id,
8820 AbstractTypeArguments* instance_type_arguments, 8806 AbstractTypeArguments* instance_type_arguments,
8821 AbstractTypeArguments* instantiator_type_arguments, 8807 AbstractTypeArguments* instantiator_type_arguments,
8822 Bool* test_result) const { 8808 Bool* test_result) const {
8823 Array& data = Array::Handle(cache()); 8809 Array& data = Array::Handle(cache());
8824 intptr_t data_pos = ix * kTestEntryLength; 8810 intptr_t data_pos = ix * kTestEntryLength;
8825 Smi& instance_class_id_handle = Smi::Handle(); 8811 *instance_class_id =
8826 instance_class_id_handle ^= data.At(data_pos + kInstanceClassId); 8812 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId)));
8827 *instance_class_id = instance_class_id_handle.Value();
8828 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); 8813 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments);
8829 *instantiator_type_arguments ^= 8814 *instantiator_type_arguments ^=
8830 data.At(data_pos + kInstantiatorTypeArguments); 8815 data.At(data_pos + kInstantiatorTypeArguments);
8831 *test_result ^= data.At(data_pos + kTestResult); 8816 *test_result ^= data.At(data_pos + kTestResult);
8832 } 8817 }
8833 8818
8834 8819
8835 const char* SubtypeTestCache::ToCString() const { 8820 const char* SubtypeTestCache::ToCString() const {
8836 return "SubtypeTestCache"; 8821 return "SubtypeTestCache";
8837 } 8822 }
(...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after
10487 10472
10488 10473
10489 RawInteger* Integer::ArithmeticOp(Token::Kind operation, 10474 RawInteger* Integer::ArithmeticOp(Token::Kind operation,
10490 const Integer& other) const { 10475 const Integer& other) const {
10491 // In 32-bit mode, the result of any operation between two Smis will fit in a 10476 // In 32-bit mode, the result of any operation between two Smis will fit in a
10492 // 32-bit signed result, except the product of two Smis, which will be 64-bit. 10477 // 32-bit signed result, except the product of two Smis, which will be 64-bit.
10493 // In 64-bit mode, the result of any operation between two Smis will fit in a 10478 // In 64-bit mode, the result of any operation between two Smis will fit in a
10494 // 64-bit signed result, except the product of two Smis (unless the Smis are 10479 // 64-bit signed result, except the product of two Smis (unless the Smis are
10495 // 32-bit or less). 10480 // 32-bit or less).
10496 if (IsSmi() && other.IsSmi()) { 10481 if (IsSmi() && other.IsSmi()) {
10497 Smi& left_smi = Smi::Handle(); 10482 const intptr_t left_value = Smi::Value(Smi::RawCast(raw()));
10498 Smi& right_smi = Smi::Handle(); 10483 const intptr_t right_value = Smi::Value(Smi::RawCast(other.raw()));
10499 left_smi ^= raw();
10500 right_smi ^= other.raw();
10501 const intptr_t left_value = left_smi.Value();
10502 const intptr_t right_value = right_smi.Value();
10503 switch (operation) { 10484 switch (operation) {
10504 case Token::kADD: 10485 case Token::kADD:
10505 return Integer::New(left_value + right_value); 10486 return Integer::New(left_value + right_value);
10506 case Token::kSUB: 10487 case Token::kSUB:
10507 return Integer::New(left_value - right_value); 10488 return Integer::New(left_value - right_value);
10508 case Token::kMUL: { 10489 case Token::kMUL: {
10509 if (Smi::kBits < 32) { 10490 if (Smi::kBits < 32) {
10510 // In 32-bit mode, the product of two Smis fits in a 64-bit result. 10491 // In 32-bit mode, the product of two Smis fits in a 64-bit result.
10511 return Integer::New(static_cast<int64_t>(left_value) * 10492 return Integer::New(static_cast<int64_t>(left_value) *
10512 static_cast<int64_t>(right_value)); 10493 static_cast<int64_t>(right_value));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
10585 } 10566 }
10586 10567
10587 10568
10588 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { 10569 static bool Are64bitOperands(const Integer& op1, const Integer& op2) {
10589 return !op1.IsBigint() && !op2.IsBigint(); 10570 return !op1.IsBigint() && !op2.IsBigint();
10590 } 10571 }
10591 10572
10592 10573
10593 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const { 10574 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const {
10594 if (IsSmi() && other.IsSmi()) { 10575 if (IsSmi() && other.IsSmi()) {
10595 Smi& op1 = Smi::Handle(); 10576 intptr_t op1_value = Smi::Value(Smi::RawCast(raw()));
10596 Smi& op2 = Smi::Handle(); 10577 intptr_t op2_value = Smi::Value(Smi::RawCast(other.raw()));
10597 op1 ^= raw();
10598 op2 ^= other.raw();
10599 intptr_t result = 0; 10578 intptr_t result = 0;
10600 switch (kind) { 10579 switch (kind) {
10601 case Token::kBIT_AND: 10580 case Token::kBIT_AND:
10602 result = op1.Value() & op2.Value(); 10581 result = op1_value & op2_value;
10603 break; 10582 break;
10604 case Token::kBIT_OR: 10583 case Token::kBIT_OR:
10605 result = op1.Value() | op2.Value(); 10584 result = op1_value | op2_value;
10606 break; 10585 break;
10607 case Token::kBIT_XOR: 10586 case Token::kBIT_XOR:
10608 result = op1.Value() ^ op2.Value(); 10587 result = op1_value ^ op2_value;
10609 break; 10588 break;
10610 default: 10589 default:
10611 UNIMPLEMENTED(); 10590 UNIMPLEMENTED();
10612 } 10591 }
10613 ASSERT(Smi::IsValid(result)); 10592 ASSERT(Smi::IsValid(result));
10614 return Smi::New(result); 10593 return Smi::New(result);
10615 } else if (Are64bitOperands(*this, other)) { 10594 } else if (Are64bitOperands(*this, other)) {
10616 int64_t a = AsInt64Value(); 10595 int64_t a = AsInt64Value();
10617 int64_t b = other.AsInt64Value(); 10596 int64_t b = other.AsInt64Value();
10618 switch (kind) { 10597 switch (kind) {
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
12578 StorePointer(&(raw_ptr()->data_), new_contents.raw()); 12557 StorePointer(&(raw_ptr()->data_), new_contents.raw());
12579 } 12558 }
12580 12559
12581 12560
12582 RawObject* GrowableObjectArray::RemoveLast() const { 12561 RawObject* GrowableObjectArray::RemoveLast() const {
12583 ASSERT(!IsNull()); 12562 ASSERT(!IsNull());
12584 ASSERT(Length() > 0); 12563 ASSERT(Length() > 0);
12585 intptr_t index = Length() - 1; 12564 intptr_t index = Length() - 1;
12586 const Array& contents = Array::Handle(data()); 12565 const Array& contents = Array::Handle(data());
12587 const Object& obj = Object::Handle(contents.At(index)); 12566 const Object& obj = Object::Handle(contents.At(index));
12588 contents.SetAt(index, Object::Handle()); 12567 contents.SetAt(index, null_object());
12589 SetLength(index); 12568 SetLength(index);
12590 return obj.raw(); 12569 return obj.raw();
12591 } 12570 }
12592 12571
12593 12572
12594 bool GrowableObjectArray::Equals(const Instance& other) const { 12573 bool GrowableObjectArray::Equals(const Instance& other) const {
12595 // If both handles point to the same raw instance they are equal. 12574 // If both handles point to the same raw instance they are equal.
12596 if (this->raw() == other.raw()) { 12575 if (this->raw() == other.raw()) {
12597 return true; 12576 return true;
12598 } 12577 }
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
13320 space); 13299 space);
13321 return reinterpret_cast<RawWeakProperty*>(raw); 13300 return reinterpret_cast<RawWeakProperty*>(raw);
13322 } 13301 }
13323 13302
13324 13303
13325 const char* WeakProperty::ToCString() const { 13304 const char* WeakProperty::ToCString() const {
13326 return "_WeakProperty"; 13305 return "_WeakProperty";
13327 } 13306 }
13328 13307
13329 } // namespace dart 13308 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698