Merge "Report loaded classes to native debugger."
diff --git a/compiler/dex/quick/quick_compiler.cc b/compiler/dex/quick/quick_compiler.cc
index 3260a7a..ebc9a2c 100644
--- a/compiler/dex/quick/quick_compiler.cc
+++ b/compiler/dex/quick/quick_compiler.cc
@@ -520,7 +520,12 @@
// In the rare cases we compile experimental opcodes, the runtime has an option to enable it,
// which will force scanning for any unsupported opcodes.
static bool SkipScanningUnsupportedOpcodes(InstructionSet instruction_set) {
- if (UNLIKELY(kUnsupportedOpcodesSize[instruction_set] == 0U)) {
+ Runtime* runtime = Runtime::Current();
+ if (UNLIKELY(runtime->AreExperimentalFlagsEnabled(ExperimentalFlags::kDefaultMethods))) {
+ // Always need to scan opcodes if we have default methods since invoke-super for interface
+ // methods is never going to be supported in the quick compiler.
+ return false;
+ } else if (UNLIKELY(kUnsupportedOpcodesSize[instruction_set] == 0U)) {
// All opcodes are supported no matter what. Usually not the case
// since experimental opcodes are not implemented in the quick compiler.
return true;
@@ -538,8 +543,28 @@
}
}
+bool QuickCompiler::CanCompileInstruction(const MIR* mir,
+ const DexFile& dex_file) const {
+ switch (mir->dalvikInsn.opcode) {
+ // Quick compiler won't support new instruction semantics to invoke-super into an interface
+ // method
+ case Instruction::INVOKE_SUPER: // Fall-through
+ case Instruction::INVOKE_SUPER_RANGE: {
+ DCHECK(mir->dalvikInsn.IsInvoke());
+ uint32_t invoke_method_idx = mir->dalvikInsn.vB;
+ const DexFile::MethodId& method_id = dex_file.GetMethodId(invoke_method_idx);
+ const DexFile::ClassDef* class_def = dex_file.FindClassDef(method_id.class_idx_);
+ // False if we are an interface i.e. !(java_access_flags & kAccInterface)
+ return class_def != nullptr && ((class_def->GetJavaAccessFlags() & kAccInterface) == 0);
+ }
+ default:
+ return true;
+ }
+}
+
// Skip the method that we do not support currently.
-bool QuickCompiler::CanCompileMethod(uint32_t method_idx, const DexFile& dex_file,
+bool QuickCompiler::CanCompileMethod(uint32_t method_idx,
+ const DexFile& dex_file,
CompilationUnit* cu) const {
// This is a limitation in mir_graph. See MirGraph::SetNumSSARegs.
if (cu->mir_graph->GetNumOfCodeAndTempVRs() > kMaxAllowedDalvikRegisters) {
@@ -580,6 +605,9 @@
<< MIRGraph::extended_mir_op_names_[opcode - kMirOpFirst];
}
return false;
+ } else if (!CanCompileInstruction(mir, dex_file)) {
+ VLOG(compiler) << "Cannot compile dalvik opcode : " << mir->dalvikInsn.opcode;
+ return false;
}
// Check if it invokes a prototype that we cannot support.
if (std::find(kInvokeOpcodes, kInvokeOpcodes + arraysize(kInvokeOpcodes), opcode)
diff --git a/compiler/dex/quick/quick_compiler.h b/compiler/dex/quick/quick_compiler.h
index d512b25..55f45f1 100644
--- a/compiler/dex/quick/quick_compiler.h
+++ b/compiler/dex/quick/quick_compiler.h
@@ -18,6 +18,7 @@
#define ART_COMPILER_DEX_QUICK_QUICK_COMPILER_H_
#include "compiler.h"
+#include "dex/mir_graph.h"
namespace art {
@@ -74,6 +75,8 @@
explicit QuickCompiler(CompilerDriver* driver);
private:
+ bool CanCompileInstruction(const MIR* mir, const DexFile& dex_file) const;
+
std::unique_ptr<PassManager> pre_opt_pass_manager_;
std::unique_ptr<PassManager> post_opt_pass_manager_;
DISALLOW_COPY_AND_ASSIGN(QuickCompiler);
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 3847c81..17b2f5e 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -122,8 +122,10 @@
return true;
}
auto it1 = dex_file_oat_filename_map_->find(d1);
+ DCHECK(it1 != dex_file_oat_filename_map_->end());
auto it2 = dex_file_oat_filename_map_->find(d2);
- return it1 == it2;
+ DCHECK(it2 != dex_file_oat_filename_map_->end());
+ return it1->second == it2->second;
}
void CompileAll(jobject class_loader,
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc
index d710747..eee6116 100644
--- a/compiler/optimizing/bounds_check_elimination.cc
+++ b/compiler/optimizing/bounds_check_elimination.cc
@@ -1296,8 +1296,13 @@
*/
bool DynamicBCESeemsProfitable(HLoopInformation* loop, HBasicBlock* block) {
if (loop != nullptr) {
+ // The loop preheader of an irreducible loop does not dominate all the blocks in
+ // the loop. We would need to find the common dominator of all blocks in the loop.
+ if (loop->IsIrreducible()) {
+ return false;
+ }
// A try boundary preheader is hard to handle.
- // TODO: remove this restriction
+ // TODO: remove this restriction.
if (loop->GetPreHeader()->GetLastInstruction()->IsTryBoundary()) {
return false;
}
diff --git a/compiler/optimizing/bounds_check_elimination_test.cc b/compiler/optimizing/bounds_check_elimination_test.cc
index dbeb1cc..b7c24ff 100644
--- a/compiler/optimizing/bounds_check_elimination_test.cc
+++ b/compiler/optimizing/bounds_check_elimination_test.cc
@@ -42,7 +42,6 @@
void RunBCE() {
graph_->BuildDominatorTree();
- graph_->AnalyzeNaturalLoops();
InstructionSimplifier(graph_).Run();
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc
index 1af6846..3721813 100644
--- a/compiler/optimizing/builder.cc
+++ b/compiler/optimizing/builder.cc
@@ -1271,44 +1271,14 @@
// Add move-result for StringFactory method.
uint32_t orig_this_reg = is_range ? register_index : args[0];
- HInstruction* fake_string = LoadLocal(orig_this_reg, Primitive::kPrimNot, invoke->GetDexPc());
- invoke->SetArgumentAt(argument_index, fake_string);
+ HInstruction* new_instance = LoadLocal(orig_this_reg, Primitive::kPrimNot, invoke->GetDexPc());
+ invoke->SetArgumentAt(argument_index, new_instance);
current_block_->AddInstruction(invoke);
- PotentiallySimplifyFakeString(orig_this_reg, invoke->GetDexPc(), invoke);
latest_result_ = invoke;
-
return true;
}
-void HGraphBuilder::PotentiallySimplifyFakeString(uint16_t original_dex_register,
- uint32_t dex_pc,
- HInvoke* actual_string) {
- if (!graph_->IsDebuggable()) {
- // Notify that we cannot compile with baseline. The dex registers aliasing
- // with `original_dex_register` will be handled when we optimize
- // (see HInstructionSimplifer::VisitFakeString).
- can_use_baseline_for_string_init_ = false;
- return;
- }
- const VerifiedMethod* verified_method =
- compiler_driver_->GetVerifiedMethod(dex_file_, dex_compilation_unit_->GetDexMethodIndex());
- if (verified_method != nullptr) {
- UpdateLocal(original_dex_register, actual_string, dex_pc);
- const SafeMap<uint32_t, std::set<uint32_t>>& string_init_map =
- verified_method->GetStringInitPcRegMap();
- auto map_it = string_init_map.find(dex_pc);
- if (map_it != string_init_map.end()) {
- for (uint32_t reg : map_it->second) {
- HInstruction* load_local = LoadLocal(original_dex_register, Primitive::kPrimNot, dex_pc);
- UpdateLocal(reg, load_local, dex_pc);
- }
- }
- } else {
- can_use_baseline_for_string_init_ = false;
- }
-}
-
static Primitive::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) {
const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
const char* type = dex_file.GetFieldTypeDescriptor(field_id);
@@ -2698,18 +2668,10 @@
}
case Instruction::NEW_INSTANCE: {
- uint16_t type_index = instruction.VRegB_21c();
- if (compiler_driver_->IsStringTypeIndex(type_index, dex_file_)) {
- int32_t register_index = instruction.VRegA();
- HFakeString* fake_string = new (arena_) HFakeString(dex_pc);
- current_block_->AddInstruction(fake_string);
- UpdateLocal(register_index, fake_string, dex_pc);
- } else {
- if (!BuildNewInstance(type_index, dex_pc)) {
- return false;
- }
- UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
+ if (!BuildNewInstance(instruction.VRegB_21c(), dex_pc)) {
+ return false;
}
+ UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
break;
}
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 57c5058..ea0b9ec 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -1326,12 +1326,6 @@
<< "instruction->DebugName()=" << instruction->DebugName()
<< " slow_path->GetDescription()=" << slow_path->GetDescription();
DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC()) ||
- // Control flow would not come back into the code if a fatal slow
- // path is taken, so we do not care if it triggers GC.
- slow_path->IsFatal() ||
- // HDeoptimize is a special case: we know we are not coming back from
- // it into the code.
- instruction->IsDeoptimize() ||
// When read barriers are enabled, some instructions use a
// slow path to emit a read barrier, which does not trigger
// GC, is not fatal, nor is emitted by HDeoptimize
diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc
index 45520b4..a11ceb9 100644
--- a/compiler/optimizing/code_generator_arm.cc
+++ b/compiler/optimizing/code_generator_arm.cc
@@ -3651,20 +3651,34 @@
void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
- InvokeRuntimeCallingConvention calling_convention;
- locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
- locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ if (instruction->IsStringAlloc()) {
+ locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
+ } else {
+ InvokeRuntimeCallingConvention calling_convention;
+ locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
+ locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ }
locations->SetOut(Location::RegisterLocation(R0));
}
void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
// Note: if heap poisoning is enabled, the entry point takes cares
// of poisoning the reference.
- codegen_->InvokeRuntime(instruction->GetEntrypoint(),
- instruction,
- instruction->GetDexPc(),
- nullptr);
- CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ if (instruction->IsStringAlloc()) {
+ // String is allocated through StringFactory. Call NewEmptyString entry point.
+ Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
+ MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize);
+ __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
+ __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
+ __ blx(LR);
+ codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
+ } else {
+ codegen_->InvokeRuntime(instruction->GetEntrypoint(),
+ instruction,
+ instruction->GetDexPc(),
+ nullptr);
+ CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ }
}
void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
@@ -6225,8 +6239,16 @@
HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
MethodReference target_method) {
- if (desired_dispatch_info.code_ptr_location ==
- HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
+ HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
+ // We disable pc-relative load when there is an irreducible loop, as the optimization
+ // is incompatible with it.
+ if (GetGraph()->HasIrreducibleLoops() &&
+ (dispatch_info.method_load_kind ==
+ HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
+ dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
+ }
+
+ if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
const DexFile& outer_dex_file = GetGraph()->GetDexFile();
if (&outer_dex_file != target_method.dex_file) {
// Calls across dex files are more likely to exceed the available BL range,
@@ -6237,14 +6259,14 @@
? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
: HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
return HInvokeStaticOrDirect::DispatchInfo {
- desired_dispatch_info.method_load_kind,
+ dispatch_info.method_load_kind,
code_ptr_location,
- desired_dispatch_info.method_load_data,
+ dispatch_info.method_load_data,
0u
};
}
}
- return desired_dispatch_info;
+ return dispatch_info;
}
Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
@@ -6486,18 +6508,6 @@
LOG(FATAL) << "Unreachable";
}
-void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
- DCHECK(codegen_->IsBaseline());
- LocationSummary* locations =
- new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
- locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
-}
-
-void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
- DCHECK(codegen_->IsBaseline());
- // Will be generated at use site.
-}
-
// Simple implementation of packed switch - generate cascaded compare/jumps.
void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
LocationSummary* locations =
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index a3150d3..6ed2c5a 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -604,30 +604,13 @@
DCHECK(!instruction_->IsInvoke() ||
(instruction_->IsInvokeStaticOrDirect() &&
instruction_->GetLocations()->Intrinsified()));
+ // The read barrier instrumentation does not support the
+ // HArm64IntermediateAddress instruction yet.
+ DCHECK(!(instruction_->IsArrayGet() &&
+ instruction_->AsArrayGet()->GetArray()->IsArm64IntermediateAddress()));
__ Bind(GetEntryLabel());
- // Note: In the case of a HArrayGet instruction, when the base
- // address is a HArm64IntermediateAddress instruction, it does not
- // point to the array object itself, but to an offset within this
- // object. However, the read barrier entry point needs the array
- // object address to be passed as first argument. So we
- // temporarily set back `obj_` to that address, and restore its
- // initial value later.
- if (instruction_->IsArrayGet() &&
- instruction_->AsArrayGet()->GetArray()->IsArm64IntermediateAddress()) {
- if (kIsDebugBuild) {
- HArm64IntermediateAddress* intermediate_address =
- instruction_->AsArrayGet()->GetArray()->AsArm64IntermediateAddress();
- uint32_t intermediate_address_offset =
- intermediate_address->GetOffset()->AsIntConstant()->GetValueAsUint64();
- DCHECK_EQ(intermediate_address_offset, offset_);
- DCHECK_EQ(mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(), offset_);
- }
- Register obj_reg = RegisterFrom(obj_, Primitive::kPrimInt);
- __ Sub(obj_reg, obj_reg, offset_);
- }
-
SaveLiveRegisters(codegen, locations);
// We may have to change the index's value, but as `index_` is a
@@ -728,22 +711,6 @@
RestoreLiveRegisters(codegen, locations);
- // Restore the value of `obj_` when it corresponds to a
- // HArm64IntermediateAddress instruction.
- if (instruction_->IsArrayGet() &&
- instruction_->AsArrayGet()->GetArray()->IsArm64IntermediateAddress()) {
- if (kIsDebugBuild) {
- HArm64IntermediateAddress* intermediate_address =
- instruction_->AsArrayGet()->GetArray()->AsArm64IntermediateAddress();
- uint32_t intermediate_address_offset =
- intermediate_address->GetOffset()->AsIntConstant()->GetValueAsUint64();
- DCHECK_EQ(intermediate_address_offset, offset_);
- DCHECK_EQ(mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value(), offset_);
- }
- Register obj_reg = RegisterFrom(obj_, Primitive::kPrimInt);
- __ Add(obj_reg, obj_reg, offset_);
- }
-
__ B(GetExitLabel());
}
@@ -1032,13 +999,6 @@
Primitive::Type type = instruction->GetType();
DCHECK_NE(type, Primitive::kPrimVoid);
- if (instruction->IsFakeString()) {
- // The fake string is an alias for null.
- DCHECK(IsBaseline());
- instruction = locations->Out().GetConstant();
- DCHECK(instruction->IsNullConstant()) << instruction->DebugName();
- }
-
if (instruction->IsCurrentMethod()) {
MoveLocation(location,
Location::DoubleStackSlot(kCurrentMethodStackOffset),
@@ -1977,6 +1937,9 @@
}
void LocationsBuilderARM64::VisitArm64IntermediateAddress(HArm64IntermediateAddress* instruction) {
+ // The read barrier instrumentation does not support the
+ // HArm64IntermediateAddress instruction yet.
+ DCHECK(!kEmitCompilerReadBarrier);
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
locations->SetInAt(0, Location::RequiresRegister());
@@ -1986,6 +1949,9 @@
void InstructionCodeGeneratorARM64::VisitArm64IntermediateAddress(
HArm64IntermediateAddress* instruction) {
+ // The read barrier instrumentation does not support the
+ // HArm64IntermediateAddress instruction yet.
+ DCHECK(!kEmitCompilerReadBarrier);
__ Add(OutputRegister(instruction),
InputRegisterAt(instruction, 0),
Operand(InputOperandAt(instruction, 1)));
@@ -2074,6 +2040,9 @@
} else {
Register temp = temps.AcquireSameSizeAs(obj);
if (instruction->GetArray()->IsArm64IntermediateAddress()) {
+ // The read barrier instrumentation does not support the
+ // HArm64IntermediateAddress instruction yet.
+ DCHECK(!kEmitCompilerReadBarrier);
// We do not need to compute the intermediate address from the array: the
// input instruction has done it already. See the comment in
// `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`.
@@ -2100,11 +2069,6 @@
if (index.IsConstant()) {
codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset);
} else {
- // Note: when `obj_loc` is a HArm64IntermediateAddress, it does
- // not contain the base address of the array object, which is
- // needed by the read barrier entry point. So the read barrier
- // slow path will temporarily set back `obj_loc` to the right
- // address (see ReadBarrierForHeapReferenceSlowPathARM64::EmitNativeCode).
codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset, index);
}
}
@@ -2168,6 +2132,9 @@
UseScratchRegisterScope temps(masm);
Register temp = temps.AcquireSameSizeAs(array);
if (instruction->GetArray()->IsArm64IntermediateAddress()) {
+ // The read barrier instrumentation does not support the
+ // HArm64IntermediateAddress instruction yet.
+ DCHECK(!kEmitCompilerReadBarrier);
// We do not need to compute the intermediate address from the array: the
// input instruction has done it already. See the comment in
// `InstructionSimplifierArm64::TryExtractArrayAccessAddress()`.
@@ -4061,19 +4028,33 @@
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
InvokeRuntimeCallingConvention calling_convention;
- locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
- locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
+ if (instruction->IsStringAlloc()) {
+ locations->AddTemp(LocationFrom(kArtMethodRegister));
+ } else {
+ locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
+ locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
+ }
locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
}
void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
// Note: if heap poisoning is enabled, the entry point takes cares
// of poisoning the reference.
- codegen_->InvokeRuntime(instruction->GetEntrypoint(),
- instruction,
- instruction->GetDexPc(),
- nullptr);
- CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ if (instruction->IsStringAlloc()) {
+ // String is allocated through StringFactory. Call NewEmptyString entry point.
+ Location temp = instruction->GetLocations()->GetTemp(0);
+ MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
+ __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString)));
+ __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value()));
+ __ Blr(lr);
+ codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
+ } else {
+ codegen_->InvokeRuntime(instruction->GetEntrypoint(),
+ instruction,
+ instruction->GetDexPc(),
+ nullptr);
+ CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ }
}
void LocationsBuilderARM64::VisitNot(HNot* instruction) {
@@ -4559,18 +4540,6 @@
LOG(FATAL) << "Unreachable";
}
-void LocationsBuilderARM64::VisitFakeString(HFakeString* instruction) {
- DCHECK(codegen_->IsBaseline());
- LocationSummary* locations =
- new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
- locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
-}
-
-void InstructionCodeGeneratorARM64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
- DCHECK(codegen_->IsBaseline());
- // Will be generated at use site.
-}
-
// Simple implementation of packed switch - generate cascaded compare/jumps.
void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
LocationSummary* locations =
diff --git a/compiler/optimizing/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc
index 3229129..e34767c 100644
--- a/compiler/optimizing/code_generator_mips.cc
+++ b/compiler/optimizing/code_generator_mips.cc
@@ -4357,19 +4357,34 @@
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
InvokeRuntimeCallingConvention calling_convention;
- locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
- locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ if (instruction->IsStringAlloc()) {
+ locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
+ } else {
+ locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
+ locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ }
locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
}
void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
- codegen_->InvokeRuntime(
- GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(),
- instruction,
- instruction->GetDexPc(),
- nullptr,
- IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck));
- CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ if (instruction->IsStringAlloc()) {
+ // String is allocated through StringFactory. Call NewEmptyString entry point.
+ Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
+ MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsWordSize);
+ __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
+ __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
+ __ Jalr(T9);
+ __ Nop();
+ codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
+ } else {
+ codegen_->InvokeRuntime(
+ GetThreadOffset<kMipsWordSize>(instruction->GetEntrypoint()).Int32Value(),
+ instruction,
+ instruction->GetDexPc(),
+ nullptr,
+ IsDirectEntrypoint(kQuickAllocObjectWithAccessCheck));
+ CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ }
}
void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
@@ -5222,18 +5237,6 @@
HandleCondition(comp);
}
-void LocationsBuilderMIPS::VisitFakeString(HFakeString* instruction) {
- DCHECK(codegen_->IsBaseline());
- LocationSummary* locations =
- new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
- locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
-}
-
-void InstructionCodeGeneratorMIPS::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
- DCHECK(codegen_->IsBaseline());
- // Will be generated at use site.
-}
-
void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
diff --git a/compiler/optimizing/code_generator_mips64.cc b/compiler/optimizing/code_generator_mips64.cc
index 38c32ca..79cd56d 100644
--- a/compiler/optimizing/code_generator_mips64.cc
+++ b/compiler/optimizing/code_generator_mips64.cc
@@ -3515,17 +3515,32 @@
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
InvokeRuntimeCallingConvention calling_convention;
- locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
- locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ if (instruction->IsStringAlloc()) {
+ locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
+ } else {
+ locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
+ locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ }
locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
}
void InstructionCodeGeneratorMIPS64::VisitNewInstance(HNewInstance* instruction) {
- codegen_->InvokeRuntime(instruction->GetEntrypoint(),
- instruction,
- instruction->GetDexPc(),
- nullptr);
- CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ if (instruction->IsStringAlloc()) {
+ // String is allocated through StringFactory. Call NewEmptyString entry point.
+ GpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<GpuRegister>();
+ MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMips64WordSize);
+ __ LoadFromOffset(kLoadDoubleword, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
+ __ LoadFromOffset(kLoadDoubleword, T9, temp, code_offset.Int32Value());
+ __ Jalr(T9);
+ __ Nop();
+ codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
+ } else {
+ codegen_->InvokeRuntime(instruction->GetEntrypoint(),
+ instruction,
+ instruction->GetDexPc(),
+ nullptr);
+ CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ }
}
void LocationsBuilderMIPS64::VisitNot(HNot* instruction) {
@@ -4210,18 +4225,6 @@
HandleCondition(comp);
}
-void LocationsBuilderMIPS64::VisitFakeString(HFakeString* instruction) {
- DCHECK(codegen_->IsBaseline());
- LocationSummary* locations =
- new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
- locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
-}
-
-void InstructionCodeGeneratorMIPS64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
- DCHECK(codegen_->IsBaseline());
- // Will be generated at use site.
-}
-
// Simple implementation of packed switch - generate cascaded compare/jumps.
void LocationsBuilderMIPS64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
LocationSummary* locations =
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index c24d258..6259acd 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -3943,20 +3943,33 @@
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
locations->SetOut(Location::RegisterLocation(EAX));
- InvokeRuntimeCallingConvention calling_convention;
- locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
- locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ if (instruction->IsStringAlloc()) {
+ locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
+ } else {
+ InvokeRuntimeCallingConvention calling_convention;
+ locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
+ locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ }
}
void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) {
// Note: if heap poisoning is enabled, the entry point takes cares
// of poisoning the reference.
- codegen_->InvokeRuntime(instruction->GetEntrypoint(),
- instruction,
- instruction->GetDexPc(),
- nullptr);
- CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
- DCHECK(!codegen_->IsLeafMethod());
+ if (instruction->IsStringAlloc()) {
+ // String is allocated through StringFactory. Call NewEmptyString entry point.
+ Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
+ MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize);
+ __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString)));
+ __ call(Address(temp, code_offset.Int32Value()));
+ codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
+ } else {
+ codegen_->InvokeRuntime(instruction->GetEntrypoint(),
+ instruction,
+ instruction->GetDexPc(),
+ nullptr);
+ CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ DCHECK(!codegen_->IsLeafMethod());
+ }
}
void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) {
@@ -4187,19 +4200,28 @@
HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch(
const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
MethodReference target_method ATTRIBUTE_UNUSED) {
- switch (desired_dispatch_info.code_ptr_location) {
+ HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
+
+ // We disable pc-relative load when there is an irreducible loop, as the optimization
+ // is incompatible with it.
+ if (GetGraph()->HasIrreducibleLoops() &&
+ (dispatch_info.method_load_kind ==
+ HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
+ dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
+ }
+ switch (dispatch_info.code_ptr_location) {
case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
// For direct code, we actually prefer to call via the code pointer from ArtMethod*.
// (Though the direct CALL ptr16:32 is available for consideration).
return HInvokeStaticOrDirect::DispatchInfo {
- desired_dispatch_info.method_load_kind,
+ dispatch_info.method_load_kind,
HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
- desired_dispatch_info.method_load_data,
+ dispatch_info.method_load_data,
0u
};
default:
- return desired_dispatch_info;
+ return dispatch_info;
}
}
@@ -6746,18 +6768,6 @@
LOG(FATAL) << "Unreachable";
}
-void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) {
- DCHECK(codegen_->IsBaseline());
- LocationSummary* locations =
- new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
- locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
-}
-
-void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
- DCHECK(codegen_->IsBaseline());
- // Will be generated at use site.
-}
-
// Simple implementation of packed switch - generate cascaded compare/jumps.
void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) {
LocationSummary* locations =
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 294b40e..e024ce2 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -3912,21 +3912,33 @@
LocationSummary* locations =
new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
InvokeRuntimeCallingConvention calling_convention;
- locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
- locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ if (instruction->IsStringAlloc()) {
+ locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
+ } else {
+ locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
+ locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
+ }
locations->SetOut(Location::RegisterLocation(RAX));
}
void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) {
// Note: if heap poisoning is enabled, the entry point takes cares
// of poisoning the reference.
- codegen_->InvokeRuntime(instruction->GetEntrypoint(),
- instruction,
- instruction->GetDexPc(),
- nullptr);
- CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
-
- DCHECK(!codegen_->IsLeafMethod());
+ if (instruction->IsStringAlloc()) {
+ // String is allocated through StringFactory. Call NewEmptyString entry point.
+ CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>();
+ MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize);
+ __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true));
+ __ call(Address(temp, code_offset.SizeValue()));
+ codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
+ } else {
+ codegen_->InvokeRuntime(instruction->GetEntrypoint(),
+ instruction,
+ instruction->GetDexPc(),
+ nullptr);
+ CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
+ DCHECK(!codegen_->IsLeafMethod());
+ }
}
void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) {
@@ -6323,18 +6335,6 @@
LOG(FATAL) << "Unreachable";
}
-void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) {
- DCHECK(codegen_->IsBaseline());
- LocationSummary* locations =
- new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
- locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
-}
-
-void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
- DCHECK(codegen_->IsBaseline());
- // Will be generated at use site.
-}
-
// Simple implementation of packed switch - generate cascaded compare/jumps.
void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
LocationSummary* locations =
diff --git a/compiler/optimizing/dead_code_elimination.cc b/compiler/optimizing/dead_code_elimination.cc
index 67ff87a..86a695b 100644
--- a/compiler/optimizing/dead_code_elimination.cc
+++ b/compiler/optimizing/dead_code_elimination.cc
@@ -81,12 +81,6 @@
}
}
-static void MarkLoopHeadersContaining(const HBasicBlock& block, ArenaBitVector* set) {
- for (HLoopInformationOutwardIterator it(block); !it.Done(); it.Advance()) {
- set->SetBit(it.Current()->GetHeader()->GetBlockId());
- }
-}
-
void HDeadCodeElimination::MaybeRecordDeadBlock(HBasicBlock* block) {
if (stats_ != nullptr) {
stats_->RecordStat(MethodCompilationStat::kRemovedDeadInstruction,
@@ -98,36 +92,45 @@
// Classify blocks as reachable/unreachable.
ArenaAllocator* allocator = graph_->GetArena();
ArenaBitVector live_blocks(allocator, graph_->GetBlocks().size(), false);
- ArenaBitVector affected_loops(allocator, graph_->GetBlocks().size(), false);
MarkReachableBlocks(graph_, &live_blocks);
bool removed_one_or_more_blocks = false;
+ // If the graph has irreducible loops we need to reset all graph analysis we have done
+ // before: the irreducible loop can be turned into a reducible one.
+ // For simplicity, we do the full computation regardless of the type of the loops.
+ bool rerun_dominance_and_loop_analysis = false;
// Remove all dead blocks. Iterate in post order because removal needs the
// block's chain of dominators and nested loops need to be updated from the
// inside out.
for (HPostOrderIterator it(*graph_); !it.Done(); it.Advance()) {
HBasicBlock* block = it.Current();
+ if (block->IsLoopHeader() && block->GetLoopInformation()->IsIrreducible()) {
+ rerun_dominance_and_loop_analysis = true;
+ }
int id = block->GetBlockId();
- if (live_blocks.IsBitSet(id)) {
- if (affected_loops.IsBitSet(id)) {
- DCHECK(block->IsLoopHeader());
- block->GetLoopInformation()->Update();
- }
- } else {
+ if (!live_blocks.IsBitSet(id)) {
MaybeRecordDeadBlock(block);
- MarkLoopHeadersContaining(*block, &affected_loops);
block->DisconnectAndDelete();
removed_one_or_more_blocks = true;
+ if (block->IsInLoop()) {
+ rerun_dominance_and_loop_analysis = true;
+ }
}
}
// If we removed at least one block, we need to recompute the full
// dominator tree and try block membership.
if (removed_one_or_more_blocks) {
- graph_->ClearDominanceInformation();
- graph_->ComputeDominanceInformation();
- graph_->ComputeTryBlockInformation();
+ if (rerun_dominance_and_loop_analysis) {
+ graph_->ClearLoopInformation();
+ graph_->ClearDominanceInformation();
+ graph_->BuildDominatorTree();
+ } else {
+ graph_->ClearDominanceInformation();
+ graph_->ComputeDominanceInformation();
+ graph_->ComputeTryBlockInformation();
+ }
}
// Connect successive blocks created by dead branches. Order does not matter.
diff --git a/compiler/optimizing/dex_cache_array_fixups_arm.cc b/compiler/optimizing/dex_cache_array_fixups_arm.cc
index 6582063..3db254a 100644
--- a/compiler/optimizing/dex_cache_array_fixups_arm.cc
+++ b/compiler/optimizing/dex_cache_array_fixups_arm.cc
@@ -83,6 +83,11 @@
};
void DexCacheArrayFixups::Run() {
+ if (graph_->HasIrreducibleLoops()) {
+ // Do not run this optimization, as irreducible loops do not work with an instruction
+ // that can be live-in at the irreducible loop header.
+ return;
+ }
DexCacheArrayFixupsVisitor visitor(graph_);
visitor.VisitInsertionOrder();
visitor.MoveBasesIfNeeded();
diff --git a/compiler/optimizing/find_loops_test.cc b/compiler/optimizing/find_loops_test.cc
index 9b0eb70..4770fa2 100644
--- a/compiler/optimizing/find_loops_test.cc
+++ b/compiler/optimizing/find_loops_test.cc
@@ -33,7 +33,6 @@
const DexFile::CodeItem* item = reinterpret_cast<const DexFile::CodeItem*>(data);
builder.BuildGraph(*item);
graph->BuildDominatorTree();
- graph->AnalyzeNaturalLoops();
return graph;
}
diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc
index 6d0bdbe..9439ba0 100644
--- a/compiler/optimizing/graph_checker.cc
+++ b/compiler/optimizing/graph_checker.cc
@@ -391,6 +391,15 @@
}
}
+ // Ensure dominated blocks have `block` as the dominator.
+ for (HBasicBlock* dominated : block->GetDominatedBlocks()) {
+ if (dominated->GetDominator() != block) {
+ AddError(StringPrintf("Block %d should be the dominator of %d.",
+ block->GetBlockId(),
+ dominated->GetBlockId()));
+ }
+ }
+
// Ensure there is no critical edge (i.e., an edge connecting a
// block with multiple successors to a block with multiple
// predecessors). Exceptional edges are synthesized and hence
@@ -467,13 +476,7 @@
int id = loop_header->GetBlockId();
HLoopInformation* loop_information = loop_header->GetLoopInformation();
- // Ensure the pre-header block is first in the list of predecessors of a loop
- // header and that the header block is its only successor.
- if (!loop_header->IsLoopPreHeaderFirstPredecessor()) {
- AddError(StringPrintf(
- "Loop pre-header is not the first predecessor of the loop header %d.",
- id));
- } else if (loop_information->GetPreHeader()->GetSuccessors().size() != 1) {
+ if (loop_information->GetPreHeader()->GetSuccessors().size() != 1) {
AddError(StringPrintf(
"Loop pre-header %d of loop defined by header %d has %zu successors.",
loop_information->GetPreHeader()->GetBlockId(),
@@ -532,20 +535,6 @@
}
}
- // Ensure all blocks in the loop are live and dominated by the loop header.
- for (uint32_t i : loop_blocks.Indexes()) {
- HBasicBlock* loop_block = GetGraph()->GetBlocks()[i];
- if (loop_block == nullptr) {
- AddError(StringPrintf("Loop defined by header %d contains a previously removed block %d.",
- id,
- i));
- } else if (!loop_header->Dominates(loop_block)) {
- AddError(StringPrintf("Loop block %d not dominated by loop header %d.",
- i,
- id));
- }
- }
-
// If this is a nested loop, ensure the outer loops contain a superset of the blocks.
for (HLoopInformationOutwardIterator it(*loop_header); !it.Done(); it.Advance()) {
HLoopInformation* outer_info = it.Current();
@@ -556,6 +545,29 @@
outer_info->GetHeader()->GetBlockId()));
}
}
+
+ // Ensure the pre-header block is first in the list of predecessors of a loop
+ // header and that the header block is its only successor.
+ if (!loop_header->IsLoopPreHeaderFirstPredecessor()) {
+ AddError(StringPrintf(
+ "Loop pre-header is not the first predecessor of the loop header %d.",
+ id));
+ }
+
+ // Ensure all blocks in the loop are live and dominated by the loop header in
+ // the case of natural loops.
+ for (uint32_t i : loop_blocks.Indexes()) {
+ HBasicBlock* loop_block = GetGraph()->GetBlocks()[i];
+ if (loop_block == nullptr) {
+ AddError(StringPrintf("Loop defined by header %d contains a previously removed block %d.",
+ id,
+ i));
+ } else if (!loop_information->IsIrreducible() && !loop_header->Dominates(loop_block)) {
+ AddError(StringPrintf("Loop block %d not dominated by loop header %d.",
+ i,
+ id));
+ }
+ }
}
void SSAChecker::VisitInstruction(HInstruction* instruction) {
@@ -606,6 +618,34 @@
instruction->GetId()));
}
}
+
+ if (instruction->CanThrowIntoCatchBlock()) {
+ // Find the top-level environment. This corresponds to the environment of
+ // the catch block since we do not inline methods with try/catch.
+ HEnvironment* environment = instruction->GetEnvironment();
+ while (environment->GetParent() != nullptr) {
+ environment = environment->GetParent();
+ }
+
+ // Find all catch blocks and test that `instruction` has an environment
+ // value for each one.
+ const HTryBoundary& entry = instruction->GetBlock()->GetTryCatchInformation()->GetTryEntry();
+ for (HBasicBlock* catch_block : entry.GetExceptionHandlers()) {
+ for (HInstructionIterator phi_it(catch_block->GetPhis()); !phi_it.Done(); phi_it.Advance()) {
+ HPhi* catch_phi = phi_it.Current()->AsPhi();
+ if (environment->GetInstructionAt(catch_phi->GetRegNumber()) == nullptr) {
+ AddError(StringPrintf("Instruction %s:%d throws into catch block %d "
+ "with catch phi %d for vreg %d but its "
+ "corresponding environment slot is empty.",
+ instruction->DebugName(),
+ instruction->GetId(),
+ catch_block->GetBlockId(),
+ catch_phi->GetId(),
+ catch_phi->GetRegNumber()));
+ }
+ }
+ }
+ }
}
static Primitive::Type PrimitiveKind(Primitive::Type type) {
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc
index 5f1328f..32c3a92 100644
--- a/compiler/optimizing/graph_visualizer.cc
+++ b/compiler/optimizing/graph_visualizer.cc
@@ -486,7 +486,9 @@
StartAttributeStream("is_low") << interval->IsLowInterval();
StartAttributeStream("is_high") << interval->IsHighInterval();
}
- } else if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
+ }
+
+ if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
StartAttributeStream("liveness") << instruction->GetLifetimePosition();
LocationSummary* locations = instruction->GetLocations();
if (locations != nullptr) {
@@ -498,15 +500,29 @@
attr << inputs << "->";
DumpLocation(attr, locations->Out());
}
- } else if (IsPass(LICM::kLoopInvariantCodeMotionPassName)
- || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName)) {
+ }
+
+ if (IsPass(LICM::kLoopInvariantCodeMotionPassName)
+ || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName)
+ || IsPass(HDeadCodeElimination::kInitialDeadCodeEliminationPassName)
+ || IsPass(SsaBuilder::kSsaBuilderPassName)) {
HLoopInformation* info = instruction->GetBlock()->GetLoopInformation();
if (info == nullptr) {
StartAttributeStream("loop") << "none";
} else {
StartAttributeStream("loop") << "B" << info->GetHeader()->GetBlockId();
+ HLoopInformation* outer = info->GetPreHeader()->GetLoopInformation();
+ if (outer != nullptr) {
+ StartAttributeStream("outer_loop") << "B" << outer->GetHeader()->GetBlockId();
+ } else {
+ StartAttributeStream("outer_loop") << "none";
+ }
+ StartAttributeStream("irreducible")
+ << std::boolalpha << info->IsIrreducible() << std::noboolalpha;
}
- } else if ((IsPass(SsaBuilder::kSsaBuilderPassName)
+ }
+
+ if ((IsPass(SsaBuilder::kSsaBuilderPassName)
|| IsPass(HInliner::kInlinerPassName))
&& (instruction->GetType() == Primitive::kPrimNot)) {
ReferenceTypeInfo info = instruction->IsLoadClass()
diff --git a/compiler/optimizing/gvn.cc b/compiler/optimizing/gvn.cc
index 4af111b..b492278 100644
--- a/compiler/optimizing/gvn.cc
+++ b/compiler/optimizing/gvn.cc
@@ -125,6 +125,14 @@
});
}
+ void Clear() {
+ num_entries_ = 0;
+ for (size_t i = 0; i < num_buckets_; ++i) {
+ buckets_[i] = nullptr;
+ }
+ buckets_owned_.SetInitialBits(num_buckets_);
+ }
+
// Updates this set by intersecting with instructions in a predecessor's set.
void IntersectWith(ValueSet* predecessor) {
if (IsEmpty()) {
@@ -191,14 +199,6 @@
return clone_iterator;
}
- void Clear() {
- num_entries_ = 0;
- for (size_t i = 0; i < num_buckets_; ++i) {
- buckets_[i] = nullptr;
- }
- buckets_owned_.SetInitialBits(num_buckets_);
- }
-
// Iterates over buckets with impure instructions (even indices) and deletes
// the ones on which 'cond' returns true.
template<typename Functor>
@@ -261,11 +261,14 @@
}
}
- // Generates a hash code for an instruction. Pure instructions are put into
- // odd buckets to speed up deletion.
+ // Generates a hash code for an instruction.
size_t HashCode(HInstruction* instruction) const {
size_t hash_code = instruction->ComputeHashCode();
- if (instruction->GetSideEffects().HasDependencies()) {
+ // Pure instructions are put into odd buckets to speed up deletion. Note that in the
+ // case of irreducible loops, we don't put pure instructions in odd buckets, as we
+ // need to delete them when entering the loop.
+ if (instruction->GetSideEffects().HasDependencies() ||
+ instruction->GetBlock()->GetGraph()->HasIrreducibleLoops()) {
return (hash_code << 1) | 0;
} else {
return (hash_code << 1) | 1;
@@ -360,8 +363,14 @@
}
if (!set->IsEmpty()) {
if (block->IsLoopHeader()) {
- DCHECK_EQ(block->GetDominator(), block->GetLoopInformation()->GetPreHeader());
- set->Kill(side_effects_.GetLoopEffects(block));
+ if (block->GetLoopInformation()->IsIrreducible()) {
+ // To satisfy our linear scan algorithm, no instruction should flow in an irreducible
+ // loop header.
+ set->Clear();
+ } else {
+ DCHECK_EQ(block->GetDominator(), block->GetLoopInformation()->GetPreHeader());
+ set->Kill(side_effects_.GetLoopEffects(block));
+ }
} else if (predecessors.size() > 1) {
for (HBasicBlock* predecessor : predecessors) {
set->IntersectWith(sets_[predecessor->GetBlockId()]);
diff --git a/compiler/optimizing/induction_var_analysis.cc b/compiler/optimizing/induction_var_analysis.cc
index eef6cef..37f2d79 100644
--- a/compiler/optimizing/induction_var_analysis.cc
+++ b/compiler/optimizing/induction_var_analysis.cc
@@ -76,7 +76,9 @@
// range analysis on outer loop while visiting inner loops.
for (HReversePostOrderIterator it_graph(*graph_); !it_graph.Done(); it_graph.Advance()) {
HBasicBlock* graph_block = it_graph.Current();
- if (graph_block->IsLoopHeader()) {
+ // Don't analyze irreducible loops.
+ // TODO(ajcbik): could/should we remove this restriction?
+ if (graph_block->IsLoopHeader() && !graph_block->GetLoopInformation()->IsIrreducible()) {
VisitLoop(graph_block->GetLoopInformation());
}
}
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index 48d3299..293282e 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -539,7 +539,7 @@
return false;
}
- if (callee_graph->TryBuildingSsa(handles_) != kBuildSsaSuccess) {
+ if (callee_graph->TryBuildingSsa(handles_) != kAnalysisSuccess) {
VLOG(compiler) << "Method " << PrettyMethod(method_index, callee_dex_file)
<< " could not be transformed to SSA";
return false;
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index b90afb1..49fc8c7 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -77,7 +77,6 @@
void VisitUShr(HUShr* instruction) OVERRIDE;
void VisitXor(HXor* instruction) OVERRIDE;
void VisitInstanceOf(HInstanceOf* instruction) OVERRIDE;
- void VisitFakeString(HFakeString* fake_string) OVERRIDE;
void VisitInvoke(HInvoke* invoke) OVERRIDE;
void VisitDeoptimize(HDeoptimize* deoptimize) OVERRIDE;
@@ -1179,48 +1178,6 @@
TryReplaceWithRotate(instruction);
}
-void InstructionSimplifierVisitor::VisitFakeString(HFakeString* instruction) {
- HInstruction* actual_string = nullptr;
-
- // Find the string we need to replace this instruction with. The actual string is
- // the return value of a StringFactory call.
- for (HUseIterator<HInstruction*> it(instruction->GetUses()); !it.Done(); it.Advance()) {
- HInstruction* use = it.Current()->GetUser();
- if (use->IsInvokeStaticOrDirect()
- && use->AsInvokeStaticOrDirect()->IsStringFactoryFor(instruction)) {
- use->AsInvokeStaticOrDirect()->RemoveFakeStringArgumentAsLastInput();
- actual_string = use;
- break;
- }
- }
-
- // Check that there is no other instruction that thinks it is the factory for that string.
- if (kIsDebugBuild) {
- CHECK(actual_string != nullptr);
- for (HUseIterator<HInstruction*> it(instruction->GetUses()); !it.Done(); it.Advance()) {
- HInstruction* use = it.Current()->GetUser();
- if (use->IsInvokeStaticOrDirect()) {
- CHECK(!use->AsInvokeStaticOrDirect()->IsStringFactoryFor(instruction));
- }
- }
- }
-
- // We need to remove any environment uses of the fake string that are not dominated by
- // `actual_string` to null.
- for (HUseIterator<HEnvironment*> it(instruction->GetEnvUses()); !it.Done(); it.Advance()) {
- HEnvironment* environment = it.Current()->GetUser();
- if (!actual_string->StrictlyDominates(environment->GetHolder())) {
- environment->RemoveAsUserOfInput(it.Current()->GetIndex());
- environment->SetRawEnvAt(it.Current()->GetIndex(), nullptr);
- }
- }
-
- // Only uses dominated by `actual_string` must remain. We can safely replace and remove
- // `instruction`.
- instruction->ReplaceWith(actual_string);
- instruction->GetBlock()->RemoveInstruction(instruction);
-}
-
void InstructionSimplifierVisitor::SimplifyStringEquals(HInvoke* instruction) {
HInstruction* argument = instruction->InputAt(1);
HInstruction* receiver = instruction->InputAt(0);
diff --git a/compiler/optimizing/instruction_simplifier_arm64.cc b/compiler/optimizing/instruction_simplifier_arm64.cc
index 6bbc751..4bcfc54 100644
--- a/compiler/optimizing/instruction_simplifier_arm64.cc
+++ b/compiler/optimizing/instruction_simplifier_arm64.cc
@@ -30,6 +30,15 @@
HInstruction* array,
HInstruction* index,
int access_size) {
+ if (kEmitCompilerReadBarrier) {
+ // The read barrier instrumentation does not support the
+ // HArm64IntermediateAddress instruction yet.
+ //
+ // TODO: Handle this case properly in the ARM64 code generator and
+ // re-enable this optimization; otherwise, remove this TODO.
+ // b/26601270
+ return;
+ }
if (index->IsConstant() ||
(index->IsBoundsCheck() && index->AsBoundsCheck()->GetIndex()->IsConstant())) {
// When the index is a constant all the addressing can be fitted in the
diff --git a/compiler/optimizing/licm.cc b/compiler/optimizing/licm.cc
index 02befc0..a6b4078 100644
--- a/compiler/optimizing/licm.cc
+++ b/compiler/optimizing/licm.cc
@@ -94,6 +94,16 @@
SideEffects loop_effects = side_effects_.GetLoopEffects(block);
HBasicBlock* pre_header = loop_info->GetPreHeader();
+ bool contains_irreducible_loop = false;
+ if (graph_->HasIrreducibleLoops()) {
+ for (HBlocksInLoopIterator it_loop(*loop_info); !it_loop.Done(); it_loop.Advance()) {
+ if (it_loop.Current()->GetLoopInformation()->IsIrreducible()) {
+ contains_irreducible_loop = true;
+ break;
+ }
+ }
+ }
+
for (HBlocksInLoopIterator it_loop(*loop_info); !it_loop.Done(); it_loop.Advance()) {
HBasicBlock* inner = it_loop.Current();
DCHECK(inner->IsInLoop());
@@ -104,6 +114,12 @@
}
visited.SetBit(inner->GetBlockId());
+ if (contains_irreducible_loop) {
+ // We cannot licm in an irreducible loop, or in a natural loop containing an
+ // irreducible loop.
+ continue;
+ }
+
// We can move an instruction that can throw only if it is the first
// throwing instruction in the loop. Note that the first potentially
// throwing instruction encountered that is not hoisted stops this
diff --git a/compiler/optimizing/load_store_elimination.cc b/compiler/optimizing/load_store_elimination.cc
index 2b313f6..c4492c8 100644
--- a/compiler/optimizing/load_store_elimination.cc
+++ b/compiler/optimizing/load_store_elimination.cc
@@ -582,9 +582,22 @@
DCHECK(block->IsLoopHeader());
int block_id = block->GetBlockId();
ArenaVector<HInstruction*>& heap_values = heap_values_for_[block_id];
+
+ // Don't eliminate loads in irreducible loops. This is safe for singletons, because
+ // they are always used by the non-eliminated loop-phi.
+ if (block->GetLoopInformation()->IsIrreducible()) {
+ if (kIsDebugBuild) {
+ for (size_t i = 0; i < heap_values.size(); i++) {
+ DCHECK_EQ(heap_values[i], kUnknownHeapValue);
+ }
+ }
+ return;
+ }
+
HBasicBlock* pre_header = block->GetLoopInformation()->GetPreHeader();
ArenaVector<HInstruction*>& pre_header_heap_values =
heap_values_for_[pre_header->GetBlockId()];
+
// Inherit the values from pre-header.
for (size_t i = 0; i < heap_values.size(); i++) {
heap_values[i] = pre_header_heap_values[i];
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 8de9700..854d92a 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include "nodes.h"
#include "code_generator.h"
@@ -90,6 +89,7 @@
for (size_t i = 0; i < blocks_.size(); ++i) {
if (!visited.IsBitSet(i)) {
HBasicBlock* block = blocks_[i];
+ if (block == nullptr) continue;
DCHECK(block->GetPhis().IsEmpty()) << "Phis are not inserted at this stage";
for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
RemoveAsUser(it.Current());
@@ -102,6 +102,7 @@
for (size_t i = 0; i < blocks_.size(); ++i) {
if (!visited.IsBitSet(i)) {
HBasicBlock* block = blocks_[i];
+ if (block == nullptr) continue;
// We only need to update the successor, which might be live.
for (HBasicBlock* successor : block->GetSuccessors()) {
successor->RemovePredecessor(block);
@@ -113,7 +114,7 @@
}
}
-void HGraph::BuildDominatorTree() {
+GraphAnalysisResult HGraph::BuildDominatorTree() {
// (1) Simplify the CFG so that catch blocks have only exceptional incoming
// edges. This invariant simplifies building SSA form because Phis cannot
// collect both normal- and exceptional-flow values at the same time.
@@ -130,7 +131,7 @@
RemoveInstructionsAsUsersFromDeadBlocks(visited);
// (4) Remove blocks not visited during the initial DFS.
- // Step (4) requires dead blocks to be removed from the
+ // Step (5) requires dead blocks to be removed from the
// predecessors list of live blocks.
RemoveDeadBlocks(visited);
@@ -140,6 +141,20 @@
// (6) Compute the dominance information and the reverse post order.
ComputeDominanceInformation();
+
+ // (7) Analyze loops discover through back edge analysis, and
+ // set the loop information on each block.
+ GraphAnalysisResult result = AnalyzeLoops();
+ if (result != kAnalysisSuccess) {
+ return result;
+ }
+
+ // (8) Precompute per-block try membership before entering the SSA builder,
+ // which needs the information to build catch block phis from values of
+ // locals at throwing instructions inside try blocks.
+ ComputeTryBlockInformation();
+
+ return kAnalysisSuccess;
}
void HGraph::ClearDominanceInformation() {
@@ -149,6 +164,17 @@
reverse_post_order_.clear();
}
+void HGraph::ClearLoopInformation() {
+ SetHasIrreducibleLoops(false);
+ for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) {
+ HBasicBlock* current = it.Current();
+ if (current->IsLoopHeader()) {
+ current->RemoveInstruction(current->GetLoopInformation()->GetSuspendCheck());
+ }
+ current->SetLoopInformation(nullptr);
+ }
+}
+
void HBasicBlock::ClearDominanceInformation() {
dominated_blocks_.clear();
dominator_ = nullptr;
@@ -190,31 +216,28 @@
// dominator of the block. We can then start visiting its successors.
if (++visits[successor->GetBlockId()] ==
successor->GetPredecessors().size() - successor->NumberOfBackEdges()) {
- successor->GetDominator()->AddDominatedBlock(successor);
reverse_post_order_.push_back(successor);
worklist.push_back(successor);
}
}
}
+
+ // Populate `dominated_blocks_` information after computing all dominators.
+ // The potential presence of irreducible loops require to do it after.
+ for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) {
+ HBasicBlock* block = it.Current();
+ if (!block->IsEntryBlock()) {
+ block->GetDominator()->AddDominatedBlock(block);
+ }
+ }
}
-BuildSsaResult HGraph::TryBuildingSsa(StackHandleScopeCollection* handles) {
- BuildDominatorTree();
-
- // The SSA builder requires loops to all be natural. Specifically, the dead phi
- // elimination phase checks the consistency of the graph when doing a post-order
- // visit for eliminating dead phis: a dead phi can only have loop header phi
- // users remaining when being visited.
- BuildSsaResult result = AnalyzeNaturalLoops();
- if (result != kBuildSsaSuccess) {
+GraphAnalysisResult HGraph::TryBuildingSsa(StackHandleScopeCollection* handles) {
+ GraphAnalysisResult result = BuildDominatorTree();
+ if (result != kAnalysisSuccess) {
return result;
}
- // Precompute per-block try membership before entering the SSA builder,
- // which needs the information to build catch block phis from values of
- // locals at throwing instructions inside try blocks.
- ComputeTryBlockInformation();
-
// Create the inexact Object reference type and store it in the HGraph.
ScopedObjectAccess soa(Thread::Current());
ClassLinker* linker = Runtime::Current()->GetClassLinker();
@@ -224,12 +247,12 @@
// Tranforms graph to SSA form.
result = SsaBuilder(this, handles).BuildSsa();
- if (result != kBuildSsaSuccess) {
+ if (result != kAnalysisSuccess) {
return result;
}
in_ssa_form_ = true;
- return kBuildSsaSuccess;
+ return kAnalysisSuccess;
}
HBasicBlock* HGraph::SplitEdge(HBasicBlock* block, HBasicBlock* successor) {
@@ -331,7 +354,7 @@
// can be invalidated. We remember the initial size to avoid iterating over the new blocks.
for (size_t block_id = 0u, end = blocks_.size(); block_id != end; ++block_id) {
HBasicBlock* catch_block = blocks_[block_id];
- if (!catch_block->IsCatchBlock()) {
+ if (catch_block == nullptr || !catch_block->IsCatchBlock()) {
continue;
}
@@ -438,7 +461,7 @@
}
}
-BuildSsaResult HGraph::AnalyzeNaturalLoops() const {
+GraphAnalysisResult HGraph::AnalyzeLoops() const {
// Order does not matter.
for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) {
HBasicBlock* block = it.Current();
@@ -446,16 +469,26 @@
if (block->IsCatchBlock()) {
// TODO: Dealing with exceptional back edges could be tricky because
// they only approximate the real control flow. Bail out for now.
- return kBuildSsaFailThrowCatchLoop;
+ return kAnalysisFailThrowCatchLoop;
}
- HLoopInformation* info = block->GetLoopInformation();
- if (!info->Populate()) {
- // Abort if the loop is non natural. We currently bailout in such cases.
- return kBuildSsaFailNonNaturalLoop;
- }
+ block->GetLoopInformation()->Populate();
}
}
- return kBuildSsaSuccess;
+ return kAnalysisSuccess;
+}
+
+void HLoopInformation::Dump(std::ostream& os) {
+ os << "header: " << header_->GetBlockId() << std::endl;
+ os << "pre header: " << GetPreHeader()->GetBlockId() << std::endl;
+ for (HBasicBlock* block : back_edges_) {
+ os << "back edge: " << block->GetBlockId() << std::endl;
+ }
+ for (HBasicBlock* block : header_->GetPredecessors()) {
+ os << "predecessor: " << block->GetBlockId() << std::endl;
+ }
+ for (uint32_t idx : blocks_.Indexes()) {
+ os << " in loop: " << idx << std::endl;
+ }
}
void HGraph::InsertConstant(HConstant* constant) {
@@ -555,61 +588,65 @@
}
}
-bool HLoopInformation::Populate() {
+void HLoopInformation::PopulateIrreducibleRecursive(HBasicBlock* block) {
+ if (blocks_.IsBitSet(block->GetBlockId())) {
+ return;
+ }
+
+ if (block->IsLoopHeader()) {
+ // If we hit a loop header in an irreducible loop, we first check if the
+ // pre header of that loop belongs to the currently analyzed loop. If it does,
+ // then we visit the back edges.
+ // Note that we cannot use GetPreHeader, as the loop may have not been populated
+ // yet.
+ HBasicBlock* pre_header = block->GetPredecessors()[0];
+ PopulateIrreducibleRecursive(pre_header);
+ if (blocks_.IsBitSet(pre_header->GetBlockId())) {
+ blocks_.SetBit(block->GetBlockId());
+ block->SetInLoop(this);
+ HLoopInformation* info = block->GetLoopInformation();
+ for (HBasicBlock* back_edge : info->GetBackEdges()) {
+ PopulateIrreducibleRecursive(back_edge);
+ }
+ }
+ } else {
+ // Visit all predecessors. If one predecessor is part of the loop, this
+ // block is also part of this loop.
+ for (HBasicBlock* predecessor : block->GetPredecessors()) {
+ PopulateIrreducibleRecursive(predecessor);
+ if (blocks_.IsBitSet(predecessor->GetBlockId())) {
+ blocks_.SetBit(block->GetBlockId());
+ block->SetInLoop(this);
+ }
+ }
+ }
+}
+
+void HLoopInformation::Populate() {
DCHECK_EQ(blocks_.NumSetBits(), 0u) << "Loop information has already been populated";
+ // Populate this loop: starting with the back edge, recursively add predecessors
+ // that are not already part of that loop. Set the header as part of the loop
+ // to end the recursion.
+ // This is a recursive implementation of the algorithm described in
+ // "Advanced Compiler Design & Implementation" (Muchnick) p192.
+ blocks_.SetBit(header_->GetBlockId());
+ header_->SetInLoop(this);
for (HBasicBlock* back_edge : GetBackEdges()) {
DCHECK(back_edge->GetDominator() != nullptr);
if (!header_->Dominates(back_edge)) {
- // This loop is not natural. Do not bother going further.
- return false;
+ irreducible_ = true;
+ header_->GetGraph()->SetHasIrreducibleLoops(true);
+ PopulateIrreducibleRecursive(back_edge);
+ } else {
+ PopulateRecursive(back_edge);
}
-
- // Populate this loop: starting with the back edge, recursively add predecessors
- // that are not already part of that loop. Set the header as part of the loop
- // to end the recursion.
- // This is a recursive implementation of the algorithm described in
- // "Advanced Compiler Design & Implementation" (Muchnick) p192.
- blocks_.SetBit(header_->GetBlockId());
- PopulateRecursive(back_edge);
- }
- return true;
-}
-
-void HLoopInformation::Update() {
- HGraph* graph = header_->GetGraph();
- for (uint32_t id : blocks_.Indexes()) {
- HBasicBlock* block = graph->GetBlocks()[id];
- // Reset loop information of non-header blocks inside the loop, except
- // members of inner nested loops because those should already have been
- // updated by their own LoopInformation.
- if (block->GetLoopInformation() == this && block != header_) {
- block->SetLoopInformation(nullptr);
- }
- }
- blocks_.ClearAllBits();
-
- if (back_edges_.empty()) {
- // The loop has been dismantled, delete its suspend check and remove info
- // from the header.
- DCHECK(HasSuspendCheck());
- header_->RemoveInstruction(suspend_check_);
- header_->SetLoopInformation(nullptr);
- header_ = nullptr;
- suspend_check_ = nullptr;
- } else {
- if (kIsDebugBuild) {
- for (HBasicBlock* back_edge : back_edges_) {
- DCHECK(header_->Dominates(back_edge));
- }
- }
- // This loop still has reachable back edges. Repopulate the list of blocks.
- bool populate_successful = Populate();
- DCHECK(populate_successful);
}
}
HBasicBlock* HLoopInformation::GetPreHeader() const {
- return header_->GetDominator();
+ HBasicBlock* block = header_->GetPredecessors()[0];
+ DCHECK(irreducible_ || (block == header_->GetDominator()));
+ return block;
}
bool HLoopInformation::Contains(const HBasicBlock& block) const {
@@ -2169,6 +2206,11 @@
}
}
+bool HNewInstance::IsStringAlloc() const {
+ ScopedObjectAccess soa(Thread::Current());
+ return GetReferenceTypeInfo().IsStringClass();
+}
+
bool HInvoke::NeedsEnvironment() const {
if (!IsIntrinsic()) {
return true;
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index b65d0f5..859d570 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -44,7 +44,6 @@
class HCurrentMethod;
class HDoubleConstant;
class HEnvironment;
-class HFakeString;
class HFloatConstant;
class HGraphBuilder;
class HGraphVisitor;
@@ -98,11 +97,10 @@
kCondAE, // >=
};
-enum BuildSsaResult {
- kBuildSsaFailNonNaturalLoop,
- kBuildSsaFailThrowCatchLoop,
- kBuildSsaFailAmbiguousArrayOp,
- kBuildSsaSuccess,
+enum GraphAnalysisResult {
+ kAnalysisFailThrowCatchLoop,
+ kAnalysisFailAmbiguousArrayOp,
+ kAnalysisSuccess,
};
class HInstructionList : public ValueObject {
@@ -289,6 +287,7 @@
temporaries_vreg_slots_(0),
has_bounds_checks_(false),
has_try_catch_(false),
+ has_irreducible_loops_(false),
debuggable_(debuggable),
current_instruction_id_(start_instruction_id),
dex_file_(dex_file),
@@ -324,20 +323,20 @@
// Try building the SSA form of this graph, with dominance computation and
// loop recognition. Returns a code specifying that it was successful or the
// reason for failure.
- BuildSsaResult TryBuildingSsa(StackHandleScopeCollection* handles);
+ GraphAnalysisResult TryBuildingSsa(StackHandleScopeCollection* handles);
void ComputeDominanceInformation();
void ClearDominanceInformation();
-
- void BuildDominatorTree();
+ void ClearLoopInformation();
+ void FindBackEdges(ArenaBitVector* visited);
+ GraphAnalysisResult BuildDominatorTree();
void SimplifyCFG();
void SimplifyCatchBlocks();
// Analyze all natural loops in this graph. Returns a code specifying that it
// was successful or the reason for failure. The method will fail if a loop
- // is not natural, that is the header does not dominate a back edge, or if it
// is a throw-catch loop, i.e. the header is a catch block.
- BuildSsaResult AnalyzeNaturalLoops() const;
+ GraphAnalysisResult AnalyzeLoops() const;
// Iterate over blocks to compute try block membership. Needs reverse post
// order and loop information.
@@ -482,6 +481,9 @@
bool HasTryCatch() const { return has_try_catch_; }
void SetHasTryCatch(bool value) { has_try_catch_ = value; }
+ bool HasIrreducibleLoops() const { return has_irreducible_loops_; }
+ void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; }
+
ArtMethod* GetArtMethod() const { return art_method_; }
void SetArtMethod(ArtMethod* method) { art_method_ = method; }
@@ -491,7 +493,6 @@
HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor);
private:
- void FindBackEdges(ArenaBitVector* visited);
void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const;
void RemoveDeadBlocks(const ArenaBitVector& visited);
@@ -558,6 +559,9 @@
// try/catch-related passes if false.
bool has_try_catch_;
+ // Flag whether there are any irreducible loops in the graph.
+ bool has_irreducible_loops_;
+
// Indicates whether the graph should be compiled in a way that
// ensures full debuggability. If false, we can apply more
// aggressive optimizations that may limit the level of debugging.
@@ -613,12 +617,17 @@
HLoopInformation(HBasicBlock* header, HGraph* graph)
: header_(header),
suspend_check_(nullptr),
+ irreducible_(false),
back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)),
// Make bit vector growable, as the number of blocks may change.
blocks_(graph->GetArena(), graph->GetBlocks().size(), true) {
back_edges_.reserve(kDefaultNumberOfBackEdges);
}
+ bool IsIrreducible() const { return irreducible_; }
+
+ void Dump(std::ostream& os);
+
HBasicBlock* GetHeader() const {
return header_;
}
@@ -661,15 +670,8 @@
ReplaceElement(back_edges_, existing, new_back_edge);
}
- // Finds blocks that are part of this loop. Returns whether the loop is a natural loop,
- // that is the header dominates the back edge.
- bool Populate();
-
- // Reanalyzes the loop by removing loop info from its blocks and re-running
- // Populate(). If there are no back edges left, the loop info is completely
- // removed as well as its SuspendCheck instruction. It must be run on nested
- // inner loops first.
- void Update();
+ // Finds blocks that are part of this loop.
+ void Populate();
// Returns whether this loop information contains `block`.
// Note that this loop information *must* be populated before entering this function.
@@ -690,9 +692,11 @@
private:
// Internal recursive implementation of `Populate`.
void PopulateRecursive(HBasicBlock* block);
+ void PopulateIrreducibleRecursive(HBasicBlock* block);
HBasicBlock* header_;
HSuspendCheck* suspend_check_;
+ bool irreducible_;
ArenaVector<HBasicBlock*> back_edges_;
ArenaBitVector blocks_;
@@ -1019,6 +1023,11 @@
return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader();
}
+ bool IsFirstPredecessorBackEdge() const {
+ DCHECK(IsLoopHeader());
+ return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]);
+ }
+
HLoopInformation* GetLoopInformation() const {
return loop_information_;
}
@@ -1156,7 +1165,6 @@
M(DoubleConstant, Constant) \
M(Equal, Condition) \
M(Exit, Instruction) \
- M(FakeString, Instruction) \
M(FloatConstant, Constant) \
M(Goto, Instruction) \
M(GreaterThan, Condition) \
@@ -1831,7 +1839,10 @@
void SetBlock(HBasicBlock* block) { block_ = block; }
bool IsInBlock() const { return block_ != nullptr; }
bool IsInLoop() const { return block_->IsInLoop(); }
- bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); }
+ bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); }
+ bool IsIrreducibleLoopHeaderPhi() const {
+ return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible();
+ }
virtual size_t InputCount() const = 0;
HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); }
@@ -3252,6 +3263,61 @@
DISALLOW_COPY_AND_ASSIGN(HDoubleConstant);
};
+class HNewInstance : public HExpression<2> {
+ public:
+ HNewInstance(HInstruction* cls,
+ HCurrentMethod* current_method,
+ uint32_t dex_pc,
+ uint16_t type_index,
+ const DexFile& dex_file,
+ bool can_throw,
+ bool finalizable,
+ QuickEntrypointEnum entrypoint)
+ : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc),
+ type_index_(type_index),
+ dex_file_(dex_file),
+ can_throw_(can_throw),
+ finalizable_(finalizable),
+ entrypoint_(entrypoint) {
+ SetRawInputAt(0, cls);
+ SetRawInputAt(1, current_method);
+ }
+
+ uint16_t GetTypeIndex() const { return type_index_; }
+ const DexFile& GetDexFile() const { return dex_file_; }
+
+ // Calls runtime so needs an environment.
+ bool NeedsEnvironment() const OVERRIDE { return true; }
+
+ // It may throw when called on type that's not instantiable/accessible.
+ // It can throw OOME.
+ // TODO: distinguish between the two cases so we can for example allow allocation elimination.
+ bool CanThrow() const OVERRIDE { return can_throw_ || true; }
+
+ bool IsFinalizable() const { return finalizable_; }
+
+ bool CanBeNull() const OVERRIDE { return false; }
+
+ QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; }
+
+ void SetEntrypoint(QuickEntrypointEnum entrypoint) {
+ entrypoint_ = entrypoint;
+ }
+
+ bool IsStringAlloc() const;
+
+ DECLARE_INSTRUCTION(NewInstance);
+
+ private:
+ const uint16_t type_index_;
+ const DexFile& dex_file_;
+ const bool can_throw_;
+ const bool finalizable_;
+ QuickEntrypointEnum entrypoint_;
+
+ DISALLOW_COPY_AND_ASSIGN(HNewInstance);
+};
+
enum class Intrinsics {
#define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \
k ## Name,
@@ -3545,10 +3611,9 @@
// Get the index of the special input, if any.
//
- // If the invoke IsStringInit(), it initially has a HFakeString special argument
- // which is removed by the instruction simplifier; if the invoke HasCurrentMethodInput(),
- // the "special input" is the current method pointer; otherwise there may be one
- // platform-specific special input, such as PC-relative addressing base.
+ // If the invoke HasCurrentMethodInput(), the "special input" is the current
+ // method pointer; otherwise there may be one platform-specific special input,
+ // such as PC-relative addressing base.
uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); }
InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; }
@@ -3622,20 +3687,18 @@
DCHECK(!IsStaticWithExplicitClinitCheck());
}
- bool IsStringFactoryFor(HFakeString* str) const {
- if (!IsStringInit()) return false;
- DCHECK(!HasCurrentMethodInput());
- if (InputCount() == (number_of_arguments_)) return false;
- return InputAt(InputCount() - 1)->AsFakeString() == str;
+ HNewInstance* GetThisArgumentOfStringInit() const {
+ DCHECK(IsStringInit());
+ size_t index = InputCount() - 1;
+ DCHECK(InputAt(index)->IsNewInstance());
+ return InputAt(index)->AsNewInstance();
}
- void RemoveFakeStringArgumentAsLastInput() {
+ void RemoveThisArgumentOfStringInit() {
DCHECK(IsStringInit());
- size_t last_input_index = InputCount() - 1;
- HInstruction* last_input = InputAt(last_input_index);
- DCHECK(last_input != nullptr);
- DCHECK(last_input->IsFakeString()) << last_input->DebugName();
- RemoveAsUserOfInput(last_input_index);
+ size_t index = InputCount() - 1;
+ DCHECK(InputAt(index)->IsNewInstance());
+ RemoveAsUserOfInput(index);
inputs_.pop_back();
}
@@ -3743,59 +3806,6 @@
DISALLOW_COPY_AND_ASSIGN(HInvokeInterface);
};
-class HNewInstance : public HExpression<2> {
- public:
- HNewInstance(HInstruction* cls,
- HCurrentMethod* current_method,
- uint32_t dex_pc,
- uint16_t type_index,
- const DexFile& dex_file,
- bool can_throw,
- bool finalizable,
- QuickEntrypointEnum entrypoint)
- : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc),
- type_index_(type_index),
- dex_file_(dex_file),
- can_throw_(can_throw),
- finalizable_(finalizable),
- entrypoint_(entrypoint) {
- SetRawInputAt(0, cls);
- SetRawInputAt(1, current_method);
- }
-
- uint16_t GetTypeIndex() const { return type_index_; }
- const DexFile& GetDexFile() const { return dex_file_; }
-
- // Calls runtime so needs an environment.
- bool NeedsEnvironment() const OVERRIDE { return true; }
-
- // It may throw when called on type that's not instantiable/accessible.
- // It can throw OOME.
- // TODO: distinguish between the two cases so we can for example allow allocation elimination.
- bool CanThrow() const OVERRIDE { return can_throw_ || true; }
-
- bool IsFinalizable() const { return finalizable_; }
-
- bool CanBeNull() const OVERRIDE { return false; }
-
- QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; }
-
- void SetEntrypoint(QuickEntrypointEnum entrypoint) {
- entrypoint_ = entrypoint;
- }
-
- DECLARE_INSTRUCTION(NewInstance);
-
- private:
- const uint16_t type_index_;
- const DexFile& dex_file_;
- const bool can_throw_;
- const bool finalizable_;
- QuickEntrypointEnum entrypoint_;
-
- DISALLOW_COPY_AND_ASSIGN(HNewInstance);
-};
-
class HNeg : public HUnaryOperation {
public:
HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc)
@@ -4010,8 +4020,10 @@
class HDivZeroCheck : public HExpression<1> {
public:
+ // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException`
+ // constructor.
HDivZeroCheck(HInstruction* value, uint32_t dex_pc)
- : HExpression(value->GetType(), SideEffects::None(), dex_pc) {
+ : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) {
SetRawInputAt(0, value);
}
@@ -5574,26 +5586,6 @@
DISALLOW_COPY_AND_ASSIGN(HMonitorOperation);
};
-/**
- * A HInstruction used as a marker for the replacement of new + <init>
- * of a String to a call to a StringFactory. Only baseline will see
- * the node at code generation, where it will be be treated as null.
- * When compiling non-baseline, `HFakeString` instructions are being removed
- * in the instruction simplifier.
- */
-class HFakeString : public HTemplateInstruction<0> {
- public:
- explicit HFakeString(uint32_t dex_pc = kNoDexPc)
- : HTemplateInstruction(SideEffects::None(), dex_pc) {}
-
- Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; }
-
- DECLARE_INSTRUCTION(FakeString);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(HFakeString);
-};
-
class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> {
public:
MoveOperands(Location source,
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 988e32b..bb840ea 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -782,19 +782,16 @@
{
PassScope scope(SsaBuilder::kSsaBuilderPassName, &pass_observer);
- BuildSsaResult result = graph->TryBuildingSsa(&handles);
- if (result != kBuildSsaSuccess) {
+ GraphAnalysisResult result = graph->TryBuildingSsa(&handles);
+ if (result != kAnalysisSuccess) {
switch (result) {
- case kBuildSsaFailNonNaturalLoop:
- MaybeRecordStat(MethodCompilationStat::kNotCompiledNonNaturalLoop);
- break;
- case kBuildSsaFailThrowCatchLoop:
+ case kAnalysisFailThrowCatchLoop:
MaybeRecordStat(MethodCompilationStat::kNotCompiledThrowCatchLoop);
break;
- case kBuildSsaFailAmbiguousArrayOp:
+ case kAnalysisFailAmbiguousArrayOp:
MaybeRecordStat(MethodCompilationStat::kNotCompiledAmbiguousArrayOp);
break;
- case kBuildSsaSuccess:
+ case kAnalysisSuccess:
UNREACHABLE();
}
pass_observer.SetGraphInBadState();
diff --git a/compiler/optimizing/optimizing_compiler_stats.h b/compiler/optimizing/optimizing_compiler_stats.h
index bca1632..f8035aa 100644
--- a/compiler/optimizing/optimizing_compiler_stats.h
+++ b/compiler/optimizing/optimizing_compiler_stats.h
@@ -38,7 +38,6 @@
kRemovedDeadInstruction,
kRemovedNullCheck,
kNotCompiledBranchOutsideMethodCode,
- kNotCompiledNonNaturalLoop,
kNotCompiledThrowCatchLoop,
kNotCompiledAmbiguousArrayOp,
kNotCompiledHugeMethod,
@@ -106,7 +105,6 @@
case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break;
case kRemovedNullCheck: name = "RemovedNullCheck"; break;
case kNotCompiledBranchOutsideMethodCode: name = "NotCompiledBranchOutsideMethodCode"; break;
- case kNotCompiledNonNaturalLoop : name = "NotCompiledNonNaturalLoop"; break;
case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break;
diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h
index af3a005..5a91043 100644
--- a/compiler/optimizing/optimizing_unit_test.h
+++ b/compiler/optimizing/optimizing_unit_test.h
@@ -117,7 +117,7 @@
inline void TransformToSsa(HGraph* graph) {
ScopedObjectAccess soa(Thread::Current());
StackHandleScopeCollection handles(soa.Self());
- EXPECT_EQ(graph->TryBuildingSsa(&handles), kBuildSsaSuccess);
+ EXPECT_EQ(graph->TryBuildingSsa(&handles), kAnalysisSuccess);
}
} // namespace art
diff --git a/compiler/optimizing/pc_relative_fixups_x86.cc b/compiler/optimizing/pc_relative_fixups_x86.cc
index a385448..1394dfa 100644
--- a/compiler/optimizing/pc_relative_fixups_x86.cc
+++ b/compiler/optimizing/pc_relative_fixups_x86.cc
@@ -145,6 +145,11 @@
};
void PcRelativeFixups::Run() {
+ if (graph_->HasIrreducibleLoops()) {
+ // Do not run this optimization, as irreducible loops do not work with an instruction
+ // that can be live-in at the irreducible loop header.
+ return;
+ }
PCRelativeHandlerVisitor visitor(graph_);
visitor.VisitInsertionOrder();
visitor.MoveBaseIfNeeded();
diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc
index 1c25e48..527c242 100644
--- a/compiler/optimizing/reference_type_propagation.cc
+++ b/compiler/optimizing/reference_type_propagation.cc
@@ -58,7 +58,6 @@
void VisitCheckCast(HCheckCast* instr) OVERRIDE;
void VisitBoundType(HBoundType* instr) OVERRIDE;
void VisitNullCheck(HNullCheck* instr) OVERRIDE;
- void VisitFakeString(HFakeString* instr) OVERRIDE;
void UpdateReferenceTypeInfo(HInstruction* instr,
uint16_t type_idx,
const DexFile& dex_file,
@@ -568,10 +567,6 @@
}
}
-void RTPVisitor::VisitFakeString(HFakeString* instr) {
- instr->SetReferenceTypeInfo(ReferenceTypeInfo::Create(string_class_handle_, /* is_exact */ true));
-}
-
void RTPVisitor::VisitBoundType(HBoundType* instr) {
ScopedObjectAccess soa(Thread::Current());
diff --git a/compiler/optimizing/register_allocator.cc b/compiler/optimizing/register_allocator.cc
index eb0419b..2bae4bc 100644
--- a/compiler/optimizing/register_allocator.cc
+++ b/compiler/optimizing/register_allocator.cc
@@ -179,9 +179,11 @@
ProcessInstruction(inst_it.Current());
}
- if (block->IsCatchBlock()) {
- // By blocking all registers at the top of each catch block, we force
- // intervals used after catch to spill.
+ if (block->IsCatchBlock() ||
+ (block->GetLoopInformation() != nullptr && block->GetLoopInformation()->IsIrreducible())) {
+ // By blocking all registers at the top of each catch block or irreducible loop, we force
+ // intervals belonging to the live-in set of the catch/header block to be spilled.
+ // TODO(ngeoffray): Phis in this block could be allocated in register.
size_t position = block->GetLifetimeStart();
BlockRegisters(position, position + 1);
}
@@ -1870,8 +1872,10 @@
// Resolve non-linear control flow across branches. Order does not matter.
for (HLinearOrderIterator it(*codegen_->GetGraph()); !it.Done(); it.Advance()) {
HBasicBlock* block = it.Current();
- if (block->IsCatchBlock()) {
- // Instructions live at the top of catch blocks were forced to spill.
+ if (block->IsCatchBlock() ||
+ (block->GetLoopInformation() != nullptr && block->GetLoopInformation()->IsIrreducible())) {
+ // Instructions live at the top of catch blocks or irreducible loop header
+ // were forced to spill.
if (kIsDebugBuild) {
BitVector* live = liveness_.GetLiveInSet(*block);
for (uint32_t idx : live->Indexes()) {
diff --git a/compiler/optimizing/register_allocator_test.cc b/compiler/optimizing/register_allocator_test.cc
index 306a457..572faa8 100644
--- a/compiler/optimizing/register_allocator_test.cc
+++ b/compiler/optimizing/register_allocator_test.cc
@@ -535,7 +535,7 @@
(*phi)->AddInput(*input2);
graph->BuildDominatorTree();
- graph->AnalyzeNaturalLoops();
+ graph->AnalyzeLoops();
return graph;
}
diff --git a/compiler/optimizing/ssa_builder.cc b/compiler/optimizing/ssa_builder.cc
index f6bab8e..7494e33 100644
--- a/compiler/optimizing/ssa_builder.cc
+++ b/compiler/optimizing/ssa_builder.cc
@@ -68,7 +68,7 @@
// should be replaced with a null constant.
// Both type propagation and redundant phi elimination ensure `int_operand`
// can only be the 0 constant.
- DCHECK(int_operand->IsIntConstant());
+ DCHECK(int_operand->IsIntConstant()) << int_operand->DebugName();
DCHECK_EQ(0, int_operand->AsIntConstant()->GetValue());
equality_instr->ReplaceInput(GetGraph()->GetNullConstant(), int_operand == right ? 1 : 0);
}
@@ -422,7 +422,7 @@
return true;
}
-BuildSsaResult SsaBuilder::BuildSsa() {
+GraphAnalysisResult SsaBuilder::BuildSsa() {
// 1) Visit in reverse post order. We need to have all predecessors of a block
// visited (with the exception of loops) in order to create the right environment
// for that block. For loops, we create phis whose inputs will be set in 2).
@@ -462,7 +462,7 @@
// computed the type of the array input, the ambiguity can be resolved and the
// correct equivalents kept.
if (!FixAmbiguousArrayOps()) {
- return kBuildSsaFailAmbiguousArrayOp;
+ return kAnalysisFailAmbiguousArrayOp;
}
// 8) Mark dead phis. This will mark phis which are not used by instructions
@@ -497,7 +497,7 @@
}
}
- return kBuildSsaSuccess;
+ return kAnalysisSuccess;
}
ArenaVector<HInstruction*>* SsaBuilder::GetLocalsFor(HBasicBlock* block) {
@@ -885,4 +885,22 @@
VisitInstruction(aset);
}
+void SsaBuilder::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
+ VisitInstruction(invoke);
+
+ if (invoke->IsStringInit()) {
+ // This is a StringFactory call which acts as a String constructor. Its
+ // result replaces the empty String pre-allocated by NewInstance.
+ HNewInstance* new_instance = invoke->GetThisArgumentOfStringInit();
+ invoke->RemoveThisArgumentOfStringInit();
+
+ // Walk over all vregs and replace any occurrence of `new_instance` with `invoke`.
+ for (size_t vreg = 0, e = current_locals_->size(); vreg < e; ++vreg) {
+ if ((*current_locals_)[vreg] == new_instance) {
+ (*current_locals_)[vreg] = invoke;
+ }
+ }
+ }
+}
+
} // namespace art
diff --git a/compiler/optimizing/ssa_builder.h b/compiler/optimizing/ssa_builder.h
index 0fcc3a1..28eef6a 100644
--- a/compiler/optimizing/ssa_builder.h
+++ b/compiler/optimizing/ssa_builder.h
@@ -49,7 +49,7 @@
*/
class SsaBuilder : public HGraphVisitor {
public:
- explicit SsaBuilder(HGraph* graph, StackHandleScopeCollection* handles)
+ SsaBuilder(HGraph* graph, StackHandleScopeCollection* handles)
: HGraphVisitor(graph),
handles_(handles),
agets_fixed_(false),
@@ -63,20 +63,21 @@
loop_headers_.reserve(kDefaultNumberOfLoops);
}
- BuildSsaResult BuildSsa();
+ GraphAnalysisResult BuildSsa();
// Returns locals vector for `block`. If it is a catch block, the vector will be
// prepopulated with catch phis for vregs which are defined in `current_locals_`.
ArenaVector<HInstruction*>* GetLocalsFor(HBasicBlock* block);
HInstruction* ValueOfLocal(HBasicBlock* block, size_t local);
- void VisitBasicBlock(HBasicBlock* block);
- void VisitLoadLocal(HLoadLocal* load);
- void VisitStoreLocal(HStoreLocal* store);
- void VisitInstruction(HInstruction* instruction);
- void VisitTemporary(HTemporary* instruction);
- void VisitArrayGet(HArrayGet* aget);
- void VisitArraySet(HArraySet* aset);
+ void VisitBasicBlock(HBasicBlock* block) OVERRIDE;
+ void VisitLoadLocal(HLoadLocal* load) OVERRIDE;
+ void VisitStoreLocal(HStoreLocal* store) OVERRIDE;
+ void VisitInstruction(HInstruction* instruction) OVERRIDE;
+ void VisitTemporary(HTemporary* instruction) OVERRIDE;
+ void VisitArrayGet(HArrayGet* aget) OVERRIDE;
+ void VisitArraySet(HArraySet* aset) OVERRIDE;
+ void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE;
static constexpr const char* kSsaBuilderPassName = "ssa_builder";
diff --git a/compiler/optimizing/ssa_liveness_analysis.cc b/compiler/optimizing/ssa_liveness_analysis.cc
index b9d8731..a5609fc 100644
--- a/compiler/optimizing/ssa_liveness_analysis.cc
+++ b/compiler/optimizing/ssa_liveness_analysis.cc
@@ -273,6 +273,18 @@
}
if (block->IsLoopHeader()) {
+ if (kIsDebugBuild && block->GetLoopInformation()->IsIrreducible()) {
+ // To satisfy our liveness algorithm, we need to ensure loop headers of
+ // irreducible loops do not have any live-in instructions, except constants
+ // and the current method, which can be trivially re-materialized.
+ for (uint32_t idx : live_in->Indexes()) {
+ HInstruction* instruction = GetInstructionFromSsaIndex(idx);
+ DCHECK(instruction->GetBlock()->IsEntryBlock()) << instruction->DebugName();
+ DCHECK(!instruction->IsParameterValue()) << instruction->DebugName();
+ DCHECK(instruction->IsCurrentMethod() || instruction->IsConstant())
+ << instruction->DebugName();
+ }
+ }
size_t last_position = block->GetLoopInformation()->GetLifetimeEnd();
// For all live_in instructions at the loop header, we need to create a range
// that covers the full loop.
diff --git a/compiler/optimizing/ssa_phi_elimination.cc b/compiler/optimizing/ssa_phi_elimination.cc
index 2eef307..6816b6a 100644
--- a/compiler/optimizing/ssa_phi_elimination.cc
+++ b/compiler/optimizing/ssa_phi_elimination.cc
@@ -154,6 +154,7 @@
cycle_worklist.push_back(phi);
visited_phis_in_cycle.insert(phi->GetId());
bool catch_phi_in_cycle = phi->IsCatchPhi();
+ bool irreducible_loop_phi_in_cycle = phi->IsIrreducibleLoopHeaderPhi();
// First do a simple loop over inputs and check if they are all the same.
for (size_t j = 0; j < phi->InputCount(); ++j) {
@@ -187,6 +188,7 @@
cycle_worklist.push_back(input->AsPhi());
visited_phis_in_cycle.insert(input->GetId());
catch_phi_in_cycle |= input->AsPhi()->IsCatchPhi();
+ irreducible_loop_phi_in_cycle |= input->IsIrreducibleLoopHeaderPhi();
} else {
// Already visited, nothing to do.
}
@@ -206,6 +208,15 @@
continue;
}
+ if (irreducible_loop_phi_in_cycle && !candidate->IsConstant()) {
+ // For irreducible loops, we need to keep the phis to satisfy our linear scan
+ // algorithm.
+ // There is one exception for constants, as the type propagation requires redundant
+ // cyclic phis of a constant to be removed. This is ok for the linear scan as it
+ // has to deal with constants anyway, and they can trivially be rematerialized.
+ continue;
+ }
+
for (HPhi* current : cycle_worklist) {
// The candidate may not dominate a phi in a catch block: there may be non-throwing
// instructions at the beginning of a try range, that may be the first input of
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 808643a..ea54239 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -520,6 +520,7 @@
compiled_methods_filename_(nullptr),
app_image_(false),
boot_image_(false),
+ multi_image_(false),
is_host_(false),
image_writer_(nullptr),
driver_(nullptr),
@@ -660,7 +661,7 @@
}
}
- void ProcessOptions(ParserOptions* parser_options, bool multi_image) {
+ void ProcessOptions(ParserOptions* parser_options) {
boot_image_ = !image_filenames_.empty();
app_image_ = app_image_fd_ != -1 || !app_image_file_name_.empty();
@@ -851,86 +852,17 @@
compiler_options_->verbose_methods_ = verbose_methods_.empty() ? nullptr : &verbose_methods_;
- if (!IsBootImage() && multi_image) {
+ if (!IsBootImage() && multi_image_) {
Usage("--multi-image can only be used when creating boot images");
}
- if (IsBootImage() && multi_image && image_filenames_.size() > 1) {
+ if (IsBootImage() && multi_image_ && image_filenames_.size() > 1) {
Usage("--multi-image cannot be used with multiple image names");
}
// For now, if we're on the host and compile the boot image, *always* use multiple image files.
if (!kIsTargetBuild && IsBootImage()) {
if (image_filenames_.size() == 1) {
- multi_image = true;
- }
- }
-
- if (IsBootImage() && multi_image) {
- // Expand the oat and image filenames.
- std::string base_oat = oat_filenames_[0];
- size_t last_oat_slash = base_oat.rfind('/');
- if (last_oat_slash == std::string::npos) {
- Usage("--multi-image used with unusable oat filename %s", base_oat.c_str());
- }
- // We also need to honor path components that were encoded through '@'. Otherwise the loading
- // code won't be able to find the images.
- if (base_oat.find('@', last_oat_slash) != std::string::npos) {
- last_oat_slash = base_oat.rfind('@');
- }
- base_oat = base_oat.substr(0, last_oat_slash + 1);
-
- std::string base_img = image_filenames_[0];
- size_t last_img_slash = base_img.rfind('/');
- if (last_img_slash == std::string::npos) {
- Usage("--multi-image used with unusable image filename %s", base_img.c_str());
- }
- // We also need to honor path components that were encoded through '@'. Otherwise the loading
- // code won't be able to find the images.
- if (base_img.find('@', last_img_slash) != std::string::npos) {
- last_img_slash = base_img.rfind('@');
- }
-
- // Get the prefix, which is the primary image name (without path components). Strip the
- // extension.
- std::string prefix = base_img.substr(last_img_slash + 1);
- if (prefix.rfind('.') != std::string::npos) {
- prefix = prefix.substr(0, prefix.rfind('.'));
- }
- if (!prefix.empty()) {
- prefix = prefix + "-";
- }
-
- base_img = base_img.substr(0, last_img_slash + 1);
-
- // Note: we have some special case here for our testing. We have to inject the differentiating
- // parts for the different core images.
- std::string infix; // Empty infix by default.
- {
- // Check the first name.
- std::string dex_file = oat_filenames_[0];
- size_t last_dex_slash = dex_file.rfind('/');
- if (last_dex_slash != std::string::npos) {
- dex_file = dex_file.substr(last_dex_slash + 1);
- }
- size_t last_dex_dot = dex_file.rfind('.');
- if (last_dex_dot != std::string::npos) {
- dex_file = dex_file.substr(0, last_dex_dot);
- }
- if (StartsWith(dex_file, "core-")) {
- infix = dex_file.substr(strlen("core"));
- }
- }
-
- // Now create the other names. Use a counted loop to skip the first one.
- for (size_t i = 1; i < dex_locations_.size(); ++i) {
- // TODO: Make everything properly std::string.
- std::string image_name = CreateMultiImageName(dex_locations_[i], prefix, infix, ".art");
- char_backing_storage_.push_back(base_img + image_name);
- image_filenames_.push_back((char_backing_storage_.end() - 1)->c_str());
-
- std::string oat_name = CreateMultiImageName(dex_locations_[i], prefix, infix, ".oat");
- char_backing_storage_.push_back(base_oat + oat_name);
- oat_filenames_.push_back((char_backing_storage_.end() - 1)->c_str());
+ multi_image_ = true;
}
}
@@ -943,6 +875,74 @@
key_value_store_.reset(new SafeMap<std::string, std::string>());
}
+ void ExpandOatAndImageFilenames() {
+ std::string base_oat = oat_filenames_[0];
+ size_t last_oat_slash = base_oat.rfind('/');
+ if (last_oat_slash == std::string::npos) {
+ Usage("--multi-image used with unusable oat filename %s", base_oat.c_str());
+ }
+ // We also need to honor path components that were encoded through '@'. Otherwise the loading
+ // code won't be able to find the images.
+ if (base_oat.find('@', last_oat_slash) != std::string::npos) {
+ last_oat_slash = base_oat.rfind('@');
+ }
+ base_oat = base_oat.substr(0, last_oat_slash + 1);
+
+ std::string base_img = image_filenames_[0];
+ size_t last_img_slash = base_img.rfind('/');
+ if (last_img_slash == std::string::npos) {
+ Usage("--multi-image used with unusable image filename %s", base_img.c_str());
+ }
+ // We also need to honor path components that were encoded through '@'. Otherwise the loading
+ // code won't be able to find the images.
+ if (base_img.find('@', last_img_slash) != std::string::npos) {
+ last_img_slash = base_img.rfind('@');
+ }
+
+ // Get the prefix, which is the primary image name (without path components). Strip the
+ // extension.
+ std::string prefix = base_img.substr(last_img_slash + 1);
+ if (prefix.rfind('.') != std::string::npos) {
+ prefix = prefix.substr(0, prefix.rfind('.'));
+ }
+ if (!prefix.empty()) {
+ prefix = prefix + "-";
+ }
+
+ base_img = base_img.substr(0, last_img_slash + 1);
+
+ // Note: we have some special case here for our testing. We have to inject the differentiating
+ // parts for the different core images.
+ std::string infix; // Empty infix by default.
+ {
+ // Check the first name.
+ std::string dex_file = oat_filenames_[0];
+ size_t last_dex_slash = dex_file.rfind('/');
+ if (last_dex_slash != std::string::npos) {
+ dex_file = dex_file.substr(last_dex_slash + 1);
+ }
+ size_t last_dex_dot = dex_file.rfind('.');
+ if (last_dex_dot != std::string::npos) {
+ dex_file = dex_file.substr(0, last_dex_dot);
+ }
+ if (StartsWith(dex_file, "core-")) {
+ infix = dex_file.substr(strlen("core"));
+ }
+ }
+
+ // Now create the other names. Use a counted loop to skip the first one.
+ for (size_t i = 1; i < dex_locations_.size(); ++i) {
+ // TODO: Make everything properly std::string.
+ std::string image_name = CreateMultiImageName(dex_locations_[i], prefix, infix, ".art");
+ char_backing_storage_.push_back(base_img + image_name);
+ image_filenames_.push_back((char_backing_storage_.end() - 1)->c_str());
+
+ std::string oat_name = CreateMultiImageName(dex_locations_[i], prefix, infix, ".oat");
+ char_backing_storage_.push_back(base_oat + oat_name);
+ oat_filenames_.push_back((char_backing_storage_.end() - 1)->c_str());
+ }
+ }
+
// Modify the input string in the following way:
// 0) Assume input is /a/b/c.d
// 1) Strip the path -> c.d
@@ -1014,8 +1014,6 @@
std::unique_ptr<ParserOptions> parser_options(new ParserOptions());
compiler_options_.reset(new CompilerOptions());
- bool multi_image = false;
-
for (int i = 0; i < argc; i++) {
const StringPiece option(argv[i]);
const bool log_options = false;
@@ -1115,7 +1113,7 @@
gLogVerbosity.compiler = false;
Split(option.substr(strlen("--verbose-methods=")).ToString(), ',', &verbose_methods_);
} else if (option == "--multi-image") {
- multi_image = true;
+ multi_image_ = true;
} else if (option.starts_with("--no-inline-from=")) {
no_inline_from_string_ = option.substr(strlen("--no-inline-from=")).data();
} else if (!compiler_options_->ParseCompilerOption(option, Usage)) {
@@ -1123,7 +1121,7 @@
}
}
- ProcessOptions(parser_options.get(), multi_image);
+ ProcessOptions(parser_options.get());
// Insert some compiler things.
InsertCompileOptions(argc, argv);
@@ -1132,6 +1130,11 @@
// Check whether the oat output files are writable, and open them for later. Also open a swap
// file, if a name is given.
bool OpenFile() {
+ // Expand oat and image filenames for multi image.
+ if (IsBootImage() && multi_image_) {
+ ExpandOatAndImageFilenames();
+ }
+
bool create_file = oat_fd_ == -1; // as opposed to using open file descriptor
if (create_file) {
for (const char* oat_filename : oat_filenames_) {
@@ -1185,6 +1188,22 @@
// released immediately.
unlink(swap_file_name_.c_str());
}
+
+ // If we use a swap file, ensure we are above the threshold to make it necessary.
+ if (swap_fd_ != -1) {
+ if (!UseSwap(IsBootImage(), dex_files_)) {
+ close(swap_fd_);
+ swap_fd_ = -1;
+ VLOG(compiler) << "Decided to run without swap.";
+ } else {
+ LOG(INFO) << "Large app, accepted running with swap.";
+ }
+ }
+ // Note that dex2oat won't close the swap_fd_. The compiler driver's swap space will do that.
+
+ // Organize inputs, handling multi-dex and multiple oat file outputs.
+ CreateDexOatMappings();
+
return true;
}
@@ -1247,6 +1266,21 @@
ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
if (boot_image_filename_.empty()) {
dex_files_ = class_linker->GetBootClassPath();
+ // Prune invalid dex locations.
+ for (size_t i = 0; i < dex_locations_.size(); i++) {
+ const char* dex_location = dex_locations_[i];
+ bool contains = false;
+ for (const DexFile* dex_file : dex_files_) {
+ if (strcmp(dex_location, dex_file->GetLocation().c_str()) == 0) {
+ contains = true;
+ break;
+ }
+ }
+ if (!contains) {
+ dex_locations_.erase(dex_locations_.begin() + i);
+ i--;
+ }
+ }
} else {
TimingLogger::ScopedTiming t_dex("Opening dex files", timings_);
if (dex_filenames_.empty()) {
@@ -1297,18 +1331,6 @@
dex_file->CreateTypeLookupTable();
}
- // If we use a swap file, ensure we are above the threshold to make it necessary.
- if (swap_fd_ != -1) {
- if (!UseSwap(IsBootImage(), dex_files_)) {
- close(swap_fd_);
- swap_fd_ = -1;
- VLOG(compiler) << "Decided to run without swap.";
- } else {
- LOG(INFO) << "Large app, accepted running with swap.";
- }
- }
- // Note that dex2oat won't close the swap_fd_. The compiler driver's swap space will do that.
-
/*
* If we're not in interpret-only or verify-none mode, go ahead and compile small applications.
* Don't bother to check if we're doing the image.
@@ -1328,16 +1350,11 @@
}
}
- // Organize inputs, handling multi-dex and multiple oat file outputs.
- CreateDexOatMappings();
-
return true;
}
void CreateDexOatMappings() {
if (oat_files_.size() > 1) {
- // TODO: This needs to change, as it is not a stable mapping. If a dex file is missing,
- // the images will be out of whack. b/26317072
size_t index = 0;
for (size_t i = 0; i < oat_files_.size(); ++i) {
std::vector<const DexFile*> dex_files;
@@ -1369,7 +1386,6 @@
// Handle and ClassLoader creation needs to come after Runtime::Create
jobject class_loader = nullptr;
- jobject class_path_class_loader = nullptr;
Thread* self = Thread::Current();
if (!boot_image_filename_.empty()) {
@@ -1384,12 +1400,10 @@
key_value_store_->Put(OatHeader::kClassPathKey,
OatFile::EncodeDexFileDependencies(class_path_files));
- class_path_class_loader = class_linker->CreatePathClassLoader(self,
- class_path_files,
- nullptr);
+ // Then the dex files we'll compile. Thus we'll resolve the class-path first.
+ class_path_files.insert(class_path_files.end(), dex_files_.begin(), dex_files_.end());
- // Class path loader as parent so that we'll resolve there first.
- class_loader = class_linker->CreatePathClassLoader(self, dex_files_, class_path_class_loader);
+ class_loader = class_linker->CreatePathClassLoader(self, class_path_files);
}
// Find the dex file we should not inline from.
@@ -1505,57 +1519,56 @@
driver_->CompileAll(class_loader, dex_files_, timings_);
}
- // TODO: Update comments about how this works for multi image. b/26317072
- // Notes on the interleaving of creating the image and oat file to
+ // Notes on the interleaving of creating the images and oat files to
// ensure the references between the two are correct.
//
// Currently we have a memory layout that looks something like this:
//
// +--------------+
- // | image |
+ // | images |
// +--------------+
- // | boot oat |
+ // | oat files |
// +--------------+
// | alloc spaces |
// +--------------+
//
- // There are several constraints on the loading of the image and boot.oat.
+ // There are several constraints on the loading of the images and oat files.
//
- // 1. The image is expected to be loaded at an absolute address and
- // contains Objects with absolute pointers within the image.
+ // 1. The images are expected to be loaded at an absolute address and
+ // contain Objects with absolute pointers within the images.
//
- // 2. There are absolute pointers from Methods in the image to their
- // code in the oat.
+ // 2. There are absolute pointers from Methods in the images to their
+ // code in the oat files.
//
- // 3. There are absolute pointers from the code in the oat to Methods
- // in the image.
+ // 3. There are absolute pointers from the code in the oat files to Methods
+ // in the images.
//
- // 4. There are absolute pointers from code in the oat to other code
- // in the oat.
+ // 4. There are absolute pointers from code in the oat files to other code
+ // in the oat files.
//
// To get this all correct, we go through several steps.
//
- // 1. We prepare offsets for all data in the oat file and calculate
+ // 1. We prepare offsets for all data in the oat files and calculate
// the oat data size and code size. During this stage, we also set
// oat code offsets in methods for use by the image writer.
//
- // 2. We prepare offsets for the objects in the image and calculate
- // the image size.
+ // 2. We prepare offsets for the objects in the images and calculate
+ // the image sizes.
//
- // 3. We create the oat file. Originally this was just our own proprietary
+ // 3. We create the oat files. Originally this was just our own proprietary
// file but now it is contained within an ELF dynamic object (aka an .so
- // file). Since we know the image size and oat data size and code size we
+ // file). Since we know the image sizes and oat data sizes and code sizes we
// can prepare the ELF headers and we then know the ELF memory segment
// layout and we can now resolve all references. The compiler provides
// LinkerPatch information in each CompiledMethod and we resolve these,
// using the layout information and image object locations provided by
// image writer, as we're writing the method code.
//
- // 4. We create the image file. It needs to know where the oat file
- // will be loaded after itself. Originally when oat file was simply
- // memory mapped so we could predict where its contents were based
- // on the file size. Now that it is an ELF file, we need to inspect
- // the ELF file to understand the in memory segment layout including
+ // 4. We create the image files. They need to know where the oat files
+ // will be loaded after itself. Originally oat files were simply
+ // memory mapped so we could predict where their contents were based
+ // on the file size. Now that they are ELF files, we need to inspect
+ // the ELF files to understand the in memory segment layout including
// where the oat header is located within.
// TODO: We could just remember this information from step 3.
//
@@ -1839,8 +1852,8 @@
return result;
}
- static size_t OpenDexFiles(const std::vector<const char*>& dex_filenames,
- const std::vector<const char*>& dex_locations,
+ static size_t OpenDexFiles(std::vector<const char*>& dex_filenames,
+ std::vector<const char*>& dex_locations,
std::vector<std::unique_ptr<const DexFile>>* dex_files) {
DCHECK(dex_files != nullptr) << "OpenDexFiles out-param is nullptr";
size_t failure_count = 0;
@@ -1851,6 +1864,9 @@
std::string error_msg;
if (!OS::FileExists(dex_filename)) {
LOG(WARNING) << "Skipping non-existent dex file '" << dex_filename << "'";
+ dex_filenames.erase(dex_filenames.begin() + i);
+ dex_locations.erase(dex_locations.begin() + i);
+ i--;
continue;
}
if (!DexFile::Open(dex_filename, dex_location, &error_msg, dex_files)) {
@@ -2280,6 +2296,7 @@
std::unique_ptr<std::unordered_set<std::string>> compiled_methods_;
bool app_image_;
bool boot_image_;
+ bool multi_image_;
bool is_host_;
std::string android_root_;
std::vector<const DexFile*> dex_files_;
@@ -2434,11 +2451,6 @@
}
}
- // Check early that the result of compilation can be written
- if (!dex2oat.OpenFile()) {
- return EXIT_FAILURE;
- }
-
// Print the complete line when any of the following is true:
// 1) Debug build
// 2) Compiling an image
@@ -2452,6 +2464,11 @@
}
if (!dex2oat.Setup()) {
+ return EXIT_FAILURE;
+ }
+
+ // Check early that the result of compilation can be written
+ if (!dex2oat.OpenFile()) {
dex2oat.EraseOatFiles();
return EXIT_FAILURE;
}
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 52c6524..7b9ce5b 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -395,6 +395,9 @@
os << "MAGIC:\n";
os << oat_header.GetMagic() << "\n\n";
+ os << "LOCATION:\n";
+ os << oat_file_.GetLocation() << "\n\n";
+
os << "CHECKSUM:\n";
os << StringPrintf("0x%08x\n\n", oat_header.GetChecksum());
@@ -2424,7 +2427,7 @@
// Need a class loader.
// Fake that we're a compiler.
- jobject class_loader = class_linker->CreatePathClassLoader(self, class_path, /*parent*/nullptr);
+ jobject class_loader = class_linker->CreatePathClassLoader(self, class_path);
// Use the class loader while dumping.
StackHandleScope<1> scope(self);
diff --git a/runtime/arch/stub_test.cc b/runtime/arch/stub_test.cc
index 7170f73..d4b873e 100644
--- a/runtime/arch/stub_test.cc
+++ b/runtime/arch/stub_test.cc
@@ -378,8 +378,8 @@
"memory"); // clobber.
#elif defined(__mips__) && defined(__LP64__)
__asm__ __volatile__ (
- // Spill a0-a7 and t0-t3 which we say we don't clobber. May contain args.
- "daddiu $sp, $sp, -96\n\t"
+ // Spill a0-a7 which we say we don't clobber. May contain args.
+ "daddiu $sp, $sp, -64\n\t"
"sd $a0, 0($sp)\n\t"
"sd $a1, 8($sp)\n\t"
"sd $a2, 16($sp)\n\t"
@@ -388,10 +388,6 @@
"sd $a5, 40($sp)\n\t"
"sd $a6, 48($sp)\n\t"
"sd $a7, 56($sp)\n\t"
- "sd $t0, 64($sp)\n\t"
- "sd $t1, 72($sp)\n\t"
- "sd $t2, 80($sp)\n\t"
- "sd $t3, 88($sp)\n\t"
"daddiu $sp, $sp, -16\n\t" // Reserve stack space, 16B aligned.
"sd %[referrer], 0($sp)\n\t"
@@ -427,18 +423,16 @@
"ld $a5, 40($sp)\n\t"
"ld $a6, 48($sp)\n\t"
"ld $a7, 56($sp)\n\t"
- "ld $t0, 64($sp)\n\t"
- "ld $t1, 72($sp)\n\t"
- "ld $t2, 80($sp)\n\t"
- "ld $t3, 88($sp)\n\t"
- "daddiu $sp, $sp, 96\n\t"
+ "daddiu $sp, $sp, 64\n\t"
"move %[result], $v0\n\t" // Store the call result.
: [result] "=r" (result)
: [arg0] "r"(arg0), [arg1] "r"(arg1), [arg2] "r"(arg2), [code] "r"(code), [self] "r"(self),
[referrer] "r"(referrer), [hidden] "r"(hidden)
- : "at", "v0", "v1", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
- "t8", "t9", "k0", "k1", "fp", "ra",
+ // Instead aliases t0-t3, register names $12-$15 has been used in the clobber list because
+ // t0-t3 are ambiguous.
+ : "at", "v0", "v1", "$12", "$13", "$14", "$15", "s0", "s1", "s2", "s3", "s4", "s5", "s6",
+ "s7", "t8", "t9", "k0", "k1", "fp", "ra",
"$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", "$f8", "$f9", "$f10", "$f11",
"$f12", "$f13", "$f14", "$f15", "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22",
"$f23", "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index cf548ad..a5f5c49 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -225,8 +225,7 @@
}
case kSuper:
// Constructors and static methods are called with invoke-direct.
- // Interface methods cannot be invoked with invoke-super.
- return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
+ return IsConstructor() || IsStatic();
case kInterface: {
mirror::Class* methods_class = GetDeclaringClass();
return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 8efad88..0be2fa2 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -267,7 +267,9 @@
bool HasSameNameAndSignature(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
// Find the method that this method overrides.
- ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
+ ArtMethod* FindOverriddenMethod(size_t pointer_size)
+ REQUIRES(Roles::uninterruptible_)
+ SHARED_REQUIRES(Locks::mutator_lock_);
// Find the method index for this method within other_dexfile. If this method isn't present then
// return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 1299915..ed833c4 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -46,6 +46,7 @@
#include "dex_file-inl.h"
#include "entrypoints/entrypoint_utils.h"
#include "entrypoints/runtime_asm_entrypoints.h"
+#include "experimental_flags.h"
#include "gc_root-inl.h"
#include "gc/accounting/card_table-inl.h"
#include "gc/accounting/heap_bitmap.h"
@@ -4829,7 +4830,6 @@
return false;
}
bool has_defaults = false;
- // TODO May need to replace this with real VTable for invoke_super
// Assign each method an IMT index and set the default flag.
for (size_t i = 0; i < num_virtual_methods; ++i) {
ArtMethod* m = klass->GetVirtualMethodDuringLinking(i, image_pointer_size_);
@@ -5467,6 +5467,53 @@
}
}
+static void FillImtFromSuperClass(Handle<mirror::Class> klass,
+ Handle<mirror::IfTable> iftable,
+ ArtMethod* unimplemented_method,
+ ArtMethod* imt_conflict_method,
+ ArtMethod** out_imt,
+ size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
+ DCHECK(klass->HasSuperClass());
+ mirror::Class* super_class = klass->GetSuperClass();
+ if (super_class->ShouldHaveEmbeddedImtAndVTable()) {
+ for (size_t i = 0; i < mirror::Class::kImtSize; ++i) {
+ out_imt[i] = super_class->GetEmbeddedImTableEntry(i, pointer_size);
+ }
+ } else {
+ // No imt in the super class, need to reconstruct from the iftable.
+ mirror::IfTable* if_table = super_class->GetIfTable();
+ const size_t length = super_class->GetIfTableCount();
+ for (size_t i = 0; i < length; ++i) {
+ mirror::Class* interface = iftable->GetInterface(i);
+ const size_t num_virtuals = interface->NumDeclaredVirtualMethods();
+ const size_t method_array_count = if_table->GetMethodArrayCount(i);
+ DCHECK_EQ(num_virtuals, method_array_count);
+ if (method_array_count == 0) {
+ continue;
+ }
+ auto* method_array = if_table->GetMethodArray(i);
+ for (size_t j = 0; j < num_virtuals; ++j) {
+ auto method = method_array->GetElementPtrSize<ArtMethod*>(j, pointer_size);
+ DCHECK(method != nullptr) << PrettyClass(super_class);
+ // Miranda methods cannot be used to implement an interface method and defaults should be
+ // skipped in case we override it.
+ if (method->IsDefault() || method->IsMiranda()) {
+ continue;
+ }
+ ArtMethod* interface_method = interface->GetVirtualMethod(j, pointer_size);
+ uint32_t imt_index = interface_method->GetDexMethodIndex() % mirror::Class::kImtSize;
+ auto** imt_ref = &out_imt[imt_index];
+ if (*imt_ref == unimplemented_method) {
+ *imt_ref = method;
+ } else if (*imt_ref != imt_conflict_method) {
+ *imt_ref = imt_conflict_method;
+ }
+ }
+ }
+ }
+}
+
+// TODO This method needs to be split up into several smaller methods.
bool ClassLinker::LinkInterfaceMethods(
Thread* self,
Handle<mirror::Class> klass,
@@ -5474,7 +5521,19 @@
ArtMethod** out_imt) {
StackHandleScope<3> hs(self);
Runtime* const runtime = Runtime::Current();
+
+ const bool is_interface = klass->IsInterface();
+ // TODO It might in the future prove useful to make interfaces have full iftables, allowing a
+ // faster invoke-super implementation in the interpreter/across dex-files.
+ // We will just skip doing any of this on non-debug builds for speed.
+ if (is_interface &&
+ !kIsDebugBuild &&
+ !runtime->AreExperimentalFlagsEnabled(ExperimentalFlags::kDefaultMethods)) {
+ return true;
+ }
+
const bool has_superclass = klass->HasSuperClass();
+ const bool fill_tables = !is_interface;
const size_t super_ifcount = has_superclass ? klass->GetSuperClass()->GetIfTableCount() : 0U;
const size_t method_alignment = ArtMethod::Alignment(image_pointer_size_);
const size_t method_size = ArtMethod::Size(image_pointer_size_);
@@ -5482,10 +5541,6 @@
MutableHandle<mirror::IfTable> iftable(hs.NewHandle(klass->GetIfTable()));
- // If we're an interface, we don't need the vtable pointers, so we're done.
- if (klass->IsInterface()) {
- return true;
- }
// These are allocated on the heap to begin, we then transfer to linear alloc when we re-create
// the virtual methods array.
// Need to use low 4GB arenas for compiler or else the pointers wont fit in 32 bit method array
@@ -5502,71 +5557,42 @@
ArtMethod* const unimplemented_method = runtime->GetImtUnimplementedMethod();
ArtMethod* const imt_conflict_method = runtime->GetImtConflictMethod();
// Copy the IMT from the super class if possible.
- bool extend_super_iftable = false;
- if (has_superclass) {
- mirror::Class* super_class = klass->GetSuperClass();
- extend_super_iftable = true;
- if (super_class->ShouldHaveEmbeddedImtAndVTable()) {
- for (size_t i = 0; i < mirror::Class::kImtSize; ++i) {
- out_imt[i] = super_class->GetEmbeddedImTableEntry(i, image_pointer_size_);
- }
- } else {
- // No imt in the super class, need to reconstruct from the iftable.
- mirror::IfTable* if_table = super_class->GetIfTable();
- const size_t length = super_class->GetIfTableCount();
- for (size_t i = 0; i < length; ++i) {
- mirror::Class* interface = iftable->GetInterface(i);
- const size_t num_virtuals = interface->NumVirtualMethods();
- const size_t method_array_count = if_table->GetMethodArrayCount(i);
- DCHECK_EQ(num_virtuals, method_array_count);
- if (method_array_count == 0) {
- continue;
- }
- auto* method_array = if_table->GetMethodArray(i);
- for (size_t j = 0; j < num_virtuals; ++j) {
- auto method = method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size_);
- DCHECK(method != nullptr) << PrettyClass(super_class);
- // Miranda methods cannot be used to implement an interface method and defaults should be
- // skipped in case we override it.
- if (method->IsDefault() || method->IsMiranda()) {
- continue;
- }
- ArtMethod* interface_method = interface->GetVirtualMethod(j, image_pointer_size_);
- uint32_t imt_index = interface_method->GetDexMethodIndex() % mirror::Class::kImtSize;
- auto** imt_ref = &out_imt[imt_index];
- if (*imt_ref == unimplemented_method) {
- *imt_ref = method;
- } else if (*imt_ref != imt_conflict_method) {
- *imt_ref = imt_conflict_method;
- }
- }
- }
- }
+ const bool extend_super_iftable = has_superclass;
+ if (has_superclass && fill_tables) {
+ FillImtFromSuperClass(klass,
+ iftable,
+ unimplemented_method,
+ imt_conflict_method,
+ out_imt,
+ image_pointer_size_);
}
+
// Allocate method arrays before since we don't want miss visiting miranda method roots due to
// thread suspension.
- for (size_t i = 0; i < ifcount; ++i) {
- size_t num_methods = iftable->GetInterface(i)->NumVirtualMethods();
- if (num_methods > 0) {
- const bool is_super = i < super_ifcount;
- // This is an interface implemented by a super-class. Therefore we can just copy the method
- // array from the superclass.
- const bool super_interface = is_super && extend_super_iftable;
- mirror::PointerArray* method_array;
- if (super_interface) {
- mirror::IfTable* if_table = klass->GetSuperClass()->GetIfTable();
- DCHECK(if_table != nullptr);
- DCHECK(if_table->GetMethodArray(i) != nullptr);
- // If we are working on a super interface, try extending the existing method array.
- method_array = down_cast<mirror::PointerArray*>(if_table->GetMethodArray(i)->Clone(self));
- } else {
- method_array = AllocPointerArray(self, num_methods);
+ if (fill_tables) {
+ for (size_t i = 0; i < ifcount; ++i) {
+ size_t num_methods = iftable->GetInterface(i)->NumDeclaredVirtualMethods();
+ if (num_methods > 0) {
+ const bool is_super = i < super_ifcount;
+ // This is an interface implemented by a super-class. Therefore we can just copy the method
+ // array from the superclass.
+ const bool super_interface = is_super && extend_super_iftable;
+ mirror::PointerArray* method_array;
+ if (super_interface) {
+ mirror::IfTable* if_table = klass->GetSuperClass()->GetIfTable();
+ DCHECK(if_table != nullptr);
+ DCHECK(if_table->GetMethodArray(i) != nullptr);
+ // If we are working on a super interface, try extending the existing method array.
+ method_array = down_cast<mirror::PointerArray*>(if_table->GetMethodArray(i)->Clone(self));
+ } else {
+ method_array = AllocPointerArray(self, num_methods);
+ }
+ if (UNLIKELY(method_array == nullptr)) {
+ self->AssertPendingOOMException();
+ return false;
+ }
+ iftable->SetMethodArray(i, method_array);
}
- if (UNLIKELY(method_array == nullptr)) {
- self->AssertPendingOOMException();
- return false;
- }
- iftable->SetMethodArray(i, method_array);
}
}
@@ -5582,12 +5608,16 @@
DCHECK_GE(i, 0u);
DCHECK_LT(i, ifcount);
- size_t num_methods = iftable->GetInterface(i)->NumVirtualMethods();
+ size_t num_methods = iftable->GetInterface(i)->NumDeclaredVirtualMethods();
if (num_methods > 0) {
StackHandleScope<2> hs2(self);
const bool is_super = i < super_ifcount;
const bool super_interface = is_super && extend_super_iftable;
- auto method_array(hs2.NewHandle(iftable->GetMethodArray(i)));
+ // We don't actually create or fill these tables for interfaces, we just copy some methods for
+ // conflict methods. Just set this as nullptr in those cases.
+ Handle<mirror::PointerArray> method_array(fill_tables
+ ? hs2.NewHandle(iftable->GetMethodArray(i))
+ : hs2.NewHandle<mirror::PointerArray>(nullptr));
ArraySlice<ArtMethod> input_virtual_methods;
ScopedNullHandle<mirror::PointerArray> null_handle;
@@ -5600,7 +5630,7 @@
// at the super-classes iftable methods (copied into method_array previously) when we are
// looking for the implementation of a super-interface method but that is rather dirty.
bool using_virtuals;
- if (super_interface) {
+ if (super_interface || is_interface) {
// If we are overwriting a super class interface, try to only virtual methods instead of the
// whole vtable.
using_virtuals = true;
@@ -5610,6 +5640,7 @@
// For a new interface, however, we need the whole vtable in case a new
// interface method is implemented in the whole superclass.
using_virtuals = false;
+ DCHECK(vtable.Get() != nullptr);
input_vtable_array = vtable;
input_array_length = input_vtable_array->GetLength();
}
@@ -5659,13 +5690,15 @@
break;
} else {
found_impl = true;
- method_array->SetElementPtrSize(j, vtable_method, image_pointer_size_);
- // Place method in imt if entry is empty, place conflict otherwise.
- SetIMTRef(unimplemented_method,
- imt_conflict_method,
- image_pointer_size_,
- vtable_method,
- /*out*/imt_ptr);
+ if (LIKELY(fill_tables)) {
+ method_array->SetElementPtrSize(j, vtable_method, image_pointer_size_);
+ // Place method in imt if entry is empty, place conflict otherwise.
+ SetIMTRef(unimplemented_method,
+ imt_conflict_method,
+ image_pointer_size_,
+ vtable_method,
+ /*out*/imt_ptr);
+ }
break;
}
}
@@ -5692,7 +5725,7 @@
method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size_);
DCHECK(supers_method != nullptr);
DCHECK(interface_name_comparator.HasSameNameAndSignature(supers_method));
- if (!supers_method->IsOverridableByDefaultMethod()) {
+ if (LIKELY(!supers_method->IsOverridableByDefaultMethod())) {
// The method is not overridable by a default method (i.e. it is directly implemented
// in some class). Therefore move onto the next interface method.
continue;
@@ -5714,11 +5747,13 @@
} else {
// See if we already have a conflict method for this method.
ArtMethod* preexisting_conflict = FindSameNameAndSignature(interface_name_comparator,
- default_conflict_methods);
+ default_conflict_methods);
if (LIKELY(preexisting_conflict != nullptr)) {
// We already have another conflict we can reuse.
default_conflict_method = preexisting_conflict;
} else {
+ // Note that we do this even if we are an interface since we need to create this and
+ // cannot reuse another classes.
// Create a new conflict method for this to use.
default_conflict_method =
reinterpret_cast<ArtMethod*>(allocator.Alloc(method_size));
@@ -5728,7 +5763,7 @@
}
current_method = default_conflict_method;
break;
- }
+ } // case kDefaultConflict
case DefaultMethodSearchResult::kDefaultFound: {
DCHECK(current_method != nullptr);
// Found a default method.
@@ -5737,8 +5772,12 @@
// We found a default method but it was the same one we already have from our
// superclass. Don't bother adding it to our vtable again.
current_method = vtable_impl;
- } else {
+ } else if (LIKELY(fill_tables)) {
+ // Interfaces don't need to copy default methods since they don't have vtables.
// Only record this default method if it is new to save space.
+ // TODO It might be worthwhile to copy default methods on interfaces anyway since it
+ // would make lookup for interface super much faster. (We would only need to scan
+ // the iftable to find if there is a NSME or AME.)
ArtMethod* old = FindSameNameAndSignature(interface_name_comparator, default_methods);
if (old == nullptr) {
// We found a default method implementation and there were no conflicts.
@@ -5749,7 +5788,7 @@
}
}
break;
- }
+ } // case kDefaultFound
case DefaultMethodSearchResult::kAbstractFound: {
DCHECK(current_method == nullptr);
// Abstract method masks all defaults.
@@ -5761,38 +5800,46 @@
current_method = vtable_impl;
}
break;
+ } // case kAbstractFound
+ }
+ if (LIKELY(fill_tables)) {
+ if (current_method != nullptr) {
+ // We found a default method implementation. Record it in the iftable and IMT.
+ method_array->SetElementPtrSize(j, current_method, image_pointer_size_);
+ SetIMTRef(unimplemented_method,
+ imt_conflict_method,
+ image_pointer_size_,
+ current_method,
+ /*out*/imt_ptr);
+ } else if (!super_interface) {
+ // We could not find an implementation for this method and since it is a brand new
+ // interface we searched the entire vtable (and all default methods) for an
+ // implementation but couldn't find one. We therefore need to make a miranda method.
+ //
+ // Find out if there is already a miranda method we can use.
+ ArtMethod* miranda_method = FindSameNameAndSignature(interface_name_comparator,
+ miranda_methods);
+ if (miranda_method == nullptr) {
+ DCHECK(interface_method->IsAbstract()) << PrettyMethod(interface_method);
+ miranda_method = reinterpret_cast<ArtMethod*>(allocator.Alloc(method_size));
+ CHECK(miranda_method != nullptr);
+ // Point the interface table at a phantom slot.
+ new(miranda_method) ArtMethod(interface_method, image_pointer_size_);
+ miranda_methods.push_back(miranda_method);
+ }
+ method_array->SetElementPtrSize(j, miranda_method, image_pointer_size_);
}
}
- if (current_method != nullptr) {
- // We found a default method implementation. Record it in the iftable and IMT.
- method_array->SetElementPtrSize(j, current_method, image_pointer_size_);
- SetIMTRef(unimplemented_method,
- imt_conflict_method,
- image_pointer_size_,
- current_method,
- /*out*/imt_ptr);
- } else if (!super_interface) {
- // We could not find an implementation for this method and since it is a brand new
- // interface we searched the entire vtable (and all default methods) for an implementation
- // but couldn't find one. We therefore need to make a miranda method.
- //
- // Find out if there is already a miranda method we can use.
- ArtMethod* miranda_method = FindSameNameAndSignature(interface_name_comparator,
- miranda_methods);
- if (miranda_method == nullptr) {
- DCHECK(interface_method->IsAbstract()) << PrettyMethod(interface_method);
- miranda_method = reinterpret_cast<ArtMethod*>(allocator.Alloc(method_size));
- CHECK(miranda_method != nullptr);
- // Point the interface table at a phantom slot.
- new(miranda_method) ArtMethod(interface_method, image_pointer_size_);
- miranda_methods.push_back(miranda_method);
- }
- method_array->SetElementPtrSize(j, miranda_method, image_pointer_size_);
- }
- }
- }
- }
- if (!miranda_methods.empty() || !default_methods.empty() || !default_conflict_methods.empty()) {
+ } // For each method in interface end.
+ } // if (num_methods > 0)
+ } // For each interface.
+ const bool has_new_virtuals = !(miranda_methods.empty() &&
+ default_methods.empty() &&
+ default_conflict_methods.empty());
+ // TODO don't extend virtuals of interface unless necessary (when is it?).
+ if (has_new_virtuals) {
+ DCHECK(!is_interface || (default_methods.empty() && miranda_methods.empty()))
+ << "Interfaces should only have default-conflict methods appended to them.";
VLOG(class_linker) << PrettyClass(klass.Get()) << ": miranda_methods=" << miranda_methods.size()
<< " default_methods=" << default_methods.size()
<< " default_conflict_methods=" << default_conflict_methods.size();
@@ -5889,101 +5936,102 @@
// suspension assert.
self->EndAssertNoThreadSuspension(old_cause);
- const size_t old_vtable_count = vtable->GetLength();
- const size_t new_vtable_count = old_vtable_count +
- miranda_methods.size() +
- default_methods.size() +
- default_conflict_methods.size();
- miranda_methods.clear();
- vtable.Assign(down_cast<mirror::PointerArray*>(vtable->CopyOf(self, new_vtable_count)));
- if (UNLIKELY(vtable.Get() == nullptr)) {
- self->AssertPendingOOMException();
- return false;
- }
- out = methods->begin(method_size, method_alignment) + old_method_count;
- size_t vtable_pos = old_vtable_count;
- for (size_t i = old_method_count; i < new_method_count; ++i) {
- // Leave the declaring class alone as type indices are relative to it
- out->SetMethodIndex(0xFFFF & vtable_pos);
- vtable->SetElementPtrSize(vtable_pos, &*out, image_pointer_size_);
- ++out;
- ++vtable_pos;
- }
- CHECK_EQ(vtable_pos, new_vtable_count);
- // Update old vtable methods. We use the default_translations map to figure out what each vtable
- // entry should be updated to, if they need to be at all.
- for (size_t i = 0; i < old_vtable_count; ++i) {
- ArtMethod* translated_method = vtable->GetElementPtrSize<ArtMethod*>(i, image_pointer_size_);
- // Try and find what we need to change this method to.
- auto translation_it = default_translations.find(i);
- bool found_translation = false;
- if (translation_it != default_translations.end()) {
- if (translation_it->second.IsInConflict()) {
- // Find which conflict method we are to use for this method.
- MethodNameAndSignatureComparator old_method_comparator(
- translated_method->GetInterfaceMethodIfProxy(image_pointer_size_));
- ArtMethod* new_conflict_method = FindSameNameAndSignature(old_method_comparator,
- default_conflict_methods);
- CHECK(new_conflict_method != nullptr) << "Expected a conflict method!";
- translated_method = new_conflict_method;
- } else if (translation_it->second.IsAbstract()) {
- // Find which miranda method we are to use for this method.
- MethodNameAndSignatureComparator old_method_comparator(
- translated_method->GetInterfaceMethodIfProxy(image_pointer_size_));
- ArtMethod* miranda_method = FindSameNameAndSignature(old_method_comparator,
- miranda_methods);
- DCHECK(miranda_method != nullptr);
- translated_method = miranda_method;
- } else {
- // Normal default method (changed from an older default or abstract interface method).
- DCHECK(translation_it->second.IsTranslation());
- translated_method = translation_it->second.GetTranslation();
+ if (fill_tables) {
+ // Update the vtable to the new method structures. We can skip this for interfaces since they
+ // do not have vtables.
+ const size_t old_vtable_count = vtable->GetLength();
+ const size_t new_vtable_count = old_vtable_count +
+ miranda_methods.size() +
+ default_methods.size() +
+ default_conflict_methods.size();
+ vtable.Assign(down_cast<mirror::PointerArray*>(vtable->CopyOf(self, new_vtable_count)));
+ if (UNLIKELY(vtable.Get() == nullptr)) {
+ self->AssertPendingOOMException();
+ return false;
+ }
+ out = methods->begin(method_size, method_alignment) + old_method_count;
+ size_t vtable_pos = old_vtable_count;
+ // Update all the newly copied method's indexes so they denote their placement in the vtable.
+ for (size_t i = old_method_count; i < new_method_count; ++i) {
+ // Leave the declaring class alone the method's dex_code_item_offset_ and dex_method_index_
+ // fields are references into the dex file the method was defined in. Since the ArtMethod
+ // does not store that information it uses declaring_class_->dex_cache_.
+ out->SetMethodIndex(0xFFFF & vtable_pos);
+ vtable->SetElementPtrSize(vtable_pos, &*out, image_pointer_size_);
+ ++out;
+ ++vtable_pos;
+ }
+ CHECK_EQ(vtable_pos, new_vtable_count);
+ // Update old vtable methods. We use the default_translations map to figure out what each
+ // vtable entry should be updated to, if they need to be at all.
+ for (size_t i = 0; i < old_vtable_count; ++i) {
+ ArtMethod* translated_method = vtable->GetElementPtrSize<ArtMethod*>(
+ i, image_pointer_size_);
+ // Try and find what we need to change this method to.
+ auto translation_it = default_translations.find(i);
+ bool found_translation = false;
+ if (translation_it != default_translations.end()) {
+ if (translation_it->second.IsInConflict()) {
+ // Find which conflict method we are to use for this method.
+ MethodNameAndSignatureComparator old_method_comparator(
+ translated_method->GetInterfaceMethodIfProxy(image_pointer_size_));
+ ArtMethod* new_conflict_method = FindSameNameAndSignature(old_method_comparator,
+ default_conflict_methods);
+ CHECK(new_conflict_method != nullptr) << "Expected a conflict method!";
+ translated_method = new_conflict_method;
+ } else if (translation_it->second.IsAbstract()) {
+ // Find which miranda method we are to use for this method.
+ MethodNameAndSignatureComparator old_method_comparator(
+ translated_method->GetInterfaceMethodIfProxy(image_pointer_size_));
+ ArtMethod* miranda_method = FindSameNameAndSignature(old_method_comparator,
+ miranda_methods);
+ DCHECK(miranda_method != nullptr);
+ translated_method = miranda_method;
+ } else {
+ // Normal default method (changed from an older default or abstract interface method).
+ DCHECK(translation_it->second.IsTranslation());
+ translated_method = translation_it->second.GetTranslation();
+ }
+ found_translation = true;
}
- found_translation = true;
- }
- DCHECK(translated_method != nullptr);
- auto it = move_table.find(translated_method);
- if (it != move_table.end()) {
- auto* new_method = it->second;
- DCHECK(new_method != nullptr);
- vtable->SetElementPtrSize(i, new_method, image_pointer_size_);
- } else {
- // If it was not going to be updated we wouldn't have put it into the default_translations
- // map.
- CHECK(!found_translation) << "We were asked to update this vtable entry. Must not fail.";
- }
- }
-
- if (kIsDebugBuild) {
- for (size_t i = 0; i < new_vtable_count; ++i) {
- CHECK(move_table.find(vtable->GetElementPtrSize<ArtMethod*>(i, image_pointer_size_)) ==
- move_table.end());
- }
- }
-
- klass->SetVTable(vtable.Get());
- // Go fix up all the stale (old miranda or default method) pointers.
- // First do it on the iftable.
- for (size_t i = 0; i < ifcount; ++i) {
- for (size_t j = 0, count = iftable->GetMethodArrayCount(i); j < count; ++j) {
- auto* method_array = iftable->GetMethodArray(i);
- auto* m = method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size_);
- DCHECK(m != nullptr) << PrettyClass(klass.Get());
- auto it = move_table.find(m);
+ DCHECK(translated_method != nullptr);
+ auto it = move_table.find(translated_method);
if (it != move_table.end()) {
- auto* new_m = it->second;
- DCHECK(new_m != nullptr) << PrettyClass(klass.Get());
- method_array->SetElementPtrSize(j, new_m, image_pointer_size_);
+ auto* new_method = it->second;
+ DCHECK(new_method != nullptr);
+ vtable->SetElementPtrSize(i, new_method, image_pointer_size_);
+ } else {
+ // If it was not going to be updated we wouldn't have put it into the default_translations
+ // map.
+ CHECK(!found_translation) << "We were asked to update this vtable entry. Must not fail.";
+ }
+ }
+ klass->SetVTable(vtable.Get());
+
+ // Go fix up all the stale iftable pointers.
+ for (size_t i = 0; i < ifcount; ++i) {
+ for (size_t j = 0, count = iftable->GetMethodArrayCount(i); j < count; ++j) {
+ auto* method_array = iftable->GetMethodArray(i);
+ auto* m = method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size_);
+ DCHECK(m != nullptr) << PrettyClass(klass.Get());
+ auto it = move_table.find(m);
+ if (it != move_table.end()) {
+ auto* new_m = it->second;
+ DCHECK(new_m != nullptr) << PrettyClass(klass.Get());
+ method_array->SetElementPtrSize(j, new_m, image_pointer_size_);
+ }
+ }
+ }
+
+ // Fix up IMT next
+ for (size_t i = 0; i < mirror::Class::kImtSize; ++i) {
+ auto it = move_table.find(out_imt[i]);
+ if (it != move_table.end()) {
+ out_imt[i] = it->second;
}
}
}
- // Fix up IMT next
- for (size_t i = 0; i < mirror::Class::kImtSize; ++i) {
- auto it = move_table.find(out_imt[i]);
- if (it != move_table.end()) {
- out_imt[i] = it->second;
- }
- }
+
// Check that there are no stale methods are in the dex cache array.
if (kIsDebugBuild) {
auto* resolved_methods = klass->GetDexCache()->GetResolvedMethods();
@@ -6007,7 +6055,7 @@
} else {
self->EndAssertNoThreadSuspension(old_cause);
}
- if (kIsDebugBuild) {
+ if (kIsDebugBuild && !is_interface) {
SanityCheckVTable(klass, image_pointer_size_);
}
return true;
@@ -6397,7 +6445,13 @@
DCHECK(resolved == nullptr || resolved->GetDeclaringClass()->IsInterface());
}
break;
- case kSuper: // Fall-through.
+ case kSuper:
+ if (klass->IsInterface()) {
+ resolved = klass->FindInterfaceMethod(dex_cache.Get(), method_idx, image_pointer_size_);
+ } else {
+ resolved = klass->FindVirtualMethod(dex_cache.Get(), method_idx, image_pointer_size_);
+ }
+ break;
case kVirtual:
resolved = klass->FindVirtualMethod(dex_cache.Get(), method_idx, image_pointer_size_);
break;
@@ -6419,7 +6473,13 @@
resolved = klass->FindInterfaceMethod(name, signature, image_pointer_size_);
DCHECK(resolved == nullptr || resolved->GetDeclaringClass()->IsInterface());
break;
- case kSuper: // Fall-through.
+ case kSuper:
+ if (klass->IsInterface()) {
+ resolved = klass->FindInterfaceMethod(name, signature, image_pointer_size_);
+ } else {
+ resolved = klass->FindVirtualMethod(name, signature, image_pointer_size_);
+ }
+ break;
case kVirtual:
resolved = klass->FindVirtualMethod(name, signature, image_pointer_size_);
break;
@@ -6845,9 +6905,7 @@
}
}
-jobject ClassLinker::CreatePathClassLoader(Thread* self,
- std::vector<const DexFile*>& dex_files,
- jobject parent_loader) {
+jobject ClassLinker::CreatePathClassLoader(Thread* self, std::vector<const DexFile*>& dex_files) {
// SOAAlreadyRunnable is protected, and we need something to add a global reference.
// We could move the jobject to the callers, but all call-sites do this...
ScopedObjectAccessUnchecked soa(self);
@@ -6878,8 +6936,8 @@
for (const DexFile* dex_file : dex_files) {
StackHandleScope<3> hs2(self);
- // CreatePathClassLoader is only used by gtests and dex2oat. Index 0 of h_long_array is
- // supposed to be the oat file but we can leave it null.
+ // CreatePathClassLoader is only used by gtests. Index 0 of h_long_array is supposed to be the
+ // oat file but we can leave it null.
Handle<mirror::LongArray> h_long_array = hs2.NewHandle(mirror::LongArray::Alloc(
self,
kDexFileIndexStart + 1));
@@ -6925,10 +6983,9 @@
mirror::Class::FindField(self, hs.NewHandle(h_path_class_loader->GetClass()), "parent",
"Ljava/lang/ClassLoader;");
DCHECK(parent_field != nullptr);
- mirror::Object* parent = (parent_loader != nullptr)
- ? soa.Decode<mirror::ClassLoader*>(parent_loader)
- : soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self);
- parent_field->SetObject<false>(h_path_class_loader.Get(), parent);
+ mirror::Object* boot_cl =
+ soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self);
+ parent_field->SetObject<false>(h_path_class_loader.Get(), boot_cl);
// Make it a global ref and return.
ScopedLocalRef<jobject> local_ref(
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 9d432c6..f1fd0c3 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -523,10 +523,7 @@
// Creates a GlobalRef PathClassLoader that can be used to load classes from the given dex files.
// Note: the objects are not completely set up. Do not use this outside of tests and the compiler.
- // If parent_loader is null then we use the boot class loader.
- jobject CreatePathClassLoader(Thread* self,
- std::vector<const DexFile*>& dex_files,
- jobject parent_loader)
+ jobject CreatePathClassLoader(Thread* self, std::vector<const DexFile*>& dex_files)
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!dex_lock_);
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 99353c5..471d7ca 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -24,6 +24,7 @@
#include "class_linker-inl.h"
#include "common_runtime_test.h"
#include "dex_file.h"
+#include "experimental_flags.h"
#include "entrypoints/entrypoint_utils-inl.h"
#include "gc/heap.h"
#include "mirror/abstract_method.h"
@@ -228,7 +229,7 @@
if (klass->IsInterface()) {
EXPECT_EQ(0U, iftable->GetMethodArrayCount(i));
} else {
- EXPECT_EQ(interface->NumVirtualMethods(), iftable->GetMethodArrayCount(i));
+ EXPECT_EQ(interface->NumDeclaredVirtualMethods(), iftable->GetMethodArrayCount(i));
}
}
if (klass->IsAbstract()) {
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index a4e16ae..e89c5af 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -117,14 +117,15 @@
static bool unstarted_initialized_ = false;
-CommonRuntimeTest::CommonRuntimeTest() {}
-CommonRuntimeTest::~CommonRuntimeTest() {
+CommonRuntimeTestImpl::CommonRuntimeTestImpl() {}
+
+CommonRuntimeTestImpl::~CommonRuntimeTestImpl() {
// Ensure the dex files are cleaned up before the runtime.
loaded_dex_files_.clear();
runtime_.reset();
}
-void CommonRuntimeTest::SetUpAndroidRoot() {
+void CommonRuntimeTestImpl::SetUpAndroidRoot() {
if (IsHost()) {
// $ANDROID_ROOT is set on the device, but not necessarily on the host.
// But it needs to be set so that icu4c can find its locale data.
@@ -166,7 +167,7 @@
}
}
-void CommonRuntimeTest::SetUpAndroidData(std::string& android_data) {
+void CommonRuntimeTestImpl::SetUpAndroidData(std::string& android_data) {
// On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache
if (IsHost()) {
const char* tmpdir = getenv("TMPDIR");
@@ -185,7 +186,8 @@
setenv("ANDROID_DATA", android_data.c_str(), 1);
}
-void CommonRuntimeTest::TearDownAndroidData(const std::string& android_data, bool fail_on_error) {
+void CommonRuntimeTestImpl::TearDownAndroidData(const std::string& android_data,
+ bool fail_on_error) {
if (fail_on_error) {
ASSERT_EQ(rmdir(android_data.c_str()), 0);
} else {
@@ -235,13 +237,13 @@
return founddir;
}
-std::string CommonRuntimeTest::GetAndroidHostToolsDir() {
+std::string CommonRuntimeTestImpl::GetAndroidHostToolsDir() {
return GetAndroidToolsDir("prebuilts/gcc/linux-x86/host",
"x86_64-linux-glibc2.15",
"x86_64-linux");
}
-std::string CommonRuntimeTest::GetAndroidTargetToolsDir(InstructionSet isa) {
+std::string CommonRuntimeTestImpl::GetAndroidTargetToolsDir(InstructionSet isa) {
switch (isa) {
case kArm:
case kThumb2:
@@ -269,15 +271,16 @@
return "";
}
-std::string CommonRuntimeTest::GetCoreArtLocation() {
+std::string CommonRuntimeTestImpl::GetCoreArtLocation() {
return GetCoreFileLocation("art");
}
-std::string CommonRuntimeTest::GetCoreOatLocation() {
+std::string CommonRuntimeTestImpl::GetCoreOatLocation() {
return GetCoreFileLocation("oat");
}
-std::unique_ptr<const DexFile> CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) {
+std::unique_ptr<const DexFile> CommonRuntimeTestImpl::LoadExpectSingleDexFile(
+ const char* location) {
std::vector<std::unique_ptr<const DexFile>> dex_files;
std::string error_msg;
MemMap::Init();
@@ -290,7 +293,7 @@
}
}
-void CommonRuntimeTest::SetUp() {
+void CommonRuntimeTestImpl::SetUp() {
SetUpAndroidRoot();
SetUpAndroidData(android_data_);
dalvik_cache_.append(android_data_.c_str());
@@ -345,7 +348,7 @@
FinalizeSetup();
}
-void CommonRuntimeTest::FinalizeSetup() {
+void CommonRuntimeTestImpl::FinalizeSetup() {
// Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this
// set up.
if (!unstarted_initialized_) {
@@ -369,7 +372,7 @@
runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U);
}
-void CommonRuntimeTest::ClearDirectory(const char* dirpath) {
+void CommonRuntimeTestImpl::ClearDirectory(const char* dirpath) {
ASSERT_TRUE(dirpath != nullptr);
DIR* dir = opendir(dirpath);
ASSERT_TRUE(dir != nullptr);
@@ -396,7 +399,7 @@
closedir(dir);
}
-void CommonRuntimeTest::TearDown() {
+void CommonRuntimeTestImpl::TearDown() {
const char* android_data = getenv("ANDROID_DATA");
ASSERT_TRUE(android_data != nullptr);
ClearDirectory(dalvik_cache_.c_str());
@@ -453,12 +456,12 @@
return StringPrintf("%s/framework/%s%s.jar", path.c_str(), jar_prefix.c_str(), suffix.c_str());
}
-std::vector<std::string> CommonRuntimeTest::GetLibCoreDexFileNames() {
+std::vector<std::string> CommonRuntimeTestImpl::GetLibCoreDexFileNames() {
return std::vector<std::string>({GetDexFileName("core-oj", IsHost()),
GetDexFileName("core-libart", IsHost())});
}
-std::string CommonRuntimeTest::GetTestAndroidRoot() {
+std::string CommonRuntimeTestImpl::GetTestAndroidRoot() {
if (IsHost()) {
const char* host_dir = getenv("ANDROID_HOST_OUT");
CHECK(host_dir != nullptr);
@@ -478,7 +481,7 @@
#define ART_TARGET_NATIVETEST_DIR_STRING ""
#endif
-std::string CommonRuntimeTest::GetTestDexFileName(const char* name) {
+std::string CommonRuntimeTestImpl::GetTestDexFileName(const char* name) {
CHECK(name != nullptr);
std::string filename;
if (IsHost()) {
@@ -493,7 +496,8 @@
return filename;
}
-std::vector<std::unique_ptr<const DexFile>> CommonRuntimeTest::OpenTestDexFiles(const char* name) {
+std::vector<std::unique_ptr<const DexFile>> CommonRuntimeTestImpl::OpenTestDexFiles(
+ const char* name) {
std::string filename = GetTestDexFileName(name);
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
@@ -506,13 +510,13 @@
return dex_files;
}
-std::unique_ptr<const DexFile> CommonRuntimeTest::OpenTestDexFile(const char* name) {
+std::unique_ptr<const DexFile> CommonRuntimeTestImpl::OpenTestDexFile(const char* name) {
std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name);
EXPECT_EQ(1U, vector.size());
return std::move(vector[0]);
}
-std::vector<const DexFile*> CommonRuntimeTest::GetDexFiles(jobject jclass_loader) {
+std::vector<const DexFile*> CommonRuntimeTestImpl::GetDexFiles(jobject jclass_loader) {
std::vector<const DexFile*> ret;
ScopedObjectAccess soa(Thread::Current());
@@ -572,7 +576,7 @@
return ret;
}
-const DexFile* CommonRuntimeTest::GetFirstDexFile(jobject jclass_loader) {
+const DexFile* CommonRuntimeTestImpl::GetFirstDexFile(jobject jclass_loader) {
std::vector<const DexFile*> tmp(GetDexFiles(jclass_loader));
DCHECK(!tmp.empty());
const DexFile* ret = tmp[0];
@@ -580,7 +584,7 @@
return ret;
}
-jobject CommonRuntimeTest::LoadDex(const char* dex_name) {
+jobject CommonRuntimeTestImpl::LoadDex(const char* dex_name) {
std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name);
std::vector<const DexFile*> class_path;
CHECK_NE(0U, dex_files.size());
@@ -591,13 +595,12 @@
Thread* self = Thread::Current();
jobject class_loader = Runtime::Current()->GetClassLinker()->CreatePathClassLoader(self,
- class_path,
- nullptr);
+ class_path);
self->SetClassLoaderOverride(class_loader);
return class_loader;
}
-std::string CommonRuntimeTest::GetCoreFileLocation(const char* suffix) {
+std::string CommonRuntimeTestImpl::GetCoreFileLocation(const char* suffix) {
CHECK(suffix != nullptr);
std::string location;
diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h
index 7223b6e..0ce40e8 100644
--- a/runtime/common_runtime_test.h
+++ b/runtime/common_runtime_test.h
@@ -64,8 +64,10 @@
std::unique_ptr<File> file_;
};
-class CommonRuntimeTest : public testing::Test {
+class CommonRuntimeTestImpl {
public:
+ CommonRuntimeTestImpl();
+ virtual ~CommonRuntimeTestImpl();
static void SetUpAndroidRoot();
// Note: setting up ANDROID_DATA may create a temporary directory. If this is used in a
@@ -74,19 +76,25 @@
static void TearDownAndroidData(const std::string& android_data, bool fail_on_error);
- CommonRuntimeTest();
- ~CommonRuntimeTest();
-
// Gets the paths of the libcore dex files.
static std::vector<std::string> GetLibCoreDexFileNames();
// Returns bin directory which contains host's prebuild tools.
static std::string GetAndroidHostToolsDir();
- // Returns bin directory which contains target's prebuild tools.
+ // Returns bin directory wahich contains target's prebuild tools.
static std::string GetAndroidTargetToolsDir(InstructionSet isa);
protected:
+ // Allow subclases such as CommonCompilerTest to add extra options.
+ virtual void SetUpRuntimeOptions(RuntimeOptions* options ATTRIBUTE_UNUSED) {}
+
+ // Called before the runtime is created.
+ virtual void PreRuntimeCreate() {}
+
+ // Called after the runtime is created.
+ virtual void PostRuntimeCreate() {}
+
static bool IsHost() {
return !kIsTargetBuild;
}
@@ -99,25 +107,8 @@
std::unique_ptr<const DexFile> LoadExpectSingleDexFile(const char* location);
- virtual void SetUp();
-
- // Allow subclases such as CommonCompilerTest to add extra options.
- virtual void SetUpRuntimeOptions(RuntimeOptions* options ATTRIBUTE_UNUSED) {}
-
void ClearDirectory(const char* dirpath);
- virtual void TearDown();
-
- // Called before the runtime is created.
- virtual void PreRuntimeCreate() {}
-
- // Called after the runtime is created.
- virtual void PostRuntimeCreate() {}
-
- // Called to finish up runtime creation and filling test fields. By default runs root
- // initializers, initialize well-known classes, and creates the heap thread pool.
- virtual void FinalizeSetup();
-
std::string GetTestAndroidRoot();
std::string GetTestDexFileName(const char* name);
@@ -150,12 +141,45 @@
std::unique_ptr<CompilerCallbacks> callbacks_;
+ void SetUp();
+
+ void TearDown();
+
+ void FinalizeSetup();
+
private:
static std::string GetCoreFileLocation(const char* suffix);
std::vector<std::unique_ptr<const DexFile>> loaded_dex_files_;
};
+template <typename TestType>
+class CommonRuntimeTestBase : public TestType, public CommonRuntimeTestImpl {
+ public:
+ CommonRuntimeTestBase() {}
+ virtual ~CommonRuntimeTestBase() {}
+
+ protected:
+ virtual void SetUp() {
+ CommonRuntimeTestImpl::SetUp();
+ }
+
+ virtual void TearDown() {
+ CommonRuntimeTestImpl::TearDown();
+ }
+
+ // Called to finish up runtime creation and filling test fields. By default runs root
+ // initializers, initialize well-known classes, and creates the heap thread pool.
+ virtual void FinalizeSetup() {
+ CommonRuntimeTestImpl::FinalizeSetup();
+ }
+};
+
+using CommonRuntimeTest = CommonRuntimeTestBase<testing::Test>;
+
+template <typename Param>
+using CommonRuntimeTestWithParam = CommonRuntimeTestBase<testing::TestWithParam<Param>>;
+
// Sets a CheckJni abort hook to catch failures. Note that this will cause CheckJNI to carry on
// rather than aborting, so be careful!
class CheckJniAbortCatcher {
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 40e2b15..b4208fe 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -86,6 +86,14 @@
PrettyMethod(method).c_str()).c_str());
}
+void ThrowAbstractMethodError(uint32_t method_idx, const DexFile& dex_file) {
+ ThrowException("Ljava/lang/AbstractMethodError;", /* referrer */ nullptr,
+ StringPrintf("abstract method \"%s\"",
+ PrettyMethod(method_idx,
+ dex_file,
+ /* with_signature */ true).c_str()).c_str());
+}
+
// ArithmeticException
void ThrowArithmeticExceptionDivideByZero() {
@@ -211,6 +219,22 @@
msg.str().c_str());
}
+void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method,
+ mirror::Class* target_class,
+ mirror::Object* this_object,
+ ArtMethod* referrer) {
+ // Referrer is calling interface_method on this_object, however, the interface_method isn't
+ // implemented by this_object.
+ CHECK(this_object != nullptr);
+ std::ostringstream msg;
+ msg << "Class '" << PrettyDescriptor(this_object->GetClass())
+ << "' does not implement interface '" << PrettyDescriptor(target_class) << "' in call to '"
+ << PrettyMethod(method) << "'";
+ ThrowException("Ljava/lang/IncompatibleClassChangeError;",
+ referrer != nullptr ? referrer->GetDeclaringClass() : nullptr,
+ msg.str().c_str());
+}
+
void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
mirror::Object* this_object,
ArtMethod* referrer) {
diff --git a/runtime/common_throws.h b/runtime/common_throws.h
index 85fe2b3..39c4e52 100644
--- a/runtime/common_throws.h
+++ b/runtime/common_throws.h
@@ -27,6 +27,7 @@
} // namespace mirror
class ArtField;
class ArtMethod;
+class DexFile;
class Signature;
class StringPiece;
@@ -35,6 +36,9 @@
void ThrowAbstractMethodError(ArtMethod* method)
SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
+void ThrowAbstractMethodError(uint32_t method_idx, const DexFile& dex_file)
+ SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
+
// ArithmeticException
void ThrowArithmeticExceptionDivideByZero() SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
@@ -107,6 +111,12 @@
ArtMethod* method, ArtMethod* referrer)
SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
+void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method,
+ mirror::Class* target_class,
+ mirror::Object* this_object,
+ ArtMethod* referrer)
+ SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
+
void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
mirror::Object* this_object,
ArtMethod* referrer)
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index ba2fb94..9a9f42b 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -416,10 +416,10 @@
return nullptr; // Failure.
} else if (access_check) {
mirror::Class* methods_class = resolved_method->GetDeclaringClass();
- mirror::Class* referring_class = referrer->GetDeclaringClass();
bool can_access_resolved_method =
- referring_class->CheckResolvedMethodAccess<type>(methods_class, resolved_method,
- method_idx);
+ referrer->GetDeclaringClass()->CheckResolvedMethodAccess<type>(methods_class,
+ resolved_method,
+ method_idx);
if (UNLIKELY(!can_access_resolved_method)) {
DCHECK(self->IsExceptionPending()); // Throw exception and unwind.
return nullptr; // Failure.
@@ -450,23 +450,56 @@
return klass->GetVTableEntry(vtable_index, class_linker->GetImagePointerSize());
}
case kSuper: {
- mirror::Class* super_class = referrer->GetDeclaringClass()->GetSuperClass();
- uint16_t vtable_index = resolved_method->GetMethodIndex();
- if (access_check) {
- // Check existence of super class.
- if (super_class == nullptr || !super_class->HasVTable() ||
- vtable_index >= static_cast<uint32_t>(super_class->GetVTableLength())) {
- // Behavior to agree with that of the verifier.
+ // TODO This lookup is quite slow.
+ // NB This is actually quite tricky to do any other way. We cannot use GetDeclaringClass since
+ // that will actually not be what we want in some cases where there are miranda methods or
+ // defaults. What we actually need is a GetContainingClass that says which classes virtuals
+ // this method is coming from.
+ mirror::Class* referring_class = referrer->GetDeclaringClass();
+ uint16_t method_type_idx = referring_class->GetDexFile().GetMethodId(method_idx).class_idx_;
+ mirror::Class* method_reference_class = class_linker->ResolveType(method_type_idx, referrer);
+ if (UNLIKELY(method_reference_class == nullptr)) {
+ // Bad type idx.
+ CHECK(self->IsExceptionPending());
+ return nullptr;
+ } else if (!method_reference_class->IsInterface()) {
+ // It is not an interface.
+ mirror::Class* super_class = referring_class->GetSuperClass();
+ uint16_t vtable_index = resolved_method->GetMethodIndex();
+ if (access_check) {
+ // Check existence of super class.
+ if (super_class == nullptr || !super_class->HasVTable() ||
+ vtable_index >= static_cast<uint32_t>(super_class->GetVTableLength())) {
+ // Behavior to agree with that of the verifier.
+ ThrowNoSuchMethodError(type, resolved_method->GetDeclaringClass(),
+ resolved_method->GetName(), resolved_method->GetSignature());
+ return nullptr; // Failure.
+ }
+ }
+ DCHECK(super_class != nullptr);
+ DCHECK(super_class->HasVTable());
+ return super_class->GetVTableEntry(vtable_index, class_linker->GetImagePointerSize());
+ } else {
+ // It is an interface.
+ if (access_check) {
+ if (!method_reference_class->IsAssignableFrom((*this_object)->GetClass())) {
+ ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(resolved_method,
+ method_reference_class,
+ *this_object,
+ referrer);
+ return nullptr; // Failure.
+ }
+ }
+ // TODO We can do better than this for a (compiled) fastpath.
+ ArtMethod* result = method_reference_class->FindVirtualMethodForInterfaceSuper(
+ resolved_method, class_linker->GetImagePointerSize());
+ // Throw an NSME if nullptr;
+ if (result == nullptr) {
ThrowNoSuchMethodError(type, resolved_method->GetDeclaringClass(),
resolved_method->GetName(), resolved_method->GetSignature());
- return nullptr; // Failure.
}
- } else {
- // Super class must exist.
- DCHECK(super_class != nullptr);
+ return result;
}
- DCHECK(super_class->HasVTable());
- return super_class->GetVTableEntry(vtable_index, class_linker->GetImagePointerSize());
}
case kInterface: {
uint32_t imt_index = resolved_method->GetDexMethodIndex() % mirror::Class::kImtSize;
@@ -576,8 +609,9 @@
if (UNLIKELY(this_object == nullptr && type != kStatic)) {
return nullptr;
}
+ mirror::Class* referring_class = referrer->GetDeclaringClass();
ArtMethod* resolved_method =
- referrer->GetDeclaringClass()->GetDexCache()->GetResolvedMethod(method_idx, sizeof(void*));
+ referring_class->GetDexCache()->GetResolvedMethod(method_idx, sizeof(void*));
if (UNLIKELY(resolved_method == nullptr)) {
return nullptr;
}
@@ -588,7 +622,6 @@
return nullptr;
}
mirror::Class* methods_class = resolved_method->GetDeclaringClass();
- mirror::Class* referring_class = referrer->GetDeclaringClass();
if (UNLIKELY(!referring_class->CanAccess(methods_class) ||
!referring_class->CanAccessMember(methods_class,
resolved_method->GetAccessFlags()))) {
@@ -601,12 +634,25 @@
} else if (type == kStatic || type == kDirect) {
return resolved_method;
} else if (type == kSuper) {
- mirror::Class* super_class = referrer->GetDeclaringClass()->GetSuperClass();
- if (resolved_method->GetMethodIndex() >= super_class->GetVTableLength()) {
- // The super class does not have the method.
+ // TODO This lookup is rather slow.
+ uint16_t method_type_idx = referring_class->GetDexFile().GetMethodId(method_idx).class_idx_;
+ mirror::Class* method_reference_class =
+ referring_class->GetDexCache()->GetResolvedType(method_type_idx);
+ if (method_reference_class == nullptr) {
+ // Need to do full type resolution...
return nullptr;
+ } else if (!method_reference_class->IsInterface()) {
+ // It is not an interface.
+ mirror::Class* super_class = referrer->GetDeclaringClass()->GetSuperClass();
+ if (resolved_method->GetMethodIndex() >= super_class->GetVTableLength()) {
+ // The super class does not have the method.
+ return nullptr;
+ }
+ return super_class->GetVTableEntry(resolved_method->GetMethodIndex(), sizeof(void*));
+ } else {
+ return method_reference_class->FindVirtualMethodForInterfaceSuper(
+ resolved_method, sizeof(void*));
}
- return super_class->GetVTableEntry(resolved_method->GetMethodIndex(), sizeof(void*));
} else {
DCHECK(type == kVirtual);
return this_object->GetClass()->GetVTableEntry(
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 9f61449..7d60264 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -931,6 +931,9 @@
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee) const {
+ // We can not have thread suspension since that would cause the this_object parameter to
+ // potentially become a dangling pointer. An alternative could be to put it in a handle instead.
+ ScopedAssertNoThreadSuspension ants(thread, __FUNCTION__);
for (InstrumentationListener* listener : invoke_virtual_or_interface_listeners_) {
if (listener != nullptr) {
listener->InvokeVirtualOrInterface(thread, this_object, caller, dex_pc, callee);
diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h
index 5e0a11d..b29245f 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -104,6 +104,7 @@
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee)
+ REQUIRES(Roles::uninterruptible_)
SHARED_REQUIRES(Locks::mutator_lock_) = 0;
};
diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc
index e7b4731..6b5218d 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -239,7 +239,7 @@
}
#if !defined(__clang__)
-#if defined(__arm__) && !defined(ART_USE_READ_BARRIER)
+#if defined(__arm__)
// TODO: remove when all targets implemented.
static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
#else
@@ -247,7 +247,7 @@
#endif
#else
// Clang 3.4 fails to build the goto interpreter implementation.
-#if defined(__arm__) && !defined(ART_USE_READ_BARRIER)
+#if defined(__arm__)
static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
#else
static constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImplKind;
diff --git a/runtime/interpreter/mterp/arm/op_iget_object_quick.S b/runtime/interpreter/mterp/arm/op_iget_object_quick.S
index fe29106..16cb118 100644
--- a/runtime/interpreter/mterp/arm/op_iget_object_quick.S
+++ b/runtime/interpreter/mterp/arm/op_iget_object_quick.S
@@ -2,9 +2,8 @@
/* op vA, vB, offset@CCCC */
mov r2, rINST, lsr #12 @ r2<- B
FETCH r1, 1 @ r1<- field byte offset
+ EXPORT_PC
GET_VREG r0, r2 @ r0<- object we're operating on
- cmp r0, #0 @ check object for null
- beq common_errNullObject @ object was null
bl artIGetObjectFromMterp @ (obj, offset)
ldr r3, [rSELF, #THREAD_EXCEPTION_OFFSET]
ubfx r2, rINST, #8, #4 @ r2<- A
diff --git a/runtime/interpreter/mterp/out/mterp_arm.S b/runtime/interpreter/mterp/out/mterp_arm.S
index 2d6f057..9ae98a2 100644
--- a/runtime/interpreter/mterp/out/mterp_arm.S
+++ b/runtime/interpreter/mterp/out/mterp_arm.S
@@ -7147,9 +7147,8 @@
/* op vA, vB, offset@CCCC */
mov r2, rINST, lsr #12 @ r2<- B
FETCH r1, 1 @ r1<- field byte offset
+ EXPORT_PC
GET_VREG r0, r2 @ r0<- object we're operating on
- cmp r0, #0 @ check object for null
- beq common_errNullObject @ object was null
bl artIGetObjectFromMterp @ (obj, offset)
ldr r3, [rSELF, #THREAD_EXCEPTION_OFFSET]
ubfx r2, rINST, #8, #4 @ r2<- A
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index bf3bd3c..2d575bd 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -105,7 +105,7 @@
code_size = initial_capacity - data_size;
DCHECK_EQ(code_size + data_size, initial_capacity);
return new JitCodeCache(
- code_map, data_map, code_size, data_size, garbage_collect_code, max_capacity);
+ code_map, data_map, code_size, data_size, max_capacity, garbage_collect_code);
}
JitCodeCache::JitCodeCache(MemMap* code_map,
@@ -127,6 +127,7 @@
last_update_time_ns_(0),
garbage_collect_code_(garbage_collect_code) {
+ DCHECK_GE(max_capacity, initial_code_capacity + initial_data_capacity);
code_mspace_ = create_mspace_with_base(code_map_->Begin(), code_end_, false /*locked*/);
data_mspace_ = create_mspace_with_base(data_map_->Begin(), data_end_, false /*locked*/);
@@ -673,9 +674,7 @@
size_t profile_info_size = RoundUp(
sizeof(ProfilingInfo) + sizeof(InlineCache) * entries.size(),
sizeof(void*));
- ScopedThreadSuspension sts(self, kSuspended);
MutexLock mu(self, lock_);
- WaitForPotentialCollectionToComplete(self);
// Check whether some other thread has concurrently created it.
ProfilingInfo* info = method->GetProfilingInfo(sizeof(void*));
diff --git a/runtime/jit/jit_instrumentation.cc b/runtime/jit/jit_instrumentation.cc
index 6531325..4cbaf2c 100644
--- a/runtime/jit/jit_instrumentation.cc
+++ b/runtime/jit/jit_instrumentation.cc
@@ -177,9 +177,8 @@
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee ATTRIBUTE_UNUSED) {
- instrumentation_cache_->AddSamples(thread, caller, 1);
// We make sure we cannot be suspended, as the profiling info can be concurrently deleted.
- thread->StartAssertNoThreadSuspension("Instrumenting invoke");
+ instrumentation_cache_->AddSamples(thread, caller, 1);
DCHECK(this_object != nullptr);
ProfilingInfo* info = caller->GetProfilingInfo(sizeof(void*));
if (info != nullptr) {
@@ -188,7 +187,6 @@
Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(caller->GetDeclaringClass());
info->AddInvokeInfo(dex_pc, this_object->GetClass());
}
- thread->EndAssertNoThreadSuspension(nullptr);
}
void JitInstrumentationCache::WaitForCompilationToFinish(Thread* self) {
diff --git a/runtime/jit/jit_instrumentation.h b/runtime/jit/jit_instrumentation.h
index 1f96d59..15969e4 100644
--- a/runtime/jit/jit_instrumentation.h
+++ b/runtime/jit/jit_instrumentation.h
@@ -78,7 +78,9 @@
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee)
- OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_);
+ OVERRIDE
+ REQUIRES(Roles::uninterruptible_)
+ SHARED_REQUIRES(Locks::mutator_lock_);
static constexpr uint32_t kJitEvents =
instrumentation::Instrumentation::kMethodEntered |
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index ef4fe15..53118e0 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -616,6 +616,7 @@
<< " IsErroneous=" <<
IsErroneous<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()
<< " IsString=" << (this == String::GetJavaLangString())
+ << " status= " << GetStatus<kVerifyFlags>()
<< " descriptor=" << PrettyDescriptor(this);
return GetField32<kVerifyFlags>(AccessFlagsOffset());
}
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index 66060f2..b49fc74 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -538,6 +538,71 @@
return nullptr;
}
+ArtMethod* Class::FindVirtualMethodForInterfaceSuper(ArtMethod* method, size_t pointer_size) {
+ DCHECK(method->GetDeclaringClass()->IsInterface());
+ DCHECK(IsInterface()) << "Should only be called on a interface class";
+ // Check if we have one defined on this interface first. This includes searching copied ones to
+ // get any conflict methods. Conflict methods are copied into each subtype from the supertype. We
+ // don't do any indirect method checks here.
+ for (ArtMethod& iface_method : GetVirtualMethods(pointer_size)) {
+ if (method->HasSameNameAndSignature(&iface_method)) {
+ return &iface_method;
+ }
+ }
+
+ std::vector<ArtMethod*> abstract_methods;
+ // Search through the IFTable for a working version. We don't need to check for conflicts
+ // because if there was one it would appear in this classes virtual_methods_ above.
+
+ Thread* self = Thread::Current();
+ StackHandleScope<2> hs(self);
+ MutableHandle<mirror::IfTable> iftable(hs.NewHandle(GetIfTable()));
+ MutableHandle<mirror::Class> iface(hs.NewHandle<mirror::Class>(nullptr));
+ size_t iftable_count = GetIfTableCount();
+ // Find the method. We don't need to check for conflicts because they would have been in the
+ // copied virtuals of this interface. Order matters, traverse in reverse topological order; most
+ // subtypiest interfaces get visited first.
+ for (size_t k = iftable_count; k != 0;) {
+ k--;
+ DCHECK_LT(k, iftable->Count());
+ iface.Assign(iftable->GetInterface(k));
+ // Iterate through every declared method on this interface. Each direct method's name/signature
+ // is unique so the order of the inner loop doesn't matter.
+ for (auto& method_iter : iface->GetDeclaredVirtualMethods(pointer_size)) {
+ ArtMethod* current_method = &method_iter;
+ if (current_method->HasSameNameAndSignature(method)) {
+ if (current_method->IsDefault()) {
+ // Handle JLS soft errors, a default method from another superinterface tree can
+ // "override" an abstract method(s) from another superinterface tree(s). To do this,
+ // ignore any [default] method which are dominated by the abstract methods we've seen so
+ // far. Check if overridden by any in abstract_methods. We do not need to check for
+ // default_conflicts because we would hit those before we get to this loop.
+ bool overridden = false;
+ for (ArtMethod* possible_override : abstract_methods) {
+ DCHECK(possible_override->HasSameNameAndSignature(current_method));
+ if (iface->IsAssignableFrom(possible_override->GetDeclaringClass())) {
+ overridden = true;
+ break;
+ }
+ }
+ if (!overridden) {
+ return current_method;
+ }
+ } else {
+ // Is not default.
+ // This might override another default method. Just stash it for now.
+ abstract_methods.push_back(current_method);
+ }
+ }
+ }
+ }
+ // If we reach here we either never found any declaration of the method (in which case
+ // 'abstract_methods' is empty or we found no non-overriden default methods in which case
+ // 'abstract_methods' contains a number of abstract implementations of the methods. We choose one
+ // of these arbitrarily.
+ return abstract_methods.empty() ? nullptr : abstract_methods[0];
+}
+
ArtMethod* Class::FindClassInitializer(size_t pointer_size) {
for (ArtMethod& method : GetDirectMethods(pointer_size)) {
if (method.IsClassInitializer()) {
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index 489c269..3a06b82 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -848,6 +848,11 @@
ArtMethod* FindVirtualMethodForSuper(ArtMethod* method, size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
+ // Given a method from some implementor of this interface, return the specific implementation
+ // method for this class.
+ ArtMethod* FindVirtualMethodForInterfaceSuper(ArtMethod* method, size_t pointer_size)
+ SHARED_REQUIRES(Locks::mutator_lock_);
+
// Given a method implemented by this class, but potentially from a
// super class or interface, return the specific implementation
// method for this class.
@@ -1058,7 +1063,7 @@
SHARED_REQUIRES(Locks::mutator_lock_);
pid_t GetClinitThreadId() SHARED_REQUIRES(Locks::mutator_lock_) {
- DCHECK(IsIdxLoaded() || IsErroneous());
+ DCHECK(IsIdxLoaded() || IsErroneous()) << PrettyClass(this);
return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
}
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index e89c74d..0ddd4a2 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -16,6 +16,8 @@
#include "java_lang_Class.h"
+#include <iostream>
+
#include "art_field-inl.h"
#include "class_linker.h"
#include "common_throws.h"
@@ -303,7 +305,10 @@
// We log the error for this specific case, as the user might just swallow the exception.
// This helps diagnose crashes when applications rely on the String#value field being
// there.
- LOG(ERROR) << "The String#value field is not present on Android versions >= 6.0";
+ // Also print on the error stream to test it through run-test.
+ std::string message("The String#value field is not present on Android versions >= 6.0");
+ LOG(ERROR) << message;
+ std::cerr << message << std::endl;
}
// We may have a pending exception if we failed to resolve.
if (!soa.Self()->IsExceptionPending()) {
diff --git a/runtime/type_lookup_table_test.cc b/runtime/type_lookup_table_test.cc
index 7f500cc..ea4d8b5 100644
--- a/runtime/type_lookup_table_test.cc
+++ b/runtime/type_lookup_table_test.cc
@@ -25,10 +25,10 @@
namespace art {
-class TypeLookupTableTest : public CommonRuntimeTest {
- public:
- size_t kDexNoIndex = DexFile::kDexNoIndex; // Make copy to prevent linking errors.
-};
+static const size_t kDexNoIndex = DexFile::kDexNoIndex; // Make copy to prevent linking errors.
+
+using DescriptorClassDefIdxPair = std::pair<const char*, uint32_t>;
+class TypeLookupTableTest : public CommonRuntimeTestWithParam<DescriptorClassDefIdxPair> {};
TEST_F(TypeLookupTableTest, CreateLookupTable) {
ScopedObjectAccess soa(Thread::Current());
@@ -39,48 +39,28 @@
ASSERT_EQ(32U, table->RawDataLength());
}
-TEST_F(TypeLookupTableTest, FindNonExistingClassWithoutCollisions) {
+TEST_P(TypeLookupTableTest, Find) {
ScopedObjectAccess soa(Thread::Current());
std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Lookup"));
std::unique_ptr<TypeLookupTable> table(TypeLookupTable::Create(*dex_file));
ASSERT_NE(nullptr, table.get());
- const char* descriptor = "LBA;";
+ auto pair = GetParam();
+ const char* descriptor = pair.first;
size_t hash = ComputeModifiedUtf8Hash(descriptor);
uint32_t class_def_idx = table->Lookup(descriptor, hash);
- ASSERT_EQ(kDexNoIndex, class_def_idx);
+ ASSERT_EQ(pair.second, class_def_idx);
}
-TEST_F(TypeLookupTableTest, FindNonExistingClassWithCollisions) {
- ScopedObjectAccess soa(Thread::Current());
- std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Lookup"));
- std::unique_ptr<TypeLookupTable> table(TypeLookupTable::Create(*dex_file));
- ASSERT_NE(nullptr, table.get());
- const char* descriptor = "LDA;";
- size_t hash = ComputeModifiedUtf8Hash(descriptor);
- uint32_t class_def_idx = table->Lookup(descriptor, hash);
- ASSERT_EQ(kDexNoIndex, class_def_idx);
-}
-
-TEST_F(TypeLookupTableTest, FindClassNoCollisions) {
- ScopedObjectAccess soa(Thread::Current());
- std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Lookup"));
- std::unique_ptr<TypeLookupTable> table(TypeLookupTable::Create(*dex_file));
- ASSERT_NE(nullptr, table.get());
- const char* descriptor = "LC;";
- size_t hash = ComputeModifiedUtf8Hash(descriptor);
- uint32_t class_def_idx = table->Lookup(descriptor, hash);
- ASSERT_EQ(2U, class_def_idx);
-}
-
-TEST_F(TypeLookupTableTest, FindClassWithCollisions) {
- ScopedObjectAccess soa(Thread::Current());
- std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Lookup"));
- std::unique_ptr<TypeLookupTable> table(TypeLookupTable::Create(*dex_file));
- ASSERT_NE(nullptr, table.get());
- const char* descriptor = "LAB;";
- size_t hash = ComputeModifiedUtf8Hash(descriptor);
- uint32_t class_def_idx = table->Lookup(descriptor, hash);
- ASSERT_EQ(1U, class_def_idx);
-}
-
+INSTANTIATE_TEST_CASE_P(FindNonExistingClassWithoutCollisions,
+ TypeLookupTableTest,
+ testing::Values(DescriptorClassDefIdxPair("LAB;", 1U)));
+INSTANTIATE_TEST_CASE_P(FindNonExistingClassWithCollisions,
+ TypeLookupTableTest,
+ testing::Values(DescriptorClassDefIdxPair("LDA;", kDexNoIndex)));
+INSTANTIATE_TEST_CASE_P(FindClassNoCollisions,
+ TypeLookupTableTest,
+ testing::Values(DescriptorClassDefIdxPair("LC;", 2U)));
+INSTANTIATE_TEST_CASE_P(FindClassWithCollisions,
+ TypeLookupTableTest,
+ testing::Values(DescriptorClassDefIdxPair("LAB;", 1U)));
} // namespace art
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index d75587b..1c95648 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -3639,8 +3639,9 @@
return *common_super;
}
+// TODO Maybe I should just add a METHOD_SUPER to MethodType?
ArtMethod* MethodVerifier::ResolveMethodAndCheckAccess(
- uint32_t dex_method_idx, MethodType method_type) {
+ uint32_t dex_method_idx, MethodType method_type, bool is_super) {
const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx);
const RegType& klass_type = ResolveClassAndCheckAccess(method_id.class_idx_);
if (klass_type.IsConflict()) {
@@ -3667,6 +3668,8 @@
res_method = klass->FindDirectMethod(name, signature, pointer_size);
} else if (method_type == METHOD_INTERFACE) {
res_method = klass->FindInterfaceMethod(name, signature, pointer_size);
+ } else if (is_super && klass->IsInterface()) {
+ res_method = klass->FindInterfaceMethod(name, signature, pointer_size);
} else {
res_method = klass->FindVirtualMethod(name, signature, pointer_size);
}
@@ -3939,7 +3942,7 @@
// we're making.
const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
- ArtMethod* res_method = ResolveMethodAndCheckAccess(method_idx, method_type);
+ ArtMethod* res_method = ResolveMethodAndCheckAccess(method_idx, method_type, is_super);
if (res_method == nullptr) { // error or class is unresolved
// Check what we can statically.
if (!have_pending_hard_failure_) {
@@ -3949,24 +3952,32 @@
}
// If we're using invoke-super(method), make sure that the executing method's class' superclass
- // has a vtable entry for the target method.
+ // has a vtable entry for the target method. Or the target is on a interface.
if (is_super) {
DCHECK(method_type == METHOD_VIRTUAL);
- const RegType& super = GetDeclaringClass().GetSuperClass(®_types_);
- if (super.IsUnresolvedTypes()) {
- Fail(VERIFY_ERROR_NO_METHOD) << "unknown super class in invoke-super from "
- << PrettyMethod(dex_method_idx_, *dex_file_)
- << " to super " << PrettyMethod(res_method);
- return nullptr;
- }
- mirror::Class* super_klass = super.GetClass();
- if (res_method->GetMethodIndex() >= super_klass->GetVTableLength()) {
- Fail(VERIFY_ERROR_NO_METHOD) << "invalid invoke-super from "
- << PrettyMethod(dex_method_idx_, *dex_file_)
- << " to super " << super
- << "." << res_method->GetName()
- << res_method->GetSignature();
- return nullptr;
+ if (res_method->GetDeclaringClass()->IsInterface()) {
+ // TODO Fill in this part. Verify what we can...
+ if (Runtime::Current()->IsAotCompiler()) {
+ Fail(VERIFY_ERROR_FORCE_INTERPRETER) << "Currently we only allow invoke-super in "
+ << "interpreter when using interface methods";
+ }
+ } else {
+ const RegType& super = GetDeclaringClass().GetSuperClass(®_types_);
+ if (super.IsUnresolvedTypes()) {
+ Fail(VERIFY_ERROR_NO_METHOD) << "unknown super class in invoke-super from "
+ << PrettyMethod(dex_method_idx_, *dex_file_)
+ << " to super " << PrettyMethod(res_method);
+ return nullptr;
+ }
+ mirror::Class* super_klass = super.GetClass();
+ if (res_method->GetMethodIndex() >= super_klass->GetVTableLength()) {
+ Fail(VERIFY_ERROR_NO_METHOD) << "invalid invoke-super from "
+ << PrettyMethod(dex_method_idx_, *dex_file_)
+ << " to super " << super
+ << "." << res_method->GetName()
+ << res_method->GetSignature();
+ return nullptr;
+ }
}
}
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index 79db576..ec0a8f9 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -654,7 +654,7 @@
* the referrer can access the resolved method.
* Does not throw exceptions.
*/
- ArtMethod* ResolveMethodAndCheckAccess(uint32_t method_idx, MethodType method_type)
+ ArtMethod* ResolveMethodAndCheckAccess(uint32_t method_idx, MethodType method_type, bool is_super)
SHARED_REQUIRES(Locks::mutator_lock_);
/*
diff --git a/runtime/verifier/reg_type.cc b/runtime/verifier/reg_type.cc
index 16cab03..0894f5d 100644
--- a/runtime/verifier/reg_type.cc
+++ b/runtime/verifier/reg_type.cc
@@ -667,13 +667,13 @@
// float/long/double MERGE float/long/double_constant => float/long/double
return SelectNonConstant(*this, incoming_type);
} else if (IsReferenceTypes() && incoming_type.IsReferenceTypes()) {
- if (IsZero() || incoming_type.IsZero()) {
- return SelectNonConstant(*this, incoming_type); // 0 MERGE ref => ref
- } else if (IsUninitializedTypes() || incoming_type.IsUninitializedTypes()) {
+ if (IsUninitializedTypes() || incoming_type.IsUninitializedTypes()) {
// Something that is uninitialized hasn't had its constructor called. Unitialized types are
// special. They may only ever be merged with themselves (must be taken care of by the
// caller of Merge(), see the DCHECK on entry). So mark any other merge as conflicting here.
return conflict;
+ } else if (IsZero() || incoming_type.IsZero()) {
+ return SelectNonConstant(*this, incoming_type); // 0 MERGE ref => ref
} else if (IsJavaLangObject() || incoming_type.IsJavaLangObject()) {
return reg_types->JavaLangObject(false); // Object MERGE ref => Object
} else if (IsUnresolvedTypes() || incoming_type.IsUnresolvedTypes()) {
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index 80b751c..7c7981e 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -246,28 +246,18 @@
}
/*
- * A basic Join operation on classes. For a pair of types S and T the Join,
- *written S v T = J, is
- * S <: J, T <: J and for-all U such that S <: U, T <: U then J <: U. That is
- *J is the parent of
- * S and T such that there isn't a parent of both S and T that isn't also the
- *parent of J (ie J
+ * A basic Join operation on classes. For a pair of types S and T the Join, written S v T = J, is
+ * S <: J, T <: J and for-all U such that S <: U, T <: U then J <: U. That is J is the parent of
+ * S and T such that there isn't a parent of both S and T that isn't also the parent of J (ie J
* is the deepest (lowest upper bound) parent of S and T).
*
- * This operation applies for regular classes and arrays, however, for
- *interface types there
- * needn't be a partial ordering on the types. We could solve the problem of a
- *lack of a partial
- * order by introducing sets of types, however, the only operation permissible
- *on an interface is
- * invoke-interface. In the tradition of Java verifiers [1] we defer the
- *verification of interface
- * types until an invoke-interface call on the interface typed reference at
- *runtime and allow
- * the perversion of Object being assignable to an interface type (note,
- *however, that we don't
- * allow assignment of Object or Interface to any concrete class and are
- *therefore type safe).
+ * This operation applies for regular classes and arrays, however, for interface types there
+ * needn't be a partial ordering on the types. We could solve the problem of a lack of a partial
+ * order by introducing sets of types, however, the only operation permissible on an interface is
+ * invoke-interface. In the tradition of Java verifiers [1] we defer the verification of interface
+ * types until an invoke-interface call on the interface typed reference at runtime and allow
+ * the perversion of Object being assignable to an interface type (note, however, that we don't
+ * allow assignment of Object or Interface to any concrete class and are therefore type safe).
*
* [1] Java bytecode verification: algorithms and formalizations, Xavier Leroy
*/
diff --git a/test/091-override-package-private-method/build b/test/091-override-package-private-method/build
new file mode 100755
index 0000000..5a340dc
--- /dev/null
+++ b/test/091-override-package-private-method/build
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# Copyright (C) 2015 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.
+
+# Stop if something fails.
+set -e
+
+mkdir classes
+${JAVAC} -d classes `find src -name '*.java'`
+
+mkdir classes-ex
+mv classes/OverridePackagePrivateMethodSuper.class classes-ex
+
+if [ ${USE_JACK} = "true" ]; then
+ # Create .jack files from classes generated with javac.
+ ${JILL} classes --output classes.jack
+ ${JILL} classes-ex --output classes-ex.jack
+
+ # Create DEX files from .jack files.
+ ${JACK} --import classes.jack --output-dex .
+ zip $TEST_NAME.jar classes.dex
+ ${JACK} --import classes-ex.jack --output-dex .
+ zip ${TEST_NAME}-ex.jar classes.dex
+else
+ if [ ${NEED_DEX} = "true" ]; then
+ ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex --dump-width=1000 classes
+ zip $TEST_NAME.jar classes.dex
+ ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes.dex --dump-width=1000 classes-ex
+ zip ${TEST_NAME}-ex.jar classes.dex
+ fi
+fi
diff --git a/test/091-override-package-private-method/expected.txt b/test/091-override-package-private-method/expected.txt
new file mode 100644
index 0000000..286cfcd
--- /dev/null
+++ b/test/091-override-package-private-method/expected.txt
@@ -0,0 +1 @@
+OverridePackagePrivateMethodTest
diff --git a/test/091-override-package-private-method/info.txt b/test/091-override-package-private-method/info.txt
new file mode 100644
index 0000000..8e183bf
--- /dev/null
+++ b/test/091-override-package-private-method/info.txt
@@ -0,0 +1,3 @@
+Test features with a secondary dex file.
+
+- Regression test to ensure AOT compiler correctly manages overriden package-private method.
diff --git a/test/091-override-package-private-method/run b/test/091-override-package-private-method/run
new file mode 100755
index 0000000..d8c3c79
--- /dev/null
+++ b/test/091-override-package-private-method/run
@@ -0,0 +1,18 @@
+#!/bin/bash
+#
+# Copyright (C) 2014 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.
+
+# Use secondary switch to add secondary dex file to class path.
+exec ${RUN} "${@}" --secondary
diff --git a/test/091-override-package-private-method/src/Main.java b/test/091-override-package-private-method/src/Main.java
new file mode 100644
index 0000000..6543c98
--- /dev/null
+++ b/test/091-override-package-private-method/src/Main.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+/**
+ * Override package-private method test.
+ */
+public class Main {
+ public static void main(String[] args) {
+ try {
+ new OverridePackagePrivateMethodTest().test(new Object());
+ } catch (Exception e) {
+ System.out.println("Got unexpected exception " + e);
+ }
+ }
+}
diff --git a/test/091-override-package-private-method/src/OverridePackagePrivateMethodSuper.java b/test/091-override-package-private-method/src/OverridePackagePrivateMethodSuper.java
new file mode 100644
index 0000000..4ad051e
--- /dev/null
+++ b/test/091-override-package-private-method/src/OverridePackagePrivateMethodSuper.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+public class OverridePackagePrivateMethodSuper {
+ void print() {
+ System.out.println("OverridePackagePrivateMethodSuper");
+ }
+}
diff --git a/test/091-override-package-private-method/src/OverridePackagePrivateMethodTest.java b/test/091-override-package-private-method/src/OverridePackagePrivateMethodTest.java
new file mode 100644
index 0000000..2f2b7ca
--- /dev/null
+++ b/test/091-override-package-private-method/src/OverridePackagePrivateMethodTest.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+public class OverridePackagePrivateMethodTest extends OverridePackagePrivateMethodSuper {
+ public void test(Object obj) {
+ if (obj == null) {
+ throw new NullPointerException("Got null");
+ }
+ print();
+ }
+
+ void print() {
+ System.out.println("OverridePackagePrivateMethodTest");
+ }
+}
diff --git a/test/143-string-value/check b/test/143-string-value/check
index cdf7b78..92f6e90 100755
--- a/test/143-string-value/check
+++ b/test/143-string-value/check
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Strip run-specific numbers (pid and line number)
-sed -e 's/^art E[ ]\+[0-9]\+[ ]\+[0-9]\+ art\/runtime\/native\/java_lang_Class.cc:[0-9]\+\] //' "$2" > "$2.tmp"
+# Strip error log messages.
+sed -e '/^art E.*\] /d' "$2" > "$2.tmp"
diff --strip-trailing-cr -q "$1" "$2.tmp" >/dev/null
diff --git a/test/495-checker-checkcast-tests/src/Main.java b/test/495-checker-checkcast-tests/src/Main.java
index 4b2bf09..6011c7c 100644
--- a/test/495-checker-checkcast-tests/src/Main.java
+++ b/test/495-checker-checkcast-tests/src/Main.java
@@ -113,13 +113,13 @@
}
/// CHECK-START: java.lang.String Main.knownTestWithLoadedClass() register (after)
- /// CHECK-NOT: LoadClass
+ /// CHECK-NOT: CheckCast
public static String knownTestWithLoadedClass() {
return (String)$inline$getString();
}
/// CHECK-START: Itf Main.knownTestWithUnloadedClass() register (after)
- /// CHECK: LoadClass
+ /// CHECK: CheckCast
public static Itf knownTestWithUnloadedClass() {
return (Itf)$inline$getString();
}
diff --git a/test/559-checker-irreducible-loop/expected.txt b/test/559-checker-irreducible-loop/expected.txt
new file mode 100644
index 0000000..b64be7a
--- /dev/null
+++ b/test/559-checker-irreducible-loop/expected.txt
@@ -0,0 +1,7 @@
+84
+30
+168
+126
+class Main
+42
+-42
diff --git a/test/559-checker-irreducible-loop/info.txt b/test/559-checker-irreducible-loop/info.txt
new file mode 100644
index 0000000..e0ace18
--- /dev/null
+++ b/test/559-checker-irreducible-loop/info.txt
@@ -0,0 +1 @@
+Tests for irreducible loop support in compiler.
diff --git a/test/559-checker-irreducible-loop/smali/IrreducibleLoop.smali b/test/559-checker-irreducible-loop/smali/IrreducibleLoop.smali
new file mode 100644
index 0000000..30a648d
--- /dev/null
+++ b/test/559-checker-irreducible-loop/smali/IrreducibleLoop.smali
@@ -0,0 +1,561 @@
+# Copyright (C) 2015 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.
+
+.class public LIrreducibleLoop;
+
+.super Ljava/lang/Object;
+
+# Back-edges in the ascii-art graphs are represented with dash '-'.
+
+# Test that we support a simple irreducible loop.
+#
+# entry
+# / \
+# / \
+# loop_entry \
+# / \- \
+# exit \- \
+# other_loop_entry
+#
+## CHECK-START: int IrreducibleLoop.simpleLoop(int) dead_code_elimination (before)
+## CHECK: irreducible:true
+.method public static simpleLoop(I)I
+ .registers 2
+ const/16 v0, 42
+ if-eq v1, v0, :other_loop_entry
+ :loop_entry
+ if-ne v1, v0, :exit
+ add-int v0, v0, v0
+ :other_loop_entry
+ add-int v0, v0, v0
+ goto :loop_entry
+ :exit
+ return v0
+.end method
+
+# Test that lse does not wrongly optimize loads in irreducible loops. At the
+# SSA level, since we create redundant phis for irreducible loop headers, lse
+# does not see the relation between the dex register and the phi.
+#
+# entry
+# p1
+# / \
+# / \
+# / \
+# / \
+# loop_pre_entry \
+# set 42 in p1:myField \
+# / \
+# loop_entry \
+# get p1.myField \
+# / \- \
+# exit \- \
+# \- \
+# other_loop_entry
+# set 30 in p1:myField
+#
+## CHECK-START: int IrreducibleLoop.lse(int, Main) dead_code_elimination (after)
+## CHECK: irreducible:true
+#
+## CHECK-START: int IrreducibleLoop.lse(int, Main) load_store_elimination (after)
+## CHECK: InstanceFieldGet
+.method public static lse(ILMain;)I
+ .registers 4
+ const/16 v0, 42
+ const/16 v1, 30
+ if-eq p0, v0, :other_loop_pre_entry
+ goto: loop_pre_entry
+ :loop_pre_entry
+ iput v0, p1, LMain;->myField:I
+ :loop_entry
+ if-ne v1, v0, :exit
+ :other_loop_entry
+ iget v0, p1, LMain;->myField:I
+ if-eq v1, v0, :exit
+ goto :loop_entry
+ :exit
+ return v0
+ :other_loop_pre_entry
+ iput v1, p1, LMain;->myField:I
+ goto :other_loop_entry
+.end method
+
+# Check that if a irreducible loop entry is dead, the loop can become
+# natural.
+# We start with:
+#
+# entry
+# / \
+# / \
+# loop_entry \
+# / \- \
+# exit \- \
+# other_loop_entry
+#
+## CHECK-START: int IrreducibleLoop.dce(int) dead_code_elimination (before)
+## CHECK: irreducible:true
+
+# And end with:
+#
+# entry
+# /
+# /
+# loop_entry
+# / \-
+# exit \-
+# other_loop_entry
+
+## CHECK-START: int IrreducibleLoop.dce(int) dead_code_elimination (after)
+## CHECK-NOT: irreducible:true
+.method public static dce(I)I
+ .registers 3
+ const/16 v0, 42
+ const/16 v1, 168
+ if-ne v0, v0, :other_loop_pre_entry
+ :loop_entry
+ if-ne v0, v0, :exit
+ add-int v0, v0, v0
+ :other_loop_entry
+ add-int v0, v0, v0
+ if-eq v0, v1, :exit
+ goto :loop_entry
+ :exit
+ return v0
+ :other_loop_pre_entry
+ add-int v0, v0, v0
+ goto :other_loop_entry
+.end method
+
+# Check that a dex register only used in the loop header remains live thanks
+# to the (redundant) Phi created at the loop header for it.
+#
+# entry
+# p0
+# / \
+# / \
+# / \
+# loop_entry \
+# i0 = phi(p0,i1) \
+# / \- \
+# exit \- \
+# other_loop_entry
+# i1 = phi(p0, i0)
+#
+## CHECK-START: int IrreducibleLoop.liveness(int) liveness (after)
+## CHECK-DAG: <<Arg:i\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopPhiUse:\d+>>)}
+## CHECK-DAG: <<LoopPhi:i\d+>> Phi [<<Arg>>,<<PhiInLoop:i\d+>>] liveness:<<ArgLoopPhiUse>> ranges:{[<<ArgLoopPhiUse>>,<<PhiInLoopUse:\d+>>)}
+## CHECK-DAG: <<PhiInLoop>> Phi [<<Arg>>,<<LoopPhi>>] liveness:<<PhiInLoopUse>> ranges:{[<<PhiInLoopUse>>,<<BackEdgeLifetimeEnd:\d+>>)}
+## CHECK: Return liveness:<<ReturnLiveness:\d+>>
+## CHECK-EVAL: <<ReturnLiveness>> == <<BackEdgeLifetimeEnd>> + 2
+.method public static liveness(I)I
+ .registers 2
+ const/16 v0, 42
+ if-eq p0, v0, :other_loop_entry
+ :loop_entry
+ add-int v0, v0, p0
+ if-ne v1, v0, :exit
+ :other_loop_entry
+ add-int v0, v0, v0
+ goto :loop_entry
+ :exit
+ return v0
+.end method
+
+# Check that we don't GVN across irreducible loops:
+# "const-class 1" in loop_entry should not be GVN with
+# "const-class 1" in entry.
+#
+# entry
+# const-class 1
+# / \
+# / \
+# loop_entry \
+# const-class 1 \
+# / \- \
+# exit \- \
+# other_loop_entry
+# const-class 2
+#
+## CHECK-START: java.lang.Class IrreducibleLoop.gvn() GVN (before)
+## CHECK: LoadClass
+## CHECK: LoadClass
+## CHECK: LoadClass
+## CHECK-NOT: LoadClass
+
+## CHECK-START: java.lang.Class IrreducibleLoop.gvn() GVN (after)
+## CHECK: LoadClass
+## CHECK: LoadClass
+## CHECK: LoadClass
+## CHECK-NOT: LoadClass
+
+.method public static gvn()Ljava/lang/Class;
+ .registers 3
+ const/4 v2, 0
+ const-class v0, LMain;
+ if-ne v0, v2, :other_loop_entry
+ :loop_entry
+ const-class v0, LMain;
+ if-ne v0, v2, :exit
+ :other_loop_entry
+ const-class v1, LIrreducibleLoop;
+ goto :loop_entry
+ :exit
+ return-object v0
+.end method
+
+# Check that we don't LICM across irreducible loops:
+# "add" in loop_entry should not be LICMed.
+#
+# entry
+# / \
+# / \
+# loop_entry \
+# add \
+# / \- \
+# exit \- \
+# other_loop_entry
+#
+## CHECK-START: int IrreducibleLoop.licm1(int) licm (after)
+## CHECK: Add irreducible:true
+.method public static licm1(I)I
+ .registers 3
+ const/4 v0, 0
+ if-ne p0, v0, :other_loop_entry
+ :loop_entry
+ add-int v0, p0, p0
+ if-ne v0, p0, :exit
+ :other_loop_entry
+ sub-int v1, p0, p0
+ goto :loop_entry
+ :exit
+ sub-int v0, v0, p0
+ return v0
+.end method
+
+# Check that we don't LICM across irreducible loops:
+# "const-class" in loop_entry should not be LICMed.
+#
+# entry
+# / \
+# / \
+# loop_entry \
+# const-class \
+# / \- \
+# exit \- \
+# other_loop_entry
+#
+## CHECK-START: int IrreducibleLoop.licm2(int) licm (after)
+## CHECK: LoadClass irreducible:true
+.method public static licm2(I)I
+ .registers 3
+ const/4 v0, 0
+ if-ne p0, v0, :other_loop_entry
+ :loop_entry
+ const-class v1, LIrreducibleLoop;
+ if-ne v0, p0, :exit
+ :other_loop_entry
+ sub-int v1, p0, p0
+ goto :loop_entry
+ :exit
+ sub-int v0, v0, p0
+ return v0
+.end method
+
+# Check that we don't LICM in a natural loop that contains an irreducible loop:
+# "const-class" should not be LICMed.
+#
+# entry
+# |
+# loop_entry
+# const-class -------------------
+# / \ -
+# / \ -
+# exit loop_body -
+# / \ -
+# / \ -
+# irreducible_loop_entry \ -
+# - \ \ -
+# - \ \ -
+# - irreducible_loop_other_entry
+# - |
+# - |
+# ------ irreducible_loop_back_edge
+#
+## CHECK-START: int IrreducibleLoop.licm3(int, int, int) licm (after)
+## CHECK: LoadClass loop:<<OuterLoop:B\d+>> irreducible:false
+## CHECK: Goto outer_loop:<<OuterLoop>> irreducible:true
+.method public static licm3(III)I
+ .registers 4
+ :loop_entry
+ const-class v0, LIrreducibleLoop;
+ if-ne p1, p2, :exit
+ goto :loop_body
+
+ :loop_body
+ if-eq p0, p1, :irreducible_loop_entry
+ goto :irreducible_loop_other_entry
+
+ :irreducible_loop_entry
+ goto :irreducible_loop_other_entry
+
+ :irreducible_loop_other_entry
+ if-eq p0, p2, :loop_entry
+ goto :irreducible_loop_back_edge
+
+ :irreducible_loop_back_edge
+ goto :irreducible_loop_entry
+ :exit
+ return p0
+.end method
+
+# Check a loop within an irreducible loop
+#
+# entry
+# / \
+# / \
+# irreducible_loop_entry \
+# / - \ irreducible_loop_pre_other_entry
+# exit - \ /
+# - irreducible_loop_body
+# - |
+# - |
+# - loop_within_header
+# - / \-
+# - / \-
+# irreducible_loop_back_edge loop_within_back_edge
+#
+## CHECK-START: void IrreducibleLoop.analyze1(int) ssa_builder (after)
+## CHECK-DAG: Goto loop:<<OuterLoop:B\d+>> outer_loop:none irreducible:true
+## CHECK-DAG: Goto outer_loop:<<OuterLoop>> irreducible:false
+.method public static analyze1(I)V
+ .registers 1
+ if-eq p0, p0, :irreducible_loop_entry
+ goto :irreducible_loop_pre_other_entry
+
+ :irreducible_loop_entry
+ if-eq p0, p0, :exit
+ goto :irreducible_loop_body
+
+ :irreducible_loop_body
+ :loop_within_header
+ if-eq p0, p0, :irreducible_loop_back_edge
+ goto :loop_within_back_edge
+
+ :loop_within_back_edge
+ goto :loop_within_header
+
+ :irreducible_loop_back_edge
+ goto :irreducible_loop_entry
+
+ :irreducible_loop_pre_other_entry
+ goto :irreducible_loop_body
+
+ :exit
+ return-void
+.end method
+
+# Check than a loop before an irreducible loop is not part of the
+# irreducible loop.
+#
+# entry
+# |
+# |
+# loop_header
+# / \-
+# / \-
+# irreducible_loop_pre_entry loop_body
+# / \
+# / \
+# irreducible_loop_entry \
+# / \- irreducible_loop_other_pre_entry
+# / \- /
+# exit \- /
+# irreducible_loop_body
+#
+## CHECK-START: void IrreducibleLoop.analyze2(int) ssa_builder (after)
+## CHECK-DAG: Goto outer_loop:none irreducible:false
+## CHECK-DAG: Goto outer_loop:none irreducible:true
+.method public static analyze2(I)V
+ .registers 1
+ :loop_header
+ if-eq p0, p0, :irreducible_loop_pre_entry
+ goto :loop_body
+ :loop_body
+ goto :loop_header
+
+ :irreducible_loop_pre_entry
+ if-eq p0, p0, :irreducible_loop_other_pre_entry
+ goto :irreducible_loop_entry
+
+ :irreducible_loop_entry
+ if-eq p0, p0, :exit
+ goto :irreducible_loop_body
+
+ :irreducible_loop_body
+ goto :irreducible_loop_entry
+
+ :irreducible_loop_other_pre_entry
+ goto :irreducible_loop_body
+
+ :exit
+ return-void
+.end method
+
+# Check two irreducible loops, one within another.
+#
+# entry
+# / \
+# / \
+# loop1_header loop2_header
+# - | / -
+# - | / -
+# - | / -
+# - | / -
+# - loop2_body -
+# - / \ -
+# - / \ -
+# loop1_body loop2_back_edge
+# |
+# |
+# exit
+#
+## CHECK-START: void IrreducibleLoop.analyze3(int) ssa_builder (after)
+## CHECK-DAG: Goto loop:<<OuterLoop:B\d+>> outer_loop:none irreducible:true
+## CHECK-DAG: Goto outer_loop:<<OuterLoop>> irreducible:true
+.method public static analyze3(I)V
+ .registers 1
+ if-eq p0, p0, :loop2_header
+ goto :loop1_header
+
+ :loop1_header
+ goto :loop2_body
+
+ :loop2_header
+ goto :loop2_body
+
+ :loop2_body
+ if-eq p0, p0, :loop2_back_edge
+ goto :loop1_body
+
+ :loop2_back_edge
+ goto :loop2_header
+
+ :loop1_body
+ if-eq p0, p0, :exit
+ goto :loop1_header
+
+ :exit
+ return-void
+.end method
+
+# Check two irreducible loops, one within another. Almost identical
+# to analyze3 except the branches of the first 'if' are swapped, to
+# ensure the order at which we find the back edges does not matter.
+#
+# entry
+# / \
+# / \
+# loop1_header loop2_header
+# - | / -
+# - | / -
+# - | / -
+# - | / -
+# - loop2_body -
+# - / \ -
+# - / \ -
+# loop1_body loop2_back_edge
+# |
+# |
+# exit
+#
+## CHECK-START: void IrreducibleLoop.analyze4(int) ssa_builder (after)
+## CHECK-DAG: Goto loop:<<OuterLoop:B\d+>> outer_loop:none irreducible:true
+## CHECK-DAG: Goto outer_loop:<<OuterLoop>> irreducible:true
+.method public static analyze4(I)V
+ .registers 1
+ if-eq p0, p0, :loop1_header
+ goto :loop2_header
+
+ :loop1_header
+ goto :loop2_body
+
+ :loop2_header
+ goto :loop2_body
+
+ :loop2_body
+ if-eq p0, p0, :loop2_back_edge
+ goto :loop1_body
+
+ :loop2_back_edge
+ goto :loop2_header
+
+ :loop1_body
+ if-eq p0, p0, :exit
+ goto :loop1_header
+
+ :exit
+ return-void
+.end method
+
+# Check two irreducible loops, one within another. Almost identical
+# to analyze3 and analyze4, except that the inner loop exits from the
+# back edge, and not the body.
+#
+# entry
+# / \
+# / \
+# loop1_header loop2_header
+# - \ / -
+# - \ / -
+# - \ / -
+# - \ / -
+# - loop2_body -
+# - | -
+# - | -
+# - loop2_back_edge ------
+# - |
+# - |
+# ----- loop1_body
+# |
+# |
+# exit
+#
+## CHECK-START: void IrreducibleLoop.analyze5(int) ssa_builder (after)
+## CHECK-DAG: Goto loop:<<OuterLoop:B\d+>> outer_loop:none irreducible:true
+## CHECK-DAG: Goto outer_loop:<<OuterLoop>> irreducible:true
+.method public static analyze5(I)V
+ .registers 1
+ if-eq p0, p0, :loop1_header
+ goto :loop2_header
+
+ :loop1_header
+ goto :loop2_body
+
+ :loop2_header
+ goto :loop2_body
+
+ :loop2_body
+ goto :loop2_back_edge
+
+ :loop2_back_edge
+ if-eq p0, p0, :loop2_header
+ goto :loop1_body
+
+ :loop1_body
+ if-eq p0, p0, :exit
+ goto :loop1_header
+
+ :exit
+ return-void
+.end method
diff --git a/test/559-checker-irreducible-loop/src/Main.java b/test/559-checker-irreducible-loop/src/Main.java
new file mode 100644
index 0000000..ab84f81
--- /dev/null
+++ b/test/559-checker-irreducible-loop/src/Main.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+import java.lang.reflect.Method;
+
+public class Main {
+ // Workaround for b/18051191.
+ class InnerClass {}
+
+ public static void main(String[] args) throws Exception {
+ Class<?> c = Class.forName("IrreducibleLoop");
+ {
+ Method m = c.getMethod("simpleLoop", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
+
+ {
+ Method m = c.getMethod("lse", int.class, Main.class);
+ Object[] arguments = { 42, new Main() };
+ System.out.println(m.invoke(null, arguments));
+ }
+
+ {
+ Method m = c.getMethod("dce", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
+
+ {
+ Method m = c.getMethod("liveness", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
+
+ {
+ Method m = c.getMethod("gvn");
+ Object[] arguments = { };
+ System.out.println(m.invoke(null, arguments));
+ }
+
+ {
+ Method m = c.getMethod("licm1", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
+
+ {
+ Method m = c.getMethod("licm2", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
+ }
+
+ int myField;
+}
diff --git a/test/563-checker-fakestring/expected.txt b/test/563-checker-fakestring/expected.txt
new file mode 100644
index 0000000..6a5618e
--- /dev/null
+++ b/test/563-checker-fakestring/expected.txt
@@ -0,0 +1 @@
+JNI_OnLoad called
diff --git a/test/563-checker-fakestring/info.txt b/test/563-checker-fakestring/info.txt
new file mode 100644
index 0000000..ef09d8c
--- /dev/null
+++ b/test/563-checker-fakestring/info.txt
@@ -0,0 +1,2 @@
+Regression test for FakeString simplification which incorrectly assumed that
+it cannot be used before a call to StringFactory.
\ No newline at end of file
diff --git a/test/563-checker-fakestring/smali/TestCase.smali b/test/563-checker-fakestring/smali/TestCase.smali
new file mode 100644
index 0000000..cd52f3d
--- /dev/null
+++ b/test/563-checker-fakestring/smali/TestCase.smali
@@ -0,0 +1,100 @@
+# Copyright (C) 2016 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.
+
+.class public LTestCase;
+.super Ljava/lang/Object;
+
+# Test that all vregs holding the new-instance are updated after the
+# StringFactory call.
+
+## CHECK-START: java.lang.String TestCase.vregAliasing(byte[]) register (after)
+## CHECK-DAG: Return [<<String:l\d+>>]
+## CHECK-DAG: <<String>> InvokeStaticOrDirect method_name:java.lang.String.<init>
+
+.method public static vregAliasing([B)Ljava/lang/String;
+ .registers 5
+
+ # Create new instance of String and store it to v0, v1, v2.
+ new-instance v0, Ljava/lang/String;
+ move-object v1, v0
+ move-object v2, v0
+
+ # Call String.<init> on v1.
+ const-string v3, "UTF8"
+ invoke-direct {v1, p0, v3}, Ljava/lang/String;-><init>([BLjava/lang/String;)V
+
+ # Return the object from v2.
+ return-object v2
+
+.end method
+
+# Test usage of String new-instance before it is initialized.
+
+## CHECK-START: void TestCase.compareNewInstance() register (after)
+## CHECK-DAG: <<Null:l\d+>> NullConstant
+## CHECK-DAG: <<String:l\d+>> NewInstance
+## CHECK-DAG: <<Cond:z\d+>> NotEqual [<<String>>,<<Null>>]
+## CHECK-DAG: If [<<Cond>>]
+
+.method public static compareNewInstance()V
+ .registers 3
+
+ new-instance v0, Ljava/lang/String;
+ if-nez v0, :return
+
+ # Will throw NullPointerException if this branch is taken.
+ const v1, 0x0
+ const-string v2, "UTF8"
+ invoke-direct {v0, v1, v2}, Ljava/lang/String;-><init>([BLjava/lang/String;)V
+ return-void
+
+ :return
+ return-void
+
+.end method
+
+# Test deoptimization between String's allocation and initialization.
+
+## CHECK-START: int TestCase.deoptimizeNewInstance(int[], byte[]) register (after)
+## CHECK: <<String:l\d+>> NewInstance
+## CHECK: Deoptimize env:[[<<String>>,{{.*]]}}
+## CHECK: InvokeStaticOrDirect method_name:java.lang.String.<init>
+
+.method public static deoptimizeNewInstance([I[B)I
+ .registers 6
+
+ const v2, 0x0
+ const v1, 0x1
+
+ new-instance v0, Ljava/lang/String;
+
+ # Deoptimize here if the array is too short.
+ aget v1, p0, v1
+ add-int/2addr v2, v1
+
+ # Check that we're being executed by the interpreter.
+ invoke-static {}, LMain;->assertIsInterpreted()V
+
+ # String allocation should succeed.
+ const-string v3, "UTF8"
+ invoke-direct {v0, p1, v3}, Ljava/lang/String;-><init>([BLjava/lang/String;)V
+
+ # This ArrayGet will throw ArrayIndexOutOfBoundsException.
+ const v1, 0x4
+ aget v1, p0, v1
+ add-int/2addr v2, v1
+
+ return v2
+
+.end method
diff --git a/test/563-checker-fakestring/src/Main.java b/test/563-checker-fakestring/src/Main.java
new file mode 100644
index 0000000..750f718
--- /dev/null
+++ b/test/563-checker-fakestring/src/Main.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+public class Main {
+ // Workaround for b/18051191.
+ class Inner {}
+
+ public static native void assertIsInterpreted();
+
+ private static void assertEqual(String expected, String actual) {
+ if (!expected.equals(actual)) {
+ throw new Error("Assertion failed: " + expected + " != " + actual);
+ }
+ }
+
+ public static void main(String[] args) throws Throwable {
+ System.loadLibrary(args[0]);
+ Class<?> c = Class.forName("TestCase");
+ String testString = "Hello world";
+ byte[] testData = testString.getBytes("UTF8");
+
+ {
+ Method m = c.getMethod("vregAliasing", byte[].class);
+ String result = (String) m.invoke(null, new Object[] { testData });
+ assertEqual(testString, result);
+ }
+
+ {
+ c.getMethod("compareNewInstance").invoke(null, (Object[]) null);
+ }
+
+ {
+ Method m = c.getMethod("deoptimizeNewInstance", int[].class, byte[].class);
+ try {
+ m.invoke(null, new Object[] { new int[] { 1, 2, 3 }, testData });
+ } catch (InvocationTargetException ex) {
+ if (ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
+ // Expected.
+ } else {
+ throw ex.getCause();
+ }
+ }
+ }
+ }
+}
diff --git a/test/800-smali/expected.txt b/test/800-smali/expected.txt
index 27f5b5d..2e66af5 100644
--- a/test/800-smali/expected.txt
+++ b/test/800-smali/expected.txt
@@ -49,4 +49,5 @@
b/25494456
b/21869691
b/26143249
+b/26579108
Done!
diff --git a/test/800-smali/smali/b_26579108.smali b/test/800-smali/smali/b_26579108.smali
new file mode 100644
index 0000000..dde3825
--- /dev/null
+++ b/test/800-smali/smali/b_26579108.smali
@@ -0,0 +1,34 @@
+# Copyright (C) 2016 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.
+
+.class public LB26579108;
+.super Ljava/lang/Object;
+
+# Ensure that merging uninitialized type and null does not pass verification.
+
+.field public static field:I
+
+.method public static run()Ljava/lang/String;
+ .registers 2
+ new-instance v0, Ljava/lang/String;
+
+ sget v1, LB26579108;->field:I
+ if-eqz v1, :cond_5
+
+ const/4 v0, 0x0
+ :cond_5
+
+ invoke-direct {v0}, Ljava/lang/String;-><init>()V
+ return-object v0
+ .end method
diff --git a/test/800-smali/src/Main.java b/test/800-smali/src/Main.java
index cc3b0b4..38aa58d 100644
--- a/test/800-smali/src/Main.java
+++ b/test/800-smali/src/Main.java
@@ -143,6 +143,8 @@
new IncompatibleClassChangeError(), null));
testCases.add(new TestCase("b/26143249", "B26143249", "run", null,
new AbstractMethodError(), null));
+ testCases.add(new TestCase("b/26579108", "B26579108", "run", null, new VerifyError(),
+ null));
}
public void runTests() {
@@ -188,8 +190,7 @@
if (tc.expectedException != null) {
errorReturn = new IllegalStateException("Expected an exception in test " +
tc.testName);
- }
- if (tc.expectedReturn == null && retValue != null) {
+ } else if (tc.expectedReturn == null && retValue != null) {
errorReturn = new IllegalStateException("Expected a null result in test " +
tc.testName);
} else if (tc.expectedReturn != null &&
diff --git a/test/969-iface-super/build b/test/969-iface-super/build
new file mode 100755
index 0000000..b1ef320
--- /dev/null
+++ b/test/969-iface-super/build
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+
+# make us exit on a failure
+set -e
+
+# Should we compile with Java source code. By default we will use Smali.
+USES_JAVA_SOURCE="false"
+if [[ $@ == *"--jvm"* ]]; then
+ USES_JAVA_SOURCE="true"
+elif [[ "$USE_JACK" == "true" ]]; then
+ if $JACK -D jack.java.source.version=1.8 2>/dev/null; then
+ USES_JAVA_SOURCE="true"
+ else
+ echo "WARNING: Cannot use jack because it does not support JLS 1.8. Falling back to smali" >&2
+ fi
+fi
+
+# Generate the smali Main.smali file or fail
+${ANDROID_BUILD_TOP}/art/test/utils/python/generate_smali_main.py ./smali
+
+if [[ "$USES_JAVA_SOURCE" == "true" ]]; then
+ # We are compiling java code, create it.
+ mkdir -p src
+ ${ANDROID_BUILD_TOP}/art/tools/extract-embedded-java ./smali ./src
+ # Ignore the smali directory.
+ EXTRA_ARGS="--no-smali"
+fi
+
+./default-build "$@" "$EXTRA_ARGS" --experimental default-methods
diff --git a/test/969-iface-super/expected.txt b/test/969-iface-super/expected.txt
new file mode 100644
index 0000000..f310d10
--- /dev/null
+++ b/test/969-iface-super/expected.txt
@@ -0,0 +1,47 @@
+Testing for type A
+A-virtual A.SayHi()='Hello '
+A-interface iface.SayHi()='Hello '
+End testing for type A
+Testing for type B
+B-virtual B.SayHi()='Hello Hello '
+B-interface iface.SayHi()='Hello Hello '
+B-interface iface2.SayHi()='Hello Hello '
+End testing for type B
+Testing for type C
+C-virtual C.SayHi()='Hello and welcome '
+C-interface iface.SayHi()='Hello and welcome '
+End testing for type C
+Testing for type D
+D-virtual D.SayHi()='Hello Hello and welcome '
+D-interface iface.SayHi()='Hello Hello and welcome '
+D-interface iface2.SayHi()='Hello Hello and welcome '
+End testing for type D
+Testing for type E
+E-virtual E.SayHi()='Hello there!'
+E-interface iface.SayHi()='Hello there!'
+E-interface iface3.SayHi()='Hello there!'
+End testing for type E
+Testing for type F
+F-virtual E.SayHi()='Hello there!'
+F-virtual F.SayHi()='Hello there!'
+F-interface iface.SayHi()='Hello there!'
+F-interface iface3.SayHi()='Hello there!'
+F-virtual F.SaySurprisedHi()='Hello there!!'
+End testing for type F
+Testing for type G
+G-virtual E.SayHi()='Hello there!?'
+G-virtual F.SayHi()='Hello there!?'
+G-virtual G.SayHi()='Hello there!?'
+G-interface iface.SayHi()='Hello there!?'
+G-interface iface3.SayHi()='Hello there!?'
+G-virtual F.SaySurprisedHi()='Hello there!!'
+G-virtual G.SaySurprisedHi()='Hello there!!'
+G-virtual G.SayVerySurprisedHi()='Hello there!!!'
+End testing for type G
+Testing for type H
+H-virtual H.SayConfusedHi()='Hello ?!'
+H-virtual A.SayHi()='Hello ?'
+H-virtual H.SayHi()='Hello ?'
+H-interface iface.SayHi()='Hello ?'
+H-virtual H.SaySurprisedHi()='Hello !'
+End testing for type H
diff --git a/test/969-iface-super/info.txt b/test/969-iface-super/info.txt
new file mode 100644
index 0000000..c0555d2
--- /dev/null
+++ b/test/969-iface-super/info.txt
@@ -0,0 +1,6 @@
+Smali-based tests for experimental interface static methods.
+
+This tests invoke-super with default methods.
+
+To run with --jvm you must export JAVA_HOME to a java-8 installation and pass
+the --use-java-home to run-test
diff --git a/test/969-iface-super/run b/test/969-iface-super/run
new file mode 100755
index 0000000..8944ea9
--- /dev/null
+++ b/test/969-iface-super/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2015 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.
+
+${RUN} "$@" --experimental default-methods
diff --git a/test/969-iface-super/smali/A.smali b/test/969-iface-super/smali/A.smali
new file mode 100644
index 0000000..e7760a1
--- /dev/null
+++ b/test/969-iface-super/smali/A.smali
@@ -0,0 +1,28 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class A implements iface {
+# }
+
+.class public LA;
+.super Ljava/lang/Object;
+.implements Liface;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
diff --git a/test/969-iface-super/smali/B.smali b/test/969-iface-super/smali/B.smali
new file mode 100644
index 0000000..e529d05
--- /dev/null
+++ b/test/969-iface-super/smali/B.smali
@@ -0,0 +1,28 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class B implements iface2 {
+# }
+
+.class public LB;
+.super Ljava/lang/Object;
+.implements Liface2;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
diff --git a/test/969-iface-super/smali/C.smali b/test/969-iface-super/smali/C.smali
new file mode 100644
index 0000000..6fbb0c4
--- /dev/null
+++ b/test/969-iface-super/smali/C.smali
@@ -0,0 +1,41 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class C implements iface {
+# public String SayHi() {
+# return iface.super.SayHi() + " and welcome ";
+# }
+# }
+
+.class public LC;
+.super Ljava/lang/Object;
+.implements Liface;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+.method public SayHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, Liface;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, " and welcome "
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/D.smali b/test/969-iface-super/smali/D.smali
new file mode 100644
index 0000000..ecd4629
--- /dev/null
+++ b/test/969-iface-super/smali/D.smali
@@ -0,0 +1,41 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class D implements iface2 {
+# public String SayHi() {
+# return iface2.super.SayHi() + " and welcome ";
+# }
+# }
+
+.class public LD;
+.super Ljava/lang/Object;
+.implements Liface2;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+.method public SayHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, Liface2;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, " and welcome "
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/E.smali b/test/969-iface-super/smali/E.smali
new file mode 100644
index 0000000..558aaea
--- /dev/null
+++ b/test/969-iface-super/smali/E.smali
@@ -0,0 +1,41 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class E implements iface3 {
+# public String SayHi() {
+# return iface3.super.SayHi() + " there!";
+# }
+# }
+
+.class public LE;
+.super Ljava/lang/Object;
+.implements Liface3;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+.method public SayHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, Liface3;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, " there!"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/F.smali b/test/969-iface-super/smali/F.smali
new file mode 100644
index 0000000..c402d5c
--- /dev/null
+++ b/test/969-iface-super/smali/F.smali
@@ -0,0 +1,40 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class F extends E {
+# public String SaySurprisedHi() {
+# return super.SayHi() + "!";
+# }
+# }
+
+.class public LF;
+.super LE;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, LE;-><init>()V
+ return-void
+.end method
+
+.method public SaySurprisedHi()Ljava/lang/String;
+ .registers 2
+ invoke-super {p0}, LE;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, "!"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/G.smali b/test/969-iface-super/smali/G.smali
new file mode 100644
index 0000000..45705e6
--- /dev/null
+++ b/test/969-iface-super/smali/G.smali
@@ -0,0 +1,53 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class G extends F {
+# public String SayHi() {
+# return super.SayHi() + "?";
+# }
+# public String SayVerySurprisedHi() {
+# return super.SaySurprisedHi() + "!";
+# }
+# }
+
+.class public LG;
+.super LF;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, LF;-><init>()V
+ return-void
+.end method
+
+.method public SayHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, LF;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, "?"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
+
+.method public SayVerySurprisedHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, LF;->SaySurprisedHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, "!"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/H.smali b/test/969-iface-super/smali/H.smali
new file mode 100644
index 0000000..12f246b
--- /dev/null
+++ b/test/969-iface-super/smali/H.smali
@@ -0,0 +1,66 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public class H extends A {
+# public String SayHi() {
+# return super.SayHi() + "?";
+# }
+# public String SaySurprisedHi() {
+# return super.SayHi() + "!";
+# }
+# public String SayConfusedHi() {
+# return SayHi() + "!";
+# }
+# }
+
+.class public LH;
+.super LA;
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {p0}, LA;-><init>()V
+ return-void
+.end method
+
+.method public SayHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, LA;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, "?"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
+
+.method public SaySurprisedHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, LA;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, "!"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
+
+.method public SayConfusedHi()Ljava/lang/String;
+ .locals 2
+ invoke-virtual {p0}, LH;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ const-string v1, "!"
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/classes.xml b/test/969-iface-super/smali/classes.xml
new file mode 100644
index 0000000..4d205bd
--- /dev/null
+++ b/test/969-iface-super/smali/classes.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2015 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.
+-->
+
+<data>
+ <classes>
+ <class name="A" super="java/lang/Object">
+ <implements>
+ <item>iface</item>
+ </implements>
+ <methods> </methods>
+ </class>
+
+ <class name="B" super="java/lang/Object">
+ <implements>
+ <item>iface2</item>
+ </implements>
+ <methods> </methods>
+ </class>
+
+ <class name="C" super="java/lang/Object">
+ <implements>
+ <item>iface</item>
+ </implements>
+ <methods> </methods>
+ </class>
+
+ <class name="D" super="java/lang/Object">
+ <implements>
+ <item>iface2</item>
+ </implements>
+ <methods> </methods>
+ </class>
+
+ <class name="E" super="java/lang/Object">
+ <implements>
+ <item>iface3</item>
+ </implements>
+ <methods> </methods>
+ </class>
+
+ <class name="F" super="E">
+ <implements> </implements>
+ <methods>
+ <item>SaySurprisedHi</item>
+ </methods>
+ </class>
+
+ <class name="G" super="F">
+ <implements> </implements>
+ <methods>
+ <item>SayVerySurprisedHi</item>
+ </methods>
+ </class>
+
+ <class name="H" super="A">
+ <implements> </implements>
+ <methods>
+ <item>SaySurprisedHi</item>
+ <item>SayConfusedHi</item>
+ </methods>
+ </class>
+ </classes>
+
+ <interfaces>
+ <interface name="iface" super="java/lang/Object">
+ <implements> </implements>
+ <methods>
+ <item>SayHi</item>
+ </methods>
+ </interface>
+
+ <interface name="iface2" super="java/lang/Object">
+ <implements>
+ <item>iface</item>
+ </implements>
+ <methods> </methods>
+ </interface>
+
+ <interface name="iface3" super="java/lang/Object">
+ <implements>
+ <item>iface</item>
+ </implements>
+ <methods> </methods>
+ </interface>
+ </interfaces>
+</data>
diff --git a/test/969-iface-super/smali/iface.smali b/test/969-iface-super/smali/iface.smali
new file mode 100644
index 0000000..08bb93d
--- /dev/null
+++ b/test/969-iface-super/smali/iface.smali
@@ -0,0 +1,30 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public interface iface {
+# public default String SayHi() {
+# return "Hello ";
+# }
+# }
+
+.class public abstract interface Liface;
+.super Ljava/lang/Object;
+
+.method public SayHi()Ljava/lang/String;
+ .locals 1
+ const-string v0, "Hello "
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/iface2.smali b/test/969-iface-super/smali/iface2.smali
new file mode 100644
index 0000000..ce6f864
--- /dev/null
+++ b/test/969-iface-super/smali/iface2.smali
@@ -0,0 +1,36 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public interface iface2 extends iface {
+# public default String SayHi() {
+# return iface.super.SayHi() + iface.super.SayHi();
+# }
+# }
+
+.class public abstract interface Liface2;
+.super Ljava/lang/Object;
+.implements Liface;
+
+.method public SayHi()Ljava/lang/String;
+ .locals 2
+ invoke-super {p0}, Liface;->SayHi()Ljava/lang/String;
+ move-result-object v0
+ invoke-super {p0}, Liface;->SayHi()Ljava/lang/String;
+ move-result-object v1
+ invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v0
+ return-object v0
+.end method
diff --git a/test/969-iface-super/smali/iface3.smali b/test/969-iface-super/smali/iface3.smali
new file mode 100644
index 0000000..bf20036
--- /dev/null
+++ b/test/969-iface-super/smali/iface3.smali
@@ -0,0 +1,22 @@
+# /*
+# * Copyright (C) 2015 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.
+# */
+#
+# public interface iface3 extends iface {
+# }
+
+.class public abstract interface Liface3;
+.super Ljava/lang/Object;
+.implements Liface;
diff --git a/test/970-iface-super-resolution-generated/build b/test/970-iface-super-resolution-generated/build
new file mode 100755
index 0000000..2d9830b
--- /dev/null
+++ b/test/970-iface-super-resolution-generated/build
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+
+# make us exit on a failure
+set -e
+
+# We will be making more files than the ulimit is set to allow. Remove it temporarily.
+OLD_ULIMIT=`ulimit -S`
+ulimit -S unlimited
+
+restore_ulimit() {
+ ulimit -S "$OLD_ULIMIT"
+}
+trap 'restore_ulimit' ERR
+
+# Should we compile with Java source code. By default we will use Smali.
+USES_JAVA_SOURCE="false"
+if [[ $@ == *"--jvm"* ]]; then
+ USES_JAVA_SOURCE="true"
+elif [[ "$USE_JACK" == "true" ]]; then
+ if $JACK -D jack.java.source.version=1.8 2>/dev/null; then
+ USES_JAVA_SOURCE="true"
+ else
+ echo "WARNING: Cannot use jack because it does not support JLS 1.8. Falling back to smali" >&2
+ fi
+fi
+
+if [[ "$USES_JAVA_SOURCE" == "true" ]]; then
+ # Build the Java files
+ mkdir -p src
+ mkdir -p src2
+ ./util-src/generate_java.py ./src2 ./src ./expected.txt
+else
+ # Generate the smali files and expected.txt or fail
+ mkdir -p smali
+ ./util-src/generate_smali.py ./smali ./expected.txt
+fi
+
+./default-build "$@" --experimental default-methods
+
+# Reset the ulimit back to its initial value
+restore_ulimit
diff --git a/test/970-iface-super-resolution-generated/expected.txt b/test/970-iface-super-resolution-generated/expected.txt
new file mode 100644
index 0000000..1ddd65d
--- /dev/null
+++ b/test/970-iface-super-resolution-generated/expected.txt
@@ -0,0 +1 @@
+This file is generated by util-src/generate_smali.py do not directly modify!
diff --git a/test/970-iface-super-resolution-generated/info.txt b/test/970-iface-super-resolution-generated/info.txt
new file mode 100644
index 0000000..2cd2cc7
--- /dev/null
+++ b/test/970-iface-super-resolution-generated/info.txt
@@ -0,0 +1,17 @@
+Smali-based tests for experimental interface default methods.
+
+This tests that interface method resolution order is correct.
+
+Obviously needs to run under ART or a Java 8 Language runtime and compiler.
+
+When run smali test files are generated by the util-src/generate_smali.py
+script. If we run with --jvm we will use the
+$(ANDROID_BUILD_TOP)/art/tools/extract-embedded-java script to turn the smali
+into equivalent Java using the embedded Java code.
+
+Care should be taken when updating the generate_smali.py script. It should always
+return equivalent output when run multiple times and the expected output should
+be valid.
+
+Do not modify the expected.txt file. It is generated on each run by
+util-src/generate_smali.py.
diff --git a/test/970-iface-super-resolution-generated/run b/test/970-iface-super-resolution-generated/run
new file mode 100755
index 0000000..6d2930d
--- /dev/null
+++ b/test/970-iface-super-resolution-generated/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+
+${RUN} "$@" --experimental default-methods
diff --git a/test/970-iface-super-resolution-generated/util-src/generate_java.py b/test/970-iface-super-resolution-generated/util-src/generate_java.py
new file mode 100755
index 0000000..c12f10d
--- /dev/null
+++ b/test/970-iface-super-resolution-generated/util-src/generate_java.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2015 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.
+
+"""
+Generate java test files for test 966.
+"""
+
+import generate_smali as base
+import os
+import sys
+from pathlib import Path
+
+BUILD_TOP = os.getenv("ANDROID_BUILD_TOP")
+if BUILD_TOP is None:
+ print("ANDROID_BUILD_TOP not set. Please run build/envsetup.sh", file=sys.stderr)
+ sys.exit(1)
+
+# Allow us to import mixins.
+sys.path.append(str(Path(BUILD_TOP)/"art"/"test"/"utils"/"python"))
+
+import testgen.mixins as mixins
+
+class JavaConverter(mixins.DumpMixin, mixins.Named, mixins.JavaFileMixin):
+ """
+ A class that can convert a SmaliFile to a JavaFile.
+ """
+ def __init__(self, inner):
+ self.inner = inner
+
+ def get_name(self):
+ return self.inner.get_name()
+
+ def __str__(self):
+ out = ""
+ for line in str(self.inner).splitlines(keepends = True):
+ if line.startswith("#"):
+ out += line[1:]
+ return out
+
+def main(argv):
+ final_java_dir = Path(argv[1])
+ if not final_java_dir.exists() or not final_java_dir.is_dir():
+ print("{} is not a valid java dir".format(final_java_dir), file=sys.stderr)
+ sys.exit(1)
+ initial_java_dir = Path(argv[2])
+ if not initial_java_dir.exists() or not initial_java_dir.is_dir():
+ print("{} is not a valid java dir".format(initial_java_dir), file=sys.stderr)
+ sys.exit(1)
+ expected_txt = Path(argv[3])
+ mainclass, all_files = base.create_all_test_files()
+ with expected_txt.open('w') as out:
+ print(mainclass.get_expected(), file=out)
+ for f in all_files:
+ if f.initial_build_different():
+ JavaConverter(f).dump(final_java_dir)
+ JavaConverter(f.get_initial_build_version()).dump(initial_java_dir)
+ else:
+ JavaConverter(f).dump(initial_java_dir)
+ if isinstance(f, base.TestInterface):
+ JavaConverter(f).dump(final_java_dir)
+
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/test/970-iface-super-resolution-generated/util-src/generate_smali.py b/test/970-iface-super-resolution-generated/util-src/generate_smali.py
new file mode 100755
index 0000000..cb7b0fa
--- /dev/null
+++ b/test/970-iface-super-resolution-generated/util-src/generate_smali.py
@@ -0,0 +1,614 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2015 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.
+
+"""
+Generate Smali test files for test 966.
+"""
+
+import os
+import sys
+from pathlib import Path
+
+BUILD_TOP = os.getenv("ANDROID_BUILD_TOP")
+if BUILD_TOP is None:
+ print("ANDROID_BUILD_TOP not set. Please run build/envsetup.sh", file=sys.stderr)
+ sys.exit(1)
+
+# Allow us to import utils and mixins.
+sys.path.append(str(Path(BUILD_TOP)/"art"/"test"/"utils"/"python"))
+
+from testgen.utils import get_copyright, subtree_sizes, gensym, filter_blanks
+import testgen.mixins as mixins
+
+from functools import total_ordering
+import itertools
+import string
+
+# The max depth the tree can have.
+MAX_IFACE_DEPTH = 3
+
+class MainClass(mixins.DumpMixin, mixins.Named, mixins.SmaliFileMixin):
+ """
+ A Main.smali file containing the Main class and the main function. It will run
+ all the test functions we have.
+ """
+
+ MAIN_CLASS_TEMPLATE = """{copyright}
+
+.class public LMain;
+.super Ljava/lang/Object;
+
+# class Main {{
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {{p0}}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+{test_groups}
+
+{main_func}
+
+# }}
+"""
+
+ MAIN_FUNCTION_TEMPLATE = """
+# public static void main(String[] args) {{
+.method public static main([Ljava/lang/String;)V
+ .locals 2
+
+ {test_group_invoke}
+
+ return-void
+.end method
+# }}
+"""
+
+ TEST_GROUP_INVOKE_TEMPLATE = """
+# {test_name}();
+ invoke-static {{}}, {test_name}()V
+"""
+
+ def __init__(self):
+ """
+ Initialize this MainClass. We start out with no tests.
+ """
+ self.tests = set()
+
+ def add_test(self, ty):
+ """
+ Add a test for the concrete type 'ty'
+ """
+ self.tests.add(Func(ty))
+
+ def get_expected(self):
+ """
+ Get the expected output of this test.
+ """
+ all_tests = sorted(self.tests)
+ return filter_blanks("\n".join(a.get_expected() for a in all_tests))
+
+ def initial_build_different(self):
+ return False
+
+ def get_name(self):
+ """
+ Gets the name of this class
+ """
+ return "Main"
+
+ def __str__(self):
+ """
+ Print the smali code for this test.
+ """
+ all_tests = sorted(self.tests)
+ test_invoke = ""
+ test_groups = ""
+ for t in all_tests:
+ test_groups += str(t)
+ for t in all_tests:
+ test_invoke += self.TEST_GROUP_INVOKE_TEMPLATE.format(test_name=t.get_name())
+ main_func = self.MAIN_FUNCTION_TEMPLATE.format(test_group_invoke=test_invoke)
+
+ return self.MAIN_CLASS_TEMPLATE.format(copyright = get_copyright('smali'),
+ test_groups = test_groups,
+ main_func = main_func)
+
+class Func(mixins.Named, mixins.NameComparableMixin):
+ """
+ A function that tests the functionality of a concrete type. Should only be
+ constructed by MainClass.add_test.
+ """
+
+ TEST_FUNCTION_TEMPLATE = """
+# public static void {fname}() {{
+# try {{
+# {farg} v = new {farg}();
+# System.out.println("Testing {tree}");
+# v.testAll();
+# System.out.println("Success: testing {tree}");
+# return;
+# }} catch (Exception e) {{
+# System.out.println("Failure: testing {tree}");
+# e.printStackTrace(System.out);
+# return;
+# }}
+# }}
+.method public static {fname}()V
+ .locals 7
+ :call_{fname}_try_start
+ sget-object v2, Ljava/lang/System;->out:Ljava/io/PrintStream;
+
+ new-instance v6, L{farg};
+ invoke-direct {{v6}}, L{farg};-><init>()V
+
+ const-string v3, "Testing {tree}"
+ invoke-virtual {{v2, v3}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+
+ invoke-virtual {{v6}}, L{farg};->testAll()V
+
+ const-string v3, "Success: testing {tree}"
+ invoke-virtual {{v2, v3}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+
+ return-void
+ :call_{fname}_try_end
+ .catch Ljava/lang/Exception; {{:call_{fname}_try_start .. :call_{fname}_try_end}} :error_{fname}_start
+ :error_{fname}_start
+ move-exception v3
+ sget-object v2, Ljava/lang/System;->out:Ljava/io/PrintStream;
+ const-string v4, "Failure: testing {tree}"
+ invoke-virtual {{v2, v3}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ invoke-virtual {{v3,v2}}, Ljava/lang/Error;->printStackTrace(Ljava/io/PrintStream;)V
+ return-void
+.end method
+"""
+
+ OUTPUT_FORMAT = """
+Testing {tree}
+{test_output}
+Success: testing {tree}
+""".strip()
+
+ def __init__(self, farg):
+ """
+ Initialize a test function for the given argument
+ """
+ self.farg = farg
+
+ def __str__(self):
+ """
+ Print the smali code for this test function.
+ """
+ return self.TEST_FUNCTION_TEMPLATE.format(fname = self.get_name(),
+ farg = self.farg.get_name(),
+ tree = self.farg.get_tree())
+
+ def get_name(self):
+ """
+ Gets the name of this test function
+ """
+ return "TEST_FUNC_{}".format(self.farg.get_name())
+
+ def get_expected(self):
+ """
+ Get the expected output of this function.
+ """
+ return self.OUTPUT_FORMAT.format(
+ tree = self.farg.get_tree(),
+ test_output = self.farg.get_test_output().strip())
+
+class TestClass(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.SmaliFileMixin):
+ """
+ A class that will be instantiated to test interface initialization order.
+ """
+
+ TEST_CLASS_TEMPLATE = """{copyright}
+
+.class public L{class_name};
+.super Ljava/lang/Object;
+{implements_spec}
+
+# public class {class_name} implements {ifaces} {{
+#
+# public {class_name}() {{
+# }}
+.method public constructor <init>()V
+ .locals 2
+ invoke-direct {{p0}}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+# public String getCalledInterface() {{
+# throw new Error("Should not be called");
+# }}
+.method public getCalledInterface()V
+ .locals 2
+ const-string v0, "Should not be called"
+ new-instance v1, Ljava/lang/Error;
+ invoke-direct {{v1, v0}}, Ljava/lang/Error;-><init>(Ljava/lang/String;)V
+ throw v1
+.end method
+
+# public void testAll() {{
+# boolean failed = false;
+# Error exceptions = new Error("Test failures");
+.method public testAll()V
+ .locals 5
+ const/4 v0, 0
+ const-string v1, "Test failures"
+ new-instance v2, Ljava/lang/Error;
+ invoke-direct {{v2, v1}}, Ljava/lang/Error;-><init>(Ljava/lang/String;)V
+
+ {test_calls}
+
+# if (failed) {{
+ if-eqz v0, :end
+# throw exceptions;
+ throw v2
+ :end
+# }}
+ return-void
+# }}
+.end method
+
+{test_funcs}
+
+# }}
+"""
+
+ IMPLEMENTS_TEMPLATE = """
+.implements L{iface_name};
+"""
+
+ TEST_CALL_TEMPLATE = """
+# try {{
+# test_{iface}_super();
+# }} catch (Throwable t) {{
+# exceptions.addSuppressed(t);
+# failed = true;
+# }}
+ :try_{iface}_start
+ invoke-virtual {{p0}}, L{class_name};->test_{iface}_super()V
+ goto :error_{iface}_end
+ :try_{iface}_end
+ .catch Ljava/lang/Throwable; {{:try_{iface}_start .. :try_{iface}_end}} :error_{iface}_start
+ :error_{iface}_start
+ move-exception v3
+ invoke-virtual {{v2, v3}}, Ljava/lang/Throwable;->addSuppressed(Ljava/lang/Throwable;)V
+ const/4 v0, 1
+ :error_{iface}_end
+"""
+
+ TEST_FUNC_TEMPLATE = """
+# public void test_{iface}_super() {{
+# try {{
+# System.out.println("{class_name} -> {iface}.super.getCalledInterface(): " +
+# {iface}.super.getCalledInterface());
+# }} catch (NoSuchMethodError e) {{
+# System.out.println("{class_name} -> {iface}.super.getCalledInterface(): NoSuchMethodError");
+# }} catch (IncompatibleClassChangeError e) {{
+# System.out.println("{class_name} -> {iface}.super.getCalledInterface(): IncompatibleClassChangeError");
+# }} catch (Throwable t) {{
+# System.out.println("{class_name} -> {iface}.super.getCalledInterface(): Unknown error occurred");
+# throw t;
+# }}
+# }}
+.method public test_{iface}_super()V
+ .locals 3
+ sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
+ :try_start
+ const-string v1, "{class_name} -> {iface}.super.getCalledInterface(): "
+ invoke-super {{p0}}, L{iface};->getCalledInterface()Ljava/lang/String;
+ move-result-object v2
+
+ invoke-virtual {{v1, v2}}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;
+ move-result-object v1
+
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+
+ return-void
+ :try_end
+ .catch Ljava/lang/NoSuchMethodError; {{:try_start .. :try_end}} :AME_catch
+ .catch Ljava/lang/IncompatibleClassChangeError; {{:try_start .. :try_end}} :ICCE_catch
+ .catch Ljava/lang/Throwable; {{:try_start .. :try_end}} :throwable_catch
+ :AME_catch
+ const-string v1, "{class_name} -> {iface}.super.getCalledInterface(): NoSuchMethodError"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ return-void
+ :ICCE_catch
+ const-string v1, "{class_name} -> {iface}.super.getCalledInterface(): IncompatibleClassChangeError"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ return-void
+ :throwable_catch
+ move-exception v2
+ const-string v1, "{class_name} -> {iface}.super.getCalledInterface(): Unknown error occurred"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ throw v2
+.end method
+""".strip()
+
+ OUTPUT_TEMPLATE = "{class_name} -> {iface}.super.getCalledInterface(): {result}"
+
+ def __init__(self, ifaces, name = None):
+ """
+ Initialize this test class which implements the given interfaces
+ """
+ self.ifaces = ifaces
+ if name is None:
+ self.class_name = "CLASS_"+gensym()
+ else:
+ self.class_name = name
+
+ def get_initial_build_version(self):
+ """
+ Returns a version of this class that can be used for the initial build (meaning no compiler
+ checks will be triggered).
+ """
+ return TestClass([i.get_initial_build_version() for i in self.ifaces], self.class_name)
+
+ def initial_build_different(self):
+ return False
+
+ def get_name(self):
+ """
+ Gets the name of this interface
+ """
+ return self.class_name
+
+ def get_tree(self):
+ """
+ Print out a representation of the type tree of this class
+ """
+ return "[{fname} {iftree}]".format(fname = self.get_name(), iftree = print_tree(self.ifaces))
+
+ def get_test_output(self):
+ return '\n'.join(map(lambda a: self.OUTPUT_TEMPLATE.format(class_name = self.get_name(),
+ iface = a.get_name(),
+ result = a.get_output()),
+ self.ifaces))
+
+ def __str__(self):
+ """
+ Print the smali code for this class.
+ """
+ funcs = '\n'.join(map(lambda a: self.TEST_FUNC_TEMPLATE.format(iface = a.get_name(),
+ class_name = self.get_name()),
+ self.ifaces))
+ calls = '\n'.join(map(lambda a: self.TEST_CALL_TEMPLATE.format(iface = a.get_name(),
+ class_name = self.get_name()),
+ self.ifaces))
+ s_ifaces = '\n'.join(map(lambda a: self.IMPLEMENTS_TEMPLATE.format(iface_name = a.get_name()),
+ self.ifaces))
+ j_ifaces = ', '.join(map(lambda a: a.get_name(), self.ifaces))
+ return self.TEST_CLASS_TEMPLATE.format(copyright = get_copyright('smali'),
+ implements_spec = s_ifaces,
+ ifaces = j_ifaces,
+ class_name = self.class_name,
+ test_funcs = funcs,
+ test_calls = calls)
+
+class IncompatibleClassChangeErrorResult(mixins.Named):
+ def get_name(self):
+ return "IncompatibleClassChangeError"
+
+ICCE = IncompatibleClassChangeErrorResult()
+
+class NoSuchMethodErrorResult(mixins.Named):
+ def get_name(self):
+ return "NoSuchMethodError"
+
+NSME = NoSuchMethodErrorResult()
+
+class TestInterface(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.SmaliFileMixin):
+ """
+ An interface that will be used to test default method resolution order.
+ """
+
+ TEST_INTERFACE_TEMPLATE = """{copyright}
+.class public abstract interface L{class_name};
+.super Ljava/lang/Object;
+{implements_spec}
+
+# public interface {class_name} {extends} {ifaces} {{
+
+{funcs}
+
+# }}
+"""
+
+ ABSTRACT_FUNC_TEMPLATE = """
+"""
+
+ DEFAULT_FUNC_TEMPLATE = """
+# public default String getCalledInterface() {{
+# return "{class_name}";
+# }}
+.method public getCalledInterface()Ljava/lang/String;
+ .locals 1
+ const-string v0, "{class_name}"
+ return-object v0
+.end method
+"""
+
+ IMPLEMENTS_TEMPLATE = """
+.implements L{iface_name};
+"""
+
+ def __init__(self, ifaces, default, name = None):
+ """
+ Initialize interface with the given super-interfaces
+ """
+ self.ifaces = ifaces
+ self.default = default
+ if name is None:
+ end = "_DEFAULT" if default else ""
+ self.class_name = "INTERFACE_"+gensym()+end
+ else:
+ self.class_name = name
+
+ def get_initial_build_version(self):
+ """
+ Returns a version of this class that can be used for the initial build (meaning no compiler
+ checks will be triggered).
+ """
+ return TestInterface([i.get_initial_build_version() for i in self.ifaces],
+ True,
+ self.class_name)
+
+ def initial_build_different(self):
+ return not self.default
+
+ def get_name(self):
+ """
+ Gets the name of this interface
+ """
+ return self.class_name
+
+ def __iter__(self):
+ """
+ Performs depth-first traversal of the interface tree this interface is the
+ root of. Does not filter out repeats.
+ """
+ for i in self.ifaces:
+ yield i
+ yield from i
+
+ def get_called(self):
+ """
+ Get the interface whose default method would be called when calling the
+ CalledInterfaceName function.
+ """
+ all_ifaces = set(iface for iface in self if iface.default)
+ for i in all_ifaces:
+ if all(map(lambda j: i not in j.get_super_types(), all_ifaces)):
+ return i
+ return ICCE if any(map(lambda i: i.default, all_ifaces)) else NSME
+
+ def get_super_types(self):
+ """
+ Returns a set of all the supertypes of this interface
+ """
+ return set(i2 for i2 in self)
+
+ def get_output(self):
+ if self.default:
+ return self.get_name()
+ else:
+ return self.get_called().get_name()
+
+ def get_tree(self):
+ """
+ Print out a representation of the type tree of this class
+ """
+ return "[{class_name} {iftree}]".format(class_name = self.get_name(),
+ iftree = print_tree(self.ifaces))
+ def __str__(self):
+ """
+ Print the smali code for this interface.
+ """
+ s_ifaces = '\n'.join(map(lambda a: self.IMPLEMENTS_TEMPLATE.format(iface_name = a.get_name()),
+ self.ifaces))
+ j_ifaces = ', '.join(map(lambda a: a.get_name(), self.ifaces))
+ if self.default:
+ funcs = self.DEFAULT_FUNC_TEMPLATE.format(class_name = self.class_name)
+ else:
+ funcs = self.ABSTRACT_FUNC_TEMPLATE
+ return self.TEST_INTERFACE_TEMPLATE.format(copyright = get_copyright('smali'),
+ implements_spec = s_ifaces,
+ extends = "extends" if len(self.ifaces) else "",
+ ifaces = j_ifaces,
+ funcs = funcs,
+ class_name = self.class_name)
+
+def dump_tree(ifaces):
+ """
+ Yields all the interfaces transitively implemented by the set in
+ reverse-depth-first order
+ """
+ for i in ifaces:
+ yield from dump_tree(i.ifaces)
+ yield i
+
+def print_tree(ifaces):
+ """
+ Prints the tree for the given ifaces.
+ """
+ return " ".join(i.get_tree() for i in ifaces)
+
+# Cached output of subtree_sizes for speed of access.
+SUBTREES = [set(tuple(sorted(l)) for l in subtree_sizes(i)) for i in range(MAX_IFACE_DEPTH + 1)]
+
+def create_test_classes():
+ """
+ Yield all the test classes with the different interface trees
+ """
+ for num in range(1, MAX_IFACE_DEPTH + 1):
+ for split in SUBTREES[num]:
+ ifaces = []
+ for sub in split:
+ ifaces.append(list(create_interface_trees(sub)))
+ for supers in itertools.product(*ifaces):
+ yield TestClass(supers)
+
+def create_interface_trees(num):
+ """
+ Yield all the interface trees up to 'num' depth.
+ """
+ if num == 0:
+ yield TestInterface(tuple(), False)
+ yield TestInterface(tuple(), True)
+ return
+ for split in SUBTREES[num]:
+ ifaces = []
+ for sub in split:
+ ifaces.append(list(create_interface_trees(sub)))
+ for supers in itertools.product(*ifaces):
+ yield TestInterface(supers, False)
+ yield TestInterface(supers, True)
+ for selected in (set(dump_tree(supers)) - set(supers)):
+ yield TestInterface(tuple([selected] + list(supers)), True)
+ yield TestInterface(tuple([selected] + list(supers)), False)
+ # TODO Should add on some from higher up the tree.
+
+def create_all_test_files():
+ """
+ Creates all the objects representing the files in this test. They just need to
+ be dumped.
+ """
+ mc = MainClass()
+ classes = {mc}
+ for clazz in create_test_classes():
+ classes.add(clazz)
+ for i in dump_tree(clazz.ifaces):
+ classes.add(i)
+ mc.add_test(clazz)
+ return mc, classes
+
+def main(argv):
+ smali_dir = Path(argv[1])
+ if not smali_dir.exists() or not smali_dir.is_dir():
+ print("{} is not a valid smali dir".format(smali_dir), file=sys.stderr)
+ sys.exit(1)
+ expected_txt = Path(argv[2])
+ mainclass, all_files = create_all_test_files()
+ with expected_txt.open('w') as out:
+ print(mainclass.get_expected(), file=out)
+ for f in all_files:
+ f.dump(smali_dir)
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/test/971-iface-super-partial-compile-generated/build b/test/971-iface-super-partial-compile-generated/build
new file mode 100755
index 0000000..1e9f8aa
--- /dev/null
+++ b/test/971-iface-super-partial-compile-generated/build
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+
+# make us exit on a failure
+set -e
+
+# We will be making more files than the ulimit is set to allow. Remove it temporarily.
+OLD_ULIMIT=`ulimit -S`
+ulimit -S unlimited
+
+restore_ulimit() {
+ ulimit -S "$OLD_ULIMIT"
+}
+trap 'restore_ulimit' ERR
+
+# TODO: Support running with jack.
+
+if [[ $@ == *"--jvm"* ]]; then
+ # Build the Java files if we are running a --jvm test
+ mkdir -p classes
+ mkdir -p src
+ echo "${JAVAC} \$@" >> ./javac_exec.sh
+ # This will use java_exec.sh to execute the javac compiler. It will place the
+ # compiled class files in ./classes and the expected values in expected.txt
+ #
+ # After this the src directory will contain the final versions of all files.
+ ./util-src/generate_java.py ./javac_exec.sh ./src ./classes ./expected.txt ./build_log
+else
+ mkdir -p ./smali
+ # Generate the smali files and expected.txt or fail
+ ./util-src/generate_smali.py ./smali ./expected.txt
+ # Use the default build script
+ ./default-build "$@" "$EXTRA_ARGS" --experimental default-methods
+fi
+
+# Reset the ulimit back to its initial value
+restore_ulimit
diff --git a/test/971-iface-super-partial-compile-generated/expected.txt b/test/971-iface-super-partial-compile-generated/expected.txt
new file mode 100644
index 0000000..1ddd65d
--- /dev/null
+++ b/test/971-iface-super-partial-compile-generated/expected.txt
@@ -0,0 +1 @@
+This file is generated by util-src/generate_smali.py do not directly modify!
diff --git a/test/971-iface-super-partial-compile-generated/info.txt b/test/971-iface-super-partial-compile-generated/info.txt
new file mode 100644
index 0000000..bc1c428
--- /dev/null
+++ b/test/971-iface-super-partial-compile-generated/info.txt
@@ -0,0 +1,17 @@
+Smali-based tests for experimental interface default methods.
+
+This tests that interface method resolution order is correct in the presence of
+partial compilation/illegal invokes.
+
+Obviously needs to run under ART or a Java 8 Language runtime and compiler.
+
+When run smali test files are generated by the util-src/generate_smali.py
+script. If we run with --jvm we will use the util-src/generate_java.py script
+will generate equivalent java code based on the smali code.
+
+Care should be taken when updating the generate_smali.py script. It should always
+return equivalent output when run multiple times and the expected output should
+be valid.
+
+Do not modify the expected.txt file. It is generated on each run by
+util-src/generate_smali.py.
diff --git a/test/971-iface-super-partial-compile-generated/run b/test/971-iface-super-partial-compile-generated/run
new file mode 100755
index 0000000..6d2930d
--- /dev/null
+++ b/test/971-iface-super-partial-compile-generated/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+
+${RUN} "$@" --experimental default-methods
diff --git a/test/971-iface-super-partial-compile-generated/util-src/generate_java.py b/test/971-iface-super-partial-compile-generated/util-src/generate_java.py
new file mode 100755
index 0000000..99b0479
--- /dev/null
+++ b/test/971-iface-super-partial-compile-generated/util-src/generate_java.py
@@ -0,0 +1,138 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2015 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.
+
+"""
+Generate java test files for test 966.
+"""
+
+import generate_smali as base
+import os
+import sys
+from pathlib import Path
+
+BUILD_TOP = os.getenv("ANDROID_BUILD_TOP")
+if BUILD_TOP is None:
+ print("ANDROID_BUILD_TOP not set. Please run build/envsetup.sh", file=sys.stderr)
+ sys.exit(1)
+
+# Allow us to import mixins.
+sys.path.append(str(Path(BUILD_TOP)/"art"/"test"/"utils"/"python"))
+
+import testgen.mixins as mixins
+import functools
+import operator
+import subprocess
+
+class JavaConverter(mixins.DumpMixin, mixins.Named, mixins.JavaFileMixin):
+ """
+ A class that can convert a SmaliFile to a JavaFile.
+ """
+ def __init__(self, inner):
+ self.inner = inner
+
+ def get_name(self):
+ """Gets the name of this file."""
+ return self.inner.get_name()
+
+ def __str__(self):
+ out = ""
+ for line in str(self.inner).splitlines(keepends = True):
+ if line.startswith("#"):
+ out += line[1:]
+ return out
+
+class Compiler:
+ def __init__(self, sources, javac, temp_dir, classes_dir):
+ self.javac = javac
+ self.temp_dir = temp_dir
+ self.classes_dir = classes_dir
+ self.sources = sources
+
+ def compile_files(self, args, files):
+ """
+ Compile the files given with the arguments given.
+ """
+ args = args.split()
+ files = list(map(str, files))
+ cmd = ['sh', '-a', '-e', '--', str(self.javac)] + args + files
+ print("Running compile command: {}".format(cmd))
+ subprocess.check_call(cmd)
+ print("Compiled {} files".format(len(files)))
+
+ def execute(self):
+ """
+ Compiles this test, doing partial compilation as necessary.
+ """
+ # Compile Main and all classes first. Force all interfaces to be default so that there will be
+ # no compiler problems (works since classes only implement 1 interface).
+ for f in self.sources:
+ if isinstance(f, base.TestInterface):
+ JavaConverter(f.get_specific_version(base.InterfaceType.default)).dump(self.temp_dir)
+ else:
+ JavaConverter(f).dump(self.temp_dir)
+ self.compile_files("-d {}".format(self.classes_dir), self.temp_dir.glob("*.java"))
+
+ # Now we compile the interfaces
+ ifaces = set(i for i in self.sources if isinstance(i, base.TestInterface))
+ filters = (lambda a: a.is_default(), lambda a: not a.is_default())
+ converters = (lambda a: JavaConverter(a.get_specific_version(base.InterfaceType.default)),
+ lambda a: JavaConverter(a.get_specific_version(base.InterfaceType.empty)))
+ while len(ifaces) != 0:
+ for iface_filter, iface_converter in zip(filters, converters):
+ # Find those ifaces where there are no (uncompiled) interfaces that are subtypes.
+ tops = set(filter(lambda a: iface_filter(a) and not any(map(lambda i: a in i.get_super_types(), ifaces)), ifaces))
+ files = []
+ # Dump these ones, they are getting compiled.
+ for f in tops:
+ out = JavaConverter(f)
+ out.dump(self.temp_dir)
+ files.append(self.temp_dir / out.get_file_name())
+ # Force all superinterfaces of these to be empty so there will be no conflicts
+ overrides = functools.reduce(operator.or_, map(lambda i: i.get_super_types(), tops), set())
+ for overridden in overrides:
+ out = iface_converter(overridden)
+ out.dump(self.temp_dir)
+ files.append(self.temp_dir / out.get_file_name())
+ self.compile_files("-d {outdir} -cp {outdir}".format(outdir = self.classes_dir), files)
+ # Remove these from the set of interfaces to be compiled.
+ ifaces -= tops
+ print("Finished compiling all files.")
+ return
+
+def main(argv):
+ javac_exec = Path(argv[1])
+ if not javac_exec.exists() or not javac_exec.is_file():
+ print("{} is not a shell script".format(javac_exec), file=sys.stderr)
+ sys.exit(1)
+ temp_dir = Path(argv[2])
+ if not temp_dir.exists() or not temp_dir.is_dir():
+ print("{} is not a valid source dir".format(temp_dir), file=sys.stderr)
+ sys.exit(1)
+ classes_dir = Path(argv[3])
+ if not classes_dir.exists() or not classes_dir.is_dir():
+ print("{} is not a valid classes directory".format(classes_dir), file=sys.stderr)
+ sys.exit(1)
+ expected_txt = Path(argv[4])
+ mainclass, all_files = base.create_all_test_files()
+
+ with expected_txt.open('w') as out:
+ print(mainclass.get_expected(), file=out)
+ print("Wrote expected output")
+
+ Compiler(all_files, javac_exec, temp_dir, classes_dir).execute()
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/test/971-iface-super-partial-compile-generated/util-src/generate_smali.py b/test/971-iface-super-partial-compile-generated/util-src/generate_smali.py
new file mode 100755
index 0000000..f01c904
--- /dev/null
+++ b/test/971-iface-super-partial-compile-generated/util-src/generate_smali.py
@@ -0,0 +1,689 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2015 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.
+
+"""
+Generate Smali test files for test 967.
+"""
+
+import os
+import sys
+from pathlib import Path
+
+BUILD_TOP = os.getenv("ANDROID_BUILD_TOP")
+if BUILD_TOP is None:
+ print("ANDROID_BUILD_TOP not set. Please run build/envsetup.sh", file=sys.stderr)
+ sys.exit(1)
+
+# Allow us to import utils and mixins.
+sys.path.append(str(Path(BUILD_TOP)/"art"/"test"/"utils"/"python"))
+
+from testgen.utils import get_copyright, subtree_sizes, gensym, filter_blanks
+import testgen.mixins as mixins
+
+from enum import Enum
+from functools import total_ordering
+import itertools
+import string
+
+# The max depth the type tree can have.
+MAX_IFACE_DEPTH = 3
+
+class MainClass(mixins.DumpMixin, mixins.Named, mixins.SmaliFileMixin):
+ """
+ A Main.smali file containing the Main class and the main function. It will run
+ all the test functions we have.
+ """
+
+ MAIN_CLASS_TEMPLATE = """{copyright}
+
+.class public LMain;
+.super Ljava/lang/Object;
+
+# class Main {{
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {{p0}}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+{test_funcs}
+
+{main_func}
+
+# }}
+"""
+
+ MAIN_FUNCTION_TEMPLATE = """
+# public static void main(String[] args) {{
+.method public static main([Ljava/lang/String;)V
+ .locals 0
+
+ {test_group_invoke}
+
+ return-void
+.end method
+# }}
+"""
+
+ TEST_GROUP_INVOKE_TEMPLATE = """
+# {test_name}();
+ invoke-static {{}}, {test_name}()V
+"""
+
+ def __init__(self):
+ """
+ Initialize this MainClass. We start out with no tests.
+ """
+ self.tests = set()
+
+ def get_expected(self):
+ """
+ Get the expected output of this test.
+ """
+ all_tests = sorted(self.tests)
+ return filter_blanks("\n".join(a.get_expected() for a in all_tests))
+
+ def add_test(self, ty):
+ """
+ Add a test for the concrete type 'ty'
+ """
+ self.tests.add(Func(ty))
+
+ def get_name(self):
+ """
+ Get the name of this class
+ """
+ return "Main"
+
+ def __str__(self):
+ """
+ Print the MainClass smali code.
+ """
+ all_tests = sorted(self.tests)
+ test_invoke = ""
+ test_funcs = ""
+ for t in all_tests:
+ test_funcs += str(t)
+ for t in all_tests:
+ test_invoke += self.TEST_GROUP_INVOKE_TEMPLATE.format(test_name=t.get_name())
+ main_func = self.MAIN_FUNCTION_TEMPLATE.format(test_group_invoke=test_invoke)
+
+ return self.MAIN_CLASS_TEMPLATE.format(copyright = get_copyright("smali"),
+ test_funcs = test_funcs,
+ main_func = main_func)
+
+class Func(mixins.Named, mixins.NameComparableMixin):
+ """
+ A function that tests the functionality of a concrete type. Should only be
+ constructed by MainClass.add_test.
+ """
+
+ TEST_FUNCTION_TEMPLATE = """
+# public static void {fname}() {{
+# {farg} v = null;
+# try {{
+# v = new {farg}();
+# }} catch (Throwable e) {{
+# System.out.println("Unexpected error occurred which creating {farg} instance");
+# e.printStackTrace(System.out);
+# return;
+# }}
+# try {{
+# v.callSupers();
+# return;
+# }} catch (Throwable e) {{
+# e.printStackTrace(System.out);
+# return;
+# }}
+# }}
+.method public static {fname}()V
+ .locals 7
+ sget-object v4, Ljava/lang/System;->out:Ljava/io/PrintStream;
+
+ :new_{fname}_try_start
+ new-instance v0, L{farg};
+ invoke-direct {{v0}}, L{farg};-><init>()V
+ goto :call_{fname}_try_start
+ :new_{fname}_try_end
+ .catch Ljava/lang/Throwable; {{:new_{fname}_try_start .. :new_{fname}_try_end}} :new_error_{fname}_start
+ :new_error_{fname}_start
+ move-exception v6
+ const-string v5, "Unexpected error occurred which creating {farg} instance"
+ invoke-virtual {{v4,v5}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ invoke-virtual {{v6,v4}}, Ljava/lang/Throwable;->printStackTrace(Ljava/io/PrintStream;)V
+ return-void
+ :call_{fname}_try_start
+ invoke-virtual {{v0}}, L{farg};->callSupers()V
+ return-void
+ :call_{fname}_try_end
+ .catch Ljava/lang/Throwable; {{:call_{fname}_try_start .. :call_{fname}_try_end}} :error_{fname}_start
+ :error_{fname}_start
+ move-exception v6
+ invoke-virtual {{v6,v4}}, Ljava/lang/Throwable;->printStackTrace(Ljava/io/PrintStream;)V
+ return-void
+.end method
+"""
+
+ def __init__(self, farg):
+ """
+ Initialize a test function for the given argument
+ """
+ self.farg = farg
+
+ def get_expected(self):
+ """
+ Get the expected output calling this function.
+ """
+ return "\n".join(self.farg.get_expected())
+
+ def get_name(self):
+ """
+ Get the name of this function
+ """
+ return "TEST_FUNC_{}".format(self.farg.get_name())
+
+ def __str__(self):
+ """
+ Print the smali code of this function.
+ """
+ return self.TEST_FUNCTION_TEMPLATE.format(fname = self.get_name(),
+ farg = self.farg.get_name())
+
+class InterfaceCallResponse(Enum):
+ """
+ An enumeration of all the different types of responses to an interface call we can have
+ """
+ NoError = 0
+ NoSuchMethodError = 1
+ AbstractMethodError = 2
+ IncompatibleClassChangeError = 3
+
+ def get_output_format(self):
+ if self == InterfaceCallResponse.NoError:
+ return "No exception thrown for {iface_name}.super.call() on {tree}\n"
+ elif self == InterfaceCallResponse.AbstractMethodError:
+ return "AbstractMethodError thrown for {iface_name}.super.call() on {tree}\n"
+ elif self == InterfaceCallResponse.NoSuchMethodError:
+ return "NoSuchMethodError thrown for {iface_name}.super.call() on {tree}\n"
+ else:
+ return "IncompatibleClassChangeError thrown for {iface_name}.super.call() on {tree}\n"
+
+class TestClass(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.SmaliFileMixin):
+ """
+ A class that will be instantiated to test interface super behavior.
+ """
+
+ TEST_CLASS_TEMPLATE = """{copyright}
+
+.class public L{class_name};
+.super Ljava/lang/Object;
+{implements_spec}
+
+# public class {class_name} implements {ifaces} {{
+
+.method public constructor <init>()V
+ .registers 1
+ invoke-direct {{p0}}, Ljava/lang/Object;-><init>()V
+ return-void
+.end method
+
+# public void call() {{
+# throw new Error("{class_name}.call(v) should never get called!");
+# }}
+.method public call()V
+ .locals 2
+ new-instance v0, Ljava/lang/Error;
+ const-string v1, "{class_name}.call(v) should never get called!"
+ invoke-direct {{v0, v1}}, Ljava/lang/Error;-><init>(Ljava/lang/String;)V
+ throw v0
+.end method
+
+# public void callSupers() {{
+.method public callSupers()V
+ .locals 4
+ sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
+
+ {super_calls}
+
+ return-void
+.end method
+# }}
+
+# }}
+"""
+ SUPER_CALL_TEMPLATE = """
+# try {{
+# System.out.println("Calling {iface_name}.super.call() on {tree}");
+# {iface_name}.super.call();
+# System.out.println("No exception thrown for {iface_name}.super.call() on {tree}");
+# }} catch (AbstractMethodError ame) {{
+# System.out.println("AbstractMethodError thrown for {iface_name}.super.call() on {tree}");
+# }} catch (NoSuchMethodError nsme) {{
+# System.out.println("NoSuchMethodError thrown for {iface_name}.super.call() on {tree}");
+# }} catch (IncompatibleClassChangeError icce) {{
+# System.out.println("IncompatibleClassChangeError thrown for {iface_name}.super.call() on {tree}");
+# }} catch (Throwable t) {{
+# System.out.println("Unknown error thrown for {iface_name}.super.call() on {tree}");
+# throw t;
+# }}
+ :call_{class_name}_{iface_name}_try_start
+ const-string v1, "Calling {iface_name}.super.call() on {tree}"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ invoke-super {{p0}}, L{iface_name};->call()V
+ const-string v1, "No exception thrown for {iface_name}.super.call() on {tree}"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ goto :call_{class_name}_{iface_name}_end
+ :call_{class_name}_{iface_name}_try_end
+ .catch Ljava/lang/AbstractMethodError; {{:call_{class_name}_{iface_name}_try_start .. :call_{class_name}_{iface_name}_try_end}} :AME_{class_name}_{iface_name}_start
+ .catch Ljava/lang/NoSuchMethodError; {{:call_{class_name}_{iface_name}_try_start .. :call_{class_name}_{iface_name}_try_end}} :NSME_{class_name}_{iface_name}_start
+ .catch Ljava/lang/IncompatibleClassChangeError; {{:call_{class_name}_{iface_name}_try_start .. :call_{class_name}_{iface_name}_try_end}} :ICCE_{class_name}_{iface_name}_start
+ .catch Ljava/lang/Throwable; {{:call_{class_name}_{iface_name}_try_start .. :call_{class_name}_{iface_name}_try_end}} :error_{class_name}_{iface_name}_start
+ :AME_{class_name}_{iface_name}_start
+ const-string v1, "AbstractMethodError thrown for {iface_name}.super.call() on {tree}"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ goto :call_{class_name}_{iface_name}_end
+ :NSME_{class_name}_{iface_name}_start
+ const-string v1, "NoSuchMethodError thrown for {iface_name}.super.call() on {tree}"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ goto :call_{class_name}_{iface_name}_end
+ :ICCE_{class_name}_{iface_name}_start
+ const-string v1, "IncompatibleClassChangeError thrown for {iface_name}.super.call() on {tree}"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ goto :call_{class_name}_{iface_name}_end
+ :error_{class_name}_{iface_name}_start
+ move-exception v2
+ const-string v1, "Unknown error thrown for {iface_name}.super.call() on {tree}"
+ invoke-virtual {{v0, v1}}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
+ throw v2
+ :call_{class_name}_{iface_name}_end
+"""
+
+ IMPLEMENTS_TEMPLATE = """
+.implements L{iface_name};
+"""
+
+ OUTPUT_PREFIX = "Calling {iface_name}.super.call() on {tree}\n"
+
+ def __init__(self, ifaces):
+ """
+ Initialize this test class which implements the given interfaces
+ """
+ self.ifaces = ifaces
+ self.class_name = "CLASS_"+gensym()
+
+ def get_name(self):
+ """
+ Get the name of this class
+ """
+ return self.class_name
+
+ def get_tree(self):
+ """
+ Print out a representation of the type tree of this class
+ """
+ return "[{class_name} {iface_tree}]".format(class_name = self.class_name,
+ iface_tree = print_tree(self.ifaces))
+
+ def __iter__(self):
+ """
+ Step through all interfaces implemented transitively by this class
+ """
+ for i in self.ifaces:
+ yield i
+ yield from i
+
+ def get_expected(self):
+ for iface in self.ifaces:
+ yield self.OUTPUT_PREFIX.format(iface_name = iface.get_name(), tree = self.get_tree())
+ yield from iface.get_expected()
+ yield iface.get_response().get_output_format().format(iface_name = iface.get_name(),
+ tree = self.get_tree())
+
+ def __str__(self):
+ """
+ Print the smali code of this class.
+ """
+ s_ifaces = '\n'.join(map(lambda a: self.IMPLEMENTS_TEMPLATE.format(iface_name = a.get_name()),
+ self.ifaces))
+ j_ifaces = ', '.join(map(lambda a: a.get_name(), self.ifaces))
+ super_template = self.SUPER_CALL_TEMPLATE
+ super_calls = "\n".join(super_template.format(iface_name = iface.get_name(),
+ class_name = self.get_name(),
+ tree = self.get_tree()) for iface in self.ifaces)
+ return self.TEST_CLASS_TEMPLATE.format(copyright = get_copyright('smali'),
+ ifaces = j_ifaces,
+ implements_spec = s_ifaces,
+ tree = self.get_tree(),
+ class_name = self.class_name,
+ super_calls = super_calls)
+
+class InterfaceType(Enum):
+ """
+ An enumeration of all the different types of interfaces we can have.
+
+ default: It has a default method
+ abstract: It has a method declared but not defined
+ empty: It does not have the method
+ """
+ default = 0
+ abstract = 1
+ empty = 2
+
+ def get_suffix(self):
+ if self == InterfaceType.default:
+ return "_DEFAULT"
+ elif self == InterfaceType.abstract:
+ return "_ABSTRACT"
+ elif self == InterfaceType.empty:
+ return "_EMPTY"
+ else:
+ raise TypeError("Interface type had illegal value.")
+
+class ConflictInterface:
+ """
+ A singleton representing a conflict of default methods.
+ """
+
+ def is_conflict(self):
+ """
+ Returns true if this is a conflict interface and calling the method on this interface will
+ result in an IncompatibleClassChangeError.
+ """
+ return True
+
+ def is_abstract(self):
+ """
+ Returns true if this is an abstract interface and calling the method on this interface will
+ result in an AbstractMethodError.
+ """
+ return False
+
+ def is_empty(self):
+ """
+ Returns true if this is an abstract interface and calling the method on this interface will
+ result in a NoSuchMethodError.
+ """
+ return False
+
+ def is_default(self):
+ """
+ Returns true if this is a default interface and calling the method on this interface will
+ result in a method actually being called.
+ """
+ return False
+
+ def get_response(self):
+ return InterfaceCallResponse.IncompatibleClassChangeError
+
+CONFLICT_TYPE = ConflictInterface()
+
+class TestInterface(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, mixins.SmaliFileMixin):
+ """
+ An interface that will be used to test default method resolution order.
+ """
+
+ TEST_INTERFACE_TEMPLATE = """{copyright}
+.class public abstract interface L{class_name};
+.super Ljava/lang/Object;
+{implements_spec}
+
+# public interface {class_name} {extends} {ifaces} {{
+
+{func}
+
+# }}
+"""
+
+ SUPER_CALL_TEMPLATE = TestClass.SUPER_CALL_TEMPLATE
+ OUTPUT_PREFIX = TestClass.OUTPUT_PREFIX
+
+ DEFAULT_FUNC_TEMPLATE = """
+# public default void call() {{
+.method public call()V
+ .locals 4
+ sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
+
+ {super_calls}
+
+ return-void
+.end method
+# }}
+"""
+
+ ABSTRACT_FUNC_TEMPLATE = """
+# public void call();
+.method public abstract call()V
+.end method
+"""
+
+ EMPTY_FUNC_TEMPLATE = """"""
+
+ IMPLEMENTS_TEMPLATE = """
+.implements L{iface_name};
+"""
+
+ def __init__(self, ifaces, iface_type, full_name = None):
+ """
+ Initialize interface with the given super-interfaces
+ """
+ self.ifaces = sorted(ifaces)
+ self.iface_type = iface_type
+ if full_name is None:
+ end = self.iface_type.get_suffix()
+ self.class_name = "INTERFACE_"+gensym()+end
+ else:
+ self.class_name = full_name
+
+ def get_specific_version(self, v):
+ """
+ Returns a copy of this interface of the given type for use in partial compilation.
+ """
+ return TestInterface(self.ifaces, v, full_name = self.class_name)
+
+ def get_super_types(self):
+ """
+ Returns a set of all the supertypes of this interface
+ """
+ return set(i2 for i2 in self)
+
+ def is_conflict(self):
+ """
+ Returns true if this is a conflict interface and calling the method on this interface will
+ result in an IncompatibleClassChangeError.
+ """
+ return False
+
+ def is_abstract(self):
+ """
+ Returns true if this is an abstract interface and calling the method on this interface will
+ result in an AbstractMethodError.
+ """
+ return self.iface_type == InterfaceType.abstract
+
+ def is_empty(self):
+ """
+ Returns true if this is an abstract interface and calling the method on this interface will
+ result in a NoSuchMethodError.
+ """
+ return self.iface_type == InterfaceType.empty
+
+ def is_default(self):
+ """
+ Returns true if this is a default interface and calling the method on this interface will
+ result in a method actually being called.
+ """
+ return self.iface_type == InterfaceType.default
+
+ def get_expected(self):
+ response = self.get_response()
+ if response == InterfaceCallResponse.NoError:
+ for iface in self.ifaces:
+ if self.is_default():
+ yield self.OUTPUT_PREFIX.format(iface_name = iface.get_name(), tree = self.get_tree())
+ yield from iface.get_expected()
+ if self.is_default():
+ yield iface.get_response().get_output_format().format(iface_name = iface.get_name(),
+ tree = self.get_tree())
+
+ def get_response(self):
+ if self.is_default():
+ return InterfaceCallResponse.NoError
+ elif self.is_abstract():
+ return InterfaceCallResponse.AbstractMethodError
+ elif len(self.ifaces) == 0:
+ return InterfaceCallResponse.NoSuchMethodError
+ else:
+ return self.get_called().get_response()
+
+ def get_called(self):
+ """
+ Returns the interface that will be called when the method on this class is invoked or
+ CONFLICT_TYPE if there is no interface that will be called.
+ """
+ if not self.is_empty() or len(self.ifaces) == 0:
+ return self
+ else:
+ best = self
+ for super_iface in self.ifaces:
+ super_best = super_iface.get_called()
+ if super_best.is_conflict():
+ return CONFLICT_TYPE
+ elif best.is_default():
+ if super_best.is_default():
+ return CONFLICT_TYPE
+ elif best.is_abstract():
+ if super_best.is_default():
+ best = super_best
+ else:
+ assert best.is_empty()
+ best = super_best
+ return best
+
+ def get_name(self):
+ """
+ Get the name of this class
+ """
+ return self.class_name
+
+ def get_tree(self):
+ """
+ Print out a representation of the type tree of this class
+ """
+ return "[{class_name} {iftree}]".format(class_name = self.get_name(),
+ iftree = print_tree(self.ifaces))
+
+ def __iter__(self):
+ """
+ Performs depth-first traversal of the interface tree this interface is the
+ root of. Does not filter out repeats.
+ """
+ for i in self.ifaces:
+ yield i
+ yield from i
+
+ def __str__(self):
+ """
+ Print the smali code of this interface.
+ """
+ s_ifaces = '\n'.join(map(lambda a: self.IMPLEMENTS_TEMPLATE.format(iface_name = a.get_name()),
+ self.ifaces))
+ j_ifaces = ', '.join(map(lambda a: a.get_name(), self.ifaces))
+ if self.is_default():
+ super_template = self.SUPER_CALL_TEMPLATE
+ super_calls ="\n".join(super_template.format(iface_name = iface.get_name(),
+ class_name = self.get_name(),
+ tree = self.get_tree()) for iface in self.ifaces)
+ funcs = self.DEFAULT_FUNC_TEMPLATE.format(super_calls = super_calls)
+ elif self.is_abstract():
+ funcs = self.ABSTRACT_FUNC_TEMPLATE.format()
+ else:
+ funcs = ""
+ return self.TEST_INTERFACE_TEMPLATE.format(copyright = get_copyright('smali'),
+ implements_spec = s_ifaces,
+ extends = "extends" if len(self.ifaces) else "",
+ ifaces = j_ifaces,
+ func = funcs,
+ tree = self.get_tree(),
+ class_name = self.class_name)
+
+def print_tree(ifaces):
+ """
+ Prints a list of iface trees
+ """
+ return " ".join(i.get_tree() for i in ifaces)
+
+# The deduplicated output of subtree_sizes for each size up to
+# MAX_LEAF_IFACE_PER_OBJECT.
+SUBTREES = [set(tuple(sorted(l)) for l in subtree_sizes(i))
+ for i in range(MAX_IFACE_DEPTH + 1)]
+
+def create_test_classes():
+ """
+ Yield all the test classes with the different interface trees
+ """
+ for num in range(1, MAX_IFACE_DEPTH + 1):
+ for split in SUBTREES[num]:
+ ifaces = []
+ for sub in split:
+ ifaces.append(list(create_interface_trees(sub)))
+ for supers in itertools.product(*ifaces):
+ yield TestClass(supers)
+
+def create_interface_trees(num):
+ """
+ Yield all the interface trees up to 'num' depth.
+ """
+ if num == 0:
+ for iftype in InterfaceType:
+ yield TestInterface(tuple(), iftype)
+ return
+ for split in SUBTREES[num]:
+ ifaces = []
+ for sub in split:
+ ifaces.append(list(create_interface_trees(sub)))
+ for supers in itertools.product(*ifaces):
+ for iftype in InterfaceType:
+ yield TestInterface(supers, iftype)
+
+def create_all_test_files():
+ """
+ Creates all the objects representing the files in this test. They just need to
+ be dumped.
+ """
+ mc = MainClass()
+ classes = {mc}
+ for clazz in create_test_classes():
+ classes.add(clazz)
+ for i in clazz:
+ classes.add(i)
+ mc.add_test(clazz)
+ return mc, classes
+
+def main(argv):
+ smali_dir = Path(argv[1])
+ if not smali_dir.exists() or not smali_dir.is_dir():
+ print("{} is not a valid smali dir".format(smali_dir), file=sys.stderr)
+ sys.exit(1)
+ expected_txt = Path(argv[2])
+ mainclass, all_files = create_all_test_files()
+ with expected_txt.open('w') as out:
+ print(mainclass.get_expected(), file=out)
+ for f in all_files:
+ f.dump(smali_dir)
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk
index c9343d4..f62d0e9 100644
--- a/test/Android.run-test.mk
+++ b/test/Android.run-test.mk
@@ -239,7 +239,10 @@
960-default-smali \
961-default-iface-resolution-generated \
964-default-iface-init-generated \
- 968-default-partial-compile-generated
+ 968-default-partial-compile-generated \
+ 969-iface-super \
+ 970-iface-super-resolution-generated \
+ 971-iface-super-partial-compile-generated
# Check if we have python3 to run our tests.
ifeq ($(wildcard /usr/bin/python3),)
@@ -267,16 +270,6 @@
TEST_ART_BROKEN_PREBUILD_RUN_TESTS :=
-# 143-string-value tests for a LOG(E) tag, which is only supported on host.
-TEST_ART_BROKEN_TARGET_RUN_TESTS := \
- 143-string-value \
-
-ART_TEST_KNOWN_BROKEN += $(call all-run-test-names,target,$(RUN_TYPES),$(PREBUILD_TYPES), \
- $(COMPILER_TYPES),$(RELOCATE_TYPES),$(TRACE_TYPES),$(GC_TYPES),$(JNI_TYPES), \
- $(IMAGE_TYPES), $(PICTEST_TYPES), $(DEBUGGABLE_TYPES), $(TEST_ART_BROKEN_TARGET_RUN_TESTS), $(ALL_ADDRESS_SIZES))
-
-TEST_ART_BROKEN_TARGET_RUN_TESTS :=
-
# 554-jit-profile-file is disabled because it needs a primary oat file to know what it should save.
TEST_ART_BROKEN_NO_PREBUILD_TESTS := \
117-nopatchoat \
@@ -463,7 +456,8 @@
# Known broken tests for the default compiler (Quick).
TEST_ART_BROKEN_DEFAULT_RUN_TESTS := \
- 457-regs
+ 457-regs \
+ 563-checker-fakestring
ifneq (,$(filter default,$(COMPILER_TYPES)))
ART_TEST_KNOWN_BROKEN += $(call all-run-test-names,$(TARGET_TYPES),$(RUN_TYPES),$(PREBUILD_TYPES), \
@@ -542,10 +536,13 @@
# Tests that should fail in the read barrier configuration with the Optimizing compiler.
# 484: Baker's fast path based read barrier compiler instrumentation generates code containing
# more parallel moves on x86, thus some Checker assertions may fail.
+# 527: On ARM64, the read barrier instrumentation does not support the HArm64IntermediateAddress
+# instruction yet (b/26601270).
# 537: Expects an array copy to be intrinsified on x86-64, but calling-on-slowpath intrinsics are
# not yet handled in the read barrier configuration.
TEST_ART_BROKEN_OPTIMIZING_READ_BARRIER_RUN_TESTS := \
484-checker-register-hints \
+ 527-checker-array-access-split \
537-checker-arraycopy
# Tests that should fail in the read barrier configuration with JIT.
diff --git a/test/run-test b/test/run-test
index 4f111d2..033e2c6 100755
--- a/test/run-test
+++ b/test/run-test
@@ -733,7 +733,7 @@
# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
build_file_size_limit=2048
run_file_size_limit=2048
-if echo "$test_dir" | grep -Eq "(083|089|964)" > /dev/null; then
+if echo "$test_dir" | grep -Eq "(083|089|964|971)" > /dev/null; then
build_file_size_limit=5120
run_file_size_limit=5120
fi
diff --git a/tools/libcore_failures.txt b/tools/libcore_failures.txt
index f2c810a..351e99e 100644
--- a/tools/libcore_failures.txt
+++ b/tools/libcore_failures.txt
@@ -258,6 +258,12 @@
"dalvik.system.JniTest#testPassingLongs",
"dalvik.system.JniTest#testPassingObjectReferences",
"dalvik.system.JniTest#testPassingShorts",
- "dalvik.system.JniTest#testPassingThis"]
+ "dalvik.system.JniTest#testPassingThis",
+ "libcore.util.NativeAllocationRegistryTest#testBadSize",
+ "libcore.util.NativeAllocationRegistryTest#testNativeAllocationAllocatorAndNoSharedRegistry",
+ "libcore.util.NativeAllocationRegistryTest#testNativeAllocationAllocatorAndSharedRegistry",
+ "libcore.util.NativeAllocationRegistryTest#testNativeAllocationNoAllocatorAndNoSharedRegistry",
+ "libcore.util.NativeAllocationRegistryTest#testNativeAllocationNoAllocatorAndSharedRegistry",
+ "libcore.util.NativeAllocationRegistryTest#testNullArguments"]
}
]
diff --git a/tools/libcore_failures_concurrent_collector.txt b/tools/libcore_failures_concurrent_collector.txt
index 2cb2c50..e55c000 100644
--- a/tools/libcore_failures_concurrent_collector.txt
+++ b/tools/libcore_failures_concurrent_collector.txt
@@ -27,7 +27,9 @@
description: "TimeoutException on host-{x86,x86-64}-concurrent-collector",
result: EXEC_FAILED,
modes: [host],
- names: ["libcore.java.util.zip.GZIPOutputStreamTest#testSyncFlushEnabled",
+ names: ["libcore.java.util.zip.DeflaterOutputStreamTest#testSyncFlushDisabled",
+ "libcore.java.util.zip.GZIPOutputStreamTest#testSyncFlushEnabled",
+ "libcore.java.util.zip.OldAndroidGZIPStreamTest#testGZIPStream",
"libcore.java.util.zip.ZipFileTest#testZipFileWithLotsOfEntries",
"libcore.java.util.zip.ZipInputStreamTest#testLongMessage"],
bug: 26507762