| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, | 52 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, |
| 53 "Huge method cutoff in tokens: Disables optimizations for huge methods."); | 53 "Huge method cutoff in tokens: Disables optimizations for huge methods."); |
| 54 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, | 54 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, |
| 55 "Huge method cutoff in unoptimized code size (in bytes)."); | 55 "Huge method cutoff in unoptimized code size (in bytes)."); |
| 56 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false, | 56 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false, |
| 57 "Throw an exception when the result of an integer calculation will not " | 57 "Throw an exception when the result of an integer calculation will not " |
| 58 "fit into a javascript integer."); | 58 "fit into a javascript integer."); |
| 59 DECLARE_FLAG(bool, trace_compiler); | 59 DECLARE_FLAG(bool, trace_compiler); |
| 60 DECLARE_FLAG(bool, eliminate_type_checks); | 60 DECLARE_FLAG(bool, eliminate_type_checks); |
| 61 DECLARE_FLAG(bool, enable_type_checks); | 61 DECLARE_FLAG(bool, enable_type_checks); |
| 62 DECLARE_FLAG(bool, trace_deoptimization); |
| 63 DECLARE_FLAG(bool, trace_deoptimization_verbose); |
| 62 DECLARE_FLAG(bool, error_on_bad_override); | 64 DECLARE_FLAG(bool, error_on_bad_override); |
| 63 | 65 |
| 64 static const char* kGetterPrefix = "get:"; | 66 static const char* kGetterPrefix = "get:"; |
| 65 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); | 67 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); |
| 66 static const char* kSetterPrefix = "set:"; | 68 static const char* kSetterPrefix = "set:"; |
| 67 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); | 69 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); |
| 68 | 70 |
| 69 cpp_vtable Object::handle_vtable_ = 0; | 71 cpp_vtable Object::handle_vtable_ = 0; |
| 70 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; | 72 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; |
| 71 cpp_vtable Smi::handle_vtable_ = 0; | 73 cpp_vtable Smi::handle_vtable_ = 0; |
| (...skipping 5226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5298 } else { | 5300 } else { |
| 5299 result.SetOffset(0); | 5301 result.SetOffset(0); |
| 5300 } | 5302 } |
| 5301 result.set_is_final(is_final); | 5303 result.set_is_final(is_final); |
| 5302 result.set_is_const(is_const); | 5304 result.set_is_const(is_const); |
| 5303 result.set_owner(owner); | 5305 result.set_owner(owner); |
| 5304 result.set_token_pos(token_pos); | 5306 result.set_token_pos(token_pos); |
| 5305 result.set_has_initializer(false); | 5307 result.set_has_initializer(false); |
| 5306 result.set_guarded_cid(kIllegalCid); | 5308 result.set_guarded_cid(kIllegalCid); |
| 5307 result.set_is_nullable(false); | 5309 result.set_is_nullable(false); |
| 5310 result.set_guarded_list_length(Field::kUnknownFixedLength); |
| 5308 result.set_dependent_code(Object::null_array()); | 5311 result.set_dependent_code(Object::null_array()); |
| 5309 return result.raw(); | 5312 return result.raw(); |
| 5310 } | 5313 } |
| 5311 | 5314 |
| 5312 | 5315 |
| 5313 | 5316 |
| 5314 RawField* Field::Clone(const Class& new_owner) const { | 5317 RawField* Field::Clone(const Class& new_owner) const { |
| 5315 Field& clone = Field::Handle(); | 5318 Field& clone = Field::Handle(); |
| 5316 clone ^= Object::Clone(*this, Heap::kOld); | 5319 clone ^= Object::Clone(*this, Heap::kOld); |
| 5317 const Class& owner = Class::Handle(this->owner()); | 5320 const Class& owner = Class::Handle(this->owner()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5421 set_dependent_code(Object::null_array()); | 5424 set_dependent_code(Object::null_array()); |
| 5422 | 5425 |
| 5423 // Deoptimize all dependent code on the stack. | 5426 // Deoptimize all dependent code on the stack. |
| 5424 Code& code = Code::Handle(); | 5427 Code& code = Code::Handle(); |
| 5425 { | 5428 { |
| 5426 DartFrameIterator iterator; | 5429 DartFrameIterator iterator; |
| 5427 StackFrame* frame = iterator.NextFrame(); | 5430 StackFrame* frame = iterator.NextFrame(); |
| 5428 while (frame != NULL) { | 5431 while (frame != NULL) { |
| 5429 code = frame->LookupDartCode(); | 5432 code = frame->LookupDartCode(); |
| 5430 if (IsDependentCode(code_objects, code)) { | 5433 if (IsDependentCode(code_objects, code)) { |
| 5434 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
| 5435 Function& function = Function::Handle(code.function()); |
| 5436 OS::PrintErr("Deoptimizing %s because guard on field %s failed.\n", |
| 5437 function.ToFullyQualifiedCString(), |
| 5438 ToCString()); |
| 5439 } |
| 5431 DeoptimizeAt(code, frame->pc()); | 5440 DeoptimizeAt(code, frame->pc()); |
| 5432 } | 5441 } |
| 5433 frame = iterator.NextFrame(); | 5442 frame = iterator.NextFrame(); |
| 5434 } | 5443 } |
| 5435 } | 5444 } |
| 5436 | 5445 |
| 5437 // Switch functions that use dependent code to unoptimized code. | 5446 // Switch functions that use dependent code to unoptimized code. |
| 5438 WeakProperty& weak_property = WeakProperty::Handle(); | 5447 WeakProperty& weak_property = WeakProperty::Handle(); |
| 5439 Function& function = Function::Handle(); | 5448 Function& function = Function::Handle(); |
| 5440 for (intptr_t i = 0; i < code_objects.Length(); i++) { | 5449 for (intptr_t i = 0; i < code_objects.Length(); i++) { |
| 5441 weak_property ^= code_objects.At(i); | 5450 weak_property ^= code_objects.At(i); |
| 5442 code ^= weak_property.key(); | 5451 code ^= weak_property.key(); |
| 5443 if (code.IsNull()) { | 5452 if (code.IsNull()) { |
| 5444 // Code was garbage collected already. | 5453 // Code was garbage collected already. |
| 5445 continue; | 5454 continue; |
| 5446 } | 5455 } |
| 5447 | 5456 |
| 5448 function ^= code.function(); | 5457 function ^= code.function(); |
| 5449 // If function uses dependent code switch it to unoptimized. | 5458 // If function uses dependent code switch it to unoptimized. |
| 5450 if (function.CurrentCode() == code.raw()) { | 5459 if (function.CurrentCode() == code.raw()) { |
| 5451 ASSERT(function.HasOptimizedCode()); | 5460 ASSERT(function.HasOptimizedCode()); |
| 5461 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
| 5462 OS::PrintErr("Switching %s to unoptimized code because guard" |
| 5463 " on field %s was violated.\n", |
| 5464 function.ToFullyQualifiedCString(), |
| 5465 ToCString()); |
| 5466 } |
| 5452 function.SwitchToUnoptimizedCode(); | 5467 function.SwitchToUnoptimizedCode(); |
| 5453 } | 5468 } |
| 5454 } | 5469 } |
| 5455 } | 5470 } |
| 5456 | 5471 |
| 5457 | 5472 |
| 5458 void Field::UpdateCid(intptr_t cid) const { | 5473 void Field::UpdateCid(intptr_t cid) const { |
| 5459 if (guarded_cid() == kIllegalCid) { | 5474 if (guarded_cid() == kIllegalCid) { |
| 5460 // Field is assigned first time. | 5475 // Field is assigned first time. |
| 5461 set_guarded_cid(cid); | 5476 set_guarded_cid(cid); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5481 ASSERT(guarded_cid() != cid); | 5496 ASSERT(guarded_cid() != cid); |
| 5482 set_guarded_cid(kDynamicCid); | 5497 set_guarded_cid(kDynamicCid); |
| 5483 set_is_nullable(true); | 5498 set_is_nullable(true); |
| 5484 } | 5499 } |
| 5485 | 5500 |
| 5486 // Expected class id or nullability of the field changed. | 5501 // Expected class id or nullability of the field changed. |
| 5487 DeoptimizeDependentCode(); | 5502 DeoptimizeDependentCode(); |
| 5488 } | 5503 } |
| 5489 | 5504 |
| 5490 | 5505 |
| 5506 void Field::UpdateLength(intptr_t list_length) const { |
| 5507 ASSERT(is_final() || (!is_final() && |
| 5508 (list_length < Field::kUnknownFixedLength))); |
| 5509 ASSERT((list_length == Field::kNoFixedLength) || |
| 5510 (list_length > Field::kUnknownFixedLength)); |
| 5511 ASSERT(guarded_cid() != kIllegalCid); |
| 5512 |
| 5513 const bool force_invalidate = (guarded_cid() == kDynamicCid) && |
| 5514 (list_length != Field::kNoFixedLength); |
| 5515 |
| 5516 const bool list_length_unknown = |
| 5517 (guarded_list_length() == Field::kUnknownFixedLength); |
| 5518 const bool list_length_changed = (guarded_list_length() != list_length); |
| 5519 |
| 5520 if (list_length_unknown && list_length_changed && !force_invalidate) { |
| 5521 // List length set for first time. |
| 5522 set_guarded_list_length(list_length); |
| 5523 return; |
| 5524 } |
| 5525 |
| 5526 if (!list_length_changed && !force_invalidate) { |
| 5527 // List length unchanged. |
| 5528 return; |
| 5529 } |
| 5530 |
| 5531 // Multiple list lengths assigned here, stop tracking length. |
| 5532 set_guarded_list_length(Field::kNoFixedLength); |
| 5533 DeoptimizeDependentCode(); |
| 5534 } |
| 5535 |
| 5536 |
| 5491 void LiteralToken::set_literal(const String& literal) const { | 5537 void LiteralToken::set_literal(const String& literal) const { |
| 5492 StorePointer(&raw_ptr()->literal_, literal.raw()); | 5538 StorePointer(&raw_ptr()->literal_, literal.raw()); |
| 5493 } | 5539 } |
| 5494 | 5540 |
| 5495 | 5541 |
| 5496 void LiteralToken::set_value(const Object& value) const { | 5542 void LiteralToken::set_value(const Object& value) const { |
| 5497 StorePointer(&raw_ptr()->value_, value.raw()); | 5543 StorePointer(&raw_ptr()->value_, value.raw()); |
| 5498 } | 5544 } |
| 5499 | 5545 |
| 5500 | 5546 |
| (...skipping 9160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14661 } | 14707 } |
| 14662 | 14708 |
| 14663 | 14709 |
| 14664 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14710 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14665 stream->OpenObject(); | 14711 stream->OpenObject(); |
| 14666 stream->CloseObject(); | 14712 stream->CloseObject(); |
| 14667 } | 14713 } |
| 14668 | 14714 |
| 14669 | 14715 |
| 14670 } // namespace dart | 14716 } // namespace dart |
| OLD | NEW |