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 #include "runtime/tests/class_linker_test_extension.h"
17
18 #include "runtime/include/class_linker-inl.h"
19 #include "runtime/include/runtime.h"
20
21 namespace ark::test {
22
23 // Runtime::GetCurrent() can not be used in .h files
InitializeImpl(bool compressedStringEnabled)24 bool ClassLinkerTestExtension::InitializeImpl([[maybe_unused]] bool compressedStringEnabled)
25 {
26 LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(GetLanguage());
27
28 auto *classClass = CreateClass(ctx.GetClassClassDescriptor(), GetClassVTableSize(ClassRoot::CLASS),
29 GetClassIMTSize(ClassRoot::CLASS), GetClassSize(ClassRoot::CLASS));
30 coretypes::Class::FromRuntimeClass(classClass)->SetClass(classClass);
31 classClass->SetState(Class::State::LOADED);
32
33 auto *objClass = CreateClass(ctx.GetObjectClassDescriptor(), GetClassVTableSize(ClassRoot::OBJECT),
34 GetClassIMTSize(ClassRoot::OBJECT), GetClassSize(ClassRoot::OBJECT));
35 objClass->SetObjectSize(ObjectHeader::ObjectHeaderSize());
36 classClass->SetBase(objClass);
37 objClass->SetState(Class::State::LOADED);
38
39 GetClassLinker()->AddClassRoot(ClassRoot::OBJECT, objClass);
40 GetClassLinker()->AddClassRoot(ClassRoot::CLASS, classClass);
41
42 return true;
43 }
44
45 } // namespace ark::test
46