2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * The VM wraps some additional data structures around the DexFile. These
21 #ifndef DALVIK_DVMDEX_H_
22 #define DALVIK_DVMDEX_H_
24 #include "libdex/DexFile.h"
35 * Some additional VM data structures that are associated with the DEX file.
38 /* pointer to the DexFile we're associated with */
41 /* clone of pDexFile->pHeader (it's used frequently enough) */
42 const DexHeader
* pHeader
;
44 /* interned strings; parallel to "stringIds" */
45 struct StringObject
** pResStrings
;
47 /* resolved classes; parallel to "typeIds" */
48 struct ClassObject
** pResClasses
;
50 /* resolved methods; parallel to "methodIds" */
51 struct Method
** pResMethods
;
53 /* resolved instance fields; parallel to "fieldIds" */
54 /* (this holds both InstField and StaticField) */
55 struct Field
** pResFields
;
57 /* interface method lookup cache */
58 struct AtomicCache
* pInterfaceCache
;
60 /* shared memory region with file contents */
61 bool isMappedReadOnly
;
64 /* lock ensuring mutual exclusion during updates */
65 pthread_mutex_t modLock
;
70 * Given a file descriptor for an open "optimized" DEX file, map it into
71 * memory and parse the contents.
73 * On success, returns 0 and sets "*ppDvmDex" to a newly-allocated DvmDex.
74 * On failure, returns a meaningful error code [currently just -1].
76 int dvmDexFileOpenFromFd(int fd
, DvmDex
** ppDvmDex
);
79 * Open a partial DEX file. Only useful as part of the optimization process.
81 int dvmDexFileOpenPartial(const void* addr
, int len
, DvmDex
** ppDvmDex
);
84 * Free a DvmDex structure, along with any associated structures.
86 void dvmDexFileFree(DvmDex
* pDvmDex
);
90 * Change the 1- or 2-byte value at the specified address to a new value. If
91 * the location already has the new value, do nothing.
93 * This does not make any synchronization guarantees. The caller must
94 * ensure exclusivity vs. other callers.
96 * For the 2-byte call, the pointer should have 16-bit alignment.
98 * Returns "true" on success.
100 bool dvmDexChangeDex1(DvmDex
* pDvmDex
, u1
* addr
, u1 newVal
);
101 bool dvmDexChangeDex2(DvmDex
* pDvmDex
, u2
* addr
, u2 newVal
);
105 * Return the requested item if it has been resolved, or NULL if it hasn't.
107 INLINE
struct StringObject
* dvmDexGetResolvedString(const DvmDex
* pDvmDex
,
110 assert(stringIdx
< pDvmDex
->pHeader
->stringIdsSize
);
111 return pDvmDex
->pResStrings
[stringIdx
];
113 INLINE
struct ClassObject
* dvmDexGetResolvedClass(const DvmDex
* pDvmDex
,
116 assert(classIdx
< pDvmDex
->pHeader
->typeIdsSize
);
117 return pDvmDex
->pResClasses
[classIdx
];
119 INLINE
struct Method
* dvmDexGetResolvedMethod(const DvmDex
* pDvmDex
,
122 assert(methodIdx
< pDvmDex
->pHeader
->methodIdsSize
);
123 return pDvmDex
->pResMethods
[methodIdx
];
125 INLINE
struct Field
* dvmDexGetResolvedField(const DvmDex
* pDvmDex
,
128 assert(fieldIdx
< pDvmDex
->pHeader
->fieldIdsSize
);
129 return pDvmDex
->pResFields
[fieldIdx
];
133 * Update the resolved item table. Resolution always produces the same
134 * result, so we're not worried about atomicity here.
136 INLINE
void dvmDexSetResolvedString(DvmDex
* pDvmDex
, u4 stringIdx
,
137 struct StringObject
* str
)
139 assert(stringIdx
< pDvmDex
->pHeader
->stringIdsSize
);
140 pDvmDex
->pResStrings
[stringIdx
] = str
;
142 INLINE
void dvmDexSetResolvedClass(DvmDex
* pDvmDex
, u4 classIdx
,
143 struct ClassObject
* clazz
)
145 assert(classIdx
< pDvmDex
->pHeader
->typeIdsSize
);
146 pDvmDex
->pResClasses
[classIdx
] = clazz
;
148 INLINE
void dvmDexSetResolvedMethod(DvmDex
* pDvmDex
, u4 methodIdx
,
149 struct Method
* method
)
151 assert(methodIdx
< pDvmDex
->pHeader
->methodIdsSize
);
152 pDvmDex
->pResMethods
[methodIdx
] = method
;
154 INLINE
void dvmDexSetResolvedField(DvmDex
* pDvmDex
, u4 fieldIdx
,
157 assert(fieldIdx
< pDvmDex
->pHeader
->fieldIdsSize
);
158 pDvmDex
->pResFields
[fieldIdx
] = field
;
161 #endif // DALVIK_DVMDEX_H_