Changeset 4363


Ignore:
Timestamp:
10/14/03 12:48:04 (20 years ago)
Author:
piso
Message:

extends Lisp => extends Primitive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/room.java

    r4051 r4363  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: room.java,v 1.3 2003-09-25 15:37:08 piso Exp $
     5 * $Id: room.java,v 1.4 2003-10-14 12:48:04 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2222package org.armedbear.lisp;
    2323
    24 public final class room extends Lisp
     24// ### room
     25public final class room extends Primitive
    2526{
    26     private static final Primitive ROOM = new Primitive("room") {
    27         public LispObject execute(LispObject[] args) throws ConditionThrowable
    28         {
    29             Runtime runtime = Runtime.getRuntime();
    30             long total = 0;
    31             long free = 0;
    32             long maxFree = 0;
    33             while (true) {
    34                 try {
    35                     runtime.gc();
    36                     Thread.currentThread().sleep(100);
    37                     runtime.runFinalization();
    38                     Thread.currentThread().sleep(100);
    39                     runtime.gc();
    40                     Thread.currentThread().sleep(100);
    41                 }
    42                 catch (InterruptedException e) {}
    43                 total = runtime.totalMemory();
    44                 free = runtime.freeMemory();
    45                 if (free > maxFree)
    46                     maxFree = free;
    47                 else
    48                     break;
     27    private room()
     28    {
     29        super("room");
     30    }
     31
     32    public LispObject execute(LispObject[] args) throws ConditionThrowable
     33    {
     34        Runtime runtime = Runtime.getRuntime();
     35        long total = 0;
     36        long free = 0;
     37        long maxFree = 0;
     38        while (true) {
     39            try {
     40                runtime.gc();
     41                Thread.currentThread().sleep(100);
     42                runtime.runFinalization();
     43                Thread.currentThread().sleep(100);
     44                runtime.gc();
     45                Thread.currentThread().sleep(100);
    4946            }
    50             long used = total - free;
    51             CharacterOutputStream out = getStandardOutput();
    52             StringBuffer sb = new StringBuffer("Total memory ");
    53             sb.append(total);
    54             sb.append(" bytes");
    55             sb.append(System.getProperty("line.separator"));
    56             sb.append(used);
    57             sb.append(" bytes used");
    58             sb.append(System.getProperty("line.separator"));
    59             sb.append(free);
    60             sb.append(" bytes free");
    61             sb.append(System.getProperty("line.separator"));
    62             out.writeString(sb.toString());
    63             out.flushOutput();
    64             return number(used);
     47            catch (InterruptedException e) {}
     48            total = runtime.totalMemory();
     49            free = runtime.freeMemory();
     50            if (free > maxFree)
     51                maxFree = free;
     52            else
     53                break;
    6554        }
    66     };
     55        long used = total - free;
     56        CharacterOutputStream out = getStandardOutput();
     57        StringBuffer sb = new StringBuffer("Total memory ");
     58        sb.append(total);
     59        sb.append(" bytes");
     60        sb.append(System.getProperty("line.separator"));
     61        sb.append(used);
     62        sb.append(" bytes used");
     63        sb.append(System.getProperty("line.separator"));
     64        sb.append(free);
     65        sb.append(" bytes free");
     66        sb.append(System.getProperty("line.separator"));
     67        out.writeString(sb.toString());
     68        out.flushOutput();
     69        return number(used);
     70    }
     71
     72    private static final room ROOM = new room();
    6773}
Note: See TracChangeset for help on using the changeset viewer.