jni: Add @CriticalNative optimization to speed up JNI transitions
Change-Id: I963059ac3a72dd8e6a867596c356d7062deb6da7
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index f9bc249..1392399 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -335,20 +335,30 @@
}
bool ArtMethod::IsAnnotatedWithFastNative() {
+ return IsAnnotatedWith(WellKnownClasses::dalvik_annotation_optimization_FastNative,
+ DexFile::kDexVisibilityBuild);
+}
+
+bool ArtMethod::IsAnnotatedWithCriticalNative() {
+ return IsAnnotatedWith(WellKnownClasses::dalvik_annotation_optimization_CriticalNative,
+ DexFile::kDexVisibilityBuild);
+}
+
+bool ArtMethod::IsAnnotatedWith(jclass klass, uint32_t visibility) {
Thread* self = Thread::Current();
ScopedObjectAccess soa(self);
StackHandleScope<1> shs(self);
const DexFile& dex_file = GetDeclaringClass()->GetDexFile();
- mirror::Class* fast_native_annotation =
- soa.Decode<mirror::Class*>(WellKnownClasses::dalvik_annotation_optimization_FastNative);
- Handle<mirror::Class> fast_native_handle(shs.NewHandle(fast_native_annotation));
+ mirror::Class* annotation = soa.Decode<mirror::Class*>(klass);
+ DCHECK(annotation->IsAnnotation());
+ Handle<mirror::Class> annotation_handle(shs.NewHandle(annotation));
// Note: Resolves any method annotations' classes as a side-effect.
// -- This seems allowed by the spec since it says we can preload any classes
// referenced by another classes's constant pool table.
- return dex_file.IsMethodAnnotationPresent(this, fast_native_handle, DexFile::kDexVisibilityBuild);
+ return dex_file.IsMethodAnnotationPresent(this, annotation_handle, visibility);
}
bool ArtMethod::EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params) {