[trans-mem] Beginning of refactoring

Submitted by Torvald Riegel on June 29, 2011, 9:12 p.m.


Message ID 1309381962.3609.661.camel@triegel.csb
State New
Headers show

Commit Message

Torvald Riegel June 29, 2011, 9:12 p.m.
Patch contains more clean-up: the trycommit, rollback and
registerThrownObject functions in the ABI are unnecessary for how we
support exception handling.

Ok for branch?
commit 79ae722913f40715882b4c7b3fb798306f1ad3ae
Author: Torvald Riegel <triegel@redhat.com>
Date:   Wed Jun 29 23:05:28 2011 +0200

    Removed unnecessary trycommit, rollback, and registerThrownObject ABI functions.


Richard Henderson June 29, 2011, 9:22 p.m.
On 06/29/2011 02:12 PM, Torvald Riegel wrote:
> Patch contains more clean-up: the trycommit, rollback and
> registerThrownObject functions in the ABI are unnecessary for how we
> support exception handling.
> Ok for branch?

Looks good.


Patch hide | download patch | download mbox

diff --git a/libitm/beginend.cc b/libitm/beginend.cc
index 7ed5073..9b16973 100644
--- a/libitm/beginend.cc
+++ b/libitm/beginend.cc
@@ -184,25 +184,12 @@  GTM::gtm_transaction::rollback ()
-_ITM_rollbackTransaction (void)
-  gtm_transaction *tx = gtm_tx();
-  assert ((tx->prop & pr_hasNoAbort) == 0);
-  assert ((tx->state & gtm_transaction::STATE_ABORTING) == 0);
-  tx->rollback ();
-  tx->state |= gtm_transaction::STATE_ABORTING;
 _ITM_abortTransaction (_ITM_abortReason reason)
   gtm_transaction *tx = gtm_tx();
   assert (reason == userAbort);
   assert ((tx->prop & pr_hasNoAbort) == 0);
-  assert ((tx->state & gtm_transaction::STATE_ABORTING) == 0);
   if (tx->state & gtm_transaction::STATE_IRREVOCABLE)
     abort ();
@@ -238,7 +225,7 @@  GTM::gtm_transaction::trycommit ()
 GTM::gtm_transaction::trycommit_and_finalize ()
-  if ((this->state & gtm_transaction::STATE_ABORTING) || trycommit ())
+  if (trycommit ())
       abi_disp()->fini ();
       set_gtm_tx (this->prev);
@@ -252,14 +239,6 @@  GTM::gtm_transaction::trycommit_and_finalize ()
   return false;
-_ITM_tryCommitTransaction (void)
-  gtm_transaction *tx = gtm_tx();
-  assert ((tx->state & gtm_transaction::STATE_ABORTING) == 0);
-  return tx->trycommit ();
 GTM::gtm_transaction::restart (gtm_restart_reason r)
diff --git a/libitm/libitm.h b/libitm/libitm.h
index df89d33..abd4274 100644
--- a/libitm/libitm.h
+++ b/libitm/libitm.h
@@ -45,7 +45,7 @@  extern "C" {
 #define ITM_NORETURN	__attribute__((noreturn))
 #define ITM_PURE __attribute__((transaction_pure))
 /* The following are externally visible definitions and functions, though
    only very few of these should be called by user code.  */
@@ -91,6 +91,7 @@  typedef enum
    pr_RaRBarriersOmitted	= 0x0200,
    pr_undoLogCode		= 0x0400,
    pr_preferUninstrumented	= 0x0800,
+   /* Exception blocks are not used nor supported. */
    pr_exceptionBlock		= 0x1000,
    pr_readOnly			= 0x4000,
    pr_hasElse			= 0x200000,
@@ -138,12 +139,8 @@  extern _ITM_transactionId_t _ITM_getTransactionId(void) ITM_REGPARM;
 extern uint32_t _ITM_beginTransaction(uint32_t, ...) ITM_REGPARM;
 extern void _ITM_abortTransaction(_ITM_abortReason) ITM_REGPARM ITM_NORETURN;
-extern void _ITM_rollbackTransaction (void) ITM_REGPARM;
 extern void _ITM_commitTransaction (void) ITM_REGPARM;
-extern bool _ITM_tryCommitTransaction(void) ITM_REGPARM;
-extern void _ITM_registerThrownObject (const void *, size_t) ITM_REGPARM;
 extern void _ITM_changeTransactionMode (_ITM_transactionState) ITM_REGPARM;
diff --git a/libitm/libitm.map b/libitm/libitm.map
index 0d52a7c..49d0b1b 100644
--- a/libitm/libitm.map
+++ b/libitm/libitm.map
@@ -12,9 +12,6 @@  LIBITM_1.0 {
-	_ITM_registerThrownObject;
-	_ITM_rollbackTransaction;
-	_ITM_tryCommitTransaction;
diff --git a/libitm/libitm.texi b/libitm/libitm.texi
index 8d8de8c..046b0bd 100644
--- a/libitm/libitm.texi
+++ b/libitm/libitm.texi
@@ -221,25 +221,34 @@  reported for the dynamic scope as well, not just for the lexical scope
 (@code{hasNoAbort}). Without this, a library cannot exploit this together
 with flat nesting.
-@strong{TODO} @code{exceptionBlock?}
+@code{exceptionBlock} is not supported because exception blocks are not used.
 @subsubsection [No changes] Windows exception state
 @subsubsection [No changes] Other machine state
-@subsubsection Results from beginTransaction
-@strong{TODO} @code{abortTransaction} supported?
+@subsubsection [No changes] Results from beginTransaction
 @subsection Aborting a transaction
-@strong{TODO} make consistent with EH.
-@subsection Committing a transaction
-@strong{TODO} make consistent with EH.
+@code{_ITM_rollbackTransaction} is not supported. @code{_ITM_abortTransaction}
+is supported but the abort reason @code{exceptionBlockAbort} is not (and there
+are no exception blocks in general, so the related cases also do not have to
+be considered).
-@subsection Exception handling support
+@subsection Committing a transaction
-@strong{TODO} Document wrappers. Document code generated for commit, perhaps
-with examples similar to those in the specification. What can be removed from
-the ABI in turn? Document requirements on libstdc++ (@code{_cxa_tm_cleanup()}).
+The exception handling (EH) scheme is different. The Intel ABI requires the
+@code{_ITM_tryCommitTransaction} function that will return even when the
+commit failed and will have to be matched with calls to either
+@code{_ITM_abortTransaction} or @code{_ITM_commitTransaction}. In contrast,
+gcc relies on transactional wrappers for the functions of the Exception
+Handling ABI and on one additional commit function (shown below). This allows
+the TM to keep track of EH internally and thus it does not have to embed the
+cleanup of EH state into the existing EH code in the program.
+@code{_ITM_tryCommitTransaction} is not supported.
+@code{_ITM_commitTransactionToId} is also not supported because the
+propagation of thrown exceptions will not bypass commits of nested
 void _ITM_commitTransactionEH(void *exc_ptr) ITM_REGPARM;
@@ -249,6 +258,42 @@  void *_ITM_cxa_begin_catch (void *exc_ptr);
 void _ITM_cxa_end_catch (void);
 @end example
+@code{_ITM_commitTransactionEH} must be called to commit a transaction if an
+exception could be in flight at this position in the code. @code{exc_ptr} is
+the current exception or zero if there is no current exception.
+The @code{_ITM_cxa...} functions are transactional wrappers for the respective
+@code{__cxa...} functions and must be called instead of these in transactional
+To support this EH scheme, libstdc++ needs to provide one additional function
+(@code{_cxa_tm_cleanup}), which is used by the TM to clean up the exception
+handling state while rolling back a transaction:
+void __cxa_tm_cleanup (void *unthrown_obj, void *cleanup_exc,
+                       unsigned int caught_count);
+@end example
+@code{unthrown_obj} is non-null if the program called
+@code{__cxa_allocate_exception} for this exception but did not yet called
+@code{__cxa_throw} for it. @code{cleanup_exc} is non-null if the program is
+currently processing a cleanup along an exception path but has not caught this
+exception yet. @code{caught_count} is the nesting depth of
+@code{__cxa_begin_catch} within the transaction (which can be counted by the TM
+using @code{_ITM_cxa_begin_catch} and @code{_ITM_cxa_end_catch});
+@code{__cxa_tm_cleanup} then performs rollback by essentially performing
+@code{__cxa_end_catch} that many times.
+@subsection Exception handling support
+Currently, there is no support for functionality like
+@code{__transaction_cancel throw} as described in the C++ TM specification.
+Supporting this should be possible with the EH scheme explained previously
+because via the transactional wrappers for the EH ABI, the TM is able to
+observe and intercept EH.
 @subsection [No changes] Transition to serial--irrevocable mode
 @subsection [No changes] Data transfer functions
diff --git a/libitm/libitm_i.h b/libitm/libitm_i.h
index d323d45..98c2c75 100644
--- a/libitm/libitm_i.h
+++ b/libitm/libitm_i.h
@@ -146,10 +146,6 @@  struct gtm_transaction
   // Set if the serial-irrevocable dispatch table is installed.
   // Implies that no logging is being done, and abort is not possible.
   static const uint32_t STATE_IRREVOCABLE	= 0x0002;
-  // Set if we're in the process of aborting the transaction.  This is
-  // used when _ITM_rollbackTransaction is called to begin the abort
-  // and ends with _ITM_commitTransaction.
-  static const uint32_t STATE_ABORTING		= 0x0004;
   // A bitmask of the above.
   uint32_t state;