| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // As code and functions are in the same address space, | 155 // As code and functions are in the same address space, |
| 156 // it is safe to put them in a single code map. | 156 // it is safe to put them in a single code map. |
| 157 var func = this.codeMap_.findDynamicEntryByStartAddress(funcAddr); | 157 var func = this.codeMap_.findDynamicEntryByStartAddress(funcAddr); |
| 158 if (!func) { | 158 if (!func) { |
| 159 func = new Profile.FunctionEntry(name); | 159 func = new Profile.FunctionEntry(name); |
| 160 this.codeMap_.addCode(funcAddr, func); | 160 this.codeMap_.addCode(funcAddr, func); |
| 161 } else if (func.name !== name) { | 161 } else if (func.name !== name) { |
| 162 // Function object has been overwritten with a new one. | 162 // Function object has been overwritten with a new one. |
| 163 func.name = name; | 163 func.name = name; |
| 164 } | 164 } |
| 165 var entry = new Profile.DynamicFuncCodeEntry(size, type, func, state); | 165 var entry = this.codeMap_.findDynamicEntryByStartAddress(start); |
| 166 this.codeMap_.addCode(start, entry); | 166 if (entry) { |
| 167 if (entry.size === size && entry.func === func) { |
| 168 // Entry state has changed. |
| 169 entry.state = state; |
| 170 } |
| 171 } else { |
| 172 entry = new Profile.DynamicFuncCodeEntry(size, type, func, state); |
| 173 this.codeMap_.addCode(start, entry); |
| 174 } |
| 167 return entry; | 175 return entry; |
| 168 }; | 176 }; |
| 169 | 177 |
| 170 | 178 |
| 171 /** | 179 /** |
| 172 * Reports about moving of a dynamic code entry. | 180 * Reports about moving of a dynamic code entry. |
| 173 * | 181 * |
| 174 * @param {number} from Current code entry address. | 182 * @param {number} from Current code entry address. |
| 175 * @param {number} to New code entry address. | 183 * @param {number} to New code entry address. |
| 176 */ | 184 */ |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } else { | 375 } else { |
| 368 // Propagate weights so percents can be calculated correctly. | 376 // Propagate weights so percents can be calculated correctly. |
| 369 counters.getRoot().selfWeight = root.selfWeight; | 377 counters.getRoot().selfWeight = root.selfWeight; |
| 370 counters.getRoot().totalWeight = root.totalWeight; | 378 counters.getRoot().totalWeight = root.totalWeight; |
| 371 } | 379 } |
| 372 return counters; | 380 return counters; |
| 373 }; | 381 }; |
| 374 | 382 |
| 375 | 383 |
| 376 /** | 384 /** |
| 385 * Cleans up function entries that are not referenced by code entries. |
| 386 */ |
| 387 Profile.prototype.cleanUpFuncEntries = function() { |
| 388 var referencedFuncEntries = []; |
| 389 var entries = this.codeMap_.getAllDynamicEntriesWithAddresses(); |
| 390 for (var i = 0, l = entries.length; i < l; ++i) { |
| 391 if (entries[i][1].constructor === Profile.FunctionEntry) { |
| 392 entries[i][1].used = false; |
| 393 } |
| 394 } |
| 395 for (var i = 0, l = entries.length; i < l; ++i) { |
| 396 if ("func" in entries[i][1]) { |
| 397 entries[i][1].func.used = true; |
| 398 } |
| 399 } |
| 400 for (var i = 0, l = entries.length; i < l; ++i) { |
| 401 if (entries[i][1].constructor === Profile.FunctionEntry && |
| 402 !entries[i][1].used) { |
| 403 this.codeMap_.deleteCode(entries[i][0]); |
| 404 } |
| 405 } |
| 406 }; |
| 407 |
| 408 |
| 409 /** |
| 377 * Creates a dynamic code entry. | 410 * Creates a dynamic code entry. |
| 378 * | 411 * |
| 379 * @param {number} size Code size. | 412 * @param {number} size Code size. |
| 380 * @param {string} type Code type. | 413 * @param {string} type Code type. |
| 381 * @param {string} name Function name. | 414 * @param {string} name Function name. |
| 382 * @constructor | 415 * @constructor |
| 383 */ | 416 */ |
| 384 Profile.DynamicCodeEntry = function(size, type, name) { | 417 Profile.DynamicCodeEntry = function(size, type, name) { |
| 385 CodeMap.CodeEntry.call(this, size, name); | 418 CodeMap.CodeEntry.call(this, size, name); |
| 386 this.type = type; | 419 this.type = type; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 401 Profile.DynamicCodeEntry.prototype.getRawName = function() { | 434 Profile.DynamicCodeEntry.prototype.getRawName = function() { |
| 402 return this.name; | 435 return this.name; |
| 403 }; | 436 }; |
| 404 | 437 |
| 405 | 438 |
| 406 Profile.DynamicCodeEntry.prototype.isJSFunction = function() { | 439 Profile.DynamicCodeEntry.prototype.isJSFunction = function() { |
| 407 return false; | 440 return false; |
| 408 }; | 441 }; |
| 409 | 442 |
| 410 | 443 |
| 444 Profile.DynamicCodeEntry.prototype.toString = function() { |
| 445 return this.getName() + ': ' + this.size.toString(16); |
| 446 }; |
| 447 |
| 448 |
| 411 /** | 449 /** |
| 412 * Creates a dynamic code entry. | 450 * Creates a dynamic code entry. |
| 413 * | 451 * |
| 414 * @param {number} size Code size. | 452 * @param {number} size Code size. |
| 415 * @param {string} type Code type. | 453 * @param {string} type Code type. |
| 416 * @param {Profile.FunctionEntry} func Shared function entry. | 454 * @param {Profile.FunctionEntry} func Shared function entry. |
| 417 * @param {Profile.CodeState} state Code optimization state. | 455 * @param {Profile.CodeState} state Code optimization state. |
| 418 * @constructor | 456 * @constructor |
| 419 */ | 457 */ |
| 420 Profile.DynamicFuncCodeEntry = function(size, type, func, state) { | 458 Profile.DynamicFuncCodeEntry = function(size, type, func, state) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 441 Profile.DynamicFuncCodeEntry.prototype.getRawName = function() { | 479 Profile.DynamicFuncCodeEntry.prototype.getRawName = function() { |
| 442 return this.func.getName(); | 480 return this.func.getName(); |
| 443 }; | 481 }; |
| 444 | 482 |
| 445 | 483 |
| 446 Profile.DynamicFuncCodeEntry.prototype.isJSFunction = function() { | 484 Profile.DynamicFuncCodeEntry.prototype.isJSFunction = function() { |
| 447 return true; | 485 return true; |
| 448 }; | 486 }; |
| 449 | 487 |
| 450 | 488 |
| 489 Profile.DynamicFuncCodeEntry.prototype.toString = function() { |
| 490 return this.getName() + ': ' + this.size.toString(16); |
| 491 }; |
| 492 |
| 493 |
| 451 /** | 494 /** |
| 452 * Creates a shared function object entry. | 495 * Creates a shared function object entry. |
| 453 * | 496 * |
| 454 * @param {string} name Function name. | 497 * @param {string} name Function name. |
| 455 * @constructor | 498 * @constructor |
| 456 */ | 499 */ |
| 457 Profile.FunctionEntry = function(name) { | 500 Profile.FunctionEntry = function(name) { |
| 458 CodeMap.CodeEntry.call(this, 0, name); | 501 CodeMap.CodeEntry.call(this, 0, name); |
| 459 }; | 502 }; |
| 460 | 503 |
| 461 | 504 |
| 462 /** | 505 /** |
| 463 * Returns node name. | 506 * Returns node name. |
| 464 */ | 507 */ |
| 465 Profile.FunctionEntry.prototype.getName = function() { | 508 Profile.FunctionEntry.prototype.getName = function() { |
| 466 var name = this.name; | 509 var name = this.name; |
| 467 if (name.length == 0) { | 510 if (name.length == 0) { |
| 468 name = '<anonymous>'; | 511 name = '<anonymous>'; |
| 469 } else if (name.charAt(0) == ' ') { | 512 } else if (name.charAt(0) == ' ') { |
| 470 // An anonymous function with location: " aaa.js:10". | 513 // An anonymous function with location: " aaa.js:10". |
| 471 name = '<anonymous>' + name; | 514 name = '<anonymous>' + name; |
| 472 } | 515 } |
| 473 return name; | 516 return name; |
| 474 }; | 517 }; |
| 475 | 518 |
| 519 Profile.FunctionEntry.prototype.toString = CodeMap.CodeEntry.prototype.toString; |
| 476 | 520 |
| 477 /** | 521 /** |
| 478 * Constructs a call graph. | 522 * Constructs a call graph. |
| 479 * | 523 * |
| 480 * @constructor | 524 * @constructor |
| 481 */ | 525 */ |
| 482 function CallTree() { | 526 function CallTree() { |
| 483 this.root_ = new CallTree.Node( | 527 this.root_ = new CallTree.Node( |
| 484 CallTree.ROOT_NODE_LABEL); | 528 CallTree.ROOT_NODE_LABEL); |
| 485 }; | 529 }; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 labels, opt_f) { | 786 labels, opt_f) { |
| 743 for (var pos = 0, curr = this; pos < labels.length && curr != null; pos++) { | 787 for (var pos = 0, curr = this; pos < labels.length && curr != null; pos++) { |
| 744 var child = curr.findChild(labels[pos]); | 788 var child = curr.findChild(labels[pos]); |
| 745 if (opt_f) { | 789 if (opt_f) { |
| 746 opt_f(child, pos); | 790 opt_f(child, pos); |
| 747 } | 791 } |
| 748 curr = child; | 792 curr = child; |
| 749 } | 793 } |
| 750 return curr; | 794 return curr; |
| 751 }; | 795 }; |
| OLD | NEW |