Skip to content

Commit

Permalink
Bug 1640211 - Use js::FunctionFlags for WrappedFunction instead of ma…
Browse files Browse the repository at this point in the history
…nually defining bit-fields. r=tcampbell

We don't want to keep a pointer to the native or jitInfo, because that would mean in the long run we would have
to include those into CacheIR as well. (We are going to construct WrappedFunction off-main thread in the future
and initialize the flags explicitly via CacheIR, probably)

Add *Unchecked helpers to JSFunction to avoid asserts reading flags from off-thread.

Differential Revision: https://phabricator.services.mozilla.com/D76531
  • Loading branch information
evilpie committed May 22, 2020
1 parent 1895e30 commit 0593336
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
10 changes: 1 addition & 9 deletions js/src/jit/MIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,15 +1454,7 @@ bool MParameter::congruentTo(const MDefinition* ins) const {
}

WrappedFunction::WrappedFunction(JSFunction* fun)
: fun_(fun),
nargs_(fun->nargs()),
isNative_(fun->isNative()),
isNativeWithJitEntry_(fun->isNativeWithJitEntry()),
isConstructor_(fun->isConstructor()),
isClassConstructor_(fun->isClassConstructor()),
isSelfHostedBuiltin_(fun->isSelfHostedBuiltin()),
isExtended_(fun->isExtended()),
hasJitInfo_(fun->hasJitInfo()) {}
: fun_(fun), nargs_(fun->nargs()), flags_(fun->flags()) {}

MCall* MCall::New(TempAllocator& alloc, JSFunction* target, size_t maxArgc,
size_t numActualArgs, bool construct, bool ignoresReturnValue,
Expand Down
35 changes: 17 additions & 18 deletions js/src/jit/MIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -2627,34 +2627,33 @@ class MInitElemGetterSetter
class WrappedFunction : public TempObject {
CompilerFunction fun_;
uint16_t nargs_;
bool isNative_ : 1;
bool isNativeWithJitEntry_ : 1;
bool isConstructor_ : 1;
bool isClassConstructor_ : 1;
bool isSelfHostedBuiltin_ : 1;
bool isExtended_ : 1;
bool hasJitInfo_ : 1;
js::FunctionFlags flags_;

public:
explicit WrappedFunction(JSFunction* fun);
size_t nargs() const { return nargs_; }

bool isNative() const { return isNative_; }
bool isNativeWithJitEntry() const { return isNativeWithJitEntry_; }
bool isNative() const { return flags_.isNative(); }
bool isNativeWithJitEntry() const { return flags_.isNativeWithJitEntry(); }
bool isNativeWithCppEntry() const {
return isNative() && !isNativeWithJitEntry();
}

bool isConstructor() const { return isConstructor_; }
bool isClassConstructor() const { return isClassConstructor_; }
bool isSelfHostedBuiltin() const { return isSelfHostedBuiltin_; }
bool isExtended() const { return isExtended_; }
bool hasJitInfo() const { return hasJitInfo_; }
bool isConstructor() const { return flags_.isConstructor(); }
bool isClassConstructor() const { return flags_.isClassConstructor(); }

// fun->native() and fun->jitInfo() can safely be called off-thread: these
// fields never change.
JSNative native() const { return fun_->native(); }
const JSJitInfo* jitInfo() const { return fun_->jitInfo(); }
// These fields never change, they can be accessed off-main thread.
JSNative native() const {
MOZ_ASSERT(isNative());
return fun_->nativeUnchecked();
}
bool hasJitInfo() const {
return flags_.isBuiltinNative() && fun_->jitInfoUnchecked();
}
const JSJitInfo* jitInfo() const {
MOZ_ASSERT(hasJitInfo());
return fun_->jitInfoUnchecked();
}

JSFunction* rawJSFunction() const { return fun_; }

Expand Down
8 changes: 8 additions & 0 deletions js/src/vm/JSFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ class JSFunction : public js::NativeObject {
MOZ_ASSERT(isNative());
return u.native.func_;
}
JSNative nativeUnchecked() const {
// Called by Ion off-main thread.
return u.native.func_;
}

JSNative maybeNative() const { return isInterpreted() ? nullptr : native(); }

Expand All @@ -536,6 +540,10 @@ class JSFunction : public js::NativeObject {
MOZ_ASSERT(hasJitInfo());
return u.native.extra.jitInfo_;
}
const JSJitInfo* jitInfoUnchecked() const {
// Called by Ion off-main thread.
return u.native.extra.jitInfo_;
}
void setJitInfo(const JSJitInfo* data) {
MOZ_ASSERT(isBuiltinNative());
u.native.extra.jitInfo_ = data;
Expand Down

0 comments on commit 0593336

Please sign in to comment.