| 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/globals.h" // Needed here to get TARGET_ARCH_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/code_generator.h" | 8 #include "vm/code_generator.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 TypeArguments::Handle(), | 1413 TypeArguments::Handle(), |
| 1414 &malformed_error)) { | 1414 &malformed_error)) { |
| 1415 __ PushObject(negate_result ? bool_false : bool_true); | 1415 __ PushObject(negate_result ? bool_false : bool_true); |
| 1416 } else { | 1416 } else { |
| 1417 __ PushObject(negate_result ? bool_true : bool_false); | 1417 __ PushObject(negate_result ? bool_true : bool_false); |
| 1418 } | 1418 } |
| 1419 __ jmp(&done, Assembler::kNearJump); | 1419 __ jmp(&done, Assembler::kNearJump); |
| 1420 | 1420 |
| 1421 // Compare if the classes are equal. | 1421 // Compare if the classes are equal. |
| 1422 __ Bind(&compare_classes); | 1422 __ Bind(&compare_classes); |
| 1423 const Class* compare_class = NULL; | 1423 // Note that in instanceof both positive and negative tests must be fast. |
| 1424 if (type.IsStringInterface()) { | 1424 if (type.IsBoolInterface()) { |
| 1425 compare_class = &Class::ZoneHandle( | 1425 // Bool interface has only bool class. |
| 1426 Isolate::Current()->object_store()->one_byte_string_class()); | 1426 Label is_bool; |
| 1427 } else if (type.IsBoolInterface()) { | 1427 const Class & bool_class = Class::ZoneHandle( |
| 1428 compare_class = &Class::ZoneHandle( | |
| 1429 Isolate::Current()->object_store()->bool_class()); | 1428 Isolate::Current()->object_store()->bool_class()); |
| 1430 } else if (!type_class.is_interface()) { | 1429 __ movl(ECX, FieldAddress(EAX, Object::class_offset())); |
| 1431 // Use equality test in prolog of cache test. | 1430 __ CompareObject(ECX, bool_class); |
| 1432 compare_class = NULL; | 1431 __ j(EQUAL, &is_bool, Assembler::kNearJump); |
| 1432 __ PushObject(negate_result ? bool_true : bool_false); |
| 1433 __ jmp(&done); |
| 1434 __ Bind(&is_bool); |
| 1435 __ PushObject(negate_result ? bool_false : bool_true); |
| 1436 __ Bind(&done); |
| 1437 return; |
| 1433 } | 1438 } |
| 1439 |
| 1434 // EAX: instance being tested. | 1440 // EAX: instance being tested. |
| 1435 if (compare_class == NULL) { | 1441 // Optional quick equality check and then the type test cache test. |
| 1436 // Optional quick equality check and then the type test cache test. | 1442 Label loop, runtime_call, found_in_cache, cache_test; |
| 1437 Label loop, runtime_call, found_in_cache, cache_test; | 1443 __ movl(ECX, FieldAddress(EAX, Object::class_offset())); |
| 1438 __ movl(ECX, FieldAddress(EAX, Object::class_offset())); | 1444 if (!type_class.is_interface()) { |
| 1439 if (!type_class.is_interface()) { | 1445 // Class equality test first. |
| 1440 // Class equality test first. | 1446 __ CompareObject(ECX, type_class); |
| 1441 __ CompareObject(ECX, type_class); | 1447 __ j(NOT_EQUAL, &cache_test, Assembler::kNearJump); |
| 1442 __ j(NOT_EQUAL, &cache_test, Assembler::kNearJump); | 1448 // Equal! |
| 1443 // Equal! | |
| 1444 __ PushObject(negate_result ? bool_false : bool_true); | |
| 1445 __ jmp(&done, Assembler::kNearJump); | |
| 1446 } | |
| 1447 __ Bind(&cache_test); | |
| 1448 // TODO(srdjan): Convert other tests to this simple form. | |
| 1449 // Class we are testing against has no type arguments. | |
| 1450 // TODO(srdjan): Canonicalize initial array? | |
| 1451 // TODO(srdjan): Account for 'negate_result' in cache. | |
| 1452 // The type test array is null-terminated. Two consecutive | |
| 1453 // array elements correspond to one test: | |
| 1454 // array[i + 0] : class. | |
| 1455 // array[i + 1] : result for the class. | |
| 1456 AddCurrentDescriptor(PcDescriptors::kTypeTest, node_id, token_index); | |
| 1457 __ LoadObject(EDX, Array::ZoneHandle(Array::New(2))); | |
| 1458 __ addl(EDX, Immediate(Array::data_offset() - kHeapObjectTag)); | |
| 1459 __ Bind(&loop); | |
| 1460 __ movl(EBX, Address(EDX, 0)); | |
| 1461 __ cmpl(ECX, EBX); | |
| 1462 __ j(EQUAL, &found_in_cache, Assembler::kNearJump); | |
| 1463 __ addl(EDX, Immediate(kWordSize * 2)); | |
| 1464 __ cmpl(EBX, raw_null); | |
| 1465 __ j(NOT_EQUAL, &loop, Assembler::kNearJump); | |
| 1466 __ jmp(&runtime_call, Assembler::kNearJump); | |
| 1467 __ Bind(&found_in_cache); | |
| 1468 __ pushl(Address(EDX, kWordSize)); | |
| 1469 __ jmp(&check_negate_done); | |
| 1470 __ Bind(&runtime_call); | |
| 1471 } else { | |
| 1472 Label runtime_call; | |
| 1473 __ movl(ECX, FieldAddress(EAX, Object::class_offset())); | |
| 1474 __ CompareObject(ECX, *compare_class); | |
| 1475 __ j(NOT_EQUAL, &runtime_call, Assembler::kNearJump); | |
| 1476 __ PushObject(negate_result ? bool_false : bool_true); | 1449 __ PushObject(negate_result ? bool_false : bool_true); |
| 1477 __ jmp(&done, Assembler::kNearJump); | 1450 __ jmp(&done, Assembler::kNearJump); |
| 1478 __ Bind(&runtime_call); | |
| 1479 } | 1451 } |
| 1452 __ Bind(&cache_test); |
| 1453 // TODO(srdjan): Convert other tests to this simple form. |
| 1454 // Class we are testing against has no type arguments. |
| 1455 // TODO(srdjan): Canonicalize initial array? |
| 1456 // TODO(srdjan): Account for 'negate_result' in cache. |
| 1457 // The type test array is null-terminated. Two consecutive |
| 1458 // array elements correspond to one test: |
| 1459 // array[i + 0] : class. |
| 1460 // array[i + 1] : result for the class. |
| 1461 AddCurrentDescriptor(PcDescriptors::kTypeTest, node_id, token_index); |
| 1462 __ LoadObject(EDX, Array::ZoneHandle(Array::New(2))); |
| 1463 __ addl(EDX, Immediate(Array::data_offset() - kHeapObjectTag)); |
| 1464 __ Bind(&loop); |
| 1465 __ movl(EBX, Address(EDX, 0)); |
| 1466 __ cmpl(ECX, EBX); |
| 1467 __ j(EQUAL, &found_in_cache, Assembler::kNearJump); |
| 1468 __ addl(EDX, Immediate(kWordSize * 2)); |
| 1469 __ cmpl(EBX, raw_null); |
| 1470 __ j(NOT_EQUAL, &loop, Assembler::kNearJump); |
| 1471 __ jmp(&runtime_call, Assembler::kNearJump); |
| 1472 __ Bind(&found_in_cache); |
| 1473 __ pushl(Address(EDX, kWordSize)); |
| 1474 __ jmp(&check_negate_done); |
| 1475 __ Bind(&runtime_call); |
| 1480 } | 1476 } |
| 1481 } | 1477 } |
| 1482 __ PushObject(Object::ZoneHandle()); // Make room for the result. | 1478 __ PushObject(Object::ZoneHandle()); // Make room for the result. |
| 1483 const Immediate location = | 1479 const Immediate location = |
| 1484 Immediate(reinterpret_cast<int32_t>(Smi::New(token_index))); | 1480 Immediate(reinterpret_cast<int32_t>(Smi::New(token_index))); |
| 1485 const Immediate node_id_as_smi = | 1481 const Immediate node_id_as_smi = |
| 1486 Immediate(reinterpret_cast<int32_t>(Smi::New(node_id))); | 1482 Immediate(reinterpret_cast<int32_t>(Smi::New(node_id))); |
| 1487 __ pushl(location); // Push the source location. | 1483 __ pushl(location); // Push the source location. |
| 1488 __ pushl(node_id_as_smi); // node-id. | 1484 __ pushl(node_id_as_smi); // node-id. |
| 1489 __ pushl(EAX); // Push the instance. | 1485 __ pushl(EAX); // Push the instance. |
| (...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2890 const Error& error = Error::Handle( | 2886 const Error& error = Error::Handle( |
| 2891 Parser::FormatError(script, token_index, "Error", format, args)); | 2887 Parser::FormatError(script, token_index, "Error", format, args)); |
| 2892 va_end(args); | 2888 va_end(args); |
| 2893 Isolate::Current()->long_jump_base()->Jump(1, error); | 2889 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2894 UNREACHABLE(); | 2890 UNREACHABLE(); |
| 2895 } | 2891 } |
| 2896 | 2892 |
| 2897 } // namespace dart | 2893 } // namespace dart |
| 2898 | 2894 |
| 2899 #endif // defined TARGET_ARCH_IA32 | 2895 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |