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

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

Issue 1368173002: Do not eagerly finalize when optimizing. Remove allocation of temporary strings in new space. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Improve comments Created 5 years, 2 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/report.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4431 matching lines...) Expand 10 before | Expand all | Expand 10 after
4442 const LibraryPrefix& library_prefix) const { 4442 const LibraryPrefix& library_prefix) const {
4443 StorePointer(&raw_ptr()->library_prefix_, library_prefix.raw()); 4443 StorePointer(&raw_ptr()->library_prefix_, library_prefix.raw());
4444 } 4444 }
4445 4445
4446 4446
4447 RawString* UnresolvedClass::Name() const { 4447 RawString* UnresolvedClass::Name() const {
4448 if (library_prefix() != LibraryPrefix::null()) { 4448 if (library_prefix() != LibraryPrefix::null()) {
4449 const LibraryPrefix& lib_prefix = LibraryPrefix::Handle(library_prefix()); 4449 const LibraryPrefix& lib_prefix = LibraryPrefix::Handle(library_prefix());
4450 String& name = String::Handle(); 4450 String& name = String::Handle();
4451 name = lib_prefix.name(); // Qualifier. 4451 name = lib_prefix.name(); // Qualifier.
4452 name = String::Concat(name, Symbols::Dot()); 4452 Zone* zone = Thread::Current()->zone();
4453 const String& str = String::Handle(ident()); 4453 GrowableHandlePtrArray<const String> strs(zone, 3);
4454 name = String::Concat(name, str); 4454 strs.Add(name);
4455 return name.raw(); 4455 strs.Add(Symbols::Dot());
4456 strs.Add(String::Handle(zone, ident()));
4457 return Symbols::FromConcatAll(strs);
4456 } else { 4458 } else {
4457 return ident(); 4459 return ident();
4458 } 4460 }
4459 } 4461 }
4460 4462
4461 4463
4462 const char* UnresolvedClass::ToCString() const { 4464 const char* UnresolvedClass::ToCString() const {
4463 const char* cname = String::Handle(Name()).ToCString(); 4465 const char* cname = String::Handle(Name()).ToCString();
4464 return OS::SCreate(Thread::Current()->zone(), 4466 return OS::SCreate(Thread::Current()->zone(),
4465 "unresolved class '%s'", cname); 4467 "unresolved class '%s'", cname);
(...skipping 4263 matching lines...) Expand 10 before | Expand all | Expand 10 after
8729 intptr_t end_pos = *first_token_index; 8731 intptr_t end_pos = *first_token_index;
8730 while (tkit.CurrentTokenKind() != Token::kNEWLINE && 8732 while (tkit.CurrentTokenKind() != Token::kNEWLINE &&
8731 tkit.CurrentTokenKind() != Token::kEOS) { 8733 tkit.CurrentTokenKind() != Token::kEOS) {
8732 end_pos = tkit.CurrentPosition(); 8734 end_pos = tkit.CurrentPosition();
8733 tkit.Advance(); 8735 tkit.Advance();
8734 } 8736 }
8735 *last_token_index = end_pos; 8737 *last_token_index = end_pos;
8736 } 8738 }
8737 8739
8738 8740
8739 RawString* Script::GetLine(intptr_t line_number) const { 8741 RawString* Script::GetLine(intptr_t line_number, Heap::Space space) const {
8740 const String& src = String::Handle(Source()); 8742 const String& src = String::Handle(Source());
8741 intptr_t relative_line_number = line_number - line_offset(); 8743 intptr_t relative_line_number = line_number - line_offset();
8742 intptr_t current_line = 1; 8744 intptr_t current_line = 1;
8743 intptr_t line_start_idx = -1; 8745 intptr_t line_start_idx = -1;
8744 intptr_t last_char_idx = -1; 8746 intptr_t last_char_idx = -1;
8745 for (intptr_t ix = 0; 8747 for (intptr_t ix = 0;
8746 (ix < src.Length()) && (current_line <= relative_line_number); 8748 (ix < src.Length()) && (current_line <= relative_line_number);
8747 ix++) { 8749 ix++) {
8748 if ((current_line == relative_line_number) && (line_start_idx < 0)) { 8750 if ((current_line == relative_line_number) && (line_start_idx < 0)) {
8749 line_start_idx = ix; 8751 line_start_idx = ix;
8750 } 8752 }
8751 if (src.CharAt(ix) == '\n') { 8753 if (src.CharAt(ix) == '\n') {
8752 current_line++; 8754 current_line++;
8753 } else if (src.CharAt(ix) == '\r') { 8755 } else if (src.CharAt(ix) == '\r') {
8754 if ((ix + 1 != src.Length()) && (src.CharAt(ix + 1) != '\n')) { 8756 if ((ix + 1 != src.Length()) && (src.CharAt(ix + 1) != '\n')) {
8755 current_line++; 8757 current_line++;
8756 } 8758 }
8757 } else { 8759 } else {
8758 last_char_idx = ix; 8760 last_char_idx = ix;
8759 } 8761 }
8760 } 8762 }
8761 // Guarantee that returned string is never NULL. 8763 // Guarantee that returned string is never NULL.
8762 8764
8763 if (line_start_idx >= 0) { 8765 if (line_start_idx >= 0) {
8764 return String::SubString(src, 8766 return String::SubString(src,
8765 line_start_idx, 8767 line_start_idx,
8766 last_char_idx - line_start_idx + 1); 8768 last_char_idx - line_start_idx + 1,
8769 space);
8767 } else { 8770 } else {
8768 return Symbols::Empty().raw(); 8771 return Symbols::Empty().raw();
8769 } 8772 }
8770 } 8773 }
8771 8774
8772 8775
8773 RawString* Script::GetSnippet(intptr_t from_line, 8776 RawString* Script::GetSnippet(intptr_t from_line,
8774 intptr_t from_column, 8777 intptr_t from_column,
8775 intptr_t to_line, 8778 intptr_t to_line,
8776 intptr_t to_column) const { 8779 intptr_t to_column) const {
(...skipping 5267 matching lines...) Expand 10 before | Expand all | Expand 10 after
14044 RawObject* raw = Object::Allocate(LanguageError::kClassId, 14047 RawObject* raw = Object::Allocate(LanguageError::kClassId,
14045 LanguageError::InstanceSize(), 14048 LanguageError::InstanceSize(),
14046 space); 14049 space);
14047 NoSafepointScope no_safepoint; 14050 NoSafepointScope no_safepoint;
14048 result ^= raw; 14051 result ^= raw;
14049 } 14052 }
14050 result.set_previous_error(prev_error); 14053 result.set_previous_error(prev_error);
14051 result.set_script(script); 14054 result.set_script(script);
14052 result.set_token_pos(token_pos); 14055 result.set_token_pos(token_pos);
14053 result.set_kind(kind); 14056 result.set_kind(kind);
14054 result.set_message(String::Handle(String::NewFormattedV(format, args))); 14057 result.set_message(String::Handle(
14058 String::NewFormattedV(format, args, space)));
14055 return result.raw(); 14059 return result.raw();
14056 } 14060 }
14057 14061
14058 14062
14059 RawLanguageError* LanguageError::NewFormatted(const Error& prev_error, 14063 RawLanguageError* LanguageError::NewFormatted(const Error& prev_error,
14060 const Script& script, 14064 const Script& script,
14061 intptr_t token_pos, 14065 intptr_t token_pos,
14062 Report::Kind kind, 14066 Report::Kind kind,
14063 Heap::Space space, 14067 Heap::Space space,
14064 const char* format, ...) { 14068 const char* format, ...) {
(...skipping 2128 matching lines...) Expand 10 before | Expand all | Expand 10 after
16193 // There is no need to canonicalize the instantiated type parameter, since all 16197 // There is no need to canonicalize the instantiated type parameter, since all
16194 // type arguments are canonicalized at type finalization time. It would be too 16198 // type arguments are canonicalized at type finalization time. It would be too
16195 // early to canonicalize the returned type argument here, since instantiation 16199 // early to canonicalize the returned type argument here, since instantiation
16196 // not only happens at run time, but also during type finalization. 16200 // not only happens at run time, but also during type finalization.
16197 return type_arg.raw(); 16201 return type_arg.raw();
16198 } 16202 }
16199 16203
16200 16204
16201 bool TypeParameter::CheckBound(const AbstractType& bounded_type, 16205 bool TypeParameter::CheckBound(const AbstractType& bounded_type,
16202 const AbstractType& upper_bound, 16206 const AbstractType& upper_bound,
16203 Error* bound_error) const { 16207 Error* bound_error,
16208 Heap::Space space) const {
16204 ASSERT((bound_error != NULL) && bound_error->IsNull()); 16209 ASSERT((bound_error != NULL) && bound_error->IsNull());
16205 ASSERT(bounded_type.IsFinalized()); 16210 ASSERT(bounded_type.IsFinalized());
16206 ASSERT(upper_bound.IsFinalized()); 16211 ASSERT(upper_bound.IsFinalized());
16207 ASSERT(!bounded_type.IsMalformed()); 16212 ASSERT(!bounded_type.IsMalformed());
16208 if (bounded_type.IsSubtypeOf(upper_bound, bound_error)) { 16213 if (bounded_type.IsSubtypeOf(upper_bound, bound_error, space)) {
16209 return true; 16214 return true;
16210 } 16215 }
16211 // Set bound_error if the caller is interested and if this is the first error. 16216 // Set bound_error if the caller is interested and if this is the first error.
16212 if ((bound_error != NULL) && bound_error->IsNull()) { 16217 if ((bound_error != NULL) && bound_error->IsNull()) {
16213 // Report the bound error only if both the bounded type and the upper bound 16218 // Report the bound error only if both the bounded type and the upper bound
16214 // are instantiated. Otherwise, we cannot tell yet it is a bound error. 16219 // are instantiated. Otherwise, we cannot tell yet it is a bound error.
16215 if (bounded_type.IsInstantiated() && upper_bound.IsInstantiated()) { 16220 if (bounded_type.IsInstantiated() && upper_bound.IsInstantiated()) {
16216 const String& bounded_type_name = String::Handle( 16221 const String& bounded_type_name = String::Handle(
16217 bounded_type.UserVisibleName()); 16222 bounded_type.UserVisibleName());
16218 const String& upper_bound_name = String::Handle( 16223 const String& upper_bound_name = String::Handle(
(...skipping 2564 matching lines...) Expand 10 before | Expand all | Expand 10 after
18783 RawString* String::NewFormatted(const char* format, ...) { 18788 RawString* String::NewFormatted(const char* format, ...) {
18784 va_list args; 18789 va_list args;
18785 va_start(args, format); 18790 va_start(args, format);
18786 RawString* result = NewFormattedV(format, args); 18791 RawString* result = NewFormattedV(format, args);
18787 NoSafepointScope no_safepoint; 18792 NoSafepointScope no_safepoint;
18788 va_end(args); 18793 va_end(args);
18789 return result; 18794 return result;
18790 } 18795 }
18791 18796
18792 18797
18793 RawString* String::NewFormattedV(const char* format, va_list args) { 18798 RawString* String::NewFormatted(Heap::Space space, const char* format, ...) {
18799 va_list args;
18800 va_start(args, format);
18801 RawString* result = NewFormattedV(format, args, space);
18802 NoSafepointScope no_safepoint;
18803 va_end(args);
18804 return result;
18805 }
18806
18807
18808 RawString* String::NewFormattedV(const char* format, va_list args,
18809 Heap::Space space) {
18794 va_list args_copy; 18810 va_list args_copy;
18795 va_copy(args_copy, args); 18811 va_copy(args_copy, args);
18796 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy); 18812 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy);
18797 va_end(args_copy); 18813 va_end(args_copy);
18798 18814
18799 Zone* zone = Thread::Current()->zone(); 18815 Zone* zone = Thread::Current()->zone();
18800 char* buffer = zone->Alloc<char>(len + 1); 18816 char* buffer = zone->Alloc<char>(len + 1);
18801 OS::VSNPrint(buffer, (len + 1), format, args); 18817 OS::VSNPrint(buffer, (len + 1), format, args);
18802 18818
18803 return String::New(buffer); 18819 return String::New(buffer, space);
18804 } 18820 }
18805 18821
18806 18822
18807 RawString* String::Concat(const String& str1, 18823 RawString* String::Concat(const String& str1,
18808 const String& str2, 18824 const String& str2,
18809 Heap::Space space) { 18825 Heap::Space space) {
18810 ASSERT(!str1.IsNull() && !str2.IsNull()); 18826 ASSERT(!str1.IsNull() && !str2.IsNull());
18811 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize()); 18827 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize());
18812 if (char_size == kTwoByteChar) { 18828 if (char_size == kTwoByteChar) {
18813 return TwoByteString::Concat(str1, str2, space); 18829 return TwoByteString::Concat(str1, str2, space);
(...skipping 2637 matching lines...) Expand 10 before | Expand all | Expand 10 after
21451 return tag_label.ToCString(); 21467 return tag_label.ToCString();
21452 } 21468 }
21453 21469
21454 21470
21455 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21471 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21456 Instance::PrintJSONImpl(stream, ref); 21472 Instance::PrintJSONImpl(stream, ref);
21457 } 21473 }
21458 21474
21459 21475
21460 } // namespace dart 21476 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/report.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698