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" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 20 | #include "base/utils.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 21 | #include "class_linker-inl.h" |
David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 22 | #include "dex/descriptors_names.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 23 | #include "gc/accounting/card_table-inl.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 24 | #include "handle_scope.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 25 | #include "mirror/class-inl.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 26 | #include "mirror/object-inl.h" |
| 27 | #include "mirror/object_array-inl.h" |
| 28 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 29 | #include "scoped_thread_state_change-inl.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 30 | #include "well_known_classes.h" |
| 31 | |
| 32 | namespace art { |
| 33 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 34 | void ArtField::SetOffset(MemberOffset num_bytes) { |
| 35 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
| 36 | if (kIsDebugBuild && Runtime::Current()->IsAotCompiler() && |
| 37 | Runtime::Current()->IsCompilingBootImage()) { |
| 38 | Primitive::Type type = GetTypeAsPrimitiveType(); |
| 39 | if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) { |
| 40 | DCHECK_ALIGNED(num_bytes.Uint32Value(), 8); |
| 41 | } |
| 42 | } |
| 43 | // Not called within a transaction. |
| 44 | offset_ = num_bytes.Uint32Value(); |
| 45 | } |
| 46 | |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 47 | ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 48 | DCHECK(GetDeclaringClass()->IsProxyClass()); |
Vladimir Marko | 208f670 | 2017-12-08 12:00:50 +0000 | [diff] [blame] | 49 | ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupClass( |
| 50 | Thread::Current(), descriptor, /* class_loader */ nullptr); |
| 51 | DCHECK(klass != nullptr); |
| 52 | return klass; |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 53 | } |
| 54 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 55 | std::string ArtField::PrettyField(ArtField* f, bool with_type) { |
| 56 | if (f == nullptr) { |
| 57 | return "null"; |
| 58 | } |
| 59 | return f->PrettyField(with_type); |
| 60 | } |
| 61 | |
| 62 | std::string ArtField::PrettyField(bool with_type) { |
| 63 | std::string result; |
| 64 | if (with_type) { |
| 65 | result += PrettyDescriptor(GetTypeDescriptor()); |
| 66 | result += ' '; |
| 67 | } |
| 68 | std::string temp; |
| 69 | result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp)); |
| 70 | result += '.'; |
| 71 | result += GetName(); |
| 72 | return result; |
| 73 | } |
| 74 | |
Andreas Gampe | a1d2f95 | 2017-04-20 22:53:58 -0700 | [diff] [blame] | 75 | void ArtField::GetAccessFlagsDCheck() { |
| 76 | CHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
| 77 | } |
| 78 | |
| 79 | void ArtField::GetOffsetDCheck() { |
| 80 | CHECK(GetDeclaringClass()->IsResolved()); |
| 81 | } |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 82 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 83 | } // namespace art |