Refactor compiler tests around CompilerDriver.
Introduce CommonCompilerDriverTest and inherit that in tests
that need to use CompilerDriver. This is in preparation for
moving the CompilerDriver to dex2oat/.
Test: m test-art-host-gtest
Change-Id: I46cf0bc1df4327569eef5526eeab0781473173a1
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 0ebaa5f..04c6cc5 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -339,7 +339,10 @@
art_cc_library {
name: "libart-compiler-gtest",
defaults: ["libart-gtest-defaults"],
- srcs: ["common_compiler_test.cc"],
+ srcs: [
+ "common_compiler_driver_test.cc",
+ "common_compiler_test.cc",
+ ],
shared_libs: [
"libartd-compiler",
"libartd-disassembler",
diff --git a/compiler/common_compiler_driver_test.cc b/compiler/common_compiler_driver_test.cc
new file mode 100644
index 0000000..bba2c2f
--- /dev/null
+++ b/compiler/common_compiler_driver_test.cc
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/mman.h>
+
+#include "common_compiler_driver_test.h"
+
+#include "base/casts.h"
+#include "base/timing_logger.h"
+#include "dex/quick_compiler_callbacks.h"
+#include "driver/compiler_driver.h"
+#include "driver/compiler_options.h"
+#include "utils/atomic_dex_ref_map-inl.h"
+
+namespace art {
+
+CommonCompilerDriverTest::CommonCompilerDriverTest() : inaccessible_page_(nullptr) {}
+CommonCompilerDriverTest::~CommonCompilerDriverTest() {}
+
+void CommonCompilerDriverTest::CompileAll(jobject class_loader,
+ const std::vector<const DexFile*>& dex_files,
+ TimingLogger* timings) {
+ TimingLogger::ScopedTiming t(__FUNCTION__, timings);
+ SetDexFilesForOatFile(dex_files);
+
+ compiler_driver_->InitializeThreadPools();
+
+ compiler_driver_->PreCompile(class_loader,
+ dex_files,
+ timings,
+ &compiler_options_->image_classes_,
+ verification_results_.get());
+
+ // Verification results in the `callback_` should not be used during compilation.
+ down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
+ reinterpret_cast<VerificationResults*>(inaccessible_page_));
+ compiler_options_->verification_results_ = verification_results_.get();
+ compiler_driver_->CompileAll(class_loader, dex_files, timings);
+ compiler_options_->verification_results_ = nullptr;
+ down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
+ verification_results_.get());
+
+ compiler_driver_->FreeThreadPools();
+}
+
+void CommonCompilerDriverTest::SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
+ compiler_options_->dex_files_for_oat_file_ = dex_files;
+ compiler_driver_->compiled_classes_.AddDexFiles(dex_files);
+ compiler_driver_->dex_to_dex_compiler_.SetDexFiles(dex_files);
+}
+
+void CommonCompilerDriverTest::ReserveImageSpace() {
+ // Reserve where the image will be loaded up front so that other parts of test set up don't
+ // accidentally end up colliding with the fixed memory address when we need to load the image.
+ std::string error_msg;
+ MemMap::Init();
+ image_reservation_ = MemMap::MapAnonymous("image reservation",
+ reinterpret_cast<uint8_t*>(ART_BASE_ADDRESS),
+ (size_t)120 * 1024 * 1024, // 120MB
+ PROT_NONE,
+ false /* no need for 4gb flag with fixed mmap */,
+ /*reuse=*/ false,
+ /*reservation=*/ nullptr,
+ &error_msg);
+ CHECK(image_reservation_.IsValid()) << error_msg;
+}
+
+void CommonCompilerDriverTest::UnreserveImageSpace() {
+ image_reservation_.Reset();
+}
+
+void CommonCompilerDriverTest::CreateCompilerDriver() {
+ ApplyInstructionSet();
+
+ compiler_options_->image_type_ = CompilerOptions::ImageType::kBootImage;
+ compiler_options_->compile_pic_ = false; // Non-PIC boot image is a test configuration.
+ compiler_options_->SetCompilerFilter(GetCompilerFilter());
+ compiler_options_->image_classes_.swap(*GetImageClasses());
+ compiler_options_->profile_compilation_info_ = GetProfileCompilationInfo();
+ compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
+ compiler_kind_,
+ number_of_threads_,
+ /* swap_fd= */ -1));
+}
+
+void CommonCompilerDriverTest::SetUpRuntimeOptions(RuntimeOptions* options) {
+ CommonCompilerTest::SetUpRuntimeOptions(options);
+
+ QuickCompilerCallbacks* callbacks =
+ new QuickCompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp);
+ callbacks->SetVerificationResults(verification_results_.get());
+ callbacks_.reset(callbacks);
+}
+
+void CommonCompilerDriverTest::SetUp() {
+ CommonCompilerTest::SetUp();
+
+ CreateCompilerDriver();
+
+ // Note: We cannot use MemMap because some tests tear down the Runtime and destroy
+ // the gMaps, so when destroying the MemMap, the test would crash.
+ inaccessible_page_ = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ CHECK(inaccessible_page_ != MAP_FAILED) << strerror(errno);
+}
+
+void CommonCompilerDriverTest::TearDown() {
+ if (inaccessible_page_ != nullptr) {
+ munmap(inaccessible_page_, kPageSize);
+ inaccessible_page_ = nullptr;
+ }
+ image_reservation_.Reset();
+ compiler_driver_.reset();
+
+ CommonCompilerTest::TearDown();
+}
+
+// Get the set of image classes given to the compiler options in CreateCompilerDriver().
+std::unique_ptr<HashSet<std::string>> CommonCompilerDriverTest::GetImageClasses() {
+ // Empty set: by default no classes are retained in the image.
+ return std::make_unique<HashSet<std::string>>();
+}
+
+// Get ProfileCompilationInfo that should be passed to the driver.
+ProfileCompilationInfo* CommonCompilerDriverTest::GetProfileCompilationInfo() {
+ // Null, profile information will not be taken into account.
+ return nullptr;
+}
+
+} // namespace art
diff --git a/compiler/common_compiler_driver_test.h b/compiler/common_compiler_driver_test.h
new file mode 100644
index 0000000..e3354d4
--- /dev/null
+++ b/compiler/common_compiler_driver_test.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_COMPILER_COMMON_COMPILER_DRIVER_TEST_H_
+#define ART_COMPILER_COMMON_COMPILER_DRIVER_TEST_H_
+
+#include <vector>
+
+#include <jni.h>
+
+#include "common_compiler_test.h"
+#include "base/hash_set.h"
+#include "base/mem_map.h"
+
+namespace art {
+
+class CompilerDriver;
+class DexFile;
+class ProfileCompilationInfo;
+class TimingLogger;
+
+class CommonCompilerDriverTest : public CommonCompilerTest {
+ public:
+ CommonCompilerDriverTest();
+ ~CommonCompilerDriverTest();
+
+ void CompileAll(jobject class_loader,
+ const std::vector<const DexFile*>& dex_files,
+ TimingLogger* timings) REQUIRES(!Locks::mutator_lock_);
+
+ void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
+
+ void ReserveImageSpace();
+
+ void UnreserveImageSpace();
+
+ void CreateCompilerDriver();
+
+ protected:
+ void SetUpRuntimeOptions(RuntimeOptions* options) override;
+
+ void SetUp() override;
+ void TearDown() override;
+
+ // Get the set of image classes given to the compiler-driver in SetUp.
+ virtual std::unique_ptr<HashSet<std::string>> GetImageClasses();
+
+ virtual ProfileCompilationInfo* GetProfileCompilationInfo();
+
+ size_t number_of_threads_ = 2u;
+
+ std::unique_ptr<CompilerDriver> compiler_driver_;
+
+ private:
+ MemMap image_reservation_;
+ void* inaccessible_page_;
+};
+
+} // namespace art
+
+#endif // ART_COMPILER_COMMON_COMPILER_DRIVER_TEST_H_
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 2046f4f..2dd6fdd 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -28,9 +28,8 @@
#include "class_linker.h"
#include "compiled_method-inl.h"
#include "dex/descriptors_names.h"
-#include "dex/quick_compiler_callbacks.h"
#include "dex/verification_results.h"
-#include "driver/compiler_driver.h"
+#include "driver/compiled_method_storage.h"
#include "driver/compiler_options.h"
#include "jni/java_vm_ext.h"
#include "interpreter/interpreter.h"
@@ -48,17 +47,8 @@
CommonCompilerTest::CommonCompilerTest() {}
CommonCompilerTest::~CommonCompilerTest() {}
-void CommonCompilerTest::MakeExecutable(ArtMethod* method) {
+void CommonCompilerTest::MakeExecutable(ArtMethod* method, const CompiledMethod* compiled_method) {
CHECK(method != nullptr);
-
- const CompiledMethod* compiled_method = nullptr;
- if (!method->IsAbstract()) {
- mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache();
- const DexFile& dex_file = *dex_cache->GetDexFile();
- compiled_method =
- compiler_driver_->GetCompiledMethod(MethodReference(&dex_file,
- method->GetDexMethodIndex()));
- }
// If the code size is 0 it means the method was skipped due to profile guided compilation.
if (compiled_method != nullptr && compiled_method->GetQuickCode().size() != 0u) {
ArrayRef<const uint8_t> code = compiled_method->GetQuickCode();
@@ -112,32 +102,6 @@
FlushInstructionCache(reinterpret_cast<void*>(base), reinterpret_cast<void*>(base + len));
}
-void CommonCompilerTest::MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader,
- const char* class_name) {
- std::string class_descriptor(DotToDescriptor(class_name));
- Thread* self = Thread::Current();
- StackHandleScope<1> hs(self);
- Handle<mirror::ClassLoader> loader(hs.NewHandle(class_loader));
- ObjPtr<mirror::Class> klass = class_linker_->FindClass(self, class_descriptor.c_str(), loader);
- CHECK(klass != nullptr) << "Class not found " << class_name;
- PointerSize pointer_size = class_linker_->GetImagePointerSize();
- for (auto& m : klass->GetMethods(pointer_size)) {
- MakeExecutable(&m);
- }
-}
-
-// Get the set of image classes given to the compiler options in SetUp.
-std::unique_ptr<HashSet<std::string>> CommonCompilerTest::GetImageClasses() {
- // Empty set: by default no classes are retained in the image.
- return std::make_unique<HashSet<std::string>>();
-}
-
-// Get ProfileCompilationInfo that should be passed to the driver.
-ProfileCompilationInfo* CommonCompilerTest::GetProfileCompilationInfo() {
- // Null, profile information will not be taken into account.
- return nullptr;
-}
-
void CommonCompilerTest::SetUp() {
CommonRuntimeTest::SetUp();
{
@@ -150,13 +114,7 @@
runtime_->SetCalleeSaveMethod(runtime_->CreateCalleeSaveMethod(), type);
}
}
-
- CreateCompilerDriver();
}
- // Note: We cannot use MemMap because some tests tear down the Runtime and destroy
- // the gMaps, so when destroying the MemMap, the test would crash.
- inaccessible_page_ = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- CHECK(inaccessible_page_ != MAP_FAILED) << strerror(errno);
}
void CommonCompilerTest::ApplyInstructionSet() {
@@ -186,29 +144,13 @@
}
}
-void CommonCompilerTest::CreateCompilerDriver() {
- ApplyInstructionSet();
-
- compiler_options_->image_type_ = CompilerOptions::ImageType::kBootImage;
- compiler_options_->compile_pic_ = false; // Non-PIC boot image is a test configuration.
- compiler_options_->SetCompilerFilter(GetCompilerFilter());
- compiler_options_->image_classes_.swap(*GetImageClasses());
- compiler_options_->profile_compilation_info_ = GetProfileCompilationInfo();
- compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
- compiler_kind_,
- number_of_threads_,
- /* swap_fd= */ -1));
-}
-
void CommonCompilerTest::SetUpRuntimeOptions(RuntimeOptions* options) {
CommonRuntimeTest::SetUpRuntimeOptions(options);
compiler_options_.reset(new CompilerOptions);
verification_results_.reset(new VerificationResults(compiler_options_.get()));
- QuickCompilerCallbacks* callbacks =
- new QuickCompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp);
- callbacks->SetVerificationResults(verification_results_.get());
- callbacks_.reset(callbacks);
+
+ ApplyInstructionSet();
}
Compiler::Kind CommonCompilerTest::GetCompilerKind() const {
@@ -220,90 +162,50 @@
}
void CommonCompilerTest::TearDown() {
- compiler_driver_.reset();
- callbacks_.reset();
verification_results_.reset();
compiler_options_.reset();
- image_reservation_.Reset();
- if (inaccessible_page_ != nullptr) {
- munmap(inaccessible_page_, kPageSize);
- inaccessible_page_ = nullptr;
- }
CommonRuntimeTest::TearDown();
}
-void CommonCompilerTest::CompileClass(mirror::ClassLoader* class_loader, const char* class_name) {
- std::string class_descriptor(DotToDescriptor(class_name));
- Thread* self = Thread::Current();
- StackHandleScope<1> hs(self);
- Handle<mirror::ClassLoader> loader(hs.NewHandle(class_loader));
- ObjPtr<mirror::Class> klass = class_linker_->FindClass(self, class_descriptor.c_str(), loader);
- CHECK(klass != nullptr) << "Class not found " << class_name;
- auto pointer_size = class_linker_->GetImagePointerSize();
- for (auto& m : klass->GetMethods(pointer_size)) {
- CompileMethod(&m);
- }
-}
-
void CommonCompilerTest::CompileMethod(ArtMethod* method) {
CHECK(method != nullptr);
TimingLogger timings("CommonCompilerTest::CompileMethod", false, false);
TimingLogger::ScopedTiming t(__FUNCTION__, &timings);
+ CompiledMethodStorage storage(/*swap_fd=*/ -1);
+ const CompiledMethod* compiled_method = nullptr;
{
- Thread* self = Thread::Current();
- jobject class_loader = self->GetJniEnv()->GetVm()->AddGlobalRef(self, method->GetClassLoader());
-
DCHECK(!Runtime::Current()->IsStarted());
- const DexFile* dex_file = method->GetDexFile();
- uint16_t class_def_idx = method->GetClassDefIndex();
- uint32_t method_idx = method->GetDexMethodIndex();
- uint32_t access_flags = method->GetAccessFlags();
- InvokeType invoke_type = method->GetInvokeType();
+ Thread* self = Thread::Current();
StackHandleScope<2> hs(self);
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache()));
- Handle<mirror::ClassLoader> h_class_loader = hs.NewHandle(
- self->DecodeJObject(class_loader)->AsClassLoader());
- const dex::CodeItem* code_item = dex_file->GetCodeItem(method->GetCodeItemOffset());
-
- std::vector<const DexFile*> dex_files;
- dex_files.push_back(dex_file);
-
- // Go to native so that we don't block GC during compilation.
- ScopedThreadSuspension sts(self, kNative);
-
- compiler_driver_->InitializeThreadPools();
-
- compiler_driver_->PreCompile(class_loader,
- dex_files,
- &timings,
- &compiler_options_->image_classes_,
- verification_results_.get());
-
- // Verification results in the `callback_` should not be used during compilation.
- down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
- reinterpret_cast<VerificationResults*>(inaccessible_page_));
+ std::unique_ptr<Compiler> compiler(
+ Compiler::Create(*compiler_options_, &storage, compiler_kind_));
+ const DexFile& dex_file = *method->GetDexFile();
+ Handle<mirror::DexCache> dex_cache = hs.NewHandle(class_linker_->FindDexCache(self, dex_file));
+ Handle<mirror::ClassLoader> class_loader = hs.NewHandle(method->GetClassLoader());
compiler_options_->verification_results_ = verification_results_.get();
- compiler_driver_->CompileOne(self,
- class_loader,
- *dex_file,
- class_def_idx,
- method_idx,
- access_flags,
- invoke_type,
- code_item,
- dex_cache,
- h_class_loader);
+ if (method->IsNative()) {
+ compiled_method = compiler->JniCompile(method->GetAccessFlags(),
+ method->GetDexMethodIndex(),
+ dex_file,
+ dex_cache);
+ } else {
+ verification_results_->AddDexFile(&dex_file);
+ verification_results_->CreateVerifiedMethodFor(
+ MethodReference(&dex_file, method->GetDexMethodIndex()));
+ compiled_method = compiler->Compile(method->GetCodeItem(),
+ method->GetAccessFlags(),
+ method->GetInvokeType(),
+ method->GetClassDefIndex(),
+ method->GetDexMethodIndex(),
+ class_loader,
+ dex_file,
+ dex_cache);
+ }
compiler_options_->verification_results_ = nullptr;
- down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
- verification_results_.get());
-
- compiler_driver_->FreeThreadPools();
-
- self->GetJniEnv()->DeleteGlobalRef(class_loader);
}
TimingLogger::ScopedTiming t2("MakeExecutable", &timings);
- MakeExecutable(method);
+ MakeExecutable(method, compiled_method);
}
void CommonCompilerTest::CompileDirectMethod(Handle<mirror::ClassLoader> class_loader,
@@ -336,58 +238,6 @@
CompileMethod(method);
}
-void CommonCompilerTest::ReserveImageSpace() {
- // Reserve where the image will be loaded up front so that other parts of test set up don't
- // accidentally end up colliding with the fixed memory address when we need to load the image.
- std::string error_msg;
- MemMap::Init();
- image_reservation_ = MemMap::MapAnonymous("image reservation",
- reinterpret_cast<uint8_t*>(ART_BASE_ADDRESS),
- (size_t)120 * 1024 * 1024, // 120MB
- PROT_NONE,
- false /* no need for 4gb flag with fixed mmap */,
- /*reuse=*/ false,
- /*reservation=*/ nullptr,
- &error_msg);
- CHECK(image_reservation_.IsValid()) << error_msg;
-}
-
-void CommonCompilerTest::CompileAll(jobject class_loader,
- const std::vector<const DexFile*>& dex_files,
- TimingLogger* timings) {
- TimingLogger::ScopedTiming t(__FUNCTION__, timings);
- SetDexFilesForOatFile(dex_files);
-
- compiler_driver_->InitializeThreadPools();
-
- compiler_driver_->PreCompile(class_loader,
- dex_files,
- timings,
- &compiler_options_->image_classes_,
- verification_results_.get());
-
- // Verification results in the `callback_` should not be used during compilation.
- down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
- reinterpret_cast<VerificationResults*>(inaccessible_page_));
- compiler_options_->verification_results_ = verification_results_.get();
- compiler_driver_->CompileAll(class_loader, dex_files, timings);
- compiler_options_->verification_results_ = nullptr;
- down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
- verification_results_.get());
-
- compiler_driver_->FreeThreadPools();
-}
-
-void CommonCompilerTest::UnreserveImageSpace() {
- image_reservation_.Reset();
-}
-
-void CommonCompilerTest::SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
- compiler_options_->dex_files_for_oat_file_ = dex_files;
- compiler_driver_->compiled_classes_.AddDexFiles(dex_files);
- compiler_driver_->dex_to_dex_compiler_.SetDexFiles(dex_files);
-}
-
void CommonCompilerTest::ClearBootImageOption() {
compiler_options_->image_type_ = CompilerOptions::ImageType::kNone;
}
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index a71908e..4f4e49a 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -24,7 +24,6 @@
#include "arch/instruction_set.h"
#include "arch/instruction_set_features.h"
-#include "base/hash_set.h"
#include "common_runtime_test.h"
#include "compiler.h"
#include "oat_file.h"
@@ -34,11 +33,10 @@
class ClassLoader;
} // namespace mirror
-class CompilerDriver;
+class CompiledMethod;
class CompilerOptions;
class CumulativeLogger;
class DexFile;
-class ProfileCompilationInfo;
class TimingLogger;
class VerificationResults;
@@ -49,16 +47,11 @@
CommonCompilerTest();
~CommonCompilerTest();
- // Create an OatMethod based on pointers (for unit tests).
- OatFile::OatMethod CreateOatMethod(const void* code);
-
- void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
+ void MakeExecutable(ArtMethod* method, const CompiledMethod* compiled_method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
static void MakeExecutable(const void* code_start, size_t code_length);
- void MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader, const char* class_name)
- REQUIRES_SHARED(Locks::mutator_lock_);
-
protected:
void SetUp() override;
@@ -67,20 +60,12 @@
Compiler::Kind GetCompilerKind() const;
void SetCompilerKind(Compiler::Kind compiler_kind);
- // Get the set of image classes given to the compiler-driver in SetUp.
- virtual std::unique_ptr<HashSet<std::string>> GetImageClasses();
-
- virtual ProfileCompilationInfo* GetProfileCompilationInfo();
-
virtual CompilerFilter::Filter GetCompilerFilter() const {
return CompilerFilter::kDefaultCompilerFilter;
}
void TearDown() override;
- void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
- REQUIRES_SHARED(Locks::mutator_lock_);
-
void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
@@ -91,25 +76,12 @@
const char* method_name, const char* signature)
REQUIRES_SHARED(Locks::mutator_lock_);
- void CompileAll(jobject class_loader,
- const std::vector<const DexFile*>& dex_files,
- TimingLogger* timings) REQUIRES(!Locks::mutator_lock_);
-
void ApplyInstructionSet();
void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant);
- void CreateCompilerDriver();
-
- void ReserveImageSpace();
-
- void UnreserveImageSpace();
-
- void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
-
void ClearBootImageOption();
Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
- size_t number_of_threads_ = 2u;
InstructionSet instruction_set_ =
(kRuntimeISA == InstructionSet::kArm) ? InstructionSet::kThumb2 : kRuntimeISA;
@@ -119,12 +91,8 @@
std::unique_ptr<CompilerOptions> compiler_options_;
std::unique_ptr<VerificationResults> verification_results_;
- std::unique_ptr<CompilerDriver> compiler_driver_;
private:
- MemMap image_reservation_;
- void* inaccessible_page_;
-
// Chunks must not move their storage after being created - use the node-based std::list.
std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
};
diff --git a/compiler/dex/dex_to_dex_decompiler_test.cc b/compiler/dex/dex_to_dex_decompiler_test.cc
index 1f04546..b5525dc 100644
--- a/compiler/dex/dex_to_dex_decompiler_test.cc
+++ b/compiler/dex/dex_to_dex_decompiler_test.cc
@@ -18,7 +18,7 @@
#include "base/casts.h"
#include "class_linker.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
#include "compiled_method-inl.h"
#include "compiler_callbacks.h"
#include "dex/class_accessor-inl.h"
@@ -36,7 +36,7 @@
namespace art {
-class DexToDexDecompilerTest : public CommonCompilerTest {
+class DexToDexDecompilerTest : public CommonCompilerDriverTest {
public:
void CompileAll(jobject class_loader) REQUIRES(!Locks::mutator_lock_) {
TimingLogger timings("DexToDexDecompilerTest::CompileAll", false, false);
@@ -47,7 +47,7 @@
down_cast<QuickCompilerCallbacks*>(Runtime::Current()->GetCompilerCallbacks())->SetVerifierDeps(
new verifier::VerifierDeps(GetDexFiles(class_loader)));
std::vector<const DexFile*> dex_files = GetDexFiles(class_loader);
- CommonCompilerTest::CompileAll(class_loader, dex_files, &timings);
+ CommonCompilerDriverTest::CompileAll(class_loader, dex_files, &timings);
}
void RunTest(const char* dex_name) {
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 1c9830b..3be5627 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -643,55 +643,6 @@
quick_fn);
}
-// Compile a single Method. (For testing only.)
-void CompilerDriver::CompileOne(Thread* self,
- jobject class_loader,
- const DexFile& dex_file,
- uint16_t class_def_idx,
- uint32_t method_idx,
- uint32_t access_flags,
- InvokeType invoke_type,
- const dex::CodeItem* code_item,
- Handle<mirror::DexCache> dex_cache,
- Handle<mirror::ClassLoader> h_class_loader) {
- // Can we run DEX-to-DEX compiler on this class ?
- optimizer::DexToDexCompiler::CompilationLevel dex_to_dex_compilation_level =
- GetDexToDexCompilationLevel(self,
- *this,
- class_loader,
- dex_file,
- dex_file.GetClassDef(class_def_idx));
-
- CompileMethodQuick(self,
- this,
- code_item,
- access_flags,
- invoke_type,
- class_def_idx,
- method_idx,
- h_class_loader,
- dex_file,
- dex_to_dex_compilation_level,
- dex_cache);
-
- const size_t num_methods = dex_to_dex_compiler_.NumCodeItemsToQuicken(self);
- if (num_methods != 0) {
- DCHECK_EQ(num_methods, 1u);
- CompileMethodDex2Dex(self,
- this,
- code_item,
- access_flags,
- invoke_type,
- class_def_idx,
- method_idx,
- h_class_loader,
- dex_file,
- dex_to_dex_compilation_level,
- dex_cache);
- dex_to_dex_compiler_.ClearState();
- }
-}
-
void CompilerDriver::Resolve(jobject class_loader,
const std::vector<const DexFile*>& dex_files,
TimingLogger* timings) {
@@ -903,7 +854,7 @@
// Avoid adding the dex files in the case where we aren't going to add compiled methods.
// This reduces RAM usage for this case.
for (const DexFile* dex_file : dex_files) {
- // Can be already inserted if the caller is CompileOne. This happens for gtests.
+ // Can be already inserted. This happens for gtests.
if (!compiled_methods_.HaveDexFile(dex_file)) {
compiled_methods_.AddDexFile(dex_file);
}
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 199835c..85f0e17 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -121,19 +121,6 @@
TimingLogger* timings)
REQUIRES(!Locks::mutator_lock_);
- // Compile a single Method. (For testing only.)
- void CompileOne(Thread* self,
- jobject class_loader,
- const DexFile& dex_file,
- uint16_t class_def_idx,
- uint32_t method_idx,
- uint32_t access_flags,
- InvokeType invoke_type,
- const dex::CodeItem* code_item,
- Handle<mirror::DexCache> dex_cache,
- Handle<mirror::ClassLoader> h_class_loader)
- REQUIRES(!Locks::mutator_lock_);
-
const CompilerOptions& GetCompilerOptions() const {
return *compiler_options_;
}
@@ -360,7 +347,7 @@
// Compiler for dex to dex (quickening).
optimizer::DexToDexCompiler dex_to_dex_compiler_;
- friend class CommonCompilerTest;
+ friend class CommonCompilerDriverTest;
friend class CompileClassVisitor;
friend class DexToDexDecompilerTest;
friend class InitializeClassVisitor;
diff --git a/compiler/driver/compiler_driver_test.cc b/compiler/driver/compiler_driver_test.cc
index e73d072..dd2b3ab 100644
--- a/compiler/driver/compiler_driver_test.cc
+++ b/compiler/driver/compiler_driver_test.cc
@@ -24,7 +24,7 @@
#include "art_method-inl.h"
#include "base/casts.h"
#include "class_linker-inl.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
#include "compiler_callbacks.h"
#include "dex/dex_file.h"
#include "dex/dex_file_types.h"
@@ -40,7 +40,7 @@
namespace art {
-class CompilerDriverTest : public CommonCompilerTest {
+class CompilerDriverTest : public CommonCompilerDriverTest {
protected:
void CompileAllAndMakeExecutable(jobject class_loader) REQUIRES(!Locks::mutator_lock_) {
TimingLogger timings("CompilerDriverTest::CompileAllAndMakeExecutable", false, false);
@@ -77,6 +77,20 @@
}
}
+ void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
+ CHECK(method != nullptr);
+
+ const CompiledMethod* compiled_method = nullptr;
+ if (!method->IsAbstract()) {
+ mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache();
+ const DexFile& dex_file = *dex_cache->GetDexFile();
+ compiled_method =
+ compiler_driver_->GetCompiledMethod(MethodReference(&dex_file,
+ method->GetDexMethodIndex()));
+ }
+ CommonCompilerTest::MakeExecutable(method, compiled_method);
+ }
+
void MakeDexFileExecutable(jobject class_loader, const DexFile& dex_file) {
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 25d7b36..5908b87 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -463,6 +463,7 @@
friend class Dex2Oat;
friend class DexToDexDecompilerTest;
+ friend class CommonCompilerDriverTest;
friend class CommonCompilerTest;
friend class jit::JitCompiler;
friend class verifier::VerifierDepsTest;
diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc
index 4d26058..b2277ad 100644
--- a/compiler/verifier_deps_test.cc
+++ b/compiler/verifier_deps_test.cc
@@ -20,7 +20,7 @@
#include "art_method-inl.h"
#include "base/indenter.h"
#include "class_linker.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
#include "compiler_callbacks.h"
#include "dex/class_accessor-inl.h"
#include "dex/class_iterator.h"
@@ -57,7 +57,7 @@
verifier::VerifierDeps* deps_;
};
-class VerifierDepsTest : public CommonCompilerTest {
+class VerifierDepsTest : public CommonCompilerDriverTest {
public:
void SetUpRuntimeOptions(RuntimeOptions* options) override {
CommonCompilerTest::SetUpRuntimeOptions(options);
diff --git a/dex2oat/linker/elf_writer_test.cc b/dex2oat/linker/elf_writer_test.cc
index e016f29..d8a360a 100644
--- a/dex2oat/linker/elf_writer_test.cc
+++ b/dex2oat/linker/elf_writer_test.cc
@@ -22,7 +22,7 @@
#include "base/mem_map.h"
#include "base/unix_file/fd_file.h"
#include "base/utils.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
#include "elf_file.h"
#include "elf_file_impl.h"
#include "elf_writer_quick.h"
@@ -32,7 +32,7 @@
namespace art {
namespace linker {
-class ElfWriterTest : public CommonCompilerTest {
+class ElfWriterTest : public CommonCompilerDriverTest {
protected:
void SetUp() override {
ReserveImageSpace();
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h
index 6b56517..aa4fb70 100644
--- a/dex2oat/linker/image_test.h
+++ b/dex2oat/linker/image_test.h
@@ -34,7 +34,7 @@
#include "base/unix_file/fd_file.h"
#include "base/utils.h"
#include "class_linker-inl.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
#include "compiler_callbacks.h"
#include "debug/method_debug_info.h"
#include "dex/quick_compiler_callbacks.h"
@@ -73,7 +73,7 @@
~CompilationHelper();
};
-class ImageTest : public CommonCompilerTest {
+class ImageTest : public CommonCompilerDriverTest {
protected:
virtual void SetUp() {
ReserveImageSpace();
diff --git a/dex2oat/linker/oat_writer_test.cc b/dex2oat/linker/oat_writer_test.cc
index db0a1e5..1277cc7 100644
--- a/dex2oat/linker/oat_writer_test.cc
+++ b/dex2oat/linker/oat_writer_test.cc
@@ -23,7 +23,7 @@
#include "base/stl_util.h"
#include "base/unix_file/fd_file.h"
#include "class_linker.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
#include "compiled_method-inl.h"
#include "compiler.h"
#include "debug/method_debug_info.h"
@@ -53,7 +53,7 @@
namespace art {
namespace linker {
-class OatTest : public CommonCompilerTest {
+class OatTest : public CommonCompilerDriverTest {
protected:
static const bool kCompile = false; // DISABLED_ due to the time to compile libcore