Home | History | Annotate | Download | only in lang
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 /*
     18  * Copyright (C) 2012 The Android Open Source Project
     19  *
     20  * Licensed under the Apache License, Version 2.0 (the "License");
     21  * you may not use this file except in compliance with the License.
     22  * You may obtain a copy of the License at
     23  *
     24  *      http://www.apache.org/licenses/LICENSE-2.0
     25  *
     26  * Unless required by applicable law or agreed to in writing, software
     27  * distributed under the License is distributed on an "AS IS" BASIS,
     28  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     29  * See the License for the specific language governing permissions and
     30  * limitations under the License.
     31  */
     32 
     33 package java.lang;
     34 
     35 import com.android.dex.Dex;
     36 import java.lang.reflect.ArtField;
     37 import java.lang.reflect.ArtMethod;
     38 
     39 /**
     40  * A dex cache holds resolved copies of strings, fields, methods, and classes from the dexfile.
     41  */
     42 final class DexCache {
     43     /** Lazily initialized dex file wrapper. Volatile to avoid double-check locking issues. */
     44     private volatile Dex dex;
     45 
     46     /** The location of the associated dex file. */
     47     String location;
     48 
     49     /**
     50      * References to fields as they become resolved following interpreter semantics. May refer to
     51      * fields defined in other dex files.
     52      */
     53     ArtField[] resolvedFields;
     54 
     55     /**
     56      * References to methods as they become resolved following interpreter semantics. May refer to
     57      * methods defined in other dex files.
     58      */
     59     ArtMethod[] resolvedMethods;
     60 
     61     /**
     62      * References to types as they become resolved following interpreter semantics. May refer to
     63      * types defined in other dex files.
     64      */
     65     Class[] resolvedTypes;
     66 
     67     /**
     68      * References to strings as they become resolved following interpreter semantics. All strings
     69      * are interned.
     70      */
     71     String[] strings;
     72 
     73     /** Holds C pointer to dexFile. */
     74     private long dexFile;
     75 
     76     // Only created by the VM.
     77     private DexCache() {}
     78 
     79     Dex getDex() {
     80         Dex result = dex;
     81         if (result == null) {
     82             synchronized (this) {
     83                 result = dex;
     84                 if (result == null) {
     85                     dex = result = getDexNative();
     86                 }
     87             }
     88         }
     89         return result;
     90     }
     91 
     92     private native Dex getDexNative();
     93 }
     94 
     95