blob: 576bf7d69eb7822ba64e3679b8448b418b55f1be [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 */
Carl Shapiro375fb112011-06-14 20:31:24 -070019#ifndef DALVIK_ALLOC_HEAP_INTERNAL_H_
20#define DALVIK_ALLOC_HEAP_INTERNAL_H_
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080021
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080022#include "MarkSweep.h"
23
Carl Shapiro50e5fd52011-04-27 14:44:47 -070024struct HeapSource;
Carl Shapiro18555fc2010-12-02 13:36:58 -080025
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080026struct GcHeap {
Carl Shapiroa97851e2011-05-11 18:08:21 -070027 HeapSource *heapSource;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080028
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080029 /* Linked lists of subclass instances of java/lang/ref/Reference
30 * that we find while recursing. The "next" pointers are hidden
Carl Shapiroa97851e2011-05-11 18:08:21 -070031 * in the Reference objects' pendingNext fields. These lists are
32 * cleared and rebuilt each time the GC runs.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080033 */
Carl Shapiro3475f9c2011-03-21 13:35:24 -070034 Object *softReferences;
35 Object *weakReferences;
36 Object *finalizerReferences;
37 Object *phantomReferences;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080038
Carl Shapiroce87bfe2011-03-30 19:35:34 -070039 /* The list of Reference objects that need to be enqueued.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080040 */
Carl Shapiroce87bfe2011-03-30 19:35:34 -070041 Object *clearedReferences;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080042
43 /* The current state of the mark step.
44 * Only valid during a GC.
45 */
Carl Shapiroa97851e2011-05-11 18:08:21 -070046 GcMarkContext markContext;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080047
Barry Hayes6e5cf602010-06-22 12:32:59 -070048 /* GC's card table */
Carl Shapiroa97851e2011-05-11 18:08:21 -070049 u1* cardTableBase;
50 size_t cardTableLength;
Andy McFaddenaf6cf542011-11-04 12:56:55 -070051 size_t cardTableMaxLength;
Carl Shapiroeebf7c62011-06-07 21:42:44 -070052 size_t cardTableOffset;
Barry Hayes6e5cf602010-06-22 12:32:59 -070053
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080054 /* Is the GC running? Used to avoid recursive calls to GC.
55 */
Carl Shapiroa97851e2011-05-11 18:08:21 -070056 bool gcRunning;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080057
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080058 /*
59 * Debug control values
60 */
Carl Shapiroa97851e2011-05-11 18:08:21 -070061 int ddmHpifWhen;
62 int ddmHpsgWhen;
63 int ddmHpsgWhat;
64 int ddmNhsgWhen;
65 int ddmNhsgWhat;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080066};
67
68bool dvmLockHeap(void);
69void dvmUnlockHeap(void);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080070
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
Steve Block1663a6c2011-10-12 17:24:48 +010081#define LOGV_HEAP(...) ALOG(LOG_VERBOSE, HEAP_LOG_TAG, __VA_ARGS__)
82#define LOGD_HEAP(...) ALOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080083#endif
Carl Shapiroa5e14d62010-12-02 14:04:22 -080084#define LOGI_HEAP(...) \
Carl Shapiroae188c62011-04-08 13:11:58 -070085 do { \
Steve Block1663a6c2011-10-12 17:24:48 +010086 if (!gDvm.zygote) { ALOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__); } \
Carl Shapiroae188c62011-04-08 13:11:58 -070087 } while (0)
88
Steve Block1663a6c2011-10-12 17:24:48 +010089#define LOGW_HEAP(...) ALOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__)
90#define LOGE_HEAP(...) ALOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080091
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080092#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 Shapiro375fb112011-06-14 20:31:24 -070097#endif // DALVIK_ALLOC_HEAP_INTERNAL_H_