1 /**
2 * Copyright (c) 2021-2024 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_PLUGINS_ETS_RUNTIME_STUBS_INL_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_STUBS_INL_H
18
19 #include "plugins/ets/runtime/ets_coroutine.h"
20 #include "plugins/ets/runtime/types/ets_object.h"
21 #include "plugins/ets/runtime/ets_stubs.h"
22
23 namespace ark::ets {
24
EtsReferenceNullish(EtsCoroutine * coro,EtsObject * ref)25 ALWAYS_INLINE inline bool EtsReferenceNullish(EtsCoroutine *coro, EtsObject *ref)
26 {
27 return ref == nullptr || ref == EtsObject::FromCoreType(coro->GetUndefinedObject());
28 }
29
IsRefNullish(EtsCoroutine * coro,EtsObject * ref)30 ALWAYS_INLINE inline bool IsRefNullish(EtsCoroutine *coro, EtsObject *ref)
31 {
32 return ref == nullptr || ref == EtsObject::FromCoreType(coro->GetUndefinedObject());
33 }
34
EtsReferenceEquals(EtsCoroutine * coro,EtsObject * ref1,EtsObject * ref2)35 ALWAYS_INLINE inline bool EtsReferenceEquals(EtsCoroutine *coro, EtsObject *ref1, EtsObject *ref2)
36 {
37 if (UNLIKELY(ref1 == ref2)) {
38 return true;
39 }
40
41 if (IsRefNullish(coro, ref1) || IsRefNullish(coro, ref2)) {
42 return IsRefNullish(coro, ref1) && IsRefNullish(coro, ref2);
43 }
44
45 if (LIKELY(!(ref1->GetClass()->IsValueTyped() && ref2->GetClass()->IsValueTyped()))) {
46 return false;
47 }
48 return EtsValueTypedEquals(coro, ref1, ref2);
49 }
50
51 // CC-OFFNXT(C_RULE_ID_INLINE_FUNCTION_SIZE) Perf critical common runtime code stub
GetMethodOwnerClassInFrames(EtsCoroutine * coro,uint32_t depth)52 inline EtsClass *GetMethodOwnerClassInFrames(EtsCoroutine *coro, uint32_t depth)
53 {
54 auto stack = StackWalker::Create(coro);
55 for (uint32_t i = 0; i < depth && stack.HasFrame(); ++i) {
56 stack.NextFrame();
57 }
58 if (UNLIKELY(!stack.HasFrame())) {
59 return nullptr;
60 }
61 auto method = stack.GetMethod();
62 if (UNLIKELY(method == nullptr)) {
63 return nullptr;
64 }
65 return EtsClass::FromRuntimeClass(method->GetClass());
66 }
67
68 } // namespace ark::ets
69
70 #endif // PANDA_PLUGINS_ETS_RUNTIME_STUBS_INL_H
71