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

Side by Side Diff: src/code-events.cc

Issue 10795074: Add a new API V8::SetJitCodeEventHandler to push code name and location to users such as profilers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix gcc compilation. Fix HandleScope lifetime in test. Add TODOs. Remove trailing WS. Amend docs pe… Created 8 years, 4 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 // Copyright 2012 the V8 project authors. All rights reserved.
2 // 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 #include "v8.h"
29
30 #include "code-events.h"
31
32 namespace v8 {
33 namespace internal {
34
35 static const char* CodeKindToString(Code::Kind kind) {
36 switch (kind) {
37 #define DEF_CASE(name) case Code::name: return #name;
38 CODE_KIND_LIST(DEF_CASE)
39 #undef DEF_CASE
40 default:
41 return "*UNKNOWN*";
42 }
43 }
44
45 JitCodeEventHandler CodeEvents::event_handler_ = NULL;
46
47
48 void CodeEvents::AddCode(const char* name,
49 Code* code,
50 Script* script,
51 CompilationInfo* info) {
52 JitCodeEvent event = { JitCodeEvent::CODE_ADDED,
53 code->instruction_start(),
54 code->instruction_size(),
55 { NULL } };
56 event.name = name;
57 event_handler_(&event);
58 }
59
60
61 void CodeEvents::AddCode(Handle<String> name,
62 Handle<Script> script,
63 Handle<Code> code,
64 CompilationInfo* info) {
65 if (!name.is_null()) {
66 SmartArrayPointer<char> name_cstring = name->ToCString(DISALLOW_NULLS);
mnaganov (inactive) 2012/07/30 11:43:36 Are you sure this works correctly? SmartArrayPoint
mnaganov (inactive) 2012/07/30 13:33:16 I'm sorry, I haven't realized you are calling the
Sigurður Ásgeirsson 2012/07/30 13:54:43 I lifted this code pretty much verbatim from GDBJI
67 AddCode(*name_cstring, *code, *script, info);
68 } else {
69 AddCode("", *code, *script, info);
70 }
71 }
72
73
74 void CodeEvents::AddCode(String* name, Code* code) {
75 AddCode(name != NULL ? *name->ToCString(DISALLOW_NULLS) : NULL, code);
76 }
77
78
79 void CodeEvents::AddCode(const char* name, Code* code) {
80 EmbeddedVector<char, 256> buffer;
81 StringBuilder builder(buffer.start(), buffer.length());
82
83 builder.AddString(CodeKindToString(code->kind()));
84 if ((name != NULL) && (*name != '\0')) {
85 builder.AddString(": ");
86 builder.AddString(name);
87 } else {
88 builder.AddFormatted(": code object %p", static_cast<void*>(code));
89 }
90
91 AddCode(builder.Finalize(), code, NULL, NULL);
92 }
93
94
95 void CodeEvents::AddCode(Code* code) {
96 AddCode("", code);
97 }
98
99 void CodeEvents::MoveCode(Address src, Address dst) {
100 Code* src_code = Code::cast(HeapObject::FromAddress(src));
101
102 JitCodeEvent event = { JitCodeEvent::CODE_MOVED,
103 src_code->instruction_start(),
104 src_code->instruction_size(),
105 { NULL } };
106
107 // Calculate the header size.
108 const size_t header_size =
109 src_code->instruction_start() - reinterpret_cast<byte*>(src_code);
110
111 event.new_code_start = dst + header_size;
112
113 event_handler_(&event);
114 }
115
116
117 void CodeEvents::RemoveCode(Code* code) {
118 JitCodeEvent event = { JitCodeEvent::CODE_REMOVED,
119 code->instruction_start(),
120 code->instruction_size(),
121 { NULL } };
122
123 event_handler_(&event);
124 }
125
126
127 } } // namespace v8::internal
OLDNEW
« include/v8.h ('K') | « src/code-events.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698