• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
20 #include "base/utils.h"
21 #include "class_linker-inl.h"
22 #include "dex/descriptors_names.h"
23 #include "gc/accounting/card_table-inl.h"
24 #include "handle_scope.h"
25 #include "mirror/class-inl.h"
26 #include "mirror/object-inl.h"
27 #include "mirror/object_array-inl.h"
28 #include "runtime.h"
29 #include "scoped_thread_state_change-inl.h"
30 #include "well_known_classes.h"
31 
32 namespace art {
33 
SetOffset(MemberOffset num_bytes)34 void ArtField::SetOffset(MemberOffset num_bytes) {
35   DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
36   DCHECK_ALIGNED_PARAM(num_bytes.Uint32Value(),
37                        Primitive::ComponentSize(GetTypeAsPrimitiveType()));
38   // Not called within a transaction.
39   offset_ = num_bytes.Uint32Value();
40 }
41 
ProxyFindSystemClass(const char * descriptor)42 ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) {
43   DCHECK(IsProxyField());
44   ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupClass(
45       Thread::Current(), descriptor, /* class_loader= */ nullptr);
46   DCHECK(klass != nullptr);
47   return klass;
48 }
49 
PrettyField(ArtField * f,bool with_type)50 std::string ArtField::PrettyField(ArtField* f, bool with_type) {
51   if (f == nullptr) {
52     return "null";
53   }
54   return f->PrettyField(with_type);
55 }
56 
PrettyField(bool with_type)57 std::string ArtField::PrettyField(bool with_type) {
58   std::string result;
59   if (with_type) {
60     result += PrettyDescriptor(GetTypeDescriptor());
61     result += ' ';
62   }
63   std::string temp;
64   result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp));
65   result += '.';
66   result += GetName();
67   return result;
68 }
69 
70 }  // namespace art
71