blob: b867621f02358e37e4aad480f0df63a1a48dede3 [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"
David Sehr8f4b0562018-03-02 12:01:51 -080020#include "base/utils.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010021#include "class_linker-inl.h"
David Sehrb2ec9f52018-02-21 13:20:31 -080022#include "dex/descriptors_names.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070023#include "gc/accounting/card_table-inl.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010024#include "handle_scope.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070025#include "mirror/class-inl.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070026#include "mirror/object-inl.h"
27#include "mirror/object_array-inl.h"
28#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070029#include "scoped_thread_state_change-inl.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070030#include "well_known_classes.h"
31
32namespace art {
33
Mathieu Chartierc7853442015-03-27 14:35:38 -070034void 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 Chartier3398c782016-09-30 10:27:43 -070047ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) {
Nicolas Geoffray3a090922015-11-24 09:17:30 +000048 DCHECK(GetDeclaringClass()->IsProxyClass());
Vladimir Marko208f6702017-12-08 12:00:50 +000049 ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupClass(
50 Thread::Current(), descriptor, /* class_loader */ nullptr);
51 DCHECK(klass != nullptr);
52 return klass;
Vladimir Marko3481ba22015-04-13 12:22:36 +010053}
54
Mathieu Chartier3398c782016-09-30 10:27:43 -070055ObjPtr<mirror::String> ArtField::ResolveGetStringName(Thread* self,
Andreas Gampe8a0128a2016-11-28 07:38:35 -080056 dex::StringIndex string_idx,
Mathieu Chartier3398c782016-09-30 10:27:43 -070057 ObjPtr<mirror::DexCache> dex_cache) {
Vladimir Marko3481ba22015-04-13 12:22:36 +010058 StackHandleScope<1> hs(self);
Vladimir Markoa64b52d2017-12-08 16:27:49 +000059 return Runtime::Current()->GetClassLinker()->ResolveString(string_idx, hs.NewHandle(dex_cache));
Vladimir Marko3481ba22015-04-13 12:22:36 +010060}
61
David Sehr709b0702016-10-13 09:12:37 -070062std::string ArtField::PrettyField(ArtField* f, bool with_type) {
63 if (f == nullptr) {
64 return "null";
65 }
66 return f->PrettyField(with_type);
67}
68
69std::string ArtField::PrettyField(bool with_type) {
70 std::string result;
71 if (with_type) {
72 result += PrettyDescriptor(GetTypeDescriptor());
73 result += ' ';
74 }
75 std::string temp;
76 result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp));
77 result += '.';
78 result += GetName();
79 return result;
80}
81
Andreas Gampea1d2f952017-04-20 22:53:58 -070082void ArtField::GetAccessFlagsDCheck() {
83 CHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
84}
85
86void ArtField::GetOffsetDCheck() {
87 CHECK(GetDeclaringClass()->IsResolved());
88}
David Sehr709b0702016-10-13 09:12:37 -070089
Mathieu Chartierc7853442015-03-27 14:35:38 -070090} // namespace art