| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 16 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 17 | /* |
| Andy McFadden | 2e1ee50 | 2010-03-24 13:25:53 -0700 | [diff] [blame^] | 18 | * DEX preparation declarations. |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 19 | */ |
| Andy McFadden | 2e1ee50 | 2010-03-24 13:25:53 -0700 | [diff] [blame^] | 20 | #ifndef _DALVIK_DEXPREPARE |
| 21 | #define _DALVIK_DEXPREPARE |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Global DEX optimizer control. Determines the circumstances in which we |
| 25 | * try to rewrite instructions in the DEX file. |
| 26 | */ |
| 27 | typedef enum DexOptimizerMode { |
| 28 | OPTIMIZE_MODE_UNKNOWN = 0, |
| 29 | OPTIMIZE_MODE_NONE, /* never optimize */ |
| 30 | OPTIMIZE_MODE_VERIFIED, /* only optimize verified classes (default) */ |
| 31 | OPTIMIZE_MODE_ALL /* optimize all classes */ |
| 32 | } DexOptimizerMode; |
| 33 | |
| 34 | /* some additional bit flags for dexopt */ |
| 35 | enum DexoptFlags { |
| 36 | DEXOPT_GEN_REGISTER_MAPS = 1, /* generate register maps during verify */ |
| 37 | }; |
| 38 | |
| 39 | /* |
| Andy McFadden | 62a7516 | 2009-04-17 17:23:37 -0700 | [diff] [blame] | 40 | * An enumeration of problems that can turn up during verification. |
| 41 | */ |
| 42 | typedef enum VerifyError { |
| 43 | VERIFY_ERROR_NONE = 0, /* no error; must be zero */ |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 44 | VERIFY_ERROR_GENERIC, /* VerifyError */ |
| Andy McFadden | 62a7516 | 2009-04-17 17:23:37 -0700 | [diff] [blame] | 45 | |
| Andy McFadden | af0e838 | 2009-08-28 10:38:37 -0700 | [diff] [blame] | 46 | VERIFY_ERROR_NO_CLASS, /* NoClassDefFoundError */ |
| 47 | VERIFY_ERROR_NO_FIELD, /* NoSuchFieldError */ |
| 48 | VERIFY_ERROR_NO_METHOD, /* NoSuchMethodError */ |
| 49 | VERIFY_ERROR_ACCESS_CLASS, /* IllegalAccessError */ |
| 50 | VERIFY_ERROR_ACCESS_FIELD, /* IllegalAccessError */ |
| 51 | VERIFY_ERROR_ACCESS_METHOD, /* IllegalAccessError */ |
| 52 | VERIFY_ERROR_CLASS_CHANGE, /* IncompatibleClassChangeError */ |
| 53 | VERIFY_ERROR_INSTANTIATION, /* InstantiationError */ |
| Andy McFadden | 62a7516 | 2009-04-17 17:23:37 -0700 | [diff] [blame] | 54 | } VerifyError; |
| 55 | |
| Andy McFadden | af0e838 | 2009-08-28 10:38:37 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Identifies the type of reference in the instruction that generated the |
| 58 | * verify error (e.g. VERIFY_ERROR_ACCESS_CLASS could come from a method, |
| 59 | * field, or class reference). |
| 60 | * |
| 61 | * This must fit in two bits. |
| 62 | */ |
| 63 | typedef enum VerifyErrorRefType { |
| 64 | VERIFY_ERROR_REF_CLASS = 0, |
| 65 | VERIFY_ERROR_REF_FIELD = 1, |
| 66 | VERIFY_ERROR_REF_METHOD = 2, |
| 67 | } VerifyErrorRefType; |
| 68 | |
| 69 | #define kVerifyErrorRefTypeShift 6 |
| 70 | |
| Andy McFadden | 62a7516 | 2009-04-17 17:23:37 -0700 | [diff] [blame] | 71 | #define VERIFY_OK(_failure) ((_failure) == VERIFY_ERROR_NONE) |
| 72 | |
| 73 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 74 | * Given the full path to a DEX or Jar file, and (if appropriate) the name |
| 75 | * within the Jar, open the optimized version from the cache. |
| 76 | * |
| 77 | * If "*pNewFile" is set, a new file has been created with only a stub |
| 78 | * "opt" header, and the caller is expected to fill in the blanks. |
| 79 | * |
| 80 | * Returns the file descriptor, locked and seeked past the "opt" header. |
| 81 | */ |
| 82 | int dvmOpenCachedDexFile(const char* fileName, const char* cachedFile, |
| 83 | u4 modWhen, u4 crc, bool isBootstrap, bool* pNewFile, bool createIfMissing); |
| 84 | |
| 85 | /* |
| 86 | * Unlock the specified file descriptor. Use in conjunction with |
| 87 | * dvmOpenCachedDexFile(). |
| 88 | * |
| 89 | * Returns true on success. |
| 90 | */ |
| 91 | bool dvmUnlockCachedDexFile(int fd); |
| 92 | |
| 93 | /* |
| 94 | * Verify the contents of the "opt" header, and check the DEX file's |
| 95 | * dependencies on its source zip (if available). |
| 96 | */ |
| 97 | bool dvmCheckOptHeaderAndDependencies(int fd, bool sourceAvail, u4 modWhen, |
| 98 | u4 crc, bool expectVerify, bool expectOpt); |
| 99 | |
| 100 | /* |
| 101 | * Optimize a DEX file. The file must start with the "opt" header, followed |
| 102 | * by the plain DEX data. It must be mmap()able. |
| 103 | * |
| 104 | * "fileName" is only used for debug output. |
| 105 | */ |
| 106 | bool dvmOptimizeDexFile(int fd, off_t dexOffset, long dexLen, |
| 107 | const char* fileName, u4 modWhen, u4 crc, bool isBootstrap); |
| 108 | |
| 109 | /* |
| 110 | * Continue the optimization process on the other side of a fork/exec. |
| 111 | */ |
| 112 | bool dvmContinueOptimization(int fd, off_t dexOffset, long dexLength, |
| 113 | const char* fileName, u4 modWhen, u4 crc, bool isBootstrap); |
| 114 | |
| Andy McFadden | 2e1ee50 | 2010-03-24 13:25:53 -0700 | [diff] [blame^] | 115 | #endif /*_DALVIK_DEXPREPARE*/ |