Add initial default method support to Art
This commit starts the process of adding default methods and their
associated pieces to ART.
This adds full support for calling default methods using
invoke-interface and invoke-virtual on objects implementing the
interfaces. Verifier is changed to allow this when the runtime is
started with -Xexperimental:default-methods.
This also adds support for defining and calling static methods on
interface classes with invoke-static.
Directly calling overridden default methods using invoke-super is not
yet supported.
This adds 5 new run-tests for this functionality.
Bug: 24618811
Change-Id: I35ca800d99d3329348b277789b70ceeeba6e7f03
diff --git a/runtime/dex_file_verifier.cc b/runtime/dex_file_verifier.cc
index 09416cc..a5f9d09 100644
--- a/runtime/dex_file_verifier.cc
+++ b/runtime/dex_file_verifier.cc
@@ -23,7 +23,9 @@
#include "base/stringprintf.h"
#include "dex_file-inl.h"
+#include "experimental_flags.h"
#include "leb128.h"
+#include "runtime.h"
#include "safe_map.h"
#include "utf-inl.h"
#include "utils.h"
@@ -2530,7 +2532,14 @@
}
// Only the static initializer may have code in an interface.
- if (((class_access_flags & kAccInterface) != 0) && !is_clinit_by_name) {
+ // TODO We should have some way determine whether to allow this experimental flag without the
+ // runtime being started.
+ // We assume experimental flags are enabled when running without a runtime to enable tools like
+ // dexdump to handle dex files with these features.
+ if (((class_access_flags & kAccInterface) != 0)
+ && !is_clinit_by_name
+ && Runtime::Current() != nullptr
+ && !Runtime::Current()->AreExperimentalFlagsEnabled(ExperimentalFlags::kDefaultMethods)) {
*error_msg = StringPrintf("Non-clinit interface method %" PRIu32 " should not have code",
method_index);
return false;