Bitvector shared

Issue:                        https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB2M86
Signed-off-by: yulicheng <chengyuli1@huawei.com>
This commit is contained in:
YuliCheng 2024-11-14 17:53:45 +08:00
parent fd8fd6ae20
commit 50a3f0f992
6 changed files with 16 additions and 4 deletions

View File

@ -51,7 +51,7 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg
auto* newBitSetVector = new std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>>();
if (!length->IsZero()) {
int32_t capacity = (length->GetInt() / JSAPIBitVector::BIT_SET_LENGTH) + 1;
int32_t capacity = std::max(0, (length->GetInt() / JSAPIBitVector::BIT_SET_LENGTH) + 1);
std::bitset<JSAPIBitVector::BIT_SET_LENGTH> initBitSet;
newBitSetVector->resize(capacity, initBitSet);
@ -60,7 +60,7 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg
ContainersBitVector::FreeBitsetVectorPointer,
newBitSetVector);
obj->SetNativePointer(thread, pointer);
obj->SetLength(length->GetInt());
obj->SetLength(std::max(0, length->GetInt()));
return obj.GetTaggedValue();
}

View File

@ -359,7 +359,7 @@ JSTaggedValue JSAPIBitVector::FlipBitByIndex(JSThread* thread, const JSHandle<JS
{
[[maybe_unused]] ConcurrentApiScope<JSAPIBitVector, ModType::WRITE> scope(thread,
JSHandle<JSTaggedValue>::Cast(bitVector));
if (index >= bitVector->GetLength()) {
if (index >= bitVector->GetLength() || index < 0) {
std::ostringstream oss;
oss << "The value of \"index\" is out of range. It must be >= 0 && <= " << (bitVector->GetLength() - 1)
<< ". Received value is: " << index;

View File

@ -80,7 +80,9 @@ public:
ACCESSORS_PRIMITIVE_FIELD(Length, int32_t, LENGTH_OFFSET, MOD_RECORD_OFFSET);
ACCESSORS_SYNCHRONIZED_PRIMITIVE_FIELD(ModRecord, uint32_t, MOD_RECORD_OFFSET, LAST_OFFSET);
DEFINE_ALIGN_SIZE(LAST_OFFSET);
static constexpr uint32_t MAX_INLINE = PropertyAttributes::MAX_FAST_PROPS_CAPACITY -
SIZE / JSTaggedValue::TaggedTypeSize() + 1;
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, NATIVE_POINTER_OFFSET, LENGTH_OFFSET);
DECL_DUMP()

View File

@ -15,6 +15,7 @@
#include "ecmascript/jspandafile/class_info_extractor.h"
#include "ecmascript/js_api/js_api_bitvector.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
@ -1179,6 +1180,8 @@ std::pair<uint32_t, uint32_t> SendableClassDefiner::GetSizeAndMaxInlineByType(JS
return { JSSharedSet::SIZE, JSSharedSet::MAX_INLINE };
case JSType::JS_SENDABLE_ARRAY_BUFFER:
return { JSSendableArrayBuffer::SIZE, JSSendableArrayBuffer::MAX_INLINE };
case JSType::JS_API_BITVECTOR:
return { JSAPIBitVector::SIZE, JSAPIBitVector::MAX_INLINE };
default:
if (JSType::JS_SHARED_TYPED_ARRAY_FIRST < type && type <= JSType::JS_SHARED_TYPED_ARRAY_LAST) {
return { JSSharedTypedArray::SIZE, JSSharedTypedArray::MAX_INLINE };

View File

@ -602,6 +602,7 @@ public:
bool IsTreeMap(const EcmaVM *vm);
bool IsTreeSet(const EcmaVM *vm);
bool IsVector(const EcmaVM *vm);
bool IsBitVector(const EcmaVM *vm);
bool IsSendableObject(const EcmaVM *vm);
bool IsJSShared(const EcmaVM *vm);
bool IsSharedArray(const EcmaVM *vm);

View File

@ -1004,6 +1004,12 @@ bool JSValueRef::IsVector(const EcmaVM *vm)
return JSNApiHelper::ToJSTaggedValue(this).IsJSAPIVector();
}
bool JSValueRef::IsBitVector(const EcmaVM *vm)
{
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
return JSNApiHelper::ToJSTaggedValue(this).IsJSAPIBitVector();
}
bool JSValueRef::IsSendableObject(const EcmaVM *vm)
{
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());