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  * Manage async heap tasks.
     18  */
     19 #ifndef _DALVIK_ALLOC_HEAP_WORKER
     20 #define _DALVIK_ALLOC_HEAP_WORKER
     21 
     22 /*
     23  * Initialize any HeapWorker state that Heap.c
     24  * cares about.  This lets the GC start before the
     25  * HeapWorker thread is initialized.
     26  */
     27 void dvmInitializeHeapWorkerState(void);
     28 
     29 /*
     30  * Initialization.  Starts/stops the worker thread.
     31  */
     32 bool dvmHeapWorkerStartup(void);
     33 void dvmHeapWorkerShutdown(void);
     34 
     35 /*
     36  * Tell the worker thread to wake up and do work.
     37  * If shouldLock is false, the caller must have already
     38  * acquired gDvm.heapWorkerLock.
     39  */
     40 void dvmSignalHeapWorker(bool shouldLock);
     41 
     42 /*
     43  * Block until all pending heap worker work has finished.
     44  */
     45 void dvmWaitForHeapWorkerIdle(void);
     46 
     47 /*
     48  * Does not return until any pending finalizers have been called.
     49  * This may or may not happen in the context of the calling thread.
     50  * No exceptions will escape.
     51  *
     52  * Used by zygote, which doesn't have a HeapWorker thread.
     53  */
     54 void dvmRunFinalizationSync(void);
     55 
     56 /*
     57  * Requests that dvmHeapSourceTrim() be called no sooner
     58  * than timeoutSec seconds from now.  If timeoutSec
     59  * is zero, any pending trim is cancelled.
     60  *
     61  * Caller must hold heapWorkerLock.
     62  */
     63 void dvmScheduleHeapSourceTrim(size_t timeoutSec);
     64 
     65 /* Make sure that the HeapWorker thread hasn't spent an inordinate
     66  * amount of time inside interpreted code.
     67  *
     68  * Aborts the VM if the thread appears to be wedged.
     69  *
     70  * The caller must hold the heapWorkerLock.
     71  */
     72 void dvmAssertHeapWorkerThreadRunning();
     73 
     74 /*
     75  * The type of operation for HeapWorker to perform on an object.
     76  */
     77 typedef enum HeapWorkerOperation {
     78     WORKER_FINALIZE = 0,
     79 
     80     /* Required: WORKER_ENQUEUE <= (4-1)
     81      * This value will be stuffed in the low bits of a pointer.
     82      */
     83     WORKER_ENQUEUE = (1<<0),
     84 } HeapWorkerOperation;
     85 
     86 /*
     87  * Called by the worker thread to get the next object
     88  * to finalize/enqueue/clear.  Implemented in Heap.c.
     89  *
     90  * @param op The operation to perform on the returned object.
     91  *           Must be non-NULL.
     92  * @return The object to operate on, or NULL.
     93  */
     94 Object *dvmGetNextHeapWorkerObject(HeapWorkerOperation *op);
     95 
     96 #endif /*_DALVIK_ALLOC_HEAP_WORKER*/
     97