HeapInternal.h revision 375fb116bcb817b37509ab579dbd55cdbb765cbf
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 */ 16/* 17 * Types and macros used internally by the heap. 18 */ 19#ifndef DALVIK_ALLOC_HEAP_INTERNAL_H_ 20#define DALVIK_ALLOC_HEAP_INTERNAL_H_ 21 22#include "MarkSweep.h" 23 24struct HeapSource; 25 26struct GcHeap { 27 HeapSource *heapSource; 28 29 /* Linked lists of subclass instances of java/lang/ref/Reference 30 * that we find while recursing. The "next" pointers are hidden 31 * in the Reference objects' pendingNext fields. These lists are 32 * cleared and rebuilt each time the GC runs. 33 */ 34 Object *softReferences; 35 Object *weakReferences; 36 Object *finalizerReferences; 37 Object *phantomReferences; 38 39 /* The list of Reference objects that need to be enqueued. 40 */ 41 Object *clearedReferences; 42 43 /* The current state of the mark step. 44 * Only valid during a GC. 45 */ 46 GcMarkContext markContext; 47 48 /* GC's card table */ 49 u1* cardTableBase; 50 size_t cardTableLength; 51 size_t cardTableOffset; 52 53 /* GC's modified union table. */ 54 u1* modUnionTableBase; 55 size_t modUnionTableLength; 56 57 /* Is the GC running? Used to avoid recursive calls to GC. 58 */ 59 bool gcRunning; 60 61 /* 62 * Debug control values 63 */ 64 int ddmHpifWhen; 65 int ddmHpsgWhen; 66 int ddmHpsgWhat; 67 int ddmNhsgWhen; 68 int ddmNhsgWhat; 69}; 70 71bool dvmLockHeap(void); 72void dvmUnlockHeap(void); 73 74/* 75 * Logging helpers 76 */ 77 78#define HEAP_LOG_TAG LOG_TAG "-heap" 79 80#if LOG_NDEBUG 81#define LOGV_HEAP(...) ((void)0) 82#define LOGD_HEAP(...) ((void)0) 83#else 84#define LOGV_HEAP(...) LOG(LOG_VERBOSE, HEAP_LOG_TAG, __VA_ARGS__) 85#define LOGD_HEAP(...) LOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__) 86#endif 87#define LOGI_HEAP(...) \ 88 do { \ 89 if (!gDvm.zygote) { LOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__); } \ 90 } while (0) 91 92#define LOGW_HEAP(...) LOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__) 93#define LOGE_HEAP(...) LOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__) 94 95#define FRACTIONAL_MB(n) (n) / (1024 * 1024), \ 96 ((((n) % (1024 * 1024)) / 1024) * 1000) / 1024 97#define FRACTIONAL_PCT(n,max) ((n) * 100) / (max), \ 98 (((n) * 1000) / (max)) % 10 99 100#endif // DALVIK_ALLOC_HEAP_INTERNAL_H_ 101