Fix two bugs

1. fix serialization root uninitialied which causes random crashes.
2. fix sliced string created but not fully initialized.
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I97GKF?from=project-issue

Signed-off-by: lukai <lukai25@huawei.com>
Change-Id: I633079d1fd2f464a4df844593600f273e1676f2e
This commit is contained in:
lukai 2024-03-11 15:16:25 +08:00
parent a99d0f9f2d
commit 77ce27e1e6
3 changed files with 8 additions and 7 deletions

View File

@ -174,6 +174,7 @@ inline SlicedString *EcmaString::CreateSlicedString(const EcmaVM *vm, MemSpaceTy
{
auto slicedString = SlicedString::Cast(vm->GetFactory()->AllocSlicedStringObject(type));
slicedString->SetRawHashcode(0);
slicedString->SetParent(vm->GetJSThread(), JSTaggedValue::Undefined(), BarrierMode::SKIP_BARRIER);
return slicedString;
}

View File

@ -24,6 +24,7 @@
namespace panda::ecmascript {
constexpr size_t INITIAL_CAPACITY = 64;
constexpr int CAPACITY_INCREASE_RATE = 2;
constexpr uint32_t RESERVED_INDEX = 0;
enum class EncodeFlag : uint8_t {
// 0x00~0x06 represent new object to different space:
// 0x00: old space
@ -73,7 +74,7 @@ public:
{
regionRemainSizeVector_.clear();
free(buffer_);
if (!incompleteData_) {
if (!incompleteData_ && dataIndex_ != RESERVED_INDEX) {
Runtime::GetInstance()->RemoveSerializationRoot(thread_, dataIndex_);
}
}
@ -361,11 +362,11 @@ private:
static constexpr size_t U32_SIZE = 4;
static constexpr size_t U64_SIZE = 8;
JSThread *thread_;
uint32_t dataIndex_;
uint8_t *buffer_ = nullptr;
uint64_t sizeLimit_ = 0;
size_t bufferSize_ = 0;
size_t bufferCapacity_ = 0;
uint32_t dataIndex_ {RESERVED_INDEX};
uint8_t *buffer_ {nullptr};
uint64_t sizeLimit_ {0};
size_t bufferSize_ {0};
size_t bufferCapacity_ {0};
size_t oldSpaceSize_ {0};
size_t nonMovableSpaceSize_ {0};
size_t machineCodeSpaceSize_ {0};

View File

@ -32,7 +32,6 @@ namespace panda::ecmascript {
void ObjectFactory::NewSObjectHook() const
{
#ifndef NDEBUG
// static Mutex lock;
static std::atomic<uint32_t> count = 0;
static uint32_t frequency = vm_->GetJSOptions().GetForceSharedGCFrequency();
if (frequency == 0 || !vm_->GetJSOptions().EnableForceGC() || !vm_->IsInitialized() ||