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

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

Issue 11040062: Renamed Zone->StackZone, BaseZone->Zone, in preparation for changing isolate->get_zone() to return … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review changes Created 8 years, 2 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/zone.cc ('k') | no next file » | 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/dart.h" 6 #include "vm/dart.h"
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 #include "vm/zone.h" 9 #include "vm/zone.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DECLARE_DEBUG_FLAG(bool, trace_zone_sizes); 13 DECLARE_DEBUG_FLAG(bool, trace_zone_sizes);
14 14
15 UNIT_TEST_CASE(AllocateZone) { 15 UNIT_TEST_CASE(AllocateZone) {
16 #if defined(DEBUG) 16 #if defined(DEBUG)
17 FLAG_trace_zone_sizes = true; 17 FLAG_trace_zone_sizes = true;
18 #endif 18 #endif
19 Isolate* isolate = Isolate::Init(NULL); 19 Isolate* isolate = Isolate::Init(NULL);
20 EXPECT(Isolate::Current() == isolate); 20 EXPECT(Isolate::Current() == isolate);
21 EXPECT(isolate->current_zone() == NULL); 21 EXPECT(isolate->current_zone() == NULL);
22 { 22 {
23 Zone zone(isolate); 23 StackZone zone(isolate);
24 EXPECT(isolate->current_zone() != NULL); 24 EXPECT(isolate->current_zone() != NULL);
25 intptr_t allocated_size = 0; 25 intptr_t allocated_size = 0;
26 26
27 // The loop is to make sure we overflow one segment and go on 27 // The loop is to make sure we overflow one segment and go on
28 // to the next segment. 28 // to the next segment.
29 for (int i = 0; i < 1000; i++) { 29 for (int i = 0; i < 1000; i++) {
30 uword first = zone.AllocUnsafe(2 * kWordSize); 30 uword first = zone.AllocUnsafe(2 * kWordSize);
31 uword second = zone.AllocUnsafe(3 * kWordSize); 31 uword second = zone.AllocUnsafe(3 * kWordSize);
32 EXPECT(first != second); 32 EXPECT(first != second);
33 allocated_size = ((2 + 3) * kWordSize); 33 allocated_size = ((2 + 3) * kWordSize);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 75
76 UNIT_TEST_CASE(AllocGeneric_Success) { 76 UNIT_TEST_CASE(AllocGeneric_Success) {
77 #if defined(DEBUG) 77 #if defined(DEBUG)
78 FLAG_trace_zone_sizes = true; 78 FLAG_trace_zone_sizes = true;
79 #endif 79 #endif
80 Isolate* isolate = Isolate::Init(NULL); 80 Isolate* isolate = Isolate::Init(NULL);
81 EXPECT(Isolate::Current() == isolate); 81 EXPECT(Isolate::Current() == isolate);
82 EXPECT(isolate->current_zone() == NULL); 82 EXPECT(isolate->current_zone() == NULL);
83 { 83 {
84 Zone zone(isolate); 84 StackZone zone(isolate);
85 EXPECT(isolate->current_zone() != NULL); 85 EXPECT(isolate->current_zone() != NULL);
86 intptr_t allocated_size = 0; 86 intptr_t allocated_size = 0;
87 87
88 const intptr_t kNumElements = 1000; 88 const intptr_t kNumElements = 1000;
89 zone.Alloc<uint32_t>(kNumElements); 89 zone.Alloc<uint32_t>(kNumElements);
90 allocated_size += sizeof(uint32_t) * kNumElements; 90 allocated_size += sizeof(uint32_t) * kNumElements;
91 EXPECT_LE(allocated_size, zone.SizeInBytes()); 91 EXPECT_LE(allocated_size, zone.SizeInBytes());
92 } 92 }
93 EXPECT(isolate->current_zone() == NULL); 93 EXPECT(isolate->current_zone() == NULL);
94 isolate->Shutdown(); 94 isolate->Shutdown();
95 delete isolate; 95 delete isolate;
96 } 96 }
97 97
98 98
99 // This test is expected to crash. 99 // This test is expected to crash.
100 UNIT_TEST_CASE(AllocGeneric_Overflow) { 100 UNIT_TEST_CASE(AllocGeneric_Overflow) {
101 #if defined(DEBUG) 101 #if defined(DEBUG)
102 FLAG_trace_zone_sizes = true; 102 FLAG_trace_zone_sizes = true;
103 #endif 103 #endif
104 Isolate* isolate = Isolate::Init(NULL); 104 Isolate* isolate = Isolate::Init(NULL);
105 EXPECT(Isolate::Current() == isolate); 105 EXPECT(Isolate::Current() == isolate);
106 EXPECT(isolate->current_zone() == NULL); 106 EXPECT(isolate->current_zone() == NULL);
107 { 107 {
108 Zone zone(isolate); 108 StackZone zone(isolate);
109 EXPECT(isolate->current_zone() != NULL); 109 EXPECT(isolate->current_zone() != NULL);
110 110
111 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; 111 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1;
112 zone.Alloc<uint32_t>(kNumElements); 112 zone.Alloc<uint32_t>(kNumElements);
113 } 113 }
114 isolate->Shutdown(); 114 isolate->Shutdown();
115 delete isolate; 115 delete isolate;
116 } 116 }
117 117
118 118
(...skipping 11 matching lines...) Expand all
130 SimpleZoneObject() : slot(marker++) { } 130 SimpleZoneObject() : slot(marker++) { }
131 virtual int GetSlot() { return slot; } 131 virtual int GetSlot() { return slot; }
132 int slot; 132 int slot;
133 }; 133 };
134 134
135 // Reset the marker. 135 // Reset the marker.
136 marker = 0; 136 marker = 0;
137 137
138 // Create a few zone allocated objects. 138 // Create a few zone allocated objects.
139 { 139 {
140 Zone zone(isolate); 140 StackZone zone(isolate);
141 EXPECT_EQ(0, zone.SizeInBytes()); 141 EXPECT_EQ(0, zone.SizeInBytes());
142 SimpleZoneObject* first = new SimpleZoneObject(); 142 SimpleZoneObject* first = new SimpleZoneObject();
143 EXPECT(first != NULL); 143 EXPECT(first != NULL);
144 SimpleZoneObject* second = new SimpleZoneObject(); 144 SimpleZoneObject* second = new SimpleZoneObject();
145 EXPECT(second != NULL); 145 EXPECT(second != NULL);
146 EXPECT(first != second); 146 EXPECT(first != second);
147 intptr_t expected_size = (2 * sizeof(SimpleZoneObject)); 147 intptr_t expected_size = (2 * sizeof(SimpleZoneObject));
148 EXPECT_LE(expected_size, zone.SizeInBytes()); 148 EXPECT_LE(expected_size, zone.SizeInBytes());
149 149
150 // Make sure the constructors were invoked. 150 // Make sure the constructors were invoked.
151 EXPECT_EQ(0, first->slot); 151 EXPECT_EQ(0, first->slot);
152 EXPECT_EQ(1, second->slot); 152 EXPECT_EQ(1, second->slot);
153 153
154 // Make sure we can write to the members of the zone objects. 154 // Make sure we can write to the members of the zone objects.
155 first->slot = 42; 155 first->slot = 42;
156 second->slot = 87; 156 second->slot = 87;
157 EXPECT_EQ(42, first->slot); 157 EXPECT_EQ(42, first->slot);
158 EXPECT_EQ(87, second->slot); 158 EXPECT_EQ(87, second->slot);
159 } 159 }
160 EXPECT(isolate->current_zone() == NULL); 160 EXPECT(isolate->current_zone() == NULL);
161 isolate->Shutdown(); 161 isolate->Shutdown();
162 delete isolate; 162 delete isolate;
163 } 163 }
164 164
165 165
166 TEST_CASE(PrintToString) { 166 TEST_CASE(PrintToString) {
167 Zone zone(Isolate::Current()); 167 StackZone zone(Isolate::Current());
168 const char* result = zone.PrintToString("Hello %s!", "World"); 168 const char* result = zone.PrintToString("Hello %s!", "World");
169 EXPECT_STREQ("Hello World!", result); 169 EXPECT_STREQ("Hello World!", result);
170 } 170 }
171 171
172 } // namespace dart 172 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/zone.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698