• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 panda::test {
22 
23 // Runtime::GetCurrent() can not be used in .h files
InitializeImpl(bool compressed_string_enabled)24 bool ClassLinkerTestExtension::InitializeImpl([[maybe_unused]] bool compressed_string_enabled)
25 {
26     LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(GetLanguage());
27 
28     auto *class_class = CreateClass(ctx.GetClassClassDescriptor(), GetClassVTableSize(ClassRoot::CLASS),
29                                     GetClassIMTSize(ClassRoot::CLASS), GetClassSize(ClassRoot::CLASS));
30     coretypes::Class::FromRuntimeClass(class_class)->SetClass(class_class);
31     class_class->SetState(Class::State::LOADED);
32 
33     auto *obj_class = CreateClass(ctx.GetObjectClassDescriptor(), GetClassVTableSize(ClassRoot::OBJECT),
34                                   GetClassIMTSize(ClassRoot::OBJECT), GetClassSize(ClassRoot::OBJECT));
35     obj_class->SetObjectSize(ObjectHeader::ObjectHeaderSize());
36     class_class->SetBase(obj_class);
37     obj_class->SetState(Class::State::LOADED);
38 
39     GetClassLinker()->AddClassRoot(ClassRoot::OBJECT, obj_class);
40     GetClassLinker()->AddClassRoot(ClassRoot::CLASS, class_class);
41 
42     return true;
43 }
44 
45 }  // namespace panda::test
46