2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * Garbage-collecting allocator.
19 #ifndef DALVIK_ALLOC_ALLOC_H_
20 #define DALVIK_ALLOC_ALLOC_H_
24 /* flags for dvmMalloc */
27 ALLOC_DONT_TRACK = 0x01, /* don't add to internal tracking list */
28 ALLOC_NON_MOVING = 0x02,
34 bool dvmGcStartup(void);
35 bool dvmCreateStockExceptions(void);
36 bool dvmGcStartupAfterZygote(void);
37 void dvmGcShutdown(void);
38 void dvmGcThreadShutdown(void);
39 bool dvmGcStartupClasses(void);
42 * Do any last-minute preparation before we call fork() for the first time.
44 bool dvmGcPreZygoteFork(void);
47 * Basic allocation function.
49 * The new object will be added to the "tracked alloc" table unless
50 * flags is ALLOC_DONT_TRACK.
52 * Returns NULL and throws an exception on failure.
54 void* dvmMalloc(size_t size, int flags);
57 * Allocate a new object.
59 * The new object will be added to the "tracked alloc" table unless
60 * flags is ALLOC_DONT_TRACK.
62 * Returns NULL and throws an exception on failure.
64 extern "C" Object* dvmAllocObject(ClassObject* clazz, int flags);
67 * Track an object reference that is currently only visible internally.
68 * This is called automatically by dvmMalloc() unless ALLOC_DONT_TRACK
71 * The "self" argument is allowed as an optimization; it may be NULL.
73 extern "C" void dvmAddTrackedAlloc(Object* obj, Thread* self);
76 * Remove an object from the internal tracking list.
78 * Does nothing if "obj" is NULL.
80 * The "self" argument is allowed as an optimization; it may be NULL.
82 extern "C" void dvmReleaseTrackedAlloc(Object* obj, Thread* self);
85 * Returns true iff <obj> points to a zygote allocated object.
87 bool dvmIsZygoteObject(const Object* obj);
90 * Create a copy of an object.
92 * Returns NULL and throws an exception on failure.
94 Object* dvmCloneObject(Object* obj, int flags);
97 * Make the object finalizable.
99 extern "C" void dvmSetFinalizable(Object* obj);
102 * Determine the exact number of GC heap bytes used by an object. (Internal
103 * to heap code except for debugging.)
105 size_t dvmObjectSizeInHeap(const Object* obj);
108 * Gets the current ideal heap utilization, represented as a number
109 * between zero and one.
111 float dvmGetTargetHeapUtilization(void);
114 * Sets the new ideal heap utilization, represented as a number
115 * between zero and one.
117 void dvmSetTargetHeapUtilization(float newTarget);
120 * Initiate garbage collection.
122 * This usually happens automatically, but can also be caused by
125 void dvmCollectGarbage(void);
128 * Calls System.runFinalization().
130 void dvmRunFinalization();
133 * Returns a count of the direct instances of a class.
135 size_t dvmCountInstancesOfClass(const ClassObject *clazz);
138 * Returns a count of the instances of a class and its subclasses.
140 size_t dvmCountAssignableInstancesOfClass(const ClassObject *clazz);
143 * Removes any growth limits from the heap.
145 void dvmClearGrowthLimit(void);
148 * Returns true if the address is aligned appropriately for a heap object.
149 * Does not require the caller to hold the heap lock, and does not take the
150 * heap lock internally.
152 bool dvmIsHeapAddress(void *address);
154 bool dvmIsNonMovingObject(const Object* object);
156 #endif // DALVIK_ALLOC_ALLOC_H_