OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "api.h" | 7 #include "api.h" |
8 #include "arguments.h" | 8 #include "arguments.h" |
9 #include "bootstrapper.h" | 9 #include "bootstrapper.h" |
10 #include "code-stubs.h" | 10 #include "code-stubs.h" |
(...skipping 2035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 // We could perhaps avoid this list and instead re-use the GC metadata | 2046 // We could perhaps avoid this list and instead re-use the GC metadata |
2047 // links. | 2047 // links. |
2048 List<Handle<JSFunction> > generator_functions; | 2048 List<Handle<JSFunction> > generator_functions; |
2049 | 2049 |
2050 { | 2050 { |
2051 // We are going to iterate heap to find all functions without | 2051 // We are going to iterate heap to find all functions without |
2052 // debug break slots. | 2052 // debug break slots. |
2053 Heap* heap = isolate_->heap(); | 2053 Heap* heap = isolate_->heap(); |
2054 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, | 2054 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
2055 "preparing for breakpoints"); | 2055 "preparing for breakpoints"); |
| 2056 HeapIterator iterator(heap); |
2056 | 2057 |
2057 // Ensure no GC in this scope as we are going to use gc_metadata | 2058 // Ensure no GC in this scope as we are going to use gc_metadata |
2058 // field in the Code object to mark active functions. | 2059 // field in the Code object to mark active functions. |
2059 DisallowHeapAllocation no_allocation; | 2060 DisallowHeapAllocation no_allocation; |
2060 | 2061 |
2061 Object* active_code_marker = heap->the_hole_value(); | 2062 Object* active_code_marker = heap->the_hole_value(); |
2062 | 2063 |
2063 CollectActiveFunctionsFromThread(isolate_, | 2064 CollectActiveFunctionsFromThread(isolate_, |
2064 isolate_->thread_local_top(), | 2065 isolate_->thread_local_top(), |
2065 &active_functions, | 2066 &active_functions, |
2066 active_code_marker); | 2067 active_code_marker); |
2067 ActiveFunctionsCollector active_functions_collector(&active_functions, | 2068 ActiveFunctionsCollector active_functions_collector(&active_functions, |
2068 active_code_marker); | 2069 active_code_marker); |
2069 isolate_->thread_manager()->IterateArchivedThreads( | 2070 isolate_->thread_manager()->IterateArchivedThreads( |
2070 &active_functions_collector); | 2071 &active_functions_collector); |
2071 | 2072 |
2072 // Scan the heap for all non-optimized functions which have no | 2073 // Scan the heap for all non-optimized functions which have no |
2073 // debug break slots and are not active or inlined into an active | 2074 // debug break slots and are not active or inlined into an active |
2074 // function and mark them for lazy compilation. | 2075 // function and mark them for lazy compilation. |
2075 HeapIterator iterator(heap); | |
2076 HeapObject* obj = NULL; | 2076 HeapObject* obj = NULL; |
2077 while (((obj = iterator.next()) != NULL)) { | 2077 while (((obj = iterator.next()) != NULL)) { |
2078 if (obj->IsJSFunction()) { | 2078 if (obj->IsJSFunction()) { |
2079 JSFunction* function = JSFunction::cast(obj); | 2079 JSFunction* function = JSFunction::cast(obj); |
2080 SharedFunctionInfo* shared = function->shared(); | 2080 SharedFunctionInfo* shared = function->shared(); |
2081 | 2081 |
2082 if (!shared->allows_lazy_compilation()) continue; | 2082 if (!shared->allows_lazy_compilation()) continue; |
2083 if (!shared->script()->IsScript()) continue; | 2083 if (!shared->script()->IsScript()) continue; |
2084 if (function->IsBuiltin()) continue; | 2084 if (function->IsBuiltin()) continue; |
2085 if (shared->code()->gc_metadata() == active_code_marker) continue; | 2085 if (shared->code()->gc_metadata() == active_code_marker) continue; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 // NOTE: The below fix-point iteration depends on all functions that cannot be | 2190 // NOTE: The below fix-point iteration depends on all functions that cannot be |
2191 // compiled lazily without a context to not be compiled at all. Compilation | 2191 // compiled lazily without a context to not be compiled at all. Compilation |
2192 // will be triggered at points where we do not need a context. | 2192 // will be triggered at points where we do not need a context. |
2193 bool done = false; | 2193 bool done = false; |
2194 // The current candidate for the source position: | 2194 // The current candidate for the source position: |
2195 int target_start_position = RelocInfo::kNoPosition; | 2195 int target_start_position = RelocInfo::kNoPosition; |
2196 Handle<JSFunction> target_function; | 2196 Handle<JSFunction> target_function; |
2197 Handle<SharedFunctionInfo> target; | 2197 Handle<SharedFunctionInfo> target; |
2198 Heap* heap = isolate_->heap(); | 2198 Heap* heap = isolate_->heap(); |
2199 while (!done) { | 2199 while (!done) { |
2200 { // Extra scope for iterator and no-allocation. | 2200 { // Extra scope for iterator. |
2201 heap->EnsureHeapIsIterable(); | |
2202 DisallowHeapAllocation no_alloc_during_heap_iteration; | |
2203 HeapIterator iterator(heap); | 2201 HeapIterator iterator(heap); |
2204 for (HeapObject* obj = iterator.next(); | 2202 for (HeapObject* obj = iterator.next(); |
2205 obj != NULL; obj = iterator.next()) { | 2203 obj != NULL; obj = iterator.next()) { |
2206 bool found_next_candidate = false; | 2204 bool found_next_candidate = false; |
2207 Handle<JSFunction> function; | 2205 Handle<JSFunction> function; |
2208 Handle<SharedFunctionInfo> shared; | 2206 Handle<SharedFunctionInfo> shared; |
2209 if (obj->IsJSFunction()) { | 2207 if (obj->IsJSFunction()) { |
2210 function = Handle<JSFunction>(JSFunction::cast(obj)); | 2208 function = Handle<JSFunction>(JSFunction::cast(obj)); |
2211 shared = Handle<SharedFunctionInfo>(function->shared()); | 2209 shared = Handle<SharedFunctionInfo>(function->shared()); |
2212 ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); | 2210 ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 | 2520 |
2523 void Debug::CreateScriptCache() { | 2521 void Debug::CreateScriptCache() { |
2524 Heap* heap = isolate_->heap(); | 2522 Heap* heap = isolate_->heap(); |
2525 HandleScope scope(isolate_); | 2523 HandleScope scope(isolate_); |
2526 | 2524 |
2527 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | 2525 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
2528 // rid of all the cached script wrappers and the second gets rid of the | 2526 // rid of all the cached script wrappers and the second gets rid of the |
2529 // scripts which are no longer referenced. The second also sweeps precisely, | 2527 // scripts which are no longer referenced. The second also sweeps precisely, |
2530 // which saves us doing yet another GC to make the heap iterable. | 2528 // which saves us doing yet another GC to make the heap iterable. |
2531 heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); | 2529 heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); |
2532 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, | |
2533 "Debug::CreateScriptCache"); | |
2534 | 2530 |
2535 ASSERT(script_cache_ == NULL); | 2531 ASSERT(script_cache_ == NULL); |
2536 script_cache_ = new ScriptCache(isolate_); | 2532 script_cache_ = new ScriptCache(isolate_); |
2537 | 2533 |
2538 // Scan heap for Script objects. | 2534 // Scan heap for Script objects. |
2539 int count = 0; | 2535 int count = 0; |
2540 HeapIterator iterator(heap); | 2536 HeapIterator iterator(heap); |
2541 DisallowHeapAllocation no_allocation; | |
2542 | 2537 |
2543 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2538 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
2544 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { | 2539 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { |
2545 script_cache_->Add(Handle<Script>(Script::cast(obj))); | 2540 script_cache_->Add(Handle<Script>(Script::cast(obj))); |
2546 count++; | 2541 count++; |
2547 } | 2542 } |
2548 } | 2543 } |
2549 } | 2544 } |
2550 | 2545 |
2551 | 2546 |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 logger_->DebugEvent("Put", message.text()); | 3551 logger_->DebugEvent("Put", message.text()); |
3557 } | 3552 } |
3558 | 3553 |
3559 | 3554 |
3560 void LockingCommandMessageQueue::Clear() { | 3555 void LockingCommandMessageQueue::Clear() { |
3561 LockGuard<Mutex> lock_guard(&mutex_); | 3556 LockGuard<Mutex> lock_guard(&mutex_); |
3562 queue_.Clear(); | 3557 queue_.Clear(); |
3563 } | 3558 } |
3564 | 3559 |
3565 } } // namespace v8::internal | 3560 } } // namespace v8::internal |
OLD | NEW |