Skip to content

Commit

Permalink
Refactor Code Cache
Browse files Browse the repository at this point in the history
* reduce FILE I/O to accelerate load/store process
* add code caching functions for clean code

Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 authored and ksh8281 committed Dec 7, 2023
1 parent 59a626b commit 93d4648
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 276 deletions.
68 changes: 39 additions & 29 deletions src/api/EscargotPublic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@
#include "runtime/BigIntObject.h"
#include "runtime/SharedArrayBufferObject.h"
#include "runtime/serialization/Serializer.h"
#include "codecache/CodeCache.h"
#include "interpreter/ByteCode.h"
#include "api/internal/ValueAdapter.h"
#if defined(ENABLE_CODE_CACHE)
#include "codecache/CodeCache.h"
#endif
#if defined(ENABLE_WASM)
#include "wasm/WASMOperations.h"
#endif
Expand Down Expand Up @@ -1244,75 +1246,83 @@ void VMInstanceRef::setMaxCompiledByteCodeSize(size_t s)
toImpl(this)->setMaxCompiledByteCodeSize(s);
}

#if defined(ENABLE_CODE_CACHE)
bool VMInstanceRef::isCodeCacheEnabled()
{
#if defined(ENABLE_CODE_CACHE)
return true;
#else
return false;
#endif
}

size_t VMInstanceRef::codeCacheMinSourceLength()
{
#if defined(ENABLE_CODE_CACHE)
return toImpl(this)->codeCache()->minSourceLength();
#else
}

void VMInstanceRef::setCodeCacheMinSourceLength(size_t s)
{
toImpl(this)->codeCache()->setMinSourceLength(s);
}

size_t VMInstanceRef::codeCacheMaxCacheCount()
{
return toImpl(this)->codeCache()->maxCacheCount();
}

void VMInstanceRef::setCodeCacheMaxCacheCount(size_t s)
{
toImpl(this)->codeCache()->setMaxCacheCount(s);
}

bool VMInstanceRef::codeCacheShouldLoadFunctionOnScriptLoading()
{
return toImpl(this)->codeCache()->shouldLoadFunctionOnScriptLoading();
}

void VMInstanceRef::setCodeCacheShouldLoadFunctionOnScriptLoading(bool s)
{
toImpl(this)->codeCache()->setShouldLoadFunctionOnScriptLoading(s);
}
#else // ENABLE_CODE_CACHE
bool VMInstanceRef::isCodeCacheEnabled()
{
return false;
}

size_t VMInstanceRef::codeCacheMinSourceLength()
{
ESCARGOT_LOG_ERROR("If you want to use this function, you should enable code cache");
RELEASE_ASSERT_NOT_REACHED();
#endif
}

void VMInstanceRef::setCodeCacheMinSourceLength(size_t s)
{
#if defined(ENABLE_CODE_CACHE)
toImpl(this)->codeCache()->setMinSourceLength(s);
#else
ESCARGOT_LOG_ERROR("If you want to use this function, you should enable code cache");
RELEASE_ASSERT_NOT_REACHED();
#endif
}

size_t VMInstanceRef::codeCacheMaxCacheCount()
{
#if defined(ENABLE_CODE_CACHE)
return toImpl(this)->codeCache()->maxCacheCount();
#else
ESCARGOT_LOG_ERROR("If you want to use this function, you should enable code cache");
RELEASE_ASSERT_NOT_REACHED();
#endif
}

void VMInstanceRef::setCodeCacheMaxCacheCount(size_t s)
{
#if defined(ENABLE_CODE_CACHE)
toImpl(this)->codeCache()->setMaxCacheCount(s);
#else
ESCARGOT_LOG_ERROR("If you want to use this function, you should enable code cache");
RELEASE_ASSERT_NOT_REACHED();
#endif
}

bool VMInstanceRef::codeCacheShouldLoadFunctionOnScriptLoading()
{
#if defined(ENABLE_CODE_CACHE)
return toImpl(this)->codeCache()->shouldLoadFunctionOnScriptLoading();
#else
ESCARGOT_LOG_ERROR("If you want to use this function, you should enable code cache");
RELEASE_ASSERT_NOT_REACHED();
#endif
}

void VMInstanceRef::setCodeCacheShouldLoadFunctionOnScriptLoading(bool s)
{
#if defined(ENABLE_CODE_CACHE)
toImpl(this)->codeCache()->setShouldLoadFunctionOnScriptLoading(s);
#else
ESCARGOT_LOG_ERROR("If you want to use this function, you should enable code cache");
RELEASE_ASSERT_NOT_REACHED();
#endif
}

#endif // ENABLE_CODE_CACHE

#ifdef ESCARGOT_DEBUGGER

Expand Down
Loading

0 comments on commit 93d4648

Please sign in to comment.