| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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/precompiler.h" | 5 #include "vm/precompiler.h" |
| 6 | 6 |
| 7 #include "vm/aot_optimizer.h" | 7 #include "vm/aot_optimizer.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/branch_optimizer.h" | 10 #include "vm/branch_optimizer.h" |
| (...skipping 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2546 cls = table->At(cid); | 2546 cls = table->At(cid); |
| 2547 THR_Print("%" Pd ": %s, was %" Pd "\n", old_to_new_cid[cid], | 2547 THR_Print("%" Pd ": %s, was %" Pd "\n", old_to_new_cid[cid], |
| 2548 cls.ToCString(), cid); | 2548 cls.ToCString(), cid); |
| 2549 } | 2549 } |
| 2550 } | 2550 } |
| 2551 } | 2551 } |
| 2552 ASSERT(next_new_cid == num_cids); | 2552 ASSERT(next_new_cid == num_cids); |
| 2553 | 2553 |
| 2554 RemapClassIds(old_to_new_cid); | 2554 RemapClassIds(old_to_new_cid); |
| 2555 delete[] old_to_new_cid; | 2555 delete[] old_to_new_cid; |
| 2556 RehashTypes(); // Types use cid's as part of their hashes. |
| 2556 } | 2557 } |
| 2557 | 2558 |
| 2558 | 2559 |
| 2559 class CidRewriteVisitor : public ObjectVisitor { | 2560 class CidRewriteVisitor : public ObjectVisitor { |
| 2560 public: | 2561 public: |
| 2561 explicit CidRewriteVisitor(intptr_t* old_to_new_cids) | 2562 explicit CidRewriteVisitor(intptr_t* old_to_new_cids) |
| 2562 : old_to_new_cids_(old_to_new_cids) {} | 2563 : old_to_new_cids_(old_to_new_cids) {} |
| 2563 | 2564 |
| 2564 intptr_t Map(intptr_t cid) { | 2565 intptr_t Map(intptr_t cid) { |
| 2565 ASSERT(cid != -1); | 2566 ASSERT(cid != -1); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2620 } | 2621 } |
| 2621 } | 2622 } |
| 2622 | 2623 |
| 2623 #if defined(DEBUG) | 2624 #if defined(DEBUG) |
| 2624 I->class_table()->Validate(); | 2625 I->class_table()->Validate(); |
| 2625 I->heap()->Verify(); | 2626 I->heap()->Verify(); |
| 2626 #endif | 2627 #endif |
| 2627 } | 2628 } |
| 2628 | 2629 |
| 2629 | 2630 |
| 2631 class ClearTypeHashVisitor : public ObjectVisitor { |
| 2632 public: |
| 2633 explicit ClearTypeHashVisitor(Zone* zone) |
| 2634 : type_param_(TypeParameter::Handle(zone)), |
| 2635 type_(Type::Handle(zone)), |
| 2636 type_args_(TypeArguments::Handle(zone)), |
| 2637 bounded_type_(BoundedType::Handle(zone)) {} |
| 2638 |
| 2639 void VisitObject(RawObject* obj) { |
| 2640 if (obj->IsTypeParameter()) { |
| 2641 type_param_ ^= obj; |
| 2642 type_param_.SetHash(0); |
| 2643 } else if (obj->IsType()) { |
| 2644 type_ ^= obj; |
| 2645 type_.SetHash(0); |
| 2646 } else if (obj->IsBoundedType()) { |
| 2647 bounded_type_ ^= obj; |
| 2648 bounded_type_.SetHash(0); |
| 2649 } else if (obj->IsTypeArguments()) { |
| 2650 type_args_ ^= obj; |
| 2651 type_args_.SetHash(0); |
| 2652 } |
| 2653 } |
| 2654 |
| 2655 private: |
| 2656 TypeParameter& type_param_; |
| 2657 Type& type_; |
| 2658 TypeArguments& type_args_; |
| 2659 BoundedType& bounded_type_; |
| 2660 }; |
| 2661 |
| 2662 |
| 2663 void Precompiler::RehashTypes() { |
| 2664 // Clear all cached hash values. |
| 2665 { |
| 2666 HeapIterationScope his; |
| 2667 ClearTypeHashVisitor visitor(Z); |
| 2668 I->heap()->VisitObjects(&visitor); |
| 2669 } |
| 2670 |
| 2671 // Rehash the canonical Types table. |
| 2672 ObjectStore* object_store = I->object_store(); |
| 2673 GrowableObjectArray& types = |
| 2674 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); |
| 2675 Array& types_array = Array::Handle(Z); |
| 2676 Type& type = Type::Handle(Z); |
| 2677 { |
| 2678 CanonicalTypeSet types_table(Z, object_store->canonical_types()); |
| 2679 types_array = HashTables::ToArray(types_table, false); |
| 2680 for (intptr_t i = 0; i < (types_array.Length() - 1); i++) { |
| 2681 type ^= types_array.At(i); |
| 2682 types.Add(type); |
| 2683 } |
| 2684 types_table.Release(); |
| 2685 } |
| 2686 |
| 2687 intptr_t dict_size = Utils::RoundUpToPowerOfTwo(types.Length() * 4 / 3); |
| 2688 types_array = HashTables::New<CanonicalTypeSet>(dict_size, Heap::kOld); |
| 2689 CanonicalTypeSet types_table(Z, types_array.raw()); |
| 2690 for (intptr_t i = 0; i < types.Length(); i++) { |
| 2691 type ^= types.At(i); |
| 2692 bool present = types_table.Insert(type); |
| 2693 ASSERT(!present); |
| 2694 } |
| 2695 object_store->set_canonical_types(types_table.Release()); |
| 2696 |
| 2697 // Rehash the canonical TypeArguments table. |
| 2698 Array& typeargs_array = Array::Handle(Z); |
| 2699 GrowableObjectArray& typeargs = |
| 2700 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); |
| 2701 TypeArguments& typearg = TypeArguments::Handle(Z); |
| 2702 { |
| 2703 CanonicalTypeArgumentsSet typeargs_table( |
| 2704 Z, object_store->canonical_type_arguments()); |
| 2705 typeargs_array = HashTables::ToArray(typeargs_table, false); |
| 2706 for (intptr_t i = 0; i < (typeargs_array.Length() - 1); i++) { |
| 2707 typearg ^= typeargs_array.At(i); |
| 2708 typeargs.Add(typearg); |
| 2709 } |
| 2710 typeargs_table.Release(); |
| 2711 } |
| 2712 |
| 2713 dict_size = Utils::RoundUpToPowerOfTwo(typeargs.Length() * 4 / 3); |
| 2714 typeargs_array = |
| 2715 HashTables::New<CanonicalTypeArgumentsSet>(dict_size, Heap::kOld); |
| 2716 CanonicalTypeArgumentsSet typeargs_table(Z, typeargs_array.raw()); |
| 2717 for (intptr_t i = 0; i < typeargs.Length(); i++) { |
| 2718 typearg ^= typeargs.At(i); |
| 2719 bool present = typeargs_table.Insert(typearg); |
| 2720 ASSERT(!present); |
| 2721 } |
| 2722 object_store->set_canonical_type_arguments(typeargs_table.Release()); |
| 2723 } |
| 2724 |
| 2725 |
| 2630 void Precompiler::VerifyJITFeedback() { | 2726 void Precompiler::VerifyJITFeedback() { |
| 2631 if (jit_feedback_ == NULL) return; | 2727 if (jit_feedback_ == NULL) return; |
| 2632 | 2728 |
| 2633 ParsedJSONString* js_vmversion = jit_feedback_->StringAt("vmVersion"); | 2729 ParsedJSONString* js_vmversion = jit_feedback_->StringAt("vmVersion"); |
| 2634 if ((js_vmversion == NULL) || | 2730 if ((js_vmversion == NULL) || |
| 2635 strcmp(js_vmversion->value(), Version::CommitString()) != 0) { | 2731 strcmp(js_vmversion->value(), Version::CommitString()) != 0) { |
| 2636 THR_Print( | 2732 THR_Print( |
| 2637 "JIT feedback contains invalid vm version " | 2733 "JIT feedback contains invalid vm version " |
| 2638 "(saw %s, expected %s).\n", | 2734 "(saw %s, expected %s).\n", |
| 2639 js_vmversion->value(), Version::CommitString()); | 2735 js_vmversion->value(), Version::CommitString()); |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3667 | 3763 |
| 3668 ASSERT(FLAG_precompiled_mode); | 3764 ASSERT(FLAG_precompiled_mode); |
| 3669 const bool optimized = function.IsOptimizable(); // False for natives. | 3765 const bool optimized = function.IsOptimizable(); // False for natives. |
| 3670 DartPrecompilationPipeline pipeline(zone, field_type_map); | 3766 DartPrecompilationPipeline pipeline(zone, field_type_map); |
| 3671 return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized); | 3767 return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized); |
| 3672 } | 3768 } |
| 3673 | 3769 |
| 3674 #endif // DART_PRECOMPILER | 3770 #endif // DART_PRECOMPILER |
| 3675 | 3771 |
| 3676 } // namespace dart | 3772 } // namespace dart |
| OLD | NEW |