Added new experimental VM from Mat. This is the 'faster vm' option.
[retro/experimental.git] / toka / debug.c
blobcd891a2d46ba55afd788118d59ad25118c252cb9
1 /******************************************************
2 * Toka
4 *|F|
5 *|F| FILE: debug.c
6 *|F|
8 * Copyright (c) 2006, 2007 Charles R. Childers
10 * Permission to use, copy, modify, and distribute this
11 * software for any purpose with or without fee is hereby
12 * granted, provided that the above copyright notice and
13 * this permission notice appear in all copies.
15 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR
16 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
19 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
21 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
22 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE.
25 ******************************************************/
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <ctype.h>
32 #include <memory.h>
34 #include "toka.h"
36 extern Inst *heap;
37 extern long gc_used, gc_objects, gc_depth, gc_tdepth, last;
38 extern VM_STACK data, address, alternate;
39 extern ENTRY dictionary[];
40 extern GCITEM gc_list[];
41 extern GCITEM gc_trash[];
44 /******************************************************
45 *|G| :stat ( - ) Display information about
46 *|G| the virtual machine status
48 *|F| vm_info()
49 *|F| Display information about Toka's memory use,
50 *|F| dictionary, etc.
51 *|F|
52 ******************************************************/
53 void vm_info()
55 long a, b, c, total;
56 long permanent_objects, permanent_size;
57 long size, tsize;
59 size = 0; tsize = 0;
61 for (a = 0; a != gc_depth; a++)
62 size += gc_list[a].size;
63 for (a = 0; a != gc_tdepth; a++)
64 tsize += gc_trash[a].size;
66 permanent_objects = gc_objects - gc_depth - gc_tdepth;
67 permanent_size = gc_used - size - tsize;
69 a = (sizeof(GCITEM) * 128)*2;
70 b = (sizeof(ENTRY) * MAX_DICTIONARY_ENTRIES);
71 c = sizeof(VM_STACK) * 3 + ((MAX_DATA_STACK * sizeof(long))*2) + (MAX_RETURN_STACK * sizeof(long));
73 total = a + b + c + permanent_size + size + tsize;
75 printf("-- Memory Use -------------------------------\n");
76 printf(" %lu KiB (%lu) used for dictionary\n", b/1024, b);
77 printf(" %lu KiB (%lu) used for gc bookkeeping\n", a/1024, a);
78 printf(" %lu KiB (%lu) used for stacks\n", c/1024, c);
79 printf("\n");
80 printf(" Permanent Allocations:\n");
81 printf(" %lu objects totaling %lu KiB (%lu)\n", permanent_objects, permanent_size/1024, permanent_size);
82 printf(" Temporary Allocations:\n");
83 printf(" User: %lu objects totaling %lu KiB (%lu)\n", gc_depth, size/1024, size);
84 printf(" System: %lu objects totaling %lu KiB (%lu)\n", gc_tdepth, tsize/1024, tsize);
85 printf("\n");
86 printf(" Total: %lu KiB (%lu)\n", total/1024, total);
87 printf("-- Dictionary -------------------------------\n");
88 printf(" %lu named items (Max: %lu)\n", last, (long)MAX_DICTIONARY_ENTRIES);
89 printf("-- Stacks -----------------------------------\n");
90 printf(" Data: %lu items (Max: %lu)\n", data.sp, (long)MAX_DATA_STACK);
91 printf(" Alternate: %lu items (Max: %lu)\n", alternate.sp, (long)MAX_DATA_STACK);
92 printf(" Address: %lu items (Max: %lu)\n", address.sp, (long)MAX_RETURN_STACK);
93 printf("---------------------------------------------\n");