Commit 751aa78338c39313dffbe61ebff55cf5411f366c

  • avatar
  • loic <loic @x37-l…top.(none)>
  • Tue Feb 02 13:49:41 CET 2010
add a test program that allocate objects
  
136136 <sequence description="Launch Sweep &amp; Cleanup">
137137 <argument argLabel="sweep"/>
138138 </sequence>
139 <sequence description="alloc memory">
140 <option argLabel="alloc" longName="alloc"/>
141 <argument argLabel="nbObjects"/>
142 </sequence>
139143 <option argLabel="show" longName="show" description="Show heap debug flags"/>
140144 </syntax>
141145 <syntax alias="halt" description="Shutdown all services and devices so that the computer can be powered off"/>
  
2121package org.jnode.command.system;
2222
2323import java.io.PrintWriter;
24import java.util.ArrayList;
2425
2526import org.jnode.shell.AbstractCommand;
2627import org.jnode.shell.syntax.Argument;
2728import org.jnode.shell.syntax.EnumArgument;
2829import org.jnode.shell.syntax.FlagArgument;
30import org.jnode.shell.syntax.IntegerArgument;
2931import org.jnode.shell.syntax.StringArgument;
3032import org.jnode.util.NumberUtils;
3133import org.jnode.vm.Vm;
8787 private final StringArgument argMajorGc;
8888 private final StringArgument argMinorGc;
8989 private final StringArgument argSweep;
90 private final FlagArgument argAlloc;
91 private final IntegerArgument argAllocNbObjects;
9092
9193 private final PrintWriter out = getOutput().getPrintWriter();
9294
101101 argMajorGc = new StringArgument("major", Argument.OPTIONAL);
102102 argMinorGc = new StringArgument("major", Argument.OPTIONAL);
103103 argSweep = new StringArgument("major", Argument.OPTIONAL);
104 argAlloc = new FlagArgument("show", Argument.OPTIONAL, help_show);
105 argAllocNbObjects = new IntegerArgument("show", Argument.OPTIONAL, help_show);
104106 registerArguments(argDebugFlags, argClear, argSet, argShow, argMajorGc, argMinorGc,
105 argSweep);
107 argSweep, argAlloc, argAllocNbObjects);
106108 }
107109
108110 public static void main(String[] args) throws Exception {
123123 Vm.getHeapManager().setHeapFlags(flags);
124124 } else if (argShow.isSet()) {
125125 showFlags(Vm.getHeapManager().getHeapFlags(), out);
126 } else {
126 } else if (argAlloc.isSet() && argAllocNbObjects.isSet()) {
127 allocObjects(argAllocNbObjects.getValue());
128 }else {
127129 final Runtime rt = Runtime.getRuntime();
128130 out.format(fmt_out, str_mem_size, NumberUtils.toBinaryByte(rt.totalMemory()));
129131 out.format(fmt_out, str_mem_free, NumberUtils.toBinaryByte(rt.freeMemory()));
152152 }
153153 }
154154
155 private void gc() {
155 private void allocObjects(Integer nbObjectsToAllocate) {
156 int listSize = 42;
157 ArrayList<Object> l = null;
158 for (int i = 0; i < nbObjectsToAllocate; i++) {
159 l = new ArrayList<Object>(listSize);
160 for (int j = 0; j < listSize; j++) {
161 l.add(new Object());
162 }
163 }
164 }
165
166 private void gc() {
156167 minorGc();
157168 majorGc();
158169 sweep();