The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | */ |
Carl Shapiro | 375fb11 | 2011-06-14 20:31:24 -0700 | [diff] [blame] | 19 | #ifndef DALVIK_ALLOC_HEAP_INTERNAL_H_ |
| 20 | #define DALVIK_ALLOC_HEAP_INTERNAL_H_ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 21 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 22 | #include "MarkSweep.h" |
| 23 | |
Carl Shapiro | 50e5fd5 | 2011-04-27 14:44:47 -0700 | [diff] [blame] | 24 | struct HeapSource; |
Carl Shapiro | 18555fc | 2010-12-02 13:36:58 -0800 | [diff] [blame] | 25 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 26 | struct GcHeap { |
Carl Shapiro | a97851e | 2011-05-11 18:08:21 -0700 | [diff] [blame] | 27 | HeapSource *heapSource; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 28 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 29 | /* Linked lists of subclass instances of java/lang/ref/Reference |
| 30 | * that we find while recursing. The "next" pointers are hidden |
Carl Shapiro | a97851e | 2011-05-11 18:08:21 -0700 | [diff] [blame] | 31 | * in the Reference objects' pendingNext fields. These lists are |
| 32 | * cleared and rebuilt each time the GC runs. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 33 | */ |
Carl Shapiro | 3475f9c | 2011-03-21 13:35:24 -0700 | [diff] [blame] | 34 | Object *softReferences; |
| 35 | Object *weakReferences; |
| 36 | Object *finalizerReferences; |
| 37 | Object *phantomReferences; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 38 | |
Carl Shapiro | ce87bfe | 2011-03-30 19:35:34 -0700 | [diff] [blame] | 39 | /* The list of Reference objects that need to be enqueued. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 40 | */ |
Carl Shapiro | ce87bfe | 2011-03-30 19:35:34 -0700 | [diff] [blame] | 41 | Object *clearedReferences; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 42 | |
| 43 | /* The current state of the mark step. |
| 44 | * Only valid during a GC. |
| 45 | */ |
Carl Shapiro | a97851e | 2011-05-11 18:08:21 -0700 | [diff] [blame] | 46 | GcMarkContext markContext; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 47 | |
Barry Hayes | 6e5cf60 | 2010-06-22 12:32:59 -0700 | [diff] [blame] | 48 | /* GC's card table */ |
Carl Shapiro | a97851e | 2011-05-11 18:08:21 -0700 | [diff] [blame] | 49 | u1* cardTableBase; |
| 50 | size_t cardTableLength; |
Andy McFadden | af6cf54 | 2011-11-04 12:56:55 -0700 | [diff] [blame] | 51 | size_t cardTableMaxLength; |
Carl Shapiro | eebf7c6 | 2011-06-07 21:42:44 -0700 | [diff] [blame] | 52 | size_t cardTableOffset; |
Barry Hayes | 6e5cf60 | 2010-06-22 12:32:59 -0700 | [diff] [blame] | 53 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 54 | /* Is the GC running? Used to avoid recursive calls to GC. |
| 55 | */ |
Carl Shapiro | a97851e | 2011-05-11 18:08:21 -0700 | [diff] [blame] | 56 | bool gcRunning; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 57 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 58 | /* |
| 59 | * Debug control values |
| 60 | */ |
Carl Shapiro | a97851e | 2011-05-11 18:08:21 -0700 | [diff] [blame] | 61 | int ddmHpifWhen; |
| 62 | int ddmHpsgWhen; |
| 63 | int ddmHpsgWhat; |
| 64 | int ddmNhsgWhen; |
| 65 | int ddmNhsgWhat; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | bool dvmLockHeap(void); |
| 69 | void dvmUnlockHeap(void); |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Logging helpers |
| 73 | */ |
| 74 | |
| 75 | #define HEAP_LOG_TAG LOG_TAG "-heap" |
| 76 | |
| 77 | #if LOG_NDEBUG |
| 78 | #define LOGV_HEAP(...) ((void)0) |
| 79 | #define LOGD_HEAP(...) ((void)0) |
| 80 | #else |
| 81 | #define LOGV_HEAP(...) LOG(LOG_VERBOSE, HEAP_LOG_TAG, __VA_ARGS__) |
| 82 | #define LOGD_HEAP(...) LOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__) |
| 83 | #endif |
Carl Shapiro | a5e14d6 | 2010-12-02 14:04:22 -0800 | [diff] [blame] | 84 | #define LOGI_HEAP(...) \ |
Carl Shapiro | ae188c6 | 2011-04-08 13:11:58 -0700 | [diff] [blame] | 85 | do { \ |
| 86 | if (!gDvm.zygote) { LOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__); } \ |
| 87 | } while (0) |
| 88 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 89 | #define LOGW_HEAP(...) LOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__) |
| 90 | #define LOGE_HEAP(...) LOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__) |
| 91 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 92 | #define FRACTIONAL_MB(n) (n) / (1024 * 1024), \ |
| 93 | ((((n) % (1024 * 1024)) / 1024) * 1000) / 1024 |
| 94 | #define FRACTIONAL_PCT(n,max) ((n) * 100) / (max), \ |
| 95 | (((n) * 1000) / (max)) % 10 |
| 96 | |
Carl Shapiro | 375fb11 | 2011-06-14 20:31:24 -0700 | [diff] [blame] | 97 | #endif // DALVIK_ALLOC_HEAP_INTERNAL_H_ |