ART: Minor refactoring of JNI stub compilation.
Introduce JniCompiledMethod to avoid JNI compiler dependency
on CompiledMethod. This is done in preparation for compiling
JNI stubs in JIT as the CompiledMethod class should be used
exclusively for AOT compilation.
Test: m test-art-host-gtest
Bug: 65574695
Change-Id: I1d047d4aebc55057efb7ed3d39ea65600f5fb6ab
diff --git a/compiler/jni/quick/jni_compiler.cc b/compiler/jni/quick/jni_compiler.cc
index b93b05c..37f7d63 100644
--- a/compiler/jni/quick/jni_compiler.cc
+++ b/compiler/jni/quick/jni_compiler.cc
@@ -29,7 +29,6 @@
#include "base/macros.h"
#include "calling_convention.h"
#include "class_linker.h"
-#include "compiled_method.h"
#include "debug/dwarf/debug_frame_opcode_writer.h"
#include "dex_file-inl.h"
#include "driver/compiler_driver.h"
@@ -115,10 +114,10 @@
// convention.
//
template <PointerSize kPointerSize>
-static CompiledMethod* ArtJniCompileMethodInternal(CompilerDriver* driver,
- uint32_t access_flags,
- uint32_t method_idx,
- const DexFile& dex_file) {
+static JniCompiledMethod ArtJniCompileMethodInternal(CompilerDriver* driver,
+ uint32_t access_flags,
+ uint32_t method_idx,
+ const DexFile& dex_file) {
const bool is_native = (access_flags & kAccNative) != 0;
CHECK(is_native);
const bool is_static = (access_flags & kAccStatic) != 0;
@@ -657,16 +656,12 @@
MemoryRegion code(&managed_code[0], managed_code.size());
__ FinalizeInstructions(code);
- return CompiledMethod::SwapAllocCompiledMethod(driver,
- instruction_set,
- ArrayRef<const uint8_t>(managed_code),
- frame_size,
- main_jni_conv->CoreSpillMask(),
- main_jni_conv->FpSpillMask(),
- /* method_info */ ArrayRef<const uint8_t>(),
- /* vmap_table */ ArrayRef<const uint8_t>(),
- ArrayRef<const uint8_t>(*jni_asm->cfi().data()),
- ArrayRef<const linker::LinkerPatch>());
+ return JniCompiledMethod(instruction_set,
+ std::move(managed_code),
+ frame_size,
+ main_jni_conv->CoreSpillMask(),
+ main_jni_conv->FpSpillMask(),
+ ArrayRef<const uint8_t>(*jni_asm->cfi().data()));
}
// Copy a single parameter from the managed to the JNI calling convention.
@@ -775,10 +770,10 @@
}
}
-CompiledMethod* ArtQuickJniCompileMethod(CompilerDriver* compiler,
- uint32_t access_flags,
- uint32_t method_idx,
- const DexFile& dex_file) {
+JniCompiledMethod ArtQuickJniCompileMethod(CompilerDriver* compiler,
+ uint32_t access_flags,
+ uint32_t method_idx,
+ const DexFile& dex_file) {
if (Is64BitInstructionSet(compiler->GetInstructionSet())) {
return ArtJniCompileMethodInternal<PointerSize::k64>(
compiler, access_flags, method_idx, dex_file);
diff --git a/compiler/jni/quick/jni_compiler.h b/compiler/jni/quick/jni_compiler.h
index 3fcce55..1141994 100644
--- a/compiler/jni/quick/jni_compiler.h
+++ b/compiler/jni/quick/jni_compiler.h
@@ -17,18 +17,55 @@
#ifndef ART_COMPILER_JNI_QUICK_JNI_COMPILER_H_
#define ART_COMPILER_JNI_QUICK_JNI_COMPILER_H_
-#include "compiler.h"
-#include "dex_file.h"
+#include <vector>
+
+#include "arch/instruction_set.h"
+#include "base/array_ref.h"
namespace art {
+class ArtMethod;
class CompilerDriver;
-class CompiledMethod;
+class DexFile;
-CompiledMethod* ArtQuickJniCompileMethod(CompilerDriver* compiler,
- uint32_t access_flags,
- uint32_t method_idx,
- const DexFile& dex_file);
+class JniCompiledMethod {
+ public:
+ JniCompiledMethod(InstructionSet instruction_set,
+ std::vector<uint8_t>&& code,
+ uint32_t frame_size,
+ uint32_t core_spill_mask,
+ uint32_t fp_spill_mask,
+ ArrayRef<const uint8_t> cfi)
+ : instruction_set_(instruction_set),
+ code_(std::move(code)),
+ frame_size_(frame_size),
+ core_spill_mask_(core_spill_mask),
+ fp_spill_mask_(fp_spill_mask),
+ cfi_(cfi.begin(), cfi.end()) {}
+
+ JniCompiledMethod(JniCompiledMethod&& other) = default;
+ ~JniCompiledMethod() = default;
+
+ InstructionSet GetInstructionSet() const { return instruction_set_; }
+ ArrayRef<const uint8_t> GetCode() const { return ArrayRef<const uint8_t>(code_); }
+ uint32_t GetFrameSize() const { return frame_size_; }
+ uint32_t GetCoreSpillMask() const { return core_spill_mask_; }
+ uint32_t GetFpSpillMask() const { return fp_spill_mask_; }
+ ArrayRef<const uint8_t> GetCfi() const { return ArrayRef<const uint8_t>(cfi_); }
+
+ private:
+ InstructionSet instruction_set_;
+ std::vector<uint8_t> code_;
+ uint32_t frame_size_;
+ uint32_t core_spill_mask_;
+ uint32_t fp_spill_mask_;
+ std::vector<uint8_t> cfi_;
+};
+
+JniCompiledMethod ArtQuickJniCompileMethod(CompilerDriver* compiler,
+ uint32_t access_flags,
+ uint32_t method_idx,
+ const DexFile& dex_file);
} // namespace art
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 095ca63..5a9e2c5 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -1133,12 +1133,20 @@
}
}
- CompiledMethod* compiled_method = ArtQuickJniCompileMethod(GetCompilerDriver(),
- access_flags,
- method_idx,
- dex_file);
+ JniCompiledMethod jni_compiled_method = ArtQuickJniCompileMethod(
+ GetCompilerDriver(), access_flags, method_idx, dex_file);
MaybeRecordStat(compilation_stats_.get(), MethodCompilationStat::kCompiledNativeStub);
- return compiled_method;
+ return CompiledMethod::SwapAllocCompiledMethod(
+ GetCompilerDriver(),
+ jni_compiled_method.GetInstructionSet(),
+ jni_compiled_method.GetCode(),
+ jni_compiled_method.GetFrameSize(),
+ jni_compiled_method.GetCoreSpillMask(),
+ jni_compiled_method.GetFpSpillMask(),
+ /* method_info */ ArrayRef<const uint8_t>(),
+ /* vmap_table */ ArrayRef<const uint8_t>(),
+ jni_compiled_method.GetCfi(),
+ /* patches */ ArrayRef<const linker::LinkerPatch>());
}
Compiler* CreateOptimizingCompiler(CompilerDriver* driver) {