/** * Dealloc memory from an ecma-object */ inline void JERRY_ATTR_ALWAYS_INLINE ecma_dealloc_object (ecma_object_t *object_p) /**< object to be freed */ { #ifdef JMEM_STATS jmem_stats_free_object_bytes (sizeof (ecma_object_t)); #endif /* JMEM_STATS */ jmem_pools_free (object_p, sizeof (ecma_object_t)); } /* ecma_dealloc_object */
/** * Dealloc memory from ecma-string descriptor */ inline void JERRY_ATTR_ALWAYS_INLINE ecma_dealloc_string (ecma_string_t *string_p) /**< string to be freed */ { #ifdef JMEM_STATS jmem_stats_free_string_bytes (sizeof (ecma_string_t)); #endif /* JMEM_STATS */ jmem_pools_free (string_p, sizeof (ecma_string_t)); } /* ecma_dealloc_string */
/** * Free property values and change their type to deleted. */ void ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to */ jmem_cpointer_t name_cp, /**< name of the property or ECMA_NULL_POINTER */ ecma_property_t *property_p) /**< property */ { JERRY_ASSERT (object_p != NULL && property_p != NULL); switch (ECMA_PROPERTY_GET_TYPE (*property_p)) { case ECMA_PROPERTY_TYPE_NAMEDDATA: { if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_STRING_CONTAINER_MAGIC_STRING) { if (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE || name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER) { ecma_free_native_pointer (property_p); break; } } ecma_free_value_if_not_object (ECMA_PROPERTY_VALUE_PTR (property_p)->value); break; } case ECMA_PROPERTY_TYPE_NAMEDACCESSOR: { #ifdef JERRY_CPOINTER_32_BIT ecma_getter_setter_pointers_t *getter_setter_pair_p; getter_setter_pair_p = ECMA_GET_POINTER (ecma_getter_setter_pointers_t, ECMA_PROPERTY_VALUE_PTR (property_p)->getter_setter_pair_cp); jmem_pools_free (getter_setter_pair_p, sizeof (ecma_getter_setter_pointers_t)); #endif /* JERRY_CPOINTER_32_BIT */ break; } default: { JERRY_UNREACHABLE (); return; } } if (ecma_is_property_lcached (property_p)) { ecma_lcache_invalidate (object_p, name_cp, property_p); } if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_PROPERTY_NAME_TYPE_STRING) { ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, name_cp); ecma_deref_ecma_string (prop_name_p); } *property_p = ECMA_PROPERTY_TYPE_DELETED; } /* ecma_free_property */
int main () { TEST_INIT (); jmem_init (); for (uint32_t i = 0; i < test_iters; i++) { const size_t subiters = ((size_t) rand () % TEST_MAX_SUB_ITERS) + 1; for (size_t j = 0; j < subiters; j++) { ptrs[j] = (uint8_t *) jmem_pools_alloc (); if (ptrs[j] != NULL) { for (size_t k = 0; k < JMEM_POOL_CHUNK_SIZE; k++) { ptrs[j][k] = (uint8_t) (rand () % 256); } memcpy (data[j], ptrs[j], JMEM_POOL_CHUNK_SIZE); } } /* jmem_heap_print (false); */ for (size_t j = 0; j < subiters; j++) { if (rand () % 256 == 0) { jmem_pools_collect_empty (); } if (ptrs[j] != NULL) { JERRY_ASSERT (!memcmp (data[j], ptrs[j], JMEM_POOL_CHUNK_SIZE)); jmem_pools_free (ptrs[j]); } } } #ifdef JMEM_STATS jmem_pools_stats_print (); #endif /* JMEM_STATS */ jmem_finalize (false); return 0; } /* main */
/** * Dealloc memory from an ecma-number */ void ecma_dealloc_number (ecma_number_t *number_p) /**< number to be freed */ { jmem_pools_free ((uint8_t *) number_p, sizeof (ecma_number_t)); } /* ecma_dealloc_number */