Files
palemoon27/toolkit/devtools/server/actors/utils/stack.js
T
roytam1 d43d81d5ab import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1194905 - Build libvpx neon code without -mthumb and -mfloat-abi=softfp. r=mshal (24098bdb7)
- Remove spurious commandline.css from AF tree. (49cf2bb5c)
- Bug 969914 - Make developer toolbar match the light devtools theme when applied;r=jwalker,r=pbrosset (4047862bd)
- Bug 1152304 - Add displaying of block notes to dis() in the JS shell. (r=jimb) (9c1d7fa30)
- Bug 1126987 - Fix _lastEventSize initialization in stack.js. r=vporof (2083cb437)
- Bug 1140569 - Show async stacks attached to timeline markers. r=vporof (f05e1b60c)
- Bug 1141553 - Give function name the devtools-monospace class in the profiler r=vporof (0ca698ea2)
- Bug 1150112 - Markers overview should react to theme change, and other marker views now use CSS to automatically use theme change. r=vporof (6f72cde25)
- Bug 1050500 - Add entry reason to timeline marker. r=jsantell, r=smaug (db9cf8191)
- Bug 922221 - implement console.timeStamp(label) to create profile timeline markers. r=khuey (73e513562)
- Bug 1059908 - Merge FunctionType and FunctionSyntaxKind. r=efaust (2d765bde5)
- Bug 1059908 - Introduce a CONSTRUCTOR flag and make getter/setter/method non-constructable. r=efaust (fddb15f13)
- Bug 1162310 - Do not use nonexistent macro when XGILL_PLUGIN is defined, r=bhackett (57a5c2861)
- pointer style (55ec84b3b)
- Bug 1164602 - Replace js::NullPtr and JS::NullPtr with nullptr_t; r=sfink (9ae473e29)
- pointer style (7d735a2b9)
- pointer style (987c0128b)
- Bug 1135629 - Rename Register::code to Register::encoding for Assembler functions. r=jandem (cf915c814)
- pointer style (ac97f0d0b)
- Bug 1150337 - OdinMonkey: Optimize the full range of immediate offsets on x64. r=luke (fffb82aa6)
- fix typos (511e17002)
- pointer style (c1b54384c)
- Bug 1135707 - Fix interaction between Arm NOP fill and calculation of IonCache rejoin label r=jandem (306365ec4)
- pointer style (a8fe90ade)
- Bug 1166809 - Remove DispatchIonCache and RepatchIonCache. r=bhackett (9b8b02bf1)
- Bug 1147403 part 3 - Make IonSpewer work during off-thread compilation. r=h4writer Bug 1147403 part 3.1 - Replace newly added IonSpewPass after KeepAlive transform. r=KWierso (01bd66aa3)
- Bug 1147403 part 4 - Extract the printer from the serializer. r=h4writer (290a8887e)
- pointer style (fc70e6a1a)
- Bug 1147403 part 0 - Replace contextual information of dispatchHook by lambdas. r=shu (e177990e5)
- Bug 1065657 - Allow multiple Debuggers to track allocations at the same time. r=shu (66b5a3ba9)
- pointer style (bb317bb87)
- Bug 1147403 part 5 - Add Debugger::onIonCompilation hook. r=shu (c14a28de1)
- Bug 1147403 part 6 - Remove GetJitContext from serializing functions. r=h4writer (6d3d605a5)
- pointer style (b2ec50945)
- Bug 1147403 part 7 - Fix inIon, only reset the counter when the function is executed. r=jandem (cb6c180ef)
- Bug 1165392, Bug 1165463 - Various unboxed array fixes and optimizations, r=jandem. (28ec85004)
2020-09-16 21:57:22 +08:00

209 lines
6.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
let {Class} = require("sdk/core/heritage");
/**
* A helper class that stores stack frame objects. Each frame is
* assigned an index, and if a frame is added more than once, the same
* index is used. Users of the class can get an array of all frames
* that have been added.
*/
let StackFrameCache = Class({
/**
* Initialize this object.
*/
initialize: function() {
this._framesToCounts = null;
this._framesToIndices = null;
this._framesToForms = null;
this._lastEventSize = 0;
},
/**
* Prepare to accept frames.
*/
initFrames: function() {
if (this._framesToCounts) {
// The maps are already initialized.
return;
}
this._framesToCounts = new Map();
this._framesToIndices = new Map();
this._framesToForms = new Map();
this._lastEventSize = 0;
},
/**
* Forget all stored frames and reset to the initialized state.
*/
clearFrames: function() {
this._framesToCounts.clear();
this._framesToCounts = null;
this._framesToIndices.clear();
this._framesToIndices = null;
this._framesToForms.clear();
this._framesToForms = null;
this._lastEventSize = 0;
},
/**
* Add a frame to this stack frame cache, and return the index of
* the frame.
*/
addFrame: function(frame) {
this._assignFrameIndices(frame);
this._createFrameForms(frame);
this._countFrame(frame);
return this._framesToIndices.get(frame);
},
/**
* A helper method for the memory actor. This populates the packet
* object with "frames" and "counts" properties. Each of these
* properties will be an array indexed by frame ID. "frames" will
* contain frame objects (see makeEvent) and "counts" will hold
* allocation counts for each frame.
*
* @param packet
* The packet to update.
*
* @returns packet
*/
updateFramePacket: function(packet) {
// Now that we are guaranteed to have a form for every frame, we know the
// size the "frames" property's array must be. We use that information to
// create dense arrays even though we populate them out of order.
const size = this._framesToForms.size;
packet.frames = Array(size).fill(null);
packet.counts = Array(size).fill(0);
// Populate the "frames" and "counts" properties.
for (let [stack, index] of this._framesToIndices) {
packet.frames[index] = this._framesToForms.get(stack);
packet.counts[index] = this._framesToCounts.get(stack) || 0;
}
return packet;
},
/**
* If any new stack frames have been added to this cache since the
* last call to makeEvent (clearing the cache also resets the "last
* call"), then return a new array describing the new frames. If no
* new frames are available, return null.
*
* The frame cache assumes that the user of the cache keeps track of
* all previously-returned arrays and, in theory, concatenates them
* all to form a single array holding all frames added to the cache
* since the last reset. This concatenated array can be indexed by
* the frame ID. The array returned by this function, though, is
* dense and starts at 0.
*
* Each element in the array is an object of the form:
* {
* line: <line number for this frame>,
* column: <column number for this frame>,
* source: <filename string for this frame>,
* functionDisplayName: <this frame's inferred function name function or null>,
* parent: <frame ID -- an index into the concatenated array mentioned above>
* asyncCause: the async cause, or null
* asyncParent: <frame ID -- an index into the concatenated array mentioned above>
* }
*
* The intent of this approach is to make it simpler to efficiently
* send frame information over the debugging protocol, by only
* sending new frames.
*
* @returns array or null
*/
makeEvent: function() {
const size = this._framesToForms.size;
if (!size || size <= this._lastEventSize) {
return null;
}
let packet = Array(size - this._lastEventSize).fill(null);
for (let [stack, index] of this._framesToIndices) {
if (index >= this._lastEventSize) {
packet[index - this._lastEventSize] = this._framesToForms.get(stack);
}
}
this._lastEventSize = size;
return packet;
},
/**
* Assigns an index to the given frame and its parents, if an index is not
* already assigned.
*
* @param SavedFrame frame
* A frame to assign an index to.
*/
_assignFrameIndices: function(frame) {
if (this._framesToIndices.has(frame)) {
return;
}
if (frame) {
this._assignFrameIndices(frame.parent);
this._assignFrameIndices(frame.asyncParent);
}
const index = this._framesToIndices.size;
this._framesToIndices.set(frame, index);
},
/**
* Create the form for the given frame, if one doesn't already exist.
*
* @param SavedFrame frame
* A frame to create a form for.
*/
_createFrameForms: function(frame) {
if (this._framesToForms.has(frame)) {
return;
}
let form = null;
if (frame) {
form = {
line: frame.line,
column: frame.column,
source: frame.source,
functionDisplayName: frame.functionDisplayName,
parent: this._framesToIndices.get(frame.parent),
asyncParent: this._framesToIndices.get(frame.asyncParent),
asyncCause: frame.asyncCause
};
this._createFrameForms(frame.parent);
this._createFrameForms(frame.asyncParent);
}
this._framesToForms.set(frame, form);
},
/**
* Increment the allocation count for the provided frame.
*
* @param SavedFrame frame
* The frame whose allocation count should be incremented.
*/
_countFrame: function(frame) {
if (!this._framesToCounts.has(frame)) {
this._framesToCounts.set(frame, 1);
} else {
let count = this._framesToCounts.get(frame);
this._framesToCounts.set(frame, count + 1);
}
}
});
exports.StackFrameCache = StackFrameCache;