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      * If the class is in an erroneous state, we must return the same error on subsequent tries.
31      *
32      * This field is a logical part of the 'Class' type.
33      */
34     private Throwable erroneousStateError;
35 
36     /**
37      * A Pointer-sized-array of instance jfieldIDs in the same order as the ifields_ array.
38      * The jfieldID is associated with the ArtField at the corresonding index in the ifields_ array.
39      */
40     private Object instanceJfieldIDs;
41 
42     /**
43      * A Pointer-sized-array of jmethodIDS in the same order as the methods_
44      * array. The jmethodID is associated with the ArtField at the corresonding
45      * index in the methods_ array.
46      */
47     private Object jmethodIDs;
48 
49     /**
50      * If the class has undergone structural redefinition, the now obsolete class object.
51      *
52      * Needed to ensure that the class isn't unloaded before its jit code is. Normally this is
53      * handled by the classloader but since the class is now obsolete it's no longer held live
54      * there and instead we must do so manually. This class should not be used for anything.
55      */
56     private Class<?> obsoleteClass;
57 
58     /**
59      * An array of all obsolete DexCache objects that are needed for obsolete methods.
60      *
61      * These entries are associated with the obsolete ArtMethod pointers at the same indexes in the
62      * obsoleteMethods array.
63      *
64      * This field has native components and is a logical part of the 'Class' type.
65      */
66     private Object[] obsoleteDexCaches;
67 
68     /**
69      * An array of all native obsolete ArtMethod pointers.
70      *
71      * These are associated with their DexCaches at the same index in the obsoleteDexCaches array.
72      *
73      * This field is actually either an int[] or a long[] depending on size of a pointer.
74      *
75      * This field contains native pointers and is a logical part of the 'Class' type.
76      */
77     private Object obsoleteMethods;
78 
79     /**
80      * If set, the bytes, native pointer (as a java.lang.Long), or DexCache of the original dex-file
81      * associated with the related class.
82      *
83      * In this instance 'original' means either (1) the dex-file loaded for this class when it was
84      * first loaded after all non-retransformation capable transformations had been performed but
85      * before any retransformation capable ones had been done or (2) the most recent dex-file bytes
86      * given for a class redefinition.
87      *
88      * Needed in order to implement retransformation of classes.
89      *
90      * This field is a logical part of the 'Class' type.
91      */
92     private Object originalDexFile;
93 
94     /**
95      * A Pointer-sized-array of static jfieldIDs in the same order as the sfields_ array.
96      * The jfieldID is associated with the ArtField at the corresonding index in the sfields_ array.
97      */
98     private Object staticJfieldIDs;
99 
100     /**
101      * If set, native pointer to the initial, pre-redefine, dex file associated with the related
102      * class. This is different from the {@code originalDexFile} which is the pre-retransform dex
103      * file, i.e. could contain the bytes of the dex file provided during redefine.
104      *
105      * It is enough to store the native pointer because the pre-redefine dex file is either part
106      * of boot classpath or it is being kept alive by its class loader. Class loaders always keep
107      * dex files alive even if all their classes have been redefined.
108      *
109      * Needed in order to preserve access to dex-level hiddenapi flags after JVMTI redefine.
110      *
111      * This field is a logical part of the 'Class' type.
112      */
113     private long preRedefineDexFilePtr;
114 
115     /**
116      * ClassDef index of the related class in the pre-redefine dex file. Set together with
117      * {@code preRedefineDexFilePtr}.
118      *
119      * Needed in order to preserve access to dex-level hiddenapi flags after JVMTI redefine.
120      *
121      * This field is a logical part of the 'Class' type.
122      */
123     private int preRedefineClassDefIndex;
124 
125     /**
126      * Backing store of user-defined values pertaining to a class.
127      * Maintained by the ClassValue class.
128      *
129      * ClassValue.ClassValueMap is package-private, hence plain Object.
130      */
131     public Object classValueMap;
132 
133     /**
134     * Private constructor.
135     *
136     * Only created by the runtime.
137     */
ClassExt()138     private ClassExt() {}
139 }
140