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

Side by Side Diff: src/runtime-profiler.cc

Issue 5720003: Fix bug that disabled optimization when profiling. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 344
345 void RuntimeProfiler::OptimizeSoon(JSFunction* function) { 345 void RuntimeProfiler::OptimizeSoon(JSFunction* function) {
346 if (!IsOptimizable(function)) return; 346 if (!IsOptimizable(function)) return;
347 PendingListNode* node = new PendingListNode(function); 347 PendingListNode* node = new PendingListNode(function);
348 node->set_next(optimize_soon_list); 348 node->set_next(optimize_soon_list);
349 optimize_soon_list = node; 349 optimize_soon_list = node;
350 } 350 }
351 351
352 352
353 static void AddStateSample(SamplerState current_state) {
Vitaly Repeshko 2010/12/10 14:40:40 Rename to "UpdateStateRatio"?
Karl Klose 2010/12/10 14:45:06 Done.
354 static const int kStateWindowSize = 128;
355 static SamplerState state_window[kStateWindowSize];
356 static int state_window_position = 0;
357 static int state_counts[2] = { kStateWindowSize, 0 };
358
359 SamplerState old_state = state_window[state_window_position];
360 state_counts[old_state]--;
361 state_window[state_window_position] = current_state;
362 state_counts[current_state]++;
363 ASSERT(IsPowerOf2(kStateWindowSize));
364 state_window_position = (state_window_position + 1) &
365 (kStateWindowSize - 1);
366 NoBarrier_Store(&js_ratio, state_counts[IN_JS_STATE] * 100 /
367 kStateWindowSize);
368 }
369
370
353 void RuntimeProfiler::NotifyTick() { 371 void RuntimeProfiler::NotifyTick() {
372 // Record state sample.
373 if (Top::IsInJSState()) {
374 AddStateSample(IN_JS_STATE);
Vitaly Repeshko 2010/12/10 14:40:40 Nice place to use ?: operator. Up to you though.
Karl Klose 2010/12/10 14:45:06 Done.
375 } else {
376 AddStateSample(IN_NON_JS_STATE);
377 }
354 StackGuard::RequestRuntimeProfilerTick(); 378 StackGuard::RequestRuntimeProfilerTick();
355 } 379 }
356 380
357 381
358 void RuntimeProfiler::MarkCompactPrologue(bool is_compacting) { 382 void RuntimeProfiler::MarkCompactPrologue(bool is_compacting) {
359 if (is_compacting) { 383 if (is_compacting) {
360 // Clear all samples before mark-sweep-compact because every 384 // Clear all samples before mark-sweep-compact because every
361 // function might move. 385 // function might move.
362 ClearSampleBuffer(); 386 ClearSampleBuffer();
363 } else { 387 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 Object** RuntimeProfiler::SamplerWindowAddress() { 421 Object** RuntimeProfiler::SamplerWindowAddress() {
398 return sampler_window; 422 return sampler_window;
399 } 423 }
400 424
401 425
402 int RuntimeProfiler::SamplerWindowSize() { 426 int RuntimeProfiler::SamplerWindowSize() {
403 return kSamplerWindowSize; 427 return kSamplerWindowSize;
404 } 428 }
405 429
406 430
407 static void AddStateSample(SamplerState current_state) {
408 static const int kStateWindowSize = 128;
409 static SamplerState state_window[kStateWindowSize];
410 static int state_window_position = 0;
411 static int state_counts[2] = { kStateWindowSize, 0 };
412
413 SamplerState old_state = state_window[state_window_position];
414 state_counts[old_state]--;
415 state_window[state_window_position] = current_state;
416 state_counts[current_state]++;
417 ASSERT(IsPowerOf2(kStateWindowSize));
418 state_window_position = (state_window_position + 1) &
419 (kStateWindowSize - 1);
420 NoBarrier_Store(&js_ratio, state_counts[IN_JS_STATE] * 100 /
421 kStateWindowSize);
422 }
423
424
425 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { 431 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
426 static const int kNonJSTicksThreshold = 100; 432 static const int kNonJSTicksThreshold = 100;
427 // We suspend the runtime profiler thread when not running 433 // We suspend the runtime profiler thread when not running
428 // JavaScript. If the CPU profiler is active we must not do this 434 // JavaScript. If the CPU profiler is active we must not do this
429 // because it samples both JavaScript and C++ code. 435 // because it samples both JavaScript and C++ code.
430 if (RuntimeProfiler::IsEnabled() && 436 if (RuntimeProfiler::IsEnabled() &&
431 !CpuProfiler::is_profiling() && 437 !CpuProfiler::is_profiling() &&
432 !(FLAG_prof && FLAG_prof_auto)) { 438 !(FLAG_prof && FLAG_prof_auto)) {
433 if (Top::IsInJSState()) { 439 if (Top::IsInJSState()) {
434 AddStateSample(IN_JS_STATE);
435 non_js_ticks_ = 0; 440 non_js_ticks_ = 0;
436 } else { 441 } else {
437 AddStateSample(IN_NON_JS_STATE);
438 if (non_js_ticks_ < kNonJSTicksThreshold) { 442 if (non_js_ticks_ < kNonJSTicksThreshold) {
439 ++non_js_ticks_; 443 ++non_js_ticks_;
440 } else { 444 } else {
441 if (Top::WaitForJSState()) return true; 445 if (Top::WaitForJSState()) return true;
442 } 446 }
443 } 447 }
444 } 448 }
445 return false; 449 return false;
446 } 450 }
447 451
448 452
449 } } // namespace v8::internal 453 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698