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 cardTableMaxLength;
52    size_t cardTableOffset;
53
54    /* Is the GC running?  Used to avoid recursive calls to GC.
55     */
56    bool gcRunning;
57
58    /*
59     * Debug control values
60     */
61    int ddmHpifWhen;
62    int ddmHpsgWhen;
63    int ddmHpsgWhat;
64    int ddmNhsgWhen;
65    int ddmNhsgWhat;
66};
67
68bool dvmLockHeap(void);
69void dvmUnlockHeap(void);
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(...)    ALOG(LOG_VERBOSE, HEAP_LOG_TAG, __VA_ARGS__)
82#define LOGD_HEAP(...)    ALOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__)
83#endif
84#define LOGI_HEAP(...) \
85    do { \
86        if (!gDvm.zygote) { ALOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__); } \
87    } while (0)
88
89#define LOGW_HEAP(...)    ALOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__)
90#define LOGE_HEAP(...)    ALOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__)
91
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
97#endif  // DALVIK_ALLOC_HEAP_INTERNAL_H_
98