| 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 30 matching lines...) Expand all Loading... |
| 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 * Name generator for entries having duplicate names. | 46 * Name generator for entries having duplicate names. |
| 47 */ | 47 */ |
| 48 this.dynamicsNameGen_ = new devtools.profiler.CodeMap.NameGenerator(); | 48 this.dynamicsNameGen_ = new devtools.profiler.CodeMap.NameGenerator(); |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * Static code entries. Used for libraries code. | 51 * Static code entries. Used for statically compiled code. |
| 52 */ | 52 */ |
| 53 this.statics_ = new goog.structs.SplayTree(); | 53 this.statics_ = new goog.structs.SplayTree(); |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Libraries entries. Used for the whole static code libraries. |
| 57 */ |
| 58 this.libraries_ = new goog.structs.SplayTree(); |
| 59 |
| 60 /** |
| 56 * Map of memory pages occupied with static code. | 61 * Map of memory pages occupied with static code. |
| 57 */ | 62 */ |
| 58 this.pages_ = []; | 63 this.pages_ = []; |
| 59 }; | 64 }; |
| 60 | 65 |
| 61 | 66 |
| 62 /** | 67 /** |
| 63 * The number of alignment bits in a page address. | 68 * The number of alignment bits in a page address. |
| 64 */ | 69 */ |
| 65 devtools.profiler.CodeMap.PAGE_ALIGNMENT = 12; | 70 devtools.profiler.CodeMap.PAGE_ALIGNMENT = 12; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 * code entry with the specified starting address. | 106 * code entry with the specified starting address. |
| 102 * | 107 * |
| 103 * @param {number} start The starting address of the entry being deleted. | 108 * @param {number} start The starting address of the entry being deleted. |
| 104 */ | 109 */ |
| 105 devtools.profiler.CodeMap.prototype.deleteCode = function(start) { | 110 devtools.profiler.CodeMap.prototype.deleteCode = function(start) { |
| 106 var removedNode = this.dynamics_.remove(start); | 111 var removedNode = this.dynamics_.remove(start); |
| 107 }; | 112 }; |
| 108 | 113 |
| 109 | 114 |
| 110 /** | 115 /** |
| 116 * Adds a library entry. |
| 117 * |
| 118 * @param {number} start The starting address. |
| 119 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. |
| 120 */ |
| 121 devtools.profiler.CodeMap.prototype.addLibrary = function( |
| 122 start, codeEntry) { |
| 123 this.markPages_(start, start + codeEntry.size); |
| 124 this.libraries_.insert(start, codeEntry); |
| 125 }; |
| 126 |
| 127 |
| 128 /** |
| 111 * Adds a static code entry. | 129 * Adds a static code entry. |
| 112 * | 130 * |
| 113 * @param {number} start The starting address. | 131 * @param {number} start The starting address. |
| 114 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. | 132 * @param {devtools.profiler.CodeMap.CodeEntry} codeEntry Code entry object. |
| 115 */ | 133 */ |
| 116 devtools.profiler.CodeMap.prototype.addStaticCode = function( | 134 devtools.profiler.CodeMap.prototype.addStaticCode = function( |
| 117 start, codeEntry) { | 135 start, codeEntry) { |
| 118 this.markPages_(start, start + codeEntry.size); | |
| 119 this.statics_.insert(start, codeEntry); | 136 this.statics_.insert(start, codeEntry); |
| 120 }; | 137 }; |
| 121 | 138 |
| 122 | 139 |
| 123 /** | 140 /** |
| 124 * @private | 141 * @private |
| 125 */ | 142 */ |
| 126 devtools.profiler.CodeMap.prototype.markPages_ = function(start, end) { | 143 devtools.profiler.CodeMap.prototype.markPages_ = function(start, end) { |
| 127 for (var addr = start; addr <= end; | 144 for (var addr = start; addr <= end; |
| 128 addr += devtools.profiler.CodeMap.PAGE_SIZE) { | 145 addr += devtools.profiler.CodeMap.PAGE_SIZE) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 150 | 167 |
| 151 /** | 168 /** |
| 152 * Finds a code entry that contains the specified address. Both static and | 169 * Finds a code entry that contains the specified address. Both static and |
| 153 * dynamic code entries are considered. | 170 * dynamic code entries are considered. |
| 154 * | 171 * |
| 155 * @param {number} addr Address. | 172 * @param {number} addr Address. |
| 156 */ | 173 */ |
| 157 devtools.profiler.CodeMap.prototype.findEntry = function(addr) { | 174 devtools.profiler.CodeMap.prototype.findEntry = function(addr) { |
| 158 var pageAddr = addr >>> devtools.profiler.CodeMap.PAGE_ALIGNMENT; | 175 var pageAddr = addr >>> devtools.profiler.CodeMap.PAGE_ALIGNMENT; |
| 159 if (pageAddr in this.pages_) { | 176 if (pageAddr in this.pages_) { |
| 160 return this.findInTree_(this.statics_, addr); | 177 // Static code entries can contain "holes" of unnamed code. |
| 178 // In this case, the whole library is assigned to this address. |
| 179 return this.findInTree_(this.statics_, addr) || |
| 180 this.findInTree_(this.libraries_, addr); |
| 161 } | 181 } |
| 162 var min = this.dynamics_.findMin(); | 182 var min = this.dynamics_.findMin(); |
| 163 var max = this.dynamics_.findMax(); | 183 var max = this.dynamics_.findMax(); |
| 164 if (max != null && addr < (max.key + max.value.size) && addr >= min.key) { | 184 if (max != null && addr < (max.key + max.value.size) && addr >= min.key) { |
| 165 var dynaEntry = this.findInTree_(this.dynamics_, addr); | 185 var dynaEntry = this.findInTree_(this.dynamics_, addr); |
| 166 if (dynaEntry == null) return null; | 186 if (dynaEntry == null) return null; |
| 167 // Dedupe entry name. | 187 // Dedupe entry name. |
| 168 if (!dynaEntry.nameUpdated_) { | 188 if (!dynaEntry.nameUpdated_) { |
| 169 dynaEntry.name = this.dynamicsNameGen_.getName(dynaEntry.name); | 189 dynaEntry.name = this.dynamicsNameGen_.getName(dynaEntry.name); |
| 170 dynaEntry.nameUpdated_ = true; | 190 dynaEntry.nameUpdated_ = true; |
| 171 } | 191 } |
| 172 return dynaEntry; | 192 return dynaEntry; |
| 173 } | 193 } |
| 174 return null; | 194 return null; |
| 175 }; | 195 }; |
| 176 | 196 |
| 177 | 197 |
| 178 /** | 198 /** |
| 179 * Returns an array of all dynamic code entries, including deleted ones. | 199 * Returns an array of all dynamic code entries. |
| 180 */ | 200 */ |
| 181 devtools.profiler.CodeMap.prototype.getAllDynamicEntries = function() { | 201 devtools.profiler.CodeMap.prototype.getAllDynamicEntries = function() { |
| 182 return this.dynamics_.exportValues(); | 202 return this.dynamics_.exportValues(); |
| 183 }; | 203 }; |
| 184 | 204 |
| 185 | 205 |
| 186 /** | 206 /** |
| 187 * Returns an array of all static code entries. | 207 * Returns an array of all static code entries. |
| 188 */ | 208 */ |
| 189 devtools.profiler.CodeMap.prototype.getAllStaticEntries = function() { | 209 devtools.profiler.CodeMap.prototype.getAllStaticEntries = function() { |
| 190 return this.statics_.exportValues(); | 210 return this.statics_.exportValues(); |
| 191 }; | 211 }; |
| 192 | 212 |
| 193 | 213 |
| 194 /** | 214 /** |
| 215 * Returns an array of all libraries entries. |
| 216 */ |
| 217 devtools.profiler.CodeMap.prototype.getAllLibrariesEntries = function() { |
| 218 return this.libraries_.exportValues(); |
| 219 }; |
| 220 |
| 221 |
| 222 /** |
| 195 * Creates a code entry object. | 223 * Creates a code entry object. |
| 196 * | 224 * |
| 197 * @param {number} size Code entry size in bytes. | 225 * @param {number} size Code entry size in bytes. |
| 198 * @param {string} opt_name Code entry name. | 226 * @param {string} opt_name Code entry name. |
| 199 * @constructor | 227 * @constructor |
| 200 */ | 228 */ |
| 201 devtools.profiler.CodeMap.CodeEntry = function(size, opt_name) { | 229 devtools.profiler.CodeMap.CodeEntry = function(size, opt_name) { |
| 202 this.size = size; | 230 this.size = size; |
| 203 this.name = opt_name || ''; | 231 this.name = opt_name || ''; |
| 204 this.nameUpdated_ = false; | 232 this.nameUpdated_ = false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 221 | 249 |
| 222 | 250 |
| 223 devtools.profiler.CodeMap.NameGenerator.prototype.getName = function(name) { | 251 devtools.profiler.CodeMap.NameGenerator.prototype.getName = function(name) { |
| 224 if (!(name in this.knownNames_)) { | 252 if (!(name in this.knownNames_)) { |
| 225 this.knownNames_[name] = 0; | 253 this.knownNames_[name] = 0; |
| 226 return name; | 254 return name; |
| 227 } | 255 } |
| 228 var count = ++this.knownNames_[name]; | 256 var count = ++this.knownNames_[name]; |
| 229 return name + ' {' + count + '}'; | 257 return name + ' {' + count + '}'; |
| 230 }; | 258 }; |
| OLD | NEW |