• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef PANDA_RUNTIME_CLASS_LINKER_INL_H_
16 #define PANDA_RUNTIME_CLASS_LINKER_INL_H_
17 
18 #include "libpandafile/panda_cache.h"
19 #include "runtime/include/class_linker.h"
20 #include "runtime/include/panda_vm.h"
21 #include "runtime/include/runtime.h"
22 #include "runtime/include/mtmanaged_thread.h"
23 
24 namespace panda {
25 
GetClass(const Method & caller,panda_file::File::EntityId id,ClassLinkerErrorHandler * error_handler)26 inline Class *ClassLinker::GetClass(const Method &caller, panda_file::File::EntityId id,
27                                     ClassLinkerErrorHandler *error_handler /* = nullptr */)
28 {
29     ASSERT(!MTManagedThread::ThreadIsMTManagedThread(Thread::GetCurrent()) ||
30            !PandaVM::GetCurrent()->GetGC()->IsGCRunning() || Locks::mutator_lock->HasLock());
31 
32     Class *klass = caller.GetPandaFile()->GetPandaCache()->GetClassFromCache(id);
33     if (klass != nullptr) {
34         return klass;
35     }
36     LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(caller);
37     auto *ext = GetExtension(ctx);
38     ASSERT(ext != nullptr);
39     klass = ext->GetClass(*caller.GetPandaFile(), id, caller.GetClass()->GetLoadContext(),
40                           (error_handler == nullptr) ? ext->GetErrorHandler() : error_handler);
41     if (LIKELY(klass != nullptr)) {
42         caller.GetPandaFile()->GetPandaCache()->SetClassCache(id, klass);
43     }
44     return klass;
45 }
46 
AddClassRoot(ClassRoot root,Class * klass)47 inline void ClassLinker::AddClassRoot(ClassRoot root, Class *klass)
48 {
49     LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(*klass);
50     auto *ext = GetExtension(ctx);
51     ASSERT(ext != nullptr);
52     ASSERT(klass != nullptr);
53     ext->SetClassRoot(root, klass);
54 
55     RemoveCreatedClassInExtension(klass);
56 }
57 
58 }  // namespace panda
59 
60 #endif  // PANDA_RUNTIME_CLASS_LINKER_INL_H_
61