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

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

Issue 382993003: More PcDescriptor cleanups. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 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
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/parser.h » ('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 "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 2710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 EXPECT_EQ(150, handlers.HandlerPC(3)); 2721 EXPECT_EQ(150, handlers.HandlerPC(3));
2722 EXPECT(!handlers.NeedsStacktrace(3)); 2722 EXPECT(!handlers.NeedsStacktrace(3));
2723 EXPECT(handlers.HasCatchAll(3)); 2723 EXPECT(handlers.HasCatchAll(3));
2724 } 2724 }
2725 2725
2726 2726
2727 TEST_CASE(PcDescriptors) { 2727 TEST_CASE(PcDescriptors) {
2728 const int kNumEntries = 6; 2728 const int kNumEntries = 6;
2729 // Add PcDescriptors to the code. 2729 // Add PcDescriptors to the code.
2730 PcDescriptors& descriptors = PcDescriptors::Handle(); 2730 PcDescriptors& descriptors = PcDescriptors::Handle();
2731 descriptors ^= PcDescriptors::New(kNumEntries); 2731 descriptors ^= PcDescriptors::New(kNumEntries, true);
2732 descriptors.AddDescriptor(0, 10, RawPcDescriptors::kOther, 1, 20, 1); 2732 descriptors.AddDescriptor(0, 10, RawPcDescriptors::kOther, 1, 20, 1);
2733 descriptors.AddDescriptor(1, 20, RawPcDescriptors::kDeopt, 2, 30, 0); 2733 descriptors.AddDescriptor(1, 20, RawPcDescriptors::kDeopt, 2, 30, 0);
2734 descriptors.AddDescriptor(2, 30, RawPcDescriptors::kOther, 3, 40, 1); 2734 descriptors.AddDescriptor(2, 30, RawPcDescriptors::kOther, 3, 40, 1);
2735 descriptors.AddDescriptor(3, 10, RawPcDescriptors::kOther, 4, 40, 2); 2735 descriptors.AddDescriptor(3, 10, RawPcDescriptors::kOther, 4, 40, 2);
2736 descriptors.AddDescriptor(4, 10, RawPcDescriptors::kOther, 5, 80, 3); 2736 descriptors.AddDescriptor(4, 10, RawPcDescriptors::kOther, 5, 80, 3);
2737 descriptors.AddDescriptor(5, 80, RawPcDescriptors::kOther, 6, 150, 3); 2737 descriptors.AddDescriptor(5, 80, RawPcDescriptors::kOther, 6, 150, 3);
2738 2738
2739 extern void GenerateIncrement(Assembler* assembler); 2739 extern void GenerateIncrement(Assembler* assembler);
2740 Assembler _assembler_; 2740 Assembler _assembler_;
2741 GenerateIncrement(&_assembler_); 2741 GenerateIncrement(&_assembler_);
2742 Code& code = Code::Handle(Code::FinalizeCode( 2742 Code& code = Code::Handle(Code::FinalizeCode(
2743 *CreateFunction("Test_Code"), &_assembler_)); 2743 *CreateFunction("Test_Code"), &_assembler_));
2744 code.set_pc_descriptors(descriptors); 2744 code.set_pc_descriptors(descriptors);
2745 2745
2746 // Verify the PcDescriptor entries by accessing them. 2746 // Verify the PcDescriptor entries by accessing them.
2747 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors()); 2747 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors());
2748 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind); 2748 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind);
2749 const RawPcDescriptors::PcDescriptorRec& rec0 = iter.Next(); 2749 const RawPcDescriptors::PcDescriptorRec& rec0 = iter.Next();
2750 const RawPcDescriptors::PcDescriptorRec& rec1 = iter.Next(); 2750 const RawPcDescriptors::PcDescriptorRec& rec1 = iter.Next();
2751 const RawPcDescriptors::PcDescriptorRec& rec2 = iter.Next(); 2751 const RawPcDescriptors::PcDescriptorRec& rec2 = iter.Next();
2752 const RawPcDescriptors::PcDescriptorRec& rec3 = iter.Next(); 2752 const RawPcDescriptors::PcDescriptorRec& rec3 = iter.Next();
2753 const RawPcDescriptors::PcDescriptorRec& rec4 = iter.Next(); 2753 const RawPcDescriptors::PcDescriptorRec& rec4 = iter.Next();
2754 const RawPcDescriptors::PcDescriptorRec& rec5 = iter.Next(); 2754 const RawPcDescriptors::PcDescriptorRec& rec5 = iter.Next();
2755 ASSERT(!iter.HasNext()); 2755 ASSERT(!iter.HasNext());
2756 2756
2757 EXPECT_EQ(1, rec0.try_index); 2757 EXPECT_EQ(1, rec0.try_index());
2758 EXPECT_EQ(static_cast<uword>(10), rec0.pc); 2758 EXPECT_EQ(static_cast<uword>(10), rec0.pc());
2759 EXPECT_EQ(1, rec0.deopt_id); 2759 EXPECT_EQ(1, rec0.deopt_id());
2760 EXPECT_EQ(20, rec0.token_pos); 2760 EXPECT_EQ(20, rec0.token_pos());
2761 2761
2762 EXPECT_EQ(3, rec5.try_index); 2762 EXPECT_EQ(3, rec5.try_index());
2763 EXPECT_EQ(static_cast<uword>(80), rec5.pc); 2763 EXPECT_EQ(static_cast<uword>(80), rec5.pc());
2764 EXPECT_EQ(150, rec5.token_pos); 2764 EXPECT_EQ(150, rec5.token_pos());
2765 EXPECT_EQ(RawPcDescriptors::kOther, rec0.kind()); 2765 EXPECT_EQ(RawPcDescriptors::kOther, rec0.kind());
2766 EXPECT_EQ(RawPcDescriptors::kDeopt, rec1.kind()); 2766 EXPECT_EQ(RawPcDescriptors::kDeopt, rec1.kind());
2767 2767
2768 EXPECT_EQ(30, rec1.token_pos); 2768 EXPECT_EQ(30, rec1.token_pos());
2769 EXPECT_EQ(40, rec2.token_pos); 2769 EXPECT_EQ(40, rec2.token_pos());
2770 EXPECT_EQ(40, rec3.token_pos); 2770 EXPECT_EQ(40, rec3.token_pos());
2771 EXPECT_EQ(80, rec4.token_pos); 2771 EXPECT_EQ(80, rec4.token_pos());
2772 } 2772 }
2773 2773
2774 2774
2775 TEST_CASE(PcDescriptorsCompressed) {
2776 const int kNumEntries = 6;
2777 // Add PcDescriptors to the code.
2778 PcDescriptors& descriptors = PcDescriptors::Handle();
2779 // PcDescritpors have no try-index.
2780 descriptors ^= PcDescriptors::New(kNumEntries, false);
2781 descriptors.AddDescriptor(0, 10, RawPcDescriptors::kOther, 1, 20, -1);
2782 descriptors.AddDescriptor(1, 20, RawPcDescriptors::kDeopt, 2, 30, -1);
2783 descriptors.AddDescriptor(2, 30, RawPcDescriptors::kOther, 3, 40, -1);
2784 descriptors.AddDescriptor(3, 10, RawPcDescriptors::kOther, 4, 40, -1);
2785 descriptors.AddDescriptor(4, 10, RawPcDescriptors::kOther, 5, 80, -1);
2786 descriptors.AddDescriptor(5, 80, RawPcDescriptors::kOther, 6, 150, -1);
2787
2788 extern void GenerateIncrement(Assembler* assembler);
2789 Assembler _assembler_;
2790 GenerateIncrement(&_assembler_);
2791 Code& code = Code::Handle(Code::FinalizeCode(
2792 *CreateFunction("Test_Code"), &_assembler_));
2793 code.set_pc_descriptors(descriptors);
2794
2795 // Verify the PcDescriptor entries by accessing them.
2796 const PcDescriptors& pc_descs = PcDescriptors::Handle(code.pc_descriptors());
2797 PcDescriptors::Iterator iter(pc_descs, RawPcDescriptors::kAnyKind);
2798 const RawPcDescriptors::PcDescriptorRec& rec0 = iter.Next();
2799 const RawPcDescriptors::PcDescriptorRec& rec1 = iter.Next();
2800 const RawPcDescriptors::PcDescriptorRec& rec2 = iter.Next();
2801 const RawPcDescriptors::PcDescriptorRec& rec3 = iter.Next();
2802 const RawPcDescriptors::PcDescriptorRec& rec4 = iter.Next();
2803 const RawPcDescriptors::PcDescriptorRec& rec5 = iter.Next();
2804 ASSERT(!iter.HasNext());
2805
2806 EXPECT_EQ(-1, rec0.try_index());
2807 EXPECT_EQ(static_cast<uword>(10), rec0.pc());
2808 EXPECT_EQ(1, rec0.deopt_id());
2809 EXPECT_EQ(20, rec0.token_pos());
2810
2811 EXPECT_EQ(-1, rec5.try_index());
2812 EXPECT_EQ(static_cast<uword>(80), rec5.pc());
2813 EXPECT_EQ(150, rec5.token_pos());
2814 EXPECT_EQ(RawPcDescriptors::kOther, rec0.kind());
2815 EXPECT_EQ(RawPcDescriptors::kDeopt, rec1.kind());
2816
2817 EXPECT_EQ(30, rec1.token_pos());
2818 EXPECT_EQ(40, rec2.token_pos());
2819 EXPECT_EQ(40, rec3.token_pos());
2820 EXPECT_EQ(80, rec4.token_pos());
2821 }
2822
2823
2824
2775 static RawClass* CreateTestClass(const char* name) { 2825 static RawClass* CreateTestClass(const char* name) {
2776 const String& class_name = String::Handle(Symbols::New(name)); 2826 const String& class_name = String::Handle(Symbols::New(name));
2777 const Class& cls = Class::Handle( 2827 const Class& cls = Class::Handle(
2778 CreateDummyClass(class_name, Script::Handle())); 2828 CreateDummyClass(class_name, Script::Handle()));
2779 return cls.raw(); 2829 return cls.raw();
2780 } 2830 }
2781 2831
2782 2832
2783 static RawField* CreateTestField(const char* name) { 2833 static RawField* CreateTestField(const char* name) {
2784 const Class& cls = Class::Handle(CreateTestClass("global:")); 2834 const Class& cls = Class::Handle(CreateTestClass("global:"));
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 EXPECT_VALID(h_result); 4198 EXPECT_VALID(h_result);
4149 Integer& result = Integer::Handle(); 4199 Integer& result = Integer::Handle();
4150 result ^= Api::UnwrapHandle(h_result); 4200 result ^= Api::UnwrapHandle(h_result);
4151 String& foo = String::Handle(String::New("foo")); 4201 String& foo = String::Handle(String::New("foo"));
4152 Integer& expected = Integer::Handle(); 4202 Integer& expected = Integer::Handle();
4153 expected ^= foo.HashCode(); 4203 expected ^= foo.HashCode();
4154 EXPECT(result.IsIdenticalTo(expected)); 4204 EXPECT(result.IsIdenticalTo(expected));
4155 } 4205 }
4156 4206
4157 } // namespace dart 4207 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698