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

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

Issue 22851003: Initial support for length guards on final fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 5227 matching lines...) Expand 10 before | Expand all | Expand 10 after
5299 } else { 5301 } else {
5300 result.SetOffset(0); 5302 result.SetOffset(0);
5301 } 5303 }
5302 result.set_is_final(is_final); 5304 result.set_is_final(is_final);
5303 result.set_is_const(is_const); 5305 result.set_is_const(is_const);
5304 result.set_owner(owner); 5306 result.set_owner(owner);
5305 result.set_token_pos(token_pos); 5307 result.set_token_pos(token_pos);
5306 result.set_has_initializer(false); 5308 result.set_has_initializer(false);
5307 result.set_guarded_cid(kIllegalCid); 5309 result.set_guarded_cid(kIllegalCid);
5308 result.set_is_nullable(false); 5310 result.set_is_nullable(false);
5311 result.set_guarded_list_length(Field::kUnknownLength);
5309 result.set_dependent_code(Object::null_array()); 5312 result.set_dependent_code(Object::null_array());
5310 return result.raw(); 5313 return result.raw();
5311 } 5314 }
5312 5315
5313 5316
5314 5317
5315 RawField* Field::Clone(const Class& new_owner) const { 5318 RawField* Field::Clone(const Class& new_owner) const {
5316 Field& clone = Field::Handle(); 5319 Field& clone = Field::Handle();
5317 clone ^= Object::Clone(*this, Heap::kOld); 5320 clone ^= Object::Clone(*this, Heap::kOld);
5318 const Class& owner = Class::Handle(this->owner()); 5321 const Class& owner = Class::Handle(this->owner());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
5422 set_dependent_code(Object::null_array()); 5425 set_dependent_code(Object::null_array());
5423 5426
5424 // Deoptimize all dependent code on the stack. 5427 // Deoptimize all dependent code on the stack.
5425 Code& code = Code::Handle(); 5428 Code& code = Code::Handle();
5426 { 5429 {
5427 DartFrameIterator iterator; 5430 DartFrameIterator iterator;
5428 StackFrame* frame = iterator.NextFrame(); 5431 StackFrame* frame = iterator.NextFrame();
5429 while (frame != NULL) { 5432 while (frame != NULL) {
5430 code = frame->LookupDartCode(); 5433 code = frame->LookupDartCode();
5431 if (IsDependentCode(code_objects, code)) { 5434 if (IsDependentCode(code_objects, code)) {
5435 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
5436 Function& function = Function::Handle(code.function());
5437 OS::PrintErr("Deoptimizing %s because guard on field %s failed.\n",
5438 function.ToFullyQualifiedCString(),
5439 ToCString());
5440 }
5432 DeoptimizeAt(code, frame->pc()); 5441 DeoptimizeAt(code, frame->pc());
5433 } 5442 }
5434 frame = iterator.NextFrame(); 5443 frame = iterator.NextFrame();
5435 } 5444 }
5436 } 5445 }
5437 5446
5438 // Switch functions that use dependent code to unoptimized code. 5447 // Switch functions that use dependent code to unoptimized code.
5439 WeakProperty& weak_property = WeakProperty::Handle(); 5448 WeakProperty& weak_property = WeakProperty::Handle();
5440 Function& function = Function::Handle(); 5449 Function& function = Function::Handle();
5441 for (intptr_t i = 0; i < code_objects.Length(); i++) { 5450 for (intptr_t i = 0; i < code_objects.Length(); i++) {
5442 weak_property ^= code_objects.At(i); 5451 weak_property ^= code_objects.At(i);
5443 code ^= weak_property.key(); 5452 code ^= weak_property.key();
5444 if (code.IsNull()) { 5453 if (code.IsNull()) {
5445 // Code was garbage collected already. 5454 // Code was garbage collected already.
5446 continue; 5455 continue;
5447 } 5456 }
5448 5457
5449 function ^= code.function(); 5458 function ^= code.function();
5450 // If function uses dependent code switch it to unoptimized. 5459 // If function uses dependent code switch it to unoptimized.
5451 if (function.CurrentCode() == code.raw()) { 5460 if (function.CurrentCode() == code.raw()) {
5452 ASSERT(function.HasOptimizedCode()); 5461 ASSERT(function.HasOptimizedCode());
5462 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
5463 OS::PrintErr("Switching %s to unoptimized code because guard"
5464 " on field %s was violated.\n",
5465 function.ToFullyQualifiedCString(),
5466 ToCString());
5467 }
5453 function.SwitchToUnoptimizedCode(); 5468 function.SwitchToUnoptimizedCode();
5454 } 5469 }
5455 } 5470 }
5456 } 5471 }
5457 5472
5458 5473
5459 void Field::UpdateCid(intptr_t cid) const { 5474 void Field::UpdateCid(intptr_t cid) const {
5460 if (guarded_cid() == kIllegalCid) { 5475 if (guarded_cid() == kIllegalCid) {
5461 // Field is assigned first time. 5476 // Field is assigned first time.
5462 set_guarded_cid(cid); 5477 set_guarded_cid(cid);
(...skipping 19 matching lines...) Expand all
5482 ASSERT(guarded_cid() != cid); 5497 ASSERT(guarded_cid() != cid);
5483 set_guarded_cid(kDynamicCid); 5498 set_guarded_cid(kDynamicCid);
5484 set_is_nullable(true); 5499 set_is_nullable(true);
5485 } 5500 }
5486 5501
5487 // Expected class id or nullability of the field changed. 5502 // Expected class id or nullability of the field changed.
5488 DeoptimizeDependentCode(); 5503 DeoptimizeDependentCode();
5489 } 5504 }
5490 5505
5491 5506
5507 void Field::UpdateLength(intptr_t list_length) const {
5508 ASSERT(is_final() || (!is_final() && (list_length < Field::kUnknownLength)));
5509 ASSERT((list_length == Field::kNoLength) ||
5510 (list_length > Field::kUnknownLength));
5511 ASSERT(guarded_cid() != kIllegalCid);
5512
5513 const bool force_invalidate = guarded_cid() == kDynamicCid;
5514
5515 const bool list_length_unknown =
5516 (guarded_list_length() == Field::kUnknownLength);
5517 const bool list_length_changed = (guarded_list_length() != list_length);
5518
5519 if (list_length_unknown && list_length_changed && !force_invalidate) {
5520 // List length set for first time.
5521 set_guarded_list_length(list_length);
5522 return;
5523 }
5524
5525 if (!list_length_changed && !force_invalidate) {
5526 // List length unchanged.
5527 return;
5528 }
5529
5530 // Multiple list lengths assigned here, stop tracking length.
5531 set_guarded_list_length(Field::kNoLength);
5532 DeoptimizeDependentCode();
5533 }
5534
5535
5492 void LiteralToken::set_literal(const String& literal) const { 5536 void LiteralToken::set_literal(const String& literal) const {
5493 StorePointer(&raw_ptr()->literal_, literal.raw()); 5537 StorePointer(&raw_ptr()->literal_, literal.raw());
5494 } 5538 }
5495 5539
5496 5540
5497 void LiteralToken::set_value(const Object& value) const { 5541 void LiteralToken::set_value(const Object& value) const {
5498 StorePointer(&raw_ptr()->value_, value.raw()); 5542 StorePointer(&raw_ptr()->value_, value.raw());
5499 } 5543 }
5500 5544
5501 5545
(...skipping 9110 matching lines...) Expand 10 before | Expand all | Expand 10 after
14612 } 14656 }
14613 14657
14614 14658
14615 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14659 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14616 stream->OpenObject(); 14660 stream->OpenObject();
14617 stream->CloseObject(); 14661 stream->CloseObject();
14618 } 14662 }
14619 14663
14620 14664
14621 } // namespace dart 14665 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698