Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: src/runtime.cc

Issue 23201016: Fix deoptimization bug, where recursive call can frighten and confuse the unwitting, simple, poor c… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 JSFunction* function_;
8296 : function_(function), has_activations_(false) {} 8296 Code* code_;
8297 bool has_function_activations_;
8298 bool has_code_activations_;
8299
8300 ActivationsFinder(JSFunction* function, Code* code)
8301 : function_(function),
8302 code_(code),
8303 has_function_activations_(false),
8304 has_code_activations_(false) { }
8297 8305
8298 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { 8306 void VisitThread(Isolate* isolate, ThreadLocalTop* top) {
8299 if (has_activations_) return; 8307 JavaScriptFrameIterator it(isolate, top);
8308 VisitFrames(&it);
8309 }
8300 8310
8301 for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { 8311 void VisitFrames(JavaScriptFrameIterator* it) {
8302 JavaScriptFrame* frame = it.frame(); 8312 for (; !it->done(); it->Advance()) {
8303 if (frame->is_optimized() && frame->function() == function_) { 8313 JavaScriptFrame* frame = it->frame();
8304 has_activations_ = true; 8314 if (frame->function() == function_) has_function_activations_ = true;
Michael Starzinger 2013/08/21 16:20:28 The "has_function_activations" field seems to be u
titzer 2013/08/21 16:26:29 Correct, twers for debuggin'
8305 return; 8315 if (code_->contains(frame->pc())) has_code_activations_ = true;
8306 }
8307 } 8316 }
8308 } 8317 }
8309
8310 bool has_activations() { return has_activations_; }
8311
8312 private:
8313 JSFunction* function_;
8314 bool has_activations_;
8315 }; 8318 };
8316 8319
8317 8320
8318 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyStubFailure) { 8321 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyStubFailure) {
8319 HandleScope scope(isolate); 8322 HandleScope scope(isolate);
8320 ASSERT(args.length() == 0); 8323 ASSERT(args.length() == 0);
8321 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); 8324 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
8322 ASSERT(AllowHeapAllocation::IsAllowed()); 8325 ASSERT(AllowHeapAllocation::IsAllowed());
8323 delete deoptimizer; 8326 delete deoptimizer;
8324 return isolate->heap()->undefined_value(); 8327 return isolate->heap()->undefined_value();
8325 } 8328 }
8326 8329
8327 8330
8328 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) { 8331 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) {
8329 HandleScope scope(isolate); 8332 HandleScope scope(isolate);
8330 ASSERT(args.length() == 1); 8333 ASSERT(args.length() == 1);
8331 RUNTIME_ASSERT(args[0]->IsSmi()); 8334 RUNTIME_ASSERT(args[0]->IsSmi());
8332 Deoptimizer::BailoutType type = 8335 Deoptimizer::BailoutType type =
8333 static_cast<Deoptimizer::BailoutType>(args.smi_at(0)); 8336 static_cast<Deoptimizer::BailoutType>(args.smi_at(0));
8334 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); 8337 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
8335 ASSERT(AllowHeapAllocation::IsAllowed()); 8338 ASSERT(AllowHeapAllocation::IsAllowed());
8336 8339
8337 ASSERT(deoptimizer->compiled_code_kind() == Code::OPTIMIZED_FUNCTION); 8340 Handle<JSFunction> function(deoptimizer->function());
8341 Handle<Code> optimized_code(deoptimizer->compiled_code());
Toon Verwaest 2013/08/21 15:33:17 Could we also rename compiled_code() in the deopti
Michael Starzinger 2013/08/21 16:20:28 nit: Use an assignment instead of the copy constru
titzer 2013/08/21 16:20:48 Will have to do that rename in a later CL; wanted
titzer 2013/08/21 16:26:29 Done.
8342
8343 ASSERT(optimized_code->kind() == Code::OPTIMIZED_FUNCTION);
8344 ASSERT(type == deoptimizer->bailout_type());
8338 8345
8339 // Make sure to materialize objects before causing any allocation. 8346 // Make sure to materialize objects before causing any allocation.
8340 JavaScriptFrameIterator it(isolate); 8347 JavaScriptFrameIterator it(isolate);
8341 deoptimizer->MaterializeHeapObjects(&it); 8348 deoptimizer->MaterializeHeapObjects(&it);
8342 delete deoptimizer; 8349 delete deoptimizer;
8343 8350
8344 JavaScriptFrame* frame = it.frame(); 8351 JavaScriptFrame* frame = it.frame();
8345 RUNTIME_ASSERT(frame->function()->IsJSFunction()); 8352 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 8353
8351 // Avoid doing too much work when running with --always-opt and keep 8354 // Avoid doing too much work when running with --always-opt and keep
8352 // the optimized code around. 8355 // the optimized code around.
8353 if (FLAG_always_opt || type == Deoptimizer::LAZY) { 8356 if (FLAG_always_opt || type == Deoptimizer::LAZY) {
8354 return isolate->heap()->undefined_value(); 8357 return isolate->heap()->undefined_value();
8355 } 8358 }
8356 8359
8357 // Find other optimized activations of the function or functions that 8360 // TODO(titzer): in the case of SOFT or EAGER deopt, we may want to allow
8358 // share the same optimized code. 8361 // the code to be reused a few times before unlinking it from the function.
Toon Verwaest 2013/08/21 15:33:17 I'm not fully sure how this would work yet. Is it
titzer 2013/08/21 16:20:48 Removed.
8359 bool has_other_activations = false;
8360 while (!it.done()) {
8361 JavaScriptFrame* frame = it.frame();
8362 JSFunction* other_function = frame->function();
8363 if (frame->is_optimized() && other_function->code() == function->code()) {
8364 has_other_activations = true;
8365 break;
8366 }
8367 it.Advance();
8368 }
8369 8362
8370 if (!has_other_activations) { 8363 // Search for other activations of the same function and code.
8371 ActivationsFinder activations_finder(*function); 8364 ActivationsFinder activations_finder(*function, *optimized_code);
8372 isolate->thread_manager()->IterateArchivedThreads(&activations_finder); 8365 activations_finder.VisitFrames(&it);
8373 has_other_activations = activations_finder.has_activations(); 8366 isolate->thread_manager()->IterateArchivedThreads(&activations_finder);
8374 }
8375 8367
8376 if (!has_other_activations) { 8368 if (!activations_finder.has_code_activations_) {
8377 if (FLAG_trace_deopt) { 8369 if (FLAG_trace_deopt) {
8378 PrintF("[removing optimized code for: "); 8370 PrintF("[removing optimized code for: ");
8379 function->PrintName(); 8371 function->PrintName();
8380 PrintF("]\n"); 8372 PrintF("]\n");
8381 } 8373 }
8382 function->ReplaceCode(function->shared()->code()); 8374 if (function->code() == *optimized_code) {
8375 function->ReplaceCode(function->shared()->code());
8376 }
8383 } else { 8377 } else {
8378 // TODO(titzer): we should probably do DeoptimizeCodeList(code)
8379 // unconditionally if the code is not already marked for deoptimization.
8380 // If there is an index by shared function info, all the better.
8384 Deoptimizer::DeoptimizeFunction(*function); 8381 Deoptimizer::DeoptimizeFunction(*function);
8385 } 8382 }
Toon Verwaest 2013/08/21 15:33:17 Can't we just unconditionally do Deoptimizer::Deo
8386 // Evict optimized code for this function from the cache so that it doesn't 8383 // Evict optimized code for this function from the cache so that it doesn't
8387 // get used for new closures. 8384 // get used for new closures.
8388 function->shared()->EvictFromOptimizedCodeMap(*optimized_code, 8385 function->shared()->EvictFromOptimizedCodeMap(*optimized_code,
8389 "notify deoptimized"); 8386 "notify deoptimized");
8390 8387
8391 return isolate->heap()->undefined_value(); 8388 return isolate->heap()->undefined_value();
8392 } 8389 }
8393 8390
8394 8391
8395 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyOSR) { 8392 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyOSR) {
(...skipping 6245 matching lines...) Expand 10 before | Expand all | Expand 10 after
14641 // Handle last resort GC and make sure to allow future allocations 14638 // Handle last resort GC and make sure to allow future allocations
14642 // to grow the heap without causing GCs (if possible). 14639 // to grow the heap without causing GCs (if possible).
14643 isolate->counters()->gc_last_resort_from_js()->Increment(); 14640 isolate->counters()->gc_last_resort_from_js()->Increment();
14644 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14641 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14645 "Runtime::PerformGC"); 14642 "Runtime::PerformGC");
14646 } 14643 }
14647 } 14644 }
14648 14645
14649 14646
14650 } } // namespace v8::internal 14647 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698