Use specific exception class to abort transaction
We used to throw a java.lang.InternalError when aborting a
transaction (when preinitializing image classes at compilation time).
We now use dedicated class dalvik.system.TransactionAbortError that
is only thrown by the compiler to abort a transaction. This class has
constructors taking a java.lang.Throwable "cause" so we can wrap
exceptions causing the transaction to abort (for instance class
java.lang.ClassNotFoundException) and give more information about the
cause of the transaction abort.
Bug: 20019689
Change-Id: I019a72a1c754d8bba6a7ad6bb0f02e4fd6668622
diff --git a/runtime/transaction.cc b/runtime/transaction.cc
index 186cfea..5b8d23b 100644
--- a/runtime/transaction.cc
+++ b/runtime/transaction.cc
@@ -60,8 +60,8 @@
void Transaction::Abort(const std::string& abort_message) {
MutexLock mu(Thread::Current(), log_lock_);
- // We may abort more than once if the java.lang.InternalError thrown at the
- // time of the abort has been caught during execution of a class initializer.
+ // We may abort more than once if the exception thrown at the time of the
+ // previous abort has been caught during execution of a class initializer.
// We just keep the message of the first abort because it will cause the
// transaction to be rolled back anyway.
if (!aborted_) {
@@ -70,16 +70,17 @@
}
}
-void Transaction::ThrowInternalError(Thread* self, bool rethrow) {
+void Transaction::ThrowAbortError(Thread* self, bool rethrow) {
if (kIsDebugBuild && rethrow) {
- CHECK(IsAborted()) << "Rethrow InternalError while transaction is not aborted";
+ CHECK(IsAborted()) << "Rethrow " << Transaction::kAbortExceptionDescriptor
+ << " while transaction is not aborted";
}
std::string abort_msg(GetAbortMessage());
// Temporary workaround for b/20019689.
if (self->IsExceptionPending()) {
self->ClearException();
}
- self->ThrowNewException("Ljava/lang/InternalError;", abort_msg.c_str());
+ self->ThrowNewException(Transaction::kAbortExceptionSignature, abort_msg.c_str());
}
bool Transaction::IsAborted() {