Commit graph

269 commits

Author SHA1 Message Date
Daniel Kochmański
da3dc34241 stacks: move the binding stack to a separate structure 2025-05-14 10:53:59 +02:00
Daniel Kochmański
2f9ce70e8f stack frames: dereference directly to env->stack
Previously we've cached the stack base and dereferenced from there, but when the
stack is resized, this reference is invalidated and there is no good fix it in
all frames (we don't store back references).

This commit replaces pointers with indexes, so the stack frame is always
displaced onto the current lisp stack.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
868c3e4d31 core: don't use gc allocator to allocate a runtime environment
When we don't use mprotect (nor guard page), we allocate the memory manually.
This simplifies some code and makes the booting process less intervened with GC.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
72af2d38b0 core: move the first environment initialization before symbols
Also split init_alloc in two passes like init_unixint, so we don't invoke
directly GC_enable. The first pass leaves GC explicitly disabled.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
f49cc7f3fd core: the first environment is statically allocated
This is to avoid circularity between the first environment (and interrupts) and
the garbage collector.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
92772b1afd bytecmp: implement flat closures
This commit replaces capturing whole LEX with an explicit vector of closed
variables. We introduce a set of additional opcodes that deal with closed
entities. Locals are referred as lcl and closed variables as lex.
2025-03-27 22:45:34 +01:00
Daniel Kochmański
1ff274bf08 bytevm: don't use ecl_fdefinition for OP_FUNCTION
The function ecl_fdefinition checks also for lamdbas and whatnot, while all we
need is a lookup in the global namespace for the function name.

This commit also changes how we store SETF function definition -- instead of
maintaining them in a global environment, it is stored along with the symbol.
That saves us from taking a global lock repeatedly.
2025-03-27 22:45:34 +01:00
Daniel Kochmański
d4c20918b9 core: register the finalizer immedietely after allocation
Previously we've registered the finalizer when a symbol was dynamically bound
for the first time; this commit changes that to remove a dependency on GC when
binding special variables.
2025-03-27 22:12:49 +01:00
Daniel Kochmański
f73d4babbd Revert "Merge branch 'remove-small-cons' into 'develop'" 2024-12-15 10:01:30 +00:00
Daniel Kochmański
31fdffa6ab core: remove the "small-cons" feature and build flag 2024-12-06 13:04:34 +00:00
Daniel Kochmański
b577de1495 alloc: add missing field from ecl_symbol to the type descriptor 2024-04-23 19:50:00 +02:00
Mark Shroyer
fcaab573cc Don't enable GC fork() support on Windows
A previous commit unconditionally configures Boehm GC to support fork.
This breaks the Windows MSVC build, producing an error dialog with the
message "Fatal error in GC: fork() handling unsupported".

This commit restricts the call to GC_set_handle_fork to non-Windows
hosts.
2023-10-22 20:22:09 -07:00
Kirill A. Korinsky
fa9221ae6b Enable handle fork by GC 2023-09-25 05:06:55 +00:00
Marius Gerbershagen
1341b79eca alloc_2.d: fix gc configuration for precise gc
The local variables o and c were lost during the refactor in
bd723748d7, re-add them. Also,
the initialization in init_type_info() got moved to the wrong place in
the same refactor, this needs to be called later on.

The function GC_init_explicit_typing is internal to bdwgc and called
automatically in GC_make_descriptor. Therefore, we don't need to call
it during GC initialization.
2023-08-02 17:27:16 +02:00
Daniel Kochmański
90483505bd cleanup: remove unused slot ecl_process.queue_record 2022-11-25 20:44:33 +01:00
Daniel Kochmański
bd723748d7 alloc_2: initialize the type info in a separate function
The initialization is a lengthy function with clear responsibilities separate
from the gc initialization.
2022-11-25 17:07:36 +01:00
Daniel Kochmański
6c2cca684a cleanup: remove lingering references to the old garbage collector 2022-11-24 19:47:26 +01:00
Daniel Kochmański
e53b3d14bd ecl_list1: redefine as a preprocessor macro
This is the same as ecl_cons for all practical purposes so we simply put a
define `#define ecl_list1(x) ecl_cons(x, ECL_NIL)`.
2022-11-24 19:47:26 +01:00
Daniel Kochmański
2bbf490071 alloc_2.d: remove unused code paths
- GBC_BOEHM_OWN_ALLOCATOR is dead for a long time
- undef alloc_object was used the function rename to ecl_alloc_object
- remove mark phase ignored by the preprocessor
2022-11-24 18:54:39 +01:00
Daniel Kochmański
4e9fab94eb ecl_bignum: access the internal object with a macro ecl_bignum
This provides a better data encapsulation and is more portable. Moreover it is
consistent with how we handle other boxed values like ecl_doublefloat.
2022-05-06 10:13:08 +02:00
Marius Gerbershagen
806336ed2e multithreading: read-write-lock improvements
Read-write locks are always provided; if no operating system
primitives exist, emulate them using ordinary locks. Also provide a
Windows implementation.
2021-08-29 17:25:21 +02:00
Marius Gerbershagen
de5d56b4c6 multithreading: replace various synchronization objects by native mutexes
- Spinlocks have been replaced by ordinary locks. Without access to
  the underyling scheduler, spinlocks provide no performace benefit
  and may even be harmful in case of high contention.
- Synchronization of process creation and exiting has been simplified.
  Instead of a spinlock, a barrier and atomic operations we now use
  only a single lock protecting the shared process state and a
  condition variable for implementing process joins.
- Some locks which were implemented using Lisp objects now directly
  use a native mutex.
- Our own mutex implementation has been removed as it is now unused.
2021-08-29 17:23:20 +02:00
Marius Gerbershagen
23a7ade20c multithreading: implement mailboxes using native mutexes
The old implementation was not race condition free. If two threads (A
and B) were writing at the same time while one thread (C) was reading,
the following could happen:

1. thread A increases the write pointer (but does not store the
   message yet)
2. thread B increases the write pointer, stores the message and
   signals thread C
3. thread C tries to read from the location that thread A has not yet
   written to

The new implementation is a simple and obvious solution using a common
mutex and two condition variables for reading/writing. We don't bother
with a (complex) interrupt safe implementation.
2021-08-29 17:23:20 +02:00
Marius Gerbershagen
968083738a multithreading: implement semaphores using native mutexes 2021-08-29 17:23:20 +02:00
Marius Gerbershagen
b332f2c592 multithreading: implement barriers using native mutexes 2021-08-29 17:23:20 +02:00
Marius Gerbershagen
0f737b6ba6 multithreading: implement mutexes and condition variables using OS primitives
Replace slow homegrown mutex implementation by standard OS functions.

We try our best to be interrupt safe, however a completely safe
implementation is impossible (unless one completely removes the ability
to interrupt a thread waiting on a mutex). There is always a window
after the OS specific function has returned, but before we can set
the owner, in which interrupts will see an inconsistent state of the
mutex with regards to owner and count.

Condition variables are now based on OS functions as well. Timed
waiting on condition variables has also been implemented.
2021-08-29 17:23:19 +02:00
Marius Gerbershagen
8a38c9a3c2 remove register storage class specifier
This option is not needed anymore, ignored by modern compilers and has
been removed in the C++17 standard.

Fixes #647.
2021-07-17 12:13:05 +02:00
Marius Gerbershagen
ddb7bb72e9 gc: call finalizer for builtin object only when the object is truly unreachable
Otherwise it can happen that a user-defined finalizer for some object
A storing a builtin object B registers another finalizer for A making
B reachable again while B has already been finalized.

We can't impose an ordering for user-defined finalizers in general
since these may include cyclic references. Therefore it is the duty of
the user to write the finalizers in a consistent way which is
independent of the order in which the finalizers are called. This
doesn't work for builtin objects since the user can't influence
the finalizers in this case.

We also fix a bug which lead to the removal of the standard finalizer
if a user-defined finalizer was registered and then removed.

Co-authored-by: Daniel Kochmański <daniel@turtleware.eu>
2021-06-12 21:26:47 +02:00
Marius Gerbershagen
36a9c95c80 tree-wide: use new dpp @"" specifier for constant base strings where appropriate 2021-03-12 19:53:33 +01:00
Daniel Kochmański
7f1813cd93 ecl_alloc_weak_pointer: don't register immediate objects as disappearing
We have special-cased all immediate objects except ECL_T. Creating such link
leads to a segmentation fault when GC tries to dereference the pointer. Fixes #610.
2020-10-19 16:54:40 +02:00
Marius Gerbershagen
adaeaaf06c gc: fix for finalizers called from non-initialized threads
We can't use the standard functions like cl_list for allocating the
wrapper object for the finalizer since these need a working environment
for disabling interrupts.
2020-08-02 10:55:25 +02:00
Marius Gerbershagen
e0bf0f5ac2 gc: remove unnecessary workarounds for old bdwgc versions 2020-05-10 19:47:05 +02:00
Marius Gerbershagen
d8fbbb213e gc: fix type info for precise garbage collector mode 2020-05-08 21:10:41 +02:00
Marius Gerbershagen
c6b4296bb8 cosmetic: fix some compiler warnings 2020-04-29 20:35:37 +02:00
Daniel Kochmański
b9d54d6be7 internals: rename instance.sig to instance.slotds
Slot definitions are no longer a signature, but they are still needed
to update obsolete instances. Reader function name is also changed to
SI:INSTANCE-SLOTDS. SI:INSTANCE-SIG-SET name does not change, because
it sets both SLOTDS and the STAMP.
2020-04-19 17:04:42 +02:00
Daniel Kochmański
f1bc883ed6 clos: introduce class stamps for marking instances obsolete
We should call make-instances-obsolete from finalize-inheritance if we
want to be conforming, because user may have added their own auxiliary
methods.

This change while being last in a serie of commits was locally the
first change which solved problems. It will enable us to implement the
fast generic dispatch after the release.
2020-04-19 17:04:41 +02:00
Daniel Kochmański
3e0a8c63eb weak-pointer: return two values: value and whenever it is present
We do that to avoid confusion (like with hashtables).
2019-05-25 09:56:08 +02:00
Daniel Kochmański
ea87100a06 long-float: remove conditionalization
Many parts of the source code were bent backward to support builds
without long floats which are always present given we depend expect
c99 compiler.

The corresponding C macros (ECL_LONG_FLOAT) and the *feature*
entry (:long-float) are marked as deprecated in the documentation.
2019-05-24 21:04:59 +00:00
Daniel Kochmański
20a7030277 complex float: add gc boilerplate 2019-05-06 08:17:33 +02:00
Daniel Kochmański
f78cb49def complex float: rename cl_lispunion member complex to gencomplex
Complex is a macro specified in complex.h for c99 to simplify using
_Complex type. This file also contains functions to work on complex
floats. To avoid conflicts we rename internal name complex to
gencomplex and update all references to it.
2019-05-06 08:17:33 +02:00
Daniel Kochmański
3766821b25 cosmetic: indent, line breaks 2019-04-20 22:31:21 +02:00
Marius Gerbershagen
24dcb778cf clean up functions creating base strings from C strings
Make functions behave as documented, remove use of legacy names.
    Fixes #462.
2019-01-07 18:43:55 +01:00
Marius Gerbershagen
b5194ca774 threading: fix interrupt safety of out_of_memory function
This function used writes in the thread local environment while
    interrupts where disabled with the env->disable_interrupts
    mechanism, which causes problems with the mprotect() mechanism for
    fast interrupt dispatch.
2018-09-09 17:06:32 +02:00
Marius Gerbershagen
146b4a6ae1 cosmetic: fixed some typos and style issues 2018-03-26 21:11:11 +02:00
Marius Gerbershagen
a8d7305fb6 threading: fix race condition in stacks_scanner
The garbage collector can call stacks_scanner in a thread before
    pthread_setspecific, leading to a wrong error message. The
    solution is simply not to mark the environment, if
    pthread_setspecific has not yet been called.
2018-02-20 21:40:04 +01:00
Marius Gerbershagen
79b77fc7e5 add another forgotten ecl_enable_interrupts 2018-01-22 21:13:07 +01:00
Daniel Kochmański
2877ffde65 Merge branch 'fix-memory-corruption' into 'develop'
Use bdwgc macros to allow memory debug.

See merge request embeddable-common-lisp/ecl!92
2017-09-19 14:02:08 +00:00
Fabrizio Fabbri
bc522801a9
Use bdwgc macros to allow memory debug. 2017-09-19 00:23:47 -04:00
Marius Gerbershagen
8c2748da17 fix segmentation faults when interrupting a thread while it is exiting
When mp_process_interrupt and thread_cleanup are called at the same
time, it is possible that the thread-local environment is deallocated
while ecl_interrupt_process tries to use it. This two methods thus
need to be protected with a lock.
2017-09-13 18:51:44 +02:00
Kris Katterjohn
5095097a6a Wrap variable definitions in #ifdef's to avoid unused-variable warnings 2017-03-14 15:53:32 -05:00