2009-04-16 16:05:17 +00:00
|
|
|
// Copyright 2009 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a mapper that maps addresses into code entries.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
function CodeMap() {
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
|
|
|
* Dynamic code entries. Used for JIT compiled code.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
this.dynamics_ = new SplayTree();
|
2009-04-16 16:05:17 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-08 11:27:02 +00:00
|
|
|
* Name generator for entries having duplicate names.
|
2009-04-16 16:05:17 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
this.dynamicsNameGen_ = new CodeMap.NameGenerator();
|
2009-04-27 13:50:42 +00:00
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
2009-07-14 09:47:44 +00:00
|
|
|
* Static code entries. Used for statically compiled code.
|
2009-04-16 16:05:17 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
this.statics_ = new SplayTree();
|
2009-04-16 16:05:17 +00:00
|
|
|
|
2009-07-14 09:47:44 +00:00
|
|
|
/**
|
|
|
|
* Libraries entries. Used for the whole static code libraries.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
this.libraries_ = new SplayTree();
|
2009-07-14 09:47:44 +00:00
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
|
|
|
* Map of memory pages occupied with static code.
|
|
|
|
*/
|
|
|
|
this.pages_ = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of alignment bits in a page address.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.PAGE_ALIGNMENT = 12;
|
2009-04-16 16:05:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Page size in bytes.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.PAGE_SIZE =
|
|
|
|
1 << CodeMap.PAGE_ALIGNMENT;
|
2009-04-16 16:05:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a dynamic (i.e. moveable and discardable) code entry.
|
|
|
|
*
|
|
|
|
* @param {number} start The starting address.
|
2011-02-10 07:47:28 +00:00
|
|
|
* @param {CodeMap.CodeEntry} codeEntry Code entry object.
|
2009-04-16 16:05:17 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.addCode = function(start, codeEntry) {
|
2011-09-14 11:47:03 +00:00
|
|
|
this.deleteAllCoveredNodes_(this.dynamics_, start, start + codeEntry.size);
|
2009-04-16 16:05:17 +00:00
|
|
|
this.dynamics_.insert(start, codeEntry);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a dynamic code entry. Throws an exception if there is no dynamic
|
|
|
|
* code entry with the specified starting address.
|
|
|
|
*
|
|
|
|
* @param {number} from The starting address of the entry being moved.
|
|
|
|
* @param {number} to The destination address.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.moveCode = function(from, to) {
|
2009-04-16 16:05:17 +00:00
|
|
|
var removedNode = this.dynamics_.remove(from);
|
2011-09-14 11:47:03 +00:00
|
|
|
this.deleteAllCoveredNodes_(this.dynamics_, to, to + removedNode.value.size);
|
2009-04-16 16:05:17 +00:00
|
|
|
this.dynamics_.insert(to, removedNode.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Discards a dynamic code entry. Throws an exception if there is no dynamic
|
2009-05-08 11:27:02 +00:00
|
|
|
* code entry with the specified starting address.
|
2009-04-16 16:05:17 +00:00
|
|
|
*
|
|
|
|
* @param {number} start The starting address of the entry being deleted.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.deleteCode = function(start) {
|
2009-04-16 16:05:17 +00:00
|
|
|
var removedNode = this.dynamics_.remove(start);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-14 09:47:44 +00:00
|
|
|
/**
|
|
|
|
* Adds a library entry.
|
|
|
|
*
|
|
|
|
* @param {number} start The starting address.
|
2011-02-10 07:47:28 +00:00
|
|
|
* @param {CodeMap.CodeEntry} codeEntry Code entry object.
|
2009-07-14 09:47:44 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.addLibrary = function(
|
2009-07-14 09:47:44 +00:00
|
|
|
start, codeEntry) {
|
|
|
|
this.markPages_(start, start + codeEntry.size);
|
|
|
|
this.libraries_.insert(start, codeEntry);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
|
|
|
* Adds a static code entry.
|
|
|
|
*
|
|
|
|
* @param {number} start The starting address.
|
2011-02-10 07:47:28 +00:00
|
|
|
* @param {CodeMap.CodeEntry} codeEntry Code entry object.
|
2009-04-16 16:05:17 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.addStaticCode = function(
|
2009-04-16 16:05:17 +00:00
|
|
|
start, codeEntry) {
|
|
|
|
this.statics_.insert(start, codeEntry);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.markPages_ = function(start, end) {
|
2009-04-16 16:05:17 +00:00
|
|
|
for (var addr = start; addr <= end;
|
2011-02-10 07:47:28 +00:00
|
|
|
addr += CodeMap.PAGE_SIZE) {
|
|
|
|
this.pages_[addr >>> CodeMap.PAGE_ALIGNMENT] = 1;
|
2009-04-16 16:05:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-14 11:47:03 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
CodeMap.prototype.deleteAllCoveredNodes_ = function(tree, start, end) {
|
|
|
|
var to_delete = [];
|
|
|
|
var addr = end - 1;
|
|
|
|
while (addr >= start) {
|
|
|
|
var node = tree.findGreatestLessThan(addr);
|
|
|
|
if (!node) break;
|
|
|
|
var start2 = node.key, end2 = start2 + node.value.size;
|
|
|
|
if (start2 < end && start < end2) to_delete.push(start2);
|
|
|
|
addr = start2 - 1;
|
|
|
|
}
|
|
|
|
for (var i = 0, l = to_delete.length; i < l; ++i) tree.remove(to_delete[i]);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.isAddressBelongsTo_ = function(addr, node) {
|
2009-04-16 16:05:17 +00:00
|
|
|
return addr >= node.key && addr < (node.key + node.value.size);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.findInTree_ = function(tree, addr) {
|
2009-04-16 16:05:17 +00:00
|
|
|
var node = tree.findGreatestLessThan(addr);
|
2017-03-04 13:04:58 +00:00
|
|
|
return node && this.isAddressBelongsTo_(addr, node) ? node : null;
|
2009-04-16 16:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a code entry that contains the specified address. Both static and
|
2017-03-04 13:04:58 +00:00
|
|
|
* dynamic code entries are considered. Returns the code entry and the offset
|
|
|
|
* within the entry.
|
2009-04-16 16:05:17 +00:00
|
|
|
*
|
|
|
|
* @param {number} addr Address.
|
|
|
|
*/
|
2017-03-04 13:04:58 +00:00
|
|
|
CodeMap.prototype.findAddress = function(addr) {
|
2011-02-10 07:47:28 +00:00
|
|
|
var pageAddr = addr >>> CodeMap.PAGE_ALIGNMENT;
|
2009-04-16 16:05:17 +00:00
|
|
|
if (pageAddr in this.pages_) {
|
2009-07-14 09:47:44 +00:00
|
|
|
// Static code entries can contain "holes" of unnamed code.
|
|
|
|
// In this case, the whole library is assigned to this address.
|
2017-03-04 13:04:58 +00:00
|
|
|
var result = this.findInTree_(this.statics_, addr);
|
|
|
|
if (!result) {
|
|
|
|
result = this.findInTree_(this.libraries_, addr);
|
|
|
|
if (!result) return null;
|
|
|
|
}
|
|
|
|
return { entry : result.value, offset : addr - result.key };
|
2009-04-16 16:05:17 +00:00
|
|
|
}
|
|
|
|
var min = this.dynamics_.findMin();
|
|
|
|
var max = this.dynamics_.findMax();
|
|
|
|
if (max != null && addr < (max.key + max.value.size) && addr >= min.key) {
|
2009-05-08 11:27:02 +00:00
|
|
|
var dynaEntry = this.findInTree_(this.dynamics_, addr);
|
|
|
|
if (dynaEntry == null) return null;
|
|
|
|
// Dedupe entry name.
|
2017-03-04 13:04:58 +00:00
|
|
|
var entry = dynaEntry.value;
|
|
|
|
if (!entry.nameUpdated_) {
|
|
|
|
entry.name = this.dynamicsNameGen_.getName(entry.name);
|
|
|
|
entry.nameUpdated_ = true;
|
2009-05-08 11:27:02 +00:00
|
|
|
}
|
2017-03-04 13:04:58 +00:00
|
|
|
return { entry : entry, offset : addr - dynaEntry.key };
|
2009-04-16 16:05:17 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
/**
|
|
|
|
* Finds a code entry that contains the specified address. Both static and
|
|
|
|
* dynamic code entries are considered.
|
|
|
|
*
|
|
|
|
* @param {number} addr Address.
|
|
|
|
*/
|
|
|
|
CodeMap.prototype.findEntry = function(addr) {
|
|
|
|
var result = this.findAddress(addr);
|
|
|
|
return result ? result.entry : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
/**
|
|
|
|
* Returns a dynamic code entry using its starting address.
|
|
|
|
*
|
|
|
|
* @param {number} addr Address.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.findDynamicEntryByStartAddress =
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
function(addr) {
|
|
|
|
var node = this.dynamics_.find(addr);
|
|
|
|
return node ? node.value : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
2009-07-14 09:47:44 +00:00
|
|
|
* Returns an array of all dynamic code entries.
|
2009-04-16 16:05:17 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.getAllDynamicEntries = function() {
|
2009-05-08 11:27:02 +00:00
|
|
|
return this.dynamics_.exportValues();
|
2009-04-16 16:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-13 11:31:22 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of pairs of all dynamic code entries and their addresses.
|
|
|
|
*/
|
|
|
|
CodeMap.prototype.getAllDynamicEntriesWithAddresses = function() {
|
|
|
|
return this.dynamics_.exportKeysAndValues();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of all static code entries.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.getAllStaticEntries = function() {
|
2009-04-16 16:05:17 +00:00
|
|
|
return this.statics_.exportValues();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-28 06:56:35 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of pairs of all static code entries and their addresses.
|
|
|
|
*/
|
|
|
|
CodeMap.prototype.getAllStaticEntriesWithAddresses = function() {
|
|
|
|
return this.statics_.exportKeysAndValues();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-14 09:47:44 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of all libraries entries.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.prototype.getAllLibrariesEntries = function() {
|
2009-07-14 09:47:44 +00:00
|
|
|
return this.libraries_.exportValues();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-16 16:05:17 +00:00
|
|
|
/**
|
|
|
|
* Creates a code entry object.
|
|
|
|
*
|
|
|
|
* @param {number} size Code entry size in bytes.
|
|
|
|
* @param {string} opt_name Code entry name.
|
2014-10-17 15:44:02 +00:00
|
|
|
* @param {string} opt_type Code entry type, e.g. SHARED_LIB, CPP.
|
2009-04-16 16:05:17 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-10-17 15:44:02 +00:00
|
|
|
CodeMap.CodeEntry = function(size, opt_name, opt_type) {
|
2009-04-16 16:05:17 +00:00
|
|
|
this.size = size;
|
|
|
|
this.name = opt_name || '';
|
2014-10-17 15:44:02 +00:00
|
|
|
this.type = opt_type || '';
|
2009-05-08 11:27:02 +00:00
|
|
|
this.nameUpdated_ = false;
|
2009-04-16 16:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.CodeEntry.prototype.getName = function() {
|
2009-04-17 17:40:52 +00:00
|
|
|
return this.name;
|
|
|
|
};
|
|
|
|
|
2009-04-27 13:50:42 +00:00
|
|
|
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.CodeEntry.prototype.toString = function() {
|
2009-04-16 16:05:17 +00:00
|
|
|
return this.name + ': ' + this.size.toString(16);
|
|
|
|
};
|
2009-04-27 13:50:42 +00:00
|
|
|
|
|
|
|
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.NameGenerator = function() {
|
2009-11-25 16:39:18 +00:00
|
|
|
this.knownNames_ = {};
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-02-10 07:47:28 +00:00
|
|
|
CodeMap.NameGenerator.prototype.getName = function(name) {
|
2009-04-27 13:50:42 +00:00
|
|
|
if (!(name in this.knownNames_)) {
|
|
|
|
this.knownNames_[name] = 0;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
var count = ++this.knownNames_[name];
|
|
|
|
return name + ' {' + count + '}';
|
|
|
|
};
|