HeapInternal.h revision 1663a6c12fdf4732d7ea0a0406af6085b3c408e4
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 /* Is the GC running? Used to avoid recursive calls to GC. 54 */ 55 bool gcRunning; 56 57 /* 58 * Debug control values 59 */ 60 int ddmHpifWhen; 61 int ddmHpsgWhen; 62 int ddmHpsgWhat; 63 int ddmNhsgWhen; 64 int ddmNhsgWhat; 65}; 66 67bool dvmLockHeap(void); 68void dvmUnlockHeap(void); 69 70/* 71 * Logging helpers 72 */ 73 74#define HEAP_LOG_TAG LOG_TAG "-heap" 75 76#if LOG_NDEBUG 77#define LOGV_HEAP(...) ((void)0) 78#define LOGD_HEAP(...) ((void)0) 79#else 80#define LOGV_HEAP(...) ALOG(LOG_VERBOSE, HEAP_LOG_TAG, __VA_ARGS__) 81#define LOGD_HEAP(...) ALOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__) 82#endif 83#define LOGI_HEAP(...) \ 84 do { \ 85 if (!gDvm.zygote) { ALOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__); } \ 86 } while (0) 87 88#define LOGW_HEAP(...) ALOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__) 89#define LOGE_HEAP(...) ALOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__) 90 91#define FRACTIONAL_MB(n) (n) / (1024 * 1024), \ 92 ((((n) % (1024 * 1024)) / 1024) * 1000) / 1024 93#define FRACTIONAL_PCT(n,max) ((n) * 100) / (max), \ 94 (((n) * 1000) / (max)) % 10 95 96#endif // DALVIK_ALLOC_HEAP_INTERNAL_H_ 97