Skip to content

Commit

Permalink
Fix wrong memory allocation of ToStringRecursionPreventer in VMInstance
Browse files Browse the repository at this point in the history
* fix it to make GC correctly trace ToStringRecursionPreventer structure

Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 authored and ksh8281 committed Jul 5, 2024
1 parent e2423b2 commit 01bfe58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/runtime/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Context::Context(VMInstance* instance)
, m_defaultStructureForMappedArgumentsObject(instance->m_defaultStructureForMappedArgumentsObject)
, m_defaultStructureForUnmappedArgumentsObject(instance->m_defaultStructureForUnmappedArgumentsObject)
, m_defaultPrivateMemberStructure(instance->m_defaultPrivateMemberStructure)
, m_toStringRecursionPreventer(&instance->m_toStringRecursionPreventer)
, m_toStringRecursionPreventer(instance->m_toStringRecursionPreventer)
, m_virtualIdentifierCallback(nullptr)
, m_securityPolicyCheckCallback(nullptr)
, m_virtualIdentifierCallbackPublic(nullptr)
Expand Down
14 changes: 13 additions & 1 deletion src/runtime/VMInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void* VMInstance::operator new(size_t size)
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_defaultPrivateMemberStructure));
markHashSet(desc, GC_WORD_OFFSET(VMInstance, m_rootedObjectStructure));
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_onVMInstanceDestroyData));
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_toStringRecursionPreventer.m_registeredItems));
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_toStringRecursionPreventer));
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_regexpCache));
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_regexpOptionStringCache));
GC_set_bit(desc, GC_WORD_OFFSET(VMInstance, m_cachedUTC));
Expand Down Expand Up @@ -351,7 +351,17 @@ VMInstance::VMInstance(const char* locale, const char* timezone, const char* bas
, m_promiseHookPublic(nullptr)
, m_promiseRejectCallback(nullptr)
, m_promiseRejectCallbackPublic(nullptr)
, m_toStringRecursionPreventer(nullptr)
, m_regexpCache(nullptr)
, m_regexpOptionStringCache(nullptr)
#ifdef ENABLE_ICU
, m_calendar(nullptr)
#endif
, m_cachedUTC(nullptr)
, m_jobQueue(nullptr)
#if defined(ENABLE_CODE_CACHE)
, m_codeCache(nullptr)
#endif
{
GC_REGISTER_FINALIZER_NO_ORDER(this, [](void* obj, void*) {
VMInstance* self = (VMInstance*)obj;
Expand All @@ -365,6 +375,8 @@ VMInstance::VMInstance(const char* locale, const char* timezone, const char* bas
}
m_staticStrings.initStaticStrings();

m_toStringRecursionPreventer = new ToStringRecursionPreventer();

m_regexpCache = new (GC) RegExpCacheMap();
m_regexpOptionStringCache = (ASCIIString**)GC_MALLOC(64 * sizeof(ASCIIString*));
memset(m_regexpOptionStringCache, 0, 64 * sizeof(ASCIIString*));
Expand Down
7 changes: 1 addition & 6 deletions src/runtime/VMInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ class VMInstance : public gc {

void somePrototypeObjectDefineIndexedProperty(ExecutionState& state);

ToStringRecursionPreventer& toStringRecursionPreventer()
{
return m_toStringRecursionPreventer;
}

JobQueue* jobQueue()
{
return m_jobQueue;
Expand Down Expand Up @@ -463,7 +458,7 @@ class VMInstance : public gc {
PromiseRejectCallback m_promiseRejectCallback;
void* m_promiseRejectCallbackPublic;

ToStringRecursionPreventer m_toStringRecursionPreventer;
ToStringRecursionPreventer* m_toStringRecursionPreventer;

// regexp object data
RegExpCacheMap* m_regexpCache;
Expand Down
2 changes: 1 addition & 1 deletion test/vendortest

0 comments on commit 01bfe58

Please sign in to comment.