Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #ifndef ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_ |
| 19 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 20 | #include "base/bit_field.h" |
| 21 | #include "base/bit_utils.h" |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 22 | #include "base/macros.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 23 | #include "base/mutex.h" |
| 24 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 25 | namespace art HIDDEN { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | |
| 27 | class ClassLinker; |
| 28 | template <class MirrorType> class ObjPtr; |
| 29 | class MemberOffset; |
| 30 | class Thread; |
| 31 | |
| 32 | namespace mirror { |
| 33 | class Object; |
| 34 | template <class T> class ObjectArray; |
| 35 | } // namespace mirror |
| 36 | |
| 37 | class IntrinsicObjects { |
| 38 | public: |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 39 | enum class PatchType { |
| 40 | kIntegerValueOfObject, |
| 41 | kIntegerValueOfArray, |
| 42 | |
| 43 | kLast = kIntegerValueOfArray |
| 44 | }; |
| 45 | |
| 46 | static uint32_t EncodePatch(PatchType patch_type, uint32_t index = 0u) { |
| 47 | DCHECK(patch_type == PatchType::kIntegerValueOfObject || index == 0u); |
| 48 | return PatchTypeField::Encode(static_cast<uint32_t>(patch_type)) | IndexField::Encode(index); |
| 49 | } |
| 50 | |
| 51 | static PatchType DecodePatchType(uint32_t intrinsic_data) { |
| 52 | return static_cast<PatchType>(PatchTypeField::Decode(intrinsic_data)); |
| 53 | } |
| 54 | |
| 55 | static uint32_t DecodePatchIndex(uint32_t intrinsic_data) { |
| 56 | return IndexField::Decode(intrinsic_data); |
| 57 | } |
| 58 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 59 | // Functions for retrieving data for Integer.valueOf(). |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 60 | EXPORT static ObjPtr<mirror::ObjectArray<mirror::Object>> LookupIntegerCache( |
Vladimir Marko | 024d69f | 2019-06-13 10:52:32 +0100 | [diff] [blame] | 61 | Thread* self, ClassLinker* class_linker) REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 62 | EXPORT static ObjPtr<mirror::ObjectArray<mirror::Object>> GetIntegerValueOfCache( |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 63 | ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects) |
| 64 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 65 | EXPORT static ObjPtr<mirror::Object> GetIntegerValueOfObject( |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 66 | ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects, |
| 67 | uint32_t index) REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 68 | EXPORT static MemberOffset GetIntegerValueOfArrayDataOffset( |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 69 | ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects) |
| 70 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | static constexpr size_t kPatchTypeBits = |
| 74 | MinimumBitsToStore(static_cast<uint32_t>(PatchType::kLast)); |
| 75 | static constexpr size_t kIndexBits = BitSizeOf<uint32_t>() - kPatchTypeBits; |
| 76 | using PatchTypeField = BitField<uint32_t, 0u, kPatchTypeBits>; |
| 77 | using IndexField = BitField<uint32_t, kPatchTypeBits, kIndexBits>; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace art |
| 81 | |
| 82 | #endif // ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_ |