Home | History | Annotate | Download | only in alloc
      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_H_
     20 #define DALVIK_ALLOC_HEAP_H_
     21 
     22 struct GcSpec {
     23   /* If true, only the application heap is threatened. */
     24   bool isPartial;
     25   /* If true, the trace is run concurrently with the mutator. */
     26   bool isConcurrent;
     27   /* Toggles for the soft reference clearing policy. */
     28   bool doPreserve;
     29   /* A name for this garbage collection mode. */
     30   const char *reason;
     31 };
     32 
     33 /* Not enough space for an "ordinary" Object to be allocated. */
     34 extern const GcSpec *GC_FOR_MALLOC;
     35 
     36 /* Automatic GC triggered by exceeding a heap occupancy threshold. */
     37 extern const GcSpec *GC_CONCURRENT;
     38 
     39 /* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
     40 extern const GcSpec *GC_EXPLICIT;
     41 
     42 /* Final attempt to reclaim memory before throwing an OOM. */
     43 extern const GcSpec *GC_BEFORE_OOM;
     44 
     45 /*
     46  * Initialize the GC heap.
     47  *
     48  * Returns true if successful, false otherwise.
     49  */
     50 bool dvmHeapStartup(void);
     51 
     52 /*
     53  * Initialization that needs to wait until after leaving zygote mode.
     54  * This needs to be called before the first allocation or GC that
     55  * happens after forking.
     56  */
     57 bool dvmHeapStartupAfterZygote(void);
     58 
     59 /*
     60  * Tear down the GC heap.
     61  *
     62  * Frees all memory allocated via dvmMalloc() as
     63  * a side-effect.
     64  */
     65 void dvmHeapShutdown(void);
     66 
     67 /*
     68  * Stops any threads internal to the garbage collector.  Called before
     69  * the heap itself is shutdown.
     70  */
     71 void dvmHeapThreadShutdown(void);
     72 
     73 #if 0       // needs to be in Alloc.h so debug code can find it.
     74 /*
     75  * Returns a number of bytes greater than or
     76  * equal to the size of the named object in the heap.
     77  *
     78  * Specifically, it returns the size of the heap
     79  * chunk which contains the object.
     80  */
     81 size_t dvmObjectSizeInHeap(const Object *obj);
     82 #endif
     83 
     84 /*
     85  * Run the garbage collector without doing any locking.
     86  */
     87 void dvmCollectGarbageInternal(const GcSpec *spec);
     88 
     89 /*
     90  * Blocks the calling thread until the garbage collector is inactive.
     91  * The caller must hold the heap lock as this call releases and
     92  * re-acquires the heap lock.  After returning, no garbage collection
     93  * will be in progress and the heap lock will be held by the caller.
     94  */
     95 bool dvmWaitForConcurrentGcToComplete(void);
     96 
     97 /*
     98  * Returns true iff <obj> points to a valid allocated object.
     99  */
    100 bool dvmIsValidObject(const Object* obj);
    101 
    102 #endif  // DALVIK_ALLOC_HEAP_H_
    103