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

Side by Side Diff: tools/codemap.js

Issue 67191: Reimplement (address -> code) mapping from tickprocessor.py in JS. (Closed)
Patch Set: Added a comment to deleted_ member Created 11 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
« no previous file with comments | « test/mjsunit/tools/codemap.js ('k') | tools/splaytree.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 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
29 // Initlialize namespaces
30 var devtools = devtools || {};
31 devtools.profiler = devtools.profiler || {};
32
33
34 /**
35 * Constructs a mapper that maps addresses into code entries.
36 *
37 * @constructor
38 */
39 devtools.profiler.CodeMap = function() {
40 /**
41 * Dynamic code entries. Used for JIT compiled code.
42 */
43 this.dynamics_ = new goog.structs.SplayTree();
44
45 /**
46 * Deleted code entries. Used for code collected by the GC.
47 */
48 this.deleted_ = [];
49
50 /**
51 * Static code entries. Used for libraries code.
52 */
53 this.statics_ = new goog.structs.SplayTree();
54
55 /**
56 * Map of memory pages occupied with static code.
57 */
58 this.pages_ = [];
59 };
60
61
62 /**
63 * The number of alignment bits in a page address.
64 */
65 devtools.profiler.CodeMap.PAGE_ALIGNMENT = 12;
66
67
68 /**
69 * Page size in bytes.
70 */
71 devtools.profiler.CodeMap.PAGE_SIZE =
72 1 << devtools.profiler.CodeMap.PAGE_ALIGNMENT;
73
74
75 /**
76 * Adds a dynamic (i.e. moveable and discardable) code entry.
77 *
78 * @param {number} start The starting address.
79 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object.
80 */
81 devtools.profiler.CodeMap.prototype.addCode = function(start, codeEntry) {
82 this.dynamics_.insert(start, codeEntry);
83 };
84
85
86 /**
87 * Moves a dynamic code entry. Throws an exception if there is no dynamic
88 * code entry with the specified starting address.
89 *
90 * @param {number} from The starting address of the entry being moved.
91 * @param {number} to The destination address.
92 */
93 devtools.profiler.CodeMap.prototype.moveCode = function(from, to) {
94 var removedNode = this.dynamics_.remove(from);
95 this.dynamics_.insert(to, removedNode.value);
96 };
97
98
99 /**
100 * Discards a dynamic code entry. Throws an exception if there is no dynamic
101 * code entry with the specified starting address. The entry will still be
102 * returned from the 'getAllDynamicEntries' method.
103 *
104 * @param {number} start The starting address of the entry being deleted.
105 */
106 devtools.profiler.CodeMap.prototype.deleteCode = function(start) {
107 var removedNode = this.dynamics_.remove(start);
108 this.deleted_.push(removedNode.value);
109 };
110
111
112 /**
113 * Adds a static code entry.
114 *
115 * @param {number} start The starting address.
116 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object.
117 */
118 devtools.profiler.CodeMap.prototype.addStaticCode = function(
119 start, codeEntry) {
120 this.markPages_(start, start + codeEntry.size);
121 this.statics_.insert(start, codeEntry);
122 };
123
124
125 /**
126 * @private
127 */
128 devtools.profiler.CodeMap.prototype.markPages_ = function(start, end) {
129 for (var addr = start; addr <= end;
130 addr += devtools.profiler.CodeMap.PAGE_SIZE) {
131 this.pages_[addr >> devtools.profiler.CodeMap.PAGE_ALIGNMENT] = 1;
132 }
133 };
134
135
136 /**
137 * @private
138 */
139 devtools.profiler.CodeMap.prototype.isAddressBelongsTo_ = function(addr, node) {
140 return addr >= node.key && addr < (node.key + node.value.size);
141 };
142
143
144 /**
145 * @private
146 */
147 devtools.profiler.CodeMap.prototype.findInTree_ = function(tree, addr) {
148 var node = tree.findGreatestLessThan(addr);
149 return node && this.isAddressBelongsTo_(addr, node) ? node.value : null;
150 };
151
152
153 /**
154 * Finds a code entry that contains the specified address. Both static and
155 * dynamic code entries are considered.
156 *
157 * @param {number} addr Address.
158 */
159 devtools.profiler.CodeMap.prototype.findEntry = function(addr) {
160 var pageAddr = addr >> devtools.profiler.CodeMap.PAGE_ALIGNMENT;
161 if (pageAddr in this.pages_) {
162 return this.findInTree_(this.statics_, addr);
163 }
164 var min = this.dynamics_.findMin();
165 var max = this.dynamics_.findMax();
166 if (max != null && addr < (max.key + max.value.size) && addr >= min.key) {
167 return this.findInTree_(this.dynamics_, addr);
168 }
169 return null;
170 };
171
172
173 /**
174 * Returns an array of all dynamic code entries, including deleted ones.
175 */
176 devtools.profiler.CodeMap.prototype.getAllDynamicEntries = function() {
177 var dynamicEntries = this.dynamics_.exportValues();
178 return dynamicEntries.concat(this.deleted_);
179 };
180
181
182 /**
183 * Returns an array of all static code entries.
184 */
185 devtools.profiler.CodeMap.prototype.getAllStaticEntries = function() {
186 return this.statics_.exportValues();
187 };
188
189
190 /**
191 * Creates a code entry object.
192 *
193 * @param {number} size Code entry size in bytes.
194 * @param {string} opt_name Code entry name.
195 * @constructor
196 */
197 devtools.profiler.CodeMap.CodeEntry = function(size, opt_name) {
198 this.size = size;
199 this.name = opt_name || '';
200 };
201
202
203 devtools.profiler.CodeMap.CodeEntry.prototype.toString = function() {
204 return this.name + ': ' + this.size.toString(16);
205 };
OLDNEW
« no previous file with comments | « test/mjsunit/tools/codemap.js ('k') | tools/splaytree.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698