Compare the oat version of runtime, dex2oat and the compiler.

Ensure they match, otherwise we might get confusing crashes.

Bug: 125318570
Test: running ahat-test-dump after oat version bump triggers the check.
Change-Id: If4bc832af50c2cb851054be03c9887f9a3d4d04b
diff --git a/compiler/compiler.cc b/compiler/compiler.cc
index d044c2f..98d7339 100644
--- a/compiler/compiler.cc
+++ b/compiler/compiler.cc
@@ -22,6 +22,7 @@
 #include "base/utils.h"
 #include "dex/code_item_accessors-inl.h"
 #include "dex/dex_file.h"
+#include "oat.h"
 #include "optimizing/optimizing_compiler.h"
 
 namespace art {
@@ -29,6 +30,9 @@
 Compiler* Compiler::Create(const CompilerOptions& compiler_options,
                            CompiledMethodStorage* storage,
                            Compiler::Kind kind) {
+  // Check that oat version when runtime was compiled matches the oat version of the compiler.
+  constexpr std::array<uint8_t, 4> compiler_oat_version = OatHeader::kOatVersion;
+  OatHeader::CheckOatVersion(compiler_oat_version);
   switch (kind) {
     case kQuick:
       // TODO: Remove Quick in options.