Skip to content
Snippets Groups Projects
Commit 9096dd40 authored by Duncan Coutts's avatar Duncan Coutts Committed by Reinier Maas
Browse files

Define HEAP_ALLOCED for CMM code

Allow rts/sm/HeapAlloc.h to be #included by CMM code and have it provide
a suitable implementation of HEAP_ALLOCED.

The HEAP_ALLOCED system has three implementations, the large address
space case, two fallbakc impls, one for 32bit and one for 64bit. The
first two are simple enough that we can provide a HEAP_ALLOCED macro
that can be used in a CMM expression context.

The 64bit fallback case is rather more tricky. We provide a different
interface to HEAP_ALLOCED for this case, which has to be called in a
statement/"callish" style.
parent 2d5d85ce
No related branches found
No related tags found
No related merge requests found
......@@ -8,3 +8,4 @@
#include "Capability.h"
#include "WSDeque.h"
#include "SMPClosureOps.h"
#include "sm/HeapAlloc.h"
......@@ -56,6 +56,9 @@ extern SpinLock gc_alloc_block_sync;
#if defined(USE_LARGE_ADDRESS_SPACE)
#if !defined(CMINUSMINUS)
// If this struct is changed, the CMM macro below must be adjusted to match.
struct mblock_address_range {
W_ begin, end;
W_ padding[6]; // ensure nothing else inhabits this cache line
......@@ -66,7 +69,19 @@ extern struct mblock_address_range mblock_address_space;
(W_)(p) < (mblock_address_space.end))
# define HEAP_ALLOCED_GC(p) HEAP_ALLOCED(p)
#else /* defined(CMINUSMINUS) */
import mblock_address_space;
# define HEAP_ALLOCED(p) ((p) >= W_[mblock_address_space + WDS(0)] && \
(p) < W_[mblock_address_space + WDS(1)])
#endif
#elif SIZEOF_VOID_P == 4
#if !defined(CMINUSMINUS)
extern StgWord8 mblock_map[];
# define MBLOCK_MAP_SIZE (1 << (32 - MBLOCK_SHIFT))
......@@ -74,6 +89,15 @@ extern StgWord8 mblock_map[];
# define HEAP_ALLOCED(p) mblock_map[MBLOCK_MAP_ENTRY(p)]
# define HEAP_ALLOCED_GC(p) HEAP_ALLOCED(p)
#else /* defined(CMINUSMINUS) */
import mblock_map;
# define MBLOCK_MAP_ENTRY(p) ((p) >> MBLOCK_SHIFT)
# define HEAP_ALLOCED(p) I8[mblock_map + MBLOCK_MAP_ENTRY(p)]
#endif
/* -----------------------------------------------------------------------------
HEAP_ALLOCED for 64-bit machines (without LARGE_ADDRESS_SPACE).
......@@ -130,11 +154,13 @@ extern StgWord8 mblock_map[];
---------------------------------------------------------------------------- */
#elif SIZEOF_VOID_P == 8
#elif SIZEOF_VOID_P == 8 /* && !defined(USE_LARGE_ADDRESS_SPACE) */
#define MBC_LINE_BITS 0
#define MBC_TAG_BITS 15
#if !defined(CMINUSMINUS)
#if defined(x86_64_HOST_ARCH)
// 32bits are enough for 'entry' as modern amd64 boxes have
// only 48bit sized virtual address.
......@@ -168,7 +194,7 @@ extern W_ mpc_misses;
StgBool HEAP_ALLOCED_miss(StgWord mblock, const void *p);
INLINE_HEADER
EXTERN_INLINE
StgBool HEAP_ALLOCED(const void *p)
{
StgWord mblock;
......@@ -222,6 +248,19 @@ StgBool HEAP_ALLOCED_GC(const void *p)
}
}
#else /* defined(CMINUSMINUS) */
// This is a call to HEAP_ALLOCED C function defined above. That function is reified via the
// Inlines.c file. Since the implementation that can't use USE_LARGE_ADDRESS_SPACE is big and
// complicated we prevent duplicating it's logic. We define the interface to be used in a statement
// "callish op" style.
#define HEAP_ALLOCED_CALLISH(result, p) \
CInt r; \
(r) = ccall HEAP_ALLOCED(p "ptr"); \
result = TO_W_(r); \
#endif
#else
# error HEAP_ALLOCED not defined
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment