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); | |
2052 | 2051 |
2053 // Ensure no GC in this scope as we are going to use gc_metadata | 2052 // Ensure no GC in this scope as we are going to use gc_metadata |
2054 // field in the Code object to mark active functions. | 2053 // field in the Code object to mark active functions. |
2055 DisallowHeapAllocation no_allocation; | 2054 DisallowHeapAllocation no_allocation; |
2056 | 2055 |
2057 Object* active_code_marker = heap->the_hole_value(); | 2056 Object* active_code_marker = heap->the_hole_value(); |
2058 | 2057 |
2059 CollectActiveFunctionsFromThread(isolate_, | 2058 CollectActiveFunctionsFromThread(isolate_, |
2060 isolate_->thread_local_top(), | 2059 isolate_->thread_local_top(), |
2061 &active_functions, | 2060 &active_functions, |
2062 active_code_marker); | 2061 active_code_marker); |
2063 ActiveFunctionsCollector active_functions_collector(&active_functions, | 2062 ActiveFunctionsCollector active_functions_collector(&active_functions, |
2064 active_code_marker); | 2063 active_code_marker); |
2065 isolate_->thread_manager()->IterateArchivedThreads( | 2064 isolate_->thread_manager()->IterateArchivedThreads( |
2066 &active_functions_collector); | 2065 &active_functions_collector); |
2067 | 2066 |
2068 // Scan the heap for all non-optimized functions which have no | 2067 // Scan the heap for all non-optimized functions which have no |
2069 // debug break slots and are not active or inlined into an active | 2068 // debug break slots and are not active or inlined into an active |
2070 // function and mark them for lazy compilation. | 2069 // 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. | 2195 { // Extra scope for iterator and no-allocation. |
| 2196 heap->EnsureHeapIsIterable(); |
| 2197 DisallowHeapAllocation no_alloc_during_heap_iteration; |
2196 HeapIterator iterator(heap); | 2198 HeapIterator iterator(heap); |
2197 for (HeapObject* obj = iterator.next(); | 2199 for (HeapObject* obj = iterator.next(); |
2198 obj != NULL; obj = iterator.next()) { | 2200 obj != NULL; obj = iterator.next()) { |
2199 bool found_next_candidate = false; | 2201 bool found_next_candidate = false; |
2200 Handle<JSFunction> function; | 2202 Handle<JSFunction> function; |
2201 Handle<SharedFunctionInfo> shared; | 2203 Handle<SharedFunctionInfo> shared; |
2202 if (obj->IsJSFunction()) { | 2204 if (obj->IsJSFunction()) { |
2203 function = Handle<JSFunction>(JSFunction::cast(obj)); | 2205 function = Handle<JSFunction>(JSFunction::cast(obj)); |
2204 shared = Handle<SharedFunctionInfo>(function->shared()); | 2206 shared = Handle<SharedFunctionInfo>(function->shared()); |
2205 ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); | 2207 ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 | 2517 |
2516 void Debug::CreateScriptCache() { | 2518 void Debug::CreateScriptCache() { |
2517 Heap* heap = isolate_->heap(); | 2519 Heap* heap = isolate_->heap(); |
2518 HandleScope scope(isolate_); | 2520 HandleScope scope(isolate_); |
2519 | 2521 |
2520 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | 2522 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
2521 // rid of all the cached script wrappers and the second gets rid of the | 2523 // rid of all the cached script wrappers and the second gets rid of the |
2522 // scripts which are no longer referenced. The second also sweeps precisely, | 2524 // scripts which are no longer referenced. The second also sweeps precisely, |
2523 // which saves us doing yet another GC to make the heap iterable. | 2525 // which saves us doing yet another GC to make the heap iterable. |
2524 heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); | 2526 heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); |
| 2527 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 2528 "Debug::CreateScriptCache"); |
2525 | 2529 |
2526 ASSERT(script_cache_ == NULL); | 2530 ASSERT(script_cache_ == NULL); |
2527 script_cache_ = new ScriptCache(isolate_); | 2531 script_cache_ = new ScriptCache(isolate_); |
2528 | 2532 |
2529 // Scan heap for Script objects. | 2533 // Scan heap for Script objects. |
2530 int count = 0; | 2534 int count = 0; |
2531 HeapIterator iterator(heap); | 2535 HeapIterator iterator(heap); |
| 2536 DisallowHeapAllocation no_allocation; |
2532 | 2537 |
2533 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2538 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
2534 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { | 2539 if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { |
2535 script_cache_->Add(Handle<Script>(Script::cast(obj))); | 2540 script_cache_->Add(Handle<Script>(Script::cast(obj))); |
2536 count++; | 2541 count++; |
2537 } | 2542 } |
2538 } | 2543 } |
2539 } | 2544 } |
2540 | 2545 |
2541 | 2546 |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3546 logger_->DebugEvent("Put", message.text()); | 3551 logger_->DebugEvent("Put", message.text()); |
3547 } | 3552 } |
3548 | 3553 |
3549 | 3554 |
3550 void LockingCommandMessageQueue::Clear() { | 3555 void LockingCommandMessageQueue::Clear() { |
3551 LockGuard<Mutex> lock_guard(&mutex_); | 3556 LockGuard<Mutex> lock_guard(&mutex_); |
3552 queue_.Clear(); | 3557 queue_.Clear(); |
3553 } | 3558 } |
3554 | 3559 |
3555 } } // namespace v8::internal | 3560 } } // namespace v8::internal |
OLD | NEW |