Skip to content

Commit

Permalink
Merge pull request #22 from oven-sh/bun-jsc-debug
Browse files Browse the repository at this point in the history
Bun JSC Debug Stuff
  • Loading branch information
paperdave authored Oct 14, 2023
2 parents acc1e09 + 561ef96 commit 1a49a1f
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Source/JavaScriptCore/builtins/BuiltinNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ inline void BuiltinNames::checkPublicToPrivateMapConsistency(UniquedStringImpl*
ASSERT(String(privateName) != key);
ASSERT(privateName->isSymbol());
ASSERT(static_cast<SymbolImpl*>(privateName)->isPrivate());
#else
UNUSED_PARAM(privateName);
#endif
#else
UNUSED_PARAM(privateName);
Expand All @@ -298,6 +300,8 @@ inline void BuiltinNames::appendExternalName(const Identifier& publicName, const
{
#ifndef BUN_SKIP_FAILING_ASSERTIONS
ASSERT_UNUSED(publicName, String(publicName.impl()) == String(privateName.impl()));
#else
UNUSED_PARAM(privateName);
#endif
checkPublicToPrivateMapConsistency(privateName.impl());

Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/parser/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,12 @@ template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::p
} else {
ident = makeIdentifier(identifierStart, identifierLength);
if (m_parsingBuiltinFunction) {
#if !USE(BUN_JSC_ADDITIONS)
if (!isSafeBuiltinIdentifier(m_vm, ident)) {
m_lexErrorMessage = makeString("The use of '"_s, ident->string(), "' is disallowed in builtin functions."_s);
return ERRORTOK;
}
#endif
if (*ident == m_vm.propertyNames->undefinedKeyword)
tokenData->ident = &m_vm.propertyNames->undefinedPrivateName;
}
Expand Down
6 changes: 4 additions & 2 deletions Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ void AbstractModuleRecord::addStarExportEntry(const Identifier& moduleName)
void AbstractModuleRecord::addImportEntry(const ImportEntry& entry)
{
bool isNewEntry = m_importEntries.add(entry.localName.impl(), entry).isNewEntry;
ASSERT_UNUSED(isNewEntry, isNewEntry); // This is guaranteed by the parser.
// This is guaranteed by the parser.
ASSERT_WITH_MESSAGE(isNewEntry, "Duplicate import entry name '%s'", entry.localName.impl()->utf8().data());
}

void AbstractModuleRecord::addExportEntry(const ExportEntry& entry)
{
bool isNewEntry = m_exportEntries.add(entry.exportName.impl(), entry).isNewEntry;
ASSERT_UNUSED(isNewEntry, isNewEntry); // This is guaranteed by the parser.
// This is guaranteed by the parser.
ASSERT_WITH_MESSAGE(isNewEntry, "Duplicate export entry name '%s'", entry.exportName.impl()->utf8().data());
}

auto AbstractModuleRecord::tryGetImportEntry(UniquedStringImpl* localName) -> std::optional<ImportEntry>
Expand Down
6 changes: 6 additions & 0 deletions Source/JavaScriptCore/runtime/InternalFieldTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class InternalFieldTuple : public JSInternalFieldObjectImpl<2> {
const WriteBarrier<Unknown>& internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }
WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); }

static size_t allocationSize(Checked<size_t> inlineCapacity)
{
ASSERT_UNUSED(inlineCapacity, inlineCapacity == 0U);
return sizeof(InternalFieldTuple);
}

template<typename, SubspaceAccess mode>
static GCClient::IsoSubspace* subspaceFor(VM& vm)
{
Expand Down
6 changes: 5 additions & 1 deletion Source/JavaScriptCore/runtime/JSCellInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ ALWAYS_INLINE void* tryAllocateCellHelper(VM& vm, size_t size, GCDeferralContext
return nullptr;
}
#if ENABLE(GC_VALIDATION)
ASSERT(!vm.isInitializingObject());
ASSERT_WITH_MESSAGE(
!vm.isInitializingObject(),
"Allocating JSCell while initializing an object is not allowed. Currently initializing '%s'\n"
"This means you either forgot `Base::finishCreation(...)` or you are actually allocating.",
vm.initializingObjectClass()->className.characters());
vm.setInitializingObjectClass(T::info());
#endif
result->clearStructure();
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/runtime/JSFinalizationRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ void JSFinalizationRegistry::finalizeUnconditionally(VM& vm, CollectionScope)

if (!m_hasAlreadyScheduledWork && (readiedCell || deadCount(locker))) {
auto ticket = vm.deferredWorkTimer->addPendingWork(vm, this, { });
#ifndef BUN_SKIP_FAILING_ASSERTIONS
ASSERT(vm.deferredWorkTimer->hasPendingWork(ticket));
#endif
vm.deferredWorkTimer->scheduleWorkSoon(ticket, [this](DeferredWorkTimer::Ticket) {
JSGlobalObject* globalObject = this->globalObject();
this->m_hasAlreadyScheduledWork = false;
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/JSFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ JSFunction::JSFunction(VM& vm, NativeExecutable* executable, JSGlobalObject* glo
#if ASSERT_ENABLED
void JSFunction::finishCreation(VM& vm)
{
ASSERT(type() == JSFunctionType);
Base::finishCreation(vm);
ASSERT(jsDynamicCast<JSFunction*>(this));
ASSERT(type() == JSFunctionType);
// JSCell::{getCallData,getConstructData} relies on the following conditions.
ASSERT(methodTable()->getConstructData == &JSFunction::getConstructData);
ASSERT(methodTable()->getCallData == &JSFunction::getCallData);
Expand Down
6 changes: 3 additions & 3 deletions Source/JavaScriptCore/runtime/JSObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,10 @@ class JSObject : public JSCell {
void finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(jsDynamicCast<JSObject*>(this));
ASSERT(structure()->hasPolyProto() || getPrototypeDirect().isNull() || Heap::heap(this) == Heap::heap(getPrototypeDirect()));
ASSERT(structure()->isObject());
ASSERT(classInfo());
ASSERT(structure()->isObject());
ASSERT(structure()->hasPolyProto() || getPrototypeDirect().isNull() || Heap::heap(this) == Heap::heap(getPrototypeDirect()));
ASSERT(jsDynamicCast<JSObject*>(this));
}
#endif

Expand Down
26 changes: 26 additions & 0 deletions Source/JavaScriptCore/runtime/JSString.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ class JSString : public JSCell {
friend JSString* jsString(VM&, const String&);
friend JSString* jsString(VM&, String&&);
friend JSString* jsString(VM&, StringView);
friend JSString* jsString(VM&, const String&, GCDeferralContext*);
friend JSString* jsString(VM&, String&&, GCDeferralContext*);
friend JSString* jsString(JSGlobalObject*, JSString*, JSString*);
friend JSString* jsString(JSGlobalObject*, const String&, JSString*);
friend JSString* jsString(JSGlobalObject*, JSString*, const String&);
Expand Down Expand Up @@ -951,6 +953,30 @@ inline JSString* jsString(VM& vm, String&& s)
return JSString::create(vm, s.releaseImpl().releaseNonNull());
}

inline JSString* jsString(VM& vm, const String& s, GCDeferralContext* deferralContext)
{
int size = s.length();
if (!size)
return vm.smallStrings.emptyString();
if (size == 1) {
if (auto c = s.characterAt(0); c <= maxSingleCharacterString)
return vm.smallStrings.singleCharacterString(c);
}
return JSString::create(vm, deferralContext, *s.impl());
}

inline JSString* jsString(VM& vm, String&& s, GCDeferralContext* deferralContext)
{
int size = s.length();
if (!size)
return vm.smallStrings.emptyString();
if (size == 1) {
if (auto c = s.characterAt(0); c <= maxSingleCharacterString)
return vm.smallStrings.singleCharacterString(c);
}
return JSString::create(vm, deferralContext, s.releaseImpl().releaseNonNull());
}

ALWAYS_INLINE JSString* jsString(VM& vm, const AtomString& s)
{
return jsString(vm, s.string());
Expand Down
5 changes: 0 additions & 5 deletions Source/JavaScriptCore/runtime/SyntheticModuleRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ JSValue SyntheticModuleRecord::evaluate(JSGlobalObject*)
return jsUndefined();
}


SyntheticModuleRecord* SyntheticModuleRecord::tryCreateWithExportNamesAndValues(JSGlobalObject* globalObject, const Identifier& moduleKey, const Vector<Identifier, 4>& exportNames, const MarkedArgumentBuffer& exportValues)
{
VM& vm = globalObject->vm();
Expand All @@ -96,10 +95,6 @@ SyntheticModuleRecord* SyntheticModuleRecord::tryCreateWithExportNamesAndValues(
ASSERT(exportNames.size() == exportValues.size());

auto* moduleRecord = create(globalObject, vm, globalObject->syntheticModuleRecordStructure(), moduleKey);
for (auto& exportName : exportNames) {
moduleRecord->addExportEntry(ExportEntry::createLocal(exportName, exportName));
}

SymbolTable* exportSymbolTable = SymbolTable::create(vm);
{
auto offset = exportSymbolTable->takeNextScopeOffset(NoLockingNecessary);
Expand Down
6 changes: 6 additions & 0 deletions Source/JavaScriptCore/runtime/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {

#if ENABLE(GC_VALIDATION)
bool isInitializingObject() const;
const ClassInfo* initializingObjectClass() const;
void setInitializingObjectClass(const ClassInfo*);
#endif

Expand Down Expand Up @@ -1168,6 +1169,11 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {
};

#if ENABLE(GC_VALIDATION)
inline const ClassInfo* VM::initializingObjectClass() const
{
return m_initializingObjectClass;
}

inline bool VM::isInitializingObject() const
{
return !!m_initializingObjectClass;
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/wasm/WasmStreamingCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ StreamingCompiler::StreamingCompiler(VM& vm, CompilerMode compilerMode, JSGlobal
if (importObject)
dependencies.append(Strong<JSCell>(vm, importObject));
m_ticket = vm.deferredWorkTimer->addPendingWork(vm, promise, WTFMove(dependencies), DeferredWorkTimer::WorkKind::WebAssembly);
#ifndef BUN_SKIP_FAILING_ASSERTIONS
ASSERT(vm.deferredWorkTimer->hasPendingWork(m_ticket));
#endif
ASSERT(vm.deferredWorkTimer->hasDependancyInPendingWork(m_ticket, globalObject));
ASSERT(!importObject || vm.deferredWorkTimer->hasDependancyInPendingWork(m_ticket, importObject));
}
Expand Down

0 comments on commit 1a49a1f

Please sign in to comment.