blob: fa0900c0ecaff91e9526e488c35e407f17a2862f [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 Chartier66f19252012-09-18 08:57:04 -070034void DexCache::Init(const DexFile* dex_file,
35 String* location,
Brian Carlstroma663ea52011-08-19 23:33:41 -070036 ObjectArray<String>* strings,
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070037 ObjectArray<Class>* resolved_types,
Brian Carlstromea46f952013-07-30 01:26:50 -070038 ObjectArray<ArtMethod>* resolved_methods,
Ian Rogers5ddb4102014-01-07 08:58:46 -080039 ObjectArray<ArtField>* resolved_fields) {
40 CHECK(dex_file != nullptr);
41 CHECK(location != nullptr);
42 CHECK(strings != nullptr);
43 CHECK(resolved_types != nullptr);
44 CHECK(resolved_methods != nullptr);
45 CHECK(resolved_fields != nullptr);
Mathieu Chartier66f19252012-09-18 08:57:04 -070046
47 SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file, false);
48 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location, false);
49 SetFieldObject(StringsOffset(), strings, false);
50 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types, false);
51 SetFieldObject(ResolvedMethodsOffset(), resolved_methods, false);
52 SetFieldObject(ResolvedFieldsOffset(), resolved_fields, false);
Brian Carlstromaded5f72011-10-07 17:15:04 -070053
54 Runtime* runtime = Runtime::Current();
Ian Rogers19846512012-02-24 11:42:47 -080055 if (runtime->HasResolutionMethod()) {
56 // Initialize the resolve methods array to contain trampolines for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -070057 ArtMethod* trampoline = runtime->GetResolutionMethod();
Ian Rogers19846512012-02-24 11:42:47 -080058 size_t length = resolved_methods->GetLength();
59 for (size_t i = 0; i < length; i++) {
60 resolved_methods->SetWithoutChecks(i, trampoline);
61 }
62 }
63}
64
Brian Carlstromea46f952013-07-30 01:26:50 -070065void DexCache::Fixup(ArtMethod* trampoline) {
Ian Rogers19846512012-02-24 11:42:47 -080066 // Fixup the resolve methods array to contain trampoline for resolution.
Ian Rogers5ddb4102014-01-07 08:58:46 -080067 CHECK(trampoline != nullptr);
Brian Carlstromea46f952013-07-30 01:26:50 -070068 ObjectArray<ArtMethod>* resolved_methods = GetResolvedMethods();
Ian Rogers19846512012-02-24 11:42:47 -080069 size_t length = resolved_methods->GetLength();
70 for (size_t i = 0; i < length; i++) {
Ian Rogers5ddb4102014-01-07 08:58:46 -080071 if (resolved_methods->GetWithoutChecks(i) == nullptr) {
Ian Rogers19846512012-02-24 11:42:47 -080072 resolved_methods->SetWithoutChecks(i, trampoline);
Brian Carlstromaded5f72011-10-07 17:15:04 -070073 }
74 }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070075}
76
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070078} // namespace art