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