• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef PANDA_RUNTIME_INCLUDE_CLASS_LINKER_INL_H_
17 #define PANDA_RUNTIME_INCLUDE_CLASS_LINKER_INL_H_
18 
19 #include "libpandafile/panda_cache.h"
20 #include "runtime/include/class_linker.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     Class *klass = caller.GetPandaFile()->GetPandaCache()->GetClassFromCache(id);
30     if (klass != nullptr) {
31         return klass;
32     }
33     LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(caller);
34     auto *ext = GetExtension(ctx);
35     ASSERT(ext != nullptr);
36     klass = ext->GetClass(*caller.GetPandaFile(), id, caller.GetClass()->GetLoadContext(),
37                           error_handler == nullptr ? ext->GetErrorHandler() : error_handler);
38     if (LIKELY(klass != nullptr)) {
39         caller.GetPandaFile()->GetPandaCache()->SetClassCache(id, klass);
40     }
41     return klass;
42 }
43 
AddClassRoot(ClassRoot root,Class * klass)44 inline void ClassLinker::AddClassRoot(ClassRoot root, Class *klass)
45 {
46     LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(*klass);
47     auto *ext = GetExtension(ctx);
48     ASSERT(ext != nullptr);
49     ext->SetClassRoot(root, klass);
50 
51     RemoveCreatedClassInExtension(klass);
52 }
53 
54 }  // namespace panda
55 
56 #endif  // PANDA_RUNTIME_INCLUDE_CLASS_LINKER_INL_H_
57