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"
|
||||
#endif
|
||||
|
||||
#ifdef PANDA_TARGET_OHOS
|
||||
#include "parameters.h"
|
||||
#endif
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using RandomGenerator = base::RandomGenerator;
|
||||
using PGOProfilerManager = pgo::PGOProfilerManager;
|
||||
@ -129,6 +133,10 @@ EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options)
|
||||
if (SetThreadInfoCallback != nullptr) {
|
||||
SetThreadInfoCallback(CrashCallback);
|
||||
}
|
||||
#endif
|
||||
#ifdef PANDA_TARGET_OHOS
|
||||
int arkProperties = OHOS::system::GetIntParameter<int>("persist.ark.properties", -1);
|
||||
vm->GetJSOptions().SetArkProperties(arkProperties);
|
||||
#endif
|
||||
return vm;
|
||||
}
|
||||
@ -181,6 +189,10 @@ void EcmaVM::PostFork()
|
||||
heap_->NotifyPostFork();
|
||||
heap_->NotifyFinishColdStartSoon();
|
||||
#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)
|
||||
|
@ -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.
|
||||
// 4. Let callerContext be the running execution context.
|
||||
// 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 (thread->GetEcmaVM()->GetJSOptions().EnableMicroJobTrace()) {
|
||||
std::vector<JsFrameInfo> jsStackInfo = JsStackInfo::BuildJsStackInfo(thread, true);
|
||||
if (!jsStackInfo.empty()) {
|
||||
uint64_t jobId = thread->GetJobId();
|
||||
pendingJob->SetJobId(jobId);
|
||||
JsFrameInfo jsFrameInfo = jsStackInfo.front();
|
||||
std::string strTrace = "MicroJobQueue::EnqueueJob: threadId: " + std::to_string(thread->GetThreadId());
|
||||
strTrace += ", funcName: " + jsFrameInfo.functionName;
|
||||
strTrace += ", url: " + jsFrameInfo.fileName + ":" + jsFrameInfo.pos;
|
||||
|
||||
std::string fileName = jsFrameInfo.fileName;
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "MicroJobQueue::EnqueueJob");
|
||||
}
|
||||
#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) {
|
||||
JSHandle<TaggedQueue> promiseQueue(thread, jobQueue->GetPromiseJobQueue());
|
||||
TaggedQueue *newPromiseQueue = TaggedQueue::Push(thread, promiseQueue, JSHandle<JSTaggedValue>(pendingJob));
|
||||
|
@ -39,22 +39,18 @@ public:
|
||||
|
||||
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);
|
||||
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());
|
||||
ASSERT(job->IsCallable());
|
||||
JSHandle<TaggedArray> argv(thread, pendingJob->GetArguments());
|
||||
@ -73,7 +69,8 @@ public:
|
||||
ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET)
|
||||
ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_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);
|
||||
|
||||
DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET)
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <atomic>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "ecmascript/base/aligned_struct.h"
|
||||
#include "ecmascript/builtin_entries.h"
|
||||
@ -1267,6 +1268,15 @@ public:
|
||||
{
|
||||
return machineCodeLowMemory_;
|
||||
}
|
||||
|
||||
uint64_t GetJobId()
|
||||
{
|
||||
if (jobId_ == UINT64_MAX) {
|
||||
jobId_ = 0;
|
||||
}
|
||||
return ++jobId_;
|
||||
}
|
||||
|
||||
private:
|
||||
NO_COPY_SEMANTIC(JSThread);
|
||||
NO_MOVE_SEMANTIC(JSThread);
|
||||
@ -1370,6 +1380,9 @@ private:
|
||||
bool isJitThread_ {false};
|
||||
RecursiveMutex jitMutex_;
|
||||
bool machineCodeLowMemory_ {false};
|
||||
|
||||
uint64_t jobId_ {0};
|
||||
|
||||
#ifndef NDEBUG
|
||||
MutatorLock::MutatorLockState mutatorLockState_ = MutatorLock::MutatorLockState::UNLOCKED;
|
||||
#endif
|
||||
|
@ -2423,6 +2423,7 @@ JSHandle<job::PendingJob> ObjectFactory::NewPendingJob(const JSHandle<JSFunction
|
||||
obj->SetSpanId(0);
|
||||
obj->SetParentSpanId(0);
|
||||
obj->SetFlags(0);
|
||||
obj->SetJobId(0);
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user