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

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

Issue 2949803002: New growth strategy for growable arrays (Closed)
Patch Set: Branch-free grow size computation. Renamed function names to be clearer. Created 3 years, 6 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
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/pages.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/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 value = Smi::New(i * 10); 2141 value = Smi::New(i * 10);
2142 array.SetAt(i, value); 2142 array.SetAt(i, value);
2143 } 2143 }
2144 EXPECT_EQ(10, array.Length()); 2144 EXPECT_EQ(10, array.Length());
2145 for (intptr_t i = 0; i < 10; i++) { 2145 for (intptr_t i = 0; i < 10; i++) {
2146 expected_value = Smi::New(i * 10); 2146 expected_value = Smi::New(i * 10);
2147 value ^= array.At(i); 2147 value ^= array.At(i);
2148 EXPECT(value.Equals(expected_value)); 2148 EXPECT(value.Equals(expected_value));
2149 } 2149 }
2150 2150
2151 // Test the MakeArray functionality to make sure the resulting array 2151 // Test the MakeFixedLength functionality to make sure the resulting array
2152 // object is properly setup. 2152 // object is properly setup.
2153 // 1. Should produce an array of length 2 and a left over int8 array. 2153 // 1. Should produce an array of length 2 and a left over int8 array.
2154 Array& new_array = Array::Handle(); 2154 Array& new_array = Array::Handle();
2155 TypedData& left_over_array = TypedData::Handle(); 2155 TypedData& left_over_array = TypedData::Handle();
2156 Object& obj = Object::Handle(); 2156 Object& obj = Object::Handle();
2157 uword addr = 0; 2157 uword addr = 0;
2158 intptr_t used_size = 0; 2158 intptr_t used_size = 0;
2159 2159
2160 array = GrowableObjectArray::New(kArrayLen + 1); 2160 array = GrowableObjectArray::New(kArrayLen + 1);
2161 EXPECT_EQ(kArrayLen + 1, array.Capacity()); 2161 EXPECT_EQ(kArrayLen + 1, array.Capacity());
2162 EXPECT_EQ(0, array.Length()); 2162 EXPECT_EQ(0, array.Length());
2163 for (intptr_t i = 0; i < 2; i++) { 2163 for (intptr_t i = 0; i < 2; i++) {
2164 value = Smi::New(i); 2164 value = Smi::New(i);
2165 array.Add(value); 2165 array.Add(value);
2166 } 2166 }
2167 used_size = Array::InstanceSize(array.Length()); 2167 used_size = Array::InstanceSize(array.Length());
2168 new_array = Array::MakeArray(array); 2168 new_array = Array::MakeFixedLength(array);
2169 addr = RawObject::ToAddr(new_array.raw()); 2169 addr = RawObject::ToAddr(new_array.raw());
2170 obj = RawObject::FromAddr(addr); 2170 obj = RawObject::FromAddr(addr);
2171 EXPECT(obj.IsArray()); 2171 EXPECT(obj.IsArray());
2172 new_array ^= obj.raw(); 2172 new_array ^= obj.raw();
2173 EXPECT_EQ(2, new_array.Length()); 2173 EXPECT_EQ(2, new_array.Length());
2174 addr += used_size; 2174 addr += used_size;
2175 obj = RawObject::FromAddr(addr); 2175 obj = RawObject::FromAddr(addr);
2176 EXPECT(obj.IsTypedData()); 2176 EXPECT(obj.IsTypedData());
2177 left_over_array ^= obj.raw(); 2177 left_over_array ^= obj.raw();
2178 EXPECT_EQ((2 * kWordSize), left_over_array.Length()); 2178 EXPECT_EQ((2 * kWordSize), left_over_array.Length());
2179 2179
2180 // 2. Should produce an array of length 3 and a left over int8 array. 2180 // 2. Should produce an array of length 3 and a left over int8 array.
2181 array = GrowableObjectArray::New(kArrayLen); 2181 array = GrowableObjectArray::New(kArrayLen);
2182 EXPECT_EQ(kArrayLen, array.Capacity()); 2182 EXPECT_EQ(kArrayLen, array.Capacity());
2183 EXPECT_EQ(0, array.Length()); 2183 EXPECT_EQ(0, array.Length());
2184 for (intptr_t i = 0; i < 3; i++) { 2184 for (intptr_t i = 0; i < 3; i++) {
2185 value = Smi::New(i); 2185 value = Smi::New(i);
2186 array.Add(value); 2186 array.Add(value);
2187 } 2187 }
2188 used_size = Array::InstanceSize(array.Length()); 2188 used_size = Array::InstanceSize(array.Length());
2189 new_array = Array::MakeArray(array); 2189 new_array = Array::MakeFixedLength(array);
2190 addr = RawObject::ToAddr(new_array.raw()); 2190 addr = RawObject::ToAddr(new_array.raw());
2191 obj = RawObject::FromAddr(addr); 2191 obj = RawObject::FromAddr(addr);
2192 EXPECT(obj.IsArray()); 2192 EXPECT(obj.IsArray());
2193 new_array ^= obj.raw(); 2193 new_array ^= obj.raw();
2194 EXPECT_EQ(3, new_array.Length()); 2194 EXPECT_EQ(3, new_array.Length());
2195 addr += used_size; 2195 addr += used_size;
2196 obj = RawObject::FromAddr(addr); 2196 obj = RawObject::FromAddr(addr);
2197 EXPECT(obj.IsTypedData()); 2197 EXPECT(obj.IsTypedData());
2198 left_over_array ^= obj.raw(); 2198 left_over_array ^= obj.raw();
2199 EXPECT_EQ(0, left_over_array.Length()); 2199 EXPECT_EQ(0, left_over_array.Length());
2200 2200
2201 // 3. Should produce an array of length 1 and a left over int8 array. 2201 // 3. Should produce an array of length 1 and a left over int8 array.
2202 array = GrowableObjectArray::New(kArrayLen + 3); 2202 array = GrowableObjectArray::New(kArrayLen + 3);
2203 EXPECT_EQ((kArrayLen + 3), array.Capacity()); 2203 EXPECT_EQ((kArrayLen + 3), array.Capacity());
2204 EXPECT_EQ(0, array.Length()); 2204 EXPECT_EQ(0, array.Length());
2205 for (intptr_t i = 0; i < 1; i++) { 2205 for (intptr_t i = 0; i < 1; i++) {
2206 value = Smi::New(i); 2206 value = Smi::New(i);
2207 array.Add(value); 2207 array.Add(value);
2208 } 2208 }
2209 used_size = Array::InstanceSize(array.Length()); 2209 used_size = Array::InstanceSize(array.Length());
2210 new_array = Array::MakeArray(array); 2210 new_array = Array::MakeFixedLength(array);
2211 addr = RawObject::ToAddr(new_array.raw()); 2211 addr = RawObject::ToAddr(new_array.raw());
2212 obj = RawObject::FromAddr(addr); 2212 obj = RawObject::FromAddr(addr);
2213 EXPECT(obj.IsArray()); 2213 EXPECT(obj.IsArray());
2214 new_array ^= obj.raw(); 2214 new_array ^= obj.raw();
2215 EXPECT_EQ(1, new_array.Length()); 2215 EXPECT_EQ(1, new_array.Length());
2216 addr += used_size; 2216 addr += used_size;
2217 obj = RawObject::FromAddr(addr); 2217 obj = RawObject::FromAddr(addr);
2218 EXPECT(obj.IsTypedData()); 2218 EXPECT(obj.IsTypedData());
2219 left_over_array ^= obj.raw(); 2219 left_over_array ^= obj.raw();
2220 EXPECT_EQ((6 * kWordSize), left_over_array.Length()); 2220 EXPECT_EQ((6 * kWordSize), left_over_array.Length());
2221 2221
2222 // 4. Verify that GC can handle the filler object for a large array. 2222 // 4. Verify that GC can handle the filler object for a large array.
2223 array = GrowableObjectArray::New((1 * MB) >> kWordSizeLog2); 2223 array = GrowableObjectArray::New((1 * MB) >> kWordSizeLog2);
2224 EXPECT_EQ(0, array.Length()); 2224 EXPECT_EQ(0, array.Length());
2225 for (intptr_t i = 0; i < 1; i++) { 2225 for (intptr_t i = 0; i < 1; i++) {
2226 value = Smi::New(i); 2226 value = Smi::New(i);
2227 array.Add(value); 2227 array.Add(value);
2228 } 2228 }
2229 Heap* heap = Isolate::Current()->heap(); 2229 Heap* heap = Isolate::Current()->heap();
2230 heap->CollectAllGarbage(); 2230 heap->CollectAllGarbage();
2231 intptr_t capacity_before = heap->CapacityInWords(Heap::kOld); 2231 intptr_t capacity_before = heap->CapacityInWords(Heap::kOld);
2232 new_array = Array::MakeArray(array); 2232 new_array = Array::MakeFixedLength(array);
2233 EXPECT_EQ(1, new_array.Length()); 2233 EXPECT_EQ(1, new_array.Length());
2234 heap->CollectAllGarbage(); 2234 heap->CollectAllGarbage();
2235 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld); 2235 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld);
2236 // Page should shrink. 2236 // Page should shrink.
2237 EXPECT_LT(capacity_after, capacity_before); 2237 EXPECT_LT(capacity_after, capacity_before);
2238 EXPECT_EQ(1, new_array.Length()); 2238 EXPECT_EQ(1, new_array.Length());
2239 } 2239 }
2240 2240
2241 2241
2242 ISOLATE_UNIT_TEST_CASE(InternalTypedData) { 2242 ISOLATE_UNIT_TEST_CASE(InternalTypedData) {
(...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after
4722 // utf32->utf16 conversion. 4722 // utf32->utf16 conversion.
4723 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, 4723 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff,
4724 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; 4724 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff};
4725 4725
4726 const String& str = 4726 const String& str =
4727 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); 4727 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes)));
4728 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); 4728 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes)));
4729 } 4729 }
4730 4730
4731 } // namespace dart 4731 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698