| OLD | NEW |
| 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/assembler_macros.h" | 7 #include "vm/assembler_macros.h" |
| 8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 const AbstractType& type, | 327 const AbstractType& type, |
| 328 const AbstractTypeArguments& instantiator_type_arguments, | 328 const AbstractTypeArguments& instantiator_type_arguments, |
| 329 const Bool& result) { | 329 const Bool& result) { |
| 330 DartFrameIterator iterator; | 330 DartFrameIterator iterator; |
| 331 StackFrame* caller_frame = iterator.NextFrame(); | 331 StackFrame* caller_frame = iterator.NextFrame(); |
| 332 ASSERT(caller_frame != NULL); | 332 ASSERT(caller_frame != NULL); |
| 333 | 333 |
| 334 const Type& instance_type = Type::Handle(instance.GetType()); | 334 const Type& instance_type = Type::Handle(instance.GetType()); |
| 335 ASSERT(instance_type.IsInstantiated()); | 335 ASSERT(instance_type.IsInstantiated()); |
| 336 if (type.IsInstantiated()) { | 336 if (type.IsInstantiated()) { |
| 337 OS::Print("%s: '%s' %s '%s' (pc: 0x%x).\n", | 337 OS::Print("%s: '%s' %d %s '%s' %d (pc: 0x%x).\n", |
| 338 message, | 338 message, |
| 339 String::Handle(instance_type.Name()).ToCString(), | 339 String::Handle(instance_type.Name()).ToCString(), |
| 340 Class::Handle(instance_type.type_class()).id(), |
| 340 (result.raw() == Bool::True()) ? "is" : "is !", | 341 (result.raw() == Bool::True()) ? "is" : "is !", |
| 341 String::Handle(type.Name()).ToCString(), | 342 String::Handle(type.Name()).ToCString(), |
| 343 Class::Handle(type.type_class()).id(), |
| 342 caller_frame->pc()); | 344 caller_frame->pc()); |
| 343 } else { | 345 } else { |
| 344 // Instantiate type before printing. | 346 // Instantiate type before printing. |
| 345 const AbstractType& instantiated_type = | 347 const AbstractType& instantiated_type = |
| 346 AbstractType::Handle(type.InstantiateFrom(instantiator_type_arguments)); | 348 AbstractType::Handle(type.InstantiateFrom(instantiator_type_arguments)); |
| 347 OS::Print("%s: '%s' %s '%s' instantiated from '%s' (pc: 0x%x).\n", | 349 OS::Print("%s: '%s' %s '%s' instantiated from '%s' (pc: 0x%x).\n", |
| 348 message, | 350 message, |
| 349 String::Handle(instance_type.Name()).ToCString(), | 351 String::Handle(instance_type.Name()).ToCString(), |
| 350 (result.raw() == Bool::True()) ? "is" : "is !", | 352 (result.raw() == Bool::True()) ? "is" : "is !", |
| 351 String::Handle(instantiated_type.Name()).ToCString(), | 353 String::Handle(instantiated_type.Name()).ToCString(), |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 instance, type, instantiator_type_arguments, result); | 453 instance, type, instantiator_type_arguments, result); |
| 452 } | 454 } |
| 453 return; | 455 return; |
| 454 } | 456 } |
| 455 if (replaced) { | 457 if (replaced) { |
| 456 type_arguments_replaced = true; | 458 type_arguments_replaced = true; |
| 457 } | 459 } |
| 458 instantiator_type_arguments = instantiator.GetTypeArguments(); | 460 instantiator_type_arguments = instantiator.GetTypeArguments(); |
| 459 } | 461 } |
| 460 | 462 |
| 461 Class& last_instance_class = Class::Handle(); | 463 intptr_t last_instance_class_id = -1; |
| 462 AbstractTypeArguments& last_instance_type_arguments = | 464 AbstractTypeArguments& last_instance_type_arguments = |
| 463 AbstractTypeArguments::Handle(); | 465 AbstractTypeArguments::Handle(); |
| 464 AbstractTypeArguments& last_instantiator_type_arguments = | 466 AbstractTypeArguments& last_instantiator_type_arguments = |
| 465 AbstractTypeArguments::Handle(); | 467 AbstractTypeArguments::Handle(); |
| 466 Bool& last_result = Bool::Handle(); | 468 Bool& last_result = Bool::Handle(); |
| 467 intptr_t len = new_cache.NumberOfChecks(); | 469 intptr_t len = new_cache.NumberOfChecks(); |
| 468 for (intptr_t i = 0; i < len; ++i) { | 470 for (intptr_t i = 0; i < len; ++i) { |
| 469 new_cache.GetCheck( | 471 new_cache.GetCheck( |
| 470 i, | 472 i, |
| 471 &last_instance_class, | 473 &last_instance_class_id, |
| 472 &last_instance_type_arguments, | 474 &last_instance_type_arguments, |
| 473 &last_instantiator_type_arguments, | 475 &last_instantiator_type_arguments, |
| 474 &last_result); | 476 &last_result); |
| 475 if ((last_instance_class.raw() == instance_class.raw()) && | 477 if ((last_instance_class_id == instance_class.id()) && |
| 476 (last_instance_type_arguments.raw() == instance_type_arguments.raw()) && | 478 (last_instance_type_arguments.raw() == instance_type_arguments.raw()) && |
| 477 (last_instantiator_type_arguments.raw() == | 479 (last_instantiator_type_arguments.raw() == |
| 478 instantiator_type_arguments.raw())) { | 480 instantiator_type_arguments.raw())) { |
| 479 if (FLAG_trace_type_checks) { | 481 if (FLAG_trace_type_checks) { |
| 480 OS::Print("%d ", i); | 482 OS::Print("%d ", i); |
| 481 if (type_arguments_replaced) { | 483 if (type_arguments_replaced) { |
| 482 PrintTypeCheck("Duplicate cache entry (canonical.)", instance, type, | 484 PrintTypeCheck("Duplicate cache entry (canonical.)", instance, type, |
| 483 instantiator_type_arguments, result); | 485 instantiator_type_arguments, result); |
| 484 } else { | 486 } else { |
| 485 PrintTypeCheck("WARNING Duplicate cache entry", instance, type, | 487 PrintTypeCheck("WARNING Duplicate cache entry", instance, type, |
| 486 instantiator_type_arguments, result); | 488 instantiator_type_arguments, result); |
| 487 } | 489 } |
| 488 } | 490 } |
| 489 // Can occur if we have canonicalized arguments. | 491 // Can occur if we have canonicalized arguments. |
| 490 // TODO(srdjan): Investigate why this assert can fail. | 492 // TODO(srdjan): Investigate why this assert can fail. |
| 491 // ASSERT(type_arguments_replaced); | 493 // ASSERT(type_arguments_replaced); |
| 492 return; | 494 return; |
| 493 } | 495 } |
| 494 } | 496 } |
| 495 new_cache.AddCheck(instance_class, | 497 new_cache.AddCheck(instance_class.id(), |
| 496 instance_type_arguments, | 498 instance_type_arguments, |
| 497 instantiator_type_arguments, | 499 instantiator_type_arguments, |
| 498 result); | 500 result); |
| 499 if (FLAG_trace_type_checks) { | 501 if (FLAG_trace_type_checks) { |
| 500 AbstractType& test_type = AbstractType::Handle(type.raw()); | 502 AbstractType& test_type = AbstractType::Handle(type.raw()); |
| 501 if (!test_type.IsInstantiated()) { | 503 if (!test_type.IsInstantiated()) { |
| 502 test_type = type.InstantiateFrom(instantiator_type_arguments); | 504 test_type = type.InstantiateFrom(instantiator_type_arguments); |
| 503 } | 505 } |
| 504 OS::Print(" Updated test cache 0x%x ix:%d:\n" | 506 OS::Print(" Updated test cache 0x%x ix:%d:\n" |
| 505 " [0x%x %s, 0x%x %s]\n" | 507 " [0x%x %s %d, 0x%x %s]\n" |
| 506 " [0x%x %s, 0x%x %s] %s\n", | 508 " [0x%x %s %d, 0x%x %s] %s\n", |
| 507 new_cache.raw(), | 509 new_cache.raw(), |
| 508 len, | 510 len, |
| 509 instance_class.raw(), | 511 instance_class.raw(), |
| 510 instance_class.ToCString(), | 512 instance_class.ToCString(), |
| 513 instance_class.id(), |
| 511 instance_type_arguments.raw(), | 514 instance_type_arguments.raw(), |
| 512 instance_type_arguments.ToCString(), | 515 instance_type_arguments.ToCString(), |
| 513 test_type.type_class(), | 516 test_type.type_class(), |
| 514 Class::Handle(test_type.type_class()).ToCString(), | 517 Class::Handle(test_type.type_class()).ToCString(), |
| 518 Class::Handle(test_type.type_class()).id(), |
| 515 instantiator_type_arguments.raw(), | 519 instantiator_type_arguments.raw(), |
| 516 instantiator_type_arguments.ToCString(), | 520 instantiator_type_arguments.ToCString(), |
| 517 result.ToCString()); | 521 result.ToCString()); |
| 518 } | 522 } |
| 519 } | 523 } |
| 520 | 524 |
| 521 | 525 |
| 522 // Check that the given instance is an instance of the given type. | 526 // Check that the given instance is an instance of the given type. |
| 523 // Tested instance may not be null, because the null test is inlined. | 527 // Tested instance may not be null, because the null test is inlined. |
| 524 // Arg0: index of the token of the instanceof test (source location). | 528 // Arg0: index of the token of the instanceof test (source location). |
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 } | 1526 } |
| 1523 } | 1527 } |
| 1524 } | 1528 } |
| 1525 // The cache is null terminated, therefore the loop above should never | 1529 // The cache is null terminated, therefore the loop above should never |
| 1526 // terminate by itself. | 1530 // terminate by itself. |
| 1527 UNREACHABLE(); | 1531 UNREACHABLE(); |
| 1528 return Code::null(); | 1532 return Code::null(); |
| 1529 } | 1533 } |
| 1530 | 1534 |
| 1531 } // namespace dart | 1535 } // namespace dart |
| OLD | NEW |