OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 8160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8171 if (FLAG_trace_opt) { | 8171 if (FLAG_trace_opt) { |
8172 PrintF("[failed to optimize "); | 8172 PrintF("[failed to optimize "); |
8173 function->PrintName(); | 8173 function->PrintName(); |
8174 PrintF(": optimized compilation failed]\n"); | 8174 PrintF(": optimized compilation failed]\n"); |
8175 } | 8175 } |
8176 function->ReplaceCode(function->shared()->code()); | 8176 function->ReplaceCode(function->shared()->code()); |
8177 return function->code(); | 8177 return function->code(); |
8178 } | 8178 } |
8179 | 8179 |
8180 | 8180 |
| 8181 class ActivationsFinder : public ThreadVisitor { |
| 8182 public: |
| 8183 explicit ActivationsFinder(JSFunction* function) |
| 8184 : function_(function), has_activations_(false) {} |
| 8185 |
| 8186 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { |
| 8187 if (has_activations_) return; |
| 8188 |
| 8189 for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { |
| 8190 JavaScriptFrame* frame = it.frame(); |
| 8191 if (frame->is_optimized() && frame->function() == function_) { |
| 8192 has_activations_ = true; |
| 8193 return; |
| 8194 } |
| 8195 } |
| 8196 } |
| 8197 |
| 8198 bool has_activations() { return has_activations_; } |
| 8199 |
| 8200 private: |
| 8201 JSFunction* function_; |
| 8202 bool has_activations_; |
| 8203 }; |
| 8204 |
| 8205 |
8181 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) { | 8206 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) { |
8182 HandleScope scope(isolate); | 8207 HandleScope scope(isolate); |
8183 ASSERT(args.length() == 1); | 8208 ASSERT(args.length() == 1); |
8184 RUNTIME_ASSERT(args[0]->IsSmi()); | 8209 RUNTIME_ASSERT(args[0]->IsSmi()); |
8185 Deoptimizer::BailoutType type = | 8210 Deoptimizer::BailoutType type = |
8186 static_cast<Deoptimizer::BailoutType>(args.smi_at(0)); | 8211 static_cast<Deoptimizer::BailoutType>(args.smi_at(0)); |
8187 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); | 8212 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); |
8188 ASSERT(isolate->heap()->IsAllocationAllowed()); | 8213 ASSERT(isolate->heap()->IsAllocationAllowed()); |
8189 int frames = deoptimizer->output_count(); | 8214 int frames = deoptimizer->output_count(); |
8190 | 8215 |
(...skipping 26 matching lines...) Expand all Loading... |
8217 if (type == Deoptimizer::EAGER) { | 8242 if (type == Deoptimizer::EAGER) { |
8218 RUNTIME_ASSERT(function->IsOptimized()); | 8243 RUNTIME_ASSERT(function->IsOptimized()); |
8219 } | 8244 } |
8220 | 8245 |
8221 // Avoid doing too much work when running with --always-opt and keep | 8246 // Avoid doing too much work when running with --always-opt and keep |
8222 // the optimized code around. | 8247 // the optimized code around. |
8223 if (FLAG_always_opt || type == Deoptimizer::LAZY) { | 8248 if (FLAG_always_opt || type == Deoptimizer::LAZY) { |
8224 return isolate->heap()->undefined_value(); | 8249 return isolate->heap()->undefined_value(); |
8225 } | 8250 } |
8226 | 8251 |
8227 // Count the number of optimized activations of the function. | 8252 // Find other optimized activations of the function. |
8228 int activations = 0; | 8253 bool has_other_activations = false; |
8229 while (!it.done()) { | 8254 while (!it.done()) { |
8230 JavaScriptFrame* frame = it.frame(); | 8255 JavaScriptFrame* frame = it.frame(); |
8231 if (frame->is_optimized() && frame->function() == *function) { | 8256 if (frame->is_optimized() && frame->function() == *function) { |
8232 activations++; | 8257 has_other_activations = true; |
| 8258 break; |
8233 } | 8259 } |
8234 it.Advance(); | 8260 it.Advance(); |
8235 } | 8261 } |
8236 | 8262 |
8237 if (activations == 0) { | 8263 if (!has_other_activations) { |
| 8264 ActivationsFinder activations_finder(*function); |
| 8265 isolate->thread_manager()->IterateArchivedThreads(&activations_finder); |
| 8266 has_other_activations = activations_finder.has_activations(); |
| 8267 } |
| 8268 |
| 8269 if (!has_other_activations) { |
8238 if (FLAG_trace_deopt) { | 8270 if (FLAG_trace_deopt) { |
8239 PrintF("[removing optimized code for: "); | 8271 PrintF("[removing optimized code for: "); |
8240 function->PrintName(); | 8272 function->PrintName(); |
8241 PrintF("]\n"); | 8273 PrintF("]\n"); |
8242 } | 8274 } |
8243 function->ReplaceCode(function->shared()->code()); | 8275 function->ReplaceCode(function->shared()->code()); |
8244 } else { | 8276 } else { |
8245 Deoptimizer::DeoptimizeFunction(*function); | 8277 Deoptimizer::DeoptimizeFunction(*function); |
8246 } | 8278 } |
8247 return isolate->heap()->undefined_value(); | 8279 return isolate->heap()->undefined_value(); |
(...skipping 5008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13256 } else { | 13288 } else { |
13257 // Handle last resort GC and make sure to allow future allocations | 13289 // Handle last resort GC and make sure to allow future allocations |
13258 // to grow the heap without causing GCs (if possible). | 13290 // to grow the heap without causing GCs (if possible). |
13259 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13291 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13260 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13292 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
13261 } | 13293 } |
13262 } | 13294 } |
13263 | 13295 |
13264 | 13296 |
13265 } } // namespace v8::internal | 13297 } } // namespace v8::internal |
OLD | NEW |