blob: 342e12531e437658bac7e523012cbc7e7a32478a [file] [log] [blame]
The Android Open Source Project89c1feb2008-12-17 18:03:55 -08001/*
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/*
18 * DEX constant-reduction declarations.
19 */
20#ifndef _DALVIK_REDUCECONSTANTS
21#define _DALVIK_REDUCECONSTANTS
22
23#define DVM_RC_DISABLED 0 /* no reduction, 1:1 map */
24#define DVM_RC_REDUCING 1 /* normal constants, reduced lookup table */
25#define DVM_RC_EXPANDING 2 /* reduced constants, expanded on resolve */
26#define DVM_RC_NO_CACHE 3 /* disable the cache (reduce to zero) */
27
28enum {
29 kMapClasses = 0,
30 kMapMethods = 1,
31 kMapFields = 2,
32 kMapStrings = 3,
33
34 kNumIndexMaps
35};
36
37struct DvmDex;
38
39#define kNoIndexMapping ((u2) -1)
40
41/*
42 * Map indices back to the original.
43 */
44typedef struct IndexMap {
45 int origCount; /* original size; describes range of entries in map */
46 int newCount; /* reduced size */
47 u2* mapToNew; /* sparse map, from "orig" to "new" */
48 u2* mapToOld; /* dense map, from "new" back to "orig" */
49} IndexMap;
50typedef struct IndexMapSet {
51 /* maps for the different sections */
52 IndexMap map[kNumIndexMaps];
53
54 /* data stream that gets appended to the optimized DEX file */
55 u4 chunkType;
56 int chunkDataLen;
57 u1* chunkData;
58} IndexMapSet;
59
60/*
61 * Constant pool compaction.
62 *
63 * The caller is responsible for freeing the returned structure by
64 * calling dvmFreeIndexMap().
65 */
66IndexMapSet* dvmRewriteConstants(struct DvmDex* pDvmDex);
67
68/* free an index map set */
69void dvmFreeIndexMapSet(IndexMapSet* indexMapSet);
70
71#endif /*_DALVIK_REDUCECONSTANTS*/