• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2025 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_CORE_CORE_LANGUAGE_CONTEXT_H_
16 #define PANDA_RUNTIME_CORE_CORE_LANGUAGE_CONTEXT_H_
17 
18 #include "core/core_vm.h"
19 #include "runtime/include/language_context.h"
20 
21 #include "runtime/class_initializer.h"
22 #include "runtime/core/core_class_linker_extension.h"
23 
24 namespace ark {
25 
26 class CoreLanguageContext : public LanguageContextBase {
27 public:
28     CoreLanguageContext() = default;
29 
30     DEFAULT_COPY_SEMANTIC(CoreLanguageContext);
31     DEFAULT_MOVE_SEMANTIC(CoreLanguageContext);
32 
33     ~CoreLanguageContext() override = default;
34 
GetLanguage()35     panda_file::SourceLang GetLanguage() const override
36     {
37         return panda_file::SourceLang::PANDA_ASSEMBLY;
38     }
39 
GetLanguageType()40     LangTypeT GetLanguageType() const override
41     {
42         return PandaAssemblyLanguageConfig::LANG_TYPE;
43     }
44 
GetObjectClassDescriptor()45     const uint8_t *GetObjectClassDescriptor() const override
46     {
47         return utf::CStringAsMutf8("Lpanda/Object;");
48     }
49 
GetClassClassDescriptor()50     const uint8_t *GetClassClassDescriptor() const override
51     {
52         return utf::CStringAsMutf8("Lpanda/Class;");
53     }
54 
GetClassArrayClassDescriptor()55     const uint8_t *GetClassArrayClassDescriptor() const override
56     {
57         return utf::CStringAsMutf8("[Lpanda/Class;");
58     }
59 
GetStringArrayClassDescriptor()60     const uint8_t *GetStringArrayClassDescriptor() const override
61     {
62         return utf::CStringAsMutf8("[Lpanda/String;");
63     }
64 
GetNullPointerExceptionClassDescriptor()65     const uint8_t *GetNullPointerExceptionClassDescriptor() const override
66     {
67         return utf::CStringAsMutf8("Lpanda/NullPointerException;");
68     }
69 
GetStackOverflowErrorClassDescriptor()70     const uint8_t *GetStackOverflowErrorClassDescriptor() const override
71     {
72         return utf::CStringAsMutf8("Lpanda/StackOverflowException;");
73     }
74 
GetArrayIndexOutOfBoundsExceptionClassDescriptor()75     const uint8_t *GetArrayIndexOutOfBoundsExceptionClassDescriptor() const override
76     {
77         return utf::CStringAsMutf8("Lpanda/ArrayIndexOutOfBoundsException;");
78     }
79 
GetIndexOutOfBoundsExceptionClassDescriptor()80     const uint8_t *GetIndexOutOfBoundsExceptionClassDescriptor() const override
81     {
82         return utf::CStringAsMutf8("Lpanda/IndexOutOfBoundsException;");
83     }
84 
GetIllegalStateExceptionClassDescriptor()85     const uint8_t *GetIllegalStateExceptionClassDescriptor() const override
86     {
87         return utf::CStringAsMutf8("Lpanda/IllegalStateException;");
88     }
GetNegativeArraySizeExceptionClassDescriptor()89     const uint8_t *GetNegativeArraySizeExceptionClassDescriptor() const override
90     {
91         return utf::CStringAsMutf8("Lpanda/NegativeArraySizeException;");
92     }
93 
GetStringIndexOutOfBoundsExceptionClassDescriptor()94     const uint8_t *GetStringIndexOutOfBoundsExceptionClassDescriptor() const override
95     {
96         return utf::CStringAsMutf8("Lpanda/StringIndexOutOfBoundsException;");
97     }
98 
GetArithmeticExceptionClassDescriptor()99     const uint8_t *GetArithmeticExceptionClassDescriptor() const override
100     {
101         return utf::CStringAsMutf8("Lpanda/ArithmeticException;");
102     }
103 
GetClassCastExceptionClassDescriptor()104     const uint8_t *GetClassCastExceptionClassDescriptor() const override
105     {
106         return utf::CStringAsMutf8("Lpanda/ClassCastException;");
107     }
108 
GetAbstractMethodErrorClassDescriptor()109     const uint8_t *GetAbstractMethodErrorClassDescriptor() const override
110     {
111         return utf::CStringAsMutf8("Lpanda/AbstractMethodError;");
112     }
113 
GetArrayStoreExceptionClassDescriptor()114     const uint8_t *GetArrayStoreExceptionClassDescriptor() const override
115     {
116         return utf::CStringAsMutf8("Lpanda/ArrayStoreException;");
117     }
118 
GetRuntimeExceptionClassDescriptor()119     const uint8_t *GetRuntimeExceptionClassDescriptor() const override
120     {
121         return utf::CStringAsMutf8("Lpanda/RuntimeException;");
122     }
123 
GetFileNotFoundExceptionClassDescriptor()124     const uint8_t *GetFileNotFoundExceptionClassDescriptor() const override
125     {
126         return utf::CStringAsMutf8("Lpanda/FileNotFoundException;");
127     }
128 
GetIOExceptionClassDescriptor()129     const uint8_t *GetIOExceptionClassDescriptor() const override
130     {
131         return utf::CStringAsMutf8("Lpanda/IOException;");
132     }
133 
GetIllegalArgumentExceptionClassDescriptor()134     const uint8_t *GetIllegalArgumentExceptionClassDescriptor() const override
135     {
136         return utf::CStringAsMutf8("Lpanda/IllegalArgumentException;");
137     }
138 
GetIllegalAccessExceptionClassDescriptor()139     const uint8_t *GetIllegalAccessExceptionClassDescriptor() const override
140     {
141         return utf::CStringAsMutf8("Lpanda/IllegalAccessException;");
142     }
143 
GetOutOfMemoryErrorClassDescriptor()144     const uint8_t *GetOutOfMemoryErrorClassDescriptor() const override
145     {
146         return utf::CStringAsMutf8("Lpanda/OutOfMemoryError;");
147     }
148 
GetNoClassDefFoundErrorDescriptor()149     const uint8_t *GetNoClassDefFoundErrorDescriptor() const override
150     {
151         return utf::CStringAsMutf8("Lpanda/NoClassDefFoundError;");
152     }
153 
GetClassCircularityErrorDescriptor()154     const uint8_t *GetClassCircularityErrorDescriptor() const override
155     {
156         return utf::CStringAsMutf8("Lpanda/ClassCircularityError;");
157     }
158 
GetCoroutinesLimitExceedErrorDescriptor()159     const uint8_t *GetCoroutinesLimitExceedErrorDescriptor() const override
160     {
161         return utf::CStringAsMutf8("Lpanda/CoroutinesLimitExceedError;");
162     }
163 
GetNoSuchFieldErrorDescriptor()164     const uint8_t *GetNoSuchFieldErrorDescriptor() const override
165     {
166         return utf::CStringAsMutf8("Lpanda/NoSuchFieldError;");
167     }
168 
GetNoSuchMethodErrorDescriptor()169     const uint8_t *GetNoSuchMethodErrorDescriptor() const override
170     {
171         return utf::CStringAsMutf8("Lpanda/NoSuchMethodError;");
172     }
173 
GetExceptionInInitializerErrorDescriptor()174     const uint8_t *GetExceptionInInitializerErrorDescriptor() const override
175     {
176         return utf::CStringAsMutf8("Lpanda/ExceptionInInitializerError;");
177     }
178 
GetClassNotFoundExceptionDescriptor()179     const uint8_t *GetClassNotFoundExceptionDescriptor() const override
180     {
181         return utf::CStringAsMutf8("Lpanda/ClassNotFoundException;");
182     }
183 
GetInstantiationErrorDescriptor()184     const uint8_t *GetInstantiationErrorDescriptor() const override
185     {
186         return utf::CStringAsMutf8("Lpanda/InstantiationError;");
187     }
188 
GetUnsupportedOperationExceptionClassDescriptor()189     const uint8_t *GetUnsupportedOperationExceptionClassDescriptor() const override
190     {
191         return utf::CStringAsMutf8("Lpanda/UnsupportedOperationException;");
192     }
193 
GetVerifyErrorClassDescriptor()194     const uint8_t *GetVerifyErrorClassDescriptor() const override
195     {
196         return utf::CStringAsMutf8("Lpanda/VerifyError;");
197     }
198 
GetErrorClassDescriptor()199     const uint8_t *GetErrorClassDescriptor() const override
200     {
201         return utf::CStringAsMutf8("Lpanda/Error;");
202     }
203 
GetIncompatibleClassChangeErrorDescriptor()204     const uint8_t *GetIncompatibleClassChangeErrorDescriptor() const override
205     {
206         return utf::CStringAsMutf8("Lpanda/IncompatibleClassChangeError;");
207     }
208 
GetInitialTaggedValue()209     coretypes::TaggedValue GetInitialTaggedValue() const override
210     {
211         return coretypes::TaggedValue(coretypes::TaggedValue::VALUE_UNDEFINED);
212     }
213 
GetEncodedTaggedValue(int64_t value,int64_t tag)214     coretypes::TaggedValue GetEncodedTaggedValue([[maybe_unused]] int64_t value,
215                                                  [[maybe_unused]] int64_t tag) const override
216     {
217         return coretypes::TaggedValue(coretypes::TaggedValue::VALUE_UNDEFINED);
218     }
219 
SetExceptionToVReg(interpreter::AccVRegister & vreg,ObjectHeader * obj)220     void SetExceptionToVReg([[maybe_unused]] interpreter::AccVRegister &vreg,
221                             [[maybe_unused]] ObjectHeader *obj) const override
222     {
223         vreg.AsVRegRef().SetReference(obj);
224     }
225 
IsCallableObject(ObjectHeader * obj)226     bool IsCallableObject([[maybe_unused]] ObjectHeader *obj) const override
227     {
228         // NOTE(yaojian) : return value according to CoreLanguageContext
229         return false;
230     }
231 
GetCallTarget(ObjectHeader * obj)232     Method *GetCallTarget([[maybe_unused]] ObjectHeader *obj) const override
233     {
234         return nullptr;
235     }
236 
GetReferenceErrorDescriptor()237     const uint8_t *GetReferenceErrorDescriptor() const override
238     {
239         // NOTE(yaojian) : return value according to CoreLanguageContext
240         return nullptr;
241     }
242 
GetTypedErrorDescriptor()243     const uint8_t *GetTypedErrorDescriptor() const override
244     {
245         // NOTE(yaojian) : return value according to CoreLanguageContext
246         return nullptr;
247     }
248 
GetIllegalMonitorStateExceptionDescriptor()249     const uint8_t *GetIllegalMonitorStateExceptionDescriptor() const override
250     {
251         return utf::CStringAsMutf8("Lpanda/IllegalMonitorStateException;");
252     }
253 
254     void ThrowException(ManagedThread *thread, const uint8_t *mutf8Name, const uint8_t *mutf8Msg) const override;
255 
256     PandaUniquePtr<ITableBuilder> CreateITableBuilder(ClassLinkerErrorHandler *errHandler) const override;
257 
258     PandaUniquePtr<VTableBuilder> CreateVTableBuilder(ClassLinkerErrorHandler *errHandler) const override;
259 
InitializeClass(ClassLinker * classLinker,ManagedThread * thread,Class * klass)260     bool InitializeClass(ClassLinker *classLinker, ManagedThread *thread, Class *klass) const override
261     {
262         return ClassInitializer<MT_MODE_MULTI>::Initialize(classLinker, thread, klass);
263     }
264 
CreateClassLinkerExtension()265     std::unique_ptr<ClassLinkerExtension> CreateClassLinkerExtension() const override
266     {
267         return std::make_unique<CoreClassLinkerExtension>();
268     }
269 
270     PandaVM *CreateVM(Runtime *runtime, const RuntimeOptions &options) const override;
271 
272     mem::GC *CreateGC(mem::GCType gcType, mem::ObjectAllocatorBase *objectAllocator,
273                       const mem::GCSettings &settings) const override;
274 
275     void ThrowStackOverflowException(ManagedThread *thread) const override;
276 
277     VerificationInitAPI GetVerificationInitAPI() const override;
278 
GetVerificationTypeClass()279     const char *GetVerificationTypeClass() const override
280     {
281         return "panda.Class";
282     }
283 
GetVerificationTypeObject()284     const char *GetVerificationTypeObject() const override
285     {
286         return "panda.Object";
287     }
288 
GetVerificationTypeThrowable()289     const char *GetVerificationTypeThrowable() const override
290     {
291         return "panda.Object";
292     }
293 };
294 
295 }  // namespace ark
296 
297 #endif  // PANDA_RUNTIME_CORE_CORE_LANGUAGE_CONTEXT_H_
298