Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -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 "art_field.h" |
| 18 | |
| 19 | #include "art_field-inl.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 20 | #include "class_linker-inl.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 21 | #include "gc/accounting/card_table-inl.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 22 | #include "handle_scope.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "mirror/class-inl.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 24 | #include "mirror/object-inl.h" |
| 25 | #include "mirror/object_array-inl.h" |
| 26 | #include "runtime.h" |
| 27 | #include "scoped_thread_state_change.h" |
| 28 | #include "utils.h" |
| 29 | #include "well_known_classes.h" |
| 30 | |
| 31 | namespace art { |
| 32 | |
| 33 | ArtField::ArtField() : access_flags_(0), field_dex_idx_(0), offset_(0) { |
| 34 | declaring_class_ = GcRoot<mirror::Class>(nullptr); |
| 35 | } |
| 36 | |
| 37 | void ArtField::SetOffset(MemberOffset num_bytes) { |
| 38 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
| 39 | if (kIsDebugBuild && Runtime::Current()->IsAotCompiler() && |
| 40 | Runtime::Current()->IsCompilingBootImage()) { |
| 41 | Primitive::Type type = GetTypeAsPrimitiveType(); |
| 42 | if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) { |
| 43 | DCHECK_ALIGNED(num_bytes.Uint32Value(), 8); |
| 44 | } |
| 45 | } |
| 46 | // Not called within a transaction. |
| 47 | offset_ = num_bytes.Uint32Value(); |
| 48 | } |
| 49 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 50 | ArtField* ArtField::FindInstanceFieldWithOffset(mirror::Class* klass, uint32_t field_offset) { |
| 51 | DCHECK(klass != nullptr); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 52 | for (ArtField& field : klass->GetIFields()) { |
| 53 | if (field.GetOffset().Uint32Value() == field_offset) { |
| 54 | return &field; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | // We did not find field in the class: look into superclass. |
| 58 | return (klass->GetSuperClass() != nullptr) ? |
| 59 | FindInstanceFieldWithOffset(klass->GetSuperClass(), field_offset) : nullptr; |
| 60 | } |
| 61 | |
Hiroshi Yamauchi | eb2baaf | 2015-05-13 21:14:22 -0700 | [diff] [blame] | 62 | ArtField* ArtField::FindStaticFieldWithOffset(mirror::Class* klass, uint32_t field_offset) { |
| 63 | DCHECK(klass != nullptr); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 64 | for (ArtField& field : klass->GetSFields()) { |
| 65 | if (field.GetOffset().Uint32Value() == field_offset) { |
| 66 | return &field; |
Hiroshi Yamauchi | eb2baaf | 2015-05-13 21:14:22 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 72 | mirror::Class* ArtField::ProxyFindSystemClass(const char* descriptor) { |
| 73 | DCHECK(GetDeclaringClass()->IsProxyClass()); |
| 74 | return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(), descriptor); |
| 75 | } |
| 76 | |
| 77 | mirror::Class* ArtField::ResolveGetType(uint32_t type_idx) { |
| 78 | return Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); |
| 79 | } |
| 80 | |
| 81 | mirror::String* ArtField::ResolveGetStringName(Thread* self, const DexFile& dex_file, |
| 82 | uint32_t string_idx, mirror::DexCache* dex_cache) { |
| 83 | StackHandleScope<1> hs(self); |
| 84 | return Runtime::Current()->GetClassLinker()->ResolveString( |
| 85 | dex_file, string_idx, hs.NewHandle(dex_cache)); |
| 86 | } |
| 87 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 88 | } // namespace art |