| 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 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 const Class& cls_; | 2881 const Class& cls_; |
| 2882 DISALLOW_COPY_AND_ASSIGN(CHACodeArray); | 2882 DISALLOW_COPY_AND_ASSIGN(CHACodeArray); |
| 2883 }; | 2883 }; |
| 2884 | 2884 |
| 2885 | 2885 |
| 2886 void Class::RegisterCHACode(const Code& code) { | 2886 void Class::RegisterCHACode(const Code& code) { |
| 2887 if (FLAG_trace_cha) { | 2887 if (FLAG_trace_cha) { |
| 2888 THR_Print("RegisterCHACode %s class %s\n", | 2888 THR_Print("RegisterCHACode %s class %s\n", |
| 2889 Function::Handle(code.function()).ToQualifiedCString(), ToCString()); | 2889 Function::Handle(code.function()).ToQualifiedCString(), ToCString()); |
| 2890 } | 2890 } |
| 2891 ASSERT(Thread::Current()->IsMutatorThread()); |
| 2891 ASSERT(code.is_optimized()); | 2892 ASSERT(code.is_optimized()); |
| 2892 CHACodeArray a(*this); | 2893 CHACodeArray a(*this); |
| 2893 a.Register(code); | 2894 a.Register(code); |
| 2894 } | 2895 } |
| 2895 | 2896 |
| 2896 | 2897 |
| 2897 void Class::DisableCHAOptimizedCode() { | 2898 void Class::DisableCHAOptimizedCode() { |
| 2899 ASSERT(Thread::Current()->IsMutatorThread()); |
| 2898 CHACodeArray a(*this); | 2900 CHACodeArray a(*this); |
| 2899 a.DisableCode(); | 2901 a.DisableCode(); |
| 2900 } | 2902 } |
| 2901 | 2903 |
| 2902 | 2904 |
| 2903 bool Class::TraceAllocation(Isolate* isolate) const { | 2905 bool Class::TraceAllocation(Isolate* isolate) const { |
| 2904 ClassTable* class_table = isolate->class_table(); | 2906 ClassTable* class_table = isolate->class_table(); |
| 2905 return class_table->TraceAllocationFor(id()); | 2907 return class_table->TraceAllocationFor(id()); |
| 2906 } | 2908 } |
| 2907 | 2909 |
| (...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5346 } | 5348 } |
| 5347 | 5349 |
| 5348 | 5350 |
| 5349 bool Function::HasBreakpoint() const { | 5351 bool Function::HasBreakpoint() const { |
| 5350 Thread* thread = Thread::Current(); | 5352 Thread* thread = Thread::Current(); |
| 5351 return thread->isolate()->debugger()->HasBreakpoint(*this, thread->zone()); | 5353 return thread->isolate()->debugger()->HasBreakpoint(*this, thread->zone()); |
| 5352 } | 5354 } |
| 5353 | 5355 |
| 5354 | 5356 |
| 5355 void Function::InstallOptimizedCode(const Code& code, bool is_osr) const { | 5357 void Function::InstallOptimizedCode(const Code& code, bool is_osr) const { |
| 5358 ASSERT(Thread::Current()->IsMutatorThread()); |
| 5356 // We may not have previous code if 'always_optimize' is set. | 5359 // We may not have previous code if 'always_optimize' is set. |
| 5357 if (!is_osr && HasCode()) { | 5360 if (!is_osr && HasCode()) { |
| 5358 Code::Handle(CurrentCode()).DisableDartCode(); | 5361 Code::Handle(CurrentCode()).DisableDartCode(); |
| 5359 } | 5362 } |
| 5360 AttachCode(code); | 5363 AttachCode(code); |
| 5361 } | 5364 } |
| 5362 | 5365 |
| 5363 | 5366 |
| 5364 void Function::SetInstructions(const Code& value) const { | 5367 void Function::SetInstructions(const Code& value) const { |
| 5365 ASSERT(Thread::Current()->IsMutatorThread()); | 5368 ASSERT(Thread::Current()->IsMutatorThread()); |
| 5366 SetInstructionsSafe(value); | 5369 SetInstructionsSafe(value); |
| 5367 } | 5370 } |
| 5368 | 5371 |
| 5369 | 5372 |
| 5370 void Function::SetInstructionsSafe(const Code& value) const { | 5373 void Function::SetInstructionsSafe(const Code& value) const { |
| 5371 StorePointer(&raw_ptr()->code_, value.raw()); | 5374 StorePointer(&raw_ptr()->code_, value.raw()); |
| 5372 StoreNonPointer(&raw_ptr()->entry_point_, value.EntryPoint()); | 5375 StoreNonPointer(&raw_ptr()->entry_point_, value.EntryPoint()); |
| 5373 } | 5376 } |
| 5374 | 5377 |
| 5375 | 5378 |
| 5376 void Function::AttachCode(const Code& value) const { | 5379 void Function::AttachCode(const Code& value) const { |
| 5380 ASSERT(Thread::Current()->IsMutatorThread()); |
| 5377 // Finish setting up code before activating it. | 5381 // Finish setting up code before activating it. |
| 5378 value.set_owner(*this); | 5382 value.set_owner(*this); |
| 5379 SetInstructions(value); | 5383 SetInstructions(value); |
| 5380 ASSERT(Function::Handle(value.function()).IsNull() || | 5384 ASSERT(Function::Handle(value.function()).IsNull() || |
| 5381 (value.function() == this->raw())); | 5385 (value.function() == this->raw())); |
| 5382 } | 5386 } |
| 5383 | 5387 |
| 5384 | 5388 |
| 5385 bool Function::HasCode() const { | 5389 bool Function::HasCode() const { |
| 5386 ASSERT(raw_ptr()->code_ != Code::null()); | 5390 ASSERT(raw_ptr()->code_ != Code::null()); |
| 5387 return raw_ptr()->code_ != StubCode::LazyCompile_entry()->code(); | 5391 return raw_ptr()->code_ != StubCode::LazyCompile_entry()->code(); |
| 5388 } | 5392 } |
| 5389 | 5393 |
| 5390 | 5394 |
| 5391 void Function::ClearCode() const { | 5395 void Function::ClearCode() const { |
| 5396 ASSERT(Thread::Current()->IsMutatorThread()); |
| 5392 ASSERT((usage_counter() != 0) || (ic_data_array() == Array::null())); | 5397 ASSERT((usage_counter() != 0) || (ic_data_array() == Array::null())); |
| 5393 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); | 5398 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); |
| 5394 SetInstructions(Code::Handle(StubCode::LazyCompile_entry()->code())); | 5399 SetInstructions(Code::Handle(StubCode::LazyCompile_entry()->code())); |
| 5395 } | 5400 } |
| 5396 | 5401 |
| 5397 | 5402 |
| 5398 void Function::SwitchToUnoptimizedCode() const { | 5403 void Function::SwitchToUnoptimizedCode() const { |
| 5399 ASSERT(HasOptimizedCode()); | 5404 ASSERT(HasOptimizedCode()); |
| 5400 Thread* thread = Thread::Current(); | 5405 Thread* thread = Thread::Current(); |
| 5401 Isolate* isolate = thread->isolate(); | 5406 Isolate* isolate = thread->isolate(); |
| 5402 Zone* zone = thread->zone(); | 5407 Zone* zone = thread->zone(); |
| 5408 ASSERT(thread->IsMutatorThread()); |
| 5403 const Code& current_code = Code::Handle(zone, CurrentCode()); | 5409 const Code& current_code = Code::Handle(zone, CurrentCode()); |
| 5404 | 5410 |
| 5405 if (FLAG_trace_deoptimization_verbose) { | 5411 if (FLAG_trace_deoptimization_verbose) { |
| 5406 THR_Print("Disabling optimized code: '%s' entry: %#" Px "\n", | 5412 THR_Print("Disabling optimized code: '%s' entry: %#" Px "\n", |
| 5407 ToFullyQualifiedCString(), | 5413 ToFullyQualifiedCString(), |
| 5408 current_code.EntryPoint()); | 5414 current_code.EntryPoint()); |
| 5409 } | 5415 } |
| 5410 current_code.DisableDartCode(); | 5416 current_code.DisableDartCode(); |
| 5411 const Error& error = Error::Handle(zone, | 5417 const Error& error = Error::Handle(zone, |
| 5412 Compiler::EnsureUnoptimizedCode(thread, *this)); | 5418 Compiler::EnsureUnoptimizedCode(thread, *this)); |
| 5413 if (!error.IsNull()) { | 5419 if (!error.IsNull()) { |
| 5414 Exceptions::PropagateError(error); | 5420 Exceptions::PropagateError(error); |
| 5415 } | 5421 } |
| 5416 const Code& unopt_code = Code::Handle(zone, unoptimized_code()); | 5422 const Code& unopt_code = Code::Handle(zone, unoptimized_code()); |
| 5417 AttachCode(unopt_code); | 5423 AttachCode(unopt_code); |
| 5418 unopt_code.Enable(); | 5424 unopt_code.Enable(); |
| 5419 isolate->TrackDeoptimizedCode(current_code); | 5425 isolate->TrackDeoptimizedCode(current_code); |
| 5420 } | 5426 } |
| 5421 | 5427 |
| 5422 | 5428 |
| 5423 void Function::set_unoptimized_code(const Code& value) const { | 5429 void Function::set_unoptimized_code(const Code& value) const { |
| 5430 ASSERT(Thread::Current()->IsMutatorThread()); |
| 5424 ASSERT(value.IsNull() || !value.is_optimized()); | 5431 ASSERT(value.IsNull() || !value.is_optimized()); |
| 5425 StorePointer(&raw_ptr()->unoptimized_code_, value.raw()); | 5432 StorePointer(&raw_ptr()->unoptimized_code_, value.raw()); |
| 5426 } | 5433 } |
| 5427 | 5434 |
| 5428 | 5435 |
| 5429 RawContextScope* Function::context_scope() const { | 5436 RawContextScope* Function::context_scope() const { |
| 5430 if (IsClosureFunction()) { | 5437 if (IsClosureFunction()) { |
| 5431 const Object& obj = Object::Handle(raw_ptr()->data_); | 5438 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5432 ASSERT(!obj.IsNull()); | 5439 ASSERT(!obj.IsNull()); |
| 5433 return ClosureData::Cast(obj).context_scope(); | 5440 return ClosureData::Cast(obj).context_scope(); |
| (...skipping 2324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7758 Isolate::Current()->IncrFieldInvalidationGen(); | 7765 Isolate::Current()->IncrFieldInvalidationGen(); |
| 7759 } | 7766 } |
| 7760 | 7767 |
| 7761 private: | 7768 private: |
| 7762 const Field& field_; | 7769 const Field& field_; |
| 7763 DISALLOW_COPY_AND_ASSIGN(FieldDependentArray); | 7770 DISALLOW_COPY_AND_ASSIGN(FieldDependentArray); |
| 7764 }; | 7771 }; |
| 7765 | 7772 |
| 7766 | 7773 |
| 7767 void Field::RegisterDependentCode(const Code& code) const { | 7774 void Field::RegisterDependentCode(const Code& code) const { |
| 7775 ASSERT(Thread::Current()->IsMutatorThread()); |
| 7768 ASSERT(code.is_optimized()); | 7776 ASSERT(code.is_optimized()); |
| 7769 FieldDependentArray a(*this); | 7777 FieldDependentArray a(*this); |
| 7770 a.Register(code); | 7778 a.Register(code); |
| 7771 } | 7779 } |
| 7772 | 7780 |
| 7773 | 7781 |
| 7774 void Field::DeoptimizeDependentCode() const { | 7782 void Field::DeoptimizeDependentCode() const { |
| 7783 ASSERT(Thread::Current()->IsMutatorThread()); |
| 7775 FieldDependentArray a(*this); | 7784 FieldDependentArray a(*this); |
| 7776 a.DisableCode(); | 7785 a.DisableCode(); |
| 7777 } | 7786 } |
| 7778 | 7787 |
| 7779 | 7788 |
| 7780 bool Field::IsUninitialized() const { | 7789 bool Field::IsUninitialized() const { |
| 7781 const Instance& value = Instance::Handle(raw_ptr()->value_.static_value_); | 7790 const Instance& value = Instance::Handle(raw_ptr()->value_.static_value_); |
| 7782 ASSERT(value.raw() != Object::transition_sentinel().raw()); | 7791 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 7783 return value.raw() == Object::sentinel().raw(); | 7792 return value.raw() == Object::sentinel().raw(); |
| 7784 } | 7793 } |
| (...skipping 5762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13547 } | 13556 } |
| 13548 | 13557 |
| 13549 | 13558 |
| 13550 bool Code::IsFunctionCode() const { | 13559 bool Code::IsFunctionCode() const { |
| 13551 const Object& obj = Object::Handle(owner()); | 13560 const Object& obj = Object::Handle(owner()); |
| 13552 return obj.IsFunction(); | 13561 return obj.IsFunction(); |
| 13553 } | 13562 } |
| 13554 | 13563 |
| 13555 | 13564 |
| 13556 void Code::DisableDartCode() const { | 13565 void Code::DisableDartCode() const { |
| 13566 ASSERT(Thread::Current()->IsMutatorThread()); |
| 13557 ASSERT(IsFunctionCode()); | 13567 ASSERT(IsFunctionCode()); |
| 13558 ASSERT(instructions() == active_instructions()); | 13568 ASSERT(instructions() == active_instructions()); |
| 13559 const Code& new_code = | 13569 const Code& new_code = |
| 13560 Code::Handle(StubCode::FixCallersTarget_entry()->code()); | 13570 Code::Handle(StubCode::FixCallersTarget_entry()->code()); |
| 13561 set_active_instructions(new_code.instructions()); | 13571 set_active_instructions(new_code.instructions()); |
| 13562 } | 13572 } |
| 13563 | 13573 |
| 13564 | 13574 |
| 13565 void Code::DisableStubCode() const { | 13575 void Code::DisableStubCode() const { |
| 13566 ASSERT(IsAllocationStubCode()); | 13576 ASSERT(Thread::Current()->IsMutatorThread()); |
| 13577 ASSERT(IsAllocationStubCode()); |
| 13567 ASSERT(instructions() == active_instructions()); | 13578 ASSERT(instructions() == active_instructions()); |
| 13568 const Code& new_code = | 13579 const Code& new_code = |
| 13569 Code::Handle(StubCode::FixAllocationStubTarget_entry()->code()); | 13580 Code::Handle(StubCode::FixAllocationStubTarget_entry()->code()); |
| 13570 set_active_instructions(new_code.instructions()); | 13581 set_active_instructions(new_code.instructions()); |
| 13571 } | 13582 } |
| 13572 | 13583 |
| 13573 | 13584 |
| 13574 void Code::PrintJSONImpl(JSONStream* stream, bool ref) const { | 13585 void Code::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 13575 JSONObject jsobj(stream); | 13586 JSONObject jsobj(stream); |
| 13576 AddCommonObjectProperties(&jsobj, "Code", ref); | 13587 AddCommonObjectProperties(&jsobj, "Code", ref); |
| (...skipping 8304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21881 return tag_label.ToCString(); | 21892 return tag_label.ToCString(); |
| 21882 } | 21893 } |
| 21883 | 21894 |
| 21884 | 21895 |
| 21885 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21896 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21886 Instance::PrintJSONImpl(stream, ref); | 21897 Instance::PrintJSONImpl(stream, ref); |
| 21887 } | 21898 } |
| 21888 | 21899 |
| 21889 | 21900 |
| 21890 } // namespace dart | 21901 } // namespace dart |
| OLD | NEW |