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

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 UpdateStateRatio(SamplerState current_state) {
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 SamplerState state = Top::IsInJSState()
374 ? IN_JS_STATE
375 : IN_NON_JS_STATE;
376 UpdateStateRatio(state);
354 StackGuard::RequestRuntimeProfilerTick(); 377 StackGuard::RequestRuntimeProfilerTick();
355 } 378 }
356 379
357 380
358 void RuntimeProfiler::MarkCompactPrologue(bool is_compacting) { 381 void RuntimeProfiler::MarkCompactPrologue(bool is_compacting) {
359 if (is_compacting) { 382 if (is_compacting) {
360 // Clear all samples before mark-sweep-compact because every 383 // Clear all samples before mark-sweep-compact because every
361 // function might move. 384 // function might move.
362 ClearSampleBuffer(); 385 ClearSampleBuffer();
363 } else { 386 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 Object** RuntimeProfiler::SamplerWindowAddress() { 420 Object** RuntimeProfiler::SamplerWindowAddress() {
398 return sampler_window; 421 return sampler_window;
399 } 422 }
400 423
401 424
402 int RuntimeProfiler::SamplerWindowSize() { 425 int RuntimeProfiler::SamplerWindowSize() {
403 return kSamplerWindowSize; 426 return kSamplerWindowSize;
404 } 427 }
405 428
406 429
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() { 430 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
426 static const int kNonJSTicksThreshold = 100; 431 static const int kNonJSTicksThreshold = 100;
427 // We suspend the runtime profiler thread when not running 432 // We suspend the runtime profiler thread when not running
428 // JavaScript. If the CPU profiler is active we must not do this 433 // JavaScript. If the CPU profiler is active we must not do this
429 // because it samples both JavaScript and C++ code. 434 // because it samples both JavaScript and C++ code.
430 if (RuntimeProfiler::IsEnabled() && 435 if (RuntimeProfiler::IsEnabled() &&
431 !CpuProfiler::is_profiling() && 436 !CpuProfiler::is_profiling() &&
432 !(FLAG_prof && FLAG_prof_auto)) { 437 !(FLAG_prof && FLAG_prof_auto)) {
433 if (Top::IsInJSState()) { 438 if (Top::IsInJSState()) {
434 AddStateSample(IN_JS_STATE);
435 non_js_ticks_ = 0; 439 non_js_ticks_ = 0;
436 } else { 440 } else {
437 AddStateSample(IN_NON_JS_STATE);
438 if (non_js_ticks_ < kNonJSTicksThreshold) { 441 if (non_js_ticks_ < kNonJSTicksThreshold) {
439 ++non_js_ticks_; 442 ++non_js_ticks_;
440 } else { 443 } else {
441 if (Top::WaitForJSState()) return true; 444 if (Top::WaitForJSState()) return true;
442 } 445 }
443 } 446 }
444 } 447 }
445 return false; 448 return false;
446 } 449 }
447 450
448 451
449 } } // namespace v8::internal 452 } } // 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