xref: /aosp_15_r20/art/runtime/art_field.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include "art_field.h"
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include "art_field-inl.h"
20*795d594fSAndroid Build Coastguard Worker #include "base/utils.h"
21*795d594fSAndroid Build Coastguard Worker #include "class_linker-inl.h"
22*795d594fSAndroid Build Coastguard Worker #include "dex/descriptors_names.h"
23*795d594fSAndroid Build Coastguard Worker #include "gc/accounting/card_table-inl.h"
24*795d594fSAndroid Build Coastguard Worker #include "handle_scope.h"
25*795d594fSAndroid Build Coastguard Worker #include "mirror/class-inl.h"
26*795d594fSAndroid Build Coastguard Worker #include "mirror/object-inl.h"
27*795d594fSAndroid Build Coastguard Worker #include "mirror/object_array-inl.h"
28*795d594fSAndroid Build Coastguard Worker #include "runtime.h"
29*795d594fSAndroid Build Coastguard Worker #include "scoped_thread_state_change-inl.h"
30*795d594fSAndroid Build Coastguard Worker #include "well_known_classes.h"
31*795d594fSAndroid Build Coastguard Worker 
32*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
33*795d594fSAndroid Build Coastguard Worker 
SetOffset(MemberOffset num_bytes)34*795d594fSAndroid Build Coastguard Worker void ArtField::SetOffset(MemberOffset num_bytes) {
35*795d594fSAndroid Build Coastguard Worker   DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
36*795d594fSAndroid Build Coastguard Worker   DCHECK_ALIGNED_PARAM(num_bytes.Uint32Value(),
37*795d594fSAndroid Build Coastguard Worker                        Primitive::ComponentSize(GetTypeAsPrimitiveType()));
38*795d594fSAndroid Build Coastguard Worker   // Not called within a transaction.
39*795d594fSAndroid Build Coastguard Worker   offset_ = num_bytes.Uint32Value();
40*795d594fSAndroid Build Coastguard Worker }
41*795d594fSAndroid Build Coastguard Worker 
ProxyFindSystemClass(std::string_view descriptor)42*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(std::string_view descriptor) {
43*795d594fSAndroid Build Coastguard Worker   DCHECK(IsProxyField());
44*795d594fSAndroid Build Coastguard Worker   ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupClass(
45*795d594fSAndroid Build Coastguard Worker       Thread::Current(), descriptor, /* class_loader= */ nullptr);
46*795d594fSAndroid Build Coastguard Worker   DCHECK(klass != nullptr);
47*795d594fSAndroid Build Coastguard Worker   return klass;
48*795d594fSAndroid Build Coastguard Worker }
49*795d594fSAndroid Build Coastguard Worker 
PrettyField(ArtField * f,bool with_type)50*795d594fSAndroid Build Coastguard Worker std::string ArtField::PrettyField(ArtField* f, bool with_type) {
51*795d594fSAndroid Build Coastguard Worker   if (f == nullptr) {
52*795d594fSAndroid Build Coastguard Worker     return "null";
53*795d594fSAndroid Build Coastguard Worker   }
54*795d594fSAndroid Build Coastguard Worker   return f->PrettyField(with_type);
55*795d594fSAndroid Build Coastguard Worker }
56*795d594fSAndroid Build Coastguard Worker 
PrettyField(bool with_type)57*795d594fSAndroid Build Coastguard Worker std::string ArtField::PrettyField(bool with_type) {
58*795d594fSAndroid Build Coastguard Worker   std::string result;
59*795d594fSAndroid Build Coastguard Worker   if (with_type) {
60*795d594fSAndroid Build Coastguard Worker     result += PrettyDescriptor(GetTypeDescriptor());
61*795d594fSAndroid Build Coastguard Worker     result += ' ';
62*795d594fSAndroid Build Coastguard Worker   }
63*795d594fSAndroid Build Coastguard Worker   // Note: `GetDeclaringClassDescriptor()` does not support proxy classes.
64*795d594fSAndroid Build Coastguard Worker   std::string temp;
65*795d594fSAndroid Build Coastguard Worker   result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp));
66*795d594fSAndroid Build Coastguard Worker   result += '.';
67*795d594fSAndroid Build Coastguard Worker   result += GetName();
68*795d594fSAndroid Build Coastguard Worker   return result;
69*795d594fSAndroid Build Coastguard Worker }
70*795d594fSAndroid Build Coastguard Worker 
71*795d594fSAndroid Build Coastguard Worker }  // namespace art
72