Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index 7484200b7257a5b0881fee51e4894218731bd255..cd0e2fa0acbdd756c6945bb78868dc98e401cd68 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -3227,7 +3227,13 @@ void Function::SetCode(const Code& value) const { |
| void Function::SwitchToUnoptimizedCode() const { |
| ASSERT(HasOptimizedCode()); |
| + |
| const Code& current_code = Code::Handle(CurrentCode()); |
| + |
| + if (PcDescriptors::Handle(current_code.pc_descriptors()).Length() == 0) { |
|
srdjan
2013/03/18 18:54:35
Please add comment what this is for.
Vyacheslav Egorov (Google)
2013/03/18 19:41:18
Done.
|
| + return; |
| + } |
| + |
| if (FLAG_trace_disabling_optimized_code) { |
| OS::Print("Disabling optimized code: '%s' entry: %#"Px"\n", |
| ToFullyQualifiedCString(), |
| @@ -4687,6 +4693,9 @@ RawField* Field::New(const String& name, |
| result.set_owner(owner); |
| result.set_token_pos(token_pos); |
| result.set_has_initializer(false); |
| + result.set_guarded_cid(kIllegalCid); |
| + result.set_is_nullable(false); |
| + result.set_dependent_code(Array::Handle()); |
| return result.raw(); |
| } |
| @@ -4699,6 +4708,7 @@ RawField* Field::Clone(const Class& new_owner) const { |
| const PatchClass& clone_owner = |
| PatchClass::Handle(PatchClass::New(new_owner, owner)); |
| clone.set_owner(clone_owner); |
| + clone.set_dependent_code(Array::Handle()); |
| if (!clone.is_static()) { |
| clone.SetOffset(0); |
| } |
| @@ -4728,6 +4738,128 @@ const char* Field::ToCString() const { |
| } |
| +RawArray* Field::dependent_code() const { |
| + return raw_ptr()->dependent_code_; |
| +} |
| + |
| + |
| +void Field::set_dependent_code(const Array& array) const { |
| + raw_ptr()->dependent_code_ = array.raw(); |
| +} |
| + |
| + |
| +void Field::RegisterDependentCode(const Code& code) const { |
| + const Array& dependent = Array::Handle(dependent_code()); |
| + |
| + if (!dependent.IsNull()) { |
| + WeakProperty& weak_property = WeakProperty::Handle(); |
| + for (intptr_t i = 0; i < dependent.Length(); i++) { |
| + weak_property ^= dependent.At(i); |
| + if (weak_property.key() == Code::null()) { |
| + weak_property.set_key(code); |
| + weak_property.set_value(code); |
| + return; |
| + } |
| + } |
| + } |
| + |
| + const WeakProperty& weak_property = WeakProperty::Handle( |
| + WeakProperty::New(Heap::kOld)); |
| + weak_property.set_key(code); |
| + weak_property.set_value(code); |
| + |
| + intptr_t length = dependent.IsNull() ? 0 : dependent.Length(); |
| + const Array& new_dependent = Array::Handle( |
| + Array::Grow(dependent, length + 1, Heap::kOld)); |
| + new_dependent.SetAt(length, weak_property); |
| + set_dependent_code(new_dependent); |
| +} |
| + |
| + |
| +static bool ShouldDeoptimize(const Array& dependent_code, const Code& code) { |
| + if (!code.is_optimized()) { |
| + return false; |
| + } |
| + |
| + WeakProperty& weak_property = WeakProperty::Handle(); |
| + for (intptr_t i = 0; i < dependent_code.Length(); i++) { |
| + weak_property ^= dependent_code.At(i); |
| + if (code.raw() == weak_property.key()) { |
| + return true; |
| + } |
| + } |
| + |
| + return false; |
| +} |
| + |
| + |
| +void Field::DeoptimizeDependentCode() const { |
| + const Array& code_objects = Array::Handle(dependent_code()); |
| + |
| + if (code_objects.IsNull()) { |
| + return; |
| + } |
| + set_dependent_code(Array::Handle()); |
| + |
| + // First deoptimize all dependent methods on the stack. |
| + Code& code = Code::Handle(); |
| + { |
| + DartFrameIterator iterator; |
| + StackFrame* frame = iterator.NextFrame(); |
| + while (frame != NULL) { |
| + code = frame->LookupDartCode(); |
| + if (ShouldDeoptimize(code_objects, code)) { |
| + DeoptimizeAt(code, frame->pc()); |
| + } |
| + frame = iterator.NextFrame(); |
| + } |
| + } |
| + |
| + WeakProperty& weak_property = WeakProperty::Handle(); |
| + Function& function = Function::Handle(); |
| + for (intptr_t i = 0; i < code_objects.Length(); i++) { |
| + weak_property ^= code_objects.At(i); |
| + code ^= weak_property.key(); |
| + if (code.IsNull()) { |
| + continue; |
| + } |
| + |
| + function ^= code.function(); |
| + if (function.CurrentCode() == code.raw()) { |
| + ASSERT(function.HasOptimizedCode()); |
| + function.SwitchToUnoptimizedCode(); |
| + } |
| + } |
| +} |
| + |
| + |
| +void Field::UpdateCid(intptr_t cid) const { |
| + if (guarded_cid() == kIllegalCid) { |
| + set_guarded_cid(cid); |
| + set_is_nullable(cid == kNullCid); |
| + return; |
| + } |
| + |
| + if ((cid == guarded_cid()) || |
| + ((cid == kNullCid) && is_nullable())) { |
| + return; |
| + } |
| + |
| + if ((cid == kNullCid) && !is_nullable()) { |
| + set_is_nullable(true); |
| + } else if ((cid != kNullCid) && (guarded_cid() == kNullCid)) { |
| + ASSERT(is_nullable()); |
| + set_guarded_cid(cid); |
| + } else { |
| + ASSERT(guarded_cid() != cid); |
| + set_guarded_cid(kDynamicCid); |
| + set_is_nullable(true); |
| + } |
| + |
| + DeoptimizeDependentCode(); |
| +} |
| + |
| + |
| void LiteralToken::set_literal(const String& literal) const { |
| StorePointer(&raw_ptr()->literal_, literal.raw()); |
| } |