| OLD | NEW |
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 #error RAW_NULL should not be defined. | 91 #error RAW_NULL should not be defined. |
| 92 #endif | 92 #endif |
| 93 #define RAW_NULL kHeapObjectTag | 93 #define RAW_NULL kHeapObjectTag |
| 94 Object* Object::null_object_ = NULL; | 94 Object* Object::null_object_ = NULL; |
| 95 Array* Object::null_array_ = NULL; | 95 Array* Object::null_array_ = NULL; |
| 96 String* Object::null_string_ = NULL; | 96 String* Object::null_string_ = NULL; |
| 97 Instance* Object::null_instance_ = NULL; | 97 Instance* Object::null_instance_ = NULL; |
| 98 TypeArguments* Object::null_type_arguments_ = NULL; | 98 TypeArguments* Object::null_type_arguments_ = NULL; |
| 99 Array* Object::empty_array_ = NULL; | 99 Array* Object::empty_array_ = NULL; |
| 100 Array* Object::zero_array_ = NULL; | 100 Array* Object::zero_array_ = NULL; |
| 101 ContextScope* Object::empty_context_scope_ = NULL; |
| 101 ObjectPool* Object::empty_object_pool_ = NULL; | 102 ObjectPool* Object::empty_object_pool_ = NULL; |
| 102 PcDescriptors* Object::empty_descriptors_ = NULL; | 103 PcDescriptors* Object::empty_descriptors_ = NULL; |
| 103 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; | 104 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; |
| 104 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; | 105 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; |
| 105 Array* Object::extractor_parameter_types_ = NULL; | 106 Array* Object::extractor_parameter_types_ = NULL; |
| 106 Array* Object::extractor_parameter_names_ = NULL; | 107 Array* Object::extractor_parameter_names_ = NULL; |
| 107 Instance* Object::sentinel_ = NULL; | 108 Instance* Object::sentinel_ = NULL; |
| 108 Instance* Object::transition_sentinel_ = NULL; | 109 Instance* Object::transition_sentinel_ = NULL; |
| 109 Instance* Object::unknown_constant_ = NULL; | 110 Instance* Object::unknown_constant_ = NULL; |
| 110 Instance* Object::non_constant_ = NULL; | 111 Instance* Object::non_constant_ = NULL; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 Heap* heap = isolate->heap(); | 421 Heap* heap = isolate->heap(); |
| 421 | 422 |
| 422 // Allocate the read only object handles here. | 423 // Allocate the read only object handles here. |
| 423 null_object_ = Object::ReadOnlyHandle(); | 424 null_object_ = Object::ReadOnlyHandle(); |
| 424 null_array_ = Array::ReadOnlyHandle(); | 425 null_array_ = Array::ReadOnlyHandle(); |
| 425 null_string_ = String::ReadOnlyHandle(); | 426 null_string_ = String::ReadOnlyHandle(); |
| 426 null_instance_ = Instance::ReadOnlyHandle(); | 427 null_instance_ = Instance::ReadOnlyHandle(); |
| 427 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); | 428 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); |
| 428 empty_array_ = Array::ReadOnlyHandle(); | 429 empty_array_ = Array::ReadOnlyHandle(); |
| 429 zero_array_ = Array::ReadOnlyHandle(); | 430 zero_array_ = Array::ReadOnlyHandle(); |
| 431 empty_context_scope_ = ContextScope::ReadOnlyHandle(); |
| 430 empty_object_pool_ = ObjectPool::ReadOnlyHandle(); | 432 empty_object_pool_ = ObjectPool::ReadOnlyHandle(); |
| 431 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); | 433 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); |
| 432 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); | 434 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); |
| 433 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); | 435 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); |
| 434 extractor_parameter_types_ = Array::ReadOnlyHandle(); | 436 extractor_parameter_types_ = Array::ReadOnlyHandle(); |
| 435 extractor_parameter_names_ = Array::ReadOnlyHandle(); | 437 extractor_parameter_names_ = Array::ReadOnlyHandle(); |
| 436 sentinel_ = Instance::ReadOnlyHandle(); | 438 sentinel_ = Instance::ReadOnlyHandle(); |
| 437 transition_sentinel_ = Instance::ReadOnlyHandle(); | 439 transition_sentinel_ = Instance::ReadOnlyHandle(); |
| 438 unknown_constant_ = Instance::ReadOnlyHandle(); | 440 unknown_constant_ = Instance::ReadOnlyHandle(); |
| 439 non_constant_ = Instance::ReadOnlyHandle(); | 441 non_constant_ = Instance::ReadOnlyHandle(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 uword address = heap->Allocate(Array::InstanceSize(1), Heap::kOld); | 651 uword address = heap->Allocate(Array::InstanceSize(1), Heap::kOld); |
| 650 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(1), true); | 652 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(1), true); |
| 651 Array::initializeHandle( | 653 Array::initializeHandle( |
| 652 zero_array_, | 654 zero_array_, |
| 653 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | 655 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
| 654 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); | 656 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); |
| 655 smi = Smi::New(0); | 657 smi = Smi::New(0); |
| 656 zero_array_->SetAt(0, smi); | 658 zero_array_->SetAt(0, smi); |
| 657 } | 659 } |
| 658 | 660 |
| 661 // Allocate and initialize the canonical empty context scope object. |
| 662 { |
| 663 uword address = heap->Allocate(ContextScope::InstanceSize(0), Heap::kOld); |
| 664 InitializeObject(address, |
| 665 kContextScopeCid, |
| 666 ContextScope::InstanceSize(0), |
| 667 true); |
| 668 ContextScope::initializeHandle( |
| 669 empty_context_scope_, |
| 670 reinterpret_cast<RawContextScope*>(address + kHeapObjectTag)); |
| 671 empty_context_scope_->StoreNonPointer( |
| 672 &empty_context_scope_->raw_ptr()->num_variables_, 0); |
| 673 empty_context_scope_->StoreNonPointer( |
| 674 &empty_context_scope_->raw_ptr()->is_implicit_, true); |
| 675 } |
| 676 |
| 659 // Allocate and initialize the canonical empty object pool object. | 677 // Allocate and initialize the canonical empty object pool object. |
| 660 { | 678 { |
| 661 uword address = | 679 uword address = |
| 662 heap->Allocate(ObjectPool::InstanceSize(0), Heap::kOld); | 680 heap->Allocate(ObjectPool::InstanceSize(0), Heap::kOld); |
| 663 InitializeObject(address, | 681 InitializeObject(address, |
| 664 kObjectPoolCid, | 682 kObjectPoolCid, |
| 665 ObjectPool::InstanceSize(0), | 683 ObjectPool::InstanceSize(0), |
| 666 true); | 684 true); |
| 667 ObjectPool::initializeHandle( | 685 ObjectPool::initializeHandle( |
| 668 empty_object_pool_, | 686 empty_object_pool_, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 ASSERT(!null_string_->IsSmi()); | 787 ASSERT(!null_string_->IsSmi()); |
| 770 ASSERT(null_string_->IsString()); | 788 ASSERT(null_string_->IsString()); |
| 771 ASSERT(!null_instance_->IsSmi()); | 789 ASSERT(!null_instance_->IsSmi()); |
| 772 ASSERT(null_instance_->IsInstance()); | 790 ASSERT(null_instance_->IsInstance()); |
| 773 ASSERT(!null_type_arguments_->IsSmi()); | 791 ASSERT(!null_type_arguments_->IsSmi()); |
| 774 ASSERT(null_type_arguments_->IsTypeArguments()); | 792 ASSERT(null_type_arguments_->IsTypeArguments()); |
| 775 ASSERT(!empty_array_->IsSmi()); | 793 ASSERT(!empty_array_->IsSmi()); |
| 776 ASSERT(empty_array_->IsArray()); | 794 ASSERT(empty_array_->IsArray()); |
| 777 ASSERT(!zero_array_->IsSmi()); | 795 ASSERT(!zero_array_->IsSmi()); |
| 778 ASSERT(zero_array_->IsArray()); | 796 ASSERT(zero_array_->IsArray()); |
| 797 ASSERT(!empty_context_scope_->IsSmi()); |
| 798 ASSERT(empty_context_scope_->IsContextScope()); |
| 779 ASSERT(!empty_descriptors_->IsSmi()); | 799 ASSERT(!empty_descriptors_->IsSmi()); |
| 780 ASSERT(empty_descriptors_->IsPcDescriptors()); | 800 ASSERT(empty_descriptors_->IsPcDescriptors()); |
| 781 ASSERT(!empty_var_descriptors_->IsSmi()); | 801 ASSERT(!empty_var_descriptors_->IsSmi()); |
| 782 ASSERT(empty_var_descriptors_->IsLocalVarDescriptors()); | 802 ASSERT(empty_var_descriptors_->IsLocalVarDescriptors()); |
| 783 ASSERT(!empty_exception_handlers_->IsSmi()); | 803 ASSERT(!empty_exception_handlers_->IsSmi()); |
| 784 ASSERT(empty_exception_handlers_->IsExceptionHandlers()); | 804 ASSERT(empty_exception_handlers_->IsExceptionHandlers()); |
| 785 ASSERT(!sentinel_->IsSmi()); | 805 ASSERT(!sentinel_->IsSmi()); |
| 786 ASSERT(sentinel_->IsInstance()); | 806 ASSERT(sentinel_->IsInstance()); |
| 787 ASSERT(!transition_sentinel_->IsSmi()); | 807 ASSERT(!transition_sentinel_->IsSmi()); |
| 788 ASSERT(transition_sentinel_->IsInstance()); | 808 ASSERT(transition_sentinel_->IsInstance()); |
| (...skipping 5595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6384 if (implicit_closure_function() != Function::null()) { | 6404 if (implicit_closure_function() != Function::null()) { |
| 6385 return implicit_closure_function(); | 6405 return implicit_closure_function(); |
| 6386 } | 6406 } |
| 6387 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); | 6407 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); |
| 6388 // Create closure function. | 6408 // Create closure function. |
| 6389 const String& closure_name = String::Handle(name()); | 6409 const String& closure_name = String::Handle(name()); |
| 6390 const Function& closure_function = Function::Handle( | 6410 const Function& closure_function = Function::Handle( |
| 6391 NewClosureFunction(closure_name, *this, token_pos())); | 6411 NewClosureFunction(closure_name, *this, token_pos())); |
| 6392 | 6412 |
| 6393 // Set closure function's context scope. | 6413 // Set closure function's context scope. |
| 6394 ContextScope& context_scope = ContextScope::Handle(); | |
| 6395 if (is_static()) { | 6414 if (is_static()) { |
| 6396 context_scope = ContextScope::New(0); | 6415 closure_function.set_context_scope(Object::empty_context_scope()); |
| 6397 } else { | 6416 } else { |
| 6398 context_scope = LocalScope::CreateImplicitClosureScope(*this); | 6417 const ContextScope& context_scope = |
| 6418 ContextScope::Handle(LocalScope::CreateImplicitClosureScope(*this)); |
| 6419 closure_function.set_context_scope(context_scope); |
| 6399 } | 6420 } |
| 6400 closure_function.set_context_scope(context_scope); | |
| 6401 | 6421 |
| 6402 // Set closure function's result type to this result type. | 6422 // Set closure function's result type to this result type. |
| 6403 closure_function.set_result_type(AbstractType::Handle(result_type())); | 6423 closure_function.set_result_type(AbstractType::Handle(result_type())); |
| 6404 | 6424 |
| 6405 // Set closure function's end token to this end token. | 6425 // Set closure function's end token to this end token. |
| 6406 closure_function.set_end_token_pos(end_token_pos()); | 6426 closure_function.set_end_token_pos(end_token_pos()); |
| 6407 | 6427 |
| 6408 // The closurized method stub just calls into the original method and should | 6428 // The closurized method stub just calls into the original method and should |
| 6409 // therefore be skipped by the debugger and in stack traces. | 6429 // therefore be skipped by the debugger and in stack traces. |
| 6410 closure_function.set_is_debuggable(false); | 6430 closure_function.set_is_debuggable(false); |
| (...skipping 7163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13574 JSONArray jsarr(&jsobj, "variables"); | 13594 JSONArray jsarr(&jsobj, "variables"); |
| 13575 Object& var = Object::Handle(); | 13595 Object& var = Object::Handle(); |
| 13576 for (intptr_t index = 0; index < num_variables(); index++) { | 13596 for (intptr_t index = 0; index < num_variables(); index++) { |
| 13577 var = At(index); | 13597 var = At(index); |
| 13578 JSONObject jselement(&jsarr); | 13598 JSONObject jselement(&jsarr); |
| 13579 jselement.AddProperty("value", var); | 13599 jselement.AddProperty("value", var); |
| 13580 } | 13600 } |
| 13581 } | 13601 } |
| 13582 | 13602 |
| 13583 | 13603 |
| 13584 RawContextScope* ContextScope::New(intptr_t num_variables) { | 13604 RawContextScope* ContextScope::New(intptr_t num_variables, bool is_implicit) { |
| 13585 ASSERT(Object::context_scope_class() != Class::null()); | 13605 ASSERT(Object::context_scope_class() != Class::null()); |
| 13586 if (num_variables < 0 || num_variables > kMaxElements) { | 13606 if (num_variables < 0 || num_variables > kMaxElements) { |
| 13587 // This should be caught before we reach here. | 13607 // This should be caught before we reach here. |
| 13588 FATAL1("Fatal error in ContextScope::New: invalid num_variables %" Pd "\n", | 13608 FATAL1("Fatal error in ContextScope::New: invalid num_variables %" Pd "\n", |
| 13589 num_variables); | 13609 num_variables); |
| 13590 } | 13610 } |
| 13591 intptr_t size = ContextScope::InstanceSize(num_variables); | 13611 intptr_t size = ContextScope::InstanceSize(num_variables); |
| 13592 ContextScope& result = ContextScope::Handle(); | 13612 ContextScope& result = ContextScope::Handle(); |
| 13593 { | 13613 { |
| 13594 RawObject* raw = Object::Allocate(ContextScope::kClassId, | 13614 RawObject* raw = Object::Allocate(ContextScope::kClassId, |
| 13595 size, | 13615 size, |
| 13596 Heap::kOld); | 13616 Heap::kOld); |
| 13597 NoSafepointScope no_safepoint; | 13617 NoSafepointScope no_safepoint; |
| 13598 result ^= raw; | 13618 result ^= raw; |
| 13599 result.set_num_variables(num_variables); | 13619 result.set_num_variables(num_variables); |
| 13620 result.set_is_implicit(is_implicit); |
| 13600 } | 13621 } |
| 13601 return result.raw(); | 13622 return result.raw(); |
| 13602 } | 13623 } |
| 13603 | 13624 |
| 13604 | 13625 |
| 13605 intptr_t ContextScope::TokenIndexAt(intptr_t scope_index) const { | 13626 intptr_t ContextScope::TokenIndexAt(intptr_t scope_index) const { |
| 13606 return Smi::Value(VariableDescAddr(scope_index)->token_pos); | 13627 return Smi::Value(VariableDescAddr(scope_index)->token_pos); |
| 13607 } | 13628 } |
| 13608 | 13629 |
| 13609 | 13630 |
| (...skipping 7859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21469 return tag_label.ToCString(); | 21490 return tag_label.ToCString(); |
| 21470 } | 21491 } |
| 21471 | 21492 |
| 21472 | 21493 |
| 21473 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21494 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21474 Instance::PrintJSONImpl(stream, ref); | 21495 Instance::PrintJSONImpl(stream, ref); |
| 21475 } | 21496 } |
| 21476 | 21497 |
| 21477 | 21498 |
| 21478 } // namespace dart | 21499 } // namespace dart |
| OLD | NEW |