| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 "src/deoptimizer.h" | 5 #include "src/deoptimizer.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/ast/prettyprinter.h" | 8 #include "src/ast/prettyprinter.h" |
| 9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
| 10 #include "src/disasm.h" | 10 #include "src/disasm.h" |
| 11 #include "src/frames-inl.h" | 11 #include "src/frames-inl.h" |
| 12 #include "src/full-codegen/full-codegen.h" | 12 #include "src/full-codegen/full-codegen.h" |
| 13 #include "src/global-handles.h" | 13 #include "src/global-handles.h" |
| 14 #include "src/interpreter/interpreter.h" | 14 #include "src/interpreter/interpreter.h" |
| 15 #include "src/macro-assembler.h" | 15 #include "src/macro-assembler.h" |
| 16 #include "src/profiler/cpu-profiler.h" | 16 #include "src/profiler/cpu-profiler.h" |
| 17 #include "src/tracing/trace-event.h" |
| 17 #include "src/v8.h" | 18 #include "src/v8.h" |
| 18 | 19 |
| 19 | 20 |
| 20 namespace v8 { | 21 namespace v8 { |
| 21 namespace internal { | 22 namespace internal { |
| 22 | 23 |
| 23 static MemoryChunk* AllocateCodeChunk(MemoryAllocator* allocator) { | 24 static MemoryChunk* AllocateCodeChunk(MemoryAllocator* allocator) { |
| 24 return allocator->AllocateChunk(Deoptimizer::GetMaxDeoptTableSize(), | 25 return allocator->AllocateChunk(Deoptimizer::GetMaxDeoptTableSize(), |
| 25 base::OS::CommitPageSize(), | 26 base::OS::CommitPageSize(), |
| 26 #if defined(__native_client__) | 27 #if defined(__native_client__) |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // We might be in the middle of incremental marking with compaction. | 366 // We might be in the middle of incremental marking with compaction. |
| 366 // Tell collector to treat this code object in a special way and | 367 // Tell collector to treat this code object in a special way and |
| 367 // ignore all slots that might have been recorded on it. | 368 // ignore all slots that might have been recorded on it. |
| 368 isolate->heap()->mark_compact_collector()->InvalidateCode(codes[i]); | 369 isolate->heap()->mark_compact_collector()->InvalidateCode(codes[i]); |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 | 372 |
| 372 | 373 |
| 373 void Deoptimizer::DeoptimizeAll(Isolate* isolate) { | 374 void Deoptimizer::DeoptimizeAll(Isolate* isolate) { |
| 374 TimerEventScope<TimerEventDeoptimizeCode> timer(isolate); | 375 TimerEventScope<TimerEventDeoptimizeCode> timer(isolate); |
| 376 TRACE_EVENT0("v8", "V8.DeoptimizeCode"); |
| 375 if (FLAG_trace_deopt) { | 377 if (FLAG_trace_deopt) { |
| 376 CodeTracer::Scope scope(isolate->GetCodeTracer()); | 378 CodeTracer::Scope scope(isolate->GetCodeTracer()); |
| 377 PrintF(scope.file(), "[deoptimize all code in all contexts]\n"); | 379 PrintF(scope.file(), "[deoptimize all code in all contexts]\n"); |
| 378 } | 380 } |
| 379 DisallowHeapAllocation no_allocation; | 381 DisallowHeapAllocation no_allocation; |
| 380 // For all contexts, mark all code, then deoptimize. | 382 // For all contexts, mark all code, then deoptimize. |
| 381 Object* context = isolate->heap()->native_contexts_list(); | 383 Object* context = isolate->heap()->native_contexts_list(); |
| 382 while (!context->IsUndefined()) { | 384 while (!context->IsUndefined()) { |
| 383 Context* native_context = Context::cast(context); | 385 Context* native_context = Context::cast(context); |
| 384 MarkAllCodeForContext(native_context); | 386 MarkAllCodeForContext(native_context); |
| 385 DeoptimizeMarkedCodeForContext(native_context); | 387 DeoptimizeMarkedCodeForContext(native_context); |
| 386 context = native_context->get(Context::NEXT_CONTEXT_LINK); | 388 context = native_context->get(Context::NEXT_CONTEXT_LINK); |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 | 391 |
| 390 | 392 |
| 391 void Deoptimizer::DeoptimizeMarkedCode(Isolate* isolate) { | 393 void Deoptimizer::DeoptimizeMarkedCode(Isolate* isolate) { |
| 392 TimerEventScope<TimerEventDeoptimizeCode> timer(isolate); | 394 TimerEventScope<TimerEventDeoptimizeCode> timer(isolate); |
| 395 TRACE_EVENT0("v8", "V8.DeoptimizeCode"); |
| 393 if (FLAG_trace_deopt) { | 396 if (FLAG_trace_deopt) { |
| 394 CodeTracer::Scope scope(isolate->GetCodeTracer()); | 397 CodeTracer::Scope scope(isolate->GetCodeTracer()); |
| 395 PrintF(scope.file(), "[deoptimize marked code in all contexts]\n"); | 398 PrintF(scope.file(), "[deoptimize marked code in all contexts]\n"); |
| 396 } | 399 } |
| 397 DisallowHeapAllocation no_allocation; | 400 DisallowHeapAllocation no_allocation; |
| 398 // For all contexts, deoptimize code already marked. | 401 // For all contexts, deoptimize code already marked. |
| 399 Object* context = isolate->heap()->native_contexts_list(); | 402 Object* context = isolate->heap()->native_contexts_list(); |
| 400 while (!context->IsUndefined()) { | 403 while (!context->IsUndefined()) { |
| 401 Context* native_context = Context::cast(context); | 404 Context* native_context = Context::cast(context); |
| 402 DeoptimizeMarkedCodeForContext(native_context); | 405 DeoptimizeMarkedCodeForContext(native_context); |
| 403 context = native_context->get(Context::NEXT_CONTEXT_LINK); | 406 context = native_context->get(Context::NEXT_CONTEXT_LINK); |
| 404 } | 407 } |
| 405 } | 408 } |
| 406 | 409 |
| 407 | 410 |
| 408 void Deoptimizer::MarkAllCodeForContext(Context* context) { | 411 void Deoptimizer::MarkAllCodeForContext(Context* context) { |
| 409 Object* element = context->OptimizedCodeListHead(); | 412 Object* element = context->OptimizedCodeListHead(); |
| 410 while (!element->IsUndefined()) { | 413 while (!element->IsUndefined()) { |
| 411 Code* code = Code::cast(element); | 414 Code* code = Code::cast(element); |
| 412 CHECK_EQ(code->kind(), Code::OPTIMIZED_FUNCTION); | 415 CHECK_EQ(code->kind(), Code::OPTIMIZED_FUNCTION); |
| 413 code->set_marked_for_deoptimization(true); | 416 code->set_marked_for_deoptimization(true); |
| 414 element = code->next_code_link(); | 417 element = code->next_code_link(); |
| 415 } | 418 } |
| 416 } | 419 } |
| 417 | 420 |
| 418 | 421 |
| 419 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { | 422 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
| 420 TimerEventScope<TimerEventDeoptimizeCode> timer(function->GetIsolate()); | 423 TimerEventScope<TimerEventDeoptimizeCode> timer(function->GetIsolate()); |
| 424 TRACE_EVENT0("v8", "V8.DeoptimizeCode"); |
| 421 Code* code = function->code(); | 425 Code* code = function->code(); |
| 422 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | 426 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 423 // Mark the code for deoptimization and unlink any functions that also | 427 // Mark the code for deoptimization and unlink any functions that also |
| 424 // refer to that code. The code cannot be shared across native contexts, | 428 // refer to that code. The code cannot be shared across native contexts, |
| 425 // so we only need to search one. | 429 // so we only need to search one. |
| 426 code->set_marked_for_deoptimization(true); | 430 code->set_marked_for_deoptimization(true); |
| 427 DeoptimizeMarkedCodeForContext(function->context()->native_context()); | 431 DeoptimizeMarkedCodeForContext(function->context()->native_context()); |
| 428 } | 432 } |
| 429 } | 433 } |
| 430 | 434 |
| (...skipping 3310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3741 CHECK(value_info->IsMaterializedObject()); | 3745 CHECK(value_info->IsMaterializedObject()); |
| 3742 | 3746 |
| 3743 value_info->value_ = | 3747 value_info->value_ = |
| 3744 Handle<Object>(previously_materialized_objects->get(i), isolate_); | 3748 Handle<Object>(previously_materialized_objects->get(i), isolate_); |
| 3745 } | 3749 } |
| 3746 } | 3750 } |
| 3747 } | 3751 } |
| 3748 | 3752 |
| 3749 } // namespace internal | 3753 } // namespace internal |
| 3750 } // namespace v8 | 3754 } // namespace v8 |
| OLD | NEW |