10#ifndef ATERMPP_DETAIL_ATERM_POOL_IMPLEMENTATION_H
11#define ATERMPP_DETAIL_ATERM_POOL_IMPLEMENTATION_H
36 m_appl_dynamic_storage(*this)
52 const std::size_t arity = sym.
arity();
121 std::get<0>(
m_appl_storage).print_performance_stats(
"term_storage");
122 std::get<1>(
m_appl_storage).print_performance_stats(
"function_application_storage_1");
123 std::get<2>(
m_appl_storage).print_performance_stats(
"function_application_storage_2");
124 std::get<3>(
m_appl_storage).print_performance_stats(
"function_application_storage_3");
125 std::get<4>(
m_appl_storage).print_performance_stats(
"function_application_storage_4");
126 std::get<5>(
m_appl_storage).print_performance_stats(
"function_application_storage_5");
127 std::get<6>(
m_appl_storage).print_performance_stats(
"function_application_storage_6");
128 std::get<7>(
m_appl_storage).print_performance_stats(
"function_application_storage_7");
135 local->print_local_performance_statistics();
210 auto timestamp = std::chrono::system_clock::now();
211 std::size_t old_size =
size();
230 auto mark_duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timestamp).count();
231 timestamp = std::chrono::system_clock::now();
260 auto sweep_duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timestamp).count();
264 << mark_duration + sweep_duration <<
" ms (marking " << mark_duration <<
" ms + sweep " << sweep_duration <<
" ms).\n";
302template<
class ...Terms>
305 if constexpr (
sizeof...(Terms) <= 7)
307 return std::get<
sizeof...(Terms)>(
m_appl_storage).create_appl(term, sym, arguments...);
317template<
typename ForwardIterator>
320 ForwardIterator begin,
323 const std::size_t arity = sym.
arity();
330 return std::get<1>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
332 return std::get<2>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
334 return std::get<3>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
336 return std::get<4>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
338 return std::get<5>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
340 return std::get<6>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
342 return std::get<7>(
m_appl_storage).template create_appl_iterator<ForwardIterator>(term, sym, begin, end);
348template<
typename InputIterator,
typename ATermConverter>
351 ATermConverter converter,
355 const std::size_t arity = sym.
arity();
361 return std::get<1>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
363 return std::get<2>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
365 return std::get<3>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
367 return std::get<4>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
369 return std::get<5>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
371 return std::get<6>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
373 return std::get<7>(
m_appl_storage).template create_appl_iterator<InputIterator, ATermConverter>(term, sym, converter, begin, end);
388 auto timestamp = std::chrono::system_clock::now();
389 std::size_t old_capacity =
capacity();
412 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timestamp).count();
415 << duration <<
" ms.\n";
421 std::size_t result = 0;
425 result +=
pool->protection_set_size();
void print_performance_stats(const char *identifier) const
Prints various performance statistics for this storage.
bool create_int(aterm &term, std::size_t value)
Creates a integral term with the given value.
void resize_if_needed()
Resizes the hash table if necessary.
bool verify_sweep()
Check that all arguments of a term application are marked properly.
void add_deletion_hook(function_symbol sym, term_callback callback)
Add a callback that is triggered whenever a term with the given function symbol is destroyed.
bool create_appl_dynamic(aterm &term, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
std::size_t capacity() const noexcept
bool verify_mark()
Check that all arguments of a term application are marked properly.
void sweep()
sweep Destroys all terms that are not reachable. Requires that mark() was called first.
const function_symbol & as_int() noexcept
void created_term(bool allow_collect, mcrl2::utilities::shared_mutex &mutex)
Triggers garbage collection and resizing when conditions are met.
bool create_appl(aterm &term, const function_symbol &sym, const Terms &... arguments)
Creates a function application with the given function symbol and arguments.
std::atomic< bool > m_enable_garbage_collection
std::atomic< long > m_count_until_resize
void remove_thread_aterm_pool(thread_aterm_pool_interface &pool)
Remove thread specific aterm pool.
std::vector< thread_aterm_pool_interface * > m_thread_pools
The set of local aterm pools.
bool create_int(aterm &term, std::size_t val)
Creates a integral term with the given value.
function_symbol_pool m_function_symbol_pool
Storage for the function symbols.
void collect_impl(mcrl2::utilities::shared_mutex &mutex)
Collect garbage on all storages.
arbitrary_function_application_storage m_appl_dynamic_storage
Storage for term_appl with a dynamic number of arguments larger than 7.
function_symbol create_function_symbol(const std::string &name, const std::size_t arity, const bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity).
aterm_core m_empty_list
Represents an empty list.
void print_performance_statistics() const
Prints various performance statistics for the term pool.
std::atomic< long > m_count_until_collection
Track the number of terms destroyed and reduce the freelist.
void register_thread_aterm_pool(thread_aterm_pool_interface &pool)
Register a thread specific aterm pool.
bool create_term(aterm &term, const function_symbol &sym)
Creates a term with the given function symbol.
std::size_t protection_set_size() const
void collect(mcrl2::utilities::shared_mutex &mutex)
Force garbage collection on all storages.
bool create_appl_dynamic(aterm &term, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Creates a function application with the given function symbol and the arguments as provided by the gi...
mcrl2::utilities::shared_mutex m_shared_mutex
Garbage collection is enabled.
void add_deletion_hook(function_symbol sym, term_callback callback)
Add a callback that is triggered whenever a term with the given function symbol is destroyed.
function_symbol_pool & get_symbol_pool()
std::tuple< term_storage, function_application_storage< 1 >, function_application_storage< 2 >, function_application_storage< 3 >, function_application_storage< 4 >, function_application_storage< 5 >, function_application_storage< 6 >, function_application_storage< 7 > > m_appl_storage
Storage for function applications with a fixed number of arguments.
integer_term_storage m_int_storage
Storage for integral terms.
void resize_if_needed(mcrl2::utilities::shared_mutex &shared)
Resizes all storages if necessary.
std::size_t capacity() const noexcept
The number of terms that can be stored without resizing.
void sweep()
Collect all garbage function symbols.
void resize_if_needed()
Resize the function symbol pool if necessary.
const function_symbol & as_empty_list() noexcept
std::size_t capacity() const noexcept
function_symbol create(const std::string &name, const std::size_t arity, const bool check_for_registered_functions=false)
Creates a function symbol pair (name, arity), returns a pointer to an existing element if this pair i...
A thread specific aterm pool that provides a local interface to the global term pool....
std::size_t arity() const
Return the arity (number of arguments) of the function symbol (function_symbol).
An unprotected term does not change the reference count of the shared term when it is copied or moved...
An exclusive lock guard for the shared_mutex.
This is simply an exclusive lock based on the standard library with the ability to perform no locks w...
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
static constexpr bool EnableGarbageCollectionMetrics
Enable to print garbage collection statistics.
static constexpr bool EnableAggressiveGarbageCollection
Performs garbage collection intensively for testing purposes.
void store_in_argument_array(std::array< unprotected_aterm_core, N > &argument_array, const Args &... args)
The main namespace for the aterm++ library.
void(* term_callback)(const aterm &)