• 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_DYN_CLASS_LINKER_EXTENSION_H_
17 #define PANDA_RUNTIME_DYN_CLASS_LINKER_EXTENSION_H_
18 
19 #include "libpandafile/file_items.h"
20 #include "runtime/include/coretypes/dyn_objects.h"
21 #include "runtime/include/class_linker.h"
22 #include "runtime/include/class_linker_extension.h"
23 #include "runtime/include/hclass.h"
24 #include "runtime/include/mem/allocator.h"
25 
26 namespace panda {
27 class ClassLinker;
28 
29 using DynClass = coretypes::DynClass;
30 
31 class DynamicClassLinkerExtension : public ClassLinkerExtension {
32 public:
33     static DynamicClassLinkerExtension *GetDynamicExtension(LanguageContext ctx);
34 
DynamicClassLinkerExtension(panda_file::SourceLang lang)35     explicit DynamicClassLinkerExtension(panda_file::SourceLang lang) : ClassLinkerExtension(lang) {}
36 
37     ~DynamicClassLinkerExtension() override;
38 
39     void InitializeArrayClass(Class *arrayClass, Class *componentClass) override;
40 
41     void InitializePrimitiveClass(Class *primitiveClass) override;
42 
43     size_t GetClassVTableSize(ClassRoot root) override;
44 
45     size_t GetClassIMTSize(ClassRoot root) override;
46 
47     size_t GetClassSize(ClassRoot root) override;
48 
49     size_t GetArrayClassVTableSize() override;
50 
51     size_t GetArrayClassSize() override;
52 
53     Class *CreateClass(const uint8_t *descriptor, size_t vtableSize, size_t imt_size, size_t size) override;
54 
55     void FreeClass(Class *klass) override;
56 
InitializeClass(Class * klass)57     void InitializeClass([[maybe_unused]] Class *klass) override {}
58 
GetNativeEntryPointFor(Method * method)59     const void *GetNativeEntryPointFor([[maybe_unused]] Method *method) const override
60     {
61         return nullptr;
62     }
63 
GetErrorHandler()64     ClassLinkerErrorHandler *GetErrorHandler() override
65     {
66         return nullptr;
67     }
68 
69     template <class Callback>
70     void EnumerateClasses([[maybe_unused]] const Callback &cb,
71                           [[maybe_unused]] mem::VisitGCRootFlags flags = mem::VisitGCRootFlags::ACCESS_ROOT_ALL)
72     {
73     }
74 
75 private:
76     bool InitializeImpl(bool cmpStrEnabled) override;
77 
78     class ErrorHandler : public ClassLinkerErrorHandler {
79     public:
80         void OnError(ClassLinker::Error error, const PandaString &message) override;
81     };
82 
83     ErrorHandler errorHandler_;
84 
85     NO_COPY_SEMANTIC(DynamicClassLinkerExtension);
86     NO_MOVE_SEMANTIC(DynamicClassLinkerExtension);
87 };
88 
89 }  // namespace panda
90 
91 #endif  // PANDA_RUNTIME_DYN_CLASS_LINKER_EXTENSION_H_
92