| 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 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2583         "function mkbar () { return new (new Function(\"\")) (); }" |  2583         "function mkbar () { return new (new Function(\"\")) (); }" | 
|  2584         "function f (x) { return (x instanceof foo); }" |  2584         "function f (x) { return (x instanceof foo); }" | 
|  2585         "function g () { f(mkbar()); }" |  2585         "function g () { f(mkbar()); }" | 
|  2586         "f(new foo()); f(new foo());" |  2586         "f(new foo()); f(new foo());" | 
|  2587         "%OptimizeFunctionOnNextCall(f);" |  2587         "%OptimizeFunctionOnNextCall(f);" | 
|  2588         "f(new foo()); g();"); |  2588         "f(new foo()); g();"); | 
|  2589   } |  2589   } | 
|  2590  |  2590  | 
|  2591   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |  2591   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 
|  2592   marking->Stop(); |  2592   marking->Stop(); | 
|  2593   marking->Start(Heap::kNoGCFlags); |  2593   CcTest::heap()->StartIncrementalMarking(); | 
|  2594  |  2594  | 
|  2595   Handle<JSFunction> f = |  2595   Handle<JSFunction> f = | 
|  2596       v8::Utils::OpenHandle( |  2596       v8::Utils::OpenHandle( | 
|  2597           *v8::Handle<v8::Function>::Cast( |  2597           *v8::Handle<v8::Function>::Cast( | 
|  2598               CcTest::global()->Get(v8_str("f")))); |  2598               CcTest::global()->Get(v8_str("f")))); | 
|  2599  |  2599  | 
|  2600   CHECK(f->IsOptimized()); |  2600   CHECK(f->IsOptimized()); | 
|  2601  |  2601  | 
|  2602   while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && |  2602   while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && | 
|  2603          !marking->IsStopped()) { |  2603          !marking->IsStopped()) { | 
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2711         "f();"); |  2711         "f();"); | 
|  2712   } |  2712   } | 
|  2713   Handle<JSFunction> f = |  2713   Handle<JSFunction> f = | 
|  2714       v8::Utils::OpenHandle( |  2714       v8::Utils::OpenHandle( | 
|  2715           *v8::Handle<v8::Function>::Cast( |  2715           *v8::Handle<v8::Function>::Cast( | 
|  2716               CcTest::global()->Get(v8_str("f")))); |  2716               CcTest::global()->Get(v8_str("f")))); | 
|  2717   CHECK(f->IsOptimized()); |  2717   CHECK(f->IsOptimized()); | 
|  2718  |  2718  | 
|  2719   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |  2719   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 
|  2720   marking->Stop(); |  2720   marking->Stop(); | 
|  2721   marking->Start(Heap::kNoGCFlags); |  2721   CcTest::heap()->StartIncrementalMarking(); | 
|  2722   // The following calls will increment CcTest::heap()->global_ic_age(). |  2722   // The following calls will increment CcTest::heap()->global_ic_age(). | 
|  2723   CcTest::isolate()->ContextDisposedNotification(); |  2723   CcTest::isolate()->ContextDisposedNotification(); | 
|  2724   SimulateIncrementalMarking(CcTest::heap()); |  2724   SimulateIncrementalMarking(CcTest::heap()); | 
|  2725   CcTest::heap()->CollectAllGarbage(); |  2725   CcTest::heap()->CollectAllGarbage(); | 
|  2726   CHECK_EQ(CcTest::heap()->global_ic_age(), f->shared()->ic_age()); |  2726   CHECK_EQ(CcTest::heap()->global_ic_age(), f->shared()->ic_age()); | 
|  2727   CHECK_EQ(0, f->shared()->opt_count()); |  2727   CHECK_EQ(0, f->shared()->opt_count()); | 
|  2728   CHECK_EQ(0, f->shared()->code()->profiler_ticks()); |  2728   CHECK_EQ(0, f->shared()->code()->profiler_ticks()); | 
|  2729 } |  2729 } | 
|  2730  |  2730  | 
|  2731  |  2731  | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2768   CHECK_EQ(0, f->shared()->opt_count()); |  2768   CHECK_EQ(0, f->shared()->opt_count()); | 
|  2769   CHECK_EQ(0, f->shared()->code()->profiler_ticks()); |  2769   CHECK_EQ(0, f->shared()->code()->profiler_ticks()); | 
|  2770 } |  2770 } | 
|  2771  |  2771  | 
|  2772  |  2772  | 
|  2773 HEAP_TEST(GCFlags) { |  2773 HEAP_TEST(GCFlags) { | 
|  2774   CcTest::InitializeVM(); |  2774   CcTest::InitializeVM(); | 
|  2775   Heap* heap = CcTest::heap(); |  2775   Heap* heap = CcTest::heap(); | 
|  2776  |  2776  | 
|  2777   heap->set_current_gc_flags(Heap::kNoGCFlags); |  2777   heap->set_current_gc_flags(Heap::kNoGCFlags); | 
|  2778   CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags()); |  2778   CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags_); | 
|  2779  |  2779  | 
|  2780   // Set the flags to check whether we appropriately resets them after the GC. |  2780   // Set the flags to check whether we appropriately resets them after the GC. | 
|  2781   heap->set_current_gc_flags(Heap::kAbortIncrementalMarkingMask); |  2781   heap->set_current_gc_flags(Heap::kAbortIncrementalMarkingMask); | 
|  2782   heap->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); |  2782   heap->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); | 
|  2783   CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags()); |  2783   CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags_); | 
|  2784  |  2784  | 
|  2785   MarkCompactCollector* collector = heap->mark_compact_collector(); |  2785   MarkCompactCollector* collector = heap->mark_compact_collector(); | 
|  2786   if (collector->sweeping_in_progress()) { |  2786   if (collector->sweeping_in_progress()) { | 
|  2787     collector->EnsureSweepingCompleted(); |  2787     collector->EnsureSweepingCompleted(); | 
|  2788   } |  2788   } | 
|  2789  |  2789  | 
|  2790   IncrementalMarking* marking = heap->incremental_marking(); |  2790   IncrementalMarking* marking = heap->incremental_marking(); | 
|  2791   marking->Stop(); |  2791   marking->Stop(); | 
|  2792   marking->Start(Heap::kReduceMemoryFootprintMask); |  2792   heap->StartIncrementalMarking(Heap::kReduceMemoryFootprintMask); | 
|  2793   CHECK_NE(0, heap->current_gc_flags() & Heap::kReduceMemoryFootprintMask); |  2793   CHECK_NE(0, heap->current_gc_flags_ & Heap::kReduceMemoryFootprintMask); | 
|  2794  |  2794  | 
|  2795   heap->CollectGarbage(NEW_SPACE); |  2795   heap->CollectGarbage(NEW_SPACE); | 
|  2796   // NewSpace scavenges should not overwrite the flags. |  2796   // NewSpace scavenges should not overwrite the flags. | 
|  2797   CHECK_NE(0, heap->current_gc_flags() & Heap::kReduceMemoryFootprintMask); |  2797   CHECK_NE(0, heap->current_gc_flags_ & Heap::kReduceMemoryFootprintMask); | 
|  2798  |  2798  | 
|  2799   heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |  2799   heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 
|  2800   CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags()); |  2800   CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags_); | 
|  2801 } |  2801 } | 
|  2802  |  2802  | 
|  2803  |  2803  | 
|  2804 TEST(IdleNotificationFinishMarking) { |  2804 TEST(IdleNotificationFinishMarking) { | 
|  2805   i::FLAG_allow_natives_syntax = true; |  2805   i::FLAG_allow_natives_syntax = true; | 
|  2806   CcTest::InitializeVM(); |  2806   CcTest::InitializeVM(); | 
|  2807   SimulateFullSpace(CcTest::heap()->old_space()); |  2807   SimulateFullSpace(CcTest::heap()->old_space()); | 
|  2808   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |  2808   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 
|  2809   marking->Stop(); |  2809   marking->Stop(); | 
|  2810   marking->Start(Heap::kNoGCFlags); |  2810   CcTest::heap()->StartIncrementalMarking(); | 
|  2811  |  2811  | 
|  2812   CHECK_EQ(CcTest::heap()->gc_count(), 0); |  2812   CHECK_EQ(CcTest::heap()->gc_count(), 0); | 
|  2813  |  2813  | 
|  2814   // TODO(hpayer): We cannot write proper unit test right now for heap. |  2814   // TODO(hpayer): We cannot write proper unit test right now for heap. | 
|  2815   // The ideal test would call kMaxIdleMarkingDelayCounter to test the |  2815   // The ideal test would call kMaxIdleMarkingDelayCounter to test the | 
|  2816   // marking delay counter. |  2816   // marking delay counter. | 
|  2817  |  2817  | 
|  2818   // Perform a huge incremental marking step but don't complete marking. |  2818   // Perform a huge incremental marking step but don't complete marking. | 
|  2819   intptr_t bytes_processed = 0; |  2819   intptr_t bytes_processed = 0; | 
|  2820   do { |  2820   do { | 
| (...skipping 1932 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4753  |  4753  | 
|  4754 TEST(IncrementalMarkingStepMakesBigProgressWithLargeObjects) { |  4754 TEST(IncrementalMarkingStepMakesBigProgressWithLargeObjects) { | 
|  4755   CcTest::InitializeVM(); |  4755   CcTest::InitializeVM(); | 
|  4756   v8::HandleScope scope(CcTest::isolate()); |  4756   v8::HandleScope scope(CcTest::isolate()); | 
|  4757   CompileRun("function f(n) {" |  4757   CompileRun("function f(n) {" | 
|  4758              "    var a = new Array(n);" |  4758              "    var a = new Array(n);" | 
|  4759              "    for (var i = 0; i < n; i += 100) a[i] = i;" |  4759              "    for (var i = 0; i < n; i += 100) a[i] = i;" | 
|  4760              "};" |  4760              "};" | 
|  4761              "f(10 * 1024 * 1024);"); |  4761              "f(10 * 1024 * 1024);"); | 
|  4762   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |  4762   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 
|  4763   if (marking->IsStopped()) marking->Start(Heap::kNoGCFlags); |  4763   if (marking->IsStopped()) { | 
 |  4764     CcTest::heap()->StartIncrementalMarking(); | 
 |  4765   } | 
|  4764   // This big step should be sufficient to mark the whole array. |  4766   // This big step should be sufficient to mark the whole array. | 
|  4765   marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |  4767   marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 
|  4766   DCHECK(marking->IsComplete() || |  4768   DCHECK(marking->IsComplete() || | 
|  4767          marking->IsReadyToOverApproximateWeakClosure()); |  4769          marking->IsReadyToOverApproximateWeakClosure()); | 
|  4768 } |  4770 } | 
|  4769  |  4771  | 
|  4770  |  4772  | 
|  4771 TEST(DisableInlineAllocation) { |  4773 TEST(DisableInlineAllocation) { | 
|  4772   i::FLAG_allow_natives_syntax = true; |  4774   i::FLAG_allow_natives_syntax = true; | 
|  4773   CcTest::InitializeVM(); |  4775   CcTest::InitializeVM(); | 
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  5481   Handle<FixedArray> survivor = factory->NewFixedArray(1, NOT_TENURED); |  5483   Handle<FixedArray> survivor = factory->NewFixedArray(1, NOT_TENURED); | 
|  5482   Handle<WeakCell> weak_cells[N]; |  5484   Handle<WeakCell> weak_cells[N]; | 
|  5483  |  5485  | 
|  5484   for (int i = 0; i < N; i++) { |  5486   for (int i = 0; i < N; i++) { | 
|  5485     HandleScope inner_scope(isolate); |  5487     HandleScope inner_scope(isolate); | 
|  5486     Handle<HeapObject> value = |  5488     Handle<HeapObject> value = | 
|  5487         i == 0 ? survivor : factory->NewFixedArray(1, NOT_TENURED); |  5489         i == 0 ? survivor : factory->NewFixedArray(1, NOT_TENURED); | 
|  5488     Handle<WeakCell> weak_cell = factory->NewWeakCell(value); |  5490     Handle<WeakCell> weak_cell = factory->NewWeakCell(value); | 
|  5489     CHECK(weak_cell->value()->IsFixedArray()); |  5491     CHECK(weak_cell->value()->IsFixedArray()); | 
|  5490     IncrementalMarking* marking = heap->incremental_marking(); |  5492     IncrementalMarking* marking = heap->incremental_marking(); | 
|  5491     if (marking->IsStopped()) marking->Start(Heap::kNoGCFlags); |  5493     if (marking->IsStopped()) { | 
 |  5494       heap->StartIncrementalMarking(); | 
 |  5495     } | 
|  5492     marking->Step(128, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |  5496     marking->Step(128, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 
|  5493     heap->CollectGarbage(NEW_SPACE); |  5497     heap->CollectGarbage(NEW_SPACE); | 
|  5494     CHECK(weak_cell->value()->IsFixedArray()); |  5498     CHECK(weak_cell->value()->IsFixedArray()); | 
|  5495     weak_cells[i] = inner_scope.CloseAndEscape(weak_cell); |  5499     weak_cells[i] = inner_scope.CloseAndEscape(weak_cell); | 
|  5496   } |  5500   } | 
|  5497   heap->CollectAllGarbage(); |  5501   heap->CollectAllGarbage(); | 
|  5498   CHECK_EQ(*survivor, weak_cells[0]->value()); |  5502   CHECK_EQ(*survivor, weak_cells[0]->value()); | 
|  5499   for (int i = 1; i < N; i++) { |  5503   for (int i = 1; i < N; i++) { | 
|  5500     CHECK(weak_cells[i]->cleared()); |  5504     CHECK(weak_cells[i]->cleared()); | 
|  5501   } |  5505   } | 
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  5774   // Ensure that the object allocated where we need it. |  5778   // Ensure that the object allocated where we need it. | 
|  5775   Page* page = Page::FromAddress(o->address()); |  5779   Page* page = Page::FromAddress(o->address()); | 
|  5776   CHECK_EQ(desired_offset, page->Offset(o->address())); |  5780   CHECK_EQ(desired_offset, page->Offset(o->address())); | 
|  5777  |  5781  | 
|  5778   // Now we have an object right at the end of the page. |  5782   // Now we have an object right at the end of the page. | 
|  5779  |  5783  | 
|  5780   // Enable incremental marking to trigger actions in Heap::AdjustLiveBytes() |  5784   // Enable incremental marking to trigger actions in Heap::AdjustLiveBytes() | 
|  5781   // that would cause crash. |  5785   // that would cause crash. | 
|  5782   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |  5786   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 
|  5783   marking->Stop(); |  5787   marking->Stop(); | 
|  5784   marking->Start(Heap::kNoGCFlags); |  5788   CcTest::heap()->StartIncrementalMarking(); | 
|  5785   CHECK(marking->IsMarking()); |  5789   CHECK(marking->IsMarking()); | 
|  5786  |  5790  | 
|  5787   // Now everything is set up for crashing in JSObject::MigrateFastToFast() |  5791   // Now everything is set up for crashing in JSObject::MigrateFastToFast() | 
|  5788   // when it calls heap->AdjustLiveBytes(...). |  5792   // when it calls heap->AdjustLiveBytes(...). | 
|  5789   JSObject::MigrateToMap(o, map2); |  5793   JSObject::MigrateToMap(o, map2); | 
|  5790 } |  5794 } | 
|  5791  |  5795  | 
|  5792  |  5796  | 
|  5793 TEST(Regress3631) { |  5797 TEST(Regress3631) { | 
|  5794   i::FLAG_expose_gc = true; |  5798   i::FLAG_expose_gc = true; | 
|  5795   CcTest::InitializeVM(); |  5799   CcTest::InitializeVM(); | 
|  5796   v8::HandleScope scope(CcTest::isolate()); |  5800   v8::HandleScope scope(CcTest::isolate()); | 
|  5797   Isolate* isolate = CcTest::i_isolate(); |  5801   Isolate* isolate = CcTest::i_isolate(); | 
|  5798   Heap* heap = isolate->heap(); |  5802   Heap* heap = isolate->heap(); | 
|  5799   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |  5803   IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 
|  5800   v8::Local<v8::Value> result = CompileRun( |  5804   v8::Local<v8::Value> result = CompileRun( | 
|  5801       "var weak_map = new WeakMap();" |  5805       "var weak_map = new WeakMap();" | 
|  5802       "var future_keys = [];" |  5806       "var future_keys = [];" | 
|  5803       "for (var i = 0; i < 50; i++) {" |  5807       "for (var i = 0; i < 50; i++) {" | 
|  5804       "  var key = {'k' : i + 0.1};" |  5808       "  var key = {'k' : i + 0.1};" | 
|  5805       "  weak_map.set(key, 1);" |  5809       "  weak_map.set(key, 1);" | 
|  5806       "  future_keys.push({'x' : i + 0.2});" |  5810       "  future_keys.push({'x' : i + 0.2});" | 
|  5807       "}" |  5811       "}" | 
|  5808       "weak_map"); |  5812       "weak_map"); | 
|  5809   if (marking->IsStopped()) { |  5813   if (marking->IsStopped()) { | 
|  5810     marking->Start(Heap::kNoGCFlags); |  5814     CcTest::heap()->StartIncrementalMarking(); | 
|  5811   } |  5815   } | 
|  5812   // Incrementally mark the backing store. |  5816   // Incrementally mark the backing store. | 
|  5813   Handle<JSObject> obj = |  5817   Handle<JSObject> obj = | 
|  5814       v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |  5818       v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 
|  5815   Handle<JSWeakCollection> weak_map(reinterpret_cast<JSWeakCollection*>(*obj)); |  5819   Handle<JSWeakCollection> weak_map(reinterpret_cast<JSWeakCollection*>(*obj)); | 
|  5816   while (!Marking::IsBlack( |  5820   while (!Marking::IsBlack( | 
|  5817              Marking::MarkBitFrom(HeapObject::cast(weak_map->table()))) && |  5821              Marking::MarkBitFrom(HeapObject::cast(weak_map->table()))) && | 
|  5818          !marking->IsStopped()) { |  5822          !marking->IsStopped()) { | 
|  5819     marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |  5823     marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 
|  5820   } |  5824   } | 
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  6521   { |  6525   { | 
|  6522     SharedFunctionInfo::Iterator iterator(isolate); |  6526     SharedFunctionInfo::Iterator iterator(isolate); | 
|  6523     while (iterator.Next()) sfi_count--; |  6527     while (iterator.Next()) sfi_count--; | 
|  6524   } |  6528   } | 
|  6525  |  6529  | 
|  6526   CHECK_EQ(0, sfi_count); |  6530   CHECK_EQ(0, sfi_count); | 
|  6527 } |  6531 } | 
|  6528  |  6532  | 
|  6529 }  // namespace internal |  6533 }  // namespace internal | 
|  6530 }  // namespace v8 |  6534 }  // namespace v8 | 
| OLD | NEW |