blob: 630faee35645fff93da933935146aacd79e22038 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070016
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080017#include "dex_cache.h"
18
Brian Carlstromea46f952013-07-30 01:26:50 -070019#include "art_method-inl.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080020#include "base/logging.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070021#include "class_linker.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070022#include "gc/accounting/card_table-inl.h"
23#include "gc/heap.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070024#include "globals.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070025#include "object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "object-inl.h"
27#include "object_array-inl.h"
28#include "runtime.h"
29#include "string.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070030
31namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032namespace mirror {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070033
Mathieu Chartiere401d142015-04-22 13:56:20 -070034void 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) {
Ian Rogers5ddb4102014-01-07 08:58:46 -080037 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);
Mathieu Chartier66f19252012-09-18 08:57:04 -070043
Mathieu Chartierc7853442015-03-27 14:35:38 -070044 SetDexFile(dex_file);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070045 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location);
46 SetFieldObject<false>(StringsOffset(), strings);
Mathieu Chartierc7853442015-03-27 14:35:38 -070047 SetFieldObject<false>(ResolvedFieldsOffset(), resolved_fields);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070048 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types);
49 SetFieldObject<false>(ResolvedMethodsOffset(), resolved_methods);
Brian Carlstromaded5f72011-10-07 17:15:04 -070050
Mathieu Chartiere401d142015-04-22 13:56:20 -070051 Runtime* const runtime = Runtime::Current();
Ian Rogers19846512012-02-24 11:42:47 -080052 if (runtime->HasResolutionMethod()) {
53 // Initialize the resolve methods array to contain trampolines for resolution.
Mathieu Chartiere401d142015-04-22 13:56:20 -070054 Fixup(runtime->GetResolutionMethod(), pointer_size);
Ian Rogers19846512012-02-24 11:42:47 -080055 }
56}
57
Mathieu Chartiere401d142015-04-22 13:56:20 -070058void DexCache::Fixup(ArtMethod* trampoline, size_t pointer_size) {
Ian Rogers19846512012-02-24 11:42:47 -080059 // Fixup the resolve methods array to contain trampoline for resolution.
Ian Rogers5ddb4102014-01-07 08:58:46 -080060 CHECK(trampoline != nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -070061 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);
Brian Carlstromaded5f72011-10-07 17:15:04 -070066 }
67 }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070068}
69
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070071} // namespace art