Home | History | Annotate | Download | only in mirror
      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 
     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                     ObjectArray<StaticStorageBase>* initialized_static_storage) {
     41   CHECK(dex_file != NULL);
     42   CHECK(location != NULL);
     43   CHECK(strings != NULL);
     44   CHECK(resolved_types != NULL);
     45   CHECK(resolved_methods != NULL);
     46   CHECK(resolved_fields != NULL);
     47   CHECK(initialized_static_storage != NULL);
     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);
     57 
     58   Runtime* runtime = Runtime::Current();
     59   if (runtime->HasResolutionMethod()) {
     60     // Initialize the resolve methods array to contain trampolines for resolution.
     61     ArtMethod* trampoline = runtime->GetResolutionMethod();
     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 
     69 void DexCache::Fixup(ArtMethod* trampoline) {
     70   // Fixup the resolve methods array to contain trampoline for resolution.
     71   CHECK(trampoline != NULL);
     72   ObjectArray<ArtMethod>* resolved_methods = GetResolvedMethods();
     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);
     77     }
     78   }
     79 }
     80 
     81 }  // namespace mirror
     82 }  // namespace art
     83