blob: 0b0bc47dc7540961edbdd07e2f3c5ef76acd842f [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 * Internal heap functions
18 */
19#ifndef _DALVIK_ALLOC_HEAP
20#define _DALVIK_ALLOC_HEAP
21
22/*
23 * Initialize the GC heap.
24 *
25 * Returns true if successful, false otherwise.
26 */
27bool dvmHeapStartup(void);
28
29/*
30 * Initialization that needs to wait until after leaving zygote mode.
31 * This needs to be called before the first allocation or GC that
32 * happens after forking.
33 */
Carl Shapiroc8e06c82010-02-04 19:12:55 -080034void dvmHeapStartupAfterZygote(void);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080035
36/*
37 * Tear down the GC heap.
38 *
39 * Frees all memory allocated via dvmMalloc() as
40 * a side-effect.
41 */
42void dvmHeapShutdown(void);
43
44#if 0 // needs to be in Alloc.h so debug code can find it.
45/*
46 * Returns a number of bytes greater than or
47 * equal to the size of the named object in the heap.
48 *
49 * Specifically, it returns the size of the heap
50 * chunk which contains the object.
51 */
52size_t dvmObjectSizeInHeap(const Object *obj);
53#endif
54
Carl Shapirod25566d2010-03-11 20:39:47 -080055typedef enum {
56 /* GC all heaps. */
57 GC_FULL,
58 /* GC just the first heap. */
59 GC_PARTIAL
60} GcMode;
61
62typedef enum {
Barry Hayes1b9b4e42010-01-04 10:33:46 -080063 /* Not enough space for an "ordinary" Object to be allocated. */
64 GC_FOR_MALLOC,
65 /* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
66 GC_EXPLICIT,
67 /* GC to try to reduce heap footprint to allow more non-GC'ed memory. */
68 GC_EXTERNAL_ALLOC,
69 /* GC to dump heap contents to a file, only used under WITH_HPROF */
70 GC_HPROF_DUMP_HEAP
Carl Shapirod25566d2010-03-11 20:39:47 -080071} GcReason;
Barry Hayes1b9b4e42010-01-04 10:33:46 -080072
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080073/*
Barry Hayes962adba2010-03-17 12:12:39 -070074 * Suspend the VM as for a GC, and assert-fail if any object has any
75 * corrupt references.
76 */
77void dvmHeapSuspendAndVerify();
78
79/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080080 * Run the garbage collector without doing any locking.
81 */
Carl Shapiro29540742010-03-26 15:34:39 -070082void dvmCollectGarbageInternal(bool clearSoftRefs, GcReason reason);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080083
84#endif // _DALVIK_ALLOC_HEAP