From f663e341c550d1aa6f8f587d0ae0dbf7d254ff55 Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Mon, 4 Apr 2016 17:28:59 -0700 Subject: Workaround invokesuper underspecified behavior. The verifier allows invokesuper on a class unrelated to the referring class. However, the runtime uses the vtable of the super class of the referring class to lookup the ArtMethod. Since the receiver has no relation to the referring class, this lead to either jumping to a wrong method, or "luckily" throw a NoSuchMethodError if the vtable index is out of bounds of the super class of the referring class. This changes the runtime behavior to always throw NoSuchMethodError when hitting such invokesuper. Also, we make the verifier consistent with the runtime by treating such calls unresolved. bug=27627004 Change-Id: I68486501a9625f91679078c5a980b39974ddbf1c --- compiler/optimizing/instruction_builder.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'compiler/optimizing/instruction_builder.cc') diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc index a834216d0c..aaddc01f1f 100644 --- a/compiler/optimizing/instruction_builder.cc +++ b/compiler/optimizing/instruction_builder.cc @@ -721,6 +721,11 @@ ArtMethod* HInstructionBuilder::ResolveMethod(uint16_t method_idx, InvokeType in DCHECK(Runtime::Current()->IsAotCompiler()); return nullptr; } + if (!methods_class->IsAssignableFrom(compiling_class.Get())) { + // We cannot statically determine the target method. The runtime will throw a + // NoSuchMethodError on this one. + return nullptr; + } ArtMethod* actual_method; if (methods_class->IsInterface()) { actual_method = methods_class->FindVirtualMethodForInterfaceSuper( -- cgit v1.2.3-59-g8ed1b