OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include <stdlib.h> |
| 29 #include <utility> |
| 30 |
| 31 #include "src/v8.h" |
| 32 |
| 33 #include "src/compilation-cache.h" |
| 34 #include "src/execution.h" |
| 35 #include "src/factory.h" |
| 36 #include "src/global-handles.h" |
| 37 #include "src/ic/ic.h" |
| 38 #include "src/macro-assembler.h" |
| 39 #include "test/cctest/cctest.h" |
| 40 |
| 41 using namespace v8::internal; |
| 42 |
| 43 #if (V8_DOUBLE_FIELDS_UNBOXING) |
| 44 |
| 45 TEST(TestStoreBufferScanOnScavenge) { |
| 46 CcTest::InitializeVM(); |
| 47 Isolate* isolate = CcTest::i_isolate(); |
| 48 Factory* factory = isolate->factory(); |
| 49 v8::HandleScope scope(CcTest::isolate()); |
| 50 |
| 51 CompileRun( |
| 52 "function A() {" |
| 53 " this.x = 42.5;" |
| 54 " this.o = {};" |
| 55 "};" |
| 56 "var o = new A();"); |
| 57 |
| 58 Handle<String> obj_name = factory->InternalizeUtf8String("o"); |
| 59 |
| 60 Handle<Object> obj_value = |
| 61 Object::GetProperty(isolate->global_object(), obj_name).ToHandleChecked(); |
| 62 CHECK(obj_value->IsJSObject()); |
| 63 Handle<JSObject> obj = Handle<JSObject>::cast(obj_value); |
| 64 |
| 65 { |
| 66 // Ensure the object is properly set up. |
| 67 Map* map = obj->map(); |
| 68 DescriptorArray* descriptors = map->instance_descriptors(); |
| 69 CHECK(map->NumberOfOwnDescriptors() == 2); |
| 70 CHECK(descriptors->GetDetails(0).representation().IsDouble()); |
| 71 CHECK(descriptors->GetDetails(1).representation().IsHeapObject()); |
| 72 FieldIndex field_index = FieldIndex::ForDescriptor(map, 0); |
| 73 CHECK(field_index.is_inobject() && field_index.is_double()); |
| 74 CHECK_EQ(FLAG_unbox_double_fields, map->IsUnboxedDoubleField(field_index)); |
| 75 if (FLAG_unbox_double_fields) { |
| 76 CHECK_EQ(42.5, obj->RawFastDoublePropertyAt(field_index)); |
| 77 } |
| 78 } |
| 79 CHECK(isolate->heap()->new_space()->Contains(*obj)); |
| 80 |
| 81 // Trigger GCs so that the newly allocated object moves to old gen. |
| 82 SimulateFullSpace(CcTest::heap()->old_pointer_space()); |
| 83 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 84 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 85 |
| 86 CHECK(isolate->heap()->old_pointer_space()->Contains(*obj)); |
| 87 |
| 88 // Create temp object in the new space. |
| 89 Handle<JSArray> temp = factory->NewJSArray(FAST_ELEMENTS, NOT_TENURED); |
| 90 CHECK(isolate->heap()->new_space()->Contains(*temp)); |
| 91 |
| 92 // Construct a double value that looks like a pointer to the new space object |
| 93 // and store it into the obj. |
| 94 Address fake_object = reinterpret_cast<Address>(*temp) + kPointerSize; |
| 95 double boom_value = bit_cast<double>(fake_object); |
| 96 |
| 97 FieldIndex field_index = FieldIndex::ForDescriptor(obj->map(), 0); |
| 98 obj->FastPropertyAtPut(field_index, |
| 99 *factory->NewHeapNumber(boom_value, MUTABLE)); |
| 100 |
| 101 // Enforce scan on scavenge for the obj's page. |
| 102 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
| 103 chunk->set_scan_on_scavenge(true); |
| 104 |
| 105 // Trigger GCs and force evacuation. Should not crash there. |
| 106 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 107 } |
| 108 |
| 109 #endif |
OLD | NEW |