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