| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 global_handles->Destroy(function_.location()); | 100 global_handles->Destroy(function_.location()); |
| 101 function_= Handle<Object>::null(); | 101 function_= Handle<Object>::null(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 void PendingListNode::WeakCallback(v8::Persistent<v8::Value>, void* data) { | 105 void PendingListNode::WeakCallback(v8::Persistent<v8::Value>, void* data) { |
| 106 reinterpret_cast<PendingListNode*>(data)->Destroy(); | 106 reinterpret_cast<PendingListNode*>(data)->Destroy(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 static bool IsOptimizable(JSFunction* function) { | |
| 111 Code* code = function->code(); | |
| 112 return code->kind() == Code::FUNCTION && code->optimizable(); | |
| 113 } | |
| 114 | |
| 115 | |
| 116 Atomic32 RuntimeProfiler::state_ = 0; | 110 Atomic32 RuntimeProfiler::state_ = 0; |
| 117 // TODO(isolates): Create the semaphore lazily and clean it up when no | 111 // TODO(isolates): Create the semaphore lazily and clean it up when no |
| 118 // longer required. | 112 // longer required. |
| 119 #ifdef ENABLE_LOGGING_AND_PROFILING | 113 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 120 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0); | 114 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0); |
| 121 #endif | 115 #endif |
| 122 | 116 |
| 123 | 117 |
| 124 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) | 118 RuntimeProfiler::RuntimeProfiler(Isolate* isolate) |
| 125 : isolate_(isolate), | 119 : isolate_(isolate), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 137 ClearSampleBuffer(); | 131 ClearSampleBuffer(); |
| 138 } | 132 } |
| 139 | 133 |
| 140 | 134 |
| 141 bool RuntimeProfiler::IsEnabled() { | 135 bool RuntimeProfiler::IsEnabled() { |
| 142 return V8::UseCrankshaft() && FLAG_opt; | 136 return V8::UseCrankshaft() && FLAG_opt; |
| 143 } | 137 } |
| 144 | 138 |
| 145 | 139 |
| 146 void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) { | 140 void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) { |
| 147 ASSERT(IsOptimizable(function)); | 141 ASSERT(function->IsOptimizable()); |
| 148 if (FLAG_trace_opt) { | 142 if (FLAG_trace_opt) { |
| 149 PrintF("[marking (%s) ", eager ? "eagerly" : "lazily"); | 143 PrintF("[marking (%s) ", eager ? "eagerly" : "lazily"); |
| 150 function->PrintName(); | 144 function->PrintName(); |
| 151 PrintF(" for recompilation"); | 145 PrintF(" for recompilation"); |
| 152 if (delay > 0) { | 146 if (delay > 0) { |
| 153 PrintF(" (delayed %0.3f ms)", static_cast<double>(delay) / 1000); | 147 PrintF(" (delayed %0.3f ms)", static_cast<double>(delay) / 1000); |
| 154 } | 148 } |
| 155 PrintF("]\n"); | 149 PrintF("]\n"); |
| 156 } | 150 } |
| 157 | 151 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 230 |
| 237 | 231 |
| 238 void RuntimeProfiler::OptimizeNow() { | 232 void RuntimeProfiler::OptimizeNow() { |
| 239 HandleScope scope(isolate_); | 233 HandleScope scope(isolate_); |
| 240 PendingListNode* current = optimize_soon_list_; | 234 PendingListNode* current = optimize_soon_list_; |
| 241 while (current != NULL) { | 235 while (current != NULL) { |
| 242 PendingListNode* next = current->next(); | 236 PendingListNode* next = current->next(); |
| 243 if (current->IsValid()) { | 237 if (current->IsValid()) { |
| 244 Handle<JSFunction> function = current->function(); | 238 Handle<JSFunction> function = current->function(); |
| 245 int delay = current->Delay(); | 239 int delay = current->Delay(); |
| 246 if (IsOptimizable(*function)) { | 240 if (function->IsOptimizable()) { |
| 247 Optimize(*function, true, delay); | 241 Optimize(*function, true, delay); |
| 248 } | 242 } |
| 249 } | 243 } |
| 250 delete current; | 244 delete current; |
| 251 current = next; | 245 current = next; |
| 252 } | 246 } |
| 253 optimize_soon_list_ = NULL; | 247 optimize_soon_list_ = NULL; |
| 254 | 248 |
| 255 // Run through the JavaScript frames and collect them. If we already | 249 // Run through the JavaScript frames and collect them. If we already |
| 256 // have a sample of the function, we mark it for optimizations | 250 // have a sample of the function, we mark it for optimizations |
| (...skipping 24 matching lines...) Expand all Loading... |
| 281 | 275 |
| 282 if (function->IsMarkedForLazyRecompilation()) { | 276 if (function->IsMarkedForLazyRecompilation()) { |
| 283 Code* unoptimized = function->shared()->code(); | 277 Code* unoptimized = function->shared()->code(); |
| 284 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); | 278 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); |
| 285 if (nesting == 0) AttemptOnStackReplacement(function); | 279 if (nesting == 0) AttemptOnStackReplacement(function); |
| 286 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); | 280 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); |
| 287 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); | 281 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); |
| 288 } | 282 } |
| 289 | 283 |
| 290 // Do not record non-optimizable functions. | 284 // Do not record non-optimizable functions. |
| 291 if (!IsOptimizable(function)) continue; | 285 if (!function->IsOptimizable()) continue; |
| 292 samples[sample_count++] = function; | 286 samples[sample_count++] = function; |
| 293 | 287 |
| 294 int function_size = function->shared()->SourceSize(); | 288 int function_size = function->shared()->SourceSize(); |
| 295 int threshold_size_factor = (function_size > kSizeLimit) | 289 int threshold_size_factor = (function_size > kSizeLimit) |
| 296 ? sampler_threshold_size_factor_ | 290 ? sampler_threshold_size_factor_ |
| 297 : 1; | 291 : 1; |
| 298 | 292 |
| 299 int threshold = sampler_threshold_ * threshold_size_factor; | 293 int threshold = sampler_threshold_ * threshold_size_factor; |
| 300 int current_js_ratio = NoBarrier_Load(&js_ratio_); | 294 int current_js_ratio = NoBarrier_Load(&js_ratio_); |
| 301 | 295 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 321 // Add the collected functions as samples. It's important not to do | 315 // Add the collected functions as samples. It's important not to do |
| 322 // this as part of collecting them because this will interfere with | 316 // this as part of collecting them because this will interfere with |
| 323 // the sample lookup in case of recursive functions. | 317 // the sample lookup in case of recursive functions. |
| 324 for (int i = 0; i < sample_count; i++) { | 318 for (int i = 0; i < sample_count; i++) { |
| 325 AddSample(samples[i], kSamplerFrameWeight[i]); | 319 AddSample(samples[i], kSamplerFrameWeight[i]); |
| 326 } | 320 } |
| 327 } | 321 } |
| 328 | 322 |
| 329 | 323 |
| 330 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { | 324 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { |
| 331 if (!IsOptimizable(function)) return; | 325 if (!function->IsOptimizable()) return; |
| 332 PendingListNode* node = new PendingListNode(function); | 326 PendingListNode* node = new PendingListNode(function); |
| 333 node->set_next(optimize_soon_list_); | 327 node->set_next(optimize_soon_list_); |
| 334 optimize_soon_list_ = node; | 328 optimize_soon_list_ = node; |
| 335 } | 329 } |
| 336 | 330 |
| 337 | 331 |
| 338 #ifdef ENABLE_LOGGING_AND_PROFILING | 332 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 339 void RuntimeProfiler::UpdateStateRatio(SamplerState current_state) { | 333 void RuntimeProfiler::UpdateStateRatio(SamplerState current_state) { |
| 340 SamplerState old_state = state_window_[state_window_position_]; | 334 SamplerState old_state = state_window_[state_window_position_]; |
| 341 state_counts_[old_state]--; | 335 state_counts_[old_state]--; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } else { | 463 } else { |
| 470 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); | 464 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); |
| 471 } | 465 } |
| 472 } | 466 } |
| 473 #endif | 467 #endif |
| 474 return false; | 468 return false; |
| 475 } | 469 } |
| 476 | 470 |
| 477 | 471 |
| 478 } } // namespace v8::internal | 472 } } // namespace v8::internal |
| OLD | NEW |