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

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

Issue 10832410: Give a length field to stack bitmaps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 8 years, 4 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/bitmap.cc ('k') | runtime/vm/code_descriptors.cc » ('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/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bitmap.h" 6 #include "vm/bitmap.h"
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 TEST_CASE(BitmapBuilder) { 12 TEST_CASE(BitmapBuilder) {
13 // Test basic bit map builder operations. 13 // Test basic bit map builder operations.
14 BitmapBuilder* builder1 = new BitmapBuilder(); 14 BitmapBuilder* builder1 = new BitmapBuilder();
15 15 EXPECT_EQ(0, builder1->Length());
16 EXPECT_EQ(-1, builder1->Maximum());
17 EXPECT_EQ(-1, builder1->Minimum());
18 16
19 bool value = true; 17 bool value = true;
20 for (int32_t i = 0; i < 128; i++) { 18 for (int32_t i = 0; i < 128; i++) {
21 builder1->Set(i, value); 19 builder1->Set(i, value);
22 value = !value; 20 value = !value;
23 } 21 }
22 EXPECT_EQ(128, builder1->Length());
24 value = true; 23 value = true;
25 for (int32_t i = 0; i < 128; i++) { 24 for (int32_t i = 0; i < 128; i++) {
26 EXPECT_EQ(value, builder1->Get(i)); 25 EXPECT_EQ(value, builder1->Get(i));
27 value = !value; 26 value = !value;
28 } 27 }
29 value = true; 28 value = true;
30 for (int32_t i = 0; i < 1024; i++) { 29 for (int32_t i = 0; i < 1024; i++) {
31 builder1->Set(i, value); 30 builder1->Set(i, value);
32 value = !value; 31 value = !value;
33 } 32 }
33 EXPECT_EQ(1024, builder1->Length());
34 value = true; 34 value = true;
35 for (int32_t i = 0; i < 1024; i++) { 35 for (int32_t i = 0; i < 1024; i++) {
36 EXPECT_EQ(value, builder1->Get(i)); 36 EXPECT_EQ(value, builder1->Get(i));
37 value = !value; 37 value = !value;
38 } 38 }
39 // Create a Stackmap object from the builder and verify its contents. 39 // Create a Stackmap object from the builder and verify its contents.
40 const Stackmap& stackmap1 = 40 const Stackmap& stackmap1 = Stackmap::Handle(Stackmap::New(0, builder1));
41 Stackmap::Handle(Stackmap::New(0, 1024, builder1)); 41 EXPECT_EQ(1024, stackmap1.Length());
42 EXPECT_EQ(1022, builder1->Maximum());
43 EXPECT_EQ(0, builder1->Minimum());
44 OS::Print("%s\n", stackmap1.ToCString()); 42 OS::Print("%s\n", stackmap1.ToCString());
45 value = true; 43 value = true;
46 for (int32_t i = 0; i < 1024; i++) { 44 for (int32_t i = 0; i < 1024; i++) {
47 EXPECT_EQ(value, stackmap1.IsObject(i)); 45 EXPECT_EQ(value, stackmap1.IsObject(i));
48 value = !value; 46 value = !value;
49 } 47 }
50 EXPECT(!stackmap1.IsObject(2056)); // Out of range so returns false.
51 48
52 // Test the SetRange function in the builder. 49 // Test the SetRange function in the builder.
53 builder1->SetRange(0, 256, false); 50 builder1->SetRange(0, 256, false);
51 EXPECT_EQ(1024, builder1->Length());
54 builder1->SetRange(257, 1024, true); 52 builder1->SetRange(257, 1024, true);
53 EXPECT_EQ(1025, builder1->Length());
55 builder1->SetRange(1025, 2048, false); 54 builder1->SetRange(1025, 2048, false);
55 EXPECT_EQ(2049, builder1->Length());
56 for (int32_t i = 0; i <= 256; i++) { 56 for (int32_t i = 0; i <= 256; i++) {
57 EXPECT(!builder1->Get(i)); 57 EXPECT(!builder1->Get(i));
58 } 58 }
59 for (int32_t i = 257; i <= 1024; i++) { 59 for (int32_t i = 257; i <= 1024; i++) {
60 EXPECT(builder1->Get(i)); 60 EXPECT(builder1->Get(i));
61 } 61 }
62 for (int32_t i = 1025; i <= 2048; i++) { 62 for (int32_t i = 1025; i <= 2048; i++) {
63 EXPECT(!builder1->Get(i)); 63 EXPECT(!builder1->Get(i));
64 } 64 }
65 const Stackmap& stackmap2 = 65 const Stackmap& stackmap2 = Stackmap::Handle(Stackmap::New(0, builder1));
66 Stackmap::Handle(Stackmap::New(0, 2049, builder1)); 66 EXPECT_EQ(2049, stackmap2.Length());
67 EXPECT_EQ(1024, builder1->Maximum());
68 EXPECT_EQ(257, builder1->Minimum());
69 for (int32_t i = 0; i <= 256; i++) { 67 for (int32_t i = 0; i <= 256; i++) {
70 EXPECT(!stackmap2.IsObject(i)); 68 EXPECT(!stackmap2.IsObject(i));
71 } 69 }
72 for (int32_t i = 257; i <= 1024; i++) { 70 for (int32_t i = 257; i <= 1024; i++) {
73 EXPECT(stackmap2.IsObject(i)); 71 EXPECT(stackmap2.IsObject(i));
74 } 72 }
75 for (int32_t i = 1025; i <= 2048; i++) { 73 for (int32_t i = 1025; i <= 2048; i++) {
76 EXPECT(!stackmap2.IsObject(i)); 74 EXPECT(!stackmap2.IsObject(i));
77 } 75 }
76
77 // Test using SetLength to shorten the builder, followed by lengthening.
78 builder1->SetLength(747);
79 EXPECT_EQ(747, builder1->Length());
80 for (int32_t i = 257; i < 747; ++i) {
81 EXPECT(builder1->Get(i));
82 }
83
84 builder1->Set(800, false);
85 EXPECT_EQ(801, builder1->Length());
86 for (int32_t i = 257; i < 747; ++i) {
87 EXPECT(builder1->Get(i));
88 }
89 for (int32_t i = 747; i < 801; ++i) {
90 EXPECT(!builder1->Get(i));
91 }
92
93 builder1->Set(900, true);
94 EXPECT_EQ(901, builder1->Length());
95 for (int32_t i = 257; i < 747; ++i) {
96 EXPECT(builder1->Get(i));
97 }
98 for (int32_t i = 747; i < 900; ++i) {
99 EXPECT(!builder1->Get(i));
100 }
101 EXPECT(builder1->Get(900));
78 } 102 }
79 103
80 } // namespace dart 104 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bitmap.cc ('k') | runtime/vm/code_descriptors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698