!7833 Support sendable arraybuffer/typedarray set in clone list.

Merge pull request !7833 from lijiamin/debug
This commit is contained in:
openharmony_ci 2024-06-24 09:56:51 +00:00 committed by Gitee
commit 63eab1965c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 34 additions and 1 deletions

View File

@ -667,7 +667,6 @@ private:
EcmaRuntimeStat *runtimeStat_ {nullptr};
CMap<const JSPandaFile *, CMap<int32_t, JSTaggedValue>> cachedSharedConstpools_ {};
// todo(lijiamin) Consider expanding capacity.
std::array<JSTaggedValue, UNSHARED_CONSTANTPOOL_COUNT> unsharedConstpools_ {};
static constexpr int32_t SHARED_CONSTPOOL_KEY_NOT_FOUND = INT32_MAX; // INT32_MAX :invalid value.

View File

@ -297,6 +297,7 @@ size_t BaseDeserializer::ReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objA
break;
}
case (uint8_t)EncodeFlag::ARRAY_BUFFER:
case (uint8_t)EncodeFlag::SENDABLE_ARRAY_BUFFER:
case (uint8_t)EncodeFlag::JS_REG_EXP: {
size_t bufferLength = data_->ReadUint32(position_);
auto nativeAreaAllocator = thread_->GetEcmaVM()->GetNativeAreaAllocator();

View File

@ -45,6 +45,7 @@ enum class EncodeFlag : uint8_t {
ARRAY_BUFFER,
TRANSFER_ARRAY_BUFFER,
SHARED_ARRAY_BUFFER,
SENDABLE_ARRAY_BUFFER,
NATIVE_BINDING_OBJECT,
JS_ERROR,
JS_REG_EXP,

View File

@ -184,6 +184,11 @@ void ValueSerializer::SerializeObjectImpl(TaggedObject *object, bool isWeak)
SerializeJSSharedArrayBufferPrologue(object);
break;
}
case JSType::JS_SENDABLE_ARRAY_BUFFER: {
supportJSNativePointer_ = true;
SerializeJSSendableArrayBufferPrologue(object);
break;
}
case JSType::JS_ARRAY: {
JSArray *array = reinterpret_cast<JSArray *>(object);
trackInfo = array->GetTrackInfo();
@ -211,6 +216,7 @@ void ValueSerializer::SerializeObjectImpl(TaggedObject *object, bool isWeak)
switch (type) {
case JSType::JS_ARRAY_BUFFER:
case JSType::JS_SHARED_ARRAY_BUFFER:
case JSType::JS_SENDABLE_ARRAY_BUFFER:
case JSType::JS_REG_EXP:
// JSNativePointer supports serialization only during serialize JSArrayBuffer,
// JSSharedArrayBuffer and JSRegExp
@ -368,6 +374,31 @@ void ValueSerializer::SerializeJSSharedArrayBufferPrologue(TaggedObject *object)
}
}
void ValueSerializer::SerializeJSSendableArrayBufferPrologue(TaggedObject *object)
{
ASSERT(object->GetClass()->IsSendableArrayBuffer());
JSSendableArrayBuffer *arrayBuffer = reinterpret_cast<JSSendableArrayBuffer *>(object);
if (arrayBuffer->IsDetach()) {
LOG_ECMA(ERROR) << "ValueSerialize: don't support serialize detached sendable array buffer";
notSupport_ = true;
return;
}
size_t arrayLength = arrayBuffer->GetArrayBufferByteLength();
if (arrayLength > 0) {
bool nativeAreaAllocated = arrayBuffer->GetWithNativeAreaAllocator();
if (!nativeAreaAllocated) {
LOG_ECMA(ERROR) << "ValueSerialize: don't support clone sendablearraybuffer has external allocated buffer";
notSupport_ = true;
return;
}
data_->WriteEncodeFlag(EncodeFlag::SENDABLE_ARRAY_BUFFER);
data_->WriteUint32(arrayLength);
JSNativePointer *np =
reinterpret_cast<JSNativePointer *>(arrayBuffer->GetArrayBufferData().GetTaggedObject());
data_->WriteRawData(static_cast<uint8_t *>(np->GetExternalPointer()), arrayLength);
}
}
void ValueSerializer::SerializeJSRegExpPrologue(JSRegExp *jsRegExp)
{
uint32_t bufferSize = jsRegExp->GetLength();

View File

@ -43,6 +43,7 @@ private:
void SerializeNativeBindingObject(TaggedObject *object);
bool SerializeJSArrayBufferPrologue(TaggedObject *object);
void SerializeJSSharedArrayBufferPrologue(TaggedObject *object);
void SerializeJSSendableArrayBufferPrologue(TaggedObject *object);
void SerializeJSRegExpPrologue(JSRegExp *jsRegExp);
void InitTransferSet(CUnorderedSet<uintptr_t> transferDataSet);
bool PrepareTransfer(JSThread *thread, const JSHandle<JSTaggedValue> &transfer);