Nicolas Geoffray | dbc3387 | 2023-06-12 13:01:02 +0100 | [diff] [blame] | 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 | |
| 24 | namespace art HIDDEN { |
| 25 | |
| 26 | void CodeGenerationData::EmitJitRoots( |
| 27 | /*out*/std::vector<Handle<mirror::Object>>* roots) { |
| 28 | DCHECK(roots->empty()); |
| 29 | roots->reserve(GetNumberOfJitRoots()); |
| 30 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 31 | size_t index = 0; |
| 32 | for (auto& entry : jit_string_roots_) { |
| 33 | // Update the `roots` with the string, and replace the address temporarily |
| 34 | // stored to the index in the table. |
| 35 | uint64_t address = entry.second; |
| 36 | roots->emplace_back(reinterpret_cast<StackReference<mirror::Object>*>(address)); |
| 37 | DCHECK(roots->back() != nullptr); |
| 38 | DCHECK(roots->back()->IsString()); |
| 39 | entry.second = index; |
| 40 | // Ensure the string is strongly interned. This is a requirement on how the JIT |
| 41 | // handles strings. b/32995596 |
| 42 | class_linker->GetInternTable()->InternStrong(roots->back()->AsString()); |
| 43 | ++index; |
| 44 | } |
| 45 | for (auto& entry : jit_class_roots_) { |
| 46 | // Update the `roots` with the class, and replace the address temporarily |
| 47 | // stored to the index in the table. |
| 48 | uint64_t address = entry.second; |
| 49 | roots->emplace_back(reinterpret_cast<StackReference<mirror::Object>*>(address)); |
| 50 | DCHECK(roots->back() != nullptr); |
| 51 | DCHECK(roots->back()->IsClass()); |
| 52 | entry.second = index; |
| 53 | ++index; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } // namespace art |