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 * Internal heap functions 18 */ 19 #ifndef _DALVIK_ALLOC_HEAP 20 #define _DALVIK_ALLOC_HEAP 21 22 /* 23 * Initialize the GC heap. 24 * 25 * Returns true if successful, false otherwise. 26 */ 27 bool dvmHeapStartup(void); 28 29 /* 30 * Initialization that needs to wait until after leaving zygote mode. 31 * This needs to be called before the first allocation or GC that 32 * happens after forking. 33 */ 34 bool dvmHeapStartupAfterZygote(void); 35 36 /* 37 * Tear down the GC heap. 38 * 39 * Frees all memory allocated via dvmMalloc() as 40 * a side-effect. 41 */ 42 void dvmHeapShutdown(void); 43 44 /* 45 * Stops any threads internal to the garbage collector. Called before 46 * the heap itself is shutdown. 47 */ 48 void dvmHeapThreadShutdown(void); 49 50 #if 0 // needs to be in Alloc.h so debug code can find it. 51 /* 52 * Returns a number of bytes greater than or 53 * equal to the size of the named object in the heap. 54 * 55 * Specifically, it returns the size of the heap 56 * chunk which contains the object. 57 */ 58 size_t dvmObjectSizeInHeap(const Object *obj); 59 #endif 60 61 typedef enum { 62 /* GC all heaps. */ 63 GC_FULL, 64 /* GC just the first heap. */ 65 GC_PARTIAL 66 } GcMode; 67 68 typedef enum { 69 /* Not enough space for an "ordinary" Object to be allocated. */ 70 GC_FOR_MALLOC, 71 /* Automatic GC triggered by exceeding a heap occupancy threshold. */ 72 GC_CONCURRENT, 73 /* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */ 74 GC_EXPLICIT, 75 /* GC to try to reduce heap footprint to allow more non-GC'ed memory. */ 76 GC_EXTERNAL_ALLOC, 77 /* GC to dump heap contents to a file, only used under WITH_HPROF */ 78 GC_HPROF_DUMP_HEAP 79 } GcReason; 80 81 /* 82 * Run the garbage collector without doing any locking. 83 */ 84 void dvmCollectGarbageInternal(bool clearSoftRefs, GcReason reason); 85 86 /* 87 * Blocks the until the GC thread signals the completion of a 88 * concurrent GC. 89 */ 90 void dvmWaitForConcurrentGcToComplete(void); 91 92 #endif // _DALVIK_ALLOC_HEAP 93