Skip to content

Commit

Permalink
Issue #2083 - Part 4: Give RegExpShared a finalizer.
Browse files Browse the repository at this point in the history
Based on Mozilla bug 1345177.
  • Loading branch information
jobbautista9 authored and roytam1 committed Jan 31, 2023
1 parent 2ac60a2 commit 9824659
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 0 additions & 3 deletions js/src/gc/Heap.h
Expand Up @@ -340,9 +340,6 @@ class TenuredCell : public Cell
static MOZ_ALWAYS_INLINE void writeBarrierPost(void* cellp, TenuredCell* prior,
TenuredCell* next);

// Default implementation for kinds that don't require finalization.
void finalize(FreeOp* fop) {}

// Default implementation for kinds that don't require fixup.
void fixupAfterMovingGC() {}

Expand Down
14 changes: 8 additions & 6 deletions js/src/vm/RegExpObject.cpp
Expand Up @@ -952,12 +952,6 @@ RegExpShared::RegExpShared(JSAtom* source, RegExpFlag flags)
numNamedCaptures_(0), groupsTemplate_(nullptr)
{}

RegExpShared::~RegExpShared()
{
for (size_t i = 0; i < tables.length(); i++)
js_delete(tables[i]);
}

void
RegExpShared::traceChildren(JSTracer* trc)
{
Expand All @@ -978,6 +972,14 @@ RegExpShared::discardJitCode()
comp.jitCode = nullptr;
}

void
RegExpShared::finalize(FreeOp* fop)
{
for (size_t i = 0; i < tables.length(); i++)
js_free(tables[i]);
tables.~JitCodeTables();
}

/* static */ bool
RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re, HandleLinearString input,
CompilationMode mode, ForceByteCodeEnum force)
Expand Down
6 changes: 4 additions & 2 deletions js/src/vm/RegExpObject.h
Expand Up @@ -149,7 +149,8 @@ class RegExpShared : public gc::TenuredCell
}

// Tables referenced by JIT code.
Vector<uint8_t*, 0, SystemAllocPolicy> tables;
using JitCodeTables = Vector<uint8_t*, 0, SystemAllocPolicy>;
JitCodeTables tables;

/* Internal functions. */
RegExpShared(JSAtom* source, RegExpFlag flags);
Expand All @@ -172,7 +173,7 @@ class RegExpShared : public gc::TenuredCell
}

public:
~RegExpShared();
~RegExpShared() = delete;

// Execute this RegExp on input starting from searchIndex, filling in
// matches if specified and otherwise only determining if there is a match.
Expand Down Expand Up @@ -222,6 +223,7 @@ class RegExpShared : public gc::TenuredCell

void traceChildren(JSTracer* trc);
void discardJitCode();
void finalize(FreeOp* fop);

static size_t offsetOfSource() {
return offsetof(RegExpShared, source);
Expand Down

0 comments on commit 9824659

Please sign in to comment.