Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "field_helper.h" |
| 18 | |
| 19 | #include "class_linker-inl.h" |
| 20 | #include "dex_file.h" |
| 21 | #include "mirror/dex_cache.h" |
| 22 | #include "runtime.h" |
| 23 | #include "thread-inl.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | mirror::Class* FieldHelper::GetType(bool resolve) { |
| 28 | uint32_t field_index = field_->GetDexFieldIndex(); |
| 29 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
| 30 | return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(), |
| 31 | field_->GetTypeDescriptor()); |
| 32 | } |
| 33 | const DexFile* dex_file = field_->GetDexFile(); |
| 34 | const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index); |
| 35 | mirror::Class* type = field_->GetDexCache()->GetResolvedType(field_id.type_idx_); |
| 36 | if (resolve && (type == nullptr)) { |
| 37 | type = Runtime::Current()->GetClassLinker()->ResolveType(field_id.type_idx_, field_.Get()); |
| 38 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 39 | } |
| 40 | return type; |
| 41 | } |
| 42 | |
| 43 | const char* FieldHelper::GetDeclaringClassDescriptor() { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 44 | return field_->GetDeclaringClass()->GetDescriptor(&declaring_class_descriptor_); |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | } // namespace art |