| 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 | * 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 | */ |
| Carl Shapiro | ec805ea | 2010-06-28 16:28:26 -0700 | [diff] [blame^] | 34 | bool dvmHeapStartupAfterZygote(void); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | |
| Carl Shapiro | ec805ea | 2010-06-28 16:28:26 -0700 | [diff] [blame^] | 44 | /* |
| 45 | * Stops any threads internal to the garbage collector. Called before |
| 46 | * the heap itself is shutdown. |
| 47 | */ |
| 48 | void dvmHeapThreadShutdown(void); |
| 49 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | |
| Carl Shapiro | d25566d | 2010-03-11 20:39:47 -0800 | [diff] [blame] | 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 { |
| Barry Hayes | 1b9b4e4 | 2010-01-04 10:33:46 -0800 | [diff] [blame] | 69 | /* Not enough space for an "ordinary" Object to be allocated. */ |
| 70 | GC_FOR_MALLOC, |
| Carl Shapiro | ec805ea | 2010-06-28 16:28:26 -0700 | [diff] [blame^] | 71 | /* Automatic GC triggered by exceeding a heap occupancy threshold. */ |
| 72 | GC_CONCURRENT, |
| Barry Hayes | 1b9b4e4 | 2010-01-04 10:33:46 -0800 | [diff] [blame] | 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 |
| Carl Shapiro | d25566d | 2010-03-11 20:39:47 -0800 | [diff] [blame] | 79 | } GcReason; |
| Barry Hayes | 1b9b4e4 | 2010-01-04 10:33:46 -0800 | [diff] [blame] | 80 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 81 | /* |
| Barry Hayes | 962adba | 2010-03-17 12:12:39 -0700 | [diff] [blame] | 82 | * Suspend the VM as for a GC, and assert-fail if any object has any |
| 83 | * corrupt references. |
| 84 | */ |
| 85 | void dvmHeapSuspendAndVerify(); |
| 86 | |
| 87 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 88 | * Run the garbage collector without doing any locking. |
| 89 | */ |
| Carl Shapiro | 2954074 | 2010-03-26 15:34:39 -0700 | [diff] [blame] | 90 | void dvmCollectGarbageInternal(bool clearSoftRefs, GcReason reason); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 91 | |
| 92 | #endif // _DALVIK_ALLOC_HEAP |