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
Init(const DexFile * dex_file,String * location,ObjectArray<String> * strings,ObjectArray<Class> * resolved_types,ObjectArray<ArtMethod> * resolved_methods,ObjectArray<ArtField> * resolved_fields)34 void DexCache::Init(const DexFile* dex_file,
35 String* location,
36 ObjectArray<String>* strings,
37 ObjectArray<Class>* resolved_types,
38 ObjectArray<ArtMethod>* resolved_methods,
39 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);
46
47 SetFieldPtr<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file);
48 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location);
49 SetFieldObject<false>(StringsOffset(), strings);
50 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types);
51 SetFieldObject<false>(ResolvedMethodsOffset(), resolved_methods);
52 SetFieldObject<false>(ResolvedFieldsOffset(), resolved_fields);
53
54 Runtime* runtime = Runtime::Current();
55 if (runtime->HasResolutionMethod()) {
56 // Initialize the resolve methods array to contain trampolines for resolution.
57 ArtMethod* trampoline = runtime->GetResolutionMethod();
58 size_t length = resolved_methods->GetLength();
59 for (size_t i = 0; i < length; i++) {
60 resolved_methods->SetWithoutChecks<false>(i, trampoline);
61 }
62 }
63 }
64
Fixup(ArtMethod * trampoline)65 void DexCache::Fixup(ArtMethod* trampoline) {
66 // Fixup the resolve methods array to contain trampoline for resolution.
67 CHECK(trampoline != nullptr);
68 ObjectArray<ArtMethod>* resolved_methods = GetResolvedMethods();
69 size_t length = resolved_methods->GetLength();
70 for (size_t i = 0; i < length; i++) {
71 if (resolved_methods->GetWithoutChecks(i) == nullptr) {
72 resolved_methods->SetWithoutChecks<false>(i, trampoline);
73 }
74 }
75 }
76
77 } // namespace mirror
78 } // namespace art
79