Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "intrinsics.h" |
| 18 | |
Andreas Gampe | a1d2f95 | 2017-04-20 22:53:58 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 20 | #include "art_method-inl.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 21 | #include "base/utils.h" |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 22 | #include "class_linker.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 23 | #include "dex/invoke_type.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "driver/compiler_driver.h" |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 25 | #include "driver/compiler_options.h" |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 26 | #include "mirror/dex_cache-inl.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 27 | #include "nodes.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 28 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 29 | #include "thread-current-inl.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
Orion Hodson | cfcc9cf | 2017-09-29 15:07:27 +0100 | [diff] [blame] | 33 | // Check that intrinsic enum values fit within space set aside in ArtMethod modifier flags. |
| 34 | #define CHECK_INTRINSICS_ENUM_VALUES(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \ |
| 35 | static_assert( \ |
| 36 | static_cast<uint32_t>(Intrinsics::k ## Name) <= (kAccIntrinsicBits >> CTZ(kAccIntrinsicBits)), \ |
Orion Hodson | 4a4610a | 2017-09-28 16:57:55 +0100 | [diff] [blame] | 37 | "Instrinsics enumeration space overflow."); |
Orion Hodson | cfcc9cf | 2017-09-29 15:07:27 +0100 | [diff] [blame] | 38 | #include "intrinsics_list.h" |
| 39 | INTRINSICS_LIST(CHECK_INTRINSICS_ENUM_VALUES) |
| 40 | #undef INTRINSICS_LIST |
| 41 | #undef CHECK_INTRINSICS_ENUM_VALUES |
| 42 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 43 | // Function that returns whether an intrinsic is static/direct or virtual. |
| 44 | static inline InvokeType GetIntrinsicInvokeType(Intrinsics i) { |
| 45 | switch (i) { |
| 46 | case Intrinsics::kNone: |
| 47 | return kInterface; // Non-sensical for intrinsic. |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 48 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \ |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 49 | case Intrinsics::k ## Name: \ |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 50 | return IsStatic; |
| 51 | #include "intrinsics_list.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 52 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 53 | #undef INTRINSICS_LIST |
| 54 | #undef OPTIMIZING_INTRINSICS |
| 55 | } |
| 56 | return kInterface; |
| 57 | } |
| 58 | |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 59 | // Function that returns whether an intrinsic needs an environment or not. |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 60 | static inline IntrinsicNeedsEnvironmentOrCache NeedsEnvironmentOrCache(Intrinsics i) { |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 61 | switch (i) { |
| 62 | case Intrinsics::kNone: |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 63 | return kNeedsEnvironmentOrCache; // Non-sensical for intrinsic. |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 64 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \ |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 65 | case Intrinsics::k ## Name: \ |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 66 | return NeedsEnvironmentOrCache; |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 67 | #include "intrinsics_list.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 68 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 69 | #undef INTRINSICS_LIST |
| 70 | #undef OPTIMIZING_INTRINSICS |
| 71 | } |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 72 | return kNeedsEnvironmentOrCache; |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 73 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 74 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 75 | // Function that returns whether an intrinsic has side effects. |
| 76 | static inline IntrinsicSideEffects GetSideEffects(Intrinsics i) { |
| 77 | switch (i) { |
| 78 | case Intrinsics::kNone: |
| 79 | return kAllSideEffects; |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 80 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \ |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 81 | case Intrinsics::k ## Name: \ |
| 82 | return SideEffects; |
| 83 | #include "intrinsics_list.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 84 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 85 | #undef INTRINSICS_LIST |
| 86 | #undef OPTIMIZING_INTRINSICS |
| 87 | } |
| 88 | return kAllSideEffects; |
| 89 | } |
| 90 | |
| 91 | // Function that returns whether an intrinsic can throw exceptions. |
| 92 | static inline IntrinsicExceptions GetExceptions(Intrinsics i) { |
| 93 | switch (i) { |
| 94 | case Intrinsics::kNone: |
| 95 | return kCanThrow; |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 96 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \ |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 97 | case Intrinsics::k ## Name: \ |
| 98 | return Exceptions; |
| 99 | #include "intrinsics_list.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 100 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 101 | #undef INTRINSICS_LIST |
| 102 | #undef OPTIMIZING_INTRINSICS |
| 103 | } |
| 104 | return kCanThrow; |
| 105 | } |
| 106 | |
Orion Hodson | 4c71d00 | 2017-11-29 11:03:25 +0000 | [diff] [blame] | 107 | static bool CheckInvokeType(Intrinsics intrinsic, HInvoke* invoke) |
| 108 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 109 | // Whenever the intrinsic is marked as static, report an error if we find an InvokeVirtual. |
| 110 | // |
| 111 | // Whenever the intrinsic is marked as direct and we find an InvokeVirtual, a devirtualization |
| 112 | // failure occured. We might be in a situation where we have inlined a method that calls an |
| 113 | // intrinsic, but that method is in a different dex file on which we do not have a |
| 114 | // verified_method that would have helped the compiler driver sharpen the call. In that case, |
| 115 | // make sure that the intrinsic is actually for some final method (or in a final class), as |
| 116 | // otherwise the intrinsics setup is broken. |
| 117 | // |
| 118 | // For the last direction, we have intrinsics for virtual functions that will perform a check |
| 119 | // inline. If the precise type is known, however, the instruction will be sharpened to an |
| 120 | // InvokeStaticOrDirect. |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 121 | InvokeType intrinsic_type = GetIntrinsicInvokeType(intrinsic); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 122 | InvokeType invoke_type = invoke->GetInvokeType(); |
Orion Hodson | cfcc9cf | 2017-09-29 15:07:27 +0100 | [diff] [blame] | 123 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 124 | switch (intrinsic_type) { |
| 125 | case kStatic: |
| 126 | return (invoke_type == kStatic); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 127 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 128 | case kDirect: |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 129 | if (invoke_type == kDirect) { |
| 130 | return true; |
| 131 | } |
| 132 | if (invoke_type == kVirtual) { |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 133 | ArtMethod* art_method = invoke->GetResolvedMethod(); |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 134 | return (art_method->IsFinal() || art_method->GetDeclaringClass()->IsFinal()); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 135 | } |
| 136 | return false; |
| 137 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 138 | case kVirtual: |
| 139 | // Call might be devirtualized. |
Mingyao Yang | 6b1aebe | 2017-11-27 15:39:04 -0800 | [diff] [blame] | 140 | return (invoke_type == kVirtual || invoke_type == kDirect || invoke_type == kInterface); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 141 | |
Orion Hodson | b1b5206 | 2017-11-27 11:51:42 +0000 | [diff] [blame] | 142 | case kSuper: |
| 143 | case kInterface: |
| 144 | case kPolymorphic: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 145 | return false; |
| 146 | } |
Orion Hodson | b1b5206 | 2017-11-27 11:51:42 +0000 | [diff] [blame] | 147 | LOG(FATAL) << "Unknown intrinsic invoke type: " << intrinsic_type; |
| 148 | UNREACHABLE(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Mingyao Yang | 6b1aebe | 2017-11-27 15:39:04 -0800 | [diff] [blame] | 151 | bool IntrinsicsRecognizer::Recognize(HInvoke* invoke, |
| 152 | ArtMethod* art_method, |
| 153 | /*out*/ bool* wrong_invoke_type) { |
| 154 | if (art_method == nullptr) { |
| 155 | art_method = invoke->GetResolvedMethod(); |
| 156 | } |
Orion Hodson | b1b5206 | 2017-11-27 11:51:42 +0000 | [diff] [blame] | 157 | *wrong_invoke_type = false; |
| 158 | if (art_method == nullptr || !art_method->IsIntrinsic()) { |
| 159 | return false; |
| 160 | } |
| 161 | |
Orion Hodson | 4c71d00 | 2017-11-29 11:03:25 +0000 | [diff] [blame] | 162 | // TODO: b/65872996 The intent is that polymorphic signature methods should |
| 163 | // be compiler intrinsics. At present, they are only interpreter intrinsics. |
| 164 | if (art_method->IsPolymorphicSignature()) { |
| 165 | return false; |
Aart Bik | f0010dd | 2017-11-21 16:31:53 -0800 | [diff] [blame] | 166 | } |
Orion Hodson | b1b5206 | 2017-11-27 11:51:42 +0000 | [diff] [blame] | 167 | |
| 168 | Intrinsics intrinsic = static_cast<Intrinsics>(art_method->GetIntrinsic()); |
| 169 | if (CheckInvokeType(intrinsic, invoke) == false) { |
| 170 | *wrong_invoke_type = true; |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | invoke->SetIntrinsic(intrinsic, |
| 175 | NeedsEnvironmentOrCache(intrinsic), |
| 176 | GetSideEffects(intrinsic), |
| 177 | GetExceptions(intrinsic)); |
| 178 | return true; |
Aart Bik | f0010dd | 2017-11-21 16:31:53 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Aart Bik | 2477320 | 2018-04-26 10:28:51 -0700 | [diff] [blame] | 181 | bool IntrinsicsRecognizer::Run() { |
| 182 | bool didRecognize = false; |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 183 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 184 | for (HBasicBlock* block : graph_->GetReversePostOrder()) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 185 | for (HInstructionIterator inst_it(block->GetInstructions()); !inst_it.Done(); |
| 186 | inst_it.Advance()) { |
| 187 | HInstruction* inst = inst_it.Current(); |
| 188 | if (inst->IsInvoke()) { |
Aart Bik | f0010dd | 2017-11-21 16:31:53 -0800 | [diff] [blame] | 189 | bool wrong_invoke_type = false; |
Mingyao Yang | 6b1aebe | 2017-11-27 15:39:04 -0800 | [diff] [blame] | 190 | if (Recognize(inst->AsInvoke(), /* art_method */ nullptr, &wrong_invoke_type)) { |
Aart Bik | 2477320 | 2018-04-26 10:28:51 -0700 | [diff] [blame] | 191 | didRecognize = true; |
Aart Bik | f0010dd | 2017-11-21 16:31:53 -0800 | [diff] [blame] | 192 | MaybeRecordStat(stats_, MethodCompilationStat::kIntrinsicRecognized); |
| 193 | } else if (wrong_invoke_type) { |
| 194 | LOG(WARNING) |
| 195 | << "Found an intrinsic with unexpected invoke type: " |
| 196 | << inst->AsInvoke()->GetResolvedMethod()->PrettyMethod() << " " |
| 197 | << inst->DebugName(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
Aart Bik | 2477320 | 2018-04-26 10:28:51 -0700 | [diff] [blame] | 202 | return didRecognize; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic) { |
| 206 | switch (intrinsic) { |
| 207 | case Intrinsics::kNone: |
David Brazdil | 109c89a | 2015-07-31 17:10:43 +0100 | [diff] [blame] | 208 | os << "None"; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 209 | break; |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 210 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \ |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 211 | case Intrinsics::k ## Name: \ |
| 212 | os << # Name; \ |
| 213 | break; |
| 214 | #include "intrinsics_list.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 215 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 216 | #undef STATIC_INTRINSICS_LIST |
| 217 | #undef VIRTUAL_INTRINSICS_LIST |
| 218 | #undef OPTIMIZING_INTRINSICS |
| 219 | } |
| 220 | return os; |
| 221 | } |
| 222 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 223 | void IntrinsicVisitor::ComputeIntegerValueOfLocations(HInvoke* invoke, |
| 224 | CodeGenerator* codegen, |
| 225 | Location return_location, |
| 226 | Location first_argument_location) { |
| 227 | if (Runtime::Current()->IsAotCompiler()) { |
| 228 | if (codegen->GetCompilerOptions().IsBootImage() || |
| 229 | codegen->GetCompilerOptions().GetCompilePic()) { |
| 230 | // TODO(ngeoffray): Support boot image compilation. |
| 231 | return; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | IntegerValueOfInfo info = ComputeIntegerValueOfInfo(); |
| 236 | |
| 237 | // Most common case is that we have found all we needed (classes are initialized |
| 238 | // and in the boot image). Bail if not. |
| 239 | if (info.integer_cache == nullptr || |
| 240 | info.integer == nullptr || |
| 241 | info.cache == nullptr || |
| 242 | info.value_offset == 0 || |
| 243 | // low and high cannot be 0, per the spec. |
| 244 | info.low == 0 || |
| 245 | info.high == 0) { |
| 246 | LOG(INFO) << "Integer.valueOf will not be optimized"; |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | // The intrinsic will call if it needs to allocate a j.l.Integer. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 251 | LocationSummary* locations = new (invoke->GetBlock()->GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 252 | invoke, LocationSummary::kCallOnMainOnly, kIntrinsified); |
| 253 | if (!invoke->InputAt(0)->IsConstant()) { |
| 254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 255 | } |
| 256 | locations->AddTemp(first_argument_location); |
| 257 | locations->SetOut(return_location); |
| 258 | } |
| 259 | |
| 260 | IntrinsicVisitor::IntegerValueOfInfo IntrinsicVisitor::ComputeIntegerValueOfInfo() { |
| 261 | // Note that we could cache all of the data looked up here. but there's no good |
| 262 | // location for it. We don't want to add it to WellKnownClasses, to avoid creating global |
| 263 | // jni values. Adding it as state to the compiler singleton seems like wrong |
| 264 | // separation of concerns. |
| 265 | // The need for this data should be pretty rare though. |
| 266 | |
| 267 | // The most common case is that the classes are in the boot image and initialized, |
| 268 | // which is easy to generate code for. We bail if not. |
| 269 | Thread* self = Thread::Current(); |
| 270 | ScopedObjectAccess soa(self); |
| 271 | Runtime* runtime = Runtime::Current(); |
| 272 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 273 | gc::Heap* heap = runtime->GetHeap(); |
| 274 | IntegerValueOfInfo info; |
| 275 | info.integer_cache = class_linker->FindSystemClass(self, "Ljava/lang/Integer$IntegerCache;"); |
| 276 | if (info.integer_cache == nullptr) { |
| 277 | self->ClearException(); |
| 278 | return info; |
| 279 | } |
| 280 | if (!heap->ObjectIsInBootImageSpace(info.integer_cache) || !info.integer_cache->IsInitialized()) { |
| 281 | // Optimization only works if the class is initialized and in the boot image. |
| 282 | return info; |
| 283 | } |
| 284 | info.integer = class_linker->FindSystemClass(self, "Ljava/lang/Integer;"); |
| 285 | if (info.integer == nullptr) { |
| 286 | self->ClearException(); |
| 287 | return info; |
| 288 | } |
| 289 | if (!heap->ObjectIsInBootImageSpace(info.integer) || !info.integer->IsInitialized()) { |
| 290 | // Optimization only works if the class is initialized and in the boot image. |
| 291 | return info; |
| 292 | } |
| 293 | |
| 294 | ArtField* field = info.integer_cache->FindDeclaredStaticField("cache", "[Ljava/lang/Integer;"); |
| 295 | if (field == nullptr) { |
| 296 | return info; |
| 297 | } |
| 298 | info.cache = static_cast<mirror::ObjectArray<mirror::Object>*>( |
| 299 | field->GetObject(info.integer_cache).Ptr()); |
| 300 | if (info.cache == nullptr) { |
| 301 | return info; |
| 302 | } |
| 303 | |
| 304 | if (!heap->ObjectIsInBootImageSpace(info.cache)) { |
| 305 | // Optimization only works if the object is in the boot image. |
| 306 | return info; |
| 307 | } |
| 308 | |
| 309 | field = info.integer->FindDeclaredInstanceField("value", "I"); |
| 310 | if (field == nullptr) { |
| 311 | return info; |
| 312 | } |
| 313 | info.value_offset = field->GetOffset().Int32Value(); |
| 314 | |
| 315 | field = info.integer_cache->FindDeclaredStaticField("low", "I"); |
| 316 | if (field == nullptr) { |
| 317 | return info; |
| 318 | } |
| 319 | info.low = field->GetInt(info.integer_cache); |
| 320 | |
| 321 | field = info.integer_cache->FindDeclaredStaticField("high", "I"); |
| 322 | if (field == nullptr) { |
| 323 | return info; |
| 324 | } |
| 325 | info.high = field->GetInt(info.integer_cache); |
| 326 | |
| 327 | DCHECK_EQ(info.cache->GetLength(), info.high - info.low + 1); |
| 328 | return info; |
| 329 | } |
| 330 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 331 | } // namespace art |