14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci#include "ecmascript/compiler/aot_compilation_env.h" 164514f5e3Sopenharmony_ci#include "ecmascript/compiler/pgo_type/pgo_type_manager.h" 174514f5e3Sopenharmony_ci#include "ecmascript/ecma_context.h" 184514f5e3Sopenharmony_ci#include "ecmascript/jspandafile/program_object.h" 194514f5e3Sopenharmony_ci 204514f5e3Sopenharmony_cinamespace panda::ecmascript { 214514f5e3Sopenharmony_ciAOTCompilationEnv::AOTCompilationEnv(EcmaVM *vm) : CompilationEnv(vm) 224514f5e3Sopenharmony_ci{ 234514f5e3Sopenharmony_ci ptManager_ = thread_->GetCurrentEcmaContext()->GetPTManager(); 244514f5e3Sopenharmony_ci} 254514f5e3Sopenharmony_ci 264514f5e3Sopenharmony_ciJSRuntimeOptions &AOTCompilationEnv::GetJSOptions() 274514f5e3Sopenharmony_ci{ 284514f5e3Sopenharmony_ci return vm_->GetJSOptions(); 294514f5e3Sopenharmony_ci} 304514f5e3Sopenharmony_ci 314514f5e3Sopenharmony_ciJSHandle<GlobalEnv> AOTCompilationEnv::GetGlobalEnv() const 324514f5e3Sopenharmony_ci{ 334514f5e3Sopenharmony_ci return vm_->GetGlobalEnv(); 344514f5e3Sopenharmony_ci} 354514f5e3Sopenharmony_ci 364514f5e3Sopenharmony_ciconst CMap<ElementsKind, std::pair<ConstantIndex, ConstantIndex>> &AOTCompilationEnv::GetArrayHClassIndexMap() const 374514f5e3Sopenharmony_ci{ 384514f5e3Sopenharmony_ci return thread_->GetArrayHClassIndexMap(); 394514f5e3Sopenharmony_ci} 404514f5e3Sopenharmony_ci 414514f5e3Sopenharmony_ciconst BuiltinHClassEntries &AOTCompilationEnv::GetBuiltinHClassEntries() const 424514f5e3Sopenharmony_ci{ 434514f5e3Sopenharmony_ci return thread_->GetBuiltinHClassEntries(); 444514f5e3Sopenharmony_ci} 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_ciJSHClass *AOTCompilationEnv::GetBuiltinPrototypeHClass(BuiltinTypeId type) const 474514f5e3Sopenharmony_ci{ 484514f5e3Sopenharmony_ci return thread_->GetBuiltinPrototypeHClass(type); 494514f5e3Sopenharmony_ci} 504514f5e3Sopenharmony_ci 514514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::FindConstpool(const JSPandaFile *jsPandaFile, panda_file::File::EntityId id) const 524514f5e3Sopenharmony_ci{ 534514f5e3Sopenharmony_ci return thread_->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, id); 544514f5e3Sopenharmony_ci} 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::FindConstpool(const JSPandaFile *jsPandaFile, int32_t index) const 574514f5e3Sopenharmony_ci{ 584514f5e3Sopenharmony_ci return thread_->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, index); 594514f5e3Sopenharmony_ci} 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const 624514f5e3Sopenharmony_ci{ 634514f5e3Sopenharmony_ci JSTaggedValue cp = ptManager_->GetConstantPoolByMethodOffset(methodOffset); 644514f5e3Sopenharmony_ci return thread_->GetCurrentEcmaContext()->FindOrCreateUnsharedConstpool(cp); 654514f5e3Sopenharmony_ci} 664514f5e3Sopenharmony_ci 674514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const 684514f5e3Sopenharmony_ci{ 694514f5e3Sopenharmony_ci return thread_->GetCurrentEcmaContext()->FindOrCreateUnsharedConstpool(sharedConstpool); 704514f5e3Sopenharmony_ci} 714514f5e3Sopenharmony_ci 724514f5e3Sopenharmony_ciJSHandle<ConstantPool> AOTCompilationEnv::FindOrCreateConstPool(const JSPandaFile *jsPandaFile, 734514f5e3Sopenharmony_ci panda_file::File::EntityId id) 744514f5e3Sopenharmony_ci{ 754514f5e3Sopenharmony_ci return thread_->GetCurrentEcmaContext()->FindOrCreateConstPool(jsPandaFile, id); 764514f5e3Sopenharmony_ci} 774514f5e3Sopenharmony_ci 784514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::GetConstantPoolByMethodOffset(const uint32_t methodOffset) const 794514f5e3Sopenharmony_ci{ 804514f5e3Sopenharmony_ci return ptManager_->GetConstantPoolByMethodOffset(methodOffset); 814514f5e3Sopenharmony_ci} 824514f5e3Sopenharmony_ci 834514f5e3Sopenharmony_ciconst GlobalEnvConstants *AOTCompilationEnv::GlobalConstants() const 844514f5e3Sopenharmony_ci{ 854514f5e3Sopenharmony_ci return thread_->GlobalConstants(); 864514f5e3Sopenharmony_ci} 874514f5e3Sopenharmony_ci 884514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const 894514f5e3Sopenharmony_ci{ 904514f5e3Sopenharmony_ci return ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(thread_, constpool, index, entry); 914514f5e3Sopenharmony_ci} 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const 944514f5e3Sopenharmony_ci{ 954514f5e3Sopenharmony_ci return ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(thread_, constpool, index, entry); 964514f5e3Sopenharmony_ci} 974514f5e3Sopenharmony_ci 984514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const 994514f5e3Sopenharmony_ci{ 1004514f5e3Sopenharmony_ci return ConstantPool::GetMethodFromCache(thread_, constpool, index); 1014514f5e3Sopenharmony_ci} 1024514f5e3Sopenharmony_ci 1034514f5e3Sopenharmony_cipanda_file::File::EntityId AOTCompilationEnv::GetIdFromCache(JSTaggedValue constpool, uint32_t index) const 1044514f5e3Sopenharmony_ci{ 1054514f5e3Sopenharmony_ci return ConstantPool::GetIdFromCache(constpool, index); 1064514f5e3Sopenharmony_ci} 1074514f5e3Sopenharmony_ci 1084514f5e3Sopenharmony_ciJSTaggedValue AOTCompilationEnv::GetStringFromConstantPool(const uint32_t methodOffset, const uint16_t cpIdx, 1094514f5e3Sopenharmony_ci [[maybe_unused]] bool allowAlloc) const 1104514f5e3Sopenharmony_ci{ 1114514f5e3Sopenharmony_ci return ptManager_->GetStringFromConstantPool(methodOffset, cpIdx); 1124514f5e3Sopenharmony_ci} 1134514f5e3Sopenharmony_ci} // namespace panda::ecmascript 114