Bug 983598 part 3 - Extract RecoverReader out of the SnapshotReader. r=jandem

This commit is contained in:
Nicolas B. Pierron 2014-03-28 00:17:30 -07:00
parent 6e4dd09031
commit 7369bb3078
5 changed files with 80 additions and 48 deletions

View File

@ -41,6 +41,7 @@ SnapshotIterator::SnapshotIterator(const IonBailoutIterator &iter)
iter.snapshotOffset(), iter.snapshotOffset(),
iter.ionScript()->snapshotsRVATableSize(), iter.ionScript()->snapshotsRVATableSize(),
iter.ionScript()->snapshotsListSize()), iter.ionScript()->snapshotsListSize()),
recover_(snapshot_),
fp_(iter.jsFrame()), fp_(iter.jsFrame()),
machine_(iter.machineState()), machine_(iter.machineState()),
ionScript_(iter.ionScript()) ionScript_(iter.ionScript())

View File

@ -249,6 +249,7 @@ class IonBailoutIterator;
class SnapshotIterator class SnapshotIterator
{ {
SnapshotReader snapshot_; SnapshotReader snapshot_;
RecoverReader recover_;
IonJSFrameLayout *fp_; IonJSFrameLayout *fp_;
MachineState machine_; MachineState machine_;
IonScript *ionScript_; IonScript *ionScript_;
@ -282,6 +283,7 @@ class SnapshotIterator
public: public:
// Handle iterating over RValueAllocations of the snapshots. // Handle iterating over RValueAllocations of the snapshots.
inline RValueAllocation readAllocation() { inline RValueAllocation readAllocation() {
MOZ_ASSERT(moreAllocations());
return snapshot_.readAllocation(); return snapshot_.readAllocation();
} }
Value skip() { Value skip() {
@ -290,18 +292,23 @@ class SnapshotIterator
} }
inline uint32_t allocations() const { inline uint32_t allocations() const {
return snapshot_.allocations(); return recover_.allocations();
} }
inline bool moreAllocations() const { inline bool moreAllocations() const {
return snapshot_.moreAllocations(); return recover_.moreAllocations(snapshot_);
} }
public: public:
// Exhibits frame properties contained in the snapshot. // Exhibits frame properties contained in the snapshot.
inline uint32_t pcOffset() const { inline uint32_t pcOffset() const {
return snapshot_.pcOffset(); return recover_.pcOffset();
} }
inline bool resumeAfter() const { inline bool resumeAfter() const {
// Inline frames are inlined on calls, which are considered as being
// resumed on the Call as baseline will push the pc once we return from
// the call.
if (moreFrames())
return false;
return snapshot_.resumeAfter(); return snapshot_.resumeAfter();
} }
inline BailoutKind bailoutKind() const { inline BailoutKind bailoutKind() const {
@ -311,13 +318,14 @@ class SnapshotIterator
public: public:
// Handle iterating over frames of the snapshots. // Handle iterating over frames of the snapshots.
inline void nextFrame() { inline void nextFrame() {
snapshot_.nextFrame(); // Reuse the Snapshot buffer.
recover_.nextFrame(snapshot_);
} }
inline bool moreFrames() const { inline bool moreFrames() const {
return snapshot_.moreFrames(); return recover_.moreFrames();
} }
inline uint32_t frameCount() const { inline uint32_t frameCount() const {
return snapshot_.frameCount(); return recover_.frameCount();
} }
public: public:

View File

@ -1295,6 +1295,7 @@ SnapshotIterator::SnapshotIterator(IonScript *ionScript, SnapshotOffset snapshot
snapshotOffset, snapshotOffset,
ionScript->snapshotsRVATableSize(), ionScript->snapshotsRVATableSize(),
ionScript->snapshotsListSize()), ionScript->snapshotsListSize()),
recover_(snapshot_),
fp_(fp), fp_(fp),
machine_(machine), machine_(machine),
ionScript_(ionScript) ionScript_(ionScript)
@ -1307,6 +1308,7 @@ SnapshotIterator::SnapshotIterator(const IonFrameIterator &iter)
iter.osiIndex()->snapshotOffset(), iter.osiIndex()->snapshotOffset(),
iter.ionScript()->snapshotsRVATableSize(), iter.ionScript()->snapshotsRVATableSize(),
iter.ionScript()->snapshotsListSize()), iter.ionScript()->snapshotsListSize()),
recover_(snapshot_),
fp_(iter.jsFrame()), fp_(iter.jsFrame()),
machine_(iter.machineState()), machine_(iter.machineState()),
ionScript_(iter.ionScript()) ionScript_(iter.ionScript())
@ -1315,6 +1317,7 @@ SnapshotIterator::SnapshotIterator(const IonFrameIterator &iter)
SnapshotIterator::SnapshotIterator() SnapshotIterator::SnapshotIterator()
: snapshot_(nullptr, 0, 0, 0), : snapshot_(nullptr, 0, 0, 0),
recover_(snapshot_),
fp_(nullptr), fp_(nullptr),
ionScript_(nullptr) ionScript_(nullptr)
{ {

View File

@ -455,15 +455,12 @@ SnapshotReader::SnapshotReader(const uint8_t *snapshots, uint32_t offset,
: reader_(snapshots + offset, snapshots + listSize), : reader_(snapshots + offset, snapshots + listSize),
allocReader_(snapshots + listSize, snapshots + listSize + RVATableSize), allocReader_(snapshots + listSize, snapshots + listSize + RVATableSize),
allocTable_(snapshots + listSize), allocTable_(snapshots + listSize),
allocCount_(0),
frameCount_(0),
allocRead_(0) allocRead_(0)
{ {
if (!snapshots) if (!snapshots)
return; return;
IonSpew(IonSpew_Snapshots, "Creating snapshot reader"); IonSpew(IonSpew_Snapshots, "Creating snapshot reader");
readSnapshotHeader(); readSnapshotHeader();
nextFrame();
} }
static const uint32_t BAILOUT_KIND_SHIFT = 0; static const uint32_t BAILOUT_KIND_SHIFT = 0;
@ -480,7 +477,6 @@ SnapshotReader::readSnapshotHeader()
JS_ASSERT(frameCount_ > 0); JS_ASSERT(frameCount_ > 0);
bailoutKind_ = BailoutKind((bits >> BAILOUT_KIND_SHIFT) & BAILOUT_KIND_MASK); bailoutKind_ = BailoutKind((bits >> BAILOUT_KIND_SHIFT) & BAILOUT_KIND_MASK);
resumeAfter_ = !!(bits & (1 << BAILOUT_RESUME_SHIFT)); resumeAfter_ = !!(bits & (1 << BAILOUT_RESUME_SHIFT));
framesRead_ = 0;
#ifdef TRACK_SNAPSHOTS #ifdef TRACK_SNAPSHOTS
pcOpcode_ = reader_.readUnsigned(); pcOpcode_ = reader_.readUnsigned();
@ -494,20 +490,6 @@ SnapshotReader::readSnapshotHeader()
frameCount_, bailoutKind_, resumeAfter_); frameCount_, bailoutKind_, resumeAfter_);
} }
void
SnapshotReader::readFrameHeader()
{
JS_ASSERT(moreFrames());
JS_ASSERT(allocRead_ == allocCount_);
pcOffset_ = reader_.readUnsigned();
allocCount_ = reader_.readUnsigned();
IonSpew(IonSpew_Snapshots, "Read pc offset %u, nslots %u", pcOffset_, allocCount_);
framesRead_++;
allocRead_ = 0;
}
#ifdef TRACK_SNAPSHOTS #ifdef TRACK_SNAPSHOTS
void void
SnapshotReader::spewBailingFrom() const SnapshotReader::spewBailingFrom() const
@ -527,7 +509,6 @@ SnapshotReader::spewBailingFrom() const
RValueAllocation RValueAllocation
SnapshotReader::readAllocation() SnapshotReader::readAllocation()
{ {
JS_ASSERT(allocRead_ < allocCount_);
IonSpew(IonSpew_Snapshots, "Reading slot %u", allocRead_); IonSpew(IonSpew_Snapshots, "Reading slot %u", allocRead_);
allocRead_++; allocRead_++;
@ -545,6 +526,31 @@ SnapshotWriter::init()
return allocMap_.init(32); return allocMap_.init(32);
} }
RecoverReader::RecoverReader(SnapshotReader &snapshot)
: frameCount_(0),
framesRead_(0),
allocCount_(0)
{
if (!snapshot.reader_.more())
return;
frameCount_ = snapshot.frameCount_;
readFrame(snapshot);
}
void
RecoverReader::readFrame(SnapshotReader &snapshot)
{
JS_ASSERT(moreFrames());
JS_ASSERT(snapshot.allocRead_ == allocCount_);
pcOffset_ = snapshot.reader_.readUnsigned();
allocCount_ = snapshot.reader_.readUnsigned();
IonSpew(IonSpew_Snapshots, "Read pc offset %u, nslots %u", pcOffset_, allocCount_);
framesRead_++;
snapshot.allocRead_ = 0;
}
SnapshotOffset SnapshotOffset
SnapshotWriter::startSnapshot(uint32_t frameCount, BailoutKind kind, bool resumeAfter) SnapshotWriter::startSnapshot(uint32_t frameCount, BailoutKind kind, bool resumeAfter)
{ {

View File

@ -356,21 +356,22 @@ class SnapshotWriter
} }
}; };
class RecoverReader;
// A snapshot reader reads the entries out of the compressed snapshot buffer in // A snapshot reader reads the entries out of the compressed snapshot buffer in
// a script. These entries describe the equivalent interpreter frames at a given // a script. These entries describe the equivalent interpreter frames at a given
// position in JIT code. Each entry is an Ion's value allocations, used to // position in JIT code. Each entry is an Ion's value allocations, used to
// recover the corresponding Value from an Ion frame. // recover the corresponding Value from an Ion frame.
class SnapshotReader class SnapshotReader
{ {
friend class RecoverReader;
CompactBufferReader reader_; CompactBufferReader reader_;
CompactBufferReader allocReader_; CompactBufferReader allocReader_;
const uint8_t* allocTable_; const uint8_t* allocTable_;
uint32_t pcOffset_; // Offset from script->code.
uint32_t allocCount_; // Number of slots.
uint32_t frameCount_; uint32_t frameCount_;
BailoutKind bailoutKind_; BailoutKind bailoutKind_;
uint32_t framesRead_; // Number of frame headers that have been read.
uint32_t allocRead_; // Number of slots that have been read. uint32_t allocRead_; // Number of slots that have been read.
bool resumeAfter_; bool resumeAfter_;
@ -394,35 +395,48 @@ class SnapshotReader
SnapshotReader(const uint8_t *snapshots, uint32_t offset, SnapshotReader(const uint8_t *snapshots, uint32_t offset,
uint32_t RVATableSize, uint32_t listSize); uint32_t RVATableSize, uint32_t listSize);
uint32_t allocations() const {
return allocCount_;
}
RValueAllocation readAllocation(); RValueAllocation readAllocation();
bool moreAllocations() const { BailoutKind bailoutKind() const {
return allocRead_ < allocCount_; return bailoutKind_;
}
bool resumeAfter() const {
return resumeAfter_;
}
};
class RecoverReader
{
uint32_t frameCount_;
uint32_t framesRead_; // Number of frame headers that have been read.
uint32_t pcOffset_; // Offset from script->code.
uint32_t allocCount_; // Number of slots.
private:
void readFrame(SnapshotReader &snapshot);
public:
RecoverReader(SnapshotReader &snapshot);
bool moreFrames() const {
return framesRead_ < frameCount_;
}
void nextFrame(SnapshotReader &snapshot) {
readFrame(snapshot);
}
uint32_t frameCount() const {
return frameCount_;
} }
uint32_t pcOffset() const { uint32_t pcOffset() const {
return pcOffset_; return pcOffset_;
} }
BailoutKind bailoutKind() const {
return bailoutKind_;
}
bool resumeAfter() const {
if (moreFrames())
return false;
return resumeAfter_;
}
bool moreFrames() const { uint32_t allocations() const {
return framesRead_ < frameCount_; return allocCount_;
} }
void nextFrame() { bool moreAllocations(const SnapshotReader &snapshot) const {
readFrameHeader(); return snapshot.allocRead_ < allocCount_;
}
uint32_t frameCount() const {
return frameCount_;
} }
}; };