Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / thread.c
1 /* Copyright (C) 2016 Matthew Fluet.
2 * Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
5 *
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
8 */
9
10 void displayThread (GC_state s,
11 GC_thread thread,
12 FILE *stream) {
13 fprintf(stream,
14 "\t\texnStack = %"PRIuMAX"\n"
15 "\t\tbytesNeeded = %"PRIuMAX"\n"
16 "\t\tstack = "FMTOBJPTR"\n",
17 (uintmax_t)thread->exnStack,
18 (uintmax_t)thread->bytesNeeded,
19 thread->stack);
20 displayStack (s, (GC_stack)(objptrToPointer (thread->stack, s->heap.start)),
21 stream);
22 }
23
24 size_t sizeofThread (GC_state s) {
25 size_t res;
26
27 res = GC_NORMAL_METADATA_SIZE + sizeof (struct GC_thread);
28 res = align (res, s->alignment);
29 if (DEBUG) {
30 size_t check;
31 uint16_t bytesNonObjptrs, numObjptrs;
32
33 splitHeader (s, GC_THREAD_HEADER, NULL, NULL, &bytesNonObjptrs, &numObjptrs);
34 check = GC_NORMAL_METADATA_SIZE + (bytesNonObjptrs + (numObjptrs * OBJPTR_SIZE));
35 if (DEBUG_DETAILED)
36 fprintf (stderr,
37 "sizeofThread: res = %"PRIuMAX" check = %"PRIuMAX"\n",
38 (uintmax_t)res, (uintmax_t)check);
39 assert (check == res);
40 }
41 assert (isAligned (res, s->alignment));
42 return res;
43 }
44
45 size_t offsetofThread (GC_state s) {
46 return (sizeofThread (s)) - (GC_NORMAL_METADATA_SIZE + sizeof (struct GC_thread));
47 }