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

Side by Side Diff: vm/code_generator.cc

Issue 10173008: Simplify representation of stack frames. Remove the special types DartFrame/StubFrame and instead u… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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/code_generator.h" 5 #include "vm/code_generator.h"
6 6
7 #include "vm/code_patcher.h" 7 #include "vm/code_patcher.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // Instantiate type before printing. 337 // Instantiate type before printing.
338 const AbstractType& instantiated_type = 338 const AbstractType& instantiated_type =
339 AbstractType::Handle(type.InstantiateFrom(type_instantiator)); 339 AbstractType::Handle(type.InstantiateFrom(type_instantiator));
340 OS::Print("InstanceOf: '%s' %s '%s' instantiated from '%s'.\n", 340 OS::Print("InstanceOf: '%s' %s '%s' instantiated from '%s'.\n",
341 String::Handle(instance_type.Name()).ToCString(), 341 String::Handle(instance_type.Name()).ToCString(),
342 (result.raw() == Bool::True()) ? "is" : "is !", 342 (result.raw() == Bool::True()) ? "is" : "is !",
343 String::Handle(instantiated_type.Name()).ToCString(), 343 String::Handle(instantiated_type.Name()).ToCString(),
344 String::Handle(type.Name()).ToCString()); 344 String::Handle(type.Name()).ToCString());
345 } 345 }
346 DartFrameIterator iterator; 346 DartFrameIterator iterator;
347 DartFrame* caller_frame = iterator.NextFrame(); 347 StackFrame* caller_frame = iterator.NextFrame();
348 ASSERT(caller_frame != NULL); 348 ASSERT(caller_frame != NULL);
srdjan 2012/04/24 23:19:41 Should we add here and elsewhere an assert that ca
siva 2012/04/25 01:14:20 Done.
349 const Function& function = Function::Handle( 349 const Function& function = Function::Handle(
350 caller_frame->LookupDartFunction()); 350 caller_frame->LookupDartFunction());
351 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); 351 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString());
352 } 352 }
353 if (!result.value() && !malformed_error.IsNull()) { 353 if (!result.value() && !malformed_error.IsNull()) {
354 // Throw a dynamic type error only if the instanceof test fails. 354 // Throw a dynamic type error only if the instanceof test fails.
355 String& malformed_error_message = String::Handle( 355 String& malformed_error_message = String::Handle(
356 String::New(malformed_error.ToErrorCString())); 356 String::New(malformed_error.ToErrorCString()));
357 const String& no_name = String::Handle(String::NewSymbol("")); 357 const String& no_name = String::Handle(String::NewSymbol(""));
358 Exceptions::CreateAndThrowTypeError( 358 Exceptions::CreateAndThrowTypeError(
359 location, no_name, no_name, no_name, malformed_error_message); 359 location, no_name, no_name, no_name, malformed_error_message);
360 UNREACHABLE(); 360 UNREACHABLE();
361 } 361 }
362 // Update cache: add class of instance and result. 362 // Update cache: add class of instance and result.
363 if (type.IsInstantiated() && 363 if (type.IsInstantiated() &&
364 !Class::Handle(type.type_class()).HasTypeArguments()) { 364 !Class::Handle(type.type_class()).HasTypeArguments()) {
365 DartFrameIterator iterator; 365 DartFrameIterator iterator;
366 DartFrame* caller_frame = iterator.NextFrame(); 366 StackFrame* caller_frame = iterator.NextFrame();
367 ASSERT(caller_frame != NULL); 367 ASSERT(caller_frame != NULL);
368 const Code& code = Code::Handle(caller_frame->LookupDartCode()); 368 const Code& code = Code::Handle(caller_frame->LookupDartCode());
369 ASSERT(!code.IsNull()); 369 ASSERT(!code.IsNull());
370 uword loc = code.GetTypeTestAtNodeId(node_id); 370 uword loc = code.GetTypeTestAtNodeId(node_id);
371 // TODO(srdjan): Check when 'loc' can be 0, once implemented everywhere. 371 // TODO(srdjan): Check when 'loc' can be 0, once implemented everywhere.
372 if (loc != 0) { 372 if (loc != 0) {
373 // Found type test cache. 373 // Found type test cache.
374 Array& value = Array::Handle(CodePatcher::GetTypeTestArray(loc)); 374 Array& value = Array::Handle(CodePatcher::GetTypeTestArray(loc));
375 const Class& instance_class = Class::Handle(instance.clazz()); 375 const Class& instance_class = Class::Handle(instance.clazz());
376 376
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 dst_type.InstantiateFrom(dst_type_instantiator)); 450 dst_type.InstantiateFrom(dst_type_instantiator));
451 OS::Print("TypeCheck: type '%s' %s a subtype of type '%s' of '%s' " 451 OS::Print("TypeCheck: type '%s' %s a subtype of type '%s' of '%s' "
452 "instantiated from '%s'.\n", 452 "instantiated from '%s'.\n",
453 String::Handle(src_type.Name()).ToCString(), 453 String::Handle(src_type.Name()).ToCString(),
454 is_instance_of ? "is" : "is not", 454 is_instance_of ? "is" : "is not",
455 String::Handle(instantiated_dst_type.Name()).ToCString(), 455 String::Handle(instantiated_dst_type.Name()).ToCString(),
456 dst_name.ToCString(), 456 dst_name.ToCString(),
457 String::Handle(dst_type.Name()).ToCString()); 457 String::Handle(dst_type.Name()).ToCString());
458 } 458 }
459 DartFrameIterator iterator; 459 DartFrameIterator iterator;
460 DartFrame* caller_frame = iterator.NextFrame(); 460 StackFrame* caller_frame = iterator.NextFrame();
461 ASSERT(caller_frame != NULL); 461 ASSERT(caller_frame != NULL);
462 const Function& function = Function::Handle( 462 const Function& function = Function::Handle(
463 caller_frame->LookupDartFunction()); 463 caller_frame->LookupDartFunction());
464 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); 464 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString());
465 } 465 }
466 if (!is_instance_of) { 466 if (!is_instance_of) {
467 String& src_type_name = String::Handle(GetSimpleTypeName(src_instance)); 467 String& src_type_name = String::Handle(GetSimpleTypeName(src_instance));
468 String& dst_type_name = String::Handle(); 468 String& dst_type_name = String::Handle();
469 if (!dst_type.IsInstantiated()) { 469 if (!dst_type.IsInstantiated()) {
470 // Instantiate dst_type before reporting the error. 470 // Instantiate dst_type before reporting the error.
471 const AbstractType& instantiated_dst_type = AbstractType::Handle( 471 const AbstractType& instantiated_dst_type = AbstractType::Handle(
472 dst_type.InstantiateFrom(dst_type_instantiator)); 472 dst_type.InstantiateFrom(dst_type_instantiator));
473 dst_type_name = instantiated_dst_type.Name(); 473 dst_type_name = instantiated_dst_type.Name();
474 } else { 474 } else {
475 dst_type_name = dst_type.Name(); 475 dst_type_name = dst_type.Name();
476 } 476 }
477 String& malformed_error_message = String::Handle(); 477 String& malformed_error_message = String::Handle();
478 if (!malformed_error.IsNull()) { 478 if (!malformed_error.IsNull()) {
479 ASSERT(FLAG_enable_type_checks); 479 ASSERT(FLAG_enable_type_checks);
480 malformed_error_message = String::New(malformed_error.ToErrorCString()); 480 malformed_error_message = String::New(malformed_error.ToErrorCString());
481 } 481 }
482 Exceptions::CreateAndThrowTypeError(location, src_type_name, dst_type_name, 482 Exceptions::CreateAndThrowTypeError(location, src_type_name, dst_type_name,
483 dst_name, malformed_error_message); 483 dst_name, malformed_error_message);
484 UNREACHABLE(); 484 UNREACHABLE();
485 } 485 }
486 // Update cache: add class of instance and result. 486 // Update cache: add class of instance and result.
487 if (dst_type.IsInstantiated() && 487 if (dst_type.IsInstantiated() &&
488 !Class::Handle(dst_type.type_class()).HasTypeArguments()) { 488 !Class::Handle(dst_type.type_class()).HasTypeArguments()) {
489 DartFrameIterator iterator; 489 DartFrameIterator iterator;
490 DartFrame* caller_frame = iterator.NextFrame(); 490 StackFrame* caller_frame = iterator.NextFrame();
491 ASSERT(caller_frame != NULL); 491 ASSERT(caller_frame != NULL);
492 const Code& code = Code::Handle(caller_frame->LookupDartCode()); 492 const Code& code = Code::Handle(caller_frame->LookupDartCode());
493 ASSERT(!code.IsNull()); 493 ASSERT(!code.IsNull());
494 uword loc = code.GetTypeTestAtNodeId(node_id); 494 uword loc = code.GetTypeTestAtNodeId(node_id);
495 if (loc != 0) { 495 if (loc != 0) {
496 // Found type test cache. 496 // Found type test cache.
497 Array& value = Array::Handle(CodePatcher::GetTypeTestArray(loc)); 497 Array& value = Array::Handle(CodePatcher::GetTypeTestArray(loc));
498 const Class& src_instance_class = Class::Handle(src_instance.clazz()); 498 const Class& src_instance_class = Class::Handle(src_instance.clazz());
499 499
500 #if defined(DEBUG) 500 #if defined(DEBUG)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 const Instance& stacktrace = Instance::CheckedHandle(arguments.At(1)); 641 const Instance& stacktrace = Instance::CheckedHandle(arguments.At(1));
642 Exceptions::ReThrow(exception, stacktrace); 642 Exceptions::ReThrow(exception, stacktrace);
643 } 643 }
644 644
645 645
646 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) { 646 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) {
647 // This function is called after successful resolving and compilation of 647 // This function is called after successful resolving and compilation of
648 // the target method. 648 // the target method.
649 ASSERT(arguments.Count() == kPatchStaticCallRuntimeEntry.argument_count()); 649 ASSERT(arguments.Count() == kPatchStaticCallRuntimeEntry.argument_count());
650 DartFrameIterator iterator; 650 DartFrameIterator iterator;
651 DartFrame* caller_frame = iterator.NextFrame(); 651 StackFrame* caller_frame = iterator.NextFrame();
652 ASSERT(caller_frame != NULL); 652 ASSERT(caller_frame != NULL);
653 uword target = 0; 653 uword target = 0;
654 Function& target_function = Function::Handle(); 654 Function& target_function = Function::Handle();
655 CodePatcher::GetStaticCallAt(caller_frame->pc(), &target_function, &target); 655 CodePatcher::GetStaticCallAt(caller_frame->pc(), &target_function, &target);
656 ASSERT(target_function.HasCode()); 656 ASSERT(target_function.HasCode());
657 uword new_target = Code::Handle(target_function.CurrentCode()).EntryPoint(); 657 uword new_target = Code::Handle(target_function.CurrentCode()).EntryPoint();
658 // Verify that we are not patching repeatedly. 658 // Verify that we are not patching repeatedly.
659 ASSERT(target != new_target); 659 ASSERT(target != new_target);
660 CodePatcher::PatchStaticCallAt(caller_frame->pc(), new_target); 660 CodePatcher::PatchStaticCallAt(caller_frame->pc(), new_target);
661 if (FLAG_trace_patching) { 661 if (FLAG_trace_patching) {
662 OS::Print("PatchStaticCall: patching from 0x%x to '%s' 0x%x\n", 662 OS::Print("PatchStaticCall: patching from 0x%x to '%s' 0x%x\n",
663 caller_frame->pc(), 663 caller_frame->pc(),
664 target_function.ToFullyQualifiedCString(), 664 target_function.ToFullyQualifiedCString(),
665 new_target); 665 new_target);
666 } 666 }
667 } 667 }
668 668
669 669
670 // Resolves and compiles the target function of an instance call, updates 670 // Resolves and compiles the target function of an instance call, updates
671 // function cache of the receiver's class and returns the compiled code or null. 671 // function cache of the receiver's class and returns the compiled code or null.
672 // Only the number of named arguments is checked, but not the actual names. 672 // Only the number of named arguments is checked, but not the actual names.
673 RawCode* ResolveCompileInstanceCallTarget(Isolate* isolate, 673 RawCode* ResolveCompileInstanceCallTarget(Isolate* isolate,
674 const Instance& receiver) { 674 const Instance& receiver) {
675 DartFrameIterator iterator; 675 DartFrameIterator iterator;
676 DartFrame* caller_frame = iterator.NextFrame(); 676 StackFrame* caller_frame = iterator.NextFrame();
677 ASSERT(caller_frame != NULL); 677 ASSERT(caller_frame != NULL);
678 int num_arguments = -1; 678 int num_arguments = -1;
679 int num_named_arguments = -1; 679 int num_named_arguments = -1;
680 uword target = 0; 680 uword target = 0;
681 String& function_name = String::Handle(); 681 String& function_name = String::Handle();
682 CodePatcher::GetInstanceCallAt(caller_frame->pc(), 682 CodePatcher::GetInstanceCallAt(caller_frame->pc(),
683 &function_name, 683 &function_name,
684 &num_arguments, 684 &num_arguments,
685 &num_named_arguments, 685 &num_named_arguments,
686 &target); 686 &target);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 // fast execution with null receiver is the "==" operator. 810 // fast execution with null receiver is the "==" operator.
811 // Special handling so that we do not pollute the inline cache with null 811 // Special handling so that we do not pollute the inline cache with null
812 // classes. 812 // classes.
813 if (FLAG_trace_ic) { 813 if (FLAG_trace_ic) {
814 OS::Print("InlineCacheMissHandler Null receiver target %s\n", 814 OS::Print("InlineCacheMissHandler Null receiver target %s\n",
815 target_function.ToCString()); 815 target_function.ToCString());
816 } 816 }
817 return target_function.raw(); 817 return target_function.raw();
818 } 818 }
819 DartFrameIterator iterator; 819 DartFrameIterator iterator;
820 DartFrame* caller_frame = iterator.NextFrame(); 820 StackFrame* caller_frame = iterator.NextFrame();
821 ICData& ic_data = ICData::Handle( 821 ICData& ic_data = ICData::Handle(
822 CodePatcher::GetInstanceCallIcDataAt(caller_frame->pc())); 822 CodePatcher::GetInstanceCallIcDataAt(caller_frame->pc()));
823 #if defined(DEBUG) 823 #if defined(DEBUG)
824 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { 824 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) {
825 GrowableArray<const Class*> classes; 825 GrowableArray<const Class*> classes;
826 Function& target = Function::Handle(); 826 Function& target = Function::Handle();
827 ic_data.GetCheckAt(i, &classes, &target); 827 ic_data.GetCheckAt(i, &classes, &target);
828 bool matches = true; 828 bool matches = true;
829 for (intptr_t k = 0; k < classes.length(); k++) { 829 for (intptr_t k = 0; k < classes.length(); k++) {
830 if (classes[k]->raw() != args[k]->clazz()) { 830 if (classes[k]->raw() != args[k]->clazz()) {
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 // The top Dart frame belongs to the optimized method that needs to be 1277 // The top Dart frame belongs to the optimized method that needs to be
1278 // deoptimized. The pc of the Dart frame points to the deoptimization point. 1278 // deoptimized. The pc of the Dart frame points to the deoptimization point.
1279 // Find the node id of the deoptimization point and find the continuation 1279 // Find the node id of the deoptimization point and find the continuation
1280 // pc in the unoptimized code. 1280 // pc in the unoptimized code.
1281 // Since both unoptimized and optimized code have the same layout, we need only 1281 // Since both unoptimized and optimized code have the same layout, we need only
1282 // to patch the pc of the Dart frame and to disable/enable appropriate code. 1282 // to patch the pc of the Dart frame and to disable/enable appropriate code.
1283 DEFINE_RUNTIME_ENTRY(Deoptimize, 1) { 1283 DEFINE_RUNTIME_ENTRY(Deoptimize, 1) {
1284 ASSERT(arguments.Count() == kDeoptimizeRuntimeEntry.argument_count()); 1284 ASSERT(arguments.Count() == kDeoptimizeRuntimeEntry.argument_count());
1285 const Smi& deoptimization_reason_id = Smi::CheckedHandle(arguments.At(0)); 1285 const Smi& deoptimization_reason_id = Smi::CheckedHandle(arguments.At(0));
1286 DartFrameIterator iterator; 1286 DartFrameIterator iterator;
1287 DartFrame* caller_frame = iterator.NextFrame(); 1287 StackFrame* caller_frame = iterator.NextFrame();
1288 ASSERT(caller_frame != NULL); 1288 ASSERT(caller_frame != NULL);
1289 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); 1289 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode());
1290 const Function& function = Function::Handle(optimized_code.function()); 1290 const Function& function = Function::Handle(optimized_code.function());
1291 ASSERT(!function.IsNull()); 1291 ASSERT(!function.IsNull());
1292 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); 1292 const Code& unoptimized_code = Code::Handle(function.unoptimized_code());
1293 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized()); 1293 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized());
1294 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized()); 1294 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized());
1295 const PcDescriptors& descriptors = 1295 const PcDescriptors& descriptors =
1296 PcDescriptors::Handle(optimized_code.pc_descriptors()); 1296 PcDescriptors::Handle(optimized_code.pc_descriptors());
1297 ASSERT(!descriptors.IsNull()); 1297 ASSERT(!descriptors.IsNull());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 } 1429 }
1430 } 1430 }
1431 } 1431 }
1432 // The cache is null terminated, therefore the loop above should never 1432 // The cache is null terminated, therefore the loop above should never
1433 // terminate by itself. 1433 // terminate by itself.
1434 UNREACHABLE(); 1434 UNREACHABLE();
1435 return Code::null(); 1435 return Code::null();
1436 } 1436 }
1437 1437
1438 } // namespace dart 1438 } // namespace dart
OLDNEW
« no previous file with comments | « vm/assembler_x64.cc ('k') | vm/code_generator_ia32.cc » ('j') | vm/stack_frame.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698