| 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.VmSystem; |
| 24 |
import org.jnode.vm.memmgr.GCStatistics; |
| 25 |
|
| 26 |
/** |
| 27 |
* @author Ewout Prangsma (epr@users.sourceforge.net) |
| 28 |
*/ |
| 29 |
final class GenGCStatistics extends GCStatistics { |
| 30 |
|
| 31 |
int lastMarkIterations; |
| 32 |
long lastMajorMarkedObjects; |
| 33 |
long lastMajorMarkedObjectsSize; |
| 34 |
long lastMinorMarkedObjects; |
| 35 |
long lastMinorMarkedObjectsSize; |
| 36 |
long lastFreedBytes; |
| 37 |
long nbYellowObjects; |
| 38 |
|
| 39 |
private GenGCStatsCounter majorCounter = new GenGCStatsCounter("major gc"); |
| 40 |
private GenGCStatsCounter markCounter = new GenGCStatsCounter("mark"); |
| 41 |
private GenGCStatsCounter markForSweepCounter = new GenGCStatsCounter("mark for sweep"); |
| 42 |
private GenGCStatsCounter minorCounter = new GenGCStatsCounter("minor gc"); |
| 43 |
private GenGCStatsCounter sweepCounter = new GenGCStatsCounter("sweep"); |
| 44 |
private GenGCStatsCounter cleanupCounter = new GenGCStatsCounter("cleanup"); |
| 45 |
|
| 46 |
public static long currentMillis() { |
| 47 |
return VmSystem.currentKernelMillis(); |
| 48 |
} |
| 49 |
|
| 50 |
public static long getDuration(long beginTime) { |
| 51 |
return GenGCStatistics.currentMillis() - beginTime; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public String toString() { |
| 56 |
StringBuilder sb = new StringBuilder(); |
| 57 |
append("lastMarkIterations", lastMarkIterations, sb); |
| 58 |
append("lastMajorMarkedObjects", lastMajorMarkedObjects, sb); |
| 59 |
append("lastMajorMarkedObjectsSize", lastMajorMarkedObjectsSize, sb); |
| 60 |
append("lastMinorMarkedObjects", lastMinorMarkedObjects, sb); |
| 61 |
append("lastMinorMarkedObjectsSize", lastMinorMarkedObjectsSize, sb); |
| 62 |
append("lastFreedBytes", lastFreedBytes, sb); |
| 63 |
append("nbYellowObjects", nbYellowObjects, sb); |
| 64 |
sb.append(majorCounter.toString()); |
| 65 |
sb.append(markCounter.toString()); |
| 66 |
sb.append(markForSweepCounter.toString()); |
| 67 |
sb.append(minorCounter.toString()); |
| 68 |
sb.append(sweepCounter.toString()); |
| 69 |
sb.append(cleanupCounter.toString()); |
| 70 |
return sb.toString(); |
| 71 |
} |
| 72 |
|
| 73 |
private void append(String title, long value, StringBuilder sb) { |
| 74 |
sb.append(title); |
| 75 |
sb.append("\t"); |
| 76 |
sb.append(value); |
| 77 |
sb.append("\n"); |
| 78 |
} |
| 79 |
|
| 80 |
public void addMajorDuration(long duration) { |
| 81 |
majorCounter.addExecutionDuration(duration); |
| 82 |
} |
| 83 |
|
| 84 |
public void addMarkDuration(long duration) { |
| 85 |
markCounter.addExecutionDuration(duration); |
| 86 |
} |
| 87 |
|
| 88 |
public void addMarkForSweepDuration(long duration) { |
| 89 |
markForSweepCounter.addExecutionDuration(duration); |
| 90 |
} |
| 91 |
|
| 92 |
public void addMinorDuration(long duration) { |
| 93 |
minorCounter.addExecutionDuration(duration); |
| 94 |
} |
| 95 |
|
| 96 |
public void addSweepDuration(long duration) { |
| 97 |
sweepCounter.addExecutionDuration(duration); |
| 98 |
} |
| 99 |
|
| 100 |
public void addCleanupDuration(long duration) { |
| 101 |
cleanupCounter.addExecutionDuration(duration); |
| 102 |
} |
| 103 |
} |