buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 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 Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 22 | namespace art { |
| 23 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 24 | /* Each arena page has some overhead, so take a few bytes off */ |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 25 | #define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 26 | |
| 27 | /* Allocate the initial memory block for arena-based allocation */ |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 28 | bool oatHeapInit(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 29 | |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 30 | /* Collect memory usage statstics */ |
| 31 | //#define WITH_MEMSTATS |
| 32 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 33 | typedef struct ArenaMemBlock { |
| 34 | size_t blockSize; |
| 35 | size_t bytesAllocated; |
| 36 | struct ArenaMemBlock *next; |
| 37 | char ptr[0]; |
| 38 | } ArenaMemBlock; |
| 39 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 40 | void* oatNew(CompilationUnit* cUnit, size_t size, bool zero, |
| 41 | oatAllocKind kind = kAllocMisc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 42 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 43 | void oatArenaReset(CompilationUnit *cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 44 | |
| 45 | typedef struct GrowableList { |
| 46 | size_t numAllocated; |
| 47 | size_t numUsed; |
| 48 | intptr_t *elemList; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 49 | #ifdef WITH_MEMSTATS |
| 50 | oatListKind kind; |
| 51 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 52 | } GrowableList; |
| 53 | |
| 54 | typedef 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 | */ |
| 66 | struct ArenaBitVector { |
| 67 | bool expandable; /* expand bitmap if we run out? */ |
| 68 | u4 storageSize; /* current size, in 32-bit words */ |
| 69 | u4* storage; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 70 | #ifdef WITH_MEMSTATS |
| 71 | oatBitMapKind kind; /* for memory use tuning */ |
| 72 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /* Handy iterator to walk through the bit positions set to 1 */ |
| 76 | struct 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 */ |
| 87 | struct LIR; |
| 88 | struct BasicBlock; |
| 89 | struct CompilationUnit; |
| 90 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 91 | void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList, |
| 92 | size_t initLength, oatListKind kind = kListMisc); |
| 93 | void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList, |
| 94 | intptr_t elem); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 95 | void oatDeleteGrowableList(GrowableList* gList, intptr_t elem); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 96 | void oatGrowableListIteratorInit(GrowableList* gList, |
| 97 | GrowableListIterator* iterator); |
| 98 | intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator); |
| 99 | intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx); |
| 100 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 101 | ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit, |
| 102 | unsigned int startBits, bool expandable, |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 103 | oatBitMapKind = kBitMapMisc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 104 | void oatBitVectorIteratorInit(ArenaBitVector* pBits, |
| 105 | ArenaBitVectorIterator* iterator); |
| 106 | int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame^] | 107 | bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 108 | bool oatClearBit(ArenaBitVector* pBits, unsigned int num); |
| 109 | void oatMarkAllBits(ArenaBitVector* pBits, bool set); |
| 110 | void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length); |
| 111 | bool oatIsBitSet(const ArenaBitVector* pBits, unsigned int num); |
| 112 | void oatClearAllBits(ArenaBitVector* pBits); |
| 113 | void oatSetInitialBits(ArenaBitVector* pBits, unsigned int numBits); |
| 114 | void oatCopyBitVector(ArenaBitVector* dest, const ArenaBitVector* src); |
| 115 | bool oatIntersectBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 116 | const ArenaBitVector* src2); |
| 117 | bool oatUnifyBitVectors(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 118 | const ArenaBitVector* src2); |
| 119 | bool oatCompareBitVectors(const ArenaBitVector* src1, |
| 120 | const ArenaBitVector* src2); |
| 121 | int oatCountSetBits(const ArenaBitVector* pBits); |
| 122 | |
| 123 | void oatDumpLIRInsn(CompilationUnit* cUnit, struct LIR* lir, |
| 124 | unsigned char* baseAddr); |
| 125 | void oatDumpResourceMask(struct LIR* lir, u8 mask, const char* prefix); |
| 126 | void oatDumpBlockBitVector(const GrowableList* blocks, char* msg, |
| 127 | const ArenaBitVector* bv, int length); |
| 128 | void oatGetBlockName(struct BasicBlock* bb, char* name); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 129 | const char* oatGetShortyFromTargetIdx(CompilationUnit*, int); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 130 | void oatDumpRegLocTable(struct RegLocation*, int); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 131 | void oatDumpMemStats(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 132 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 133 | } // namespace art |
| 134 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 135 | #endif // ART_SRC_COMPILER_COMPILER_UTILITY_H_ |