blob: 40daa6db3f0cdc9235bb2e86a0653c60b82dadeb [file] [log] [blame]
Ian Rogers22d5e732014-07-15 22:23:51 -07001/*
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
25namespace art {
26
27mirror::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
43const char* FieldHelper::GetDeclaringClassDescriptor() {
44 uint32_t field_index = field_->GetDexFieldIndex();
45 if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) {
46 DCHECK(field_->IsStatic());
47 DCHECK_LT(field_index, 2U);
48 // 0 == Class[] interfaces; 1 == Class[][] throws;
49 declaring_class_descriptor_ = field_->GetDeclaringClass()->GetDescriptor();
50 return declaring_class_descriptor_.c_str();
51 }
52 const DexFile* dex_file = field_->GetDexFile();
53 const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index);
54 return dex_file->GetFieldDeclaringClassDescriptor(field_id);
55}
56
57} // namespace art