| 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 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "runtime-profiler.h" | 30 #include "runtime-profiler.h" |
| 31 | 31 |
| 32 #include "assembler.h" | 32 #include "assembler.h" |
| 33 #include "code-stubs.h" | 33 #include "code-stubs.h" |
| 34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
| 35 #include "deoptimizer.h" | 35 #include "deoptimizer.h" |
| 36 #include "execution.h" | 36 #include "execution.h" |
| 37 #include "global-handles.h" | 37 #include "global-handles.h" |
| 38 #include "mark-compact.h" |
| 38 #include "platform.h" | 39 #include "platform.h" |
| 39 #include "scopeinfo.h" | 40 #include "scopeinfo.h" |
| 40 | 41 |
| 41 namespace v8 { | 42 namespace v8 { |
| 42 namespace internal { | 43 namespace internal { |
| 43 | 44 |
| 44 | 45 |
| 45 class PendingListNode : public Malloced { | 46 class PendingListNode : public Malloced { |
| 46 public: | 47 public: |
| 47 explicit PendingListNode(JSFunction* function); | 48 explicit PendingListNode(JSFunction* function); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 function_= Handle<Object>::null(); | 101 function_= Handle<Object>::null(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 | 104 |
| 104 void PendingListNode::WeakCallback(v8::Persistent<v8::Value>, void* data) { | 105 void PendingListNode::WeakCallback(v8::Persistent<v8::Value>, void* data) { |
| 105 reinterpret_cast<PendingListNode*>(data)->Destroy(); | 106 reinterpret_cast<PendingListNode*>(data)->Destroy(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 | 109 |
| 109 static bool IsOptimizable(JSFunction* function) { | 110 static bool IsOptimizable(JSFunction* function) { |
| 110 if (function->GetHeap()->InNewSpace(function)) return false; | |
| 111 Code* code = function->code(); | 111 Code* code = function->code(); |
| 112 return code->kind() == Code::FUNCTION && code->optimizable(); | 112 return code->kind() == Code::FUNCTION && code->optimizable(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 Atomic32 RuntimeProfiler::state_ = 0; | 116 Atomic32 RuntimeProfiler::state_ = 0; |
| 117 // TODO(isolates): Create the semaphore lazily and clean it up when no | 117 // TODO(isolates): Create the semaphore lazily and clean it up when no |
| 118 // longer required. | 118 // longer required. |
| 119 #ifdef ENABLE_LOGGING_AND_PROFILING | 119 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 120 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0); | 120 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 | 208 |
| 209 void RuntimeProfiler::ClearSampleBuffer() { | 209 void RuntimeProfiler::ClearSampleBuffer() { |
| 210 memset(sampler_window_, 0, sizeof(sampler_window_)); | 210 memset(sampler_window_, 0, sizeof(sampler_window_)); |
| 211 memset(sampler_window_weight_, 0, sizeof(sampler_window_weight_)); | 211 memset(sampler_window_weight_, 0, sizeof(sampler_window_weight_)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 void RuntimeProfiler::ClearSampleBufferNewSpaceEntries() { | |
| 216 for (int i = 0; i < kSamplerWindowSize; i++) { | |
| 217 if (isolate_->heap()->InNewSpace(sampler_window_[i])) { | |
| 218 sampler_window_[i] = NULL; | |
| 219 sampler_window_weight_[i] = 0; | |
| 220 } | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 | |
| 225 int RuntimeProfiler::LookupSample(JSFunction* function) { | 215 int RuntimeProfiler::LookupSample(JSFunction* function) { |
| 226 int weight = 0; | 216 int weight = 0; |
| 227 for (int i = 0; i < kSamplerWindowSize; i++) { | 217 for (int i = 0; i < kSamplerWindowSize; i++) { |
| 228 Object* sample = sampler_window_[i]; | 218 Object* sample = sampler_window_[i]; |
| 229 if (sample != NULL) { | 219 if (sample != NULL) { |
| 230 if (function == sample) { | 220 if (function == sample) { |
| 231 weight += sampler_window_weight_[i]; | 221 weight += sampler_window_weight_[i]; |
| 232 } | 222 } |
| 233 } | 223 } |
| 234 } | 224 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // Record state sample. | 355 // Record state sample. |
| 366 SamplerState state = IsSomeIsolateInJS() | 356 SamplerState state = IsSomeIsolateInJS() |
| 367 ? IN_JS_STATE | 357 ? IN_JS_STATE |
| 368 : IN_NON_JS_STATE; | 358 : IN_NON_JS_STATE; |
| 369 UpdateStateRatio(state); | 359 UpdateStateRatio(state); |
| 370 isolate_->stack_guard()->RequestRuntimeProfilerTick(); | 360 isolate_->stack_guard()->RequestRuntimeProfilerTick(); |
| 371 #endif | 361 #endif |
| 372 } | 362 } |
| 373 | 363 |
| 374 | 364 |
| 375 void RuntimeProfiler::MarkCompactPrologue(bool is_compacting) { | |
| 376 if (is_compacting) { | |
| 377 // Clear all samples before mark-sweep-compact because every | |
| 378 // function might move. | |
| 379 ClearSampleBuffer(); | |
| 380 } else { | |
| 381 // Clear only new space entries on mark-sweep since none of the | |
| 382 // old-space functions will move. | |
| 383 ClearSampleBufferNewSpaceEntries(); | |
| 384 } | |
| 385 } | |
| 386 | |
| 387 | |
| 388 void RuntimeProfiler::Setup() { | 365 void RuntimeProfiler::Setup() { |
| 389 ClearSampleBuffer(); | 366 ClearSampleBuffer(); |
| 390 // If the ticker hasn't already started, make sure to do so to get | 367 // If the ticker hasn't already started, make sure to do so to get |
| 391 // the ticks for the runtime profiler. | 368 // the ticks for the runtime profiler. |
| 392 if (IsEnabled()) isolate_->logger()->EnsureTickerStarted(); | 369 if (IsEnabled()) isolate_->logger()->EnsureTickerStarted(); |
| 393 } | 370 } |
| 394 | 371 |
| 395 | 372 |
| 396 void RuntimeProfiler::Reset() { | 373 void RuntimeProfiler::Reset() { |
| 397 sampler_threshold_ = kSamplerThresholdInit; | 374 sampler_threshold_ = kSamplerThresholdInit; |
| 398 sampler_threshold_size_factor_ = kSamplerThresholdSizeFactorInit; | 375 sampler_threshold_size_factor_ = kSamplerThresholdSizeFactorInit; |
| 399 sampler_ticks_until_threshold_adjustment_ = | 376 sampler_ticks_until_threshold_adjustment_ = |
| 400 kSamplerTicksBetweenThresholdAdjustment; | 377 kSamplerTicksBetweenThresholdAdjustment; |
| 401 } | 378 } |
| 402 | 379 |
| 403 | 380 |
| 404 void RuntimeProfiler::TearDown() { | 381 void RuntimeProfiler::TearDown() { |
| 405 // Nothing to do. | 382 // Nothing to do. |
| 406 } | 383 } |
| 407 | 384 |
| 408 | 385 |
| 409 Object** RuntimeProfiler::SamplerWindowAddress() { | |
| 410 return sampler_window_; | |
| 411 } | |
| 412 | |
| 413 | |
| 414 int RuntimeProfiler::SamplerWindowSize() { | 386 int RuntimeProfiler::SamplerWindowSize() { |
| 415 return kSamplerWindowSize; | 387 return kSamplerWindowSize; |
| 416 } | 388 } |
| 417 | 389 |
| 418 | 390 |
| 391 // Update the pointers in the sampler window after a GC. |
| 392 void RuntimeProfiler::UpdateSamplesAfterScavenge() { |
| 393 for (int i = 0; i < kSamplerWindowSize; i++) { |
| 394 Object* function = sampler_window_[i]; |
| 395 if (function != NULL && isolate_->heap()->InNewSpace(function)) { |
| 396 MapWord map_word = HeapObject::cast(function)->map_word(); |
| 397 if (map_word.IsForwardingAddress()) { |
| 398 sampler_window_[i] = map_word.ToForwardingAddress(); |
| 399 } else { |
| 400 sampler_window_[i] = NULL; |
| 401 } |
| 402 } |
| 403 } |
| 404 } |
| 405 |
| 406 |
| 419 void RuntimeProfiler::HandleWakeUp(Isolate* isolate) { | 407 void RuntimeProfiler::HandleWakeUp(Isolate* isolate) { |
| 420 #ifdef ENABLE_LOGGING_AND_PROFILING | 408 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 421 // The profiler thread must still be waiting. | 409 // The profiler thread must still be waiting. |
| 422 ASSERT(NoBarrier_Load(&state_) >= 0); | 410 ASSERT(NoBarrier_Load(&state_) >= 0); |
| 423 // In IsolateEnteredJS we have already incremented the counter and | 411 // In IsolateEnteredJS we have already incremented the counter and |
| 424 // undid the decrement done by the profiler thread. Increment again | 412 // undid the decrement done by the profiler thread. Increment again |
| 425 // to get the right count of active isolates. | 413 // to get the right count of active isolates. |
| 426 NoBarrier_AtomicIncrement(&state_, 1); | 414 NoBarrier_AtomicIncrement(&state_, 1); |
| 427 semaphore_->Signal(); | 415 semaphore_->Signal(); |
| 428 isolate->ResetEagerOptimizingData(); | 416 isolate->ResetEagerOptimizingData(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 446 } | 434 } |
| 447 | 435 |
| 448 | 436 |
| 449 void RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown() { | 437 void RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown() { |
| 450 #ifdef ENABLE_LOGGING_AND_PROFILING | 438 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 451 semaphore_->Signal(); | 439 semaphore_->Signal(); |
| 452 #endif | 440 #endif |
| 453 } | 441 } |
| 454 | 442 |
| 455 | 443 |
| 444 void RuntimeProfiler::RemoveDeadSamples() { |
| 445 for (int i = 0; i < kSamplerWindowSize; i++) { |
| 446 Object* function = sampler_window_[i]; |
| 447 if (function != NULL && !HeapObject::cast(function)->IsMarked()) { |
| 448 sampler_window_[i] = NULL; |
| 449 } |
| 450 } |
| 451 } |
| 452 |
| 453 |
| 454 void RuntimeProfiler::UpdateSamplesAfterCompact(ObjectVisitor* visitor) { |
| 455 for (int i = 0; i < kSamplerWindowSize; i++) { |
| 456 visitor->VisitPointer(&sampler_window_[i]); |
| 457 } |
| 458 } |
| 459 |
| 460 |
| 456 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { | 461 bool RuntimeProfilerRateLimiter::SuspendIfNecessary() { |
| 457 #ifdef ENABLE_LOGGING_AND_PROFILING | 462 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 458 static const int kNonJSTicksThreshold = 100; | 463 static const int kNonJSTicksThreshold = 100; |
| 459 if (RuntimeProfiler::IsSomeIsolateInJS()) { | 464 if (RuntimeProfiler::IsSomeIsolateInJS()) { |
| 460 non_js_ticks_ = 0; | 465 non_js_ticks_ = 0; |
| 461 } else { | 466 } else { |
| 462 if (non_js_ticks_ < kNonJSTicksThreshold) { | 467 if (non_js_ticks_ < kNonJSTicksThreshold) { |
| 463 ++non_js_ticks_; | 468 ++non_js_ticks_; |
| 464 } else { | 469 } else { |
| 465 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); | 470 return RuntimeProfiler::WaitForSomeIsolateToEnterJS(); |
| 466 } | 471 } |
| 467 } | 472 } |
| 468 #endif | 473 #endif |
| 469 return false; | 474 return false; |
| 470 } | 475 } |
| 471 | 476 |
| 472 | 477 |
| 473 } } // namespace v8::internal | 478 } } // namespace v8::internal |
| OLD | NEW |