зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1484382 - Use mozilla::ScopeExit in js/src r=jandem
Bug 1484382 - Use mozilla::ScopeExit in jit/JitFrames.cpp Bug 1484382 - Use mozilla::ScopeExit in vm/TypeInference.cpp Bug 1484382 - Use mozilla::ScopeExit in jit/JitcodeMap.cpp Bug 1484382 - Use mozilla::ScopeExit in jit/JitFrames.cpp Differential Revision: https://phabricator.services.mozilla.com/D3685 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
08f60bed59
Коммит
54781329d1
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "jit/JitFrames-inl.h"
|
||||
|
||||
#include "mozilla/ScopeExit.h"
|
||||
|
||||
#include "jsutil.h"
|
||||
|
||||
#include "gc/Marking.h"
|
||||
|
@ -570,53 +572,28 @@ HandleExceptionBaseline(JSContext* cx, const JSJitFrameIter& frame, ResumeFromEx
|
|||
OnLeaveBaselineFrame(cx, frame, pc, rfe, frameOk);
|
||||
}
|
||||
|
||||
struct AutoDeleteDebugModeOSRInfo
|
||||
{
|
||||
BaselineFrame* frame;
|
||||
explicit AutoDeleteDebugModeOSRInfo(BaselineFrame* frame) : frame(frame) { MOZ_ASSERT(frame); }
|
||||
~AutoDeleteDebugModeOSRInfo() { frame->deleteDebugModeOSRInfo(); }
|
||||
};
|
||||
|
||||
struct AutoResetLastProfilerFrameOnReturnFromException
|
||||
{
|
||||
JSContext* cx;
|
||||
ResumeFromException* rfe;
|
||||
|
||||
AutoResetLastProfilerFrameOnReturnFromException(JSContext* cx, ResumeFromException* rfe)
|
||||
: cx(cx), rfe(rfe) {}
|
||||
|
||||
~AutoResetLastProfilerFrameOnReturnFromException() {
|
||||
if (!cx->runtime()->jitRuntime()->isProfilerInstrumentationEnabled(cx->runtime()))
|
||||
return;
|
||||
|
||||
MOZ_ASSERT(cx->jitActivation == cx->profilingActivation());
|
||||
|
||||
void* lastProfilingFrame = getLastProfilingFrame();
|
||||
cx->jitActivation->setLastProfilingFrame(lastProfilingFrame);
|
||||
}
|
||||
|
||||
void* getLastProfilingFrame() {
|
||||
switch (rfe->kind) {
|
||||
case ResumeFromException::RESUME_ENTRY_FRAME:
|
||||
case ResumeFromException::RESUME_WASM:
|
||||
return nullptr;
|
||||
|
||||
// The following all return into baseline frames.
|
||||
case ResumeFromException::RESUME_CATCH:
|
||||
case ResumeFromException::RESUME_FINALLY:
|
||||
case ResumeFromException::RESUME_FORCED_RETURN:
|
||||
return rfe->framePointer + BaselineFrame::FramePointerOffset;
|
||||
|
||||
// When resuming into a bailed-out ion frame, use the bailout info to
|
||||
// find the frame we are resuming into.
|
||||
case ResumeFromException::RESUME_BAILOUT:
|
||||
return rfe->bailoutInfo->incomingStack;
|
||||
}
|
||||
|
||||
MOZ_CRASH("Invalid ResumeFromException type!");
|
||||
static void*
|
||||
GetLastProfilingFrame(ResumeFromException* rfe) {
|
||||
switch (rfe->kind) {
|
||||
case ResumeFromException::RESUME_ENTRY_FRAME:
|
||||
case ResumeFromException::RESUME_WASM:
|
||||
return nullptr;
|
||||
|
||||
// The following all return into baseline frames.
|
||||
case ResumeFromException::RESUME_CATCH:
|
||||
case ResumeFromException::RESUME_FINALLY:
|
||||
case ResumeFromException::RESUME_FORCED_RETURN:
|
||||
return rfe->framePointer + BaselineFrame::FramePointerOffset;
|
||||
|
||||
// When resuming into a bailed-out ion frame, use the bailout info to
|
||||
// find the frame we are resuming into.
|
||||
case ResumeFromException::RESUME_BAILOUT:
|
||||
return rfe->bailoutInfo->incomingStack;
|
||||
}
|
||||
};
|
||||
|
||||
MOZ_CRASH("Invalid ResumeFromException type!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
HandleExceptionWasm(JSContext* cx, wasm::WasmFrameIter* iter, ResumeFromException* rfe)
|
||||
|
@ -634,7 +611,15 @@ HandleException(ResumeFromException* rfe)
|
|||
JSContext* cx = TlsContext.get();
|
||||
TraceLoggerThread* logger = TraceLoggerForCurrentThread(cx);
|
||||
|
||||
AutoResetLastProfilerFrameOnReturnFromException profFrameReset(cx, rfe);
|
||||
auto resetProfilerFrame = mozilla::MakeScopeExit([=] {
|
||||
if (!cx->runtime()->jitRuntime()->isProfilerInstrumentationEnabled(cx->runtime()))
|
||||
return;
|
||||
|
||||
MOZ_ASSERT(cx->jitActivation == cx->profilingActivation());
|
||||
|
||||
void* lastProfilingFrame = GetLastProfilingFrame(rfe);
|
||||
cx->jitActivation->setLastProfilingFrame(lastProfilingFrame);
|
||||
});
|
||||
|
||||
rfe->kind = ResumeFromException::RESUME_ENTRY_FRAME;
|
||||
|
||||
|
@ -756,7 +741,9 @@ HandleException(ResumeFromException* rfe)
|
|||
// on-stack recompile info, we should free the allocated
|
||||
// RecompileInfo struct before we leave this block, as we will not
|
||||
// be returning to the recompile handler.
|
||||
AutoDeleteDebugModeOSRInfo deleteDebugModeOSRInfo(frame.baselineFrame());
|
||||
auto deleteDebugModeOSRInfo = mozilla::MakeScopeExit([=] {
|
||||
frame.baselineFrame()->deleteDebugModeOSRInfo();
|
||||
});
|
||||
|
||||
if (rfe->kind != ResumeFromException::RESUME_ENTRY_FRAME &&
|
||||
rfe->kind != ResumeFromException::RESUME_FORCED_RETURN)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
|
||||
#include "gc/Marking.h"
|
||||
|
@ -1425,26 +1426,6 @@ JitcodeRegionEntry::findPcOffset(uint32_t queryNativeOffset, uint32_t startPcOff
|
|||
return curPcOffset;
|
||||
}
|
||||
|
||||
typedef js::Vector<char*, 32, SystemAllocPolicy> ProfilingStringVector;
|
||||
|
||||
struct AutoFreeProfilingStrings {
|
||||
ProfilingStringVector& profilingStrings_;
|
||||
bool keep_;
|
||||
explicit AutoFreeProfilingStrings(ProfilingStringVector& vec)
|
||||
: profilingStrings_(vec),
|
||||
keep_(false)
|
||||
{}
|
||||
|
||||
void keepStrings() { keep_ = true; }
|
||||
|
||||
~AutoFreeProfilingStrings() {
|
||||
if (keep_)
|
||||
return;
|
||||
for (size_t i = 0; i < profilingStrings_.length(); i++)
|
||||
js_free(profilingStrings_[i]);
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
JitcodeIonTable::makeIonEntry(JSContext* cx, JitCode* code,
|
||||
uint32_t numScripts, JSScript** scripts,
|
||||
|
@ -1461,7 +1442,12 @@ JitcodeIonTable::makeIonEntry(JSContext* cx, JitCode* code,
|
|||
if (!profilingStrings.reserve(numScripts))
|
||||
return false;
|
||||
|
||||
AutoFreeProfilingStrings autoFreeProfilingStrings(profilingStrings);
|
||||
// Cleanup allocations on failure.
|
||||
auto autoFreeProfilingStrings = mozilla::MakeScopeExit([&] {
|
||||
for (auto elem: profilingStrings)
|
||||
js_free(elem);
|
||||
});
|
||||
|
||||
for (uint32_t i = 0; i < numScripts; i++) {
|
||||
char* str = JitcodeGlobalEntry::createScriptString(cx, scripts[i]);
|
||||
if (!str)
|
||||
|
@ -1475,8 +1461,8 @@ JitcodeIonTable::makeIonEntry(JSContext* cx, JitCode* code,
|
|||
if (!mem)
|
||||
return false;
|
||||
|
||||
// Keep allocated profiling strings on destruct.
|
||||
autoFreeProfilingStrings.keepStrings();
|
||||
// Keep allocated profiling strings.
|
||||
autoFreeProfilingStrings.release();
|
||||
|
||||
SizedScriptList* scriptList = new (mem) SizedScriptList(numScripts, scripts,
|
||||
&profilingStrings[0]);
|
||||
|
|
|
@ -144,7 +144,6 @@ class JitcodeGlobalEntry
|
|||
BytecodeLocation(JSScript* script, jsbytecode* pc) : script(script), pc(pc) {}
|
||||
};
|
||||
typedef Vector<BytecodeLocation, 0, SystemAllocPolicy> BytecodeLocationVector;
|
||||
typedef Vector<const char*, 0, SystemAllocPolicy> ProfileStringVector;
|
||||
|
||||
struct BaseEntry
|
||||
{
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* 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/. */
|
||||
|
||||
#include "mozilla/ScopeExit.h"
|
||||
|
||||
#include "gc/PublicIterators.h"
|
||||
#include "js/Wrapper.h"
|
||||
#include "proxy/DeadObjectProxy.h"
|
||||
|
@ -263,62 +265,40 @@ CanReify(HandleObject obj)
|
|||
return obj->is<PropertyIteratorObject>();
|
||||
}
|
||||
|
||||
struct AutoCloseIterator
|
||||
{
|
||||
AutoCloseIterator(JSContext* cx, PropertyIteratorObject* obj) : obj(cx, obj) {}
|
||||
|
||||
~AutoCloseIterator() {
|
||||
if (obj)
|
||||
CloseIterator(obj);
|
||||
}
|
||||
|
||||
void clear() { obj = nullptr; }
|
||||
|
||||
private:
|
||||
Rooted<PropertyIteratorObject*> obj;
|
||||
};
|
||||
|
||||
static JSObject*
|
||||
Reify(JSContext* cx, JS::Compartment* origin, HandleObject objp)
|
||||
Reify(JSContext* cx, JS::Compartment* origin, HandleObject iter)
|
||||
{
|
||||
Rooted<PropertyIteratorObject*> iterObj(cx, &objp->as<PropertyIteratorObject>());
|
||||
NativeIterator* ni = iterObj->getNativeIterator();
|
||||
// Ensure iterator gets closed.
|
||||
auto autoCloseIterator = mozilla::MakeScopeExit([=] {
|
||||
CloseIterator(iter);
|
||||
});
|
||||
|
||||
NativeIterator* ni = iter->as<PropertyIteratorObject>().getNativeIterator();
|
||||
RootedObject obj(cx, ni->objectBeingIterated());
|
||||
{
|
||||
AutoCloseIterator close(cx, iterObj);
|
||||
|
||||
/* Wrap the iteratee. */
|
||||
if (!origin->wrap(cx, &obj))
|
||||
// Wrap iteratee.
|
||||
if (!origin->wrap(cx, &obj))
|
||||
return nullptr;
|
||||
|
||||
// Wrap the elements in the iterator's snapshot.
|
||||
size_t length = ni->numKeys();
|
||||
AutoIdVector keys(cx);
|
||||
if (length > 0) {
|
||||
if (!keys.reserve(length))
|
||||
return nullptr;
|
||||
|
||||
/*
|
||||
* Wrap the elements in the iterator's snapshot.
|
||||
* N.B. the order of closing/creating iterators is important due to the
|
||||
* implicit cx->enumerators state.
|
||||
*/
|
||||
size_t length = ni->numKeys();
|
||||
AutoIdVector keys(cx);
|
||||
if (length > 0) {
|
||||
if (!keys.reserve(length))
|
||||
RootedId id(cx);
|
||||
RootedValue v(cx);
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
v.setString(ni->propertiesBegin()[i]);
|
||||
if (!ValueToId<CanGC>(cx, v, &id))
|
||||
return nullptr;
|
||||
RootedId id(cx);
|
||||
RootedValue v(cx);
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
v.setString(ni->propertiesBegin()[i]);
|
||||
if (!ValueToId<CanGC>(cx, v, &id))
|
||||
return nullptr;
|
||||
cx->markId(id);
|
||||
keys.infallibleAppend(id);
|
||||
}
|
||||
cx->markId(id);
|
||||
keys.infallibleAppend(id);
|
||||
}
|
||||
|
||||
close.clear();
|
||||
CloseIterator(iterObj);
|
||||
|
||||
obj = EnumeratedIdVectorToIterator(cx, obj, keys);
|
||||
}
|
||||
return obj;
|
||||
|
||||
// Return iterator in current compartment.
|
||||
return EnumeratedIdVectorToIterator(cx, obj, keys);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
|
||||
#include <new>
|
||||
|
@ -3818,25 +3819,6 @@ ChangeObjectFixedSlotCount(JSContext* cx, PlainObject* obj, gc::AllocKind allocK
|
|||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct DestroyTypeNewScript
|
||||
{
|
||||
JSContext* cx;
|
||||
ObjectGroup* group;
|
||||
|
||||
DestroyTypeNewScript(JSContext* cx, ObjectGroup* group)
|
||||
: cx(cx), group(group)
|
||||
{}
|
||||
|
||||
~DestroyTypeNewScript() {
|
||||
if (group)
|
||||
group->clearNewScript(cx);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool
|
||||
TypeNewScript::maybeAnalyze(JSContext* cx, ObjectGroup* group, bool* regenerate, bool force)
|
||||
{
|
||||
|
@ -3868,7 +3850,10 @@ TypeNewScript::maybeAnalyze(JSContext* cx, ObjectGroup* group, bool* regenerate,
|
|||
AutoEnterAnalysis enter(cx);
|
||||
|
||||
// Any failures after this point will clear out this TypeNewScript.
|
||||
DestroyTypeNewScript destroyNewScript(cx, group);
|
||||
auto destroyNewScript = mozilla::MakeScopeExit([&] {
|
||||
if (group)
|
||||
group->clearNewScript(cx);
|
||||
});
|
||||
|
||||
// Compute the greatest common shape prefix and the largest slot span of
|
||||
// the preliminary objects.
|
||||
|
@ -4003,7 +3988,7 @@ TypeNewScript::maybeAnalyze(JSContext* cx, ObjectGroup* group, bool* regenerate,
|
|||
// An unboxed layout was constructed for the group, and this has already
|
||||
// been hooked into it.
|
||||
MOZ_ASSERT(group->unboxedLayout(sweep).newScript() == this);
|
||||
destroyNewScript.group = nullptr;
|
||||
destroyNewScript.release();
|
||||
|
||||
// Clear out the template object, which is not used for TypeNewScripts
|
||||
// with an unboxed layout. Currently it is a mutant object with a
|
||||
|
@ -4026,7 +4011,7 @@ TypeNewScript::maybeAnalyze(JSContext* cx, ObjectGroup* group, bool* regenerate,
|
|||
// is needed.
|
||||
group->addDefiniteProperties(cx, templateObject()->lastProperty());
|
||||
|
||||
destroyNewScript.group = nullptr;
|
||||
destroyNewScript.release();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4065,7 +4050,7 @@ TypeNewScript::maybeAnalyze(JSContext* cx, ObjectGroup* group, bool* regenerate,
|
|||
initializedShape_ = prefixShape;
|
||||
initializedGroup_ = group;
|
||||
|
||||
destroyNewScript.group = nullptr;
|
||||
destroyNewScript.release();
|
||||
|
||||
if (regenerate)
|
||||
*regenerate = true;
|
||||
|
|
Загрузка…
Ссылка в новой задаче