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

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

Issue 10824032: Enables V8 integration with the Intel VTune performance analysis tool. This allows the VTune profi… (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 5 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
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 #ifdef ENABLE_VTUNE_JIT_INTERFACE
59 #include <string.h>
60 #include "vtune-jit.h"
61 #include "../../factory.h"
62 #include "../../global-handles.h"
63
64 namespace v8 {
65 namespace internal {
66
67 Mutex* VTUNEJITInterface::vtunemutex_ = OS::CreateMutex();
68
69 static bool SameCodeObjects(void* key1, void* key2) {
70 return key1 == key2;
71 }
72
73
74 static HashMap* GetEntries() {
75 static HashMap* entries;
76 if (entries == NULL) {
77 entries = new HashMap(&SameCodeObjects);
78 }
79 return entries;
80 }
81
82 static uint32_t HashForCodeObject(Code* code) {
83 static const uintptr_t kGoldenRatio = 2654435761u;
84 uintptr_t hash = reinterpret_cast<uintptr_t>(code->address());
85 return static_cast<uint32_t>((hash >> kCodeAlignmentBits) * kGoldenRatio);
86 }
87
88
89 static const intptr_t kLineInfoTag = 0x1;
90
91 static bool IsSourceInfoAvailable(Handle<Script> script) {
92 return !script.is_null() &&
93 script->source()->IsString() &&
94 script->HasValidSource() &&
95 script->name()->IsString();
96 }
97
98 static bool IsLineInfoTagged(void* ptr) {
99 return 0 != (reinterpret_cast<intptr_t>(ptr));
100 }
101
102
103 static void* TagLineInfo(VtuneJITLineInfo* ptr) {
104 return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(ptr));
105 }
106
107
108 static VtuneJITLineInfo* UntagLineInfo(void* ptr) {
109 return reinterpret_cast<VtuneJITLineInfo*>(
110 reinterpret_cast<intptr_t>(ptr));
111 }
112
113
114 void VTUNEJITInterface::AddCode(const char* methodname,
115 Code* code,
116 Handle<Script> script) {
117 if (VTUNERUNNING) {
118 ScopedLock lock(vtunemutex_);
119
120 iJIT_Method_Load jmethod;
121 memset(&jmethod, 0, sizeof jmethod);
122 Handle<String> filename = Handle<String>(String::cast(script->name()));
123 SmartArrayPointer<char> filename_cstring = filename->ToCString(
124 DISALLOW_NULLS);
125
126 jmethod.method_id = iJIT_GetNewMethodID();
127 jmethod.method_name = const_cast<char*>(methodname);
128 jmethod.source_file_name = *filename_cstring;
129 jmethod.method_load_address = code->instruction_start();
130 jmethod.method_size = code->instruction_end() - code->instruction_start();
131 VTUNEDEBUG(PrintF("Filename: %s MethodName: %s\n",
132 *filename_cstring,
133 methodname));
134
135 // Look for lineinfo
136 HashMap::Entry* entry = GetEntries()->Lookup(code,
137 HashForCodeObject(code),
138 false);
139 if (entry == NULL) {
140 iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
141 reinterpret_cast<void*>(&jmethod));
142 return;
143 }
144
145 if (IsLineInfoTagged(entry->value) && IsSourceInfoAvailable(script)) {
146 // Init Script Line Ends
147 GetScriptLineNumber(script, 0);
148 VtuneJITLineInfo *vtunejitlineinfo_ = UntagLineInfo(entry->value);
149 List<LineNumberInfo>* vtunelineinfo = vtunejitlineinfo_->vtunelineinfo();
150
151 jmethod.line_number_size = vtunelineinfo->length();
152 jmethod.line_number_table = reinterpret_cast<LineNumberInfo*>(malloc(
153 sizeof(LineNumberInfo)*jmethod.line_number_size));
154 // populate the lineinfo for the code. Filter it before
155 for (int e = 0; e < vtunelineinfo->length(); e++) {
156 LineNumberInfo line_info = vtunelineinfo->at(e);
157 jmethod.line_number_table[e].Offset = line_info.Offset;
158 jmethod.line_number_table[e].LineNumber = GetScriptLineNumberSafe(
159 script,
160 line_info.LineNumber)+1;
161 }
162 delete vtunelineinfo;
163 }
164 GetEntries()->Remove(code, HashForCodeObject(code));
165
166 /* Send method load notification */
167 iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
168 reinterpret_cast<void*>(&jmethod));
169 }
170 }
171
172 void VTUNEJITInterface::AddCode(const char* methodname,
173 Code* code) {
174 if (VTUNERUNNING) {
175 ScopedLock lock(vtunemutex_);
176
177 /* Fill method information */
178 iJIT_Method_Load jmethod;
179 memset(&jmethod, 0, sizeof jmethod);
180 jmethod.method_id = iJIT_GetNewMethodID();
181 jmethod.method_name = const_cast<char *>(methodname);
182 jmethod.method_load_address = code->instruction_start();
183 jmethod.method_size = code->instruction_end() - code->instruction_start();
184 VTUNEDEBUG(PrintF("Filename: %s MethodName: %s Size: %d\n",
185 "jitter", methodname, jmethod.method_size));
186
187 /* Send method load notification */
188 iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
189 reinterpret_cast<void*>(&jmethod));
190 }
191 }
192
193 void VTUNEJITInterface::AddCode(const char* methodname,
194 Handle<Code> code) {
195 if (VTUNERUNNING) {
196 ScopedLock lock(vtunemutex_);
197
198 /* Fill method information */
199 iJIT_Method_Load jmethod;
200 memset(&jmethod, 0, sizeof jmethod);
201 jmethod.method_id = iJIT_GetNewMethodID();
202 jmethod.method_name = const_cast<char *>(methodname);
203 jmethod.method_load_address = code->instruction_start();
204 jmethod.method_size = code->instruction_end() - code->instruction_start();
205 VTUNEDEBUG(PrintF("Filename: %s MethodName: %s\n", "Jitter2", methodname));
206
207 /* Send method load notification */
208 iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
209 reinterpret_cast<void*>(&jmethod));
210 }
211 }
212
213
214 void VTUNEJITInterface::AddCode(Handle<String> methodname,
215 Handle<Code> code) {
216 if (!methodname.is_null()) {
217 SmartArrayPointer<char> name_cstring;
218 name_cstring = methodname->ToCString(DISALLOW_NULLS);
219 AddCode(*name_cstring, *code);
220 } else {
221 AddCode("", *code);
222 }
223 }
224
225
226 void VTUNEJITInterface::AddCode(Handle<String> methodname,
227 Handle<Code> code,
228 Handle<Script> script) {
229 if (!methodname.is_null()) {
230 SmartArrayPointer<char> name_cstring;
231 name_cstring = methodname->ToCString(DISALLOW_NULLS);
232 AddCode(*name_cstring, *code, script);
233 } else {
234 AddCode("", *code, script);
235 }
236 }
237
238 void VTUNEJITInterface::AddCode(String *methodname, Code* code) {
239 AddCode(methodname != NULL ?
240 *methodname->ToCString(DISALLOW_NULLS) : NULL, code);
241 }
242
243 void VTUNEJITInterface::AddCode(Code* code) {
244 const char *unknown_string = "unknown";
245 AddCode(unknown_string, code);
246 }
247
248 void VTUNEJITInterface::AddCode(Handle<Code> code) {
249 const char *unknown_string = "unknown";
250 AddCode(unknown_string, code);
251 }
252
253 void VTUNEJITInterface::RegisterDetailedLineInfo(Code* code,
254 VtuneJITLineInfo* line_info) {
255 ScopedLock lock(vtunemutex_);
256 HashMap::Entry* entry = GetEntries()->Lookup(code,
257 HashForCodeObject(code),
258 true);
259 ASSERT(entry->value == NULL);
260 entry->value = TagLineInfo(line_info);
261 }
262 }}
263 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698