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

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

Issue 16780009: When canonicalize instances check if all fields are canonical. If a field is a non-canonical number… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 DEFINE_FLAG(bool, show_internal_names, false, 44 DEFINE_FLAG(bool, show_internal_names, false,
45 "Show names of internal classes (e.g. \"OneByteString\") in error messages " 45 "Show names of internal classes (e.g. \"OneByteString\") in error messages "
46 "instead of showing the corresponding interface names (e.g. \"String\")"); 46 "instead of showing the corresponding interface names (e.g. \"String\")");
47 DEFINE_FLAG(bool, trace_disabling_optimized_code, false, 47 DEFINE_FLAG(bool, trace_disabling_optimized_code, false,
48 "Trace disabling optimized code."); 48 "Trace disabling optimized code.");
49 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, 49 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000,
50 "Huge method cutoff in tokens: Disables optimizations for huge methods."); 50 "Huge method cutoff in tokens: Disables optimizations for huge methods.");
51 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, 51 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000,
52 "Huge method cutoff in unoptimized code size (in bytes)."); 52 "Huge method cutoff in unoptimized code size (in bytes).");
53 DEFINE_FLAG(bool, report_incorrect_const_objects, true,
hausner 2013/06/11 23:29:24 Why do we need the flag?
srdjan 2013/06/12 00:22:22 Removing. It is easy to disable the error reportin
54 "Report if a const object has incorrect fields.");
53 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false, 55 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false,
54 "Throw an exception when integer arithmetic exceeds 53 bits."); 56 "Throw an exception when integer arithmetic exceeds 53 bits.");
55 DECLARE_FLAG(bool, trace_compiler); 57 DECLARE_FLAG(bool, trace_compiler);
56 DECLARE_FLAG(bool, eliminate_type_checks); 58 DECLARE_FLAG(bool, eliminate_type_checks);
57 DECLARE_FLAG(bool, enable_type_checks); 59 DECLARE_FLAG(bool, enable_type_checks);
58 DECLARE_FLAG(int, deoptimization_counter_threshold); 60 DECLARE_FLAG(int, deoptimization_counter_threshold);
59 61
60 static const char* kGetterPrefix = "get:"; 62 static const char* kGetterPrefix = "get:";
61 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); 63 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix);
62 static const char* kSetterPrefix = "set:"; 64 static const char* kSetterPrefix = "set:";
(...skipping 9024 matching lines...) Expand 10 before | Expand all | Expand 10 after
9087 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != 9089 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) !=
9088 (*reinterpret_cast<RawObject**>(other_addr + offset))) { 9090 (*reinterpret_cast<RawObject**>(other_addr + offset))) {
9089 return false; 9091 return false;
9090 } 9092 }
9091 } 9093 }
9092 } 9094 }
9093 return true; 9095 return true;
9094 } 9096 }
9095 9097
9096 9098
9097 RawInstance* Instance::Canonicalize() const { 9099 RawInstance* Instance::CheckAndCanonicalize(const char** error_str) const {
9098 ASSERT(!IsNull()); 9100 ASSERT(!IsNull());
9099 if (this->IsCanonical()) { 9101 if (this->IsCanonical()) {
9100 return this->raw(); 9102 return this->raw();
9101 } 9103 }
9102 Instance& result = Instance::Handle(); 9104 Instance& result = Instance::Handle();
9103 const Class& cls = Class::Handle(this->clazz()); 9105 const Class& cls = Class::Handle(this->clazz());
9106 if (cls.id() >= kNumPredefinedCids) {
hausner 2013/06/11 23:29:24 As discussed offline, this excludes arrays.
srdjan 2013/06/12 00:22:22 Added arrays.
9107 // Iterate over all fields, canonicalize numbers and strings, expect all
9108 // other instances to be canonical otherwise report error (return
9109 // Instance::null()).
9110 Object& obj = Object::Handle();
9111 const intptr_t end_field_offset = cls.instance_size() - kWordSize;
9112 for (intptr_t field_offset = 0;
9113 field_offset <= end_field_offset;
9114 field_offset += kWordSize) {
9115 obj = *this->FieldAddrAtOffset(field_offset);
9116 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) {
9117 if (obj.IsNumber() || obj.IsString()) {
9118 obj = Instance::Cast(obj).CheckAndCanonicalize(NULL);
9119 ASSERT(!obj.IsNull());
9120 this->SetFieldAtOffset(field_offset, obj);
9121 } else {
9122 if (FLAG_report_incorrect_const_objects) {
9123 ASSERT(error_str != NULL);
9124 const char* kFormat = "field: %s\n";
9125 const intptr_t len =
9126 OS::SNPrint(NULL, 0, kFormat, obj.ToCString()) + 1;
9127 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
9128 OS::SNPrint(chars, len, kFormat, obj.ToCString());
9129 *error_str = chars;
9130 return Instance::null();
9131 }
9132 }
9133 }
9134 }
9135 }
9104 Array& constants = Array::Handle(cls.constants()); 9136 Array& constants = Array::Handle(cls.constants());
9105 const intptr_t constants_len = constants.Length(); 9137 const intptr_t constants_len = constants.Length();
9106 // Linear search to see whether this value is already present in the 9138 // Linear search to see whether this value is already present in the
9107 // list of canonicalized constants. 9139 // list of canonicalized constants.
9108 intptr_t index = 0; 9140 intptr_t index = 0;
9109 while (index < constants_len) { 9141 while (index < constants_len) {
9110 result ^= constants.At(index); 9142 result ^= constants.At(index);
9111 if (result.IsNull()) { 9143 if (result.IsNull()) {
9112 break; 9144 break;
9113 } 9145 }
(...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after
11441 intptr_t slen = other.Length(); 11473 intptr_t slen = other.Length();
11442 for (int i = 0; i < slen; i++) { 11474 for (int i = 0; i < slen; i++) {
11443 if (this->CharAt(i) != other.CharAt(i)) { 11475 if (this->CharAt(i) != other.CharAt(i)) {
11444 return false; 11476 return false;
11445 } 11477 }
11446 } 11478 }
11447 return true; 11479 return true;
11448 } 11480 }
11449 11481
11450 11482
11451 RawInstance* String::Canonicalize() const { 11483 RawInstance* String::CheckAndCanonicalize(const char** error_str) const {
11452 if (IsCanonical()) { 11484 if (IsCanonical()) {
11453 return this->raw(); 11485 return this->raw();
11454 } 11486 }
11455 return Symbols::New(*this); 11487 return Symbols::New(*this);
11456 } 11488 }
11457 11489
11458 11490
11459 RawString* String::New(const char* cstr, Heap::Space space) { 11491 RawString* String::New(const char* cstr, Heap::Space space) {
11460 ASSERT(cstr != NULL); 11492 ASSERT(cstr != NULL);
11461 intptr_t array_len = strlen(cstr); 11493 intptr_t array_len = strlen(cstr);
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
13402 space); 13434 space);
13403 return reinterpret_cast<RawWeakProperty*>(raw); 13435 return reinterpret_cast<RawWeakProperty*>(raw);
13404 } 13436 }
13405 13437
13406 13438
13407 const char* WeakProperty::ToCString() const { 13439 const char* WeakProperty::ToCString() const {
13408 return "_WeakProperty"; 13440 return "_WeakProperty";
13409 } 13441 }
13410 13442
13411 } // namespace dart 13443 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698