Alloc.h revision 2494c5038e668add68c74dea83aca05187a89e7c
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 * Garbage-collecting allocator. 18 */ 19#ifndef _DALVIK_ALLOC_ALLOC 20#define _DALVIK_ALLOC_ALLOC 21 22#include <stddef.h> 23 24/* 25 * Initialization. 26 */ 27bool dvmGcStartup(void); 28bool dvmCreateStockExceptions(void); 29bool dvmGcStartupAfterZygote(void); 30void dvmGcShutdown(void); 31void dvmGcThreadShutdown(void); 32 33/* 34 * Do any last-minute preparation before we call fork() for the first time. 35 */ 36bool dvmGcPreZygoteFork(void); 37 38/* 39 * Basic allocation function. 40 * 41 * The new object will be added to the "tracked alloc" table unless 42 * flags is ALLOC_DONT_TRACK. 43 * 44 * Returns NULL and throws an exception on failure. 45 */ 46void* dvmMalloc(size_t size, int flags); 47 48/* 49 * Allocate a new object. 50 * 51 * The new object will be added to the "tracked alloc" table unless 52 * flags is ALLOC_DONT_TRACK. 53 * 54 * Returns NULL and throws an exception on failure. 55 */ 56Object* dvmAllocObject(ClassObject* clazz, int flags); 57 58/* flags for dvmMalloc */ 59enum { 60 ALLOC_DEFAULT = 0x00, 61 ALLOC_DONT_TRACK = 0x01, /* don't add to internal tracking list */ 62}; 63 64/* 65 * Track an object reference that is currently only visible internally. 66 * This is called automatically by dvmMalloc() unless ALLOC_DONT_TRACK 67 * is set. 68 * 69 * The "self" argument is allowed as an optimization; it may be NULL. 70 */ 71void dvmAddTrackedAlloc(Object* obj, Thread* self); 72 73/* 74 * Remove an object from the internal tracking list. 75 * 76 * Does nothing if "obj" is NULL. 77 * 78 * The "self" argument is allowed as an optimization; it may be NULL. 79 */ 80void dvmReleaseTrackedAlloc(Object* obj, Thread* self); 81 82/* 83 * Returns true iff <obj> points to a valid allocated object. 84 */ 85bool dvmIsValidObject(const Object* obj); 86 87/* 88 * Create a copy of an object. 89 * 90 * Returns NULL and throws an exception on failure. 91 */ 92Object* dvmCloneObject(Object* obj, int flags); 93 94/* 95 * Make the object finalizable. 96 */ 97void dvmSetFinalizable(Object* obj); 98 99/* 100 * Determine the exact number of GC heap bytes used by an object. (Internal 101 * to heap code except for debugging.) 102 */ 103size_t dvmObjectSizeInHeap(const Object* obj); 104 105/* 106 * Gets the current ideal heap utilization, represented as a number 107 * between zero and one. 108 */ 109float dvmGetTargetHeapUtilization(void); 110 111/* 112 * Sets the new ideal heap utilization, represented as a number 113 * between zero and one. 114 */ 115void dvmSetTargetHeapUtilization(float newTarget); 116 117/* 118 * Initiate garbage collection. 119 * 120 * This usually happens automatically, but can also be caused by 121 * Runtime.gc(). 122 */ 123void dvmCollectGarbage(void); 124 125/* 126 * Returns a count of the direct instances of a class. 127 */ 128size_t dvmCountInstancesOfClass(const ClassObject *clazz); 129 130/* 131 * Returns a count of the instances of a class and its subclasses. 132 */ 133size_t dvmCountAssignableInstancesOfClass(const ClassObject *clazz); 134 135/* 136 * Removes any growth limits from the heap. 137 */ 138void dvmClearGrowthLimit(void); 139 140/* 141 * Returns true if the address is within the bounds of the heap. 142 */ 143bool dvmIsHeapAddress(void *address); 144 145#endif /*_DALVIK_ALLOC_ALLOC*/ 146