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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 1 << CodeMap.PAGE_ALIGNMENT; | 72 1 << CodeMap.PAGE_ALIGNMENT; |
73 | 73 |
74 | 74 |
75 /** | 75 /** |
76 * Adds a dynamic (i.e. moveable and discardable) code entry. | 76 * Adds a dynamic (i.e. moveable and discardable) code entry. |
77 * | 77 * |
78 * @param {number} start The starting address. | 78 * @param {number} start The starting address. |
79 * @param {CodeMap.CodeEntry} codeEntry Code entry object. | 79 * @param {CodeMap.CodeEntry} codeEntry Code entry object. |
80 */ | 80 */ |
81 CodeMap.prototype.addCode = function(start, codeEntry) { | 81 CodeMap.prototype.addCode = function(start, codeEntry) { |
82 this.removeAllCoveredNodes_(this.dynamics_, start, start + codeEntry.size); | 82 this.deleteAllCoveredNodes_(this.dynamics_, start, start + codeEntry.size); |
83 this.dynamics_.insert(start, codeEntry); | 83 this.dynamics_.insert(start, codeEntry); |
84 }; | 84 }; |
85 | 85 |
86 | 86 |
87 /** | 87 /** |
88 * Moves a dynamic code entry. Throws an exception if there is no dynamic | 88 * Moves a dynamic code entry. Throws an exception if there is no dynamic |
89 * code entry with the specified starting address. | 89 * code entry with the specified starting address. |
90 * | 90 * |
91 * @param {number} from The starting address of the entry being moved. | 91 * @param {number} from The starting address of the entry being moved. |
92 * @param {number} to The destination address. | 92 * @param {number} to The destination address. |
93 */ | 93 */ |
94 CodeMap.prototype.moveCode = function(from, to) { | 94 CodeMap.prototype.moveCode = function(from, to) { |
95 if (from === to) return; | 95 if (from === to) return; |
96 var removedNode = this.dynamics_.remove(from); | 96 var removedNode = this.dynamics_.remove(from); |
97 this.removeAllCoveredNodes_(this.dynamics_, to, to + removedNode.value.size); | 97 this.deleteAllCoveredNodes_(this.dynamics_, to, to + removedNode.value.size); |
98 this.dynamics_.insert(to, removedNode.value); | 98 this.dynamics_.insert(to, removedNode.value); |
99 }; | 99 }; |
100 | 100 |
101 | 101 |
102 /** | 102 /** |
103 * Discards a dynamic code entry. Throws an exception if there is no dynamic | 103 * Discards a dynamic code entry. Throws an exception if there is no dynamic |
104 * code entry with the specified starting address. | 104 * code entry with the specified starting address. |
105 * | 105 * |
106 * @param {number} start The starting address of the entry being deleted. | 106 * @param {number} start The starting address of the entry being deleted. |
107 */ | 107 */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 for (var addr = start; addr <= end; | 142 for (var addr = start; addr <= end; |
143 addr += CodeMap.PAGE_SIZE) { | 143 addr += CodeMap.PAGE_SIZE) { |
144 this.pages_[addr >>> CodeMap.PAGE_ALIGNMENT] = 1; | 144 this.pages_[addr >>> CodeMap.PAGE_ALIGNMENT] = 1; |
145 } | 145 } |
146 }; | 146 }; |
147 | 147 |
148 | 148 |
149 /** | 149 /** |
150 * @private | 150 * @private |
151 */ | 151 */ |
| 152 CodeMap.prototype.deleteAllCoveredNodes_ = function(tree, start, end) { |
| 153 var to_delete = []; |
| 154 var addr = end - 1; |
| 155 while (addr >= start) { |
| 156 var node = tree.findGreatestLessThan(addr); |
| 157 if (!node) break; |
| 158 var start2 = node.key, end2 = start2 + node.value.size; |
| 159 if (start2 < end && start < end2) to_delete.push(start2); |
| 160 addr = start2 - 1; |
| 161 } |
| 162 for (var i = 0, l = to_delete.length; i < l; ++i) tree.remove(to_delete[i]); |
| 163 }; |
| 164 |
| 165 |
| 166 /** |
| 167 * @private |
| 168 */ |
152 CodeMap.prototype.isAddressBelongsTo_ = function(addr, node) { | 169 CodeMap.prototype.isAddressBelongsTo_ = function(addr, node) { |
153 return addr >= node.key && addr < (node.key + node.value.size); | 170 return addr >= node.key && addr < (node.key + node.value.size); |
154 }; | 171 }; |
155 | 172 |
156 | 173 |
157 /** | |
158 * @private | |
159 */ | |
160 CodeMap.prototype.findAllCoveredNodes_ = function(tree, start, end) { | |
161 var result = []; | |
162 var addr = end - 1; | |
163 while (addr >= start) { | |
164 var node = tree.findGreatestLessThan(addr); | |
165 if (!node) break; | |
166 var start2 = node.key, end2 = node.key + node.value.size; | |
167 if (start2 < end && start < end2) { | |
168 // Node overlaps with the interval given | |
169 result.push(node); | |
170 } | |
171 addr = node.key - 1; | |
172 } | |
173 return result; | |
174 }; | |
175 | |
176 | |
177 /** | 174 /** |
178 * @private | 175 * @private |
179 */ | 176 */ |
180 CodeMap.prototype.findInTree_ = function(tree, addr) { | 177 CodeMap.prototype.findInTree_ = function(tree, addr) { |
181 var node = tree.findGreatestLessThan(addr); | 178 var node = tree.findGreatestLessThan(addr); |
182 return node && this.isAddressBelongsTo_(addr, node) ? node.value : null; | 179 return node && this.isAddressBelongsTo_(addr, node) ? node.value : null; |
183 }; | 180 }; |
184 | 181 |
185 | 182 |
186 /** | 183 /** |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 247 |
251 | 248 |
252 /** | 249 /** |
253 * Returns an array of all libraries entries. | 250 * Returns an array of all libraries entries. |
254 */ | 251 */ |
255 CodeMap.prototype.getAllLibrariesEntries = function() { | 252 CodeMap.prototype.getAllLibrariesEntries = function() { |
256 return this.libraries_.exportValues(); | 253 return this.libraries_.exportValues(); |
257 }; | 254 }; |
258 | 255 |
259 | 256 |
260 CodeMap.prototype.removeAllCoveredNodes_ = function(tree, start, end) { | |
261 var covered = this.findAllCoveredNodes_(tree, start, end); | |
262 for (var i = 0, l = covered.length; i < l; ++i) { | |
263 tree.remove(covered[i].key); | |
264 } | |
265 }; | |
266 | |
267 | |
268 /** | 257 /** |
269 * Creates a code entry object. | 258 * Creates a code entry object. |
270 * | 259 * |
271 * @param {number} size Code entry size in bytes. | 260 * @param {number} size Code entry size in bytes. |
272 * @param {string} opt_name Code entry name. | 261 * @param {string} opt_name Code entry name. |
273 * @constructor | 262 * @constructor |
274 */ | 263 */ |
275 CodeMap.CodeEntry = function(size, opt_name) { | 264 CodeMap.CodeEntry = function(size, opt_name) { |
276 this.size = size; | 265 this.size = size; |
277 this.name = opt_name || ''; | 266 this.name = opt_name || ''; |
(...skipping 17 matching lines...) Expand all Loading... |
295 | 284 |
296 | 285 |
297 CodeMap.NameGenerator.prototype.getName = function(name) { | 286 CodeMap.NameGenerator.prototype.getName = function(name) { |
298 if (!(name in this.knownNames_)) { | 287 if (!(name in this.knownNames_)) { |
299 this.knownNames_[name] = 0; | 288 this.knownNames_[name] = 0; |
300 return name; | 289 return name; |
301 } | 290 } |
302 var count = ++this.knownNames_[name]; | 291 var count = ++this.knownNames_[name]; |
303 return name + ' {' + count + '}'; | 292 return name + ' {' + count + '}'; |
304 }; | 293 }; |
OLD | NEW |