| 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 8274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8285 ASSERT(args.length() == 1); | 8285 ASSERT(args.length() == 1); |
| 8286 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8286 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 8287 ASSERT(V8::UseCrankshaft() && FLAG_parallel_recompilation); | 8287 ASSERT(V8::UseCrankshaft() && FLAG_parallel_recompilation); |
| 8288 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions(); | 8288 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions(); |
| 8289 return function->code(); | 8289 return function->code(); |
| 8290 } | 8290 } |
| 8291 | 8291 |
| 8292 | 8292 |
| 8293 class ActivationsFinder : public ThreadVisitor { | 8293 class ActivationsFinder : public ThreadVisitor { |
| 8294 public: | 8294 public: |
| 8295 explicit ActivationsFinder(JSFunction* function) | 8295 Code* code_; |
| 8296 : function_(function), has_activations_(false) {} | 8296 bool has_code_activations_; |
| 8297 |
| 8298 explicit ActivationsFinder(Code* code) |
| 8299 : code_(code), |
| 8300 has_code_activations_(false) { } |
| 8297 | 8301 |
| 8298 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { | 8302 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { |
| 8299 if (has_activations_) return; | 8303 JavaScriptFrameIterator it(isolate, top); |
| 8304 VisitFrames(&it); |
| 8305 } |
| 8300 | 8306 |
| 8301 for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { | 8307 void VisitFrames(JavaScriptFrameIterator* it) { |
| 8302 JavaScriptFrame* frame = it.frame(); | 8308 for (; !it->done(); it->Advance()) { |
| 8303 if (frame->is_optimized() && frame->function() == function_) { | 8309 JavaScriptFrame* frame = it->frame(); |
| 8304 has_activations_ = true; | 8310 if (code_->contains(frame->pc())) has_code_activations_ = true; |
| 8305 return; | |
| 8306 } | |
| 8307 } | 8311 } |
| 8308 } | 8312 } |
| 8309 | |
| 8310 bool has_activations() { return has_activations_; } | |
| 8311 | |
| 8312 private: | |
| 8313 JSFunction* function_; | |
| 8314 bool has_activations_; | |
| 8315 }; | 8313 }; |
| 8316 | 8314 |
| 8317 | 8315 |
| 8318 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyStubFailure) { | 8316 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyStubFailure) { |
| 8319 HandleScope scope(isolate); | 8317 HandleScope scope(isolate); |
| 8320 ASSERT(args.length() == 0); | 8318 ASSERT(args.length() == 0); |
| 8321 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); | 8319 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); |
| 8322 ASSERT(AllowHeapAllocation::IsAllowed()); | 8320 ASSERT(AllowHeapAllocation::IsAllowed()); |
| 8323 delete deoptimizer; | 8321 delete deoptimizer; |
| 8324 return isolate->heap()->undefined_value(); | 8322 return isolate->heap()->undefined_value(); |
| 8325 } | 8323 } |
| 8326 | 8324 |
| 8327 | 8325 |
| 8328 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) { | 8326 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) { |
| 8329 HandleScope scope(isolate); | 8327 HandleScope scope(isolate); |
| 8330 ASSERT(args.length() == 1); | 8328 ASSERT(args.length() == 1); |
| 8331 RUNTIME_ASSERT(args[0]->IsSmi()); | 8329 RUNTIME_ASSERT(args[0]->IsSmi()); |
| 8332 Deoptimizer::BailoutType type = | 8330 Deoptimizer::BailoutType type = |
| 8333 static_cast<Deoptimizer::BailoutType>(args.smi_at(0)); | 8331 static_cast<Deoptimizer::BailoutType>(args.smi_at(0)); |
| 8334 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); | 8332 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); |
| 8335 ASSERT(AllowHeapAllocation::IsAllowed()); | 8333 ASSERT(AllowHeapAllocation::IsAllowed()); |
| 8336 | 8334 |
| 8337 ASSERT(deoptimizer->compiled_code_kind() == Code::OPTIMIZED_FUNCTION); | 8335 Handle<JSFunction> function = deoptimizer->function(); |
| 8336 Handle<Code> optimized_code = deoptimizer->compiled_code(); |
| 8337 |
| 8338 ASSERT(optimized_code->kind() == Code::OPTIMIZED_FUNCTION); |
| 8339 ASSERT(type == deoptimizer->bailout_type()); |
| 8338 | 8340 |
| 8339 // Make sure to materialize objects before causing any allocation. | 8341 // Make sure to materialize objects before causing any allocation. |
| 8340 JavaScriptFrameIterator it(isolate); | 8342 JavaScriptFrameIterator it(isolate); |
| 8341 deoptimizer->MaterializeHeapObjects(&it); | 8343 deoptimizer->MaterializeHeapObjects(&it); |
| 8342 delete deoptimizer; | 8344 delete deoptimizer; |
| 8343 | 8345 |
| 8344 JavaScriptFrame* frame = it.frame(); | 8346 JavaScriptFrame* frame = it.frame(); |
| 8345 RUNTIME_ASSERT(frame->function()->IsJSFunction()); | 8347 RUNTIME_ASSERT(frame->function()->IsJSFunction()); |
| 8346 Handle<JSFunction> function(frame->function(), isolate); | |
| 8347 Handle<Code> optimized_code(function->code()); | |
| 8348 RUNTIME_ASSERT((type != Deoptimizer::EAGER && | |
| 8349 type != Deoptimizer::SOFT) || function->IsOptimized()); | |
| 8350 | 8348 |
| 8351 // Avoid doing too much work when running with --always-opt and keep | 8349 // Avoid doing too much work when running with --always-opt and keep |
| 8352 // the optimized code around. | 8350 // the optimized code around. |
| 8353 if (FLAG_always_opt || type == Deoptimizer::LAZY) { | 8351 if (FLAG_always_opt || type == Deoptimizer::LAZY) { |
| 8354 return isolate->heap()->undefined_value(); | 8352 return isolate->heap()->undefined_value(); |
| 8355 } | 8353 } |
| 8356 | 8354 |
| 8357 // Find other optimized activations of the function or functions that | 8355 // Search for other activations of the same function and code. |
| 8358 // share the same optimized code. | 8356 ActivationsFinder activations_finder(*optimized_code); |
| 8359 bool has_other_activations = false; | 8357 activations_finder.VisitFrames(&it); |
| 8360 while (!it.done()) { | 8358 isolate->thread_manager()->IterateArchivedThreads(&activations_finder); |
| 8361 JavaScriptFrame* frame = it.frame(); | 8359 |
| 8362 JSFunction* other_function = frame->function(); | 8360 if (!activations_finder.has_code_activations_) { |
| 8363 if (frame->is_optimized() && other_function->code() == function->code()) { | 8361 if (function->code() == *optimized_code) { |
| 8364 has_other_activations = true; | 8362 if (FLAG_trace_deopt) { |
| 8365 break; | 8363 PrintF("[removing optimized code for: "); |
| 8364 function->PrintName(); |
| 8365 PrintF("]\n"); |
| 8366 } |
| 8367 function->ReplaceCode(function->shared()->code()); |
| 8366 } | 8368 } |
| 8367 it.Advance(); | |
| 8368 } | |
| 8369 | |
| 8370 if (!has_other_activations) { | |
| 8371 ActivationsFinder activations_finder(*function); | |
| 8372 isolate->thread_manager()->IterateArchivedThreads(&activations_finder); | |
| 8373 has_other_activations = activations_finder.has_activations(); | |
| 8374 } | |
| 8375 | |
| 8376 if (!has_other_activations) { | |
| 8377 if (FLAG_trace_deopt) { | |
| 8378 PrintF("[removing optimized code for: "); | |
| 8379 function->PrintName(); | |
| 8380 PrintF("]\n"); | |
| 8381 } | |
| 8382 function->ReplaceCode(function->shared()->code()); | |
| 8383 } else { | 8369 } else { |
| 8370 // TODO(titzer): we should probably do DeoptimizeCodeList(code) |
| 8371 // unconditionally if the code is not already marked for deoptimization. |
| 8372 // If there is an index by shared function info, all the better. |
| 8384 Deoptimizer::DeoptimizeFunction(*function); | 8373 Deoptimizer::DeoptimizeFunction(*function); |
| 8385 } | 8374 } |
| 8386 // Evict optimized code for this function from the cache so that it doesn't | 8375 // Evict optimized code for this function from the cache so that it doesn't |
| 8387 // get used for new closures. | 8376 // get used for new closures. |
| 8388 function->shared()->EvictFromOptimizedCodeMap(*optimized_code, | 8377 function->shared()->EvictFromOptimizedCodeMap(*optimized_code, |
| 8389 "notify deoptimized"); | 8378 "notify deoptimized"); |
| 8390 | 8379 |
| 8391 return isolate->heap()->undefined_value(); | 8380 return isolate->heap()->undefined_value(); |
| 8392 } | 8381 } |
| 8393 | 8382 |
| (...skipping 6247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14641 // Handle last resort GC and make sure to allow future allocations | 14630 // Handle last resort GC and make sure to allow future allocations |
| 14642 // to grow the heap without causing GCs (if possible). | 14631 // to grow the heap without causing GCs (if possible). |
| 14643 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14632 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14644 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14633 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14645 "Runtime::PerformGC"); | 14634 "Runtime::PerformGC"); |
| 14646 } | 14635 } |
| 14647 } | 14636 } |
| 14648 | 14637 |
| 14649 | 14638 |
| 14650 } } // namespace v8::internal | 14639 } } // namespace v8::internal |
| OLD | NEW |