| 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.vm.ObjectVisitor; |
| 24 |
import org.jnode.vm.classmgr.VmNormalClass; |
| 25 |
import org.jnode.vm.classmgr.VmType; |
| 26 |
import org.vmmagic.pragma.Uninterruptible; |
| 27 |
|
| 28 |
/** |
| 29 |
* @author Martin Husted Hartvig (hagar@jnode.org) |
| 30 |
*/ |
| 31 |
final class GenHeapStatisticsVisitor extends ObjectVisitor implements Uninterruptible { |
| 32 |
|
| 33 |
private final GenHeapStatistics heapStatistics; |
| 34 |
|
| 35 |
public GenHeapStatisticsVisitor(GenHeapStatistics heapStatistics) { |
| 36 |
this.heapStatistics = heapStatistics; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Count the visited object. |
| 41 |
* |
| 42 |
* @param object |
| 43 |
* @return boolean |
| 44 |
*/ |
| 45 |
|
| 46 |
public final boolean visit(Object object) { |
| 47 |
int size = 0; |
| 48 |
if (!heapStatistics.contains(object.getClass().getName())) { |
| 49 |
final VmType<?> type = VmType.fromClass(object.getClass()); |
| 50 |
size = (type instanceof VmNormalClass<?> ? ((VmNormalClass<?>) type).getObjectSize() |
| 51 |
: 0); |
| 52 |
} |
| 53 |
|
| 54 |
heapStatistics.add(object.getClass().getName(), size); |
| 55 |
|
| 56 |
return true; |
| 57 |
} |
| 58 |
} |