jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 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 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 30 | #ifdef __linux__ |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
| 35 | #include <errno.h> |
| 36 | #endif |
| 37 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 38 | |
| 39 | // TODO(dcarney): remove |
| 40 | #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 41 | #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 42 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 43 | #include "v8.h" |
| 44 | |
| 45 | #include "global-handles.h" |
| 46 | #include "snapshot.h" |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 47 | #include "cctest.h" |
| 48 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 49 | using namespace v8::internal; |
| 50 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 51 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 52 | TEST(MarkingDeque) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 53 | CcTest::InitializeVM(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 54 | int mem_size = 20 * kPointerSize; |
| 55 | byte* mem = NewArray<byte>(20*kPointerSize); |
| 56 | Address low = reinterpret_cast<Address>(mem); |
| 57 | Address high = low + mem_size; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 58 | MarkingDeque s; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | s.Initialize(low, high); |
| 60 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 61 | Address original_address = reinterpret_cast<Address>(&s); |
| 62 | Address current_address = original_address; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 63 | while (!s.IsFull()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 64 | s.PushBlack(HeapObject::FromAddress(current_address)); |
| 65 | current_address += kPointerSize; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 66 | } |
| 67 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 68 | while (!s.IsEmpty()) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 69 | Address value = s.Pop()->address(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 70 | current_address -= kPointerSize; |
| 71 | CHECK_EQ(current_address, value); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 72 | } |
| 73 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 74 | CHECK_EQ(original_address, current_address); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 75 | DeleteArray(mem); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | TEST(Promotion) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 80 | // This test requires compaction. If compaction is turned off, we |
| 81 | // skip the entire test. |
| 82 | if (FLAG_never_compact) return; |
| 83 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 84 | // Ensure that we get a compacting collection so that objects are promoted |
| 85 | // from new space. |
| 86 | FLAG_gc_global = true; |
| 87 | FLAG_always_compact = true; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 88 | HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 89 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 90 | CcTest::InitializeVM(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 91 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 92 | v8::HandleScope sc(CcTest::isolate()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 93 | |
| 94 | // Allocate a fixed array in the new space. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 95 | int array_size = |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 96 | (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 97 | (kPointerSize * 4); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 98 | Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 99 | |
| 100 | Handle<FixedArray> array(FixedArray::cast(obj)); |
| 101 | |
| 102 | // Array should be in the new space. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 103 | CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 104 | |
| 105 | // Call the m-c collector, so array becomes an old object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 106 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 107 | |
| 108 | // Array now sits in the old space |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 109 | CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
| 113 | TEST(NoPromotion) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 114 | HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 115 | |
| 116 | // Test the situation that some objects in new space are promoted to |
| 117 | // the old space |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 118 | CcTest::InitializeVM(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 119 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 120 | v8::HandleScope sc(CcTest::isolate()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 121 | |
| 122 | // Do a mark compact GC to shrink the heap. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 123 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 124 | |
| 125 | // Allocate a big Fixed array in the new space. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 126 | int max_size = |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 127 | Min(Page::kMaxNonCodeHeapObjectSize, HEAP->MaxObjectSizeInNewSpace()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 128 | |
| 129 | int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); |
| 130 | Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> |
| 131 | ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 132 | |
| 133 | Handle<FixedArray> array(FixedArray::cast(obj)); |
| 134 | |
| 135 | // Array still stays in the new space. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 136 | CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 137 | |
| 138 | // Allocate objects in the old space until out of memory. |
| 139 | FixedArray* host = *array; |
| 140 | while (true) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 141 | Object* obj; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 142 | { MaybeObject* maybe_obj = HEAP->AllocateFixedArray(100, TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 143 | if (!maybe_obj->ToObject(&obj)) break; |
| 144 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 145 | |
| 146 | host->set(0, obj); |
| 147 | host = FixedArray::cast(obj); |
| 148 | } |
| 149 | |
| 150 | // Call mark compact GC, and it should pass. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 151 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | |
| 155 | TEST(MarkCompactCollector) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 156 | CcTest::InitializeVM(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 157 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 158 | v8::HandleScope sc(CcTest::isolate()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 159 | // call mark-compact when heap is empty |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 160 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 161 | |
| 162 | // keep allocating garbage in new space until it fails |
| 163 | const int ARRAY_SIZE = 100; |
| 164 | Object* array; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 165 | MaybeObject* maybe_array; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 166 | do { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 167 | maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 168 | } while (maybe_array->ToObject(&array)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 169 | HEAP->CollectGarbage(NEW_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 170 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 171 | array = HEAP->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 172 | |
| 173 | // keep allocating maps until it fails |
| 174 | Object* mapp; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 175 | MaybeObject* maybe_mapp; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 176 | do { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 177 | maybe_mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 178 | } while (maybe_mapp->ToObject(&mapp)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 179 | HEAP->CollectGarbage(MAP_SPACE); |
| 180 | mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 181 | JSObject::kHeaderSize)->ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 182 | |
| 183 | // allocate a garbage |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 184 | String* func_name = String::cast( |
| 185 | HEAP->InternalizeUtf8String("theFunction")->ToObjectChecked()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 186 | SharedFunctionInfo* function_share = SharedFunctionInfo::cast( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 187 | HEAP->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 188 | JSFunction* function = JSFunction::cast( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 189 | HEAP->AllocateFunction(*Isolate::Current()->function_map(), |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 190 | function_share, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 191 | HEAP->undefined_value())->ToObjectChecked()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 192 | Map* initial_map = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 193 | Map::cast(HEAP->AllocateMap(JS_OBJECT_TYPE, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 194 | JSObject::kHeaderSize)->ToObjectChecked()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 195 | function->set_initial_map(initial_map); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 196 | Isolate::Current()->context()->global_object()->SetProperty( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 197 | func_name, function, NONE, kNonStrictMode)->ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 198 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 199 | JSObject* obj = JSObject::cast( |
| 200 | HEAP->AllocateJSObject(function)->ToObjectChecked()); |
| 201 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 202 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 203 | func_name = String::cast( |
| 204 | HEAP->InternalizeUtf8String("theFunction")->ToObjectChecked()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 205 | CHECK(Isolate::Current()->context()->global_object()-> |
| 206 | HasLocalProperty(func_name)); |
| 207 | Object* func_value = Isolate::Current()->context()->global_object()-> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 208 | GetProperty(func_name)->ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 209 | CHECK(func_value->IsJSFunction()); |
| 210 | function = JSFunction::cast(func_value); |
| 211 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 212 | obj = JSObject::cast(HEAP->AllocateJSObject(function)->ToObjectChecked()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 213 | String* obj_name = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 214 | String::cast(HEAP->InternalizeUtf8String("theObject")->ToObjectChecked()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 215 | Isolate::Current()->context()->global_object()->SetProperty( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 216 | obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 217 | String* prop_name = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 218 | String::cast(HEAP->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 219 | obj->SetProperty(prop_name, |
| 220 | Smi::FromInt(23), |
| 221 | NONE, |
| 222 | kNonStrictMode)->ToObjectChecked(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 223 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 224 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 225 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 226 | obj_name = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 227 | String::cast(HEAP->InternalizeUtf8String("theObject")->ToObjectChecked()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 228 | CHECK(Isolate::Current()->context()->global_object()-> |
| 229 | HasLocalProperty(obj_name)); |
| 230 | CHECK(Isolate::Current()->context()->global_object()-> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 231 | GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 232 | obj = JSObject::cast(Isolate::Current()->context()->global_object()-> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 233 | GetProperty(obj_name)->ToObjectChecked()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 234 | prop_name = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 235 | String::cast(HEAP->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 236 | CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 240 | // TODO(1600): compaction of map space is temporary removed from GC. |
| 241 | #if 0 |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 242 | static Handle<Map> CreateMap() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 243 | return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | |
| 247 | TEST(MapCompact) { |
| 248 | FLAG_max_map_space_pages = 16; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 249 | CcTest::InitializeVM(); |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 250 | |
| 251 | { |
| 252 | v8::HandleScope sc; |
| 253 | // keep allocating maps while pointers are still encodable and thus |
| 254 | // mark compact is permitted. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 255 | Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap()); |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 256 | do { |
| 257 | Handle<Map> map = CreateMap(); |
| 258 | map->set_prototype(*root); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 259 | root = FACTORY->NewJSObjectFromMap(map); |
| 260 | } while (HEAP->map_space()->MapPointersEncodable()); |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 261 | } |
| 262 | // Now, as we don't have any handles to just allocated maps, we should |
| 263 | // be able to trigger map compaction. |
| 264 | // To give an additional chance to fail, try to force compaction which |
| 265 | // should be impossible right now. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 266 | HEAP->CollectAllGarbage(Heap::kForceCompactionMask); |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 267 | // And now map pointers should be encodable again. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 268 | CHECK(HEAP->map_space()->MapPointersEncodable()); |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 269 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 270 | #endif |
kasperl@chromium.org | eac059f | 2010-01-25 11:02:06 +0000 | [diff] [blame] | 271 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 272 | static int gc_starts = 0; |
| 273 | static int gc_ends = 0; |
| 274 | |
| 275 | static void GCPrologueCallbackFunc() { |
| 276 | CHECK(gc_starts == gc_ends); |
| 277 | gc_starts++; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static void GCEpilogueCallbackFunc() { |
| 282 | CHECK(gc_starts == gc_ends + 1); |
| 283 | gc_ends++; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | TEST(GCCallback) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 288 | CcTest::InitializeVM(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 289 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 290 | HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); |
| 291 | HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 292 | |
| 293 | // Scavenge does not call GC callback functions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 294 | HEAP->PerformScavenge(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 295 | |
| 296 | CHECK_EQ(0, gc_starts); |
| 297 | CHECK_EQ(gc_ends, gc_starts); |
| 298 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 299 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 300 | CHECK_EQ(1, gc_starts); |
| 301 | CHECK_EQ(gc_ends, gc_starts); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | static int NumberOfWeakCalls = 0; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 306 | static void WeakPointerCallback(v8::Isolate* isolate, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 307 | v8::Persistent<v8::Value>* handle, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 308 | void* id) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 309 | ASSERT(id == reinterpret_cast<void*>(1234)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 310 | NumberOfWeakCalls++; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 311 | handle->Dispose(isolate); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | TEST(ObjectGroups) { |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 315 | FLAG_incremental_marking = false; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 316 | CcTest::InitializeVM(); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 317 | GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 318 | |
| 319 | NumberOfWeakCalls = 0; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 320 | v8::HandleScope handle_scope(CcTest::isolate()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 321 | |
| 322 | Handle<Object> g1s1 = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 323 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 324 | Handle<Object> g1s2 = |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 325 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 326 | Handle<Object> g1c1 = |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 327 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 328 | global_handles->MakeWeak(g1s1.location(), |
| 329 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 330 | &WeakPointerCallback, |
| 331 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 332 | global_handles->MakeWeak(g1s2.location(), |
| 333 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 334 | &WeakPointerCallback, |
| 335 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 336 | global_handles->MakeWeak(g1c1.location(), |
| 337 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 338 | &WeakPointerCallback, |
| 339 | NULL); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 340 | |
| 341 | Handle<Object> g2s1 = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 342 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 343 | Handle<Object> g2s2 = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 344 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 345 | Handle<Object> g2c1 = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 346 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 347 | global_handles->MakeWeak(g2s1.location(), |
| 348 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 349 | &WeakPointerCallback, |
| 350 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 351 | global_handles->MakeWeak(g2s2.location(), |
| 352 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 353 | &WeakPointerCallback, |
| 354 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 355 | global_handles->MakeWeak(g2c1.location(), |
| 356 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 357 | &WeakPointerCallback, |
| 358 | NULL); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 359 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 360 | Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 361 | |
| 362 | // Connect group 1 and 2, make a cycle. |
| 363 | Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| 364 | Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| 365 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 366 | { |
| 367 | Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 368 | Object** g1_children[] = { g1c1.location() }; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 369 | Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 370 | Object** g2_children[] = { g2c1.location() }; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 371 | global_handles->AddObjectGroup(g1_objects, 2, NULL); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 372 | global_handles->AddImplicitReferences( |
| 373 | Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 374 | global_handles->AddObjectGroup(g2_objects, 2, NULL); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 375 | global_handles->AddImplicitReferences( |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 376 | Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 377 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 378 | // Do a full GC |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 379 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 380 | |
| 381 | // All object should be alive. |
| 382 | CHECK_EQ(0, NumberOfWeakCalls); |
| 383 | |
| 384 | // Weaken the root. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 385 | global_handles->MakeWeak(root.location(), |
| 386 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 387 | &WeakPointerCallback, |
| 388 | NULL); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 389 | // But make children strong roots---all the objects (except for children) |
| 390 | // should be collectable now. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 391 | global_handles->ClearWeakness(g1c1.location()); |
| 392 | global_handles->ClearWeakness(g2c1.location()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 393 | |
| 394 | // Groups are deleted, rebuild groups. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 395 | { |
| 396 | Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 397 | Object** g1_children[] = { g1c1.location() }; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 398 | Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 399 | Object** g2_children[] = { g2c1.location() }; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 400 | global_handles->AddObjectGroup(g1_objects, 2, NULL); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 401 | global_handles->AddImplicitReferences( |
| 402 | Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 403 | global_handles->AddObjectGroup(g2_objects, 2, NULL); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 404 | global_handles->AddImplicitReferences( |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 405 | Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 406 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 407 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 408 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 409 | |
| 410 | // All objects should be gone. 5 global handles in total. |
| 411 | CHECK_EQ(5, NumberOfWeakCalls); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 412 | |
| 413 | // And now make children weak again and collect them. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 414 | global_handles->MakeWeak(g1c1.location(), |
| 415 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 416 | &WeakPointerCallback, |
| 417 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 418 | global_handles->MakeWeak(g2c1.location(), |
| 419 | reinterpret_cast<void*>(1234), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 420 | &WeakPointerCallback, |
| 421 | NULL); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 422 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 423 | HEAP->CollectGarbage(OLD_POINTER_SPACE); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 424 | CHECK_EQ(7, NumberOfWeakCalls); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 425 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 426 | |
| 427 | |
| 428 | class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
| 429 | public: |
| 430 | TestRetainedObjectInfo() : has_been_disposed_(false) {} |
| 431 | |
| 432 | bool has_been_disposed() { return has_been_disposed_; } |
| 433 | |
| 434 | virtual void Dispose() { |
| 435 | ASSERT(!has_been_disposed_); |
| 436 | has_been_disposed_ = true; |
| 437 | } |
| 438 | |
| 439 | virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { |
| 440 | return other == this; |
| 441 | } |
| 442 | |
| 443 | virtual intptr_t GetHash() { return 0; } |
| 444 | |
| 445 | virtual const char* GetLabel() { return "whatever"; } |
| 446 | |
| 447 | private: |
| 448 | bool has_been_disposed_; |
| 449 | }; |
| 450 | |
| 451 | |
| 452 | TEST(EmptyObjectGroups) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 453 | CcTest::InitializeVM(); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 454 | GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
| 455 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 456 | v8::HandleScope handle_scope(CcTest::isolate()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 457 | |
| 458 | Handle<Object> object = |
| 459 | global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 460 | |
| 461 | TestRetainedObjectInfo info; |
| 462 | global_handles->AddObjectGroup(NULL, 0, &info); |
| 463 | ASSERT(info.has_been_disposed()); |
| 464 | |
| 465 | global_handles->AddImplicitReferences( |
| 466 | Handle<HeapObject>::cast(object).location(), NULL, 0); |
| 467 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 468 | |
| 469 | |
| 470 | // Here is a memory use test that uses /proc, and is therefore Linux-only. We |
| 471 | // do not care how much memory the simulator uses, since it is only there for |
| 472 | // debugging purposes. |
| 473 | #if defined(__linux__) && !defined(USE_SIMULATOR) |
| 474 | |
| 475 | |
| 476 | static uintptr_t ReadLong(char* buffer, intptr_t* position, int base) { |
| 477 | char* end_address = buffer + *position; |
| 478 | uintptr_t result = strtoul(buffer + *position, &end_address, base); |
| 479 | CHECK(result != ULONG_MAX || errno != ERANGE); |
| 480 | CHECK(end_address > buffer + *position); |
| 481 | *position = end_address - buffer; |
| 482 | return result; |
| 483 | } |
| 484 | |
| 485 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 486 | // The memory use computed this way is not entirely accurate and depends on |
| 487 | // the way malloc allocates memory. That's why the memory use may seem to |
| 488 | // increase even though the sum of the allocated object sizes decreases. It |
| 489 | // also means that the memory use depends on the kernel and stdlib. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 490 | static intptr_t MemoryInUse() { |
| 491 | intptr_t memory_use = 0; |
| 492 | |
| 493 | int fd = open("/proc/self/maps", O_RDONLY); |
| 494 | if (fd < 0) return -1; |
| 495 | |
| 496 | const int kBufSize = 10000; |
| 497 | char buffer[kBufSize]; |
| 498 | int length = read(fd, buffer, kBufSize); |
| 499 | intptr_t line_start = 0; |
| 500 | CHECK_LT(length, kBufSize); // Make the buffer bigger. |
| 501 | CHECK_GT(length, 0); // We have to find some data in the file. |
| 502 | while (line_start < length) { |
| 503 | if (buffer[line_start] == '\n') { |
| 504 | line_start++; |
| 505 | continue; |
| 506 | } |
| 507 | intptr_t position = line_start; |
| 508 | uintptr_t start = ReadLong(buffer, &position, 16); |
| 509 | CHECK_EQ(buffer[position++], '-'); |
| 510 | uintptr_t end = ReadLong(buffer, &position, 16); |
| 511 | CHECK_EQ(buffer[position++], ' '); |
| 512 | CHECK(buffer[position] == '-' || buffer[position] == 'r'); |
| 513 | bool read_permission = (buffer[position++] == 'r'); |
| 514 | CHECK(buffer[position] == '-' || buffer[position] == 'w'); |
| 515 | bool write_permission = (buffer[position++] == 'w'); |
| 516 | CHECK(buffer[position] == '-' || buffer[position] == 'x'); |
| 517 | bool execute_permission = (buffer[position++] == 'x'); |
| 518 | CHECK(buffer[position] == '-' || buffer[position] == 'p'); |
| 519 | bool private_mapping = (buffer[position++] == 'p'); |
| 520 | CHECK_EQ(buffer[position++], ' '); |
| 521 | uintptr_t offset = ReadLong(buffer, &position, 16); |
| 522 | USE(offset); |
| 523 | CHECK_EQ(buffer[position++], ' '); |
| 524 | uintptr_t major = ReadLong(buffer, &position, 16); |
| 525 | USE(major); |
| 526 | CHECK_EQ(buffer[position++], ':'); |
| 527 | uintptr_t minor = ReadLong(buffer, &position, 16); |
| 528 | USE(minor); |
| 529 | CHECK_EQ(buffer[position++], ' '); |
| 530 | uintptr_t inode = ReadLong(buffer, &position, 10); |
| 531 | while (position < length && buffer[position] != '\n') position++; |
| 532 | if ((read_permission || write_permission || execute_permission) && |
| 533 | private_mapping && inode == 0) { |
| 534 | memory_use += (end - start); |
| 535 | } |
| 536 | |
| 537 | line_start = position; |
| 538 | } |
| 539 | close(fd); |
| 540 | return memory_use; |
| 541 | } |
| 542 | |
| 543 | |
| 544 | TEST(BootUpMemoryUse) { |
| 545 | intptr_t initial_memory = MemoryInUse(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 546 | // Avoid flakiness. |
| 547 | FLAG_crankshaft = false; |
| 548 | FLAG_parallel_recompilation = false; |
| 549 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 550 | // Only Linux has the proc filesystem and only if it is mapped. If it's not |
| 551 | // there we just skip the test. |
| 552 | if (initial_memory >= 0) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 553 | CcTest::InitializeVM(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 554 | intptr_t delta = MemoryInUse() - initial_memory; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 555 | printf("delta: %" V8_PTR_PREFIX "d kB\n", delta / 1024); |
| 556 | if (sizeof(initial_memory) == 8) { // 64-bit. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 557 | if (v8::internal::Snapshot::IsEnabled()) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 558 | CHECK_LE(delta, 4000 * 1024); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 559 | } else { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 560 | CHECK_LE(delta, 4500 * 1024); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 561 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 562 | } else { // 32-bit. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 563 | if (v8::internal::Snapshot::IsEnabled()) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 564 | CHECK_LE(delta, 2900 * 1024); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 565 | } else { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 566 | CHECK_LE(delta, 3400 * 1024); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | #endif // __linux__ and !USE_SIMULATOR |