01: /*
02: * room.java
03: *
04: * Copyright (C) 2003 Peter Graves
05: * $Id: room.java,v 1.6 2003/11/15 11:03:30 beedlem Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.lisp;
23:
24: // ### room
25: public final class room extends Primitive {
26: private room() {
27: super ("room");
28: }
29:
30: public LispObject execute(LispObject[] args)
31: throws ConditionThrowable {
32: Runtime runtime = Runtime.getRuntime();
33: long total = 0;
34: long free = 0;
35: long maxFree = 0;
36: while (true) {
37: try {
38: runtime.gc();
39: Thread.currentThread().sleep(100);
40: runtime.runFinalization();
41: Thread.currentThread().sleep(100);
42: runtime.gc();
43: Thread.currentThread().sleep(100);
44: } catch (InterruptedException e) {
45: }
46: total = runtime.totalMemory();
47: free = runtime.freeMemory();
48: if (free > maxFree)
49: maxFree = free;
50: else
51: break;
52: }
53: long used = total - free;
54: CharacterOutputStream out = getStandardOutput();
55: StringBuffer sb = new StringBuffer("Total memory ");
56: sb.append(total);
57: sb.append(" bytes");
58: sb.append(System.getProperty("line.separator"));
59: sb.append(used);
60: sb.append(" bytes used");
61: sb.append(System.getProperty("line.separator"));
62: sb.append(free);
63: sb.append(" bytes free");
64: sb.append(System.getProperty("line.separator"));
65: out.writeString(sb.toString());
66: out.flushOutput();
67: return number(used);
68: }
69:
70: private static final room ROOM = new room();
71: }
|