#include "gc.h"
#include "gc-internal.h"
#include "thread.h"
+#include "pseudo-atomic.h"
#include "alloc.h"
#include "genesis/vector.h"
#include "genesis/weak-pointer.h"
gen_av_mem_age(i));
}
fprintf(stderr," Total bytes allocated = %lu\n", bytes_allocated);
- fprintf(stderr," Dynamic-space-size bytes = %lu\n", dynamic_space_size);
+ fprintf(stderr," Dynamic-space-size bytes = %u\n", dynamic_space_size);
fpu_restore(fpu_state);
}
int orig_first_page_bytes_used;
long byte_cnt;
int more;
- long bytes_used;
+ unsigned long bytes_used;
page_index_t next_page;
int ret;
void
gc_heap_exhausted_error_or_lose (long available, long requested)
{
+ struct thread *thread = arch_os_get_current_thread();
/* Write basic information before doing anything else: if we don't
* call to lisp this is a must, and even if we do there is always
* the danger that we bounce back here before the error has been
/* If we are in GC, or totally out of memory there is no way
* to sanely transfer control to the lisp-side of things.
*/
- struct thread *thread = arch_os_get_current_thread();
print_generation_stats(1);
fprintf(stderr, "GC control variables:\n");
fprintf(stderr, " *GC-INHIBIT* = %s\n *GC-PENDING* = %s\n",
SymbolValue(GC_INHIBIT,thread)==NIL ? "false" : "true",
- SymbolValue(GC_PENDING,thread)==NIL ? "false" : "true");
+ (SymbolValue(GC_PENDING, thread) == T) ?
+ "true" : ((SymbolValue(GC_PENDING, thread) == NIL) ?
+ "false" : "in progress"));
#ifdef LISP_FEATURE_SB_THREAD
fprintf(stderr, " *STOP-FOR-GC-PENDING* = %s\n",
SymbolValue(STOP_FOR_GC_PENDING,thread)==NIL ? "false" : "true");
else {
/* FIXME: assert free_pages_lock held */
(void)thread_mutex_unlock(&free_pages_lock);
+ gc_assert(get_pseudo_atomic_atomic(thread));
+ clear_pseudo_atomic_atomic(thread);
+ if (get_pseudo_atomic_interrupted(thread))
+ do_pending_interrupt();
+ /* Another issue is that signalling HEAP-EXHAUSTED error leads
+ * to running user code at arbitrary places, even in a
+ * WITHOUT-INTERRUPTS which may lead to a deadlock without
+ * running out of the heap. So at this point all bets are
+ * off. */
+ if (SymbolValue(INTERRUPTS_ENABLED,thread) == NIL)
+ corruption_warning_and_maybe_lose
+ ("Signalling HEAP-EXHAUSTED in a WITHOUT-INTERRUPTS.");
funcall2(StaticSymbolFunction(HEAP_EXHAUSTED_ERROR),
alloc_number(available), alloc_number(requested));
lose("HEAP-EXHAUSTED-ERROR fell through");
}
page_index_t
-gc_find_freeish_pages(page_index_t *restart_page_ptr, long nbytes, int page_type_flag)
+gc_find_freeish_pages(page_index_t *restart_page_ptr, long nbytes,
+ int page_type_flag)
{
page_index_t first_page, last_page;
page_index_t restart_page = *restart_page_ptr;
restart_page = gencgc_alloc_start_page;
}
- if (nbytes>=PAGE_BYTES) {
+ gc_assert(nbytes>=0);
+ if (((unsigned long)nbytes)>=PAGE_BYTES) {
/* Search for a contiguous free space of at least nbytes,
* aligned on a page boundary. The page-alignment is strictly
* speaking needed only for objects at least large_object_size
* probability that random garbage will be bogusly interpreted as
* a pointer which prevents a page from moving. */
if (!(code_page_p(addr_page_index)
- || (is_lisp_pointer(addr) &&
+ || (is_lisp_pointer((lispobj)addr) &&
possibly_valid_dynamic_space_pointer(addr))))
return;
fprintf(stderr,
"/non-movable pages due to conservative pointers = %d (%d bytes)\n",
num_dont_move_pages,
- npage_bytes(num_dont_move_pages);
+ npage_bytes(num_dont_move_pages));
}
#endif
/* set things up so that GC happens when we finish the PA
* section */
SetSymbolValue(GC_PENDING,T,thread);
- if (SymbolValue(GC_INHIBIT,thread) == NIL)
- set_pseudo_atomic_interrupted(thread);
+ if (SymbolValue(GC_INHIBIT,thread) == NIL) {
+ set_pseudo_atomic_interrupted(thread);
+#ifdef LISP_FEATURE_PPC
+ /* PPC calls alloc() from a trap, look up the most
+ * recent one and frob that. */
+ maybe_save_gc_mask_and_block_deferrables
+ (get_interrupt_context_for_thread(thread));
+#else
+ maybe_save_gc_mask_and_block_deferrables(NULL);
+#endif
+ }
}
}
new_obj = gc_alloc_with_region(nbytes, page_type_flag, region, 0);
if ((alloc_signal & FIXNUM_TAG_MASK) == 0) {
if ((signed long) alloc_signal <= 0) {
SetSymbolValue(ALLOC_SIGNAL, T, thread);
- thread_kill(thread->os_thread, SIGPROF);
+ raise(SIGPROF);
} else {
SetSymbolValue(ALLOC_SIGNAL,
alloc_signal - (1 << N_FIXNUM_TAG_BITS),
lispobj *
alloc(long nbytes)
{
+ gc_assert(get_pseudo_atomic_atomic(arch_os_get_current_thread()));
return general_alloc(nbytes, BOXED_PAGE_FLAG);
}
\f
return 0;
} else {
+ int ret;
+ ret = thread_mutex_lock(&free_pages_lock);
+ gc_assert(ret == 0);
if (page_table[page_index].write_protected) {
/* Unprotect the page. */
os_protect(page_address(page_index), PAGE_BYTES, OS_VM_PROT_ALL);
page_index, boxed_region.first_page,
boxed_region.last_page);
}
+ ret = thread_mutex_unlock(&free_pages_lock);
+ gc_assert(ret == 0);
/* Don't worry, we can handle it. */
return 1;
}