OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0])); | 1180 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0])); |
1181 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2)); | 1181 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2)); |
1182 CompileRun("f5()"); | 1182 CompileRun("f5()"); |
1183 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); | 1183 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); |
1184 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); | 1184 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); |
1185 | 1185 |
1186 ctx[0]->Exit(); | 1186 ctx[0]->Exit(); |
1187 } | 1187 } |
1188 | 1188 |
1189 | 1189 |
| 1190 TEST(TestSizeOfObjects) { |
| 1191 v8::V8::Initialize(); |
| 1192 |
| 1193 // Get initial heap size after several full GCs, which will stabilize |
| 1194 // the heap size and return with sweeping finished completely. |
| 1195 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1196 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1197 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1198 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1199 CHECK(HEAP->old_pointer_space()->IsSweepingComplete()); |
| 1200 int initial_size = static_cast<int>(HEAP->SizeOfObjects()); |
| 1201 |
| 1202 { |
| 1203 // Allocate objects on several different old-space pages so that |
| 1204 // lazy sweeping kicks in for subsequent GC runs. |
| 1205 AlwaysAllocateScope always_allocate; |
| 1206 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); |
| 1207 for (int i = 1; i <= 100; i++) { |
| 1208 HEAP->AllocateFixedArray(8192, TENURED)->ToObjectChecked(); |
| 1209 CHECK_EQ(initial_size + i * filler_size, |
| 1210 static_cast<int>(HEAP->SizeOfObjects())); |
| 1211 } |
| 1212 } |
| 1213 |
| 1214 // The heap size should go back to initial size after a full GC, even |
| 1215 // though sweeping didn't finish yet. |
| 1216 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1217 CHECK(!HEAP->old_pointer_space()->IsSweepingComplete()); |
| 1218 CHECK_EQ(initial_size, static_cast<int>(HEAP->SizeOfObjects())); |
| 1219 |
| 1220 // Advancing the sweeper step-wise should not change the heap size. |
| 1221 while (!HEAP->old_pointer_space()->IsSweepingComplete()) { |
| 1222 HEAP->old_pointer_space()->AdvanceSweeper(KB); |
| 1223 CHECK_EQ(initial_size, static_cast<int>(HEAP->SizeOfObjects())); |
| 1224 } |
| 1225 } |
| 1226 |
| 1227 |
1190 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { | 1228 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
1191 InitializeVM(); | 1229 InitializeVM(); |
1192 HEAP->EnsureHeapIsIterable(); | 1230 HEAP->EnsureHeapIsIterable(); |
1193 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); | 1231 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); |
1194 HeapIterator iterator; | 1232 HeapIterator iterator; |
1195 intptr_t size_of_objects_2 = 0; | 1233 intptr_t size_of_objects_2 = 0; |
1196 for (HeapObject* obj = iterator.next(); | 1234 for (HeapObject* obj = iterator.next(); |
1197 obj != NULL; | 1235 obj != NULL; |
1198 obj = iterator.next()) { | 1236 obj = iterator.next()) { |
1199 size_of_objects_2 += obj->Size(); | 1237 size_of_objects_2 += obj->Size(); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 ctx2->Exit(); | 1507 ctx2->Exit(); |
1470 ctx1->Exit(); | 1508 ctx1->Exit(); |
1471 ctx1.Dispose(); | 1509 ctx1.Dispose(); |
1472 } | 1510 } |
1473 HEAP->CollectAllAvailableGarbage(); | 1511 HEAP->CollectAllAvailableGarbage(); |
1474 CHECK_EQ(2, NumberOfGlobalObjects()); | 1512 CHECK_EQ(2, NumberOfGlobalObjects()); |
1475 ctx2.Dispose(); | 1513 ctx2.Dispose(); |
1476 HEAP->CollectAllAvailableGarbage(); | 1514 HEAP->CollectAllAvailableGarbage(); |
1477 CHECK_EQ(0, NumberOfGlobalObjects()); | 1515 CHECK_EQ(0, NumberOfGlobalObjects()); |
1478 } | 1516 } |
| 1517 |
| 1518 |
| 1519 TEST(InstanceOfStubWriteBarrier) { |
| 1520 i::FLAG_allow_natives_syntax = true; |
| 1521 #ifdef DEBUG |
| 1522 i::FLAG_verify_heap = true; |
| 1523 #endif |
| 1524 InitializeVM(); |
| 1525 if (!i::V8::UseCrankshaft()) return; |
| 1526 v8::HandleScope outer_scope; |
| 1527 |
| 1528 { |
| 1529 v8::HandleScope scope; |
| 1530 CompileRun( |
| 1531 "function foo () { }" |
| 1532 "function mkbar () { return new (new Function(\"\")) (); }" |
| 1533 "function f (x) { return (x instanceof foo); }" |
| 1534 "function g () { f(mkbar()); }" |
| 1535 "f(new foo()); f(new foo());" |
| 1536 "%OptimizeFunctionOnNextCall(f);" |
| 1537 "f(new foo()); g();"); |
| 1538 } |
| 1539 |
| 1540 IncrementalMarking* marking = HEAP->incremental_marking(); |
| 1541 marking->Abort(); |
| 1542 marking->Start(); |
| 1543 |
| 1544 Handle<JSFunction> f = |
| 1545 v8::Utils::OpenHandle( |
| 1546 *v8::Handle<v8::Function>::Cast( |
| 1547 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); |
| 1548 |
| 1549 CHECK(f->IsOptimized()); |
| 1550 |
| 1551 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && |
| 1552 !marking->IsStopped()) { |
| 1553 marking->Step(MB); |
| 1554 } |
| 1555 |
| 1556 CHECK(marking->IsMarking()); |
| 1557 |
| 1558 // Discard any pending GC requests otherwise we will get GC when we enter |
| 1559 // code below. |
| 1560 if (ISOLATE->stack_guard()->IsGCRequest()) { |
| 1561 ISOLATE->stack_guard()->Continue(GC_REQUEST); |
| 1562 } |
| 1563 |
| 1564 { |
| 1565 v8::HandleScope scope; |
| 1566 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global(); |
| 1567 v8::Handle<v8::Function> g = |
| 1568 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); |
| 1569 g->Call(global, 0, NULL); |
| 1570 } |
| 1571 |
| 1572 HEAP->incremental_marking()->set_should_hurry(true); |
| 1573 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 1574 } |
OLD | NEW |