1 /*
2  * Copyright (C) 2016 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 package dalvik.system;
18 
19 /**
20  * Holder class for extraneous Class data.
21  *
22  * This class holds data for Class objects that is either rarely useful, only necessary for
23  * debugging purposes or both. This allows us to extend the Class class without impacting memory
24  * use.
25  *
26  * @hide For internal runtime use only.
27  */
28 public final class ClassExt {
29     /**
30      * An array of all obsolete DexCache objects that are needed for obsolete methods.
31      *
32      * These entries are associated with the obsolete ArtMethod pointers at the same indexes in the
33      * obsoleteMethods array.
34      *
35      * This field has native components and is a logical part of the 'Class' type.
36      */
37     private Object[] obsoleteDexCaches;
38 
39     /**
40      * An array of all native obsolete ArtMethod pointers.
41      *
42      * These are associated with their DexCaches at the same index in the obsoleteDexCaches array.
43      *
44      * This field is actually either an int[] or a long[] depending on size of a pointer.
45      *
46      * This field contains native pointers and is a logical part of the 'Class' type.
47      */
48     private Object obsoleteMethods;
49 
50     /**
51      * If set, the bytes, native pointer (as a java.lang.Long), or DexCache of the original dex-file
52      * associated with the related class.
53      *
54      * In this instance 'original' means either (1) the dex-file loaded for this class when it was
55      * first loaded after all non-retransformation capable transformations had been performed but
56      * before any retransformation capable ones had been done or (2) the most recent dex-file bytes
57      * given for a class redefinition.
58      *
59      * Needed in order to implement retransformation of classes.
60      *
61      * This field is a logical part of the 'Class' type.
62      */
63     private Object originalDexFile;
64 
65     /**
66      * If class verify fails, we must return same error on subsequent tries. We may store either
67      * the class of the error, or an actual instance of Throwable here.
68      *
69      * This field is a logical part of the 'Class' type.
70      */
71     private Object verifyError;
72 
73     /**
74      * If set, native pointer to the initial, pre-redefine, dex file associated with the related
75      * class. This is different from the {@code originalDexFile} which is the pre-retransform dex
76      * file, i.e. could contain the bytes of the dex file provided during redefine.
77      *
78      * It is enough to store the native pointer because the pre-redefine dex file is either part
79      * of boot classpath or it is being kept alive by its class loader. Class loaders always keep
80      * dex files alive even if all their classes have been redefined.
81      *
82      * Needed in order to preserve access to dex-level hiddenapi flags after JVMTI redefine.
83      *
84      * This field is a logical part of the 'Class' type.
85      */
86     private long preRedefineDexFilePtr;
87 
88     /**
89      * ClassDef index of the related class in the pre-redefine dex file. Set together with
90      * {@code preRedefineDexFilePtr}.
91      *
92      * Needed in order to preserve access to dex-level hiddenapi flags after JVMTI redefine.
93      *
94      * This field is a logical part of the 'Class' type.
95      */
96     private int preRedefineClassDefIndex;
97 
98     /**
99     * Private constructor.
100     *
101     * Only created by the runtime.
102     */
ClassExt()103     private ClassExt() {}
104 }
105