Skip to content

Commit

Permalink
Introduce an enum for the compilation kind.
Browse files Browse the repository at this point in the history
Test: test.py
Change-Id: I5329e50a6b4521933b6b171c8c0fbc618c3f67cd
  • Loading branch information
Nicolas Geoffray committed Jun 18, 2020
1 parent 289bd1c commit 0d60a2b
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 117 deletions.
4 changes: 2 additions & 2 deletions compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "base/mutex.h"
#include "base/os.h"
#include "compilation_kind.h"
#include "dex/invoke_type.h"

namespace art {
Expand Down Expand Up @@ -75,8 +76,7 @@ class Compiler {
jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
jit::JitMemoryRegion* region ATTRIBUTE_UNUSED,
ArtMethod* method ATTRIBUTE_UNUSED,
bool baseline ATTRIBUTE_UNUSED,
bool osr ATTRIBUTE_UNUSED,
CompilationKind compilation_kind ATTRIBUTE_UNUSED,
jit::JitLogger* jit_logger ATTRIBUTE_UNUSED)
REQUIRES_SHARED(Locks::mutator_lock_) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions compiler/jit/jit_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ JitCompiler::~JitCompiler() {
}

bool JitCompiler::CompileMethod(
Thread* self, JitMemoryRegion* region, ArtMethod* method, bool baseline, bool osr) {
Thread* self, JitMemoryRegion* region, ArtMethod* method, CompilationKind compilation_kind) {
SCOPED_TRACE << "JIT compiling "
<< method->PrettyMethod()
<< " (baseline=" << baseline << ", osr=" << osr << ")";
<< " (kind=" << compilation_kind << ")";

DCHECK(!method->IsProxyMethod());
DCHECK(method->GetDeclaringClass()->IsResolved());
Expand All @@ -185,7 +185,7 @@ bool JitCompiler::CompileMethod(
JitCodeCache* const code_cache = runtime->GetJit()->GetCodeCache();
uint64_t start_ns = NanoTime();
success = compiler_->JitCompile(
self, code_cache, region, method, baseline, osr, jit_logger_.get());
self, code_cache, region, method, compilation_kind, jit_logger_.get());
uint64_t duration_ns = NanoTime() - start_ns;
VLOG(jit) << "Compilation of "
<< method->PrettyMethod()
Expand Down
3 changes: 2 additions & 1 deletion compiler/jit/jit_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define ART_COMPILER_JIT_JIT_COMPILER_H_

#include "base/mutex.h"
#include "compilation_kind.h"

#include "jit/jit.h"

Expand All @@ -40,7 +41,7 @@ class JitCompiler : public JitCompilerInterface {

// Compilation entrypoint. Returns whether the compilation succeeded.
bool CompileMethod(
Thread* self, JitMemoryRegion* region, ArtMethod* method, bool baseline, bool osr)
Thread* self, JitMemoryRegion* region, ArtMethod* method, CompilationKind kind)
REQUIRES_SHARED(Locks::mutator_lock_) override;

const CompilerOptions& GetCompilerOptions() const {
Expand Down
3 changes: 1 addition & 2 deletions compiler/optimizing/inliner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2045,8 +2045,7 @@ bool HInliner::TryBuildAndInlineHelper(HInvoke* invoke_instruction,
invoke_type,
callee_dead_reference_safe,
graph_->IsDebuggable(),
/* osr= */ false,
/* baseline= */ graph_->IsCompilingBaseline(),
graph_->GetCompilationKind(),
/* start_instruction_id= */ caller_instruction_counter);
callee_graph->SetArtMethod(resolved_method);

Expand Down
26 changes: 12 additions & 14 deletions compiler/optimizing/nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "base/transform_array_ref.h"
#include "art_method.h"
#include "class_root.h"
#include "compilation_kind.h"
#include "data_type.h"
#include "deoptimization_kind.h"
#include "dex/dex_file.h"
Expand Down Expand Up @@ -378,8 +379,7 @@ class HGraph : public ArenaObject<kArenaAllocGraph> {
InvokeType invoke_type = kInvalidInvokeType,
bool dead_reference_safe = false,
bool debuggable = false,
bool osr = false,
bool baseline = false,
CompilationKind compilation_kind = CompilationKind::kOptimized,
int start_instruction_id = 0)
: allocator_(allocator),
arena_stack_(arena_stack),
Expand Down Expand Up @@ -415,8 +415,7 @@ class HGraph : public ArenaObject<kArenaAllocGraph> {
cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)),
cached_current_method_(nullptr),
art_method_(nullptr),
osr_(osr),
baseline_(baseline),
compilation_kind_(compilation_kind),
cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) {
blocks_.reserve(kDefaultNumberOfBlocks);
}
Expand Down Expand Up @@ -645,9 +644,11 @@ class HGraph : public ArenaObject<kArenaAllocGraph> {
return instruction_set_;
}

bool IsCompilingOsr() const { return osr_; }
bool IsCompilingOsr() const { return compilation_kind_ == CompilationKind::kOsr; }

bool IsCompilingBaseline() const { return baseline_; }
bool IsCompilingBaseline() const { return compilation_kind_ == CompilationKind::kBaseline; }

CompilationKind GetCompilationKind() const { return compilation_kind_; }

ArenaSet<ArtMethod*>& GetCHASingleImplementationList() {
return cha_single_implementation_list_;
Expand Down Expand Up @@ -837,14 +838,11 @@ class HGraph : public ArenaObject<kArenaAllocGraph> {
// (such as when the superclass could not be found).
ArtMethod* art_method_;

// Whether we are compiling this graph for on stack replacement: this will
// make all loops seen as irreducible and emit special stack maps to mark
// compiled code entries which the interpreter can directly jump to.
const bool osr_;

// Whether we are compiling baseline (not running optimizations). This affects
// the code being generated.
const bool baseline_;
// How we are compiling the graph: either optimized, osr, or baseline.
// For osr, we will make all loops seen as irreducible and emit special
// stack maps to mark compiled code entries which the interpreter can
// directly jump to.
const CompilationKind compilation_kind_;

// List of methods that are assumed to have single implementation.
ArenaSet<ArtMethod*> cha_single_implementation_list_;
Expand Down
36 changes: 18 additions & 18 deletions compiler/optimizing/optimizing_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ class OptimizingCompiler final : public Compiler {
jit::JitCodeCache* code_cache,
jit::JitMemoryRegion* region,
ArtMethod* method,
bool baseline,
bool osr,
CompilationKind compilation_kind,
jit::JitLogger* jit_logger)
override
REQUIRES_SHARED(Locks::mutator_lock_);
Expand Down Expand Up @@ -379,8 +378,7 @@ class OptimizingCompiler final : public Compiler {
CodeVectorAllocator* code_allocator,
const DexCompilationUnit& dex_compilation_unit,
ArtMethod* method,
bool baseline,
bool osr,
CompilationKind compilation_kind,
VariableSizedHandleScope* handles) const;

CodeGenerator* TryCompileIntrinsic(ArenaAllocator* allocator,
Expand Down Expand Up @@ -717,8 +715,7 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* allocator,
CodeVectorAllocator* code_allocator,
const DexCompilationUnit& dex_compilation_unit,
ArtMethod* method,
bool baseline,
bool osr,
CompilationKind compilation_kind,
VariableSizedHandleScope* handles) const {
MaybeRecordStat(compilation_stats_.get(), MethodCompilationStat::kAttemptBytecodeCompilation);
const CompilerOptions& compiler_options = GetCompilerOptions();
Expand Down Expand Up @@ -787,8 +784,7 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* allocator,
kInvalidInvokeType,
dead_reference_safe,
compiler_options.GetDebuggable(),
/* osr= */ osr,
/* baseline= */ baseline);
compilation_kind);

if (method != nullptr) {
graph->SetArtMethod(method);
Expand Down Expand Up @@ -861,7 +857,7 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* allocator,
}
}

if (baseline) {
if (compilation_kind == CompilationKind::kBaseline) {
RunBaselineOptimizations(graph, codegen.get(), dex_compilation_unit, &pass_observer);
} else {
RunOptimizations(graph, codegen.get(), dex_compilation_unit, &pass_observer);
Expand Down Expand Up @@ -914,7 +910,7 @@ CodeGenerator* OptimizingCompiler::TryCompileIntrinsic(
kInvalidInvokeType,
/* dead_reference_safe= */ true, // Intrinsics don't affect dead reference safety.
compiler_options.GetDebuggable(),
/* osr= */ false);
CompilationKind::kOptimized);

DCHECK(Runtime::Current()->IsAotCompiler());
DCHECK(method != nullptr);
Expand Down Expand Up @@ -1047,8 +1043,9 @@ CompiledMethod* OptimizingCompiler::Compile(const dex::CodeItem* code_item,
&code_allocator,
dex_compilation_unit,
method,
compiler_options.IsBaseline(),
/* osr= */ false,
compiler_options.IsBaseline()
? CompilationKind::kBaseline
: CompilationKind::kOptimized,
&handles));
}
}
Expand Down Expand Up @@ -1194,10 +1191,14 @@ bool OptimizingCompiler::JitCompile(Thread* self,
jit::JitCodeCache* code_cache,
jit::JitMemoryRegion* region,
ArtMethod* method,
bool baseline,
bool osr,
CompilationKind compilation_kind,
jit::JitLogger* jit_logger) {
const CompilerOptions& compiler_options = GetCompilerOptions();
// If the baseline flag was explicitly passed, change the compilation kind
// from optimized to baseline.
if (compiler_options.IsBaseline() && compilation_kind == CompilationKind::kOptimized) {
compilation_kind = CompilationKind::kBaseline;
}
DCHECK(compiler_options.IsJitCompiler());
DCHECK_EQ(compiler_options.IsJitCompilerForSharedCode(), code_cache->IsSharedRegion(*region));
StackHandleScope<3> hs(self);
Expand Down Expand Up @@ -1275,7 +1276,7 @@ bool OptimizingCompiler::JitCompile(Thread* self,
ArrayRef<const uint8_t>(stack_map),
debug_info,
/* is_full_debug_info= */ compiler_options.GetGenerateDebugInfo(),
osr,
compilation_kind,
/* has_should_deoptimize_flag= */ false,
cha_single_implementation_list)) {
code_cache->Free(self, region, reserved_code.data(), reserved_data.data());
Expand Down Expand Up @@ -1316,8 +1317,7 @@ bool OptimizingCompiler::JitCompile(Thread* self,
&code_allocator,
dex_compilation_unit,
method,
baseline || compiler_options.IsBaseline(),
osr,
compilation_kind,
&handles));
if (codegen.get() == nullptr) {
return false;
Expand Down Expand Up @@ -1384,7 +1384,7 @@ bool OptimizingCompiler::JitCompile(Thread* self,
ArrayRef<const uint8_t>(stack_map),
debug_info,
/* is_full_debug_info= */ compiler_options.GetGenerateDebugInfo(),
osr,
compilation_kind,
codegen->GetGraph()->HasShouldDeoptimizeFlag(),
codegen->GetGraph()->GetCHASingleImplementationList())) {
code_cache->Free(self, region, reserved_code.data(), reserved_data.data());
Expand Down
1 change: 1 addition & 0 deletions runtime/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ gensrcs {
"base/callee_save_type.h",
"base/locks.h",
"class_status.h",
"compilation_kind.h",
"gc_root.h",
"gc/allocator_type.h",
"gc/allocator/rosalloc.h",
Expand Down
35 changes: 35 additions & 0 deletions runtime/compilation_kind.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2020 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_RUNTIME_COMPILATION_KIND_H_
#define ART_RUNTIME_COMPILATION_KIND_H_

#include <iosfwd>
#include <stdint.h>

namespace art {

enum class CompilationKind {
kOsr,
kBaseline,
kOptimized,
};

std::ostream& operator<<(std::ostream& os, CompilationKind rhs);

} // namespace art

#endif // ART_RUNTIME_COMPILATION_KIND_H_
Loading

0 comments on commit 0d60a2b

Please sign in to comment.