| 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. |
| 5 | * |
| 6 | * MLton is released under a BSD-style license. |
| 7 | * See the file MLton-LICENSE for details. |
| 8 | */ |
| 9 | |
| 10 | size_t sizeofArrayNoMetaData (GC_state s, |
| 11 | GC_arrayLength numElements, |
| 12 | uint16_t bytesNonObjptrs, uint16_t numObjptrs) { |
| 13 | size_t result; |
| 14 | |
| 15 | result = numElements * (bytesNonObjptrs + (numObjptrs * OBJPTR_SIZE)); |
| 16 | return alignWithExtra (s, result, GC_ARRAY_METADATA_SIZE); |
| 17 | } |
| 18 | |
| 19 | size_t sizeofStackNoMetaData (__attribute__ ((unused)) GC_state s, |
| 20 | GC_stack stack) { |
| 21 | size_t result; |
| 22 | |
| 23 | result = sizeof (struct GC_stack) + stack->reserved; |
| 24 | return result; |
| 25 | } |
| 26 | |
| 27 | void sizeofObjectAux (GC_state s, pointer p, size_t* metaDataBytes, size_t* objectBytes) { |
| 28 | GC_header header; |
| 29 | GC_objectTypeTag tag; |
| 30 | uint16_t bytesNonObjptrs, numObjptrs; |
| 31 | |
| 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); |
| 41 | } else { /* Stack. */ |
| 42 | assert (STACK_TAG == tag); |
| 43 | *metaDataBytes = GC_STACK_METADATA_SIZE; |
| 44 | *objectBytes = sizeofStackNoMetaData (s, (GC_stack)p); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | size_t sizeofObject (GC_state s, pointer p) { |
| 49 | size_t metaDataBytes, objectBytes; |
| 50 | sizeofObjectAux(s, p, &metaDataBytes, &objectBytes); |
| 51 | return metaDataBytes + objectBytes; |
| 52 | } |
| 53 | |
| 54 | size_t sizeofObjectNoMetaData (GC_state s, pointer p) { |
| 55 | size_t metaDataBytes, objectBytes; |
| 56 | sizeofObjectAux(s, p, &metaDataBytes, &objectBytes); |
| 57 | return objectBytes; |
| 58 | } |