| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 265 } |
| 266 delete current; | 266 delete current; |
| 267 current = next; | 267 current = next; |
| 268 } | 268 } |
| 269 optimize_soon_list = NULL; | 269 optimize_soon_list = NULL; |
| 270 | 270 |
| 271 // Run through the JavaScript frames and collect them. If we already | 271 // Run through the JavaScript frames and collect them. If we already |
| 272 // have a sample of the function, we mark it for optimizations | 272 // have a sample of the function, we mark it for optimizations |
| 273 // (eagerly or lazily). | 273 // (eagerly or lazily). |
| 274 JSFunction* samples[kSamplerFrameCount]; | 274 JSFunction* samples[kSamplerFrameCount]; |
| 275 int count = 0; | 275 int sample_count = 0; |
| 276 int frame_count = 0; |
| 276 for (JavaScriptFrameIterator it; | 277 for (JavaScriptFrameIterator it; |
| 277 count < kSamplerFrameCount && !it.done(); | 278 frame_count++ < kSamplerFrameCount && !it.done(); |
| 278 it.Advance()) { | 279 it.Advance()) { |
| 279 JavaScriptFrame* frame = it.frame(); | 280 JavaScriptFrame* frame = it.frame(); |
| 280 JSFunction* function = JSFunction::cast(frame->function()); | 281 JSFunction* function = JSFunction::cast(frame->function()); |
| 281 | 282 |
| 282 // Adjust threshold each time we have processed | 283 // Adjust threshold each time we have processed |
| 283 // a certain number of ticks. | 284 // a certain number of ticks. |
| 284 if (sampler_ticks_until_threshold_adjustment > 0) { | 285 if (sampler_ticks_until_threshold_adjustment > 0) { |
| 285 sampler_ticks_until_threshold_adjustment--; | 286 sampler_ticks_until_threshold_adjustment--; |
| 286 if (sampler_ticks_until_threshold_adjustment <= 0) { | 287 if (sampler_ticks_until_threshold_adjustment <= 0) { |
| 287 // If the threshold is not already at the minimum | 288 // If the threshold is not already at the minimum |
| 288 // modify and reset the ticks until next adjustment. | 289 // modify and reset the ticks until next adjustment. |
| 289 if (sampler_threshold > kSamplerThresholdMin) { | 290 if (sampler_threshold > kSamplerThresholdMin) { |
| 290 sampler_threshold -= kSamplerThresholdDelta; | 291 sampler_threshold -= kSamplerThresholdDelta; |
| 291 sampler_ticks_until_threshold_adjustment = | 292 sampler_ticks_until_threshold_adjustment = |
| 292 kSamplerTicksBetweenThresholdAdjustment; | 293 kSamplerTicksBetweenThresholdAdjustment; |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 if (function->IsMarkedForLazyRecompilation()) { | 298 if (function->IsMarkedForLazyRecompilation()) { |
| 298 Code* unoptimized = function->shared()->code(); | 299 Code* unoptimized = function->shared()->code(); |
| 299 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); | 300 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); |
| 300 if (nesting == 0) AttemptOnStackReplacement(function); | 301 if (nesting == 0) AttemptOnStackReplacement(function); |
| 301 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); | 302 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); |
| 302 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); | 303 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); |
| 303 } | 304 } |
| 304 | 305 |
| 305 // Do not record non-optimizable functions. | 306 // Do not record non-optimizable functions. |
| 306 if (!IsOptimizable(function)) continue; | 307 if (!IsOptimizable(function)) continue; |
| 307 samples[count++] = function; | 308 samples[sample_count++] = function; |
| 308 | 309 |
| 309 int function_size = function->shared()->SourceSize(); | 310 int function_size = function->shared()->SourceSize(); |
| 310 int threshold_size_factor = (function_size > kSizeLimit) | 311 int threshold_size_factor = (function_size > kSizeLimit) |
| 311 ? sampler_threshold_size_factor | 312 ? sampler_threshold_size_factor |
| 312 : 1; | 313 : 1; |
| 313 | 314 |
| 314 int threshold = sampler_threshold * threshold_size_factor; | 315 int threshold = sampler_threshold * threshold_size_factor; |
| 315 int current_js_ratio = NoBarrier_Load(&js_ratio); | 316 int current_js_ratio = NoBarrier_Load(&js_ratio); |
| 316 | 317 |
| 317 // Adjust threshold depending on the ratio of time spent | 318 // Adjust threshold depending on the ratio of time spent |
| (...skipping 10 matching lines...) Expand all Loading... |
| 328 | 329 |
| 329 if (LookupSample(function) >= threshold) { | 330 if (LookupSample(function) >= threshold) { |
| 330 Optimize(function, false, 0); | 331 Optimize(function, false, 0); |
| 331 CompilationCache::MarkForEagerOptimizing(Handle<JSFunction>(function)); | 332 CompilationCache::MarkForEagerOptimizing(Handle<JSFunction>(function)); |
| 332 } | 333 } |
| 333 } | 334 } |
| 334 | 335 |
| 335 // Add the collected functions as samples. It's important not to do | 336 // Add the collected functions as samples. It's important not to do |
| 336 // this as part of collecting them because this will interfere with | 337 // this as part of collecting them because this will interfere with |
| 337 // the sample lookup in case of recursive functions. | 338 // the sample lookup in case of recursive functions. |
| 338 for (int i = 0; i < count; i++) { | 339 for (int i = 0; i < sample_count; i++) { |
| 339 AddSample(samples[i], kSamplerFrameWeight[i]); | 340 AddSample(samples[i], kSamplerFrameWeight[i]); |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 | 343 |
| 343 | 344 |
| 344 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { | 345 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { |
| 345 if (!IsOptimizable(function)) return; | 346 if (!IsOptimizable(function)) return; |
| 346 PendingListNode* node = new PendingListNode(function); | 347 PendingListNode* node = new PendingListNode(function); |
| 347 node->set_next(optimize_soon_list); | 348 node->set_next(optimize_soon_list); |
| 348 optimize_soon_list = node; | 349 optimize_soon_list = node; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } else { | 440 } else { |
| 440 if (Top::WaitForJSState()) return true; | 441 if (Top::WaitForJSState()) return true; |
| 441 } | 442 } |
| 442 } | 443 } |
| 443 } | 444 } |
| 444 return false; | 445 return false; |
| 445 } | 446 } |
| 446 | 447 |
| 447 | 448 |
| 448 } } // namespace v8::internal | 449 } } // namespace v8::internal |
| OLD | NEW |