1
/*
2
 * $Id$
3
 *
4
 * Copyright (C) 2003-2009 JNode.org
5
 *
6
 * This library is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful, but 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
14
 * License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this library; If not, write to the Free Software Foundation, Inc., 
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
 */
20
21
package org.jnode.vm.memmgr.generational;
22
23
import org.jnode.annotation.MagicPermission;
24
import org.jnode.vm.ObjectVisitor;
25
import org.jnode.vm.VmMagic;
26
import org.jnode.vm.classmgr.ObjectFlags;
27
import org.vmmagic.pragma.Uninterruptible;
28
29
/**
30
 * @author Loic Rouchon (loic.rouchon@insa-lyon.fr)
31
 */
32
@MagicPermission
33
final class GenGCSweepVisitor extends ObjectVisitor implements ObjectFlags, Uninterruptible {
34
35
    private GenGCYellowObjectManager yellowObjectManager;
36
    private long markedObjectsSize = 0L;
37
38
    public GenGCSweepVisitor(GenGCYellowObjectManager yellowObjectManager) {
39
        this.yellowObjectManager = yellowObjectManager;
40
    }
41
42
    /**
43
     * Mark every visited object white.
44
     * 
45
     * @param object
46
     * @return boolean
47
     */
48
    @Override
49
    public final boolean visit(Object object) {
50
        if (VmMagic.getObjectColor(object) == GC_YELLOW) {
51
            yellowObjectManager.deleteObject(object);
52
            markedObjectsSize += VmDefaultHeap.getObjectSize(object);
53
        }
54
        return true;
55
    }
56
57
    /**
58
     * @param currentHeap
59
     *            The currentHeap to set.
60
     */
61
    public final void setCurrentHeap(VmDefaultHeap currentHeap) {
62
        yellowObjectManager.setCurrentHeap(currentHeap);
63
    }
64
65
    public void resetMarkedObjectsSize() {
66
        markedObjectsSize = 0L;
67
    }
68
69
    public long getMarkedObjectsSize() {
70
        return markedObjectsSize;
71
    }
72
}