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 "class_linker-inl.h" 21 #include "gc/accounting/card_table-inl.h" 22 #include "handle_scope.h" 23 #include "mirror/class-inl.h" 24 #include "mirror/object-inl.h" 25 #include "mirror/object_array-inl.h" 26 #include "runtime.h" 27 #include "scoped_thread_state_change-inl.h" 28 #include "utils.h" 29 #include "well_known_classes.h" 30 31 namespace art { 32 33 void 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 46 ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) { 47 DCHECK(GetDeclaringClass()->IsProxyClass()); 48 return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(), descriptor); 49 } 50 51 ObjPtr<mirror::String> ArtField::ResolveGetStringName(Thread* self, 52 const DexFile& dex_file, 53 dex::StringIndex string_idx, 54 ObjPtr<mirror::DexCache> dex_cache) { 55 StackHandleScope<1> hs(self); 56 return Runtime::Current()->GetClassLinker()->ResolveString(dex_file, 57 string_idx, 58 hs.NewHandle(dex_cache)); 59 } 60 61 std::string ArtField::PrettyField(ArtField* f, bool with_type) { 62 if (f == nullptr) { 63 return "null"; 64 } 65 return f->PrettyField(with_type); 66 } 67 68 std::string ArtField::PrettyField(bool with_type) { 69 std::string result; 70 if (with_type) { 71 result += PrettyDescriptor(GetTypeDescriptor()); 72 result += ' '; 73 } 74 std::string temp; 75 result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp)); 76 result += '.'; 77 result += GetName(); 78 return result; 79 } 80 81 void ArtField::GetAccessFlagsDCheck() { 82 CHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); 83 } 84 85 void ArtField::GetOffsetDCheck() { 86 CHECK(GetDeclaringClass()->IsResolved()); 87 } 88 89 } // namespace art 90