})();
-(function testDeadCodeCleanups() {
- var codeMap = new CodeMap();
- codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
- codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
- assertEntry(codeMap, 'code1', 0x1500);
- assertEntry(codeMap, 'code2', 0x1700);
- codeMap.moveCode(0x1500, 0x1700); // Deprecate code2.
- assertEntry(codeMap, 'code1', 0x1700);
- codeMap.addCode(0x1750, newCodeEntry(0x100, 'code3'));
- assertNoEntry(codeMap, 0x1700);
- assertEntry(codeMap, 'code3', 0x1750);
-})();
-
-
(function testDynamicNamesDuplicates() {
var codeMap = new CodeMap();
// Code entries with same names but different addresses.
* @param {CodeMap.CodeEntry} codeEntry Code entry object.
*/
CodeMap.prototype.addCode = function(start, codeEntry) {
- this.removeAllCoveredNodes_(this.dynamics_, start, start + codeEntry.size);
this.dynamics_.insert(start, codeEntry);
};
* @param {number} to The destination address.
*/
CodeMap.prototype.moveCode = function(from, to) {
- if (from === to) return;
var removedNode = this.dynamics_.remove(from);
- this.removeAllCoveredNodes_(this.dynamics_, to, to + removedNode.value.size);
this.dynamics_.insert(to, removedNode.value);
};
};
-/**
- * @private
- */
-CodeMap.prototype.findAllCoveredNodes_ = function(tree, start, end) {
- var result = [];
- var addr = end - 1;
- while (addr >= start) {
- var node = tree.findGreatestLessThan(addr);
- if (!node) break;
- var start2 = node.key, end2 = node.key + node.value.size;
- if (start2 < end && start < end2) {
- // Node overlaps with the interval given
- result.push(node);
- }
- addr = node.key - 1;
- }
- return result;
-};
-
-
/**
* @private
*/
};
-CodeMap.prototype.removeAllCoveredNodes_ = function(tree, start, end) {
- var covered = this.findAllCoveredNodes_(tree, start, end);
- for (var i = 0, l = covered.length; i < l; ++i) {
- tree.remove(covered[i].key);
- }
-};
-
-
/**
* Creates a code entry object.
*
*/
Profile.Operation = {
MOVE: 0,
- TICK: 1
+ DELETE: 1,
+ TICK: 2
};
func.name = name;
}
var entry = this.codeMap_.findDynamicEntryByStartAddress(start);
- if (entry && entry.size === size && entry.func === func) {
- // Entry state has changed.
- entry.state = state;
- return entry;
+ if (entry) {
+ if (entry.size === size && entry.func === func) {
+ // Entry state has changed.
+ entry.state = state;
+ }
+ } else {
+ entry = new Profile.DynamicFuncCodeEntry(size, type, func, state);
+ this.codeMap_.addCode(start, entry);
}
- entry = new Profile.DynamicFuncCodeEntry(size, type, func, state);
- this.codeMap_.addCode(start, entry);
return entry;
};
};
+/**
+ * Reports about deletion of a dynamic code entry.
+ *
+ * @param {number} start Starting address.
+ */
+Profile.prototype.deleteCode = function(start) {
+ try {
+ this.codeMap_.deleteCode(start);
+ } catch (e) {
+ this.handleUnknownCode(Profile.Operation.DELETE, start);
+ }
+};
+
+
/**
* Reports about moving of a dynamic code entry.
*
processor: this.processCodeCreation },
'code-move': { parsers: [parseInt, parseInt],
processor: this.processCodeMove },
- 'code-delete': null,
+ 'code-delete': { parsers: [parseInt],
+ processor: this.processCodeDelete },
'function-creation': null,
'function-move': null,
'function-delete': null,
print('Snapshot: Code move event for unknown code: 0x' +
addr.toString(16));
break;
+ case op.DELETE:
+ print('Snapshot: Code delete event for unknown code: 0x' +
+ addr.toString(16));
+ break;
}
};
};
+SnapshotLogProcessor.prototype.processCodeDelete = function(start) {
+ this.profile_.deleteCode(start);
+};
+
+
SnapshotLogProcessor.prototype.processSnapshotPosition = function(addr, pos) {
this.serializedEntries_[pos] = this.profile_.findEntry(addr);
};
processor: this.processCodeCreation },
'code-move': { parsers: [parseInt, parseInt],
processor: this.processCodeMove },
- 'code-delete': null,
+ 'code-delete': { parsers: [parseInt],
+ processor: this.processCodeDelete },
'sfi-move': { parsers: [parseInt, parseInt],
processor: this.processFunctionMove },
'snapshot-pos': { parsers: [parseInt, parseInt],
case op.MOVE:
print('Code move event for unknown code: 0x' + addr.toString(16));
break;
+ case op.DELETE:
+ print('Code delete event for unknown code: 0x' + addr.toString(16));
+ break;
case op.TICK:
// Only unknown PCs (the first frame) are reported as unaccounted,
// otherwise tick balance will be corrupted (this behavior is compatible
};
+TickProcessor.prototype.processCodeDelete = function(start) {
+ this.profile_.deleteCode(start);
+};
+
+
TickProcessor.prototype.processFunctionMove = function(from, to) {
this.profile_.moveFunc(from, to);
};