1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/* Copyright (C) 1992, 1993, 1994, 1997, 1998 Aladdin Enterprises. All rights reserved.
This file is part of Aladdin Ghostscript.
Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
or distributor accepts any responsibility for the consequences of using it,
or for whether it serves any particular purpose or works at all, unless he
or she says so in writing. Refer to the Aladdin Ghostscript Free Public
License (the "License") for full details.
Every copy of Aladdin Ghostscript must include a copy of the License,
normally in a plain ASCII text file named PUBLIC. The License grants you
the right to copy, modify and redistribute Aladdin Ghostscript, but only
under certain conditions described in the License. Among other things, the
License requires that the copyright notice and this notice be preserved on
all copies.
*/
/* Level 2 "Virtual memory" operators */
#include "ghost.h"
#include "oper.h"
#include "estack.h"
#include "ialloc.h" /* for ivmspace.h */
#include "ivmspace.h"
#include "store.h"
/* Garbage collector control parameters. */
#define DEFAULT_VM_THRESHOLD_SMALL 20000
#define DEFAULT_VM_THRESHOLD_LARGE 250000
#define MIN_VM_THRESHOLD 1
#define MAX_VM_THRESHOLD max_long
/* ------ Local/global VM control ------ */
/* <bool> .setglobal - */
private int
zsetglobal(register os_ptr op)
{
check_type(*op, t_boolean);
ialloc_set_space(idmemory,
(op->value.boolval ? avm_global : avm_local));
pop(1);
return 0;
}
/* <bool> .currentglobal - */
private int
zcurrentglobal(register os_ptr op)
{
push(1);
make_bool(op, ialloc_space(idmemory) != avm_local);
return 0;
}
/* <any> gcheck/scheck <bool> */
private int
zgcheck(register os_ptr op)
{
check_op(1);
make_bool(op, (r_is_local(op) ? false : true));
return 0;
}
/* ------ Garbage collector control ------ */
/* These routines are exported for setuserparams. */
/*
* <int> setvmthreshold -
*
* This is implemented as a PostScript procedure that calls setuserparams.
*/
int
set_vm_threshold(long val)
{
gs_memory_gc_status_t stat;
if (val < -1)
return_error(e_rangecheck);
else if (val == -1)
val = (gs_debug_c('.') ? DEFAULT_VM_THRESHOLD_SMALL :
DEFAULT_VM_THRESHOLD_LARGE);
else if (val < MIN_VM_THRESHOLD)
val = MIN_VM_THRESHOLD;
else if (val > MAX_VM_THRESHOLD)
val = MAX_VM_THRESHOLD;
gs_memory_gc_status(idmemory->space_global, &stat);
stat.vm_threshold = val;
gs_memory_set_gc_status(idmemory->space_global, &stat);
gs_memory_gc_status(idmemory->space_local, &stat);
stat.vm_threshold = val;
gs_memory_set_gc_status(idmemory->space_local, &stat);
return 0;
}
/*
* <int> .vmreclaim -
*
* This implements only immediate garbage collection: enabling and
* disabling GC is implemented by calling setuserparams.
*/
int
set_vm_reclaim(long val)
{
if (val >= -2 && val <= 0) {
gs_memory_gc_status_t stat;
gs_memory_gc_status(idmemory->space_system, &stat);
stat.enabled = val >= -1;
gs_memory_set_gc_status(idmemory->space_system, &stat);
gs_memory_gc_status(idmemory->space_global, &stat);
stat.enabled = val >= -1;
gs_memory_set_gc_status(idmemory->space_global, &stat);
gs_memory_gc_status(idmemory->space_local, &stat);
stat.enabled = val == 0;
gs_memory_set_gc_status(idmemory->space_local, &stat);
return 0;
} else
return_error(e_rangecheck);
}
private int
zvmreclaim(register os_ptr op)
{
check_type(*op, t_integer);
if (op->value.intval == 1 || op->value.intval == 2) {
/* Force the interpreter to store its state and exit. */
/* The interpreter's caller will do the actual GC. */
return_error(e_VMreclaim);
}
return_error(e_rangecheck);
}
/* ------ Initialization procedure ------ */
/* The VM operators are defined even if the initial language level is 1, */
/* because we need them during initialization. */
const op_def zvmem2_op_defs[] =
{
{"0.currentglobal", zcurrentglobal},
{"1.gcheck", zgcheck},
{"1.setglobal", zsetglobal},
/* The rest of the operators are defined only in Level 2. */
op_def_begin_level2(),
{"1.vmreclaim", zvmreclaim},
op_def_end(0)
};
|