blob: ed764bd4b21176a5db4b30d0bb08a018cad2e802 [file] [log] [blame]
Vladimir Markoeebb8212018-06-05 14:57:24 +01001/*
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 Marko6fd16062018-06-26 11:02:04 +010020#include "base/bit_field.h"
21#include "base/bit_utils.h"
Vladimir Markoeebb8212018-06-05 14:57:24 +010022#include "base/mutex.h"
23
24namespace art {
25
26class ClassLinker;
27template <class MirrorType> class ObjPtr;
28class MemberOffset;
29class Thread;
30
31namespace mirror {
32class Object;
33template <class T> class ObjectArray;
34} // namespace mirror
35
36class IntrinsicObjects {
37 public:
Vladimir Marko6fd16062018-06-26 11:02:04 +010038 enum class PatchType {
39 kIntegerValueOfObject,
40 kIntegerValueOfArray,
41
42 kLast = kIntegerValueOfArray
43 };
44
45 static uint32_t EncodePatch(PatchType patch_type, uint32_t index = 0u) {
46 DCHECK(patch_type == PatchType::kIntegerValueOfObject || index == 0u);
47 return PatchTypeField::Encode(static_cast<uint32_t>(patch_type)) | IndexField::Encode(index);
48 }
49
50 static PatchType DecodePatchType(uint32_t intrinsic_data) {
51 return static_cast<PatchType>(PatchTypeField::Decode(intrinsic_data));
52 }
53
54 static uint32_t DecodePatchIndex(uint32_t intrinsic_data) {
55 return IndexField::Decode(intrinsic_data);
56 }
57
Vladimir Markoeebb8212018-06-05 14:57:24 +010058 // Functions for retrieving data for Integer.valueOf().
Vladimir Marko024d69f2019-06-13 10:52:32 +010059 static ObjPtr<mirror::ObjectArray<mirror::Object>> LookupIntegerCache(
60 Thread* self, ClassLinker* class_linker) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markoeebb8212018-06-05 14:57:24 +010061 static ObjPtr<mirror::ObjectArray<mirror::Object>> GetIntegerValueOfCache(
62 ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects)
63 REQUIRES_SHARED(Locks::mutator_lock_);
64 static ObjPtr<mirror::Object> GetIntegerValueOfObject(
65 ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects,
66 uint32_t index) REQUIRES_SHARED(Locks::mutator_lock_);
67 static MemberOffset GetIntegerValueOfArrayDataOffset(
68 ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects)
69 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko6fd16062018-06-26 11:02:04 +010070
71 private:
72 static constexpr size_t kPatchTypeBits =
73 MinimumBitsToStore(static_cast<uint32_t>(PatchType::kLast));
74 static constexpr size_t kIndexBits = BitSizeOf<uint32_t>() - kPatchTypeBits;
75 using PatchTypeField = BitField<uint32_t, 0u, kPatchTypeBits>;
76 using IndexField = BitField<uint32_t, kPatchTypeBits, kIndexBits>;
Vladimir Markoeebb8212018-06-05 14:57:24 +010077};
78
79} // namespace art
80
81#endif // ART_COMPILER_OPTIMIZING_INTRINSIC_OBJECTS_H_