blob: a3279d8b85282238f5dcf5f41b46996f2674f706 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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#include "Dalvik.h"
Barry Hayeseac47ed2009-06-22 11:45:20 -070018#include "alloc/clz.h"
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080019#include "alloc/HeapBitmap.h"
20#include "alloc/HeapInternal.h"
21#include "alloc/HeapSource.h"
22#include "alloc/MarkSweep.h"
23#include <limits.h> // for ULONG_MAX
24#include <sys/mman.h> // for madvise(), mmap()
25#include <cutils/ashmem.h>
The Android Open Source Project99409882009-03-18 22:20:24 -070026#include <errno.h>
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080027
28#define GC_DEBUG_PARANOID 2
29#define GC_DEBUG_BASIC 1
30#define GC_DEBUG_OFF 0
31#define GC_DEBUG(l) (GC_DEBUG_LEVEL >= (l))
32
33#if 1
34#define GC_DEBUG_LEVEL GC_DEBUG_PARANOID
35#else
36#define GC_DEBUG_LEVEL GC_DEBUG_OFF
37#endif
38
39#define VERBOSE_GC 0
40
41#define GC_LOG_TAG LOG_TAG "-gc"
42
43#if LOG_NDEBUG
44#define LOGV_GC(...) ((void)0)
45#define LOGD_GC(...) ((void)0)
46#else
47#define LOGV_GC(...) LOG(LOG_VERBOSE, GC_LOG_TAG, __VA_ARGS__)
48#define LOGD_GC(...) LOG(LOG_DEBUG, GC_LOG_TAG, __VA_ARGS__)
49#endif
50
51#if VERBOSE_GC
52#define LOGVV_GC(...) LOGV_GC(__VA_ARGS__)
53#else
54#define LOGVV_GC(...) ((void)0)
55#endif
56
57#define LOGI_GC(...) LOG(LOG_INFO, GC_LOG_TAG, __VA_ARGS__)
58#define LOGW_GC(...) LOG(LOG_WARN, GC_LOG_TAG, __VA_ARGS__)
59#define LOGE_GC(...) LOG(LOG_ERROR, GC_LOG_TAG, __VA_ARGS__)
60
61#define LOG_SCAN(...) LOGV_GC("SCAN: " __VA_ARGS__)
62#define LOG_MARK(...) LOGV_GC("MARK: " __VA_ARGS__)
63#define LOG_SWEEP(...) LOGV_GC("SWEEP: " __VA_ARGS__)
64#define LOG_REF(...) LOGV_GC("REF: " __VA_ARGS__)
65
66#define LOGV_SCAN(...) LOGVV_GC("SCAN: " __VA_ARGS__)
67#define LOGV_MARK(...) LOGVV_GC("MARK: " __VA_ARGS__)
68#define LOGV_SWEEP(...) LOGVV_GC("SWEEP: " __VA_ARGS__)
69#define LOGV_REF(...) LOGVV_GC("REF: " __VA_ARGS__)
70
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080071#define ALIGN_UP_TO_PAGE_SIZE(p) \
Andy McFadden96516932009-10-28 17:39:02 -070072 (((size_t)(p) + (SYSTEM_PAGE_SIZE - 1)) & ~(SYSTEM_PAGE_SIZE - 1))
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080073
74/* Do not cast the result of this to a boolean; the only set bit
75 * may be > 1<<8.
76 */
77static inline long isMarked(const DvmHeapChunk *hc, const GcMarkContext *ctx)
78 __attribute__((always_inline));
79static inline long isMarked(const DvmHeapChunk *hc, const GcMarkContext *ctx)
80{
81 return dvmHeapBitmapIsObjectBitSetInList(ctx->bitmaps, ctx->numBitmaps, hc);
82}
83
84static bool
85createMarkStack(GcMarkStack *stack)
86{
87 const Object **limit;
88 size_t size;
The Android Open Source Project99409882009-03-18 22:20:24 -070089 int fd, err;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080090
91 /* Create a stack big enough for the worst possible case,
92 * where the heap is perfectly full of the smallest object.
93 * TODO: be better about memory usage; use a smaller stack with
94 * overflow detection and recovery.
95 */
96 size = dvmHeapSourceGetIdealFootprint() * sizeof(Object*) /
97 (sizeof(Object) + HEAP_SOURCE_CHUNK_OVERHEAD);
98 size = ALIGN_UP_TO_PAGE_SIZE(size);
99 fd = ashmem_create_region("dalvik-heap-markstack", size);
100 if (fd < 0) {
The Android Open Source Project99409882009-03-18 22:20:24 -0700101 LOGE_GC("Could not create %d-byte ashmem mark stack: %s\n",
102 size, strerror(errno));
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800103 return false;
104 }
105 limit = (const Object **)mmap(NULL, size, PROT_READ | PROT_WRITE,
106 MAP_PRIVATE, fd, 0);
The Android Open Source Project99409882009-03-18 22:20:24 -0700107 err = errno;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800108 close(fd);
109 if (limit == MAP_FAILED) {
The Android Open Source Project99409882009-03-18 22:20:24 -0700110 LOGE_GC("Could not mmap %d-byte ashmem mark stack: %s\n",
111 size, strerror(err));
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800112 return false;
113 }
114
115 memset(stack, 0, sizeof(*stack));
116 stack->limit = limit;
117 stack->base = (const Object **)((uintptr_t)limit + size);
118 stack->top = stack->base;
119
120 return true;
121}
122
123static void
124destroyMarkStack(GcMarkStack *stack)
125{
126 munmap((char *)stack->limit,
127 (uintptr_t)stack->base - (uintptr_t)stack->limit);
128 memset(stack, 0, sizeof(*stack));
129}
130
131#define MARK_STACK_PUSH(stack, obj) \
132 do { \
133 *--(stack).top = (obj); \
134 } while (false)
135
136bool
137dvmHeapBeginMarkStep()
138{
139 GcMarkContext *mc = &gDvm.gcHeap->markContext;
140 HeapBitmap objectBitmaps[HEAP_SOURCE_MAX_HEAP_COUNT];
141 size_t numBitmaps;
142
143 if (!createMarkStack(&mc->stack)) {
144 return false;
145 }
146
147 numBitmaps = dvmHeapSourceGetObjectBitmaps(objectBitmaps,
148 HEAP_SOURCE_MAX_HEAP_COUNT);
149 if (numBitmaps <= 0) {
150 return false;
151 }
152
153 /* Create mark bitmaps that cover the same ranges as the
154 * current object bitmaps.
155 */
156 if (!dvmHeapBitmapInitListFromTemplates(mc->bitmaps, objectBitmaps,
157 numBitmaps, "mark"))
158 {
159 return false;
160 }
161
162 mc->numBitmaps = numBitmaps;
163 mc->finger = NULL;
164
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800165 return true;
166}
167
168static long setAndReturnMarkBit(GcMarkContext *ctx, const DvmHeapChunk *hc)
169 __attribute__((always_inline));
170static long
171setAndReturnMarkBit(GcMarkContext *ctx, const DvmHeapChunk *hc)
172{
173 return dvmHeapBitmapSetAndReturnObjectBitInList(ctx->bitmaps,
174 ctx->numBitmaps, hc);
175}
176
177static void _markObjectNonNullCommon(const Object *obj, GcMarkContext *ctx,
178 bool checkFinger, bool forceStack)
179 __attribute__((always_inline));
180static void
181_markObjectNonNullCommon(const Object *obj, GcMarkContext *ctx,
182 bool checkFinger, bool forceStack)
183{
184 DvmHeapChunk *hc;
185
186 assert(obj != NULL);
187
188#if GC_DEBUG(GC_DEBUG_PARANOID)
189//TODO: make sure we're locked
190 assert(obj != (Object *)gDvm.unlinkedJavaLangClass);
191 assert(dvmIsValidObject(obj));
192#endif
193
194 hc = ptr2chunk(obj);
195 if (!setAndReturnMarkBit(ctx, hc)) {
196 /* This object was not previously marked.
197 */
198 if (forceStack || (checkFinger && (void *)hc < ctx->finger)) {
199 /* This object will need to go on the mark stack.
200 */
201 MARK_STACK_PUSH(ctx->stack, obj);
202 }
203
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800204#if WITH_HPROF
205 if (gDvm.gcHeap->hprofContext != NULL) {
206 hprofMarkRootObject(gDvm.gcHeap->hprofContext, obj, 0);
207 }
208#endif
209#if DVM_TRACK_HEAP_MARKING
210 gDvm.gcHeap->markCount++;
211 gDvm.gcHeap->markSize += dvmHeapSourceChunkSize((void *)hc) +
212 HEAP_SOURCE_CHUNK_OVERHEAD;
213#endif
214
215 /* obj->clazz can be NULL if we catch an object between
216 * dvmMalloc() and DVM_OBJECT_INIT(). This is ok.
217 */
218 LOGV_MARK("0x%08x %s\n", (uint)obj,
219 obj->clazz == NULL ? "<null class>" : obj->clazz->name);
220 }
221}
222
223/* Used to mark objects when recursing. Recursion is done by moving
224 * the finger across the bitmaps in address order and marking child
225 * objects. Any newly-marked objects whose addresses are lower than
226 * the finger won't be visited by the bitmap scan, so those objects
227 * need to be added to the mark stack.
228 */
229static void
230markObjectNonNull(const Object *obj, GcMarkContext *ctx)
231{
232 _markObjectNonNullCommon(obj, ctx, true, false);
233}
234
235#define markObject(obj, ctx) \
236 do { \
237 Object *MO_obj_ = (Object *)(obj); \
238 if (MO_obj_ != NULL) { \
239 markObjectNonNull(MO_obj_, (ctx)); \
240 } \
241 } while (false)
242
243/* If the object hasn't already been marked, mark it and
244 * schedule it to be scanned for references.
245 *
246 * obj may not be NULL. The macro dvmMarkObject() should
247 * be used in situations where a reference may be NULL.
248 *
249 * This function may only be called when marking the root
250 * set. When recursing, use the internal markObject[NonNull]().
251 */
252void
253dvmMarkObjectNonNull(const Object *obj)
254{
255 _markObjectNonNullCommon(obj, &gDvm.gcHeap->markContext, false, false);
256}
257
258/* Mark the set of root objects.
259 *
260 * Things we need to scan:
261 * - System classes defined by root classloader
262 * - For each thread:
263 * - Interpreted stack, from top to "curFrame"
264 * - Dalvik registers (args + local vars)
265 * - JNI local references
266 * - Automatic VM local references (TrackedAlloc)
267 * - Associated Thread/VMThread object
268 * - ThreadGroups (could track & start with these instead of working
269 * upward from Threads)
270 * - Exception currently being thrown, if present
271 * - JNI global references
272 * - Interned string table
273 * - Primitive classes
274 * - Special objects
275 * - gDvm.outOfMemoryObj
276 * - Objects allocated with ALLOC_NO_GC
277 * - Objects pending finalization (but not yet finalized)
278 * - Objects in debugger object registry
279 *
280 * Don't need:
281 * - Native stack (for in-progress stuff in the VM)
282 * - The TrackedAlloc stuff watches all native VM references.
283 */
284void dvmHeapMarkRootSet()
285{
286 HeapRefTable *refs;
287 GcHeap *gcHeap;
288 Object **op;
289
290 gcHeap = gDvm.gcHeap;
291
292 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_STICKY_CLASS, 0);
293
294 LOG_SCAN("root class loader\n");
295 dvmGcScanRootClassLoader();
296 LOG_SCAN("primitive classes\n");
297 dvmGcScanPrimitiveClasses();
298
299 /* dvmGcScanRootThreadGroups() sets a bunch of
300 * different scan states internally.
301 */
302 HPROF_CLEAR_GC_SCAN_STATE();
303
304 LOG_SCAN("root thread groups\n");
305 dvmGcScanRootThreadGroups();
306
307 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_INTERNED_STRING, 0);
308
309 LOG_SCAN("interned strings\n");
310 dvmGcScanInternedStrings();
311
312 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_JNI_GLOBAL, 0);
313
314 LOG_SCAN("JNI global refs\n");
315 dvmGcMarkJniGlobalRefs();
316
317 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_REFERENCE_CLEANUP, 0);
318
319 LOG_SCAN("pending reference operations\n");
320 dvmHeapMarkLargeTableRefs(gcHeap->referenceOperations, true);
321
322 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_FINALIZING, 0);
323
324 LOG_SCAN("pending finalizations\n");
325 dvmHeapMarkLargeTableRefs(gcHeap->pendingFinalizationRefs, false);
326
327 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_DEBUGGER, 0);
328
329 LOG_SCAN("debugger refs\n");
330 dvmGcMarkDebuggerRefs();
331
332 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_VM_INTERNAL, 0);
333
334 /* Mark all ALLOC_NO_GC objects.
335 */
336 LOG_SCAN("ALLOC_NO_GC objects\n");
337 refs = &gcHeap->nonCollectableRefs;
338 op = refs->table;
339 while ((uintptr_t)op < (uintptr_t)refs->nextEntry) {
340 dvmMarkObjectNonNull(*(op++));
341 }
342
343 /* Mark any special objects we have sitting around.
344 */
345 LOG_SCAN("special objects\n");
346 dvmMarkObjectNonNull(gDvm.outOfMemoryObj);
347 dvmMarkObjectNonNull(gDvm.internalErrorObj);
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700348 dvmMarkObjectNonNull(gDvm.noClassDefFoundErrorObj);
Andy McFaddenb18992f2009-09-25 10:42:15 -0700349 dvmMarkObject(gDvm.jniWeakGlobalRefQueue);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800350//TODO: scan object references sitting in gDvm; use pointer begin & end
351
352 HPROF_CLEAR_GC_SCAN_STATE();
353}
354
355/*
356 * Nothing past this point is allowed to use dvmMarkObject*().
357 * Scanning/recursion must use markObject*(), which takes the
358 * finger into account.
359 */
360#define dvmMarkObjectNonNull __dont_use_dvmMarkObjectNonNull__
361
362
363/* Mark all of a ClassObject's interfaces.
364 */
365static void markInterfaces(const ClassObject *clazz, GcMarkContext *ctx)
366{
367 ClassObject **interfaces;
368 int interfaceCount;
369 int i;
370
371 /* Mark all interfaces.
372 */
373 interfaces = clazz->interfaces;
374 interfaceCount = clazz->interfaceCount;
375 for (i = 0; i < interfaceCount; i++) {
376 markObjectNonNull((Object *)*interfaces, ctx);
377 interfaces++;
378 }
379}
380
381/* Mark all objects referred to by a ClassObject's static fields.
382 */
383static void scanStaticFields(const ClassObject *clazz, GcMarkContext *ctx)
384{
385 StaticField *f;
386 int i;
387
388 //TODO: Optimize this with a bit vector or something
389 f = clazz->sfields;
390 for (i = 0; i < clazz->sfieldCount; i++) {
391 char c = f->field.signature[0];
392 if (c == '[' || c == 'L') {
393 /* It's an array or class reference.
394 */
395 markObject((Object *)f->value.l, ctx);
396 }
397 f++;
398 }
399}
400
401/* Mark all objects referred to by a DataObject's instance fields.
402 */
403static void scanInstanceFields(const DataObject *obj, ClassObject *clazz,
404 GcMarkContext *ctx)
405{
Barry Hayesd1497482009-10-28 15:32:19 -0700406 if (clazz->refOffsets != CLASS_WALK_SUPER) {
Barry Hayeseac47ed2009-06-22 11:45:20 -0700407 unsigned int refOffsets = clazz->refOffsets;
408 while (refOffsets != 0) {
409 const int rshift = CLZ(refOffsets);
410 refOffsets &= ~(CLASS_HIGH_BIT >> rshift);
411 markObject(dvmGetFieldObject((Object*)obj,
412 CLASS_OFFSET_FROM_CLZ(rshift)), ctx);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800413 }
Barry Hayeseac47ed2009-06-22 11:45:20 -0700414 } else {
415 while (clazz != NULL) {
416 InstField *f;
417 int i;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800418
Barry Hayeseac47ed2009-06-22 11:45:20 -0700419 /* All of the fields that contain object references
420 * are guaranteed to be at the beginning of the ifields list.
421 */
422 f = clazz->ifields;
423 for (i = 0; i < clazz->ifieldRefCount; i++) {
424 /* Mark the array or object reference.
425 * May be NULL.
426 *
427 * Note that, per the comment on struct InstField,
428 * f->byteOffset is the offset from the beginning of
429 * obj, not the offset into obj->instanceData.
430 */
431 markObject(dvmGetFieldObject((Object*)obj, f->byteOffset), ctx);
432 f++;
433 }
434
435 /* This will be NULL when we hit java.lang.Object
436 */
437 clazz = clazz->super;
438 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800439 }
440}
441
442/* Mark all objects referred to by the array's contents.
443 */
444static void scanObjectArray(const ArrayObject *array, GcMarkContext *ctx)
445{
446 Object **contents;
447 u4 length;
448 u4 i;
449
450 contents = (Object **)array->contents;
451 length = array->length;
452
453 for (i = 0; i < length; i++) {
454 markObject(*contents, ctx); // may be NULL
455 contents++;
456 }
457}
458
459/* Mark all objects referred to by the ClassObject.
460 */
461static void scanClassObject(const ClassObject *clazz, GcMarkContext *ctx)
462{
463 LOGV_SCAN("---------> %s\n", clazz->name);
464
465 if (IS_CLASS_FLAG_SET(clazz, CLASS_ISARRAY)) {
466 /* We're an array; mark the class object of the contents
467 * of the array.
468 *
469 * Note that we won't necessarily reach the array's element
470 * class by scanning the array contents; the array may be
471 * zero-length, or may only contain null objects.
472 */
473 markObjectNonNull((Object *)clazz->elementClass, ctx);
474 }
475
476 /* We scan these explicitly in case the only remaining
477 * reference to a particular class object is via a data
478 * object; we may not be guaranteed to reach all
479 * live class objects via a classloader.
480 */
481 markObject((Object *)clazz->super, ctx); // may be NULL (java.lang.Object)
482 markObject(clazz->classLoader, ctx); // may be NULL
483
484 scanStaticFields(clazz, ctx);
485 markInterfaces(clazz, ctx);
486}
487
488/* Mark all objects that obj refers to.
489 *
490 * Called on every object in markList.
491 */
492static void scanObject(const Object *obj, GcMarkContext *ctx)
493{
494 ClassObject *clazz;
495
496 assert(dvmIsValidObject(obj));
497 LOGV_SCAN("0x%08x %s\n", (uint)obj, obj->clazz->name);
498
499#if WITH_HPROF
500 if (gDvm.gcHeap->hprofContext != NULL) {
501 hprofDumpHeapObject(gDvm.gcHeap->hprofContext, obj);
502 }
503#endif
504
505 /* Get and mark the class object for this particular instance.
506 */
507 clazz = obj->clazz;
508 if (clazz == NULL) {
509 /* This can happen if we catch an object between
510 * dvmMalloc() and DVM_OBJECT_INIT(). The object
511 * won't contain any references yet, so we can
512 * just skip it.
513 */
514 return;
515 } else if (clazz == gDvm.unlinkedJavaLangClass) {
516 /* This class hasn't been linked yet. We're guaranteed
517 * that the object doesn't contain any references that
518 * aren't already tracked, so we can skip scanning it.
519 *
520 * NOTE: unlinkedJavaLangClass is not on the heap, so
521 * it's very important that we don't try marking it.
522 */
523 return;
524 }
Barry Hayes3592d622009-03-16 16:10:35 -0700525
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800526 assert(dvmIsValidObject((Object *)clazz));
527 markObjectNonNull((Object *)clazz, ctx);
528
529 /* Mark any references in this object.
530 */
531 if (IS_CLASS_FLAG_SET(clazz, CLASS_ISARRAY)) {
532 /* It's an array object.
533 */
534 if (IS_CLASS_FLAG_SET(clazz, CLASS_ISOBJECTARRAY)) {
535 /* It's an array of object references.
536 */
537 scanObjectArray((ArrayObject *)obj, ctx);
538 }
539 // else there's nothing else to scan
540 } else {
541 /* It's a DataObject-compatible object.
542 */
543 scanInstanceFields((DataObject *)obj, clazz, ctx);
544
545 if (IS_CLASS_FLAG_SET(clazz, CLASS_ISREFERENCE)) {
546 GcHeap *gcHeap = gDvm.gcHeap;
547 Object *referent;
548
549 /* It's a subclass of java/lang/ref/Reference.
550 * The fields in this class have been arranged
551 * such that scanInstanceFields() did not actually
552 * mark the "referent" field; we need to handle
553 * it specially.
554 *
555 * If the referent already has a strong mark (isMarked(referent)),
556 * we don't care about its reference status.
557 */
558 referent = dvmGetFieldObject(obj,
559 gDvm.offJavaLangRefReference_referent);
560 if (referent != NULL &&
561 !isMarked(ptr2chunk(referent), &gcHeap->markContext))
562 {
563 u4 refFlags;
564
565 if (gcHeap->markAllReferents) {
566 LOG_REF("Hard-marking a reference\n");
567
568 /* Don't bother with normal reference-following
569 * behavior, just mark the referent. This should
570 * only be used when following objects that just
571 * became scheduled for finalization.
572 */
573 markObjectNonNull(referent, ctx);
574 goto skip_reference;
575 }
576
577 /* See if this reference was handled by a previous GC.
578 */
579 if (dvmGetFieldObject(obj,
580 gDvm.offJavaLangRefReference_vmData) ==
581 SCHEDULED_REFERENCE_MAGIC)
582 {
583 LOG_REF("Skipping scheduled reference\n");
584
585 /* Don't reschedule it, but make sure that its
586 * referent doesn't get collected (in case it's
587 * a PhantomReference and wasn't cleared automatically).
588 */
589 //TODO: Mark these after handling all new refs of
590 // this strength, in case the new refs refer
591 // to the same referent. Not a very common
592 // case, though.
593 markObjectNonNull(referent, ctx);
594 goto skip_reference;
595 }
596
597 /* Find out what kind of reference is pointing
598 * to referent.
599 */
600 refFlags = GET_CLASS_FLAG_GROUP(clazz,
601 CLASS_ISREFERENCE |
602 CLASS_ISWEAKREFERENCE |
603 CLASS_ISPHANTOMREFERENCE);
604
605 /* We use the vmData field of Reference objects
606 * as a next pointer in a singly-linked list.
607 * That way, we don't need to allocate any memory
608 * while we're doing a GC.
609 */
610#define ADD_REF_TO_LIST(list, ref) \
611 do { \
612 Object *ARTL_ref_ = (/*de-const*/Object *)(ref); \
613 dvmSetFieldObject(ARTL_ref_, \
614 gDvm.offJavaLangRefReference_vmData, list); \
615 list = ARTL_ref_; \
616 } while (false)
617
618 /* At this stage, we just keep track of all of
619 * the live references that we've seen. Later,
620 * we'll walk through each of these lists and
621 * deal with the referents.
622 */
623 if (refFlags == CLASS_ISREFERENCE) {
624 /* It's a soft reference. Depending on the state,
625 * we'll attempt to collect all of them, some of
626 * them, or none of them.
627 */
628 if (gcHeap->softReferenceCollectionState ==
629 SR_COLLECT_NONE)
630 {
631 sr_collect_none:
632 markObjectNonNull(referent, ctx);
633 } else if (gcHeap->softReferenceCollectionState ==
634 SR_COLLECT_ALL)
635 {
636 sr_collect_all:
637 ADD_REF_TO_LIST(gcHeap->softReferences, obj);
638 } else {
639 /* We'll only try to collect half of the
640 * referents.
641 */
642 if (gcHeap->softReferenceColor++ & 1) {
643 goto sr_collect_none;
644 }
645 goto sr_collect_all;
646 }
647 } else {
648 /* It's a weak or phantom reference.
649 * Clearing CLASS_ISREFERENCE will reveal which.
650 */
651 refFlags &= ~CLASS_ISREFERENCE;
652 if (refFlags == CLASS_ISWEAKREFERENCE) {
653 ADD_REF_TO_LIST(gcHeap->weakReferences, obj);
654 } else if (refFlags == CLASS_ISPHANTOMREFERENCE) {
655 ADD_REF_TO_LIST(gcHeap->phantomReferences, obj);
656 } else {
657 assert(!"Unknown reference type");
658 }
659 }
660#undef ADD_REF_TO_LIST
661 }
662 }
663
664 skip_reference:
665 /* If this is a class object, mark various other things that
666 * its internals point to.
667 *
668 * All class objects are instances of java.lang.Class,
669 * including the java.lang.Class class object.
670 */
671 if (clazz == gDvm.classJavaLangClass) {
672 scanClassObject((ClassObject *)obj, ctx);
673 }
674 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800675}
676
677static void
678processMarkStack(GcMarkContext *ctx)
679{
680 const Object **const base = ctx->stack.base;
681
682 /* Scan anything that's on the mark stack.
683 * We can't use the bitmaps anymore, so use
684 * a finger that points past the end of them.
685 */
686 ctx->finger = (void *)ULONG_MAX;
687 while (ctx->stack.top != base) {
688 scanObject(*ctx->stack.top++, ctx);
689 }
690}
691
692#ifndef NDEBUG
693static uintptr_t gLastFinger = 0;
694#endif
695
696static bool
697scanBitmapCallback(size_t numPtrs, void **ptrs, const void *finger, void *arg)
698{
699 GcMarkContext *ctx = (GcMarkContext *)arg;
700 size_t i;
701
702#ifndef NDEBUG
703 assert((uintptr_t)finger >= gLastFinger);
704 gLastFinger = (uintptr_t)finger;
705#endif
706
707 ctx->finger = finger;
708 for (i = 0; i < numPtrs; i++) {
709 /* The pointers we're getting back are DvmHeapChunks,
710 * not Objects.
711 */
712 scanObject(chunk2ptr(*ptrs++), ctx);
713 }
714
715 return true;
716}
717
718/* Given bitmaps with the root set marked, find and mark all
719 * reachable objects. When this returns, the entire set of
720 * live objects will be marked and the mark stack will be empty.
721 */
722void dvmHeapScanMarkedObjects()
723{
724 GcMarkContext *ctx = &gDvm.gcHeap->markContext;
725
726 assert(ctx->finger == NULL);
727
728 /* The bitmaps currently have bits set for the root set.
729 * Walk across the bitmaps and scan each object.
730 */
731#ifndef NDEBUG
732 gLastFinger = 0;
733#endif
734 dvmHeapBitmapWalkList(ctx->bitmaps, ctx->numBitmaps,
735 scanBitmapCallback, ctx);
736
737 /* We've walked the mark bitmaps. Scan anything that's
738 * left on the mark stack.
739 */
740 processMarkStack(ctx);
741
742 LOG_SCAN("done with marked objects\n");
743}
744
745/** @return true if we need to schedule a call to clear().
746 */
747static bool clearReference(Object *reference)
748{
749 /* This is what the default implementation of Reference.clear()
750 * does. We're required to clear all references to a given
751 * referent atomically, so we can't pop in and out of interp
752 * code each time.
753 *
754 * Also, someone may have subclassed one of the basic Reference
755 * types, overriding clear(). We can't trust the clear()
756 * implementation to call super.clear(); we cannot let clear()
757 * resurrect the referent. If we clear it here, we can safely
758 * call any overriding implementations.
759 */
760 dvmSetFieldObject(reference,
761 gDvm.offJavaLangRefReference_referent, NULL);
762
763#if FANCY_REFERENCE_SUBCLASS
764 /* See if clear() has actually been overridden. If so,
765 * we need to schedule a call to it before calling enqueue().
766 */
767 if (reference->clazz->vtable[gDvm.voffJavaLangRefReference_clear]->clazz !=
768 gDvm.classJavaLangRefReference)
769 {
770 /* clear() has been overridden; return true to indicate
771 * that we need to schedule a call to the real clear()
772 * implementation.
773 */
774 return true;
775 }
776#endif
777
778 return false;
779}
780
781/** @return true if we need to schedule a call to enqueue().
782 */
783static bool enqueueReference(Object *reference)
784{
785#if FANCY_REFERENCE_SUBCLASS
786 /* See if this reference class has overridden enqueue();
787 * if not, we can take a shortcut.
788 */
789 if (reference->clazz->vtable[gDvm.voffJavaLangRefReference_enqueue]->clazz
790 == gDvm.classJavaLangRefReference)
791#endif
792 {
793 Object *queue = dvmGetFieldObject(reference,
794 gDvm.offJavaLangRefReference_queue);
795 Object *queueNext = dvmGetFieldObject(reference,
796 gDvm.offJavaLangRefReference_queueNext);
797 if (queue == NULL || queueNext != NULL) {
798 /* There is no queue, or the reference has already
799 * been enqueued. The Reference.enqueue() method
800 * will do nothing even if we call it.
801 */
802 return false;
803 }
804 }
805
806 /* We need to call enqueue(), but if we called it from
807 * here we'd probably deadlock. Schedule a call.
808 */
809 return true;
810}
811
812/* All objects for stronger reference levels have been
813 * marked before this is called.
814 */
815void dvmHeapHandleReferences(Object *refListHead, enum RefType refType)
816{
817 Object *reference;
818 GcMarkContext *markContext = &gDvm.gcHeap->markContext;
819 const int offVmData = gDvm.offJavaLangRefReference_vmData;
820 const int offReferent = gDvm.offJavaLangRefReference_referent;
821 bool workRequired = false;
822
823size_t numCleared = 0;
824size_t numEnqueued = 0;
825 reference = refListHead;
826 while (reference != NULL) {
827 Object *next;
828 Object *referent;
829
830 /* Pull the interesting fields out of the Reference object.
831 */
832 next = dvmGetFieldObject(reference, offVmData);
833 referent = dvmGetFieldObject(reference, offReferent);
834
835 //TODO: when handling REF_PHANTOM, unlink any references
836 // that fail this initial if(). We need to re-walk
837 // the list, and it would be nice to avoid the extra
838 // work.
839 if (referent != NULL && !isMarked(ptr2chunk(referent), markContext)) {
840 bool schedClear, schedEnqueue;
841
842 /* This is the strongest reference that refers to referent.
843 * Do the right thing.
844 */
845 switch (refType) {
846 case REF_SOFT:
847 case REF_WEAK:
848 schedClear = clearReference(reference);
849 schedEnqueue = enqueueReference(reference);
850 break;
851 case REF_PHANTOM:
852 /* PhantomReferences are not cleared automatically.
853 * Until someone clears it (or the reference itself
854 * is collected), the referent must remain alive.
855 *
856 * It's necessary to fully mark the referent because
857 * it will still be present during the next GC, and
858 * all objects that it points to must be valid.
859 * (The referent will be marked outside of this loop,
860 * after handing all references of this strength, in
861 * case multiple references point to the same object.)
Andy McFaddenb18992f2009-09-25 10:42:15 -0700862 *
863 * One exception: JNI "weak global" references are handled
864 * as a special case. They're identified by the queue.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800865 */
Andy McFaddenb18992f2009-09-25 10:42:15 -0700866 if (gDvm.jniWeakGlobalRefQueue != NULL) {
867 Object* queue = dvmGetFieldObject(reference,
868 gDvm.offJavaLangRefReference_queue);
869 if (queue == gDvm.jniWeakGlobalRefQueue) {
870 LOGV("+++ WGR: clearing + not queueing %p:%p\n",
871 reference, referent);
872 schedClear = clearReference(reference);
873 schedEnqueue = false;
874 break;
875 }
876 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800877 schedClear = false;
878
879 /* A PhantomReference is only useful with a
880 * queue, but since it's possible to create one
881 * without a queue, we need to check.
882 */
883 schedEnqueue = enqueueReference(reference);
884 break;
885 default:
886 assert(!"Bad reference type");
887 schedClear = false;
888 schedEnqueue = false;
889 break;
890 }
891numCleared += schedClear ? 1 : 0;
892numEnqueued += schedEnqueue ? 1 : 0;
893
894 if (schedClear || schedEnqueue) {
895 uintptr_t workBits;
896
897 /* Stuff the clear/enqueue bits in the bottom of
898 * the pointer. Assumes that objects are 8-byte
899 * aligned.
900 *
901 * Note that we are adding the *Reference* (which
902 * is by definition already marked at this point) to
903 * this list; we're not adding the referent (which
904 * has already been cleared).
905 */
906 assert(((intptr_t)reference & 3) == 0);
907 assert(((WORKER_CLEAR | WORKER_ENQUEUE) & ~3) == 0);
908 workBits = (schedClear ? WORKER_CLEAR : 0) |
909 (schedEnqueue ? WORKER_ENQUEUE : 0);
910 if (!dvmHeapAddRefToLargeTable(
911 &gDvm.gcHeap->referenceOperations,
912 (Object *)((uintptr_t)reference | workBits)))
913 {
914 LOGE_HEAP("dvmMalloc(): no room for any more "
915 "reference operations\n");
916 dvmAbort();
917 }
918 workRequired = true;
919 }
920
921 if (refType != REF_PHANTOM) {
922 /* Let later GCs know not to reschedule this reference.
923 */
924 dvmSetFieldObject(reference, offVmData,
925 SCHEDULED_REFERENCE_MAGIC);
926 } // else this is handled later for REF_PHANTOM
927
928 } // else there was a stronger reference to the referent.
929
930 reference = next;
931 }
932#define refType2str(r) \
933 ((r) == REF_SOFT ? "soft" : ( \
934 (r) == REF_WEAK ? "weak" : ( \
935 (r) == REF_PHANTOM ? "phantom" : "UNKNOWN" )))
936LOGD_HEAP("dvmHeapHandleReferences(): cleared %zd, enqueued %zd %s references\n", numCleared, numEnqueued, refType2str(refType));
937
938 /* Walk though the reference list again, and mark any non-clear/marked
939 * referents. Only PhantomReferences can have non-clear referents
940 * at this point.
Andy McFaddenb18992f2009-09-25 10:42:15 -0700941 *
942 * (Could skip this for JNI weak globals, since we know they've been
943 * cleared.)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800944 */
945 if (refType == REF_PHANTOM) {
946 bool scanRequired = false;
947
948 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_REFERENCE_CLEANUP, 0);
949 reference = refListHead;
950 while (reference != NULL) {
951 Object *next;
952 Object *referent;
953
954 /* Pull the interesting fields out of the Reference object.
955 */
956 next = dvmGetFieldObject(reference, offVmData);
957 referent = dvmGetFieldObject(reference, offReferent);
958
959 if (referent != NULL && !isMarked(ptr2chunk(referent), markContext)) {
960 markObjectNonNull(referent, markContext);
961 scanRequired = true;
962
963 /* Let later GCs know not to reschedule this reference.
964 */
965 dvmSetFieldObject(reference, offVmData,
966 SCHEDULED_REFERENCE_MAGIC);
967 }
968
969 reference = next;
970 }
971 HPROF_CLEAR_GC_SCAN_STATE();
972
973 if (scanRequired) {
974 processMarkStack(markContext);
975 }
976 }
977
978 if (workRequired) {
979 dvmSignalHeapWorker(false);
980 }
981}
982
983
984/* Find unreachable objects that need to be finalized,
985 * and schedule them for finalization.
986 */
987void dvmHeapScheduleFinalizations()
988{
989 HeapRefTable newPendingRefs;
990 LargeHeapRefTable *finRefs = gDvm.gcHeap->finalizableRefs;
991 Object **ref;
992 Object **lastRef;
993 size_t totalPendCount;
994 GcMarkContext *markContext = &gDvm.gcHeap->markContext;
995
996 /*
997 * All reachable objects have been marked.
998 * Any unmarked finalizable objects need to be finalized.
999 */
1000
1001 /* Create a table that the new pending refs will
1002 * be added to.
1003 */
1004 if (!dvmHeapInitHeapRefTable(&newPendingRefs, 128)) {
1005 //TODO: mark all finalizable refs and hope that
1006 // we can schedule them next time. Watch out,
1007 // because we may be expecting to free up space
1008 // by calling finalizers.
1009 LOGE_GC("dvmHeapScheduleFinalizations(): no room for "
1010 "pending finalizations\n");
1011 dvmAbort();
1012 }
1013
1014 /* Walk through finalizableRefs and move any unmarked references
1015 * to the list of new pending refs.
1016 */
1017 totalPendCount = 0;
1018 while (finRefs != NULL) {
1019 Object **gapRef;
1020 size_t newPendCount = 0;
1021
1022 gapRef = ref = finRefs->refs.table;
1023 lastRef = finRefs->refs.nextEntry;
1024 while (ref < lastRef) {
1025 DvmHeapChunk *hc;
1026
1027 hc = ptr2chunk(*ref);
1028 if (!isMarked(hc, markContext)) {
1029 if (!dvmHeapAddToHeapRefTable(&newPendingRefs, *ref)) {
1030 //TODO: add the current table and allocate
1031 // a new, smaller one.
1032 LOGE_GC("dvmHeapScheduleFinalizations(): "
1033 "no room for any more pending finalizations: %zd\n",
1034 dvmHeapNumHeapRefTableEntries(&newPendingRefs));
1035 dvmAbort();
1036 }
1037 newPendCount++;
1038 } else {
1039 /* This ref is marked, so will remain on finalizableRefs.
1040 */
1041 if (newPendCount > 0) {
1042 /* Copy it up to fill the holes.
1043 */
1044 *gapRef++ = *ref;
1045 } else {
1046 /* No holes yet; don't bother copying.
1047 */
1048 gapRef++;
1049 }
1050 }
1051 ref++;
1052 }
1053 finRefs->refs.nextEntry = gapRef;
1054 //TODO: if the table is empty when we're done, free it.
1055 totalPendCount += newPendCount;
1056 finRefs = finRefs->next;
1057 }
1058 LOGD_GC("dvmHeapScheduleFinalizations(): %zd finalizers triggered.\n",
1059 totalPendCount);
1060 if (totalPendCount == 0) {
1061 /* No objects required finalization.
1062 * Free the empty temporary table.
1063 */
1064 dvmClearReferenceTable(&newPendingRefs);
1065 return;
1066 }
1067
1068 /* Add the new pending refs to the main list.
1069 */
1070 if (!dvmHeapAddTableToLargeTable(&gDvm.gcHeap->pendingFinalizationRefs,
1071 &newPendingRefs))
1072 {
1073 LOGE_GC("dvmHeapScheduleFinalizations(): can't insert new "
1074 "pending finalizations\n");
1075 dvmAbort();
1076 }
1077
1078 //TODO: try compacting the main list with a memcpy loop
1079
1080 /* Mark the refs we just moved; we don't want them or their
1081 * children to get swept yet.
1082 */
1083 ref = newPendingRefs.table;
1084 lastRef = newPendingRefs.nextEntry;
1085 assert(ref < lastRef);
1086 HPROF_SET_GC_SCAN_STATE(HPROF_ROOT_FINALIZING, 0);
1087 while (ref < lastRef) {
1088 markObjectNonNull(*ref, markContext);
1089 ref++;
1090 }
1091 HPROF_CLEAR_GC_SCAN_STATE();
1092
1093 /* Set markAllReferents so that we don't collect referents whose
1094 * only references are in final-reachable objects.
1095 * TODO: eventually provide normal reference behavior by properly
1096 * marking these references.
1097 */
1098 gDvm.gcHeap->markAllReferents = true;
1099 processMarkStack(markContext);
1100 gDvm.gcHeap->markAllReferents = false;
1101
1102 dvmSignalHeapWorker(false);
1103}
1104
1105void dvmHeapFinishMarkStep()
1106{
1107 HeapBitmap *markBitmap;
1108 HeapBitmap objectBitmap;
1109 GcMarkContext *markContext;
1110
1111 markContext = &gDvm.gcHeap->markContext;
1112
1113 /* The sweep step freed every object that appeared in the
1114 * HeapSource bitmaps that didn't appear in the mark bitmaps.
1115 * The new state of the HeapSource is exactly the final
1116 * mark bitmaps, so swap them in.
1117 *
1118 * The old bitmaps will be swapped into the context so that
1119 * we can clean them up.
1120 */
1121 dvmHeapSourceReplaceObjectBitmaps(markContext->bitmaps,
1122 markContext->numBitmaps);
1123
1124 /* Clean up the old HeapSource bitmaps and anything else associated
1125 * with the marking process.
1126 */
1127 dvmHeapBitmapDeleteList(markContext->bitmaps, markContext->numBitmaps);
1128 destroyMarkStack(&markContext->stack);
1129
1130 memset(markContext, 0, sizeof(*markContext));
1131}
1132
1133#if WITH_HPROF && WITH_HPROF_UNREACHABLE
1134static bool
1135hprofUnreachableBitmapCallback(size_t numPtrs, void **ptrs,
1136 const void *finger, void *arg)
1137{
1138 hprof_context_t *hctx = (hprof_context_t *)arg;
1139 size_t i;
1140
1141 for (i = 0; i < numPtrs; i++) {
1142 Object *obj;
1143
1144 /* The pointers we're getting back are DvmHeapChunks, not
1145 * Objects.
1146 */
1147 obj = (Object *)chunk2ptr(*ptrs++);
1148
1149 hprofMarkRootObject(hctx, obj, 0);
1150 hprofDumpHeapObject(hctx, obj);
1151 }
1152
1153 return true;
1154}
1155
1156static void
1157hprofDumpUnmarkedObjects(const HeapBitmap markBitmaps[],
1158 const HeapBitmap objectBitmaps[], size_t numBitmaps)
1159{
1160 hprof_context_t *hctx = gDvm.gcHeap->hprofContext;
1161 if (hctx == NULL) {
1162 return;
1163 }
1164
1165 LOGI("hprof: dumping unreachable objects\n");
1166
1167 HPROF_SET_GC_SCAN_STATE(HPROF_UNREACHABLE, 0);
1168
1169 dvmHeapBitmapXorWalkLists(markBitmaps, objectBitmaps, numBitmaps,
1170 hprofUnreachableBitmapCallback, hctx);
1171
1172 HPROF_CLEAR_GC_SCAN_STATE();
1173}
1174#endif
1175
1176static bool
1177sweepBitmapCallback(size_t numPtrs, void **ptrs, const void *finger, void *arg)
1178{
1179 const ClassObject *const classJavaLangClass = gDvm.classJavaLangClass;
1180 size_t i;
Barry Hayesdde8ab02009-05-20 12:10:36 -07001181 void **origPtrs = ptrs;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001182
1183 for (i = 0; i < numPtrs; i++) {
1184 DvmHeapChunk *hc;
1185 Object *obj;
1186
1187 /* The pointers we're getting back are DvmHeapChunks, not
1188 * Objects.
1189 */
1190 hc = (DvmHeapChunk *)*ptrs++;
1191 obj = (Object *)chunk2ptr(hc);
1192
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001193 /* Free the monitor associated with the object.
1194 */
1195 dvmFreeObjectMonitor(obj);
1196
1197 /* NOTE: Dereferencing clazz is dangerous. If obj was the last
1198 * one to reference its class object, the class object could be
1199 * on the sweep list, and could already have been swept, leaving
1200 * us with a stale pointer.
1201 */
1202 LOGV_SWEEP("FREE: 0x%08x %s\n", (uint)obj, obj->clazz->name);
1203
1204 /* This assumes that java.lang.Class will never go away.
1205 * If it can, and we were the last reference to it, it
1206 * could have already been swept. However, even in that case,
1207 * gDvm.classJavaLangClass should still have a useful
1208 * value.
1209 */
1210 if (obj->clazz == classJavaLangClass) {
1211 LOGV_SWEEP("---------------> %s\n", ((ClassObject *)obj)->name);
1212 /* dvmFreeClassInnards() may have already been called,
1213 * but it's safe to call on the same ClassObject twice.
1214 */
1215 dvmFreeClassInnards((ClassObject *)obj);
1216 }
1217
1218#if 0
1219 /* Overwrite the to-be-freed object to make stale references
1220 * more obvious.
1221 */
1222 {
1223 int chunklen;
1224 ClassObject *clazz = obj->clazz;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001225 chunklen = dvmHeapSourceChunkSize(hc);
1226 memset(hc, 0xa5, chunklen);
1227 obj->clazz = (ClassObject *)((uintptr_t)clazz ^ 0xffffffff);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001228 }
1229#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001230 }
Barry Hayesdde8ab02009-05-20 12:10:36 -07001231 // TODO: dvmHeapSourceFreeList has a loop, just like the above
1232 // does. Consider collapsing the two loops to save overhead.
1233 dvmHeapSourceFreeList(numPtrs, origPtrs);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001234
1235 return true;
1236}
1237
1238/* A function suitable for passing to dvmHashForeachRemove()
1239 * to clear out any unmarked objects. Clears the low bits
1240 * of the pointer because the intern table may set them.
1241 */
1242static int isUnmarkedObject(void *object)
1243{
1244 return !isMarked(ptr2chunk((uintptr_t)object & ~(HB_OBJECT_ALIGNMENT-1)),
1245 &gDvm.gcHeap->markContext);
1246}
1247
1248/* Walk through the list of objects that haven't been
1249 * marked and free them.
1250 */
1251void
1252dvmHeapSweepUnmarkedObjects(int *numFreed, size_t *sizeFreed)
1253{
1254 const HeapBitmap *markBitmaps;
1255 const GcMarkContext *markContext;
1256 HeapBitmap objectBitmaps[HEAP_SOURCE_MAX_HEAP_COUNT];
1257 size_t origObjectsAllocated;
1258 size_t origBytesAllocated;
1259 size_t numBitmaps;
1260
1261 /* All reachable objects have been marked.
1262 * Detach any unreachable interned strings before
1263 * we sweep.
1264 */
1265 dvmGcDetachDeadInternedStrings(isUnmarkedObject);
1266
1267 /* Free any known objects that are not marked.
1268 */
1269 origObjectsAllocated = dvmHeapSourceGetValue(HS_OBJECTS_ALLOCATED, NULL, 0);
1270 origBytesAllocated = dvmHeapSourceGetValue(HS_BYTES_ALLOCATED, NULL, 0);
1271
1272 markContext = &gDvm.gcHeap->markContext;
1273 markBitmaps = markContext->bitmaps;
1274 numBitmaps = dvmHeapSourceGetObjectBitmaps(objectBitmaps,
1275 HEAP_SOURCE_MAX_HEAP_COUNT);
1276#ifndef NDEBUG
1277 if (numBitmaps != markContext->numBitmaps) {
1278 LOGE("heap bitmap count mismatch: %zd != %zd\n",
1279 numBitmaps, markContext->numBitmaps);
1280 dvmAbort();
1281 }
1282#endif
1283
1284#if WITH_HPROF && WITH_HPROF_UNREACHABLE
1285 hprofDumpUnmarkedObjects(markBitmaps, objectBitmaps, numBitmaps);
1286#endif
1287
1288 dvmHeapBitmapXorWalkLists(markBitmaps, objectBitmaps, numBitmaps,
1289 sweepBitmapCallback, NULL);
1290
1291 *numFreed = origObjectsAllocated -
1292 dvmHeapSourceGetValue(HS_OBJECTS_ALLOCATED, NULL, 0);
1293 *sizeFreed = origBytesAllocated -
1294 dvmHeapSourceGetValue(HS_BYTES_ALLOCATED, NULL, 0);
1295
1296#ifdef WITH_PROFILER
1297 if (gDvm.allocProf.enabled) {
1298 gDvm.allocProf.freeCount += *numFreed;
1299 gDvm.allocProf.freeSize += *sizeFreed;
1300 }
1301#endif
1302}