ART: Improve Constructor.newInstance
Special-case InvokeMethod to be constructor-specific so as to avoid
unnecessary and duplicate checks. Refactor for some code sharing.
Reduces Constructor.newInstance for Integer by approximately 15%
(ten runs of 10000000 invocations, reporting mean per invocation,
host x86-64 optimizing, perf stat numbers are for complete run
and do not exclude, for example, setup and prologue GC):
Before After
(perf stat)
Instructions 2503.4 2149.8
Branches 450.8 384.4
Branch-misses 1.83 0.85
(time)
Time (ns) 335.17 278.58
Bug: 20269715
Test: mmma art
Test: m test-art-host
Change-Id: Id105e542a19d72efaace60ad39fcef5e42dde006
diff --git a/runtime/reflection.h b/runtime/reflection.h
index 4391bcd..74580a2 100644
--- a/runtime/reflection.h
+++ b/runtime/reflection.h
@@ -92,6 +92,14 @@
size_t num_frames = 1)
REQUIRES_SHARED(Locks::mutator_lock_);
+// Special-casing of the above. Assumes that the method is the correct constructor, the class is
+// initialized, and that the receiver is an instance of the class.
+void InvokeConstructor(const ScopedObjectAccessAlreadyRunnable& soa,
+ ArtMethod* constructor,
+ ObjPtr<mirror::Object> receiver,
+ jobject args)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
ALWAYS_INLINE bool VerifyObjectIsClass(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c)
REQUIRES_SHARED(Locks::mutator_lock_);