blob: adb889bb1770be92c7c5080845e36dbe7b83d3b6 [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
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070017#include "class_linker.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070018#include "dex_cache.h"
19#include "heap.h"
20#include "globals.h"
21#include "logging.h"
22#include "object.h"
23
24namespace art {
25
Mathieu Chartier66f19252012-09-18 08:57:04 -070026void DexCache::Init(const DexFile* dex_file,
27 String* location,
Brian Carlstroma663ea52011-08-19 23:33:41 -070028 ObjectArray<String>* strings,
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070029 ObjectArray<Class>* resolved_types,
Mathieu Chartier66f19252012-09-18 08:57:04 -070030 ObjectArray<AbstractMethod>* resolved_methods,
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070031 ObjectArray<Field>* resolved_fields,
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070032 ObjectArray<StaticStorageBase>* initialized_static_storage) {
Mathieu Chartier66f19252012-09-18 08:57:04 -070033 CHECK(dex_file != NULL);
Brian Carlstrom83db7722011-08-26 17:32:56 -070034 CHECK(location != NULL);
35 CHECK(strings != NULL);
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070036 CHECK(resolved_types != NULL);
37 CHECK(resolved_methods != NULL);
38 CHECK(resolved_fields != NULL);
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070039 CHECK(initialized_static_storage != NULL);
Mathieu Chartier66f19252012-09-18 08:57:04 -070040
41 SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file, false);
42 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location, false);
43 SetFieldObject(StringsOffset(), strings, false);
44 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types, false);
45 SetFieldObject(ResolvedMethodsOffset(), resolved_methods, false);
46 SetFieldObject(ResolvedFieldsOffset(), resolved_fields, false);
47 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, initialized_static_storage_),
48 initialized_static_storage, false);
Brian Carlstromaded5f72011-10-07 17:15:04 -070049
50 Runtime* runtime = Runtime::Current();
Ian Rogers19846512012-02-24 11:42:47 -080051 if (runtime->HasResolutionMethod()) {
52 // Initialize the resolve methods array to contain trampolines for resolution.
Mathieu Chartier66f19252012-09-18 08:57:04 -070053 AbstractMethod* trampoline = runtime->GetResolutionMethod();
Ian Rogers19846512012-02-24 11:42:47 -080054 size_t length = resolved_methods->GetLength();
55 for (size_t i = 0; i < length; i++) {
56 resolved_methods->SetWithoutChecks(i, trampoline);
57 }
58 }
59}
60
Mathieu Chartier66f19252012-09-18 08:57:04 -070061void DexCache::Fixup(AbstractMethod* trampoline) {
Ian Rogers19846512012-02-24 11:42:47 -080062 // Fixup the resolve methods array to contain trampoline for resolution.
63 CHECK(trampoline != NULL);
Mathieu Chartier66f19252012-09-18 08:57:04 -070064 ObjectArray<AbstractMethod>* resolved_methods = GetResolvedMethods();
Ian Rogers19846512012-02-24 11:42:47 -080065 size_t length = resolved_methods->GetLength();
66 for (size_t i = 0; i < length; i++) {
67 if (resolved_methods->GetWithoutChecks(i) == NULL) {
68 resolved_methods->SetWithoutChecks(i, trampoline);
Brian Carlstromaded5f72011-10-07 17:15:04 -070069 }
70 }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070071}
72
73} // namespace art