mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
微任务新增jobId
Signed-off-by: yangxiaoshuai2022 <yangxiaoshuai@huawei.com>
This commit is contained in:
parent
0edbe4cb13
commit
c52783ad3c
@ -99,6 +99,10 @@
|
|||||||
#include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h"
|
#include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PANDA_TARGET_OHOS
|
||||||
|
#include "parameters.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace panda::ecmascript {
|
namespace panda::ecmascript {
|
||||||
using RandomGenerator = base::RandomGenerator;
|
using RandomGenerator = base::RandomGenerator;
|
||||||
using PGOProfilerManager = pgo::PGOProfilerManager;
|
using PGOProfilerManager = pgo::PGOProfilerManager;
|
||||||
@ -129,6 +133,10 @@ EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options)
|
|||||||
if (SetThreadInfoCallback != nullptr) {
|
if (SetThreadInfoCallback != nullptr) {
|
||||||
SetThreadInfoCallback(CrashCallback);
|
SetThreadInfoCallback(CrashCallback);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef PANDA_TARGET_OHOS
|
||||||
|
int arkProperties = OHOS::system::GetIntParameter<int>("persist.ark.properties", -1);
|
||||||
|
vm->GetJSOptions().SetArkProperties(arkProperties);
|
||||||
#endif
|
#endif
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
@ -181,6 +189,10 @@ void EcmaVM::PostFork()
|
|||||||
heap_->NotifyPostFork();
|
heap_->NotifyPostFork();
|
||||||
heap_->NotifyFinishColdStartSoon();
|
heap_->NotifyFinishColdStartSoon();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PANDA_TARGET_OHOS
|
||||||
|
int arkProperties = OHOS::system::GetIntParameter<int>("persist.ark.properties", -1);
|
||||||
|
GetJSOptions().SetArkProperties(arkProperties);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
EcmaVM::EcmaVM(JSRuntimeOptions options, EcmaParamConfiguration config)
|
EcmaVM::EcmaVM(JSRuntimeOptions options, EcmaParamConfiguration config)
|
||||||
|
@ -43,24 +43,45 @@ void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueu
|
|||||||
// 3. Assert: arguments is a List that has the same number of elements as the number of parameters required by job.
|
// 3. Assert: arguments is a List that has the same number of elements as the number of parameters required by job.
|
||||||
// 4. Let callerContext be the running execution context.
|
// 4. Let callerContext be the running execution context.
|
||||||
// 5. Let callerRealm be callerContext’s Realm.
|
// 5. Let callerRealm be callerContext’s Realm.
|
||||||
|
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||||
|
[[maybe_unused]] EcmaHandleScope handleScope(thread);
|
||||||
|
JSHandle<PendingJob> pendingJob(factory->NewPendingJob(job, argv));
|
||||||
|
ENQUEUE_JOB_HITRACE(pendingJob, queueType);
|
||||||
|
|
||||||
#if defined(ENABLE_BYTRACE)
|
#if defined(ENABLE_BYTRACE)
|
||||||
if (thread->GetEcmaVM()->GetJSOptions().EnableMicroJobTrace()) {
|
if (thread->GetEcmaVM()->GetJSOptions().EnableMicroJobTrace()) {
|
||||||
std::vector<JsFrameInfo> jsStackInfo = JsStackInfo::BuildJsStackInfo(thread, true);
|
std::vector<JsFrameInfo> jsStackInfo = JsStackInfo::BuildJsStackInfo(thread, true);
|
||||||
if (!jsStackInfo.empty()) {
|
if (!jsStackInfo.empty()) {
|
||||||
|
uint64_t jobId = thread->GetJobId();
|
||||||
|
pendingJob->SetJobId(jobId);
|
||||||
JsFrameInfo jsFrameInfo = jsStackInfo.front();
|
JsFrameInfo jsFrameInfo = jsStackInfo.front();
|
||||||
std::string strTrace = "MicroJobQueue::EnqueueJob: threadId: " + std::to_string(thread->GetThreadId());
|
|
||||||
strTrace += ", funcName: " + jsFrameInfo.functionName;
|
std::string fileName = jsFrameInfo.fileName;
|
||||||
strTrace += ", url: " + jsFrameInfo.fileName + ":" + jsFrameInfo.pos;
|
int lineNumber;
|
||||||
|
int columnNumber;
|
||||||
|
size_t pos = jsFrameInfo.pos.find(':', 0);
|
||||||
|
if (pos != CString::npos) {
|
||||||
|
lineNumber = std::stoi(jsFrameInfo.pos.substr(0, pos));
|
||||||
|
columnNumber = std::stoi(jsFrameInfo.pos.substr(pos + 1));
|
||||||
|
auto sourceMapcb = thread->GetEcmaVM()->GetSourceMapTranslateCallback();
|
||||||
|
if (sourceMapcb != nullptr && !fileName.empty()) {
|
||||||
|
sourceMapcb(fileName, lineNumber, columnNumber);
|
||||||
|
}
|
||||||
|
fileName += ":" + std::to_string(lineNumber) + ":" + std::to_string(columnNumber);
|
||||||
|
} else {
|
||||||
|
fileName += ":" + jsFrameInfo.pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string strTrace = "MicroJobQueue::EnqueueJob: jobId: " + std::to_string(jobId);
|
||||||
|
strTrace += ", threadId: " + std::to_string(thread->GetThreadId());
|
||||||
|
strTrace += ", funcName: " + jsFrameInfo.functionName + ", url: " + fileName;
|
||||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, strTrace);
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, strTrace);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "MicroJobQueue::EnqueueJob");
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "MicroJobQueue::EnqueueJob");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
|
||||||
[[maybe_unused]] EcmaHandleScope handleScope(thread);
|
|
||||||
JSHandle<PendingJob> pendingJob(factory->NewPendingJob(job, argv));
|
|
||||||
ENQUEUE_JOB_HITRACE(pendingJob, queueType);
|
|
||||||
if (queueType == QueueType::QUEUE_PROMISE) {
|
if (queueType == QueueType::QUEUE_PROMISE) {
|
||||||
JSHandle<TaggedQueue> promiseQueue(thread, jobQueue->GetPromiseJobQueue());
|
JSHandle<TaggedQueue> promiseQueue(thread, jobQueue->GetPromiseJobQueue());
|
||||||
TaggedQueue *newPromiseQueue = TaggedQueue::Push(thread, promiseQueue, JSHandle<JSTaggedValue>(pendingJob));
|
TaggedQueue *newPromiseQueue = TaggedQueue::Push(thread, promiseQueue, JSHandle<JSTaggedValue>(pendingJob));
|
||||||
|
@ -39,22 +39,18 @@ public:
|
|||||||
|
|
||||||
static JSTaggedValue ExecutePendingJob(const JSHandle<PendingJob> &pendingJob, JSThread *thread)
|
static JSTaggedValue ExecutePendingJob(const JSHandle<PendingJob> &pendingJob, JSThread *thread)
|
||||||
{
|
{
|
||||||
#if defined(ENABLE_BYTRACE)
|
|
||||||
if (thread->GetEcmaVM()->GetJSOptions().EnableMicroJobTrace()) {
|
|
||||||
std::vector<JsFrameInfo> jsStackInfo = JsStackInfo::BuildJsStackInfo(thread, true);
|
|
||||||
if (!jsStackInfo.empty()) {
|
|
||||||
JsFrameInfo jsFrameInfo = jsStackInfo.front();
|
|
||||||
std::string strTrace = "PendingJob::ExecutePendingJob: ";
|
|
||||||
strTrace += "threadId: " + std::to_string(thread->GetThreadId());
|
|
||||||
strTrace += ", funcName: " + jsFrameInfo.functionName;
|
|
||||||
strTrace += ", url: " + jsFrameInfo.fileName + ":" + jsFrameInfo.pos;
|
|
||||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, strTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
[[maybe_unused]] EcmaHandleScope handleScope(thread);
|
[[maybe_unused]] EcmaHandleScope handleScope(thread);
|
||||||
EXECUTE_JOB_HITRACE(pendingJob);
|
EXECUTE_JOB_HITRACE(pendingJob);
|
||||||
|
|
||||||
|
#if defined(ENABLE_BYTRACE)
|
||||||
|
#if defined(ENABLE_HITRACE)
|
||||||
|
if (thread->GetEcmaVM()->GetJSOptions().EnableMicroJobTrace()) {
|
||||||
|
std::string strTrace = "PendingJob::ExecutePendingJob: jobId: " + std::to_string(pendingJob->GetJobId());
|
||||||
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, strTrace);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
JSHandle<JSTaggedValue> job(thread, pendingJob->GetJob());
|
JSHandle<JSTaggedValue> job(thread, pendingJob->GetJob());
|
||||||
ASSERT(job->IsCallable());
|
ASSERT(job->IsCallable());
|
||||||
JSHandle<TaggedArray> argv(thread, pendingJob->GetArguments());
|
JSHandle<TaggedArray> argv(thread, pendingJob->GetArguments());
|
||||||
@ -73,7 +69,8 @@ public:
|
|||||||
ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET)
|
ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET)
|
||||||
ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_OFFSET)
|
ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_OFFSET)
|
||||||
ACCESSORS_PRIMITIVE_FIELD(ParentSpanId, uint64_t, PARENTSPANID_OFFSET, FLAGS_OFFSET)
|
ACCESSORS_PRIMITIVE_FIELD(ParentSpanId, uint64_t, PARENTSPANID_OFFSET, FLAGS_OFFSET)
|
||||||
ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, LAST_OFFSET)
|
ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, JOBID_OFFSET)
|
||||||
|
ACCESSORS_PRIMITIVE_FIELD(JobId, uint64_t, JOBID_OFFSET, LAST_OFFSET)
|
||||||
DEFINE_ALIGN_SIZE(LAST_OFFSET);
|
DEFINE_ALIGN_SIZE(LAST_OFFSET);
|
||||||
|
|
||||||
DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET)
|
DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include "ecmascript/base/aligned_struct.h"
|
#include "ecmascript/base/aligned_struct.h"
|
||||||
#include "ecmascript/builtin_entries.h"
|
#include "ecmascript/builtin_entries.h"
|
||||||
@ -1267,6 +1268,15 @@ public:
|
|||||||
{
|
{
|
||||||
return machineCodeLowMemory_;
|
return machineCodeLowMemory_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetJobId()
|
||||||
|
{
|
||||||
|
if (jobId_ == UINT64_MAX) {
|
||||||
|
jobId_ = 0;
|
||||||
|
}
|
||||||
|
return ++jobId_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_SEMANTIC(JSThread);
|
NO_COPY_SEMANTIC(JSThread);
|
||||||
NO_MOVE_SEMANTIC(JSThread);
|
NO_MOVE_SEMANTIC(JSThread);
|
||||||
@ -1370,6 +1380,9 @@ private:
|
|||||||
bool isJitThread_ {false};
|
bool isJitThread_ {false};
|
||||||
RecursiveMutex jitMutex_;
|
RecursiveMutex jitMutex_;
|
||||||
bool machineCodeLowMemory_ {false};
|
bool machineCodeLowMemory_ {false};
|
||||||
|
|
||||||
|
uint64_t jobId_ {0};
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
MutatorLock::MutatorLockState mutatorLockState_ = MutatorLock::MutatorLockState::UNLOCKED;
|
MutatorLock::MutatorLockState mutatorLockState_ = MutatorLock::MutatorLockState::UNLOCKED;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2423,6 +2423,7 @@ JSHandle<job::PendingJob> ObjectFactory::NewPendingJob(const JSHandle<JSFunction
|
|||||||
obj->SetSpanId(0);
|
obj->SetSpanId(0);
|
||||||
obj->SetParentSpanId(0);
|
obj->SetParentSpanId(0);
|
||||||
obj->SetFlags(0);
|
obj->SetFlags(0);
|
||||||
|
obj->SetJobId(0);
|
||||||
#endif
|
#endif
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user