Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 16 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 17 | #include "dex_cache.h" |
| 18 | |
| 19 | #include "abstract_method-inl.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 20 | #include "base/logging.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 21 | #include "class_linker.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame^] | 22 | #include "gc/accounting/card_table-inl.h" |
| 23 | #include "gc/heap.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 24 | #include "globals.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 25 | #include "object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "object-inl.h" |
| 27 | #include "object_array-inl.h" |
| 28 | #include "runtime.h" |
| 29 | #include "string.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 30 | |
| 31 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | namespace mirror { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 33 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 34 | void DexCache::Init(const DexFile* dex_file, |
| 35 | String* location, |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 36 | ObjectArray<String>* strings, |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 37 | ObjectArray<Class>* resolved_types, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 38 | ObjectArray<AbstractMethod>* resolved_methods, |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 39 | ObjectArray<Field>* resolved_fields, |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 40 | ObjectArray<StaticStorageBase>* initialized_static_storage) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 41 | CHECK(dex_file != NULL); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 42 | CHECK(location != NULL); |
| 43 | CHECK(strings != NULL); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 44 | CHECK(resolved_types != NULL); |
| 45 | CHECK(resolved_methods != NULL); |
| 46 | CHECK(resolved_fields != NULL); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 47 | CHECK(initialized_static_storage != NULL); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 48 | |
| 49 | SetFieldPtr(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file, false); |
| 50 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location, false); |
| 51 | SetFieldObject(StringsOffset(), strings, false); |
| 52 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types, false); |
| 53 | SetFieldObject(ResolvedMethodsOffset(), resolved_methods, false); |
| 54 | SetFieldObject(ResolvedFieldsOffset(), resolved_fields, false); |
| 55 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(DexCache, initialized_static_storage_), |
| 56 | initialized_static_storage, false); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 57 | |
| 58 | Runtime* runtime = Runtime::Current(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 59 | if (runtime->HasResolutionMethod()) { |
| 60 | // Initialize the resolve methods array to contain trampolines for resolution. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 61 | AbstractMethod* trampoline = runtime->GetResolutionMethod(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 62 | size_t length = resolved_methods->GetLength(); |
| 63 | for (size_t i = 0; i < length; i++) { |
| 64 | resolved_methods->SetWithoutChecks(i, trampoline); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 69 | void DexCache::Fixup(AbstractMethod* trampoline) { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 70 | // Fixup the resolve methods array to contain trampoline for resolution. |
| 71 | CHECK(trampoline != NULL); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 72 | ObjectArray<AbstractMethod>* resolved_methods = GetResolvedMethods(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 73 | size_t length = resolved_methods->GetLength(); |
| 74 | for (size_t i = 0; i < length; i++) { |
| 75 | if (resolved_methods->GetWithoutChecks(i) == NULL) { |
| 76 | resolved_methods->SetWithoutChecks(i, trampoline); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 81 | } // namespace mirror |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 82 | } // namespace art |