ART: Fix finalizable class in Unstarted Runtime
Add a finalizable check for emulation of Class.newInstance, as this
is not allowed in transactional mode.
Change-Id: I9633929bf484ac8807b97209ab4b422c320b04da
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 6ea3f25..95f3357 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -144,6 +144,22 @@
StackHandleScope<3> hs(self); // Class, constructor, object.
mirror::Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
Handle<mirror::Class> h_klass(hs.NewHandle(klass));
+
+ // Check that it's not null.
+ if (h_klass.Get() == nullptr) {
+ AbortTransactionOrFail(self, "Class reference is null for newInstance");
+ return;
+ }
+
+ // If we're in a transaction, class must not be finalizable (it or a superclass has a finalizer).
+ if (Runtime::Current()->IsActiveTransaction()) {
+ if (h_klass.Get()->IsFinalizable()) {
+ AbortTransaction(self, "Class for newInstance is finalizable: '%s'",
+ PrettyClass(h_klass.Get()).c_str());
+ return;
+ }
+ }
+
// There are two situations in which we'll abort this run.
// 1) If the class isn't yet initialized and initialization fails.
// 2) If we can't find the default constructor. We'll postpone the exception to runtime.