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 "dex_cache.h" 18 19 #include "art_method-inl.h" 20 #include "base/logging.h" 21 #include "class_linker.h" 22 #include "gc/accounting/card_table-inl.h" 23 #include "gc/heap.h" 24 #include "globals.h" 25 #include "object.h" 26 #include "object-inl.h" 27 #include "object_array-inl.h" 28 #include "runtime.h" 29 #include "string.h" 30 31 namespace art { 32 namespace mirror { 33 34 void DexCache::Init(const DexFile* dex_file, String* location, ObjectArray<String>* strings, 35 ObjectArray<Class>* resolved_types, PointerArray* resolved_methods, 36 PointerArray* resolved_fields, size_t pointer_size) { 37 CHECK(dex_file != nullptr); 38 CHECK(location != nullptr); 39 CHECK(strings != nullptr); 40 CHECK(resolved_types != nullptr); 41 CHECK(resolved_methods != nullptr); 42 CHECK(resolved_fields != nullptr); 43 44 SetDexFile(dex_file); 45 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location); 46 SetFieldObject<false>(StringsOffset(), strings); 47 SetFieldObject<false>(ResolvedFieldsOffset(), resolved_fields); 48 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types); 49 SetFieldObject<false>(ResolvedMethodsOffset(), resolved_methods); 50 51 Runtime* const runtime = Runtime::Current(); 52 if (runtime->HasResolutionMethod()) { 53 // Initialize the resolve methods array to contain trampolines for resolution. 54 Fixup(runtime->GetResolutionMethod(), pointer_size); 55 } 56 } 57 58 void DexCache::Fixup(ArtMethod* trampoline, size_t pointer_size) { 59 // Fixup the resolve methods array to contain trampoline for resolution. 60 CHECK(trampoline != nullptr); 61 CHECK(trampoline->IsRuntimeMethod()); 62 auto* resolved_methods = GetResolvedMethods(); 63 for (size_t i = 0, length = resolved_methods->GetLength(); i < length; i++) { 64 if (resolved_methods->GetElementPtrSize<ArtMethod*>(i, pointer_size) == nullptr) { 65 resolved_methods->SetElementPtrSize(i, trampoline, pointer_size); 66 } 67 } 68 } 69 70 } // namespace mirror 71 } // namespace art 72