| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 class Isolate; | 37 class Isolate; |
| 38 class JSFunction; | 38 class JSFunction; |
| 39 class Object; | 39 class Object; |
| 40 class Semaphore; | 40 class Semaphore; |
| 41 | 41 |
| 42 class RuntimeProfiler { | 42 class RuntimeProfiler { |
| 43 public: | 43 public: |
| 44 explicit RuntimeProfiler(Isolate* isolate); | 44 explicit RuntimeProfiler(Isolate* isolate); |
| 45 | 45 |
| 46 static void GlobalSetUp(); | |
| 47 | |
| 48 static inline bool IsEnabled() { | |
| 49 ASSERT(has_been_globally_set_up_); | |
| 50 return enabled_; | |
| 51 } | |
| 52 | |
| 53 void OptimizeNow(); | 46 void OptimizeNow(); |
| 54 | 47 |
| 55 void SetUp(); | 48 void SetUp(); |
| 56 void Reset(); | 49 void Reset(); |
| 57 void TearDown(); | 50 void TearDown(); |
| 58 | 51 |
| 59 Object** SamplerWindowAddress(); | 52 Object** SamplerWindowAddress(); |
| 60 int SamplerWindowSize(); | 53 int SamplerWindowSize(); |
| 61 | 54 |
| 62 void NotifyICChanged() { any_ic_changed_ = true; } | 55 void NotifyICChanged() { any_ic_changed_ = true; } |
| 63 | 56 |
| 64 // Rate limiting support. | 57 // Rate limiting support. |
| 65 | 58 |
| 66 // VM thread interface. | |
| 67 // | |
| 68 // Called by isolates when their states change. | |
| 69 static inline void IsolateEnteredJS(Isolate* isolate); | |
| 70 static inline void IsolateExitedJS(Isolate* isolate); | |
| 71 | |
| 72 // Profiler thread interface. | |
| 73 // | |
| 74 // WaitForSomeIsolateToEnterJS(): | |
| 75 // When no isolates are running JavaScript code for some time the | |
| 76 // profiler thread suspends itself by calling the wait function. The | |
| 77 // wait function returns true after it waited or false immediately. | |
| 78 // While the function was waiting the profiler may have been | |
| 79 // disabled so it *must check* whether it is allowed to continue. | |
| 80 static bool WaitForSomeIsolateToEnterJS(); | |
| 81 | |
| 82 // Stops the runtime profiler thread when profiling support is being | |
| 83 // turned off. | |
| 84 static void StopRuntimeProfilerThreadBeforeShutdown(Thread* thread); | |
| 85 | |
| 86 void UpdateSamplesAfterScavenge(); | 59 void UpdateSamplesAfterScavenge(); |
| 87 void RemoveDeadSamples(); | 60 void RemoveDeadSamples(); |
| 88 void UpdateSamplesAfterCompact(ObjectVisitor* visitor); | 61 void UpdateSamplesAfterCompact(ObjectVisitor* visitor); |
| 89 | 62 |
| 90 void AttemptOnStackReplacement(JSFunction* function); | 63 void AttemptOnStackReplacement(JSFunction* function); |
| 91 | 64 |
| 92 private: | 65 private: |
| 93 static const int kSamplerWindowSize = 16; | 66 static const int kSamplerWindowSize = 16; |
| 94 | 67 |
| 95 static void HandleWakeUp(Isolate* isolate); | |
| 96 | |
| 97 void Optimize(JSFunction* function, const char* reason); | 68 void Optimize(JSFunction* function, const char* reason); |
| 98 | 69 |
| 99 void ClearSampleBuffer(); | 70 void ClearSampleBuffer(); |
| 100 | 71 |
| 101 void ClearSampleBufferNewSpaceEntries(); | 72 void ClearSampleBufferNewSpaceEntries(); |
| 102 | 73 |
| 103 int LookupSample(JSFunction* function); | 74 int LookupSample(JSFunction* function); |
| 104 | 75 |
| 105 void AddSample(JSFunction* function, int weight); | 76 void AddSample(JSFunction* function, int weight); |
| 106 | 77 |
| 107 Isolate* isolate_; | 78 Isolate* isolate_; |
| 108 | 79 |
| 109 int sampler_threshold_; | 80 int sampler_threshold_; |
| 110 int sampler_threshold_size_factor_; | 81 int sampler_threshold_size_factor_; |
| 111 int sampler_ticks_until_threshold_adjustment_; | 82 int sampler_ticks_until_threshold_adjustment_; |
| 112 | 83 |
| 113 Object* sampler_window_[kSamplerWindowSize]; | 84 Object* sampler_window_[kSamplerWindowSize]; |
| 114 int sampler_window_position_; | 85 int sampler_window_position_; |
| 115 int sampler_window_weight_[kSamplerWindowSize]; | 86 int sampler_window_weight_[kSamplerWindowSize]; |
| 116 | 87 |
| 117 bool any_ic_changed_; | 88 bool any_ic_changed_; |
| 118 bool code_generated_; | 89 bool code_generated_; |
| 119 | |
| 120 // Possible state values: | |
| 121 // -1 => the profiler thread is waiting on the semaphore | |
| 122 // 0 or positive => the number of isolates running JavaScript code. | |
| 123 static Atomic32 state_; | |
| 124 | |
| 125 #ifdef DEBUG | |
| 126 static bool has_been_globally_set_up_; | |
| 127 #endif | |
| 128 static bool enabled_; | |
| 129 }; | 90 }; |
| 130 | 91 |
| 131 | |
| 132 // Implementation of RuntimeProfiler inline functions. | |
| 133 | |
| 134 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) { | |
| 135 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1); | |
| 136 if (new_state == 0) { | |
| 137 // Just incremented from -1 to 0. -1 can only be set by the | |
| 138 // profiler thread before it suspends itself and starts waiting on | |
| 139 // the semaphore. | |
| 140 HandleWakeUp(isolate); | |
| 141 } | |
| 142 ASSERT(new_state >= 0); | |
| 143 } | |
| 144 | |
| 145 | |
| 146 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) { | |
| 147 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1); | |
| 148 ASSERT(new_state >= 0); | |
| 149 USE(new_state); | |
| 150 } | |
| 151 | |
| 152 } } // namespace v8::internal | 92 } } // namespace v8::internal |
| 153 | 93 |
| 154 #endif // V8_RUNTIME_PROFILER_H_ | 94 #endif // V8_RUNTIME_PROFILER_H_ |
| OLD | NEW |