blob: c708e1662ffc6a1ee4319efea47e5b0ac8016182 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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
20#define _DALVIK_ALLOC_HEAP_INTERNAL
21
22#include <time.h> // for struct timespec
23
24#include "HeapTable.h"
25#include "MarkSweep.h"
26
Carl Shapiro18555fc2010-12-02 13:36:58 -080027typedef struct HeapSource HeapSource;
28
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080029struct GcHeap {
30 HeapSource *heapSource;
31
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080032 /* List of heap objects that will require finalization when
33 * collected. I.e., instance objects
34 *
35 * a) whose class definitions override java.lang.Object.finalize()
36 *
37 * *** AND ***
38 *
39 * b) that have never been finalized.
40 *
41 * Note that this does not exclude non-garbage objects; this
42 * is not the list of pending finalizations, but of objects that
43 * potentially have finalization in their futures.
44 */
45 LargeHeapRefTable *finalizableRefs;
46
47 /* The list of objects that need to have finalize() called
48 * on themselves. These references are part of the root set.
49 *
50 * This table is protected by gDvm.heapWorkerListLock, which must
51 * be acquired after the heap lock.
52 */
53 LargeHeapRefTable *pendingFinalizationRefs;
54
55 /* Linked lists of subclass instances of java/lang/ref/Reference
56 * that we find while recursing. The "next" pointers are hidden
57 * in the objects' <code>int Reference.vmData</code> fields.
58 * These lists are cleared and rebuilt each time the GC runs.
59 */
60 Object *softReferences;
61 Object *weakReferences;
62 Object *phantomReferences;
63
64 /* The list of Reference objects that need to be cleared and/or
65 * enqueued. The bottom two bits of the object pointers indicate
66 * whether they should be cleared and/or enqueued.
67 *
68 * This table is protected by gDvm.heapWorkerListLock, which must
69 * be acquired after the heap lock.
70 */
71 LargeHeapRefTable *referenceOperations;
72
73 /* If non-null, the method that the HeapWorker is currently
74 * executing.
75 */
76 Object *heapWorkerCurrentObject;
77 Method *heapWorkerCurrentMethod;
78
79 /* If heapWorkerCurrentObject is non-null, this gives the time when
80 * HeapWorker started executing that method. The time value must come
81 * from dvmGetRelativeTimeUsec().
82 *
83 * The "Cpu" entry tracks the per-thread CPU timer (when available).
84 */
85 u8 heapWorkerInterpStartTime;
86 u8 heapWorkerInterpCpuStartTime;
87
88 /* If any fields are non-zero, indicates the next (absolute) time that
89 * the HeapWorker thread should call dvmHeapSourceTrim().
90 */
91 struct timespec heapWorkerNextTrim;
92
93 /* The current state of the mark step.
94 * Only valid during a GC.
95 */
96 GcMarkContext markContext;
97
Barry Hayes6e5cf602010-06-22 12:32:59 -070098 /* GC's card table */
99 u1* cardTableBase;
100 size_t cardTableLength;
Barry Hayes6e5cf602010-06-22 12:32:59 -0700101
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800102 /* Is the GC running? Used to avoid recursive calls to GC.
103 */
104 bool gcRunning;
105
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800106 /*
107 * Debug control values
108 */
109
110 int ddmHpifWhen;
111 int ddmHpsgWhen;
112 int ddmHpsgWhat;
113 int ddmNhsgWhen;
114 int ddmNhsgWhat;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800115};
116
117bool dvmLockHeap(void);
118void dvmUnlockHeap(void);
119void dvmLogGcStats(size_t numFreed, size_t sizeFreed, size_t gcTimeMs);
120void dvmLogMadviseStats(size_t madvisedSizes[], size_t arrayLen);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800121
122/*
123 * Logging helpers
124 */
125
126#define HEAP_LOG_TAG LOG_TAG "-heap"
127
128#if LOG_NDEBUG
129#define LOGV_HEAP(...) ((void)0)
130#define LOGD_HEAP(...) ((void)0)
131#else
132#define LOGV_HEAP(...) LOG(LOG_VERBOSE, HEAP_LOG_TAG, __VA_ARGS__)
133#define LOGD_HEAP(...) LOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__)
134#endif
Carl Shapiroa5e14d62010-12-02 14:04:22 -0800135#define LOGI_HEAP(...) \
136 (!gDvm.zygote ? LOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__) : (void)0)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800137#define LOGW_HEAP(...) LOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__)
138#define LOGE_HEAP(...) LOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__)
139
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800140#define FRACTIONAL_MB(n) (n) / (1024 * 1024), \
141 ((((n) % (1024 * 1024)) / 1024) * 1000) / 1024
142#define FRACTIONAL_PCT(n,max) ((n) * 100) / (max), \
143 (((n) * 1000) / (max)) % 10
144
145#endif // _DALVIK_ALLOC_HEAP_INTERNAL