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 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 17 | #include "class_linker.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 18 | #include "dex_cache.h" |
| 19 | #include "heap.h" |
| 20 | #include "globals.h" |
| 21 | #include "logging.h" |
| 22 | #include "object.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 26 | void DexCache::Init(String* location, |
| 27 | ObjectArray<String>* strings, |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 28 | ObjectArray<Class>* resolved_types, |
| 29 | ObjectArray<Method>* resolved_methods, |
| 30 | ObjectArray<Field>* resolved_fields, |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 31 | ObjectArray<StaticStorageBase>* initialized_static_storage) { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 32 | CHECK(location != NULL); |
| 33 | CHECK(strings != NULL); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 34 | CHECK(resolved_types != NULL); |
| 35 | CHECK(resolved_methods != NULL); |
| 36 | CHECK(resolved_fields != NULL); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 37 | CHECK(initialized_static_storage != NULL); |
| 38 | Set(kLocation, location); |
| 39 | Set(kStrings, strings); |
| 40 | Set(kResolvedTypes, resolved_types); |
| 41 | Set(kResolvedMethods, resolved_methods); |
| 42 | Set(kResolvedFields, resolved_fields); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 43 | Set(kInitializedStaticStorage, initialized_static_storage); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 44 | |
| 45 | Runtime* runtime = Runtime::Current(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 46 | if (runtime->HasResolutionMethod()) { |
| 47 | // Initialize the resolve methods array to contain trampolines for resolution. |
| 48 | Method* trampoline = runtime->GetResolutionMethod(); |
| 49 | size_t length = resolved_methods->GetLength(); |
| 50 | for (size_t i = 0; i < length; i++) { |
| 51 | resolved_methods->SetWithoutChecks(i, trampoline); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void DexCache::Fixup(Method* trampoline) { |
| 57 | // Fixup the resolve methods array to contain trampoline for resolution. |
| 58 | CHECK(trampoline != NULL); |
| 59 | ObjectArray<Method>* resolved_methods = down_cast<ObjectArray<Method>*>(Get(kResolvedMethods)); |
| 60 | size_t length = resolved_methods->GetLength(); |
| 61 | for (size_t i = 0; i < length; i++) { |
| 62 | if (resolved_methods->GetWithoutChecks(i) == NULL) { |
| 63 | resolved_methods->SetWithoutChecks(i, trampoline); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | } // namespace art |