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