Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ ENV DEBIAN_FRONTEND=noninteractive

# Both archive.ubuntu.com and azure.archive.ubuntu.com have intermittently
# timed out from inside the GitHub-hosted docker-buildx network at different
# times. Prefer Azure (faster on Azure-hosted runners) but fall back to the
# canonical mirror if `apt-get update` can't reach it. arm64 uses
# ports.ubuntu.com which has been reachable, so leave it alone.
RUN sed -i 's|http://archive.ubuntu.com/ubuntu|http://azure.archive.ubuntu.com/ubuntu|g' /etc/apt/sources.list
# times, sometimes halfway through a step. Give apt both through its mirror
# method -- Azure first (faster on Azure-hosted runners), the canonical mirror
# as fallback -- so every individual fetch that fails on one, in any later
# `apt-get` too (llvm.sh, cmake, gcc), is retried on the other; and retry
# transient errors. arm64 uses ports.ubuntu.com which has been reachable, so
# its sources.list is left alone (the sed matches nothing there).
RUN printf 'http://azure.archive.ubuntu.com/ubuntu/\tpriority:1\nhttp://archive.ubuntu.com/ubuntu/\tpriority:2\n' > /etc/apt/mirrors.txt \
&& sed -i 's|http://archive.ubuntu.com/ubuntu/\?|mirror+file:/etc/apt/mirrors.txt|g' /etc/apt/sources.list \
&& printf 'Acquire::Retries "5";\nAcquire::http::Timeout "30";\nAcquire::https::Timeout "30";\n' > /etc/apt/apt.conf.d/80-retries
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Install basic build dependencies
RUN ( apt-get update || \
( sed -i 's|http://azure.archive.ubuntu.com/ubuntu|http://archive.ubuntu.com/ubuntu|g' /etc/apt/sources.list && apt-get update ) \
) && apt-get install -y \
RUN apt-get update && apt-get install -y \
wget \
curl \
git \
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/bytecode/BytecodeList.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
},
metadata: {
getPutInfo: GetPutInfo,
interceptorOffset: unsigned, # InterceptedGlobalProperty: the property's offset in the interceptor (operand is then the global's own variable slot, or 0); fills the padding before the union
_: {
structureID: WriteBarrierStructureID,
watchpointSet: WatchpointSet.*,
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/bytecode/CodeBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ bool CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, Unlink
metadata.m_symbolTable.set(vm, this, op.lexicalEnvironment->symbolTable());
} else if (JSScope* constantScope = JSScope::constantScopeForCodeBlock(op.type, this)) {
metadata.m_constantScope.set(vm, this, constantScope);
if (op.type == GlobalProperty || op.type == GlobalPropertyWithVarInjectionChecks)
if (isGlobalPropertyResolveType(op.type))
metadata.m_globalLexicalBindingEpoch = m_globalObject->globalLexicalBindingEpoch();
} else
metadata.m_globalObject.clear();
Expand Down Expand Up @@ -3312,7 +3312,7 @@ void CodeBlock::notifyLexicalBindingUpdate()
auto bytecode = instruction->as<OpResolveScope>();
auto& metadata = bytecode.metadata(this);
ResolveType originalResolveType = metadata.m_resolveType;
if (originalResolveType == GlobalProperty || originalResolveType == GlobalPropertyWithVarInjectionChecks) {
if (isGlobalPropertyResolveType(originalResolveType)) {
const Identifier& ident = identifier(bytecode.m_var);
if (isShadowed(ident.impl()))
metadata.m_globalLexicalBindingEpoch = 0;
Expand Down
5 changes: 5 additions & 0 deletions Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -5230,6 +5230,11 @@ bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimi
break;
}

case CheckNotCellOperand:
// "Anything but this cell" isn't expressible as an AbstractValue; the constant folder removes the check when the
// child provably isn't it.
break;

case AssertNotEmpty:
case CheckNotEmpty: {
AbstractValue& value = forNode(node->child1());
Expand Down
80 changes: 76 additions & 4 deletions Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6632,6 +6632,9 @@ bool NODELETE ByteCodeParser::needsDynamicLookup(ResolveType type, OpcodeID opco
case ClosureVar:
case ResolvedClosureVar:
case ModuleVar:
#if USE(BUN_JSC_ADDITIONS)
case InterceptedGlobalProperty:
#endif
return false;

case UnresolvedProperty:
Expand Down Expand Up @@ -10060,6 +10063,9 @@ void ByteCodeParser::parseBlock(unsigned limit)
case GlobalVarWithVarInjectionChecks:
case GlobalLexicalVar:
case GlobalLexicalVarWithVarInjectionChecks:
#if USE(BUN_JSC_ADDITIONS)
case InterceptedGlobalProperty:
#endif
constantScope = metadata.m_constantScope.get();
break;
case ModuleVar:
Expand All @@ -10085,7 +10091,7 @@ void ByteCodeParser::parseBlock(unsigned limit)
if (needsVarInjectionChecks(resolveType))
m_graph.watchpoints().addLazily(m_inlineStackTop->m_codeBlock->globalObject()->varInjectionWatchpointSet());

if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks) {
if (isGlobalPropertyResolveType(resolveType)) {
JSGlobalObject* globalObject = m_inlineStackTop->m_codeBlock->globalObject();
unsigned identifierNumber = m_inlineStackTop->m_identifierRemap[bytecode.m_var];
if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
Expand All @@ -10098,7 +10104,11 @@ void ByteCodeParser::parseBlock(unsigned limit)
case GlobalPropertyWithVarInjectionChecks:
case GlobalVarWithVarInjectionChecks:
case GlobalLexicalVar:
case GlobalLexicalVarWithVarInjectionChecks: {
case GlobalLexicalVarWithVarInjectionChecks:
#if USE(BUN_JSC_ADDITIONS)
case InterceptedGlobalProperty:
#endif
{
RELEASE_ASSERT(constantScope);
RELEASE_ASSERT(constantScope == JSScope::constantScopeForCodeBlock(resolveType, m_inlineStackTop->m_codeBlock));
set(bytecode.m_dst, weakJSConstant(constantScope));
Expand Down Expand Up @@ -10178,7 +10188,7 @@ void ByteCodeParser::parseBlock(unsigned limit)
resolveType = getPutInfo.resolveType();
if (resolveType == GlobalVar || resolveType == GlobalVarWithVarInjectionChecks || resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)
watchpoints = metadata.m_watchpointSet;
else if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks)
else if (isGlobalPropertyResolveType(resolveType))
structure = metadata.m_structureID.get();
operand = metadata.m_operand;
}
Expand Down Expand Up @@ -10224,6 +10234,35 @@ void ByteCodeParser::parseBlock(unsigned limit)
set(bytecode.m_dst, result);
break;
}
#if USE(BUN_JSC_ADDITIONS)
case InterceptedGlobalProperty: {
if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
addToGraph(ForceOSRExit);

SpeculatedType prediction = getPrediction();
CacheableIdentifier identifier = CacheableIdentifier::createFromIdentifierOwnedByCodeBlock(m_inlineStackTop->m_profiledBlock, uid);
JSObject* interceptor = globalObject->globalScopeInterceptor();

// `structure`, if the baseline cache formed, is a structure of the interceptor under which the name is
// a plain own data property of it, which the global's getOwnPropertySlot returns first: load it from
// the interceptor directly. Anything else takes the generic path (the name may not exist at all, so
// one that can throw the ReferenceError).
GetByStatus status = structure ? GetByStatus::computeFor(m_inlineStackTop->m_profiledBlock, m_currentIndex, globalObject, structure, identifier, GetByStatus::LookupMode::Normal) : GetByStatus(GetByStatus::LikelyTakesSlowPath);
if (status.state() != GetByStatus::Simple || status.numVariants() != 1 || status[0].structureSet().size() != 1 || status[0].conditionSet().size()) {
set(bytecode.m_dst, addToGraph(GetDynamicVar, OpInfo(makeDynamicVarOpInfo(identifierNumber, getPutInfo.operand())), OpInfo(prediction), get(bytecode.m_scope)));
break;
}

Node* base = weakJSConstant(interceptor);
Node* result = load(prediction, base, base, identifierNumber, status[0]);
// The global's getOwnPropertySlot substitutes its globalThis for a property holding the interceptor
// itself; leave that to it.
addToGraph(CheckNotCellOperand, OpInfo(m_graph.freeze(interceptor)), result);
addToGraph(Phantom, get(bytecode.m_scope));
set(bytecode.m_dst, result);
break;
}
#endif
case GlobalVar:
case GlobalVarWithVarInjectionChecks:
case GlobalLexicalVar:
Expand Down Expand Up @@ -10365,15 +10404,21 @@ void ByteCodeParser::parseBlock(unsigned limit)
Structure* structure = nullptr;
WatchpointSet* watchpoints = nullptr;
uintptr_t operand;
#if USE(BUN_JSC_ADDITIONS)
unsigned interceptorOffset = 0;
#endif
{
ConcurrentJSLocker locker(m_inlineStackTop->m_profiledBlock->m_lock);
getPutInfo = metadata.m_getPutInfo;
resolveType = getPutInfo.resolveType();
if (resolveType == GlobalVar || resolveType == GlobalVarWithVarInjectionChecks || resolveType == ResolvedClosureVar || resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)
watchpoints = metadata.m_watchpointSet;
else if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks)
else if (isGlobalPropertyResolveType(resolveType))
structure = metadata.m_structureID.get();
operand = metadata.m_operand;
#if USE(BUN_JSC_ADDITIONS)
interceptorOffset = metadata.m_interceptorOffset;
#endif
}

JSGlobalObject* globalObject = m_inlineStackTop->m_codeBlock->globalObject();
Expand Down Expand Up @@ -10408,6 +10453,33 @@ void ByteCodeParser::parseBlock(unsigned limit)
addToGraph(Phantom, get(bytecode.m_scope));
break;
}
#if USE(BUN_JSC_ADDITIONS)
case InterceptedGlobalProperty: {
if (!m_graph.watchGlobalProperty(globalObject, identifierNumber))
addToGraph(ForceOSRExit);
JSObject* interceptor = globalObject->globalScopeInterceptor();

// A baseline cache means: the name is a plain, writable own data property of the interceptor at
// `interceptorOffset` under `structure`, and `operand`, if non-zero, is the global's own variable slot for
// it, which the global's put() also stores to. Anything else takes the generic path (the name may not exist at
// all, so one that can throw the strict-mode ReferenceError).
PutByStatus status = (uid && structure) ? PutByStatus::computeFor(m_inlineStackTop->m_profiledBlock, m_currentIndex, globalObject, structure, CacheableIdentifier::createFromIdentifierOwnedByCodeBlock(m_inlineStackTop->m_profiledBlock, uid), false, PrivateFieldPutKind::none()) : PutByStatus(PutByStatus::LikelyTakesSlowPath);
if (status.numVariants() != 1 || status[0].kind() != PutByVariant::Replace || status[0].structure().size() != 1 || status[0].offset() != static_cast<PropertyOffset>(interceptorOffset)) {
ASSERT(identifierNumber != UINT_MAX);
addToGraph(PutDynamicVar, OpInfo(makeDynamicVarOpInfo(identifierNumber, getPutInfo.operand())), OpInfo(getPutInfo.ecmaMode()), get(bytecode.m_scope), get(bytecode.m_value));
break;
}
Node* base = weakJSConstant(interceptor);
Node* variableScope = operand ? weakJSConstant(globalObject) : nullptr; // ahead of replace(), after which exit is invalid
Node* valueNode = get(bytecode.m_value);
replace(base, identifierNumber, status[0], valueNode);
if (variableScope)
addToGraph(PutGlobalVariable, OpInfo(operand), variableScope, valueNode);
// Keep scope alive until after put.
addToGraph(Phantom, get(bytecode.m_scope));
break;
}
#endif
case GlobalLexicalVar:
case GlobalLexicalVarWithVarInjectionChecks:
case GlobalVar:
Expand Down
4 changes: 4 additions & 0 deletions Source/JavaScriptCore/dfg/DFGClobberize.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ void clobberize(Graph& graph, Node* node, const ReadFunctor& read, const WriteFu
def(PureValue(CheckIsConstant, AdjacencyList(AdjacencyList::Fixed, node->child1()), node->constant()));
return;

case CheckNotCellOperand:
def(PureValue(CheckNotCellOperand, AdjacencyList(AdjacencyList::Fixed, node->child1()), node->cellOperand()));
return;

case CheckNotEmpty:
def(PureValue(CheckNotEmpty, AdjacencyList(AdjacencyList::Fixed, node->child1())));
return;
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/dfg/DFGCloneHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ BasicBlock* CloneHelper::cloneBlock(BasicBlock* const block, const CustomizeSucc
CLONE_STATUS(CheckBadValue, Common) \
CLONE_STATUS(CheckIdent, Common) \
CLONE_STATUS(CheckIsConstant, Common) \
CLONE_STATUS(CheckNotCellOperand, Common) \
CLONE_STATUS(CheckNotEmpty, Common) \
CLONE_STATUS(CheckStructure, Common) \
CLONE_STATUS(CheckStructureOrEmpty, Common) \
Expand Down
9 changes: 9 additions & 0 deletions Source/JavaScriptCore/dfg/DFGConstantFoldingPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,15 @@ class ConstantFoldingPhase : public Phase {
break;
}

case CheckNotCellOperand: {
AbstractValue& value = m_state.forNode(node->child1());
if ((value.m_type & SpecCell) && !(value.value() && value.value() != node->cellOperand()->value()))
break;
node->remove(m_graph);
eliminated = true;
break;
}

case AssertNotEmpty:
case CheckNotEmpty: {
if (m_state.forNode(node->child1()).m_type & SpecEmpty)
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/dfg/DFGDoesGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool doesGC(Graph& graph, Node* node)
case GetGlobalLexicalVariable:
case PutGlobalVariable:
case CheckIsConstant:
case CheckNotCellOperand:
case CheckNotEmpty:
case AssertNotEmpty:
case CheckIdent:
Expand Down
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/dfg/DFGFixupPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,9 @@ class FixupPhase : public Phase {
break;
}

case CheckNotCellOperand:
break;

case ObjectCreate: {
if (node->child1()->shouldSpeculateObject()) {
fixEdge<ObjectUse>(node->child1());
Expand Down
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/dfg/DFGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ struct Node {
case CheckArrayOrEmpty:
case CheckDetached:
case CheckIsConstant:
case CheckNotCellOperand:
case CheckNotEmpty:
case CheckBadValue:
case CheckInBounds:
Expand Down Expand Up @@ -2263,6 +2264,8 @@ struct Node {
switch (op()) {
case CheckIsConstant:
return isCell(child1().useKind());
case CheckNotCellOperand:
return true;
case OverridesHasInstance:
case NewFunction:
case NewGeneratorFunction:
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/dfg/DFGNodeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ namespace JSC { namespace DFG {
macro(SetRegExpObjectLastIndex, NodeMustGenerate) \
macro(RecordRegExpCachedResult, NodeMustGenerate | NodeHasVarArgs) \
macro(CheckIsConstant, NodeMustGenerate) \
/* OSR exit if the (untyped) child is the cell operand. Used by Bun's InterceptedGlobalProperty. */\
macro(CheckNotCellOperand, NodeMustGenerate) \
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
macro(CheckNotEmpty, NodeMustGenerate) \
macro(AssertNotEmpty, NodeMustGenerate) \
macro(CheckBadValue, NodeMustGenerate) \
Expand Down
28 changes: 15 additions & 13 deletions Source/JavaScriptCore/dfg/DFGOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5968,57 +5968,59 @@ JSC_DEFINE_JIT_OPERATION(operationGetDynamicVar, EncodedJSValue, (JSGlobalObject
JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
auto scope = DECLARE_THROW_SCOPE(vm);

Identifier ident = Identifier::fromUid(vm, impl);
OPERATION_RETURN(scope, JSValue::encode(jsScope->getPropertySlot(globalObject, ident, [&] (bool found, PropertySlot& slot) -> JSValue {
// The Identifier (a ref of the uid) is only needed to build an error.
PropertyName propertyName(impl);
OPERATION_RETURN(scope, JSValue::encode(jsScope->getPropertySlot(globalObject, propertyName, [&] (bool found, PropertySlot& slot) -> JSValue {
if (!found) {
GetPutInfo getPutInfo(getPutInfoBits);
if (getPutInfo.resolveMode() == ThrowIfNotFound)
throwException(globalObject, scope, createUndefinedVariableError(globalObject, ident));
throwException(globalObject, scope, createUndefinedVariableError(globalObject, Identifier::fromUid(vm, impl)));
return jsUndefined();
}

if (jsScope->isGlobalLexicalEnvironment()) {
// When we can't statically prove we need a TDZ check, we must perform the check on the slow path.
JSValue result = slot.getValue(globalObject, ident);
JSValue result = slot.getValue(globalObject, propertyName);
if (result == jsTDZValue()) {
throwException(globalObject, scope, createTDZError(globalObject, ident.string()));
throwException(globalObject, scope, createTDZError(globalObject, Identifier::fromUid(vm, impl).string()));
return jsUndefined();
}
return result;
}

return slot.getValue(globalObject, ident);
return slot.getValue(globalObject, propertyName);
})));
}

ALWAYS_INLINE static void putDynamicVar(JSGlobalObject* globalObject, VM& vm, JSObject* scope, EncodedJSValue value, UniquedStringImpl* impl, unsigned getPutInfoBits, bool isStrictMode)
{
auto throwScope = DECLARE_THROW_SCOPE(vm);

const Identifier& ident = Identifier::fromUid(vm, impl);
// The Identifier (a ref of the uid) is only needed to build an error.
PropertyName propertyName(impl);
GetPutInfo getPutInfo(getPutInfoBits);
bool hasProperty = scope->hasProperty(globalObject, ident);
bool hasProperty = scope->hasProperty(globalObject, propertyName);
RETURN_IF_EXCEPTION(throwScope, void());
if (hasProperty
&& scope->isGlobalLexicalEnvironment()
&& !isInitialization(getPutInfo.initializationMode())) {
// When we can't statically prove we need a TDZ check, we must perform the check on the slow path.
PropertySlot slot(scope, PropertySlot::InternalMethodType::Get);
JSGlobalLexicalEnvironment::getOwnPropertySlot(scope, globalObject, ident, slot);
if (slot.getValue(globalObject, ident) == jsTDZValue()) {
throwException(globalObject, throwScope, createTDZError(globalObject, ident.string()));
JSGlobalLexicalEnvironment::getOwnPropertySlot(scope, globalObject, propertyName, slot);
if (slot.getValue(globalObject, propertyName) == jsTDZValue()) {
throwException(globalObject, throwScope, createTDZError(globalObject, Identifier::fromUid(vm, impl).string()));
return;
}
}

if (getPutInfo.resolveMode() == ThrowIfNotFound && !hasProperty) {
throwException(globalObject, throwScope, createUndefinedVariableError(globalObject, ident));
throwException(globalObject, throwScope, createUndefinedVariableError(globalObject, Identifier::fromUid(vm, impl)));
return;
}

PutPropertySlot slot(scope, isStrictMode, PutPropertySlot::UnknownContext, isInitialization(getPutInfo.initializationMode()));
throwScope.release();
scope->methodTable()->put(scope, globalObject, ident, JSValue::decode(value), slot);
scope->methodTable()->put(scope, globalObject, propertyName, JSValue::decode(value), slot);
}

JSC_DEFINE_JIT_OPERATION(operationPutDynamicVarStrict, void, (JSGlobalObject* globalObject, JSObject* jsScope, EncodedJSValue value, UniquedStringImpl* impl, unsigned getPutInfoBits))
Expand Down
Loading
Loading