xref: /aosp_15_r20/art/compiler/optimizing/code_generation_data.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "class_linker.h"
18 #include "code_generation_data.h"
19 #include "code_generator.h"
20 #include "intern_table.h"
21 #include "mirror/object-inl.h"
22 #include "runtime.h"
23 #include "well_known_classes-inl.h"
24 
25 namespace art HIDDEN {
26 
EmitJitRoots(std::vector<Handle<mirror::Object>> * roots)27 void CodeGenerationData::EmitJitRoots(
28     /*out*/std::vector<Handle<mirror::Object>>* roots) {
29   DCHECK(roots->empty());
30   roots->reserve(GetNumberOfJitRoots());
31   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
32   size_t index = 0;
33   for (auto& entry : jit_string_roots_) {
34     // Update the `roots` with the string, and replace the address temporarily
35     // stored to the index in the table.
36     uint64_t address = entry.second;
37     roots->emplace_back(reinterpret_cast<StackReference<mirror::Object>*>(address));
38     DCHECK(roots->back() != nullptr);
39     DCHECK(roots->back()->IsString());
40     entry.second = index;
41     // Ensure the string is strongly interned. This is a requirement on how the JIT
42     // handles strings. b/32995596
43     class_linker->GetInternTable()->InternStrong(roots->back()->AsString());
44     ++index;
45   }
46   for (auto& entry : jit_class_roots_) {
47     // Update the `roots` with the class, and replace the address temporarily
48     // stored to the index in the table.
49     uint64_t address = entry.second;
50     roots->emplace_back(reinterpret_cast<StackReference<mirror::Object>*>(address));
51     DCHECK(roots->back() != nullptr);
52     DCHECK(roots->back()->IsClass());
53     entry.second = index;
54     ++index;
55   }
56   for (auto& entry : jit_method_type_roots_) {
57     // Update the `roots` with the MethodType, and replace the address temporarily
58     // stored to the index in the table.
59     uint64_t address = entry.second;
60     roots->emplace_back(reinterpret_cast<StackReference<mirror::Object>*>(address));
61     DCHECK(roots->back() != nullptr);
62     DCHECK(roots->back()->InstanceOf(WellKnownClasses::java_lang_invoke_MethodType.Get()));
63     entry.second = index;
64     ++index;
65   }
66 }
67 
68 }  // namespace art
69