blob: 28d6d322fd547ad3fdf3eee63704d46b744b78c8 [file] [log] [blame]
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001// Copyright 2012 the V8 project authors. All rights reserved.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_RUNTIME_PROFILER_H_
29#define V8_RUNTIME_PROFILER_H_
30
kasperl@chromium.orga5551262010-12-07 12:49:48 +000031#include "allocation.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000032#include "atomicops.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000033
34namespace v8 {
35namespace internal {
36
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000037class Isolate;
38class JSFunction;
39class Object;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000040class Semaphore;
41
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000042class RuntimeProfiler {
kasperl@chromium.orga5551262010-12-07 12:49:48 +000043 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000044 explicit RuntimeProfiler(Isolate* isolate);
kasperl@chromium.orga5551262010-12-07 12:49:48 +000045
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000046 void OptimizeNow();
kasperl@chromium.orga5551262010-12-07 12:49:48 +000047
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +000048 void SetUp();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000049 void Reset();
50 void TearDown();
51
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +000052 void NotifyICChanged() { any_ic_changed_ = true; }
53
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000054 // Rate limiting support.
55
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000056 void UpdateSamplesAfterScavenge();
57 void RemoveDeadSamples();
58 void UpdateSamplesAfterCompact(ObjectVisitor* visitor);
59
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +000060 void AttemptOnStackReplacement(JSFunction* function);
61
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000062 private:
63 static const int kSamplerWindowSize = 16;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +000064
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +000065 void Optimize(JSFunction* function, const char* reason);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000066
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000067 void ClearSampleBuffer();
68
69 void ClearSampleBufferNewSpaceEntries();
70
71 int LookupSample(JSFunction* function);
72
73 void AddSample(JSFunction* function, int weight);
74
dslomov@chromium.orgb752d402013-06-18 11:54:54 +000075 bool CodeSizeOKForOSR(Code* shared_code);
76
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000077 Isolate* isolate_;
78
79 int sampler_threshold_;
80 int sampler_threshold_size_factor_;
81 int sampler_ticks_until_threshold_adjustment_;
82
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000083 Object* sampler_window_[kSamplerWindowSize];
84 int sampler_window_position_;
85 int sampler_window_weight_[kSamplerWindowSize];
86
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +000087 bool any_ic_changed_;
88 bool code_generated_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +000089};
90
kasperl@chromium.orga5551262010-12-07 12:49:48 +000091} } // namespace v8::internal
92
93#endif // V8_RUNTIME_PROFILER_H_