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

Side by Side Diff: test/cctest/test-unboxed-doubles.cc

Issue 880043003: Avoid issuing write barriers for unboxed double fields in Heap::CopyJSObject(). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 10 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 | « src/heap/heap.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/compilation-cache.h" 10 #include "src/compilation-cache.h"
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 // Enforce scan on scavenge for the obj's page. 1216 // Enforce scan on scavenge for the obj's page.
1217 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); 1217 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address());
1218 chunk->set_scan_on_scavenge(true); 1218 chunk->set_scan_on_scavenge(true);
1219 1219
1220 // Trigger GCs and force evacuation. Should not crash there. 1220 // Trigger GCs and force evacuation. Should not crash there.
1221 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 1221 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
1222 1222
1223 CHECK_EQ(boom_value, GetDoubleFieldValue(*obj, field_index)); 1223 CHECK_EQ(boom_value, GetDoubleFieldValue(*obj, field_index));
1224 } 1224 }
1225 1225
1226
1227 static int LenFromSize(int size) {
1228 return (size - FixedArray::kHeaderSize) / kPointerSize;
1229 }
1230
1231
1232 TEST(WriteBarriersInCopyJSObject) {
1233 FLAG_max_semi_space_size = 1; // Ensure new space is not growing.
1234 CcTest::InitializeVM();
1235 Isolate* isolate = CcTest::i_isolate();
1236 TestHeap* heap = CcTest::test_heap();
1237
1238 v8::HandleScope scope(CcTest::isolate());
1239
1240 // The plan: create JSObject which contains unboxed double value that looks
1241 // like a reference to an object in new space.
1242 // Then clone this object (forcing it to go into old space) and check
1243 // that the value of the unboxed double property of the cloned object has
1244 // was not corrupted by GC.
1245
1246 // Step 1: prepare a map for the object. We add unboxed double property to it.
1247 // Create a map with single inobject property.
1248 Handle<Map> my_map = Map::Create(isolate, 1);
1249 Handle<String> name = isolate->factory()->InternalizeUtf8String("foo");
1250 my_map = Map::CopyWithField(my_map, name, HeapType::Any(isolate), NONE,
1251 Representation::Double(),
1252 INSERT_TRANSITION).ToHandleChecked();
1253 my_map->set_pre_allocated_property_fields(1);
1254 int n_properties = my_map->InitialPropertiesLength();
1255 CHECK_GE(n_properties, 0);
1256
1257 int object_size = my_map->instance_size();
1258
1259 // Step 2: allocate a lot of objects so to almost fill new space: we need
1260 // just enough room to allocate JSObject and thus fill the newspace.
1261
1262 int allocation_amount =
1263 Min(FixedArray::kMaxSize, Page::kMaxRegularHeapObjectSize + kPointerSize);
1264 int allocation_len = LenFromSize(allocation_amount);
1265 NewSpace* new_space = heap->new_space();
1266 Address* top_addr = new_space->allocation_top_address();
1267 Address* limit_addr = new_space->allocation_limit_address();
1268 while ((*limit_addr - *top_addr) > allocation_amount) {
1269 CHECK(!heap->always_allocate());
1270 Object* array = heap->AllocateFixedArray(allocation_len).ToObjectChecked();
1271 CHECK(new_space->Contains(array));
1272 }
1273
1274 // Step 3: now allocate fixed array and JSObject to fill the whole new space.
1275 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size);
1276 int fixed_array_len = LenFromSize(to_fill);
1277 CHECK(fixed_array_len < FixedArray::kMaxLength);
1278
1279 CHECK(!heap->always_allocate());
1280 Object* array = heap->AllocateFixedArray(fixed_array_len).ToObjectChecked();
1281 CHECK(new_space->Contains(array));
1282
1283 Object* object = heap->AllocateJSObjectFromMap(*my_map).ToObjectChecked();
1284 CHECK(new_space->Contains(object));
1285 JSObject* jsobject = JSObject::cast(object);
1286 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
1287 CHECK_EQ(0, jsobject->properties()->length());
1288
1289 // Construct a double value that looks like a pointer to the new space object
1290 // and store it into the obj.
1291 Address fake_object = reinterpret_cast<Address>(array) + kPointerSize;
1292 double boom_value = bit_cast<double>(fake_object);
1293 FieldIndex index = FieldIndex::ForDescriptor(*my_map, 0);
1294 jsobject->RawFastDoublePropertyAtPut(index, boom_value);
1295
1296 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr));
1297
1298 // Step 4: clone jsobject, but force always allocate first to create a clone
1299 // in old pointer space.
1300 AlwaysAllocateScope aa_scope(isolate);
1301 Object* clone_obj = heap->CopyJSObject(jsobject).ToObjectChecked();
1302 Handle<JSObject> clone(JSObject::cast(clone_obj));
1303 CHECK(heap->old_pointer_space()->Contains(clone->address()));
1304
1305 CcTest::heap()->CollectGarbage(NEW_SPACE, "boom");
1306
1307 // The value in cloned object should not be corrupted by GC.
1308 CHECK_EQ(boom_value, clone->RawFastDoublePropertyAt(index));
1309 }
1310
1226 #endif 1311 #endif
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698