blob: a4a6e5a4fb30f6c3a60bca31a3d1ad10f56621e6 [file] [log] [blame]
Mathieu Chartierc7853442015-03-27 14:35:38 -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 "art_field.h"
18
19#include "art_field-inl.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010020#include "class_linker-inl.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070021#include "gc/accounting/card_table-inl.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010022#include "handle_scope.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070023#include "mirror/class-inl.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070024#include "mirror/object-inl.h"
25#include "mirror/object_array-inl.h"
26#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070027#include "scoped_thread_state_change-inl.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070028#include "utils.h"
29#include "well_known_classes.h"
30
31namespace art {
32
Mathieu Chartierc7853442015-03-27 14:35:38 -070033void ArtField::SetOffset(MemberOffset num_bytes) {
34 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
35 if (kIsDebugBuild && Runtime::Current()->IsAotCompiler() &&
36 Runtime::Current()->IsCompilingBootImage()) {
37 Primitive::Type type = GetTypeAsPrimitiveType();
38 if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) {
39 DCHECK_ALIGNED(num_bytes.Uint32Value(), 8);
40 }
41 }
42 // Not called within a transaction.
43 offset_ = num_bytes.Uint32Value();
44}
45
Mathieu Chartier3398c782016-09-30 10:27:43 -070046ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) {
Nicolas Geoffray3a090922015-11-24 09:17:30 +000047 DCHECK(GetDeclaringClass()->IsProxyClass());
Vladimir Marko3481ba22015-04-13 12:22:36 +010048 return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(), descriptor);
49}
50
Andreas Gampea5b09a62016-11-17 15:21:22 -080051ObjPtr<mirror::Class> ArtField::ResolveGetType(dex::TypeIndex type_idx) {
Vladimir Marko3481ba22015-04-13 12:22:36 +010052 return Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
53}
54
Mathieu Chartier3398c782016-09-30 10:27:43 -070055ObjPtr<mirror::String> ArtField::ResolveGetStringName(Thread* self,
56 const DexFile& dex_file,
Andreas Gampe8a0128a2016-11-28 07:38:35 -080057 dex::StringIndex string_idx,
Mathieu Chartier3398c782016-09-30 10:27:43 -070058 ObjPtr<mirror::DexCache> dex_cache) {
Vladimir Marko3481ba22015-04-13 12:22:36 +010059 StackHandleScope<1> hs(self);
Mathieu Chartier3398c782016-09-30 10:27:43 -070060 return Runtime::Current()->GetClassLinker()->ResolveString(dex_file,
61 string_idx,
62 hs.NewHandle(dex_cache));
Vladimir Marko3481ba22015-04-13 12:22:36 +010063}
64
David Sehr709b0702016-10-13 09:12:37 -070065std::string ArtField::PrettyField(ArtField* f, bool with_type) {
66 if (f == nullptr) {
67 return "null";
68 }
69 return f->PrettyField(with_type);
70}
71
72std::string ArtField::PrettyField(bool with_type) {
73 std::string result;
74 if (with_type) {
75 result += PrettyDescriptor(GetTypeDescriptor());
76 result += ' ';
77 }
78 std::string temp;
79 result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp));
80 result += '.';
81 result += GetName();
82 return result;
83}
84
85
Mathieu Chartierc7853442015-03-27 14:35:38 -070086} // namespace art