OLD | NEW |
---|---|
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 25 matching lines...) Expand all Loading... | |
36 * | 36 * |
37 * @constructor | 37 * @constructor |
38 */ | 38 */ |
39 devtools.profiler.CodeMap = function() { | 39 devtools.profiler.CodeMap = function() { |
40 /** | 40 /** |
41 * Dynamic code entries. Used for JIT compiled code. | 41 * Dynamic code entries. Used for JIT compiled code. |
42 */ | 42 */ |
43 this.dynamics_ = new goog.structs.SplayTree(); | 43 this.dynamics_ = new goog.structs.SplayTree(); |
44 | 44 |
45 /** | 45 /** |
46 * Deleted code entries. Used for code collected by the GC. | 46 * Name generator for entries having duplicate names. |
47 */ | 47 */ |
48 this.deleted_ = []; | |
49 | |
50 this.dynamicsNameGen_ = new devtools.profiler.CodeMap.NameGenerator(); | 48 this.dynamicsNameGen_ = new devtools.profiler.CodeMap.NameGenerator(); |
51 | 49 |
52 /** | 50 /** |
53 * Static code entries. Used for libraries code. | 51 * Static code entries. Used for libraries code. |
54 */ | 52 */ |
55 this.statics_ = new goog.structs.SplayTree(); | 53 this.statics_ = new goog.structs.SplayTree(); |
56 | 54 |
57 /** | 55 /** |
58 * Map of memory pages occupied with static code. | 56 * Map of memory pages occupied with static code. |
59 */ | 57 */ |
(...skipping 14 matching lines...) Expand all Loading... | |
74 1 << devtools.profiler.CodeMap.PAGE_ALIGNMENT; | 72 1 << devtools.profiler.CodeMap.PAGE_ALIGNMENT; |
75 | 73 |
76 | 74 |
77 /** | 75 /** |
78 * Adds a dynamic (i.e. moveable and discardable) code entry. | 76 * Adds a dynamic (i.e. moveable and discardable) code entry. |
79 * | 77 * |
80 * @param {number} start The starting address. | 78 * @param {number} start The starting address. |
81 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. | 79 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. |
82 */ | 80 */ |
83 devtools.profiler.CodeMap.prototype.addCode = function(start, codeEntry) { | 81 devtools.profiler.CodeMap.prototype.addCode = function(start, codeEntry) { |
84 var entryName = this.dynamicsNameGen_.getName(codeEntry.name); | |
85 codeEntry.name = entryName; | |
86 this.dynamics_.insert(start, codeEntry); | 82 this.dynamics_.insert(start, codeEntry); |
87 }; | 83 }; |
88 | 84 |
89 | 85 |
90 /** | 86 /** |
91 * Moves a dynamic code entry. Throws an exception if there is no dynamic | 87 * Moves a dynamic code entry. Throws an exception if there is no dynamic |
92 * code entry with the specified starting address. | 88 * code entry with the specified starting address. |
93 * | 89 * |
94 * @param {number} from The starting address of the entry being moved. | 90 * @param {number} from The starting address of the entry being moved. |
95 * @param {number} to The destination address. | 91 * @param {number} to The destination address. |
96 */ | 92 */ |
97 devtools.profiler.CodeMap.prototype.moveCode = function(from, to) { | 93 devtools.profiler.CodeMap.prototype.moveCode = function(from, to) { |
98 var removedNode = this.dynamics_.remove(from); | 94 var removedNode = this.dynamics_.remove(from); |
99 this.dynamics_.insert(to, removedNode.value); | 95 this.dynamics_.insert(to, removedNode.value); |
100 }; | 96 }; |
101 | 97 |
102 | 98 |
103 /** | 99 /** |
104 * Discards a dynamic code entry. Throws an exception if there is no dynamic | 100 * Discards a dynamic code entry. Throws an exception if there is no dynamic |
105 * code entry with the specified starting address. The entry will still be | 101 * code entry with the specified starting address. |
106 * returned from the 'getAllDynamicEntries' method. | |
107 * | 102 * |
108 * @param {number} start The starting address of the entry being deleted. | 103 * @param {number} start The starting address of the entry being deleted. |
109 */ | 104 */ |
110 devtools.profiler.CodeMap.prototype.deleteCode = function(start) { | 105 devtools.profiler.CodeMap.prototype.deleteCode = function(start) { |
111 var removedNode = this.dynamics_.remove(start); | 106 var removedNode = this.dynamics_.remove(start); |
112 this.deleted_.push(removedNode.value); | |
113 }; | 107 }; |
114 | 108 |
115 | 109 |
116 /** | 110 /** |
117 * Adds a static code entry. | 111 * Adds a static code entry. |
118 * | 112 * |
119 * @param {number} start The starting address. | 113 * @param {number} start The starting address. |
120 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. | 114 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. |
121 */ | 115 */ |
122 devtools.profiler.CodeMap.prototype.addStaticCode = function( | 116 devtools.profiler.CodeMap.prototype.addStaticCode = function( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 * @param {number} addr Address. | 155 * @param {number} addr Address. |
162 */ | 156 */ |
163 devtools.profiler.CodeMap.prototype.findEntry = function(addr) { | 157 devtools.profiler.CodeMap.prototype.findEntry = function(addr) { |
164 var pageAddr = addr >> devtools.profiler.CodeMap.PAGE_ALIGNMENT; | 158 var pageAddr = addr >> devtools.profiler.CodeMap.PAGE_ALIGNMENT; |
165 if (pageAddr in this.pages_) { | 159 if (pageAddr in this.pages_) { |
166 return this.findInTree_(this.statics_, addr); | 160 return this.findInTree_(this.statics_, addr); |
167 } | 161 } |
168 var min = this.dynamics_.findMin(); | 162 var min = this.dynamics_.findMin(); |
169 var max = this.dynamics_.findMax(); | 163 var max = this.dynamics_.findMax(); |
170 if (max != null && addr < (max.key + max.value.size) && addr >= min.key) { | 164 if (max != null && addr < (max.key + max.value.size) && addr >= min.key) { |
171 return this.findInTree_(this.dynamics_, addr); | 165 var dynaEntry = this.findInTree_(this.dynamics_, addr); |
166 if (dynaEntry == null) return null; | |
167 // Dedupe entry name. | |
168 if (!dynaEntry.nameUpdated_) { | |
Søren Thygesen Gjesse
2009/05/08 09:54:48
Is it alright to access 'private' members using ot
Mikhail Naganov
2009/05/08 11:25:40
I think so.
| |
169 dynaEntry.name = this.dynamicsNameGen_.getName(dynaEntry.name); | |
170 dynaEntry.nameUpdated_ = true; | |
171 } | |
172 return dynaEntry; | |
172 } | 173 } |
173 return null; | 174 return null; |
174 }; | 175 }; |
175 | 176 |
176 | 177 |
177 /** | 178 /** |
178 * Returns an array of all dynamic code entries, including deleted ones. | 179 * Returns an array of all dynamic code entries, including deleted ones. |
179 */ | 180 */ |
180 devtools.profiler.CodeMap.prototype.getAllDynamicEntries = function() { | 181 devtools.profiler.CodeMap.prototype.getAllDynamicEntries = function() { |
181 var dynamicEntries = this.dynamics_.exportValues(); | 182 return this.dynamics_.exportValues(); |
182 return dynamicEntries.concat(this.deleted_); | |
183 }; | 183 }; |
184 | 184 |
185 | 185 |
186 /** | 186 /** |
187 * Returns an array of all static code entries. | 187 * Returns an array of all static code entries. |
188 */ | 188 */ |
189 devtools.profiler.CodeMap.prototype.getAllStaticEntries = function() { | 189 devtools.profiler.CodeMap.prototype.getAllStaticEntries = function() { |
190 return this.statics_.exportValues(); | 190 return this.statics_.exportValues(); |
191 }; | 191 }; |
192 | 192 |
193 | 193 |
194 /** | 194 /** |
195 * Creates a code entry object. | 195 * Creates a code entry object. |
196 * | 196 * |
197 * @param {number} size Code entry size in bytes. | 197 * @param {number} size Code entry size in bytes. |
198 * @param {string} opt_name Code entry name. | 198 * @param {string} opt_name Code entry name. |
199 * @constructor | 199 * @constructor |
200 */ | 200 */ |
201 devtools.profiler.CodeMap.CodeEntry = function(size, opt_name) { | 201 devtools.profiler.CodeMap.CodeEntry = function(size, opt_name) { |
202 this.size = size; | 202 this.size = size; |
203 this.name = opt_name || ''; | 203 this.name = opt_name || ''; |
204 this.nameUpdated_ = false; | |
204 }; | 205 }; |
205 | 206 |
206 | 207 |
207 devtools.profiler.CodeMap.CodeEntry.prototype.getName = function() { | 208 devtools.profiler.CodeMap.CodeEntry.prototype.getName = function() { |
208 return this.name; | 209 return this.name; |
209 }; | 210 }; |
210 | 211 |
211 | 212 |
212 devtools.profiler.CodeMap.CodeEntry.prototype.toString = function() { | 213 devtools.profiler.CodeMap.CodeEntry.prototype.toString = function() { |
213 return this.name + ': ' + this.size.toString(16); | 214 return this.name + ': ' + this.size.toString(16); |
214 }; | 215 }; |
215 | 216 |
216 | 217 |
217 devtools.profiler.CodeMap.NameGenerator = function() { | 218 devtools.profiler.CodeMap.NameGenerator = function() { |
218 this.knownNames_ = []; | 219 this.knownNames_ = []; |
219 }; | 220 }; |
220 | 221 |
221 | 222 |
222 devtools.profiler.CodeMap.NameGenerator.prototype.getName = function(name) { | 223 devtools.profiler.CodeMap.NameGenerator.prototype.getName = function(name) { |
223 if (!(name in this.knownNames_)) { | 224 if (!(name in this.knownNames_)) { |
224 this.knownNames_[name] = 0; | 225 this.knownNames_[name] = 0; |
225 return name; | 226 return name; |
226 } | 227 } |
227 var count = ++this.knownNames_[name]; | 228 var count = ++this.knownNames_[name]; |
228 return name + ' {' + count + '}'; | 229 return name + ' {' + count + '}'; |
229 }; | 230 }; |
OLD | NEW |