1 /* Copyright (C) 2012,2016 Matthew Fluet.
2 * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 const char* objectTypeTagToString (GC_objectTypeTag tag
) {
21 die ("bad GC_objectTypeTag %u", tag
);
27 * Returns a pointer to the header for the object pointed to by p.
29 GC_header
* getHeaderp (pointer p
) {
36 * Returns the header for the object pointed to by p.
38 GC_header
getHeader (pointer p
) {
39 return *(getHeaderp(p
));
43 * Build the header for an object, given the index to its type info.
45 GC_header
buildHeaderFromTypeIndex (uint32_t t
) {
46 assert (t
< TWOPOWER (TYPE_INDEX_BITS
));
50 void splitHeader(GC_state s
, GC_header header
,
51 GC_objectTypeTag
*tagRet
, bool *hasIdentityRet
,
52 uint16_t *bytesNonObjptrsRet
, uint16_t *numObjptrsRet
) {
53 unsigned int objectTypeIndex
;
54 GC_objectType objectType
;
57 uint16_t bytesNonObjptrs
, numObjptrs
;
59 assert (1 == (header
& GC_VALID_HEADER_MASK
));
60 objectTypeIndex
= (header
& TYPE_INDEX_MASK
) >> TYPE_INDEX_SHIFT
;
61 assert (objectTypeIndex
< s
->objectTypesLength
);
62 objectType
= &(s
->objectTypes
[objectTypeIndex
]);
63 tag
= objectType
->tag
;
64 hasIdentity
= objectType
->hasIdentity
;
65 bytesNonObjptrs
= objectType
->bytesNonObjptrs
;
66 numObjptrs
= objectType
->numObjptrs
;
70 "splitHeader ("FMTHDR
")"
71 " objectTypeIndex = %u"
74 " bytesNonObjptrs = %"PRIu16
75 " numObjptrs = %"PRIu16
"\n",
78 objectTypeTagToString(tag
),
79 boolToString(hasIdentity
),
80 bytesNonObjptrs
, numObjptrs
);
84 if (hasIdentityRet
!= NULL
)
85 *hasIdentityRet
= hasIdentity
;
86 if (bytesNonObjptrsRet
!= NULL
)
87 *bytesNonObjptrsRet
= bytesNonObjptrs
;
88 if (numObjptrsRet
!= NULL
)
89 *numObjptrsRet
= numObjptrs
;
92 /* advanceToObjectData (s, p)
94 * If p points at the beginning of an object, then advanceToObjectData
95 * returns a pointer to the start of the object data.
97 pointer
advanceToObjectData (ARG_USED_FOR_ASSERT GC_state s
, pointer p
) {
101 assert (isFrontierAligned (s
, p
));
102 header
= *(GC_header
*)p
;
104 /* Looking at the counter word in an array. */
105 res
= p
+ GC_ARRAY_METADATA_SIZE
;
107 /* Looking at a header word. */
108 res
= p
+ GC_NORMAL_METADATA_SIZE
;
109 assert (isAligned ((uintptr_t)res
, s
->alignment
));
111 fprintf (stderr
, FMTPTR
" = advanceToObjectData ("FMTPTR
")\n",
112 (uintptr_t)res
, (uintptr_t)p
);