| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 5180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5191 | 5191 |
| 5192 TEST(WritableVsImmortalRoots) { | 5192 TEST(WritableVsImmortalRoots) { |
| 5193 for (int i = 0; i < Heap::kStrongRootListLength; ++i) { | 5193 for (int i = 0; i < Heap::kStrongRootListLength; ++i) { |
| 5194 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); | 5194 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); |
| 5195 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index); | 5195 bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index); |
| 5196 bool immortal = Heap::RootIsImmortalImmovable(root_index); | 5196 bool immortal = Heap::RootIsImmortalImmovable(root_index); |
| 5197 // A root value can be writable, immortal, or neither, but not both. | 5197 // A root value can be writable, immortal, or neither, but not both. |
| 5198 CHECK(!immortal || !writable); | 5198 CHECK(!immortal || !writable); |
| 5199 } | 5199 } |
| 5200 } | 5200 } |
| 5201 |
| 5202 |
| 5203 static void TestRightTrimFixedTypedArray(v8::ExternalArrayType type, |
| 5204 int initial_length, |
| 5205 int elements_to_trim) { |
| 5206 v8::HandleScope scope(CcTest::isolate()); |
| 5207 Isolate* isolate = CcTest::i_isolate(); |
| 5208 Factory* factory = isolate->factory(); |
| 5209 Heap* heap = isolate->heap(); |
| 5210 |
| 5211 Handle<FixedTypedArrayBase> array = |
| 5212 factory->NewFixedTypedArray(initial_length, type); |
| 5213 int old_size = array->size(); |
| 5214 heap->RightTrimFixedArray<Heap::FROM_MUTATOR>(*array, elements_to_trim); |
| 5215 |
| 5216 // Check that free space filler is at the right place and did not smash the |
| 5217 // array header. |
| 5218 CHECK(array->IsFixedArrayBase()); |
| 5219 CHECK_EQ(initial_length - elements_to_trim, array->length()); |
| 5220 int new_size = array->size(); |
| 5221 if (new_size != old_size) { |
| 5222 // Free space filler should be created in this case. |
| 5223 Address next_obj_address = array->address() + array->size(); |
| 5224 CHECK(HeapObject::FromAddress(next_obj_address)->IsFiller()); |
| 5225 } |
| 5226 heap->CollectAllAvailableGarbage(); |
| 5227 } |
| 5228 |
| 5229 |
| 5230 TEST(Regress472513) { |
| 5231 CcTest::InitializeVM(); |
| 5232 v8::HandleScope scope(CcTest::isolate()); |
| 5233 |
| 5234 // The combination of type/initial_length/elements_to_trim triggered |
| 5235 // typed array header smashing with free space filler (crbug/472513). |
| 5236 |
| 5237 // 64-bit cases. |
| 5238 TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 32, 6); |
| 5239 TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 32 - 7, 6); |
| 5240 TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 16, 6); |
| 5241 TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 16 - 3, 6); |
| 5242 TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 8, 6); |
| 5243 TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 8 - 1, 6); |
| 5244 |
| 5245 // 32-bit cases. |
| 5246 TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 16, 3); |
| 5247 TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 16 - 3, 3); |
| 5248 TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 8, 3); |
| 5249 TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 8 - 1, 3); |
| 5250 TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 4, 3); |
| 5251 } |
| OLD | NEW |