blob: 207140bbb1e7e954d857e612fa4393b7210a860e [file] [log] [blame]
The Android Open Source Project2ad60cf2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 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 * DEX optimization declarations.
18 */
19#ifndef _DALVIK_DEXOPTIMIZE
20#define _DALVIK_DEXOPTIMIZE
21
22/*
23 * Global DEX optimizer control. Determines the circumstances in which we
24 * try to rewrite instructions in the DEX file.
25 */
26typedef enum DexOptimizerMode {
27 OPTIMIZE_MODE_UNKNOWN = 0,
28 OPTIMIZE_MODE_NONE, /* never optimize */
29 OPTIMIZE_MODE_VERIFIED, /* only optimize verified classes (default) */
30 OPTIMIZE_MODE_ALL /* optimize all classes */
31} DexOptimizerMode;
32
33/*
34 * Given the full path to a DEX or Jar file, and (if appropriate) the name
35 * within the Jar, open the optimized version from the cache.
36 *
37 * If "*pNewFile" is set, a new file has been created with only a stub
38 * "opt" header, and the caller is expected to fill in the blanks.
39 *
40 * Returns the file descriptor, locked and seeked past the "opt" header.
41 */
42int dvmOpenCachedDexFile(const char* fileName, const char* subFileName,
43 u4 modWhen, u4 crc, bool isBootstrap, char** pCachedName, bool* pNewFile,
44 bool createIfMissing);
45
46/*
47 * Unlock the specified file descriptor. Use in conjunction with
48 * dvmOpenCachedDexFile().
49 *
50 * Returns true on success.
51 */
52bool dvmUnlockCachedDexFile(int fd);
53
54/*
55 * Verify the contents of the "opt" header, and check the DEX file's
56 * dependencies on its source zip (if available).
57 */
58bool dvmCheckOptHeaderAndDependencies(int fd, bool sourceAvail, u4 modWhen,
59 u4 crc, bool expectVerify, bool expectOpt);
60
61/*
62 * Optimize a DEX file. The file must start with the "opt" header, followed
63 * by the plain DEX data. It must be mmap()able.
64 *
65 * "fileName" is only used for debug output.
66 */
67bool dvmOptimizeDexFile(int fd, off_t dexOffset, long dexLen,
68 const char* fileName, u4 modWhen, u4 crc, bool isBootstrap);
69
70/*
71 * Continue the optimization process on the other side of a fork/exec.
72 */
73bool dvmContinueOptimization(int fd, off_t dexOffset, long dexLength,
74 const char* fileName, u4 modWhen, u4 crc, bool isBootstrap);
75
76/*
77 * Abbreviated resolution functions, for use by optimization and verification
78 * code.
79 */
80ClassObject* dvmOptResolveClass(ClassObject* referrer, u4 classIdx);
81Method* dvmOptResolveMethod(ClassObject* referrer, u4 methodIdx,
82 MethodType methodType);
83Method* dvmOptResolveInterfaceMethod(ClassObject* referrer, u4 methodIdx);
84InstField* dvmOptResolveInstField(ClassObject* referrer, u4 ifieldIdx);
85StaticField* dvmOptResolveStaticField(ClassObject* referrer, u4 sfieldIdx);
86
87#endif /*_DALVIK_DEXOPTIMIZE*/