blob: aeba3f5d9f49331449743098c4b6ff00f3843b87 [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 * Garbage-collecting allocator.
18 */
19#ifndef _DALVIK_ALLOC_ALLOC
20#define _DALVIK_ALLOC_ALLOC
21
Carl Shapiroad9400f2010-05-01 20:08:57 -070022#include <stddef.h>
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080023
24/*
25 * Initialization.
26 */
27bool dvmGcStartup(void);
Andy McFadden7fc3ce82009-07-14 15:57:23 -070028bool dvmCreateStockExceptions(void);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080029bool dvmGcStartupAfterZygote(void);
30void dvmGcShutdown(void);
Carl Shapiroec805ea2010-06-28 16:28:26 -070031void dvmGcThreadShutdown(void);
Carl Shapiroce87bfe2011-03-30 19:35:34 -070032bool dvmGcStartupClasses(void);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080033
34/*
35 * Do any last-minute preparation before we call fork() for the first time.
36 */
37bool dvmGcPreZygoteFork(void);
38
39/*
40 * Basic allocation function.
41 *
42 * The new object will be added to the "tracked alloc" table unless
Barry Hayesd4f78d32010-06-08 09:34:42 -070043 * flags is ALLOC_DONT_TRACK.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080044 *
45 * Returns NULL and throws an exception on failure.
46 */
47void* dvmMalloc(size_t size, int flags);
48
49/*
50 * Allocate a new object.
51 *
52 * The new object will be added to the "tracked alloc" table unless
Barry Hayesd4f78d32010-06-08 09:34:42 -070053 * flags is ALLOC_DONT_TRACK.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080054 *
55 * Returns NULL and throws an exception on failure.
56 */
57Object* dvmAllocObject(ClassObject* clazz, int flags);
58
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080059/* flags for dvmMalloc */
60enum {
61 ALLOC_DEFAULT = 0x00,
Barry Hayesd4f78d32010-06-08 09:34:42 -070062 ALLOC_DONT_TRACK = 0x01, /* don't add to internal tracking list */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080063};
64
65/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080066 * Track an object reference that is currently only visible internally.
67 * This is called automatically by dvmMalloc() unless ALLOC_DONT_TRACK
68 * is set.
69 *
70 * The "self" argument is allowed as an optimization; it may be NULL.
71 */
72void dvmAddTrackedAlloc(Object* obj, Thread* self);
73
74/*
75 * Remove an object from the internal tracking list.
76 *
77 * Does nothing if "obj" is NULL.
78 *
79 * The "self" argument is allowed as an optimization; it may be NULL.
80 */
81void dvmReleaseTrackedAlloc(Object* obj, Thread* self);
82
83/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080084 * Returns true iff <obj> points to a valid allocated object.
85 */
86bool dvmIsValidObject(const Object* obj);
87
88/*
89 * Create a copy of an object.
90 *
Andy McFadden0f27ad72011-02-22 13:56:47 -080091 * Returns NULL and throws an exception on failure.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080092 */
Andy McFadden0f27ad72011-02-22 13:56:47 -080093Object* dvmCloneObject(Object* obj, int flags);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080094
95/*
Andy McFadden6af2ddd2011-02-16 16:50:40 -080096 * Make the object finalizable.
97 */
98void dvmSetFinalizable(Object* obj);
99
100/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800101 * Determine the exact number of GC heap bytes used by an object. (Internal
102 * to heap code except for debugging.)
103 */
104size_t dvmObjectSizeInHeap(const Object* obj);
105
106/*
107 * Gets the current ideal heap utilization, represented as a number
108 * between zero and one.
109 */
110float dvmGetTargetHeapUtilization(void);
111
112/*
113 * Sets the new ideal heap utilization, represented as a number
114 * between zero and one.
115 */
116void dvmSetTargetHeapUtilization(float newTarget);
117
118/*
Carl Shapiro0445e482010-12-02 17:27:01 -0800119 * Initiate garbage collection.
120 *
Carl Shapiroa371fad2011-01-23 15:58:31 -0800121 * This usually happens automatically, but can also be caused by
Carl Shapirobc3ba012011-02-09 14:20:14 -0800122 * Runtime.gc().
Carl Shapiro0445e482010-12-02 17:27:01 -0800123 */
Carl Shapirobc3ba012011-02-09 14:20:14 -0800124void dvmCollectGarbage(void);
Carl Shapiro0445e482010-12-02 17:27:01 -0800125
126/*
Carl Shapirof331a602010-11-04 15:12:09 -0700127 * Returns a count of the direct instances of a class.
Carl Shapiro41eb6e92010-08-17 13:30:48 -0700128 */
129size_t dvmCountInstancesOfClass(const ClassObject *clazz);
130
Carl Shapirof331a602010-11-04 15:12:09 -0700131/*
132 * Returns a count of the instances of a class and its subclasses.
133 */
134size_t dvmCountAssignableInstancesOfClass(const ClassObject *clazz);
135
Carl Shapirodf9f08b2011-01-18 17:59:30 -0800136/*
137 * Removes any growth limits from the heap.
138 */
139void dvmClearGrowthLimit(void);
140
Carl Shapiro2494c502011-03-11 17:54:58 -0800141/*
142 * Returns true if the address is within the bounds of the heap.
143 */
144bool dvmIsHeapAddress(void *address);
145
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800146#endif /*_DALVIK_ALLOC_ALLOC*/