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

Side by Side Diff: src/third_party/vtune/vtune-jit.cc

Issue 11574031: Intel VTune integration for V8/D8 (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 8 months 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 | « src/third_party/vtune/vtune-jit.h ('k') | 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
(Empty)
1 /*
2 This file is provided under a dual BSD/GPLv2 license. When using or
3 redistributing this file, you may do so under either license.
4
5 GPL LICENSE SUMMARY
6
7 Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of version 2 of the GNU General Public License as
11 published by the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 The full GNU General Public License is included in this distribution
22 in the file called LICENSE.GPL.
23
24 Contact Information:
25 http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
26
27 BSD LICENSE
28
29 Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
30 All rights reserved.
31
32 Redistribution and use in source and binary forms, with or without
33 modification, are permitted provided that the following conditions
34 are met:
35
36 * Redistributions of source code must retain the above copyright
37 notice, this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright
39 notice, this list of conditions and the following disclaimer in
40 the documentation and/or other materials provided with the
41 distribution.
42 * Neither the name of Intel Corporation nor the names of its
43 contributors may be used to endorse or promote products derived
44 from this software without specific prior written permission.
45
46 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
49 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
50 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */
58 #include <string.h>
59
60 #ifdef WIN32
61 #include <hash_map>
62 using namespace std;
63 #else
64 // To avoid GCC 4.4 compilation warning about hash_map being deprecated.
65 #define OLD_DEPRECATED __DEPRECATED
66 #undef __DEPRECATED
67 #include <ext/hash_map>
68 #define __DEPRECATED OLD_DEPRECATED
69 using namespace __gnu_cxx;
70 #endif
71
72 #include <list>
73
74 #include "v8-vtune.h"
75 #include "vtune-jit.h"
76
77 namespace vTune {
78 namespace internal {
79
80
81 // This class is used to record the JITted code position info for JIT
82 // code profiling.
83 class JITCodeLineInfo {
84 public:
85 JITCodeLineInfo() { }
86
87 void SetPosition(intptr_t pc, int pos) {
88 AddCodeLineInfo(LineNumInfo(pc, pos));
89 }
90
91 struct LineNumInfo {
92 LineNumInfo(intptr_t pc, int pos)
93 : pc_(pc), pos_(pos) { }
94
95 intptr_t pc_;
96 int pos_;
97 };
98
99 std::list<LineNumInfo>* GetLineNumInfo() {
100 return &line_num_info_;
101 }
102
103 private:
104 void AddCodeLineInfo(const LineNumInfo& line_info) {
105 line_num_info_.push_back(line_info);
106 }
107 std::list<LineNumInfo> line_num_info_;
108 };
109
110 struct SameCodeObjects {
111 bool operator () (void* key1, void* key2) const {
112 return key1 == key2;
113 }
114 };
115
116 struct HashForCodeObject {
117 uint32_t operator () (void* code) const {
118 static const uintptr_t kGoldenRatio = 2654435761u;
119 uintptr_t hash = reinterpret_cast<uintptr_t>(code);
120 return static_cast<uint32_t>(hash * kGoldenRatio);
121 }
122 };
123
124 #ifdef WIN32
125 typedef hash_map<void*, void*> JitInfoMap;
126 #else
127 typedef hash_map<void*, void*, HashForCodeObject, SameCodeObjects> JitInfoMap;
128 #endif
129
130 static JitInfoMap* GetEntries() {
131 static JitInfoMap* entries;
132 if (entries == NULL) {
133 entries = new JitInfoMap();
134 }
135 return entries;
136 }
137
138 static bool IsLineInfoTagged(void* ptr) {
139 return 0 != (reinterpret_cast<intptr_t>(ptr));
140 }
141
142 static JITCodeLineInfo* UntagLineInfo(void* ptr) {
143 return reinterpret_cast<JITCodeLineInfo*>(
144 reinterpret_cast<intptr_t>(ptr));
145 }
146
147 // The parameter str is a mixed pattern which contains the
148 // function name and some other info. It comes from all the
149 // Logger::CodeCreateEvent(...) function. This funtion get the
150 // pure function name from the input parameter.
151 static char* GetFunctionNameFromMixedName(const char* str, int length) {
152 int index = 0;
153 int count = 0;
154 char* start_ptr = NULL;
155
156 while (str[index++] != ':' && (index < length)) {}
157
158 if (str[index] == '*' || str[index] == '~' ) index++;
159 if (index >= length) return NULL;
160
161 start_ptr = const_cast<char*>(str + index);
162
163 while (index < length && str[index++] != ' ') {
164 count++;
165 }
166
167 char* result = new char[count + 1];
168 memcpy(result, start_ptr, count);
169 result[count] = '\0';
170
171 return result;
172 }
173
174 // The JitCodeEventHandler for Vtune.
175 void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) {
176 if (VTUNERUNNING && event != NULL) {
177 switch (event->type) {
178 case v8::JitCodeEvent::CODE_ADDED: {
179 char* temp_file_name = NULL;
180 char* temp_method_name =
181 GetFunctionNameFromMixedName(event->name.str,
182 static_cast<int>(event->name.len));
183 iJIT_Method_Load jmethod;
184 memset(&jmethod, 0, sizeof jmethod);
185 jmethod.method_id = iJIT_GetNewMethodID();
186 jmethod.method_load_address = event->code_start;
187 jmethod.method_size = static_cast<unsigned int>(event->code_len);
188 jmethod.method_name = temp_method_name;
189
190 Handle<Script> script = event->script;
191
192 if (*script != NULL) {
193 // Get the source file name and set it to jmethod.source_file_name
194 if ((*script->GetScriptName())->IsString()) {
195 Handle<String> script_name =
196 Handle<String>(String::Cast(*script->GetScriptName()));
197 temp_file_name = new char[script_name->Length() + 1];
198 script_name->WriteAscii(temp_file_name);
199 jmethod.source_file_name = temp_file_name;
200 }
201
202 JitInfoMap::iterator entry =
203 GetEntries()->find(event->code_start);
204 if (entry != GetEntries()->end() && IsLineInfoTagged(entry->first)) {
205 JITCodeLineInfo* line_info = UntagLineInfo(entry->second);
206 // Get the line_num_info and set it to jmethod.line_number_table
207 std::list<JITCodeLineInfo::LineNumInfo>* vtunelineinfo =
208 line_info->GetLineNumInfo();
209
210 jmethod.line_number_size = (unsigned int)vtunelineinfo->size();
211 jmethod.line_number_table =
212 reinterpret_cast<LineNumberInfo*>(
213 malloc(sizeof(LineNumberInfo)*jmethod.line_number_size));
214
215 std::list<JITCodeLineInfo::LineNumInfo>::iterator Iter;
216 int index = 0;
217 for (Iter = vtunelineinfo->begin();
218 Iter != vtunelineinfo->end();
219 Iter++) {
220 jmethod.line_number_table[index].Offset =
221 static_cast<unsigned int>(Iter->pc_);
222 jmethod.line_number_table[index++].LineNumber =
223 script->GetLineNumber(Iter->pos_)+1;
224 }
225 GetEntries()->erase(event->code_start);
226 }
227 }
228
229 iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
230 reinterpret_cast<void*>(&jmethod));
231 if (temp_method_name)
232 delete []temp_method_name;
233 if (temp_file_name)
234 delete []temp_file_name;
235 break;
236 }
237 // TODO(chunyang.dai@intel.com): code_move will be supported.
238 case v8::JitCodeEvent::CODE_MOVED:
239 break;
240 // Currently the CODE_REMOVED event is not issued.
241 case v8::JitCodeEvent::CODE_REMOVED:
242 break;
243 case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: {
244 JITCodeLineInfo* line_info =
245 reinterpret_cast<JITCodeLineInfo*>(event->user_data);
246 if (line_info != NULL) {
247 line_info->SetPosition(static_cast<intptr_t>(event->line_info.offset),
248 static_cast<int>(event->line_info.pos));
249 }
250 break;
251 }
252 case v8::JitCodeEvent::CODE_START_LINE_INFO_RECORDING: {
253 v8::JitCodeEvent* temp_event = const_cast<v8::JitCodeEvent*>(event);
254 temp_event->user_data = new JITCodeLineInfo();
255 break;
256 }
257 case v8::JitCodeEvent::CODE_END_LINE_INFO_RECORDING: {
258 GetEntries()->insert(std::pair <void*, void*>(event->code_start, event-> user_data));
259 break;
260 }
261 default:
262 break;
263 }
264 }
265 return;
266 }
267
268 } // namespace internal
269
270 void InitilizeVtuneForV8() {
271 if (v8::V8::Initialize()) {
272 v8::V8::SetFlagsFromString("--nocompact_code_space",
273 (int)strlen("--nocompact_code_space"));
274 v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault,
275 vTune::internal::VTUNEJITInterface::event_handler);
276 }
277 }
278
279 } // namespace vTune
OLDNEW
« no previous file with comments | « src/third_party/vtune/vtune-jit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698