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 collector 18 */ 19 #ifndef _DALVIK_ALLOC_GC 20 #define _DALVIK_ALLOC_GC 21 22 /* 23 * Initiate garbage collection. 24 * 25 * This usually happens automatically, but can also be caused by Runtime.gc(). 26 */ 27 void dvmCollectGarbage(bool collectSoftRefs); 28 29 /**** 30 **** NOTE: The functions after this point will (should) only be called 31 **** during GC. 32 ****/ 33 34 /* 35 * Functions that mark an object. 36 * 37 * Currently implemented in Heap.c. 38 */ 39 40 /* 41 * Mark an object and schedule it to be scanned for 42 * references to other objects. 43 * 44 * @param obj must be a valid object 45 */ 46 void dvmMarkObjectNonNull(const Object *obj); 47 48 /* 49 * Mark an object and schedule it to be scanned for 50 * references to other objects. 51 * 52 * @param obj must be a valid object or NULL 53 */ 54 #define dvmMarkObject(obj) \ 55 do { \ 56 Object *DMO_obj_ = (Object *)(obj); \ 57 if (DMO_obj_ != NULL) { \ 58 dvmMarkObjectNonNull(DMO_obj_); \ 59 } \ 60 } while (false) 61 62 /* 63 * If obj points to a valid object, mark it and 64 * schedule it to be scanned for references to other 65 * objects. 66 * 67 * @param obj any pointer that may be an Object, or NULL 68 TODO: check for alignment, too (would require knowledge of heap chunks) 69 */ 70 #define dvmMarkIfObject(obj) \ 71 do { \ 72 Object *DMIO_obj_ = (Object *)(obj); \ 73 if (DMIO_obj_ != NULL && dvmIsValidObject(DMIO_obj_)) { \ 74 dvmMarkObjectNonNull(DMIO_obj_); \ 75 } \ 76 } while (false) 77 78 /* 79 * Functions that handle scanning various objects for references. 80 */ 81 82 /* 83 * Mark all class objects loaded by the root class loader; 84 * most of these are the java.* classes. 85 * 86 * Currently implemented in Class.c. 87 */ 88 void dvmGcScanRootClassLoader(void); 89 90 /* 91 * Mark all root ThreadGroup objects, guaranteeing that 92 * all live Thread objects will eventually be scanned. 93 * 94 * NOTE: this is a misnomer, because the current implementation 95 * actually only scans the internal list of VM threads, which 96 * will mark all VM-reachable Thread objects. Someone else 97 * must scan the root class loader, which will mark java/lang/ThreadGroup. 98 * The ThreadGroup class object has static members pointing to 99 * the root ThreadGroups, and these will be marked as a side-effect 100 * of marking the class object. 101 * 102 * Currently implemented in Thread.c. 103 */ 104 void dvmGcScanRootThreadGroups(void); 105 106 /* 107 * Mark all interned string objects. 108 * 109 * Currently implemented in Intern.c. 110 */ 111 void dvmGcScanInternedStrings(void); 112 113 /* 114 * Remove any unmarked interned string objects from the table. 115 * 116 * Currently implemented in Intern.c. 117 */ 118 void dvmGcDetachDeadInternedStrings(int (*isUnmarkedObject)(void *)); 119 120 /* 121 * Mark all primitive class objects. 122 * 123 * Currently implemented in Array.c. 124 */ 125 void dvmGcScanPrimitiveClasses(void); 126 127 /* 128 * Mark all JNI global references. 129 * 130 * Currently implemented in JNI.c. 131 */ 132 void dvmGcMarkJniGlobalRefs(void); 133 134 /* 135 * Mark all debugger references. 136 * 137 * Currently implemented in Debugger.c. 138 */ 139 void dvmGcMarkDebuggerRefs(void); 140 141 /* 142 * Optional heap profiling. 143 */ 144 #if WITH_HPROF && !defined(_DALVIK_HPROF_HPROF) 145 #include "hprof/Hprof.h" 146 #define HPROF_SET_GC_SCAN_STATE(tag_, thread_) \ 147 dvmHeapSetHprofGcScanState((tag_), (thread_)) 148 #define HPROF_CLEAR_GC_SCAN_STATE() \ 149 dvmHeapSetHprofGcScanState(0, 0) 150 #else 151 #define HPROF_SET_GC_SCAN_STATE(tag_, thread_) do {} while (false) 152 #define HPROF_CLEAR_GC_SCAN_STATE() do {} while (false) 153 #endif 154 155 #endif // _DALVIK_ALLOC_GC 156