blob: a32d51fbefb37e34b467b460eaa948058ecf64da [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,
Mathieu Chartier28357fa2016-10-18 16:27:40 -070035 ObjPtr<String> location,
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070036 StringDexCacheType* strings,
Vladimir Marko05792b92015-08-03 11:56:49 +010037 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,
Narayan Kamath25352fc2016-08-03 12:46:58 +010044 MethodTypeDexCacheType* resolved_method_types,
45 uint32_t num_resolved_method_types,
Andreas Gampe542451c2016-07-26 09:02:02 -070046 PointerSize pointer_size) {
Ian Rogers5ddb4102014-01-07 08:58:46 -080047 CHECK(dex_file != nullptr);
48 CHECK(location != nullptr);
Vladimir Marko05792b92015-08-03 11:56:49 +010049 CHECK_EQ(num_strings != 0u, strings != nullptr);
50 CHECK_EQ(num_resolved_types != 0u, resolved_types != nullptr);
51 CHECK_EQ(num_resolved_methods != 0u, resolved_methods != nullptr);
52 CHECK_EQ(num_resolved_fields != 0u, resolved_fields != nullptr);
Narayan Kamath25352fc2016-08-03 12:46:58 +010053 CHECK_EQ(num_resolved_method_types != 0u, resolved_method_types != nullptr);
Mathieu Chartier66f19252012-09-18 08:57:04 -070054
Mathieu Chartierc7853442015-03-27 14:35:38 -070055 SetDexFile(dex_file);
Mathieu Chartier76172162016-01-26 14:54:06 -080056 SetLocation(location);
Mathieu Chartierfbc31082016-01-24 11:59:56 -080057 SetStrings(strings);
58 SetResolvedTypes(resolved_types);
59 SetResolvedMethods(resolved_methods);
60 SetResolvedFields(resolved_fields);
Narayan Kamath25352fc2016-08-03 12:46:58 +010061 SetResolvedMethodTypes(resolved_method_types);
Vladimir Marko05792b92015-08-03 11:56:49 +010062 SetField32<false>(NumStringsOffset(), num_strings);
63 SetField32<false>(NumResolvedTypesOffset(), num_resolved_types);
64 SetField32<false>(NumResolvedMethodsOffset(), num_resolved_methods);
65 SetField32<false>(NumResolvedFieldsOffset(), num_resolved_fields);
Narayan Kamath25352fc2016-08-03 12:46:58 +010066 SetField32<false>(NumResolvedMethodTypesOffset(), num_resolved_method_types);
Brian Carlstromaded5f72011-10-07 17:15:04 -070067
Mathieu Chartiere401d142015-04-22 13:56:20 -070068 Runtime* const runtime = Runtime::Current();
Ian Rogers19846512012-02-24 11:42:47 -080069 if (runtime->HasResolutionMethod()) {
70 // Initialize the resolve methods array to contain trampolines for resolution.
Mathieu Chartiere401d142015-04-22 13:56:20 -070071 Fixup(runtime->GetResolutionMethod(), pointer_size);
Ian Rogers19846512012-02-24 11:42:47 -080072 }
73}
74
Andreas Gampe542451c2016-07-26 09:02:02 -070075void DexCache::Fixup(ArtMethod* trampoline, PointerSize pointer_size) {
Ian Rogers19846512012-02-24 11:42:47 -080076 // Fixup the resolve methods array to contain trampoline for resolution.
Ian Rogers5ddb4102014-01-07 08:58:46 -080077 CHECK(trampoline != nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 CHECK(trampoline->IsRuntimeMethod());
79 auto* resolved_methods = GetResolvedMethods();
Vladimir Marko05792b92015-08-03 11:56:49 +010080 for (size_t i = 0, length = NumResolvedMethods(); i < length; i++) {
81 if (GetElementPtrSize<ArtMethod*>(resolved_methods, i, pointer_size) == nullptr) {
82 SetElementPtrSize(resolved_methods, i, trampoline, pointer_size);
Brian Carlstromaded5f72011-10-07 17:15:04 -070083 }
84 }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070085}
86
Mathieu Chartier28357fa2016-10-18 16:27:40 -070087void DexCache::SetLocation(ObjPtr<mirror::String> location) {
Mathieu Chartier76172162016-01-26 14:54:06 -080088 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location);
89}
90
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070092} // namespace art