/src/ghostpdl/psi/zvmem2.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2021 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, |
13 | | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* Level 2 "Virtual memory" operators */ |
18 | | #include "ghost.h" |
19 | | #include "oper.h" |
20 | | #include "estack.h" |
21 | | #include "ialloc.h" /* for ivmspace.h */ |
22 | | #include "ivmspace.h" |
23 | | #include "ivmem2.h" |
24 | | #include "store.h" |
25 | | |
26 | | /* Garbage collector control parameters. */ |
27 | 0 | #define DEFAULT_VM_THRESHOLD_SMALL 100000 |
28 | 178k | #define DEFAULT_VM_THRESHOLD_LARGE 8000000 |
29 | | |
30 | | /* ------ Local/global VM control ------ */ |
31 | | |
32 | | /* <bool> .setglobal - */ |
33 | | static int |
34 | | zsetglobal(i_ctx_t *i_ctx_p) |
35 | 272M | { |
36 | 272M | os_ptr op = osp; |
37 | 272M | check_type(*op, t_boolean); |
38 | 272M | ialloc_set_space(idmemory, |
39 | 272M | (op->value.boolval ? avm_global : avm_local)); |
40 | 272M | pop(1); |
41 | 272M | return 0; |
42 | 272M | } |
43 | | |
44 | | /* - .currentglobal <bool> */ |
45 | | static int |
46 | | zcurrentglobal(i_ctx_t *i_ctx_p) |
47 | 188M | { |
48 | 188M | os_ptr op = osp; |
49 | | |
50 | 188M | push(1); |
51 | 188M | make_bool(op, ialloc_space(idmemory) != avm_local); |
52 | 188M | return 0; |
53 | 188M | } |
54 | | |
55 | | /* <any> gcheck/scheck <bool> */ |
56 | | static int |
57 | | zgcheck(i_ctx_t *i_ctx_p) |
58 | 65.3M | { |
59 | 65.3M | os_ptr op = osp; |
60 | | |
61 | 65.3M | check_op(1); |
62 | 65.3M | make_bool(op, (r_is_local(op) ? false : true)); |
63 | 65.3M | return 0; |
64 | 65.3M | } |
65 | | |
66 | | /* ------ Garbage collector control ------ */ |
67 | | |
68 | | /* These routines are exported for setuserparams. */ |
69 | | |
70 | | /* |
71 | | * <int> setvmthreshold - |
72 | | * |
73 | | * This is implemented as a PostScript procedure that calls setuserparams. |
74 | | */ |
75 | | int |
76 | | set_vm_threshold(i_ctx_t *i_ctx_p, int64_t val) |
77 | 433k | { |
78 | 433k | if (val < -1) |
79 | 0 | return_error(gs_error_rangecheck); |
80 | 433k | else if (val == -1) |
81 | 178k | val = (gs_debug_c('.') ? DEFAULT_VM_THRESHOLD_SMALL : |
82 | 178k | DEFAULT_VM_THRESHOLD_LARGE); |
83 | | #if PSINT32BIT==1 |
84 | | else if (val > max_int) |
85 | | val = max_int |
86 | | #endif |
87 | 433k | gs_memory_set_vm_threshold(idmemory->space_system, val); |
88 | 433k | gs_memory_set_vm_threshold(idmemory->space_global, val); |
89 | 433k | gs_memory_set_vm_threshold(idmemory->space_local, val); |
90 | 433k | return 0; |
91 | 433k | } |
92 | | |
93 | | int |
94 | | set_vm_reclaim(i_ctx_t *i_ctx_p, long val) |
95 | 432k | { |
96 | 432k | if (val >= -2 && val <= 0) { |
97 | 432k | gs_memory_set_vm_reclaim(idmemory->space_system, (val >= -1)); |
98 | 432k | gs_memory_set_vm_reclaim(idmemory->space_global, (val >= -1)); |
99 | 432k | gs_memory_set_vm_reclaim(idmemory->space_local, (val == 0)); |
100 | 432k | return 0; |
101 | 432k | } else |
102 | 0 | return_error(gs_error_rangecheck); |
103 | 432k | } |
104 | | |
105 | | /* |
106 | | * <int> .vmreclaim - |
107 | | * |
108 | | * This implements only immediate garbage collection: enabling and |
109 | | * disabling GC is implemented by calling setuserparams. |
110 | | */ |
111 | | static int |
112 | | zvmreclaim(i_ctx_t *i_ctx_p) |
113 | 89.2k | { |
114 | 89.2k | os_ptr op = osp; |
115 | | |
116 | 89.2k | check_type(*op, t_integer); |
117 | 89.2k | if (op->value.intval == 1 || op->value.intval == 2) { |
118 | | /* Force the interpreter to store its state and exit. */ |
119 | | /* The interpreter's caller will do the actual GC. */ |
120 | 89.2k | return_error(gs_error_VMreclaim); |
121 | 89.2k | } |
122 | 0 | return_error(gs_error_rangecheck); |
123 | 89.2k | } |
124 | | |
125 | | /* ------ Initialization procedure ------ */ |
126 | | |
127 | | /* The VM operators are defined even if the initial language level is 1, */ |
128 | | /* because we need them during initialization. */ |
129 | | const op_def zvmem2_op_defs[] = |
130 | | { |
131 | | {"0.currentglobal", zcurrentglobal}, |
132 | | {"1.gcheck", zgcheck}, |
133 | | {"1.setglobal", zsetglobal}, |
134 | | /* The rest of the operators are defined only in Level 2. */ |
135 | | op_def_begin_level2(), |
136 | | {"1.vmreclaim", zvmreclaim}, |
137 | | op_def_end(0) |
138 | | }; |