Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 CcTest::InitializeVM(); | |
| 1234 Isolate* isolate = CcTest::i_isolate(); | |
| 1235 TestHeap* heap = CcTest::test_heap(); | |
| 1236 | |
| 1237 // Increase the chance of 'bump-the-pointer' allocation in old space. | |
|
Hannes Payer (out of office)
2015/02/02 21:00:54
I do not get this line. Why does that increase the
Igor Sheludko
2015/02/03 09:14:21
Sorry, that was a copy/paste. Done.
| |
| 1238 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 1239 | |
| 1240 v8::HandleScope scope(CcTest::isolate()); | |
| 1241 | |
| 1242 // The plan: create JSObject which contains unboxed double value that looks | |
| 1243 // like a reference to an object in new space. | |
| 1244 // Then clone this object (forcing it to go into old space) and check | |
| 1245 // that the value of the unboxed double property of the cloned object has | |
| 1246 // was not corrupted by GC. | |
| 1247 | |
| 1248 // Step 1: prepare a map for the object. We add unboxed double property to it. | |
| 1249 // Create a map with single inobject property. | |
| 1250 Handle<Map> my_map = Map::Create(isolate, 1); | |
| 1251 Handle<String> name = isolate->factory()->InternalizeUtf8String("foo"); | |
| 1252 my_map = Map::CopyWithField(my_map, name, HeapType::Any(isolate), NONE, | |
| 1253 Representation::Double(), | |
| 1254 INSERT_TRANSITION).ToHandleChecked(); | |
| 1255 my_map->set_pre_allocated_property_fields(1); | |
| 1256 int n_properties = my_map->InitialPropertiesLength(); | |
| 1257 CHECK_GE(n_properties, 0); | |
| 1258 | |
| 1259 int object_size = my_map->instance_size(); | |
| 1260 | |
| 1261 // Step 2: allocate a lot of objects so to almost fill new space: we need | |
| 1262 // just enough room to allocate JSObject and thus fill the newspace. | |
| 1263 | |
| 1264 int allocation_amount = | |
| 1265 Min(FixedArray::kMaxSize, Page::kMaxRegularHeapObjectSize + kPointerSize); | |
| 1266 int allocation_len = LenFromSize(allocation_amount); | |
| 1267 NewSpace* new_space = heap->new_space(); | |
| 1268 Address* top_addr = new_space->allocation_top_address(); | |
| 1269 Address* limit_addr = new_space->allocation_limit_address(); | |
| 1270 while ((*limit_addr - *top_addr) > allocation_amount) { | |
|
Hannes Payer (out of office)
2015/02/02 21:00:54
Just create a filler here, that's easier. Moreover
Igor Sheludko
2015/02/03 09:14:21
Thanks for the max_semi_space_size suggestion!
Un
| |
| 1271 CHECK(!heap->always_allocate()); | |
| 1272 Object* array = heap->AllocateFixedArray(allocation_len).ToObjectChecked(); | |
| 1273 CHECK(new_space->Contains(array)); | |
| 1274 } | |
| 1275 | |
| 1276 // Step 3: now allocate fixed array and JSObject to fill the whole new space. | |
| 1277 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); | |
| 1278 int fixed_array_len = LenFromSize(to_fill); | |
| 1279 CHECK(fixed_array_len < FixedArray::kMaxLength); | |
| 1280 | |
| 1281 CHECK(!heap->always_allocate()); | |
| 1282 Object* array = heap->AllocateFixedArray(fixed_array_len).ToObjectChecked(); | |
| 1283 CHECK(new_space->Contains(array)); | |
| 1284 | |
| 1285 Object* object = heap->AllocateJSObjectFromMap(*my_map).ToObjectChecked(); | |
| 1286 CHECK(new_space->Contains(object)); | |
| 1287 JSObject* jsobject = JSObject::cast(object); | |
| 1288 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); | |
| 1289 CHECK_EQ(0, jsobject->properties()->length()); | |
| 1290 | |
| 1291 // Construct a double value that looks like a pointer to the new space object | |
| 1292 // and store it into the obj. | |
| 1293 Address fake_object = reinterpret_cast<Address>(array) + kPointerSize; | |
| 1294 double boom_value = bit_cast<double>(fake_object); | |
| 1295 FieldIndex index = FieldIndex::ForDescriptor(*my_map, 0); | |
| 1296 jsobject->RawFastDoublePropertyAtPut(index, boom_value); | |
| 1297 | |
| 1298 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); | |
| 1299 | |
| 1300 // Step 4: clone jsobject, but force always allocate first to create a clone | |
| 1301 // in old pointer space. | |
| 1302 AlwaysAllocateScope aa_scope(isolate); | |
| 1303 Object* clone_obj = heap->CopyJSObject(jsobject).ToObjectChecked(); | |
| 1304 Handle<JSObject> clone(JSObject::cast(clone_obj)); | |
| 1305 CHECK(heap->old_pointer_space()->Contains(clone->address())); | |
| 1306 | |
| 1307 CcTest::heap()->CollectGarbage(NEW_SPACE, "boom"); | |
| 1308 | |
| 1309 // The value in cloned object should not be corrupted by GC. | |
| 1310 CHECK_EQ(boom_value, clone->RawFastDoublePropertyAt(index)); | |
| 1311 } | |
| 1312 | |
| 1226 #endif | 1313 #endif |
| OLD | NEW |