1 /* Copyright (C) 2016-2017 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.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 size_t sizeofArrayNoMetaData (GC_state s
,
11 GC_arrayLength numElements
,
12 uint16_t bytesNonObjptrs
, uint16_t numObjptrs
) {
15 result
= numElements
* (bytesNonObjptrs
+ (numObjptrs
* OBJPTR_SIZE
));
16 return alignWithExtra (s
, result
, GC_ARRAY_METADATA_SIZE
);
19 size_t sizeofStackNoMetaData (__attribute__ ((unused
)) GC_state s
,
23 result
= sizeof (struct GC_stack
) + stack
->reserved
;
27 void sizeofObjectAux (GC_state s
, pointer p
, size_t* metaDataBytes
, size_t* objectBytes
) {
30 uint16_t bytesNonObjptrs
, numObjptrs
;
32 header
= getHeader (p
);
33 splitHeader (s
, header
, &tag
, NULL
, &bytesNonObjptrs
, &numObjptrs
);
34 if ((NORMAL_TAG
== tag
) or (WEAK_TAG
== tag
)) {
35 *metaDataBytes
= GC_NORMAL_METADATA_SIZE
;
36 *objectBytes
= bytesNonObjptrs
+ (numObjptrs
* OBJPTR_SIZE
);
37 } else if (ARRAY_TAG
== tag
) {
38 *metaDataBytes
= GC_ARRAY_METADATA_SIZE
;
39 *objectBytes
= sizeofArrayNoMetaData (s
, getArrayLength (p
),
40 bytesNonObjptrs
, numObjptrs
);
42 assert (STACK_TAG
== tag
);
43 *metaDataBytes
= GC_STACK_METADATA_SIZE
;
44 *objectBytes
= sizeofStackNoMetaData (s
, (GC_stack
)p
);
48 size_t sizeofObject (GC_state s
, pointer p
) {
49 size_t metaDataBytes
, objectBytes
;
50 sizeofObjectAux(s
, p
, &metaDataBytes
, &objectBytes
);
51 return metaDataBytes
+ objectBytes
;
54 size_t sizeofObjectNoMetaData (GC_state s
, pointer p
) {
55 size_t metaDataBytes
, objectBytes
;
56 sizeofObjectAux(s
, p
, &metaDataBytes
, &objectBytes
);