| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | |
| Carl Shapiro | ad9400f | 2010-05-01 20:08:57 -0700 | [diff] [blame] | 22 | #include <stddef.h> |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Initialization. |
| 26 | */ |
| 27 | bool dvmGcStartup(void); |
| Andy McFadden | 7fc3ce8 | 2009-07-14 15:57:23 -0700 | [diff] [blame] | 28 | bool dvmCreateStockExceptions(void); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 29 | bool dvmGcStartupAfterZygote(void); |
| 30 | void dvmGcShutdown(void); |
| Carl Shapiro | ec805ea | 2010-06-28 16:28:26 -0700 | [diff] [blame] | 31 | void dvmGcThreadShutdown(void); |
| Carl Shapiro | ce87bfe | 2011-03-30 19:35:34 -0700 | [diff] [blame] | 32 | bool dvmGcStartupClasses(void); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * Do any last-minute preparation before we call fork() for the first time. |
| 36 | */ |
| 37 | bool dvmGcPreZygoteFork(void); |
| 38 | |
| 39 | /* |
| 40 | * Basic allocation function. |
| 41 | * |
| 42 | * The new object will be added to the "tracked alloc" table unless |
| Barry Hayes | d4f78d3 | 2010-06-08 09:34:42 -0700 | [diff] [blame] | 43 | * flags is ALLOC_DONT_TRACK. |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 44 | * |
| 45 | * Returns NULL and throws an exception on failure. |
| 46 | */ |
| 47 | void* 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 Hayes | d4f78d3 | 2010-06-08 09:34:42 -0700 | [diff] [blame] | 53 | * flags is ALLOC_DONT_TRACK. |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 54 | * |
| 55 | * Returns NULL and throws an exception on failure. |
| 56 | */ |
| 57 | Object* dvmAllocObject(ClassObject* clazz, int flags); |
| 58 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 59 | /* flags for dvmMalloc */ |
| 60 | enum { |
| 61 | ALLOC_DEFAULT = 0x00, |
| Barry Hayes | d4f78d3 | 2010-06-08 09:34:42 -0700 | [diff] [blame] | 62 | ALLOC_DONT_TRACK = 0x01, /* don't add to internal tracking list */ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 66 | * 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 | */ |
| 72 | void 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 | */ |
| 81 | void dvmReleaseTrackedAlloc(Object* obj, Thread* self); |
| 82 | |
| 83 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 84 | * Returns true iff <obj> points to a valid allocated object. |
| 85 | */ |
| 86 | bool dvmIsValidObject(const Object* obj); |
| 87 | |
| 88 | /* |
| 89 | * Create a copy of an object. |
| 90 | * |
| Andy McFadden | 0f27ad7 | 2011-02-22 13:56:47 -0800 | [diff] [blame] | 91 | * Returns NULL and throws an exception on failure. |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 92 | */ |
| Andy McFadden | 0f27ad7 | 2011-02-22 13:56:47 -0800 | [diff] [blame] | 93 | Object* dvmCloneObject(Object* obj, int flags); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 94 | |
| 95 | /* |
| Andy McFadden | 6af2ddd | 2011-02-16 16:50:40 -0800 | [diff] [blame] | 96 | * Make the object finalizable. |
| 97 | */ |
| 98 | void dvmSetFinalizable(Object* obj); |
| 99 | |
| 100 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 101 | * Determine the exact number of GC heap bytes used by an object. (Internal |
| 102 | * to heap code except for debugging.) |
| 103 | */ |
| 104 | size_t dvmObjectSizeInHeap(const Object* obj); |
| 105 | |
| 106 | /* |
| 107 | * Gets the current ideal heap utilization, represented as a number |
| 108 | * between zero and one. |
| 109 | */ |
| 110 | float dvmGetTargetHeapUtilization(void); |
| 111 | |
| 112 | /* |
| 113 | * Sets the new ideal heap utilization, represented as a number |
| 114 | * between zero and one. |
| 115 | */ |
| 116 | void dvmSetTargetHeapUtilization(float newTarget); |
| 117 | |
| 118 | /* |
| Carl Shapiro | 0445e48 | 2010-12-02 17:27:01 -0800 | [diff] [blame] | 119 | * Initiate garbage collection. |
| 120 | * |
| Carl Shapiro | a371fad | 2011-01-23 15:58:31 -0800 | [diff] [blame] | 121 | * This usually happens automatically, but can also be caused by |
| Carl Shapiro | bc3ba01 | 2011-02-09 14:20:14 -0800 | [diff] [blame] | 122 | * Runtime.gc(). |
| Carl Shapiro | 0445e48 | 2010-12-02 17:27:01 -0800 | [diff] [blame] | 123 | */ |
| Carl Shapiro | bc3ba01 | 2011-02-09 14:20:14 -0800 | [diff] [blame] | 124 | void dvmCollectGarbage(void); |
| Carl Shapiro | 0445e48 | 2010-12-02 17:27:01 -0800 | [diff] [blame] | 125 | |
| 126 | /* |
| Carl Shapiro | f331a60 | 2010-11-04 15:12:09 -0700 | [diff] [blame] | 127 | * Returns a count of the direct instances of a class. |
| Carl Shapiro | 41eb6e9 | 2010-08-17 13:30:48 -0700 | [diff] [blame] | 128 | */ |
| 129 | size_t dvmCountInstancesOfClass(const ClassObject *clazz); |
| 130 | |
| Carl Shapiro | f331a60 | 2010-11-04 15:12:09 -0700 | [diff] [blame] | 131 | /* |
| 132 | * Returns a count of the instances of a class and its subclasses. |
| 133 | */ |
| 134 | size_t dvmCountAssignableInstancesOfClass(const ClassObject *clazz); |
| 135 | |
| Carl Shapiro | df9f08b | 2011-01-18 17:59:30 -0800 | [diff] [blame] | 136 | /* |
| 137 | * Removes any growth limits from the heap. |
| 138 | */ |
| 139 | void dvmClearGrowthLimit(void); |
| 140 | |
| Carl Shapiro | 2494c50 | 2011-03-11 17:54:58 -0800 | [diff] [blame] | 141 | /* |
| 142 | * Returns true if the address is within the bounds of the heap. |
| 143 | */ |
| 144 | bool dvmIsHeapAddress(void *address); |
| 145 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 146 | #endif /*_DALVIK_ALLOC_ALLOC*/ |