| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 TEST(MarkCompactCollector) { | 149 TEST(MarkCompactCollector) { |
| 150 FLAG_incremental_marking = false; | 150 FLAG_incremental_marking = false; |
| 151 CcTest::InitializeVM(); | 151 CcTest::InitializeVM(); |
| 152 Isolate* isolate = Isolate::Current(); | 152 Isolate* isolate = Isolate::Current(); |
| 153 Heap* heap = isolate->heap(); | 153 Heap* heap = isolate->heap(); |
| 154 | 154 |
| 155 v8::HandleScope sc(CcTest::isolate()); | 155 v8::HandleScope sc(CcTest::isolate()); |
| 156 Handle<GlobalObject> global(isolate->context()->global_object()); | |
| 157 | 156 |
| 158 // call mark-compact when heap is empty | 157 // call mark-compact when heap is empty |
| 159 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); | 158 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); |
| 160 | 159 |
| 161 // keep allocating garbage in new space until it fails | 160 // keep allocating garbage in new space until it fails |
| 162 const int ARRAY_SIZE = 100; | 161 const int ARRAY_SIZE = 100; |
| 163 Object* array; | 162 Object* array; |
| 164 MaybeObject* maybe_array; | 163 MaybeObject* maybe_array; |
| 165 do { | 164 do { |
| 166 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); | 165 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 185 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( | 184 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( |
| 186 heap->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); | 185 heap->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); |
| 187 JSFunction* function = JSFunction::cast( | 186 JSFunction* function = JSFunction::cast( |
| 188 heap->AllocateFunction(*isolate->function_map(), | 187 heap->AllocateFunction(*isolate->function_map(), |
| 189 function_share, | 188 function_share, |
| 190 heap->undefined_value())->ToObjectChecked()); | 189 heap->undefined_value())->ToObjectChecked()); |
| 191 Map* initial_map = | 190 Map* initial_map = |
| 192 Map::cast(heap->AllocateMap(JS_OBJECT_TYPE, | 191 Map::cast(heap->AllocateMap(JS_OBJECT_TYPE, |
| 193 JSObject::kHeaderSize)->ToObjectChecked()); | 192 JSObject::kHeaderSize)->ToObjectChecked()); |
| 194 function->set_initial_map(initial_map); | 193 function->set_initial_map(initial_map); |
| 195 JSReceiver::SetProperty( | 194 isolate->context()->global_object()->SetProperty( |
| 196 global, handle(func_name), handle(function), NONE, kNonStrictMode); | 195 func_name, function, NONE, kNonStrictMode)->ToObjectChecked(); |
| 197 | 196 |
| 198 JSObject* obj = JSObject::cast( | 197 JSObject* obj = JSObject::cast( |
| 199 heap->AllocateJSObject(function)->ToObjectChecked()); | 198 heap->AllocateJSObject(function)->ToObjectChecked()); |
| 200 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); | 199 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); |
| 201 | 200 |
| 202 func_name = String::cast( | 201 func_name = String::cast( |
| 203 heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); | 202 heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); |
| 204 CHECK(JSReceiver::HasLocalProperty(global, handle(func_name))); | 203 CHECK(isolate->context()->global_object()->HasLocalProperty(func_name)); |
| 205 Object* func_value = isolate->context()->global_object()-> | 204 Object* func_value = isolate->context()->global_object()-> |
| 206 GetProperty(func_name)->ToObjectChecked(); | 205 GetProperty(func_name)->ToObjectChecked(); |
| 207 CHECK(func_value->IsJSFunction()); | 206 CHECK(func_value->IsJSFunction()); |
| 208 function = JSFunction::cast(func_value); | 207 function = JSFunction::cast(func_value); |
| 209 | 208 |
| 210 obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked()); | 209 obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked()); |
| 211 String* obj_name = | 210 String* obj_name = |
| 212 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); | 211 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); |
| 213 JSReceiver::SetProperty( | 212 isolate->context()->global_object()->SetProperty( |
| 214 global, handle(obj_name), handle(obj), NONE, kNonStrictMode); | 213 obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked(); |
| 215 String* prop_name = | 214 String* prop_name = |
| 216 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); | 215 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
| 217 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 216 obj->SetProperty(prop_name, |
| 218 JSReceiver::SetProperty( | 217 Smi::FromInt(23), |
| 219 handle(obj), handle(prop_name), twenty_three, NONE, kNonStrictMode); | 218 NONE, |
| 219 kNonStrictMode)->ToObjectChecked(); |
| 220 | 220 |
| 221 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); | 221 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); |
| 222 | 222 |
| 223 obj_name = | 223 obj_name = |
| 224 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); | 224 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); |
| 225 CHECK(JSReceiver::HasLocalProperty(global, handle(obj_name))); | 225 CHECK(isolate->context()->global_object()->HasLocalProperty(obj_name)); |
| 226 CHECK(isolate->context()->global_object()-> | 226 CHECK(isolate->context()->global_object()-> |
| 227 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); | 227 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
| 228 obj = JSObject::cast(isolate->context()->global_object()-> | 228 obj = JSObject::cast(isolate->context()->global_object()-> |
| 229 GetProperty(obj_name)->ToObjectChecked()); | 229 GetProperty(obj_name)->ToObjectChecked()); |
| 230 prop_name = | 230 prop_name = |
| 231 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); | 231 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
| 232 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); | 232 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); |
| 233 } | 233 } |
| 234 | 234 |
| 235 | 235 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 260 // Now, as we don't have any handles to just allocated maps, we should | 260 // Now, as we don't have any handles to just allocated maps, we should |
| 261 // be able to trigger map compaction. | 261 // be able to trigger map compaction. |
| 262 // To give an additional chance to fail, try to force compaction which | 262 // To give an additional chance to fail, try to force compaction which |
| 263 // should be impossible right now. | 263 // should be impossible right now. |
| 264 HEAP->CollectAllGarbage(Heap::kForceCompactionMask); | 264 HEAP->CollectAllGarbage(Heap::kForceCompactionMask); |
| 265 // And now map pointers should be encodable again. | 265 // And now map pointers should be encodable again. |
| 266 CHECK(HEAP->map_space()->MapPointersEncodable()); | 266 CHECK(HEAP->map_space()->MapPointersEncodable()); |
| 267 } | 267 } |
| 268 #endif | 268 #endif |
| 269 | 269 |
| 270 static int gc_starts = 0; |
| 271 static int gc_ends = 0; |
| 272 |
| 273 static void GCPrologueCallbackFunc() { |
| 274 CHECK(gc_starts == gc_ends); |
| 275 gc_starts++; |
| 276 } |
| 277 |
| 278 |
| 279 static void GCEpilogueCallbackFunc() { |
| 280 CHECK(gc_starts == gc_ends + 1); |
| 281 gc_ends++; |
| 282 } |
| 283 |
| 284 |
| 285 TEST(GCCallback) { |
| 286 i::FLAG_stress_compaction = false; |
| 287 CcTest::InitializeVM(); |
| 288 |
| 289 HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); |
| 290 HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); |
| 291 |
| 292 // Scavenge does not call GC callback functions. |
| 293 HEAP->PerformScavenge(); |
| 294 |
| 295 CHECK_EQ(0, gc_starts); |
| 296 CHECK_EQ(gc_ends, gc_starts); |
| 297 |
| 298 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 299 CHECK_EQ(1, gc_starts); |
| 300 CHECK_EQ(gc_ends, gc_starts); |
| 301 } |
| 302 |
| 270 | 303 |
| 271 static int NumberOfWeakCalls = 0; | 304 static int NumberOfWeakCalls = 0; |
| 272 static void WeakPointerCallback(v8::Isolate* isolate, | 305 static void WeakPointerCallback(v8::Isolate* isolate, |
| 273 v8::Persistent<v8::Value>* handle, | 306 v8::Persistent<v8::Value>* handle, |
| 274 void* id) { | 307 void* id) { |
| 275 ASSERT(id == reinterpret_cast<void*>(1234)); | 308 ASSERT(id == reinterpret_cast<void*>(1234)); |
| 276 NumberOfWeakCalls++; | 309 NumberOfWeakCalls++; |
| 277 handle->Dispose(); | 310 handle->Dispose(); |
| 278 } | 311 } |
| 279 | 312 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 582 |
| 550 | 583 |
| 551 TEST(RegressJoinThreadsOnIsolateDeinit) { | 584 TEST(RegressJoinThreadsOnIsolateDeinit) { |
| 552 intptr_t size_limit = ShortLivingIsolate() * 2; | 585 intptr_t size_limit = ShortLivingIsolate() * 2; |
| 553 for (int i = 0; i < 10; i++) { | 586 for (int i = 0; i < 10; i++) { |
| 554 CHECK_GT(size_limit, ShortLivingIsolate()); | 587 CHECK_GT(size_limit, ShortLivingIsolate()); |
| 555 } | 588 } |
| 556 } | 589 } |
| 557 | 590 |
| 558 #endif // __linux__ and !USE_SIMULATOR | 591 #endif // __linux__ and !USE_SIMULATOR |
| OLD | NEW |