| 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 13 matching lines...) Expand all Loading... |
| 139 ClearSampleBuffer(); | 133 ClearSampleBuffer(); |
| 140 } | 134 } |
| 141 | 135 |
| 142 | 136 |
| 143 bool RuntimeProfiler::IsEnabled() { | 137 bool RuntimeProfiler::IsEnabled() { |
| 144 return V8::UseCrankshaft() && FLAG_opt; | 138 return V8::UseCrankshaft() && FLAG_opt; |
| 145 } | 139 } |
| 146 | 140 |
| 147 | 141 |
| 148 void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) { | 142 void RuntimeProfiler::Optimize(JSFunction* function, bool eager, int delay) { |
| 149 ASSERT(IsOptimizable(function)); | 143 ASSERT(function->IsOptimizable()); |
| 150 if (FLAG_trace_opt) { | 144 if (FLAG_trace_opt) { |
| 151 PrintF("[marking (%s) ", eager ? "eagerly" : "lazily"); | 145 PrintF("[marking (%s) ", eager ? "eagerly" : "lazily"); |
| 152 function->PrintName(); | 146 function->PrintName(); |
| 153 PrintF(" for recompilation"); | 147 PrintF(" for recompilation"); |
| 154 if (delay > 0) { | 148 if (delay > 0) { |
| 155 PrintF(" (delayed %0.3f ms)", static_cast<double>(delay) / 1000); | 149 PrintF(" (delayed %0.3f ms)", static_cast<double>(delay) / 1000); |
| 156 } | 150 } |
| 157 PrintF("]\n"); | 151 PrintF("]\n"); |
| 158 } | 152 } |
| 159 | 153 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 232 |
| 239 | 233 |
| 240 void RuntimeProfiler::OptimizeNow() { | 234 void RuntimeProfiler::OptimizeNow() { |
| 241 HandleScope scope(isolate_); | 235 HandleScope scope(isolate_); |
| 242 PendingListNode* current = optimize_soon_list_; | 236 PendingListNode* current = optimize_soon_list_; |
| 243 while (current != NULL) { | 237 while (current != NULL) { |
| 244 PendingListNode* next = current->next(); | 238 PendingListNode* next = current->next(); |
| 245 if (current->IsValid()) { | 239 if (current->IsValid()) { |
| 246 Handle<JSFunction> function = current->function(); | 240 Handle<JSFunction> function = current->function(); |
| 247 int delay = current->Delay(); | 241 int delay = current->Delay(); |
| 248 if (IsOptimizable(*function)) { | 242 if (function->IsOptimizable()) { |
| 249 Optimize(*function, true, delay); | 243 Optimize(*function, true, delay); |
| 250 } | 244 } |
| 251 } | 245 } |
| 252 delete current; | 246 delete current; |
| 253 current = next; | 247 current = next; |
| 254 } | 248 } |
| 255 optimize_soon_list_ = NULL; | 249 optimize_soon_list_ = NULL; |
| 256 | 250 |
| 257 // Run through the JavaScript frames and collect them. If we already | 251 // Run through the JavaScript frames and collect them. If we already |
| 258 // have a sample of the function, we mark it for optimizations | 252 // have a sample of the function, we mark it for optimizations |
| (...skipping 24 matching lines...) Expand all Loading... |
| 283 | 277 |
| 284 if (function->IsMarkedForLazyRecompilation()) { | 278 if (function->IsMarkedForLazyRecompilation()) { |
| 285 Code* unoptimized = function->shared()->code(); | 279 Code* unoptimized = function->shared()->code(); |
| 286 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); | 280 int nesting = unoptimized->allow_osr_at_loop_nesting_level(); |
| 287 if (nesting == 0) AttemptOnStackReplacement(function); | 281 if (nesting == 0) AttemptOnStackReplacement(function); |
| 288 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); | 282 int new_nesting = Min(nesting + 1, Code::kMaxLoopNestingMarker); |
| 289 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); | 283 unoptimized->set_allow_osr_at_loop_nesting_level(new_nesting); |
| 290 } | 284 } |
| 291 | 285 |
| 292 // Do not record non-optimizable functions. | 286 // Do not record non-optimizable functions. |
| 293 if (!IsOptimizable(function)) continue; | 287 if (!function->IsOptimizable()) continue; |
| 294 samples[sample_count++] = function; | 288 samples[sample_count++] = function; |
| 295 | 289 |
| 296 int function_size = function->shared()->SourceSize(); | 290 int function_size = function->shared()->SourceSize(); |
| 297 int threshold_size_factor = (function_size > kSizeLimit) | 291 int threshold_size_factor = (function_size > kSizeLimit) |
| 298 ? sampler_threshold_size_factor_ | 292 ? sampler_threshold_size_factor_ |
| 299 : 1; | 293 : 1; |
| 300 | 294 |
| 301 int threshold = sampler_threshold_ * threshold_size_factor; | 295 int threshold = sampler_threshold_ * threshold_size_factor; |
| 302 int current_js_ratio = NoBarrier_Load(&js_ratio_); | 296 int current_js_ratio = NoBarrier_Load(&js_ratio_); |
| 303 | 297 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 // Add the collected functions as samples. It's important not to do | 317 // Add the collected functions as samples. It's important not to do |
| 324 // this as part of collecting them because this will interfere with | 318 // this as part of collecting them because this will interfere with |
| 325 // the sample lookup in case of recursive functions. | 319 // the sample lookup in case of recursive functions. |
| 326 for (int i = 0; i < sample_count; i++) { | 320 for (int i = 0; i < sample_count; i++) { |
| 327 AddSample(samples[i], kSamplerFrameWeight[i]); | 321 AddSample(samples[i], kSamplerFrameWeight[i]); |
| 328 } | 322 } |
| 329 } | 323 } |
| 330 | 324 |
| 331 | 325 |
| 332 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { | 326 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { |
| 333 if (!IsOptimizable(function)) return; | 327 if (!function->IsOptimizable()) return; |
| 334 PendingListNode* node = new PendingListNode(function); | 328 PendingListNode* node = new PendingListNode(function); |
| 335 node->set_next(optimize_soon_list_); | 329 node->set_next(optimize_soon_list_); |
| 336 optimize_soon_list_ = node; | 330 optimize_soon_list_ = node; |
| 337 } | 331 } |
| 338 | 332 |
| 339 | 333 |
| 340 #ifdef ENABLE_LOGGING_AND_PROFILING | 334 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 341 void RuntimeProfiler::UpdateStateRatio(SamplerState current_state) { | 335 void RuntimeProfiler::UpdateStateRatio(SamplerState current_state) { |
| 342 SamplerState old_state = state_window_[state_window_position_]; | 336 SamplerState old_state = state_window_[state_window_position_]; |
| 343 state_counts_[old_state]--; | 337 state_counts_[old_state]--; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } else { | 469 } else { |
| 476 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); | 470 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); |
| 477 } | 471 } |
| 478 } | 472 } |
| 479 #endif | 473 #endif |
| 480 return false; | 474 return false; |
| 481 } | 475 } |
| 482 | 476 |
| 483 | 477 |
| 484 } } // namespace v8::internal | 478 } } // namespace v8::internal |
| OLD | NEW |