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

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

Issue 2363413004: VM: Avoid allocating strings when disassembling code. (Closed)
Patch Set: addressed comments Created 4 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/object_service.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/become.h" 10 #include "vm/become.h"
(...skipping 11907 matching lines...) Expand 10 before | Expand all | Expand 10 after
11918 uword pc_offset) const { 11918 uword pc_offset) const {
11919 const Function& func = 11919 const Function& func =
11920 Function::Handle(FunctionForPCOffset(code, function, pc_offset)); 11920 Function::Handle(FunctionForPCOffset(code, function, pc_offset));
11921 return func.script(); 11921 return func.script();
11922 } 11922 }
11923 11923
11924 11924
11925 void CodeSourceMap::Dump(const CodeSourceMap& code_source_map, 11925 void CodeSourceMap::Dump(const CodeSourceMap& code_source_map,
11926 const Code& code, 11926 const Code& code,
11927 const Function& function) { 11927 const Function& function) {
11928 const String& code_name = String::Handle(code.QualifiedName()); 11928 const char* code_name = code.QualifiedName();
11929 THR_Print("Dumping Code Source Map for %s\n", code_name.ToCString()); 11929 THR_Print("Dumping Code Source Map for %s\n", code_name);
11930 if (code_source_map.Length() == 0) { 11930 if (code_source_map.Length() == 0) {
11931 THR_Print("<empty>\n"); 11931 THR_Print("<empty>\n");
11932 return; 11932 return;
11933 } 11933 }
11934 11934
11935 const int addr_width = kBitsPerWord / 4; 11935 const int addr_width = kBitsPerWord / 4;
11936 11936
11937 Iterator iterator(code_source_map); 11937 Iterator iterator(code_source_map);
11938 Function& current_function = Function::Handle(); 11938 Function& current_function = Function::Handle();
11939 Script& current_script = Script::Handle(); 11939 Script& current_script = Script::Handle();
11940 TokenPosition tp; 11940 TokenPosition tp;
11941 while (iterator.MoveNext()) { 11941 while (iterator.MoveNext()) {
11942 const uword pc_offset = iterator.PcOffset(); 11942 const uword pc_offset = iterator.PcOffset();
11943 tp = code_source_map.TokenPositionForPCOffset(pc_offset); 11943 tp = code_source_map.TokenPositionForPCOffset(pc_offset);
11944 current_function ^= 11944 current_function ^=
11945 code_source_map.FunctionForPCOffset(code, function, pc_offset); 11945 code_source_map.FunctionForPCOffset(code, function, pc_offset);
11946 current_script ^= 11946 current_script ^=
11947 code_source_map.ScriptForPCOffset(code, function, pc_offset); 11947 code_source_map.ScriptForPCOffset(code, function, pc_offset);
11948 if (current_function.IsNull() || current_script.IsNull()) { 11948 if (current_function.IsNull() || current_script.IsNull()) {
11949 THR_Print("%#-*" Px "\t%s\t%s\n", addr_width, 11949 THR_Print("%#-*" Px "\t%s\t%s\n", addr_width,
11950 pc_offset, 11950 pc_offset,
11951 tp.ToCString(), 11951 tp.ToCString(),
11952 code_name.ToCString()); 11952 code_name);
11953 continue; 11953 continue;
11954 } 11954 }
11955 const String& uri = String::Handle(current_script.url()); 11955 const String& uri = String::Handle(current_script.url());
11956 ASSERT(!uri.IsNull()); 11956 ASSERT(!uri.IsNull());
11957 THR_Print("%#-*" Px "\t%s\t%s\t%s\n", addr_width, 11957 THR_Print("%#-*" Px "\t%s\t%s\t%s\n", addr_width,
11958 pc_offset, 11958 pc_offset,
11959 tp.ToCString(), 11959 tp.ToCString(),
11960 current_function.ToQualifiedCString(), 11960 current_function.ToQualifiedCString(),
11961 uri.ToCString()); 11961 uri.ToCString());
11962 } 11962 }
(...skipping 2474 matching lines...) Expand 10 before | Expand all | Expand 10 after
14437 Zone* zone = Thread::Current()->zone(); 14437 Zone* zone = Thread::Current()->zone();
14438 if (IsStubCode()) { 14438 if (IsStubCode()) {
14439 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); 14439 const char* name = StubCode::NameOfStub(UncheckedEntryPoint());
14440 return zone->PrintToString("[stub: %s]", name); 14440 return zone->PrintToString("[stub: %s]", name);
14441 } else { 14441 } else {
14442 return zone->PrintToString("Code entry: 0x%" Px, UncheckedEntryPoint()); 14442 return zone->PrintToString("Code entry: 0x%" Px, UncheckedEntryPoint());
14443 } 14443 }
14444 } 14444 }
14445 14445
14446 14446
14447 RawString* Code::Name() const { 14447 const char* Code::Name() const {
14448 const Object& obj = Object::Handle(owner()); 14448 const Object& obj = Object::Handle(owner());
14449 if (obj.IsNull()) { 14449 if (obj.IsNull()) {
14450 // Regular stub. 14450 // Regular stub.
14451 Thread* thread = Thread::Current(); 14451 Thread* thread = Thread::Current();
14452 Zone* zone = thread->zone(); 14452 Zone* zone = thread->zone();
14453 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); 14453 const char* name = StubCode::NameOfStub(UncheckedEntryPoint());
14454 ASSERT(name != NULL); 14454 ASSERT(name != NULL);
14455 char* stub_name = OS::SCreate(zone, 14455 char* stub_name = OS::SCreate(zone,
14456 "%s%s", Symbols::StubPrefix().ToCString(), name); 14456 "%s%s", Symbols::StubPrefix().ToCString(), name);
14457 return Symbols::New(thread, stub_name, strlen(stub_name)); 14457 return stub_name;
14458 } else if (obj.IsClass()) { 14458 } else if (obj.IsClass()) {
14459 // Allocation stub. 14459 // Allocation stub.
14460 Thread* thread = Thread::Current(); 14460 Thread* thread = Thread::Current();
14461 Zone* zone = thread->zone(); 14461 Zone* zone = thread->zone();
14462 const Class& cls = Class::Cast(obj); 14462 const Class& cls = Class::Cast(obj);
14463 String& cls_name = String::Handle(zone, cls.ScrubbedName()); 14463 String& cls_name = String::Handle(zone, cls.ScrubbedName());
14464 ASSERT(!cls_name.IsNull()); 14464 ASSERT(!cls_name.IsNull());
14465 return Symbols::FromConcat(thread, Symbols::AllocationStubFor(), cls_name); 14465 char* stub_name = OS::SCreate(zone,
14466 "%s%s", Symbols::AllocationStubFor().ToCString(), cls_name.ToCString());
14467 return stub_name;
14466 } else { 14468 } else {
14467 ASSERT(obj.IsFunction()); 14469 ASSERT(obj.IsFunction());
14468 // Dart function. 14470 // Dart function.
14469 return Function::Cast(obj).UserVisibleName(); // Same as scrubbed name. 14471 // Same as scrubbed name.
14472 return String::Handle(Function::Cast(obj).UserVisibleName()).ToCString();
14470 } 14473 }
14471 } 14474 }
14472 14475
14473 14476
14474 RawString* Code::QualifiedName() const { 14477 const char* Code::QualifiedName() const {
14475 const Object& obj = Object::Handle(owner()); 14478 const Object& obj = Object::Handle(owner());
14476 if (obj.IsFunction()) { 14479 if (obj.IsFunction()) {
14477 return Function::Cast(obj).QualifiedScrubbedName(); 14480 return String::Handle(
14481 Function::Cast(obj).QualifiedScrubbedName()).ToCString();
14478 } 14482 }
14479 return Name(); 14483 return Name();
14480 } 14484 }
14481 14485
14482 14486
14483 bool Code::IsAllocationStubCode() const { 14487 bool Code::IsAllocationStubCode() const {
14484 const Object& obj = Object::Handle(owner()); 14488 const Object& obj = Object::Handle(owner());
14485 return obj.IsClass(); 14489 return obj.IsClass();
14486 } 14490 }
14487 14491
(...skipping 1879 matching lines...) Expand 10 before | Expand all | Expand 10 after
16367 name_visibility)); 16371 name_visibility));
16368 pieces.Add(args_name); 16372 pieces.Add(args_name);
16369 } 16373 }
16370 // The name is only used for type checking and debugging purposes. 16374 // The name is only used for type checking and debugging purposes.
16371 // Unless profiling data shows otherwise, it is not worth caching the name in 16375 // Unless profiling data shows otherwise, it is not worth caching the name in
16372 // the type. 16376 // the type.
16373 return Symbols::FromConcatAll(thread, pieces); 16377 return Symbols::FromConcatAll(thread, pieces);
16374 } 16378 }
16375 16379
16376 16380
16377 // Same as user visible name, but including the URI of each occuring type.
16378 // Used to report errors involving types with identical names.
16379 //
16380 // e.g.
16381 // MyClass<String> -> MyClass<String> where
16382 // MyClass is from my_uri
16383 // String is from dart:core
16384 // MyClass<dynamic, T> -> MyClass<dynamic, T> where
16385 // MyClass is from my_uri
16386 // T of OtherClass is from other_uri
16387 // (MyClass) => int -> (MyClass) => int where
16388 // MyClass is from my_uri
16389 // int is from dart:core
16390 RawString* AbstractType::UserVisibleNameWithURI() const {
16391 Thread* thread = Thread::Current();
16392 Zone* zone = thread->zone();
16393 GrowableHandlePtrArray<const String> pieces(zone, 3);
16394 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName)));
16395 if (!IsDynamicType() && !IsVoidType()) {
16396 pieces.Add(Symbols::SpaceWhereNewLine());
16397 pieces.Add(String::Handle(zone, EnumerateURIs()));
16398 }
16399 return Symbols::FromConcatAll(thread, pieces);
16400 }
16401
16402
16403 RawString* AbstractType::ClassName() const { 16381 RawString* AbstractType::ClassName() const {
16404 ASSERT(!IsFunctionType()); 16382 ASSERT(!IsFunctionType());
16405 if (HasResolvedTypeClass()) { 16383 if (HasResolvedTypeClass()) {
16406 return Class::Handle(type_class()).Name(); 16384 return Class::Handle(type_class()).Name();
16407 } else { 16385 } else {
16408 return UnresolvedClass::Handle(unresolved_class()).Name(); 16386 return UnresolvedClass::Handle(unresolved_class()).Name();
16409 } 16387 }
16410 } 16388 }
16411 16389
16412 16390
(...skipping 4058 matching lines...) Expand 10 before | Expand all | Expand 10 after
20471 UNREACHABLE(); 20449 UNREACHABLE();
20472 return 0; 20450 return 0;
20473 } 20451 }
20474 20452
20475 20453
20476 static int32_t MergeHexCharacters(int32_t c1, int32_t c2) { 20454 static int32_t MergeHexCharacters(int32_t c1, int32_t c2) {
20477 return GetHexValue(c1) << 4 | GetHexValue(c2); 20455 return GetHexValue(c1) << 4 | GetHexValue(c2);
20478 } 20456 }
20479 20457
20480 20458
20481 RawString* String::EncodeIRI(const String& str) { 20459 const char* String::EncodeIRI(const String& str) {
20482 const intptr_t len = Utf8::Length(str); 20460 const intptr_t len = Utf8::Length(str);
20483 Zone* zone = Thread::Current()->zone(); 20461 Zone* zone = Thread::Current()->zone();
20484 uint8_t* utf8 = zone->Alloc<uint8_t>(len); 20462 uint8_t* utf8 = zone->Alloc<uint8_t>(len);
20485 str.ToUTF8(utf8, len); 20463 str.ToUTF8(utf8, len);
20486 intptr_t num_escapes = 0; 20464 intptr_t num_escapes = 0;
20487 for (int i = 0; i < len; ++i) { 20465 for (int i = 0; i < len; ++i) {
20488 uint8_t byte = utf8[i]; 20466 uint8_t byte = utf8[i];
20489 if (!IsURISafeCharacter(byte)) { 20467 if (!IsURISafeCharacter(byte)) {
20490 num_escapes += 2; 20468 num_escapes += 2;
20491 } 20469 }
20492 } 20470 }
20493 const String& dststr = String::Handle( 20471 intptr_t cstr_len = len + num_escapes + 1;
20494 OneByteString::New(len + num_escapes, Heap::kNew)); 20472 char* cstr = zone->Alloc<char>(cstr_len);
20495 { 20473 intptr_t index = 0;
20496 intptr_t index = 0; 20474 for (int i = 0; i < len; ++i) {
20497 for (int i = 0; i < len; ++i) { 20475 uint8_t byte = utf8[i];
20498 uint8_t byte = utf8[i]; 20476 if (!IsURISafeCharacter(byte)) {
20499 if (!IsURISafeCharacter(byte)) { 20477 cstr[index++] = '%';
20500 OneByteString::SetCharAt(dststr, index, '%'); 20478 cstr[index++] = GetHexCharacter(byte >> 4);
20501 OneByteString::SetCharAt(dststr, index + 1, 20479 cstr[index++] = GetHexCharacter(byte & 0xF);
20502 GetHexCharacter(byte >> 4)); 20480 } else {
20503 OneByteString::SetCharAt(dststr, index + 2, 20481 ASSERT(byte <= 127);
20504 GetHexCharacter(byte & 0xF)); 20482 cstr[index++] = byte;
20505 index += 3;
20506 } else {
20507 ASSERT(byte <= 127);
20508 OneByteString::SetCharAt(dststr, index, byte);
20509 index += 1;
20510 }
20511 } 20483 }
20512 } 20484 }
20513 return dststr.raw(); 20485 cstr[index] = '\0';
20486 return cstr;
20514 } 20487 }
20515 20488
20516 20489
20517 RawString* String::DecodeIRI(const String& str) { 20490 RawString* String::DecodeIRI(const String& str) {
20518 CodePointIterator cpi(str); 20491 CodePointIterator cpi(str);
20519 intptr_t num_escapes = 0; 20492 intptr_t num_escapes = 0;
20520 intptr_t len = str.Length(); 20493 intptr_t len = str.Length();
20521 { 20494 {
20522 CodePointIterator cpi(str); 20495 CodePointIterator cpi(str);
20523 while (cpi.Next()) { 20496 while (cpi.Next()) {
(...skipping 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after
23037 return UserTag::null(); 23010 return UserTag::null();
23038 } 23011 }
23039 23012
23040 23013
23041 const char* UserTag::ToCString() const { 23014 const char* UserTag::ToCString() const {
23042 const String& tag_label = String::Handle(label()); 23015 const String& tag_label = String::Handle(label());
23043 return tag_label.ToCString(); 23016 return tag_label.ToCString();
23044 } 23017 }
23045 23018
23046 } // namespace dart 23019 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698