blob: a6ddd1e8634af01d7b650c755e18b6a3c5b17246 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 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#ifndef ART_SRC_COMPILER_COMPILER_UTILITY_H_
18#define ART_SRC_COMPILER_COMPILER_UTILITY_H_
19
20#include "Dalvik.h"
21
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080022namespace art {
23
buzbee67bc2362011-10-11 18:08:40 -070024/* Each arena page has some overhead, so take a few bytes off */
buzbeeba938cb2012-02-03 14:47:55 -080025#define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256)
buzbee67bf8852011-08-17 17:51:35 -070026
27/* Allocate the initial memory block for arena-based allocation */
buzbeeba938cb2012-02-03 14:47:55 -080028bool oatHeapInit(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -070029
buzbee5abfa3e2012-01-31 17:01:43 -080030/* Collect memory usage statstics */
31//#define WITH_MEMSTATS
32
buzbee67bf8852011-08-17 17:51:35 -070033typedef struct ArenaMemBlock {
34 size_t blockSize;
35 size_t bytesAllocated;
36 struct ArenaMemBlock *next;
37 char ptr[0];
38} ArenaMemBlock;
39
buzbeeba938cb2012-02-03 14:47:55 -080040void* oatNew(CompilationUnit* cUnit, size_t size, bool zero,
41 oatAllocKind kind = kAllocMisc);
buzbee67bf8852011-08-17 17:51:35 -070042
buzbeeba938cb2012-02-03 14:47:55 -080043void oatArenaReset(CompilationUnit *cUnit);
buzbee67bf8852011-08-17 17:51:35 -070044
45typedef struct GrowableList {
46 size_t numAllocated;
47 size_t numUsed;
48 intptr_t *elemList;
buzbee5abfa3e2012-01-31 17:01:43 -080049#ifdef WITH_MEMSTATS
50 oatListKind kind;
51#endif
buzbee67bf8852011-08-17 17:51:35 -070052} GrowableList;
53
54typedef struct GrowableListIterator {
55 GrowableList* list;
56 size_t idx;
57 size_t size;
58} GrowableListIterator;
59
60/*
61 * Expanding bitmap, used for tracking resources. Bits are numbered starting
62 * from zero.
63 *
64 * All operations on a BitVector are unsynchronized.
65 */
66struct ArenaBitVector {
67 bool expandable; /* expand bitmap if we run out? */
68 u4 storageSize; /* current size, in 32-bit words */
69 u4* storage;
buzbee5abfa3e2012-01-31 17:01:43 -080070#ifdef WITH_MEMSTATS
71 oatBitMapKind kind; /* for memory use tuning */
72#endif
buzbee67bf8852011-08-17 17:51:35 -070073};
74
75/* Handy iterator to walk through the bit positions set to 1 */
76struct ArenaBitVectorIterator {
77 ArenaBitVector* pBits;
78 u4 idx;
79 u4 bitSize;
80};
81
82#define GET_ELEM_N(LIST, TYPE, N) (((TYPE*) LIST->elemList)[N])
83
84#define BLOCK_NAME_LEN 80
85
86/* Forward declarations */
87struct LIR;
88struct BasicBlock;
89struct CompilationUnit;
90
buzbeeba938cb2012-02-03 14:47:55 -080091void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList,
92 size_t initLength, oatListKind kind = kListMisc);
93void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList,
94 intptr_t elem);
buzbee5abfa3e2012-01-31 17:01:43 -080095void oatDeleteGrowableList(GrowableList* gList, intptr_t elem);
buzbee67bf8852011-08-17 17:51:35 -070096void oatGrowableListIteratorInit(GrowableList* gList,
97 GrowableListIterator* iterator);
98intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
99intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
100
buzbeeba938cb2012-02-03 14:47:55 -0800101ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit,
102 unsigned int startBits, bool expandable,
buzbee5abfa3e2012-01-31 17:01:43 -0800103 oatBitMapKind = kBitMapMisc);
buzbee67bf8852011-08-17 17:51:35 -0700104void oatBitVectorIteratorInit(ArenaBitVector* pBits,
105 ArenaBitVectorIterator* iterator);
106int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
buzbeeba938cb2012-02-03 14:47:55 -0800107bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num);
buzbee67bf8852011-08-17 17:51:35 -0700108bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
109void oatMarkAllBits(ArenaBitVector* pBits, bool set);
110void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);
111bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num);
112void oatClearAllBits(ArenaBitVector* pBits);
113void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits);
114void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src);
115bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
116 const ArenaBitVector* src2);
117bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1,
118 const ArenaBitVector* src2);
119bool oatCompareBitVectors(const ArenaBitVector* src1,
120 const ArenaBitVector* src2);
121int oatCountSetBits(const ArenaBitVector* pBits);
122
123void oatDumpLIRInsn(CompilationUnit* cUnit, struct LIR* lir,
124 unsigned char* baseAddr);
125void oatDumpResourceMask(struct LIR* lir, u8 mask, const char* prefix);
126void oatDumpBlockBitVector(const GrowableList* blocks, char* msg,
127 const ArenaBitVector* bv, int length);
128void oatGetBlockName(struct BasicBlock* bb, char* name);
buzbeeed3e9302011-09-23 17:34:19 -0700129const char* oatGetShortyFromTargetIdx(CompilationUnit*, int);
buzbee6181f792011-09-29 11:14:04 -0700130void oatDumpRegLocTable(struct RegLocation*, int);
buzbee5abfa3e2012-01-31 17:01:43 -0800131void oatDumpMemStats(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700132
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800133} // namespace art
134
buzbee67bf8852011-08-17 17:51:35 -0700135#endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_