-/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2008-2018 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
This file is part of the GNU Transactional Memory Library (libitm).
#include <stdlib.h>
#include <string.h>
#include <unwind.h>
-#include "local_type_traits"
+#include "local_atomic"
+
+/* Don't require libgcc_s.so for exceptions. */
+extern void _Unwind_DeleteException (_Unwind_Exception*) __attribute__((weak));
+
#include "common.h"
using namespace std;
-// A helper template for accessing an unsigned integral of SIZE bytes.
-template<size_t SIZE> struct sized_integral { };
-template<> struct sized_integral<1> { typedef uint8_t type; };
-template<> struct sized_integral<2> { typedef uint16_t type; };
-template<> struct sized_integral<4> { typedef uint32_t type; };
-template<> struct sized_integral<8> { typedef uint64_t type; };
-
typedef unsigned int gtm_word __attribute__((mode (word)));
// These values are given to GTM_restart_transaction and indicate the
#include "target.h"
#include "rwlock.h"
#include "aatree.h"
-#include "cacheline.h"
-#include "stmlock.h"
#include "dispatch.h"
#include "containers.h"
+#ifdef __USER_LABEL_PREFIX__
+# define UPFX UPFX1(__USER_LABEL_PREFIX__)
+# define UPFX1(t) UPFX2(t)
+# define UPFX2(t) #t
+#else
+# define UPFX
+#endif
+
namespace GTM HIDDEN {
+// A log of (de)allocation actions. We defer handling of some actions until
+// a commit of the outermost transaction. We also rely on potentially having
+// both an allocation and a deallocation for the same piece of memory in the
+// log; the order in which such entries are processed does not matter because
+// the actions are not in conflict (see below).
// This type is private to alloc.c, but needs to be defined so that
// the template used inside gtm_thread can instantiate.
struct gtm_alloc_action
{
+ // Iff free_fn_sz is nonzero, it must be used instead of free_fn, and vice
+ // versa.
void (*free_fn)(void *);
+ void (*free_fn_sz)(void *, size_t);
+ size_t sz;
+ // If true, this is an allocation; we discard the log entry on outermost
+ // commit, and deallocate on abort. If false, this is a deallocation and
+ // we deallocate on outermost commit and discard the log entry on abort.
bool allocated;
};
-// This type is private to local.c.
-struct gtm_undolog_entry;
-
struct gtm_thread;
// A transaction checkpoint: data that has to saved and restored when doing
_ITM_transactionId_t id;
uint32_t prop;
uint32_t cxa_catch_count;
- void *cxa_unthrown;
+ unsigned int cxa_uncaught_count;
// We might want to use a different but compatible dispatch method for
// a nested transaction.
abi_dispatch *disp;
void commit(gtm_thread* tx);
};
+// An undo log for writes.
+struct gtm_undolog
+{
+ vector<gtm_word> undolog;
+
+ // Log the previous value at a certain address.
+ // The easiest way to inline this is to just define this here.
+ void log(const void *ptr, size_t len)
+ {
+ size_t words = (len + sizeof(gtm_word) - 1) / sizeof(gtm_word);
+ gtm_word *undo = undolog.push(words + 2);
+ memcpy(undo, ptr, len);
+ undo[words] = len;
+ undo[words + 1] = (gtm_word) ptr;
+ }
+
+ void commit () { undolog.clear(); }
+ size_t size() const { return undolog.size(); }
+
+ // In local.cc
+ void rollback (gtm_thread* tx, size_t until_size = 0);
+};
+
+// An entry of a read or write log. Used by multi-lock TM methods.
+struct gtm_rwlog_entry
+{
+ atomic<gtm_word> *orec;
+ gtm_word value;
+};
+
// Contains all thread-specific data required by the entire library.
// This includes all data relevant to a single transaction. Because most
// thread-specific data is about the current transaction, we also refer to
gtm_jmpbuf jb;
// Data used by local.c for the undo log for both local and shared memory.
- vector<gtm_undolog_entry*> undolog;
+ gtm_undolog undolog;
+
+ // Read and write logs. Used by multi-lock TM methods.
+ vector<gtm_rwlog_entry> readlog;
+ vector<gtm_rwlog_entry> writelog;
// Data used by alloc.c for the malloc/free undo log.
aa_tree<uintptr_t, gtm_alloc_action> alloc_actions;
// Data used by eh_cpp.c for managing exceptions within the transaction.
uint32_t cxa_catch_count;
- void *cxa_unthrown;
+ // If cxa_uncaught_count_ptr is 0, we don't need to roll back exceptions.
+ unsigned int *cxa_uncaught_count_ptr;
+ unsigned int cxa_uncaught_count;
void *eh_in_flight;
// Checkpoints for closed nesting.
// be used for the next iteration of the transaction.
// Only restart_total is reset to zero when the transaction commits, the
// other counters are total values for all previously executed transactions.
+ // restart_total is also used by the HTM fastpath in a different way.
uint32_t restart_reason[NUM_RESTARTS];
uint32_t restart_total;
// If this transaction is inactive, shared_state is ~0. Otherwise, this is
// an active or serial transaction.
- gtm_word shared_state;
+ atomic<gtm_word> shared_state;
// The lock that provides access to serial mode. Non-serialized
- // transactions acquire read locks; a serialized transaction aquires
+ // transactions acquire read locks; a serialized transaction acquires
// a write lock.
- static gtm_rwlock serial_lock;
+ // Accessed from assembly language, thus the "asm" specifier on
+ // the name, avoiding complex name mangling.
+ static gtm_rwlock serial_lock __asm__(UPFX "gtm_serial_lock");
// The head of the list of all threads' transactions.
static gtm_thread *list_of_threads;
void commit_allocations (bool, aa_tree<uintptr_t, gtm_alloc_action>*);
void record_allocation (void *, void (*)(void *));
void forget_allocation (void *, void (*)(void *));
- void drop_references_allocations (const void *ptr)
+ void forget_allocation (void *, size_t, void (*)(void *, size_t));
+ void discard_allocation (const void *ptr)
{
- this->alloc_actions.erase((uintptr_t) ptr);
+ alloc_actions.erase((uintptr_t) ptr);
}
// In beginend.cc
void rollback (gtm_transaction_cp *cp = 0, bool aborting = false);
bool trycommit ();
- void restart (gtm_restart_reason) ITM_NORETURN;
+ void restart (gtm_restart_reason, bool finish_serial_upgrade = false)
+ ITM_NORETURN;
gtm_thread();
~gtm_thread();
// Invoked from assembly language, thus the "asm" specifier on
// the name, avoiding complex name mangling.
-#ifdef __USER_LABEL_PREFIX__
-#define UPFX1(t) UPFX(t)
-#define UPFX(t) #t
- static uint32_t begin_transaction(uint32_t, const gtm_jmpbuf *)
- __asm__(UPFX1(__USER_LABEL_PREFIX__) "GTM_begin_transaction") ITM_REGPARM;
-#else
static uint32_t begin_transaction(uint32_t, const gtm_jmpbuf *)
- __asm__("GTM_begin_transaction") ITM_REGPARM;
-#endif
+ __asm__(UPFX "GTM_begin_transaction") ITM_REGPARM;
// In eh_cpp.cc
+ void init_cpp_exceptions ();
void revert_cpp_exceptions (gtm_transaction_cp *cp = 0);
- // In local.cc
- void commit_undolog (void);
- void rollback_undolog (size_t until_size = 0);
- void drop_references_undolog (const void *, size_t);
-
// In retry.cc
// Must be called outside of transactions (i.e., after rollback).
void decide_retry_strategy (gtm_restart_reason);
// are used.
extern uint64_t gtm_spin_count_var;
-extern "C" uint32_t GTM_longjmp (const gtm_jmpbuf *, uint32_t, uint32_t)
+extern "C" uint32_t GTM_longjmp (uint32_t, const gtm_jmpbuf *, uint32_t)
ITM_NORETURN ITM_REGPARM;
extern "C" void GTM_LB (const void *, size_t) ITM_REGPARM;
extern abi_dispatch *dispatch_serialirr();
extern abi_dispatch *dispatch_serialirr_onwrite();
extern abi_dispatch *dispatch_gl_wt();
+extern abi_dispatch *dispatch_ml_wt();
+extern abi_dispatch *dispatch_htm();
-extern gtm_cacheline_mask gtm_mask_stack(gtm_cacheline *, gtm_cacheline_mask);
} // namespace GTM