YAP 7.1.0
heap.h
1//
2// File defining fields in the Yap_heap_codes global structure
3//
4// these fields used to spread all over the place, because they must be used in
5// 4 ways:
6// - they must be defined somewhere
7// - they have an #ifdef to get a shorter name
8// - they must be initialised somewhere
9// - they must be restorable and collectable (from the atom gc).
10//
11//
12// The defs include 4+ components:
13// Type
14// name in structured
15// global name
16// init code and restore code (optional)
17//
18//
19//
20// MkAT\‍(MkAtomTerm) cvts from a predefined atom to a term
21// MkPred constructs a pr%ed_entry
22// MkOp gets an opcode
23// void does nothing
24// =VALUE inits as VALUE
25// Init... sets up call to InitFunc
26// Restore... sets up call to RestoreFunc
27
28// HM refers to standard field
29// HI refers to field that does not need restore
30// H_R refers to field that does not need init, but needs restore
31// HSPACE refers to a field without init not recovery
32// HMLOCK refers to a lock
33// HRWLOCK refers to a rwlock
34// HOPCODE refers to a opcode
35// HOPCODE refers to a field initialized/restored with a proceeding
36
37/* memory management */
38HSPACE(struct malloc_state *, Yap_av)
39
40#if USE_DL_MALLOC
41HSPACE(struct memory_hole, Yap_MemoryHoles)
42HSPACE(UInt, Yap_NOfMemoryHoles)
43#if defined(YAPOR) || defined(THREADS)
44HMLOCK(lockvar, DLMallocLock)
45#endif
46#endif
47#if USE_DL_MALLOC || (USE_SYSTEM_MALLOC && HAVE_MALLINFO)
48#ifndef HeapUsed
49#define HeapUsed Yap_givemallinfo()
50#endif
51HSPACE(Int, NotHeapUsed)
52#else
53HSPACE(Int, HeapUsed)
54#endif
55HSPACE(Int, HeapMax)
56HSPACE(ADDR, HeapTop)
57HSPACE(ADDR, HeapLim)
58HSPACE(struct FREEB *, FreeBlocks)
59#if defined(YAPOR) || defined(THREADS)
60HMLOCK(lockvar, FreeBlocksLock)
61HMLOCK(lockvar, HeapUsedLock)
62HMLOCK(lockvar, HeapTopLock)
63HI(int, HeapTopOwner, -1)
64#endif
65HI(UInt, MaxStack, 0)
66HI(UInt, MaxTrail, 0)
67
68/* execution info */
69/* OPCODE REVERSE TABLE, needed to recover op tables */
70#if USE_THREADED_CODE
71HM(op_entry, OP_RTABLE, NULL, OpRTableAdjust)
72#endif
73
74/* popular opcodes */
75HMOPCODE(EXECUTE_CPRED_OP_CODE, _execute_cpred)
76HMOPCODE(EXPAND_OP_CODE, _expand_index)
77HMOPCODE(FAIL_OPCODE, _op_fail)
78HMOPCODE(INDEX_OPCODE, _index_pred)
79HMOPCODE(LOCKPRED_OPCODE, _lock_pred)
80HMOPCODE(ORLAST_OPCODE, _or_last)
81HMOPCODE(UNDEF_OPCODE, _undef_p)
82HMOPCODE(RETRY_USERC_OPCODE, _retry_userc)
83HMOPCODE(EXECUTE_CPRED_OPCODE, _execute_cpred)
84
85/* atom tables */
86HSPACE(UInt, NOfAtoms)
87HSPACE(UInt, AtomHashTableSize)
88HSPACE(UInt, WideAtomHashTableSize)
89HSPACE(UInt, NOfWideAtoms)
90HPROC(AtomHashEntry, INVISIBLECHAIN, InitInvisibleAtoms(),
91 RestoreInvisibleAtoms())
92HPROC(AtomHashEntry *, WideHashChain, InitWideAtoms(), RestoreWideAtoms())
93HPROC(AtomHashEntry *, HashChain, InitAtoms(), RestoreAtoms())
94
95#if __INIT_C__
96/* use atom defs here */
97#include "iatoms.h"
98#endif
99
100#ifdef EUROTRA
101HATOMT(TermDollarU, AtomDollarU)
102#endif
103
104// modules
105HATOMT(USER_MODULE, AtomUser)
106HATOMT(IDB_MODULE, AtomIDB)
107HATOMT(ATTRIBUTES_MODULE, AtomAttributes)
108HATOMT(CHARSIO_MODULE, AtomCharsio)
109HATOMT(CHTYPE_MODULE, AtomChType)
110HATOMT(TERMS_MODULE, AtomTerms)
111HATOMT(SYSTEM_MODULE, AtomSystem)
112HATOMT(READUTIL_MODULE, AtomReadutil)
113HATOMT(HACKS_MODULE, AtomYapHacks)
114HATOMT(ARG_MODULE, AtomArg)
115HATOMT(GLOBALS_MODULE, AtomNb)
116HATOMT(SWI_MODULE, AtomSwi)
117HATOMT(DBLOAD_MODULE, AtomDBLoad)
118HATOMT(RANGE_MODULE, AtomRange)
119HATOMT(ERROR_MODULE, AtomError)
120
121//
122// Module list
123//
124HM(struct mod_entry *, CurrentModules, NULL, ModEntryPtrAdjust)
125
126// make sure we have the modules set at this point.
127// don't actually want to define a field
128#if __INIT_C__
129Yap_InitModules();
130#endif
131
132// hidden predicates
133HM(Prop, HIDDEN_PREDICATES, NULL, RestoreHiddenPredicates())
134
135// make sure we have the streams set at this point.
136// don't actually want to define a field
137#if __INIT_C__
138Yap_InitPlIO();
139#endif
140
141HSPACE(union flagTerm *, GFlags)
142HM(UInt, GLOBAL_flagCount, Yap_InitFlags(true), RestoreFlags(GLOBAL_flagCount))
143
144/* Anderson's JIT */
145HM(prolo_exec_mode, Yap_ExecutionMode, INTERPRETED, rv_void)
146/* The Predicate Hash Table: fast access to predicates. */
147HPROC(struct pred_entry **, PredHash, InitPredHash(), RestorePredHash())
148#if defined(YAPOR) || defined(THREADS)
149HRWLOCK(rwlock_t, PredHashRWLock)
150#endif
151HSPACE(UInt, PredsInHashTable)
152HSPACE(UInt, PredHashTableSize)
153
154/* Well-Known Predicates */
155HAROP(CreepCode, AtomCreep, 1, PROLOG_MODULE)
156HAROP(UndefCode, AtomUndefp, 2, PROLOG_MODULE)
157HAROP(SpyCode, AtomSpy, 1, PROLOG_MODULE)
158HAROP(PredFail, AtomFail, 0, PROLOG_MODULE)
159HAROP(PredTrue, AtomTrue, 0, PROLOG_MODULE)
160#ifdef COROUTINING
161HAROP(WakeUpCode, AtomWakeUpGoal, 2, PROLOG_MODULE)
162#endif
163HFOP(PredGoalExpansion, FunctorGoalExpansion, USER_MODULE)
164HFOP(PredMetaCall, FunctorMetaCall, PROLOG_MODULE)
165HFOP(PredTraceMetaCall, FunctorTraceMetaCall, PROLOG_MODULE)
166HFOP(PredDollarCatch, FunctorCatch, PROLOG_MODULE)
167HFOP(PredRecordedWithKey, FunctorRecordedWithKey, PROLOG_MODULE)
168HFOP(PredLogUpdClause, FunctorDoLogUpdClause, PROLOG_MODULE)
169HFOP(PredLogUpdClauseErase, FunctorDoLogUpdClauseErase, PROLOG_MODULE)
170HFOP(PredLogUpdClause0, FunctorDoLogUpdClause, PROLOG_MODULE)
171HFOP(PredStaticClause, FunctorDoStaticClause, PROLOG_MODULE)
172HFOP(PredThrow, FunctorThrow, PROLOG_MODULE)
173HFOP(PredHandleThrow, FunctorHandleThrow, PROLOG_MODULE)
174HFOP(PredIs, FunctorIs, PROLOG_MODULE)
175HFOP(PredSafeCallCleanup, FunctorSafeCallCleanup, PROLOG_MODULE)
176HFOP(PredRestoreRegs, FunctorRestoreRegs, PROLOG_MODULE)
177HFOP(PredCommentHook, FunctorCommentHook, PROLOG_MODULE)
178#ifdef YAPOR
179HAROP(PredGetwork, AtomGetwork, 0, PROLOG_MODULE)
180HFOP(PredProcedure, MkLogPred, FunctorProcedure, PROLOG_MODULE)
181#endif /* YAPOR */
182
183/* low-level tracer */
184#ifdef LOW_LEVEL_TRACER
185HSPACE(bool, Yap_do_low_level_trace)
186#if defined(YAPOR) || defined(THREADS)
187HMLOCK(Yap_low_level_trace_lock)
188#endif
189#endif
190
191/* code management info */
192HI(UInt, Yap_ClauseSpace, 0)
193HI(UInt, Yap_IndexSpace_Tree, 0)
194HI(UInt, Yap_IndexSpace_EXT, 0)
195HI(UInt, Yap_IndexSpace_SW, 0)
196HI(UInt, Yap_LUClauseSpace, 0)
197HI(UInt, Yap_LUIndexSpace_Tree, 0)
198HI(UInt, Yap_LUIndexSpace_CP, 0)
199HI(UInt, Yap_LUIndexSpace_EXT, 0)
200HI(UInt, Yap_LUIndexSpace_SW, 0)
201
202/* static code: may be shared by many predicate or may be used for
203 * meta-execution */
204HYOP(5, COMMA_CODE, _op_fail)
205HYOP(1, DUMMYCODE, _op_fail)
206HYOP(1, FAILCODE, _op_fail)
207HYOP(1, NOCODE, _Nstop)
208#ifdef BEAM
209HYOP(beam_retry_code, 1, BEAM_RETRY_CODE, _beam_retry_code)
210#endif /* BEAM */
211
212HENVYOP(2, ENV_FOR_TRUSTFAIL, _trust_fail, PredFail, TRUSTFAILCODE)
213HSPACE(yamop *, TRUSTFAILCODE)
214
215HENVYOP(2, ENV_FOR_YESCODE, _Ystop, PredFail, YESCODE)
216HSPACE(yamop *, YESCODE)
217
218HCPYOP(1, RTRYCODE, _retry_and_mark, PredFail)
219#ifdef BEAM
220HCPYOP(1, BEAM_RETRY_CODE, PredFail)
221#endif
222#ifdef YAPOR
223HCPYOP(1, GETWORK, _getwork, PredGetwork)
224HCPYOP(1, GETWORK_SEQ, _getwork_seq, PredGetworkSeq)
225HCPYOP(1, GETWORK_FIRST_TIME, _getwork_first_time, PredGetworkFirstTime)
226#endif /* YAPOR */
227#ifdef TABLING
228HCPYOP(1, LOAD_ANSWER, _table_load_answer, PredFail)
229HCPYOP(1, TRY_ANSWER, _table_try_answer, PredFail)
230HCPYOP(1, ANSWER_RESOLUTION, _table_load_answer, PredFail)
231HCPYOP(1, COMPLETION, _table_completion, PredFail)
232#ifdef THREADS_CONSUMER_SHARING
233HCPYOP(1, ANSWER_RESOLUTION_COMPLETION, _table_answer_resolution_completion,
234 PredFail)
235#endif /* THREADS_CONSUMER_SHARING */
236#endif /* TABLING */
237
238/* */
239/* PREG just before we enter $spy. We use that to find out the clause which
240 */
241/* was calling the debugged goal. */
242/* */
243HM(struct yami *, P_before_spy, NULL, PtoOpAdjust(P_before_spy))
244
245/* support recorded_k */
246HM(struct yami *, RETRY_C_RECORDEDP_CODE, NULL,
247 PtoOpAdjust(RETRY_C_RECORDEDP_CODE))
248
249HM(struct yami *, RETRY_C_RECORDED_K_CODE, NULL,
250 PtoOpAdjust(RETRY_C_RECORDED__CODE))
251
252/* compiler flags */
253HI(bool, PROFILING, false)
254HI(bool, CALL_COUNTING, false)
255HI(bool, optimizer_on, true)
256HI(bool, compile_mode, false)
257HI(bool, profiling, false)
258HI(bool, call_counting, false)
259/********* whether we should try to compile array references ******************/
260HI(bool, compile_arrays, false)
261
262/* DBTerms: pre-compiled ground terms */
263#if defined(YAPOR) || defined(THREADS)
264HMLOCK(lockvar, DBTermsListLock)
265#endif
266HM(struct dbterm_list *, DBTermsList, NULL, RestoreDBTermsList())
267
268/* JITI support */
269HI(yamop, ExpandClausesFirst, NULL)
270HM(yamop, ExpandClausesLast, NULL, RestoreExpandList())
271HI(UInt, Yap_ExpandClauses, 0)
272#if defined(YAPOR) || defined(THREADS)
273HMLOCK(lockvar, ExpandClausesListLock)
274HMLOCK(lockvar, OpListLock)
275#endif
276/* instrumentation */
277#ifdef DEBUG
278HI(UInt, Yap_NewCps, 0L)
279HI(UInt, Yap_LiveCps, 0L)
280HI(UInt, Yap_DirtyCps, 0L)
281HI(UInt, Yap_FreedCps, 0L)
282#endif
283HI(UInt, Yap_expand_clauses_sz, 0L)
284
285/* UDI support */
286H_R(struct udi_info *, UdiControlBlocks, RestoreUdiControlBlocks())
287
288/* data-base statistics */
289/* system boots in compile mode */
290HI(Int, STATIC_PREDICATES_MARKED, false)
291
292/* Internal Database */
293HM(Prop, INT_KEYS, NULL, RestoreIntKeys())
294HM(Prop, INT_LU_KEYS, NULL, RestoreIntLUKeys())
295HM(Prop, INT_BB_KEYS, NULL, RestoreIntBBKeys())
296
297/* Internal Database Statistics */
298HI(UInt, INT_KEYS_SIZE, INT_KEYS_DEFAULT_SIZE)
299HI(UInt, INT_KEYS_TIMESTAMP, 0L)
300HI(UInt, INT_BB_KEYS_SIZE, INT_KEYS_DEFAULT_SIZE)
301
302/* Internal Data-Base Control */
303HI(int, UPDATE_MODE, UPDATE_MODE_LOGICAL)
304
305/* nasty IDB stuff */
306HPROC(struct DB_STRUCT *, DBErasedMarker, InitDBErasedMarker(),
307 RestoreDBErasedMarker())
308HPROC(struct logic_upd_clause *, LogDBErasedMarker, InitLogDBErasedMarker(),
309 RestoreLogDBErasedMarker())
310
311/* Dead clauses and IDB entries */
312H_R(struct static_clause *, DeadStaticClauses, RestoreDeadStaticClauses())
313H_R(struct static_mega_clause *, DeadMegaClauses, RestoreDeadMegaClauses())
314H_R(struct static_index *, DeadStaticIndices, RestoreDeadStaticIndices())
315H_R(struct logic_upd_clause *, DBErasedList, RestoreDBErasedList())
316H_R(struct logic_upd_index *, DBErasedIList, RestoreDBErasedIList())
317#if defined(YAPOR) || defined(THREADS)
318HMLOCK(lockvar, DeadStaticClausesLock)
319HMLOCK(lockvar, DeadMegaClausesLock)
320HMLOCK(lockvar, DeadStaticIndicesLock)
321#endif
322
323#ifdef COROUTINING
324/* number of attribute modules */
325HI(int, NUM_OF_ATTS, 1)
326/* initialised by memory allocator */
327HI(UInt, Yap_AttsSize, 0)
328#endif
329
330/* Operators */
331HM(struct operator_entry *, OpList, NULL, OpListAdjust)
332
333/* foreign code loaded */
334HM(struct ForeignLoadItem *, ForeignCodeLoaded, NULL, RestoreForeignCode())
335HI(ADDR, ForeignCodeBase, NULL)
336HI(ADDR, ForeignCodeTop, NULL)
337HI(ADDR, ForeignCodeMax, NULL)
338
339/* recorded terms */
340HM(struct record_list *, Yap_Records, NULL, RestoreYapRecords())
341
342/* SWI atoms and functors */
343HPROC(struct atom_entry *, SWI_Atoms, InitSWIAtoms(), RestoreSWIAtoms())
344HSPACE(struct functor_entry *, SWI_Functors)
345
346HSPACEN(struct swi_reverse_hash, N_SWI_HASH, SWI_ReverseHash)
347
348/* integer access to atoms */
349HSPACE(Int, AtomTranslations)
350HSPACE(Int, MaxAtomTranslations)
351
352// initialization: tell whether the system has been initialised and by whom.
353HI(int, Initialised, false)
354HI(int, InitialisedFromPL, false)
355HI(int, PL_Argc, 0)
356HI(char **, PL_Argv, NULL)
357HI(bool, FAST_BOOT_FLAG, false)
358
359// halt hooks
360HI(struct halt_hook *, HaltHooks, NULL)
361HI(fptr_t, JIT_finalizer, NULL)
362
363// stack overflow expansion/gc control
364HI(int, AllowLocalExpansion, true)
365HI(int, AllowGlobalExpansion, true)
366HI(int, AllowTrailExpansion, true)
367HI(UInt, SizeOfOverflow, 0)
368
369// amount of space recovered in all garbage collections
370HI(UInt, AGcThreshold, 10000)
371HI(Agc_hook, AGCHook, NULL)
372
373/* integer access to functors */
374HSPACE(Int, FunctorTranslations)
375HSPACE(Int, MaxFunctorTranslations)
376
377HPROCN(Atom, MAX_EMPTY_WAKEUPS, EmptyWakeups, InitEmptyWakeups(),
378 RestoreEmptyWakeups())
379HSPACE(int, MaxEmptyWakeups)
380
381/* SWI blobs */
382HM(struct YAP_blob_t *, BlobTypes, NULL, RestoreBlobTypes())
383HM(struct AtomEntryStruct *, Blobs, NULL, RestoreBlobs())
384HI(UInt, NOfBlobs, 0)
385
386HI(UInt, NOfBlobsMax, 256)
387#if defined(YAPOR) || defined(THREADS)
388HMLOCK(lockvar blobs_lock, Blobs_Lock)
389#endif
390
391#if __ANDROID__
392// no need to perform initialization, it is done before we start the Prolog
393// engine.
394HI(struct AAssetManager *, assetManager, NULL)
395HI(char *, AssetsWD, NULL)
396#endif
397
398/* multi-thread support */
399#if THREADS
400/* number of threads and processes in system */
401HI(UInt, NOfThreads, 1)
402/* number of threads created since start */
403HI(UInt, NOfThreadsCreated, 1)
404/* total run time for dead threads */
405HI(UInt, ThreadsTotalTime, 0L)
406// Threads Array
407HI(lockvar, ThreadHandlesLock, MkLock)
408#endif
409
410#if defined(YAPOR) || defined(THREADS)
411// protect long critical regions
412HI(lockvar, BGL, MkLock)
413#endif
414
415#if defined(YAPOR) || defined(TABLING)
416HSPACE(struct global_optyap_data, optyap_data)
417#endif /* YAPOR || TABLING */
418
419// whether Yap is responsible for signal handling
420
421HSPACE(int, PrologShouldHandleInterrupts)
422
423/* This is the guy who actually started the system, and who has the correct
424 * registers */
425#if defined(THREADS)
426HSPACE(pthread_t, master_thread)
427HI(struct thread_mbox *, named_mboxes, NULL)
428HI(lockvar, mboxq_lock, MkLock)
429HI(UInt, mbox_count, 0)
430HSPACE(struct swi_mutex *, WithMutex)
431#endif /* THREADS */
432
433// streams
434HSPACE(struct stream_desc *, Stream)
435#if defined(THREADS) || defined(YAPOR)
436HI(lockvar, StreamDescLock MkLock)
437#endif
438
439// access to yap initial arguments
440HSPACE(char **, argv)
441HSPACE(int, argc)
442
443// extensions to Terms
444#ifdef COROUTINING
445/* array with the ops for your favourite extensions */
446HSPACEN(ext_op, attvars_ext + 1, attas)
447#endif
448
449// agc.c
450HSPACE(int, agc_calls)
451HSPACE(YAP_ULONG_LONG, agc_collected)
452/* total time spent in GC */
453HI(Int, tot_agc_time, 0)
454/* number of heap objects in all garbage collections */
455HI(Int, tot_agc_recovered, 0)
456
457// arrays.c
458#if HAVE_MMAP
459HI(struct MMAP_ARRAY_BLOCK *, mmap_arrays, NULL)
460#endif
461
462#ifdef DEBUG
463// computils.c
464HSPACEN(char, 20, Option)
465HSPACE(YP_FILE *, logfile)
466// init.c
467// int , output_msg , false
468#endif
469
470#if defined(COFF) || defined(A_OUT)
471// loada_coff.c && load_aout.c
472HSPACEN(char, Executable, MAX_PATH)
473#endif
474
475HI(int, OpaqueHandlersCount, 0)
476HI(struct opaque_handler_struct *, OpaqueHandlers, NULL)
477
478#if __simplescalar__
479HSPACEN(char, pwd, MAX_PATH)
480#endif
481
482// udi.c
483// struct udi_control_block , RtreeCmd, void,
484
485HSPACE(char *, RestoreFile)
486
487// gprof.c
488HSPACE(Int, ProfCalls)
489HSPACE(Int, ProfGCs)
490HSPACE(Int, ProfHGrows)
491HSPACE(Int, ProfSGrows)
492HSPACE(Int, ProfMallocs)
493HSPACE(Int, ProfIndexing)
494HSPACE(Int, ProfOn)
495HSPACE(Int, ProfOns)
496HSPACE(struct RB_red_blk_node *, ProfilerRoot)
497HSPACE(struct RB_red_blk_node *, ProfilerNil)
498HI(char *, DIRNAME, NULL)
499#if LOW_PROF
500HI(int, ProfilerOn, false)
501HI(FILE *, FProf, NULL)
502HI(FILE *, FPreds, NULL)
503#endif /* LOW_PROF */
504
505// Mutexes
506#if THREADS
507HI(struct swi_mutex *, FreeMutexes, NULL)
508HI(struct swi_mutex *, mutex_backbone, NULL)
509HSPACEN(struct swi_reverse_hash, N_SWI_HASH. SWI_ReverseHash
510HI(lockvar, MUT_ACCESS, MkLock)
511#endif
512
513HI(char *, Home, NULL)
514
515/* ISO char conversion: I will make no comments */
516HI(char *, CharConversionTable, NULL)
517HI(char *, CharConversionTable2, NULL)
518
519/* time */
520HI(void *, LastWTimePtr, NULL)
521
522/* max priority */
523HI(int, MaxPriority, 1200)
524
525
526INLINE_ONLY int
527Yap_has_a_signal__ (USES_REGS1)
528{
529 return LOCAL_Signals != ((uint64_t)0);
530}
531
532INLINE_ONLY int
533Yap_has_signal__(yap_signals sig USES_REGS)
534{
535 return (LOCAL_Signals & SIGNAL_TO_BIT(sig)) != ((uint64_t)0);
536}
537
538INLINE_ONLY int
539Yap_only_has_signal__(yap_signals sig USES_REGS)
540{
541 return (LOCAL_Signals & SIGNAL_TO_BIT(sig)) == SIGNAL_TO_BIT(sig);
542}
543
Definition: alloc.h:63
void Yap_InitFlags(bool bootstrap)
Init System Prolog flags.
Definition: flags.c:2002
@ argv
read-only atom, it describes the list with all arguments received by YAP at boot
Definition: YapGFlagInfo.h:89
@ profiling
profiling
Definition: YapGFlagInfo.h:479
@ call_counting
Predicates compiled with this flag set maintain a counter on the numbers of proceduree calls and of r...
Definition: YapLFlagInfo.h:56
Definition: YapHeap.h:81
Definition: TermExt.h:99
Module property: low-level data used to manage modes.
Definition: Yatom.h:209
Definition: Yatom.h:295
Definition: Yatom.h:544
Definition: amidefs.h:264
a flag is represented as a Prolog term
Definition: YapFlags.h:189