| 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 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 // We could perhaps avoid this list and instead re-use the GC metadata | 2041 // We could perhaps avoid this list and instead re-use the GC metadata |
| 2042 // links. | 2042 // links. |
| 2043 List<Handle<JSFunction> > generator_functions; | 2043 List<Handle<JSFunction> > generator_functions; |
| 2044 | 2044 |
| 2045 { | 2045 { |
| 2046 // We are going to iterate heap to find all functions without | 2046 // We are going to iterate heap to find all functions without |
| 2047 // debug break slots. | 2047 // debug break slots. |
| 2048 Heap* heap = isolate_->heap(); | 2048 Heap* heap = isolate_->heap(); |
| 2049 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, | 2049 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 2050 "preparing for breakpoints"); | 2050 "preparing for breakpoints"); |
| 2051 HeapIterator iterator(heap); |
| 2051 | 2052 |
| 2052 // Ensure no GC in this scope as we are going to use gc_metadata | 2053 // Ensure no GC in this scope as we are going to use gc_metadata |
| 2053 // field in the Code object to mark active functions. | 2054 // field in the Code object to mark active functions. |
| 2054 DisallowHeapAllocation no_allocation; | 2055 DisallowHeapAllocation no_allocation; |
| 2055 | 2056 |
| 2056 Object* active_code_marker = heap->the_hole_value(); | 2057 Object* active_code_marker = heap->the_hole_value(); |
| 2057 | 2058 |
| 2058 CollectActiveFunctionsFromThread(isolate_, | 2059 CollectActiveFunctionsFromThread(isolate_, |
| 2059 isolate_->thread_local_top(), | 2060 isolate_->thread_local_top(), |
| 2060 &active_functions, | 2061 &active_functions, |
| 2061 active_code_marker); | 2062 active_code_marker); |
| 2062 ActiveFunctionsCollector active_functions_collector(&active_functions, | 2063 ActiveFunctionsCollector active_functions_collector(&active_functions, |
| 2063 active_code_marker); | 2064 active_code_marker); |
| 2064 isolate_->thread_manager()->IterateArchivedThreads( | 2065 isolate_->thread_manager()->IterateArchivedThreads( |
| 2065 &active_functions_collector); | 2066 &active_functions_collector); |
| 2066 | 2067 |
| 2067 // Scan the heap for all non-optimized functions which have no | 2068 // Scan the heap for all non-optimized functions which have no |
| 2068 // debug break slots and are not active or inlined into an active | 2069 // debug break slots and are not active or inlined into an active |
| 2069 // function and mark them for lazy compilation. | 2070 // function and mark them for lazy compilation. |
| 2070 HeapIterator iterator(heap); | |
| 2071 HeapObject* obj = NULL; | 2071 HeapObject* obj = NULL; |
| 2072 while (((obj = iterator.next()) != NULL)) { | 2072 while (((obj = iterator.next()) != NULL)) { |
| 2073 if (obj->IsJSFunction()) { | 2073 if (obj->IsJSFunction()) { |
| 2074 JSFunction* function = JSFunction::cast(obj); | 2074 JSFunction* function = JSFunction::cast(obj); |
| 2075 SharedFunctionInfo* shared = function->shared(); | 2075 SharedFunctionInfo* shared = function->shared(); |
| 2076 | 2076 |
| 2077 if (!shared->allows_lazy_compilation()) continue; | 2077 if (!shared->allows_lazy_compilation()) continue; |
| 2078 if (!shared->script()->IsScript()) continue; | 2078 if (!shared->script()->IsScript()) continue; |
| 2079 if (function->IsBuiltin()) continue; | 2079 if (function->IsBuiltin()) continue; |
| 2080 if (shared->code()->gc_metadata() == active_code_marker) continue; | 2080 if (shared->code()->gc_metadata() == active_code_marker) continue; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 // NOTE: The below fix-point iteration depends on all functions that cannot be | 2185 // NOTE: The below fix-point iteration depends on all functions that cannot be |
| 2186 // compiled lazily without a context to not be compiled at all. Compilation | 2186 // compiled lazily without a context to not be compiled at all. Compilation |
| 2187 // will be triggered at points where we do not need a context. | 2187 // will be triggered at points where we do not need a context. |
| 2188 bool done = false; | 2188 bool done = false; |
| 2189 // The current candidate for the source position: | 2189 // The current candidate for the source position: |
| 2190 int target_start_position = RelocInfo::kNoPosition; | 2190 int target_start_position = RelocInfo::kNoPosition; |
| 2191 Handle<JSFunction> target_function; | 2191 Handle<JSFunction> target_function; |
| 2192 Handle<SharedFunctionInfo> target; | 2192 Handle<SharedFunctionInfo> target; |
| 2193 Heap* heap = isolate_->heap(); | 2193 Heap* heap = isolate_->heap(); |
| 2194 while (!done) { | 2194 while (!done) { |
| 2195 { // Extra scope for iterator and no-allocation. | 2195 { // Extra scope for iterator. |
| 2196 heap->EnsureHeapIsIterable(); | |
| 2197 DisallowHeapAllocation no_alloc_during_heap_iteration; | |
| 2198 HeapIterator iterator(heap); | 2196 HeapIterator iterator(heap); |
| 2199 for (HeapObject* obj = iterator.next(); | 2197 for (HeapObject* obj = iterator.next(); |
| 2200 obj != NULL; obj = iterator.next()) { | 2198 obj != NULL; obj = iterator.next()) { |
| 2201 bool found_next_candidate = false; | 2199 bool found_next_candidate = false; |
| 2202 Handle<JSFunction> function; | 2200 Handle<JSFunction> function; |
| 2203 Handle<SharedFunctionInfo> shared; | 2201 Handle<SharedFunctionInfo> shared; |
| 2204 if (obj->IsJSFunction()) { | 2202 if (obj->IsJSFunction()) { |
| 2205 function = Handle<JSFunction>(JSFunction::cast(obj)); | 2203 function = Handle<JSFunction>(JSFunction::cast(obj)); |
| 2206 shared = Handle<SharedFunctionInfo>(function->shared()); | 2204 shared = Handle<SharedFunctionInfo>(function->shared()); |
| 2207 ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); | 2205 ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2517 | 2515 |
| 2518 void Debug::CreateScriptCache() { | 2516 void Debug::CreateScriptCache() { |
| 2519 Heap* heap = isolate_->heap(); | 2517 Heap* heap = isolate_->heap(); |
| 2520 HandleScope scope(isolate_); | 2518 HandleScope scope(isolate_); |
| 2521 | 2519 |
| 2522 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | 2520 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
| 2523 // rid of all the cached script wrappers and the second gets rid of the | 2521 // rid of all the cached script wrappers and the second gets rid of the |
| 2524 // scripts which are no longer referenced. The second also sweeps precisely, | 2522 // scripts which are no longer referenced. The second also sweeps precisely, |
| 2525 // which saves us doing yet another GC to make the heap iterable. | 2523 // which saves us doing yet another GC to make the heap iterable. |
| 2526 heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); | 2524 heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); |
| 2527 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, | |
| 2528 "Debug::CreateScriptCache"); | |
| 2529 | 2525 |
| 2530 ASSERT(script_cache_ == NULL); | 2526 ASSERT(script_cache_ == NULL); |
| 2531 script_cache_ = new ScriptCache(isolate_); | 2527 script_cache_ = new ScriptCache(isolate_); |
| 2532 | 2528 |
| 2533 // Scan heap for Script objects. | 2529 // Scan heap for Script objects. |
| 2534 int count = 0; | 2530 int count = 0; |
| 2535 HeapIterator iterator(heap); | 2531 HeapIterator iterator(heap); |
| 2536 DisallowHeapAllocation no_allocation; | |
| 2537 | 2532 |
| 2538 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2533 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 2539 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { | 2534 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { |
| 2540 script_cache_->Add(Handle<Script>(Script::cast(obj))); | 2535 script_cache_->Add(Handle<Script>(Script::cast(obj))); |
| 2541 count++; | 2536 count++; |
| 2542 } | 2537 } |
| 2543 } | 2538 } |
| 2544 } | 2539 } |
| 2545 | 2540 |
| 2546 | 2541 |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3551 logger_->DebugEvent("Put", message.text()); | 3546 logger_->DebugEvent("Put", message.text()); |
| 3552 } | 3547 } |
| 3553 | 3548 |
| 3554 | 3549 |
| 3555 void LockingCommandMessageQueue::Clear() { | 3550 void LockingCommandMessageQueue::Clear() { |
| 3556 LockGuard<Mutex> lock_guard(&mutex_); | 3551 LockGuard<Mutex> lock_guard(&mutex_); |
| 3557 queue_.Clear(); | 3552 queue_.Clear(); |
| 3558 } | 3553 } |
| 3559 | 3554 |
| 3560 } } // namespace v8::internal | 3555 } } // namespace v8::internal |
| OLD | NEW |