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 #include "runtime/include/language_context.h"
16
17 #include "macros.h"
18 #include "runtime/core/core_itable_builder.h"
19 #include "runtime/core/core_vm.h"
20 #include "runtime/core/core_vtable_builder.h"
21 #include "runtime/handle_scope-inl.h"
22 #include "runtime/include/class_linker.h"
23 #include "runtime/include/language_config.h"
24 #include "runtime/include/method.h"
25 #include "runtime/include/runtime.h"
26 #include "runtime/include/stack_walker.h"
27 #include "runtime/include/thread.h"
28 #include "runtime/include/vtable_builder-inl.h"
29 #include "runtime/mem/gc/gc.h"
30 #include "runtime/mem/vm_handle.h"
31
32 namespace panda {
GetCatchMethodAndOffset(Method * method,ManagedThread * thread) const33 std::pair<Method *, uint32_t> LanguageContextBase::GetCatchMethodAndOffset(Method *method, ManagedThread *thread) const
34 {
35 uint32_t catchOffset = 0;
36 Method *catchMethod = method;
37 auto stack = StackWalker::Create(thread);
38 while (stack.HasFrame()) {
39 catchMethod = stack.GetMethod();
40 if (catchMethod->GetPandaFile() == nullptr) {
41 stack.NextFrame();
42 continue;
43 }
44 if (stack.IsCFrame()) {
45 stack.NextFrame();
46 continue;
47 }
48 catchOffset = catchMethod->FindCatchBlock(thread->GetException()->ClassAddr<Class>(), stack.GetBytecodePc());
49
50 if (catchOffset != panda_file::INVALID_OFFSET) {
51 break;
52 }
53 stack.NextFrame();
54 }
55
56 return std::make_pair(catchMethod, catchOffset);
57 }
58
CreateClassLinkerExtension() const59 std::unique_ptr<ClassLinkerExtension> LanguageContextBase::CreateClassLinkerExtension() const
60 {
61 return nullptr;
62 }
63
CreatePtLangExt() const64 PandaUniquePtr<tooling::PtLangExt> LanguageContextBase::CreatePtLangExt() const
65 {
66 return nullptr;
67 }
68
ThrowException(ManagedThread * thread,const uint8_t * mutf8_name,const uint8_t * mutf8_msg) const69 void LanguageContextBase::ThrowException([[maybe_unused]] ManagedThread *thread,
70 [[maybe_unused]] const uint8_t *mutf8_name,
71 [[maybe_unused]] const uint8_t *mutf8_msg) const
72 {
73 }
74
SetExceptionToVReg(interpreter::AccVRegister & vreg,ObjectHeader * obj) const75 void LanguageContextBase::SetExceptionToVReg(
76 [[maybe_unused]] interpreter::AccVRegister &vreg, // NOLINTNEXTLINE(google-runtime-references)
77 [[maybe_unused]] ObjectHeader *obj) const
78 {
79 }
80
81 } // namespace panda
82