blob: 57066d8376011c87d2ff033a249f59e5bdb46220 [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
Vladimir Marko05792b92015-08-03 11:56:49 +010017#include "dex_cache-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080018
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
Vladimir Marko05792b92015-08-03 11:56:49 +010034void DexCache::Init(const DexFile* dex_file,
35 String* location,
36 GcRoot<String>* strings,
37 uint32_t num_strings,
38 GcRoot<Class>* resolved_types,
39 uint32_t num_resolved_types,
40 ArtMethod** resolved_methods,
41 uint32_t num_resolved_methods,
42 ArtField** resolved_fields,
43 uint32_t num_resolved_fields,
Andreas Gampe542451c2016-07-26 09:02:02 -070044 PointerSize pointer_size) {
Ian Rogers5ddb4102014-01-07 08:58:46 -080045 CHECK(dex_file != nullptr);
46 CHECK(location != nullptr);
Vladimir Marko05792b92015-08-03 11:56:49 +010047 CHECK_EQ(num_strings != 0u, strings != nullptr);
48 CHECK_EQ(num_resolved_types != 0u, resolved_types != nullptr);
49 CHECK_EQ(num_resolved_methods != 0u, resolved_methods != nullptr);
50 CHECK_EQ(num_resolved_fields != 0u, resolved_fields != nullptr);
Mathieu Chartier66f19252012-09-18 08:57:04 -070051
Mathieu Chartierc7853442015-03-27 14:35:38 -070052 SetDexFile(dex_file);
Mathieu Chartier76172162016-01-26 14:54:06 -080053 SetLocation(location);
Mathieu Chartierfbc31082016-01-24 11:59:56 -080054 SetStrings(strings);
55 SetResolvedTypes(resolved_types);
56 SetResolvedMethods(resolved_methods);
57 SetResolvedFields(resolved_fields);
Vladimir Marko05792b92015-08-03 11:56:49 +010058 SetField32<false>(NumStringsOffset(), num_strings);
59 SetField32<false>(NumResolvedTypesOffset(), num_resolved_types);
60 SetField32<false>(NumResolvedMethodsOffset(), num_resolved_methods);
61 SetField32<false>(NumResolvedFieldsOffset(), num_resolved_fields);
Brian Carlstromaded5f72011-10-07 17:15:04 -070062
Mathieu Chartiere401d142015-04-22 13:56:20 -070063 Runtime* const runtime = Runtime::Current();
Ian Rogers19846512012-02-24 11:42:47 -080064 if (runtime->HasResolutionMethod()) {
65 // Initialize the resolve methods array to contain trampolines for resolution.
Mathieu Chartiere401d142015-04-22 13:56:20 -070066 Fixup(runtime->GetResolutionMethod(), pointer_size);
Ian Rogers19846512012-02-24 11:42:47 -080067 }
68}
69
Andreas Gampe542451c2016-07-26 09:02:02 -070070void DexCache::Fixup(ArtMethod* trampoline, PointerSize pointer_size) {
Ian Rogers19846512012-02-24 11:42:47 -080071 // Fixup the resolve methods array to contain trampoline for resolution.
Ian Rogers5ddb4102014-01-07 08:58:46 -080072 CHECK(trampoline != nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -070073 CHECK(trampoline->IsRuntimeMethod());
74 auto* resolved_methods = GetResolvedMethods();
Vladimir Marko05792b92015-08-03 11:56:49 +010075 for (size_t i = 0, length = NumResolvedMethods(); i < length; i++) {
76 if (GetElementPtrSize<ArtMethod*>(resolved_methods, i, pointer_size) == nullptr) {
77 SetElementPtrSize(resolved_methods, i, trampoline, pointer_size);
Brian Carlstromaded5f72011-10-07 17:15:04 -070078 }
79 }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070080}
81
Mathieu Chartier76172162016-01-26 14:54:06 -080082void DexCache::SetLocation(mirror::String* location) {
83 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location);
84}
85
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070087} // namespace art