diff options
159 files changed, 2087 insertions, 1136 deletions
diff --git a/Android.bp b/Android.bp index caf4f9a325..4bcceffcd1 100644 --- a/Android.bp +++ b/Android.bp @@ -1,6 +1,7 @@ // TODO: These should be handled with transitive static library dependencies art_static_dependencies = [ // Note: the order is important because of static linking resolution. + "libdexfile", "libziparchive", "libnativehelper", "libnativebridge", diff --git a/adbconnection/adbconnection.cc b/adbconnection/adbconnection.cc index d8db923a28..634d6b56df 100644 --- a/adbconnection/adbconnection.cc +++ b/adbconnection/adbconnection.cc @@ -139,7 +139,8 @@ AdbConnectionState::AdbConnectionState(const std::string& agent_name) sent_agent_fds_(false), performed_handshake_(false), notified_ddm_active_(false), - next_ddm_id_(1) { + next_ddm_id_(1), + started_debugger_threads_(false) { // Setup the addr. control_addr_.controlAddrUn.sun_family = AF_UNIX; control_addr_len_ = sizeof(control_addr_.controlAddrUn.sun_family) + sizeof(kJdwpControlName) - 1; @@ -174,6 +175,7 @@ struct CallbackData { static void* CallbackFunction(void* vdata) { std::unique_ptr<CallbackData> data(reinterpret_cast<CallbackData*>(vdata)); + CHECK(data->this_ == gState); art::Thread* self = art::Thread::Attach(kAdbConnectionThreadName, true, data->thr_); @@ -199,6 +201,10 @@ static void* CallbackFunction(void* vdata) { int detach_result = art::Runtime::Current()->GetJavaVM()->DetachCurrentThread(); CHECK_EQ(detach_result, 0); + // Get rid of the connection + gState = nullptr; + delete data->this_; + return nullptr; } @@ -247,11 +253,13 @@ void AdbConnectionState::StartDebuggerThreads() { ScopedLocalRef<jobject> thr(soa.Env(), CreateAdbConnectionThread(soa.Self())); pthread_t pthread; std::unique_ptr<CallbackData> data(new CallbackData { this, soa.Env()->NewGlobalRef(thr.get()) }); + started_debugger_threads_ = true; int pthread_create_result = pthread_create(&pthread, nullptr, &CallbackFunction, data.get()); if (pthread_create_result != 0) { + started_debugger_threads_ = false; // If the create succeeded the other thread will call EndThreadBirth. art::Runtime* runtime = art::Runtime::Current(); soa.Env()->DeleteGlobalRef(data->thr_); @@ -545,6 +553,7 @@ bool AdbConnectionState::SetupAdbConnection() { } void AdbConnectionState::RunPollLoop(art::Thread* self) { + CHECK_NE(agent_name_, ""); CHECK_EQ(self->GetState(), art::kNative); art::Locks::mutator_lock_->AssertNotHeld(self); self->SetState(art::kWaitingInMainDebuggerLoop); @@ -869,24 +878,26 @@ void AdbConnectionState::StopDebuggerThreads() { shutting_down_ = true; // Wakeup the poll loop. uint64_t data = 1; - TEMP_FAILURE_RETRY(write(sleep_event_fd_, &data, sizeof(data))); + if (sleep_event_fd_ != -1) { + TEMP_FAILURE_RETRY(write(sleep_event_fd_, &data, sizeof(data))); + } } // The plugin initialization function. extern "C" bool ArtPlugin_Initialize() REQUIRES_SHARED(art::Locks::mutator_lock_) { DCHECK(art::Runtime::Current()->GetJdwpProvider() == art::JdwpProvider::kAdbConnection); // TODO Provide some way for apps to set this maybe? + DCHECK(gState == nullptr); gState = new AdbConnectionState(kDefaultJdwpAgentName); - CHECK(gState != nullptr); return ValidateJdwpOptions(art::Runtime::Current()->GetJdwpOptions()); } extern "C" bool ArtPlugin_Deinitialize() { - CHECK(gState != nullptr); - // Just do this a second time? - // TODO I don't think this should be needed. gState->StopDebuggerThreads(); - delete gState; + if (!gState->DebuggerThreadsStarted()) { + // If debugger threads were started then those threads will delete the state once they are done. + delete gState; + } return true; } diff --git a/adbconnection/adbconnection.h b/adbconnection/adbconnection.h index e63a3b607d..04e39bf4ff 100644 --- a/adbconnection/adbconnection.h +++ b/adbconnection/adbconnection.h @@ -72,7 +72,7 @@ struct AdbConnectionDdmCallback : public art::DdmCallback { class AdbConnectionState { public: - explicit AdbConnectionState(const std::string& agent_name); + explicit AdbConnectionState(const std::string& name); // Called on the listening thread to start dealing with new input. thr is used to attach the new // thread to the runtime. @@ -85,6 +85,11 @@ class AdbConnectionState { // Stops debugger threads during shutdown. void StopDebuggerThreads(); + // If StartDebuggerThreads was called successfully. + bool DebuggerThreadsStarted() { + return started_debugger_threads_; + } + private: uint32_t NextDdmId(); @@ -161,6 +166,8 @@ class AdbConnectionState { std::atomic<uint32_t> next_ddm_id_; + bool started_debugger_threads_; + socklen_t control_addr_len_; union { sockaddr_un controlAddrUn; diff --git a/cmdline/cmdline_parser_test.cc b/cmdline/cmdline_parser_test.cc index 1e79fdff1b..3cb9731a17 100644 --- a/cmdline/cmdline_parser_test.cc +++ b/cmdline/cmdline_parser_test.cc @@ -369,7 +369,7 @@ TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) { */ TEST_F(CmdlineParserTest, TestJdwpProviderEmpty) { { - EXPECT_SINGLE_PARSE_DEFAULT_VALUE(JdwpProvider::kInternal, "", M::JdwpProvider); + EXPECT_SINGLE_PARSE_DEFAULT_VALUE(JdwpProvider::kNone, "", M::JdwpProvider); } } // TEST_F diff --git a/compiler/Android.bp b/compiler/Android.bp index 2e60e7d658..453965947d 100644 --- a/compiler/Android.bp +++ b/compiler/Android.bp @@ -184,6 +184,7 @@ art_cc_defaults { }, generated_sources: ["art_compiler_operator_srcs"], shared_libs: [ + "libdexfile", "libbase", "libcutils", // for atrace. "liblzma", diff --git a/compiler/dex/inline_method_analyser.cc b/compiler/dex/inline_method_analyser.cc index ce67b85b99..dc044c1210 100644 --- a/compiler/dex/inline_method_analyser.cc +++ b/compiler/dex/inline_method_analyser.cc @@ -142,7 +142,7 @@ ArtMethod* GetTargetConstructor(ArtMethod* method, const Instruction* invoke_dir REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK_EQ(invoke_direct->Opcode(), Instruction::INVOKE_DIRECT); if (kIsDebugBuild) { - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); DCHECK_EQ(invoke_direct->VRegC_35c(), accessor.RegistersSize() - accessor.InsSize()); } @@ -324,9 +324,9 @@ bool DoAnalyseConstructor(const CodeItemDataAccessor* code_item, return false; } if (target_method->GetDeclaringClass()->IsObjectClass()) { - DCHECK_EQ(CodeItemDataAccessor(target_method).begin()->Opcode(), Instruction::RETURN_VOID); + DCHECK_EQ(target_method->DexInstructionData().begin()->Opcode(), Instruction::RETURN_VOID); } else { - CodeItemDataAccessor target_code_item(target_method); + CodeItemDataAccessor target_code_item(target_method->DexInstructionData()); if (!target_code_item.HasCodeItem()) { return false; // Native constructor? } @@ -430,7 +430,7 @@ static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_SHORT) == InlineMethodAnalyser::IPutVariant(Instruction::IPUT_SHORT), "iget/iput_short variant"); bool InlineMethodAnalyser::AnalyseMethodCode(ArtMethod* method, InlineMethod* result) { - CodeItemDataAccessor code_item(method); + CodeItemDataAccessor code_item(method->DexInstructionData()); if (!code_item.HasCodeItem()) { // Native or abstract. return false; diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 60537fd5c8..c617f54f55 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -932,7 +932,7 @@ class ResolveCatchBlockExceptionsClassVisitor : public ClassVisitor { if (method->GetCodeItem() == nullptr) { return; // native or abstract method } - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); if (accessor.TriesSize() == 0) { return; // nothing to process } diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc index 1780b1d7ed..2d82d79c4a 100644 --- a/compiler/driver/compiler_options.cc +++ b/compiler/driver/compiler_options.cc @@ -60,6 +60,7 @@ CompilerOptions::CompilerOptions() dump_cfg_append_(false), force_determinism_(false), deduplicate_code_(true), + count_hotness_in_compiled_code_(false), register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault), passes_to_run_(nullptr) { } diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h index 3f660293d2..18b0913430 100644 --- a/compiler/driver/compiler_options.h +++ b/compiler/driver/compiler_options.h @@ -274,6 +274,10 @@ class CompilerOptions FINAL { return dump_stats_; } + bool CountHotnessInCompiledCode() const { + return count_hotness_in_compiled_code_; + } + private: bool ParseDumpInitFailures(const std::string& option, std::string* error_msg); void ParseDumpCfgPasses(const StringPiece& option, UsageFn Usage); @@ -336,6 +340,10 @@ class CompilerOptions FINAL { // Whether code should be deduplicated. bool deduplicate_code_; + // Whether compiled code should increment the hotness count of ArtMethod. Note that the increments + // won't be atomic for performance reasons, so we accept races, just like in interpreter. + bool count_hotness_in_compiled_code_; + RegisterAllocator::Strategy register_allocation_strategy_; // If not null, specifies optimization passes which will be run instead of defaults. diff --git a/compiler/driver/compiler_options_map-inl.h b/compiler/driver/compiler_options_map-inl.h index f97ab08600..3b18db09fc 100644 --- a/compiler/driver/compiler_options_map-inl.h +++ b/compiler/driver/compiler_options_map-inl.h @@ -77,6 +77,9 @@ inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string } map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_); options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode); + if (map.Exists(Base::CountHotnessInCompiledCode)) { + options->count_hotness_in_compiled_code_ = true; + } if (map.Exists(Base::DumpTimings)) { options->dump_timings_ = true; @@ -137,6 +140,9 @@ inline void AddCompilerOptionsArgumentParserOptions(Builder& b) { .WithValueMap({{"false", false}, {"true", true}}) .IntoKey(Map::DeduplicateCode) + .Define({"--count-hotness-in-compiled-code"}) + .IntoKey(Map::CountHotnessInCompiledCode) + .Define({"--dump-timings"}) .IntoKey(Map::DumpTimings) diff --git a/compiler/driver/compiler_options_map.def b/compiler/driver/compiler_options_map.def index 2c56fd7974..acddae7299 100644 --- a/compiler/driver/compiler_options_map.def +++ b/compiler/driver/compiler_options_map.def @@ -58,6 +58,7 @@ COMPILER_OPTIONS_KEY (Unit, DumpCFGAppend) COMPILER_OPTIONS_KEY (std::string, RegisterAllocationStrategy) COMPILER_OPTIONS_KEY (ParseStringList<','>, VerboseMethods) COMPILER_OPTIONS_KEY (bool, DeduplicateCode, true) +COMPILER_OPTIONS_KEY (Unit, CountHotnessInCompiledCode) COMPILER_OPTIONS_KEY (Unit, DumpTimings) COMPILER_OPTIONS_KEY (Unit, DumpStats) diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc index 2c62095458..17b94d3bdf 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -76,7 +76,7 @@ extern "C" void jit_types_loaded(void* handle, mirror::Class** types, size_t cou const ArrayRef<mirror::Class*> types_array(types, count); std::vector<uint8_t> elf_file = debug::WriteDebugElfFileForClasses( kRuntimeISA, jit_compiler->GetCompilerDriver()->GetInstructionSetFeatures(), types_array); - MutexLock mu(Thread::Current(), g_jit_debug_mutex); + MutexLock mu(Thread::Current(), *Locks::native_debug_interface_lock_); CreateJITCodeEntry(std::move(elf_file)); } } diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc index 13bbffa1e3..3fd88e3e18 100644 --- a/compiler/optimizing/code_generator_arm64.cc +++ b/compiler/optimizing/code_generator_arm64.cc @@ -1488,6 +1488,14 @@ void CodeGeneratorARM64::GenerateFrameEntry() { MacroAssembler* masm = GetVIXLAssembler(); __ Bind(&frame_entry_label_); + if (GetCompilerOptions().CountHotnessInCompiledCode()) { + UseScratchRegisterScope temps(masm); + Register temp = temps.AcquireX(); + __ Ldrh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); + __ Add(temp, temp, 1); + __ Strh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); + } + bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); if (do_overflow_check) { @@ -1881,6 +1889,8 @@ void CodeGeneratorARM64::Load(DataType::Type type, DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); __ Ldr(dst, src); break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; } @@ -1959,6 +1969,8 @@ void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, __ Fmov(FPRegister(dst), temp); break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; } @@ -1986,6 +1998,8 @@ void CodeGeneratorARM64::Store(DataType::Type type, DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); __ Str(src, dst); break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; } @@ -2063,6 +2077,8 @@ void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, } break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; } @@ -3501,6 +3517,15 @@ void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* s HLoopInformation* info = block->GetLoopInformation(); if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { + if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { + UseScratchRegisterScope temps(GetVIXLAssembler()); + Register temp1 = temps.AcquireX(); + Register temp2 = temps.AcquireX(); + __ Ldr(temp1, MemOperand(sp, 0)); + __ Ldrh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); + __ Add(temp2, temp2, 1); + __ Strh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); + } GenerateSuspendCheck(info->GetSuspendCheck(), successor); return; } diff --git a/compiler/optimizing/code_generator_arm_vixl.cc b/compiler/optimizing/code_generator_arm_vixl.cc index ea6b968dc6..6d49b32dbc 100644 --- a/compiler/optimizing/code_generator_arm_vixl.cc +++ b/compiler/optimizing/code_generator_arm_vixl.cc @@ -2485,6 +2485,14 @@ void CodeGeneratorARMVIXL::GenerateFrameEntry() { DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); __ Bind(&frame_entry_label_); + if (GetCompilerOptions().CountHotnessInCompiledCode()) { + UseScratchRegisterScope temps(GetVIXLAssembler()); + vixl32::Register temp = temps.Acquire(); + __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); + __ Add(temp, temp, 1); + __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); + } + if (HasEmptyFrame()) { return; } @@ -2657,6 +2665,8 @@ Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Typ } } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unexpected parameter type " << type; break; @@ -2672,6 +2682,7 @@ Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::T case DataType::Type::kInt8: case DataType::Type::kUint16: case DataType::Type::kInt16: + case DataType::Type::kUint32: case DataType::Type::kInt32: { return LocationFrom(r0); } @@ -2680,6 +2691,7 @@ Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::T return LocationFrom(s0); } + case DataType::Type::kUint64: case DataType::Type::kInt64: { return LocationFrom(r0, r1); } @@ -2801,6 +2813,16 @@ void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* HLoopInformation* info = block->GetLoopInformation(); if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { + if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { + UseScratchRegisterScope temps(GetVIXLAssembler()); + vixl32::Register temp = temps.Acquire(); + __ Push(vixl32::Register(kMethodRegister)); + GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize); + __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); + __ Add(temp, temp, 1); + __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); + __ Pop(vixl32::Register(kMethodRegister)); + } GenerateSuspendCheck(info->GetSuspendCheck(), successor); return; } @@ -5509,6 +5531,8 @@ void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << field_type; UNREACHABLE(); @@ -5753,6 +5777,8 @@ void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << load_type; UNREACHABLE(); @@ -6245,6 +6271,8 @@ void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -6534,6 +6562,8 @@ void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << value_type; UNREACHABLE(); diff --git a/compiler/optimizing/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc index 5c8e46ed19..855da2b18f 100644 --- a/compiler/optimizing/code_generator_mips.cc +++ b/compiler/optimizing/code_generator_mips.cc @@ -58,9 +58,11 @@ Location MipsReturnLocation(DataType::Type return_type) { case DataType::Type::kInt8: case DataType::Type::kUint16: case DataType::Type::kInt16: + case DataType::Type::kUint32: case DataType::Type::kInt32: return Location::RegisterLocation(V0); + case DataType::Type::kUint64: case DataType::Type::kInt64: return Location::RegisterPairLocation(V0, V1); @@ -140,6 +142,8 @@ Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(DataType::Type t break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unexpected parameter type " << type; break; @@ -391,7 +395,7 @@ class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS { CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen); __ Bind(GetEntryLabel()); - if (!is_fatal_) { + if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { SaveLiveRegisters(codegen, locations); } @@ -1276,6 +1280,10 @@ static dwarf::Reg DWARFReg(Register reg) { void CodeGeneratorMIPS::GenerateFrameEntry() { __ Bind(&frame_entry_label_); + if (GetCompilerOptions().CountHotnessInCompiledCode()) { + LOG(WARNING) << "Unimplemented hotness update in mips backend"; + } + bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips) || !IsLeafMethod(); @@ -2817,6 +2825,8 @@ void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << instruction->GetType(); UNREACHABLE(); @@ -3132,6 +3142,8 @@ void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << instruction->GetType(); UNREACHABLE(); @@ -3271,26 +3283,8 @@ static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { } void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) { - LocationSummary::CallKind call_kind = LocationSummary::kNoCall; - bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); - TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); - switch (type_check_kind) { - case TypeCheckKind::kExactCheck: - case TypeCheckKind::kAbstractClassCheck: - case TypeCheckKind::kClassHierarchyCheck: - case TypeCheckKind::kArrayObjectCheck: - call_kind = (throws_into_catch || kEmitCompilerReadBarrier) - ? LocationSummary::kCallOnSlowPath - : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. - break; - case TypeCheckKind::kArrayCheck: - case TypeCheckKind::kUnresolvedCheck: - case TypeCheckKind::kInterfaceCheck: - call_kind = LocationSummary::kCallOnSlowPath; - break; - } - + LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); locations->SetInAt(0, Location::RequiresRegister()); @@ -3319,18 +3313,7 @@ void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) { mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); MipsLabel done; - // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases - // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding - // read barriers is done for performance and code size reasons. - bool is_type_check_slow_path_fatal = false; - if (!kEmitCompilerReadBarrier) { - is_type_check_slow_path_fatal = - (type_check_kind == TypeCheckKind::kExactCheck || - type_check_kind == TypeCheckKind::kAbstractClassCheck || - type_check_kind == TypeCheckKind::kClassHierarchyCheck || - type_check_kind == TypeCheckKind::kArrayObjectCheck) && - !instruction->CanThrowIntoCatchBlock(); - } + bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); SlowPathCodeMIPS* slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS( instruction, is_type_check_slow_path_fatal); @@ -6316,6 +6299,8 @@ void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction, case DataType::Type::kFloat64: load_type = kLoadDoubleword; break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -6469,6 +6454,8 @@ void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction, case DataType::Type::kFloat64: store_type = kStoreDoubleword; break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -7197,11 +7184,12 @@ void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) { case TypeCheckKind::kExactCheck: case TypeCheckKind::kAbstractClassCheck: case TypeCheckKind::kClassHierarchyCheck: - case TypeCheckKind::kArrayObjectCheck: - call_kind = - kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; - baker_read_barrier_slow_path = kUseBakerReadBarrier; + case TypeCheckKind::kArrayObjectCheck: { + bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); + call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; + baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; break; + } case TypeCheckKind::kArrayCheck: case TypeCheckKind::kUnresolvedCheck: case TypeCheckKind::kInterfaceCheck: @@ -7249,13 +7237,15 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { switch (type_check_kind) { case TypeCheckKind::kExactCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // Classes must be equal for the instanceof to succeed. __ Xor(out, out, cls); __ Sltiu(out, out, 1); @@ -7263,13 +7253,15 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { } case TypeCheckKind::kAbstractClassCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // If the class is abstract, we eagerly fetch the super class of the // object to avoid doing a comparison we know will fail. MipsLabel loop; @@ -7279,7 +7271,7 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { out_loc, super_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // If `out` is null, we use it for the result, and jump to `done`. __ Beqz(out, &done); __ Bne(out, cls, &loop); @@ -7288,13 +7280,15 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { } case TypeCheckKind::kClassHierarchyCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // Walk over the class hierarchy to find a match. MipsLabel loop, success; __ Bind(&loop); @@ -7304,7 +7298,7 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { out_loc, super_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); __ Bnez(out, &loop); // If `out` is null, we use it for the result, and jump to `done`. __ B(&done); @@ -7314,13 +7308,15 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { } case TypeCheckKind::kArrayObjectCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // Do an exact check. MipsLabel success; __ Beq(out, cls, &success); @@ -7330,7 +7326,7 @@ void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) { out_loc, component_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // If `out` is null, we use it for the result, and jump to `done`. __ Beqz(out, &done); __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); diff --git a/compiler/optimizing/code_generator_mips64.cc b/compiler/optimizing/code_generator_mips64.cc index bcfe051c90..8a06061c6a 100644 --- a/compiler/optimizing/code_generator_mips64.cc +++ b/compiler/optimizing/code_generator_mips64.cc @@ -55,8 +55,10 @@ Location Mips64ReturnLocation(DataType::Type return_type) { case DataType::Type::kInt8: case DataType::Type::kUint16: case DataType::Type::kInt16: + case DataType::Type::kUint32: case DataType::Type::kInt32: case DataType::Type::kReference: + case DataType::Type::kUint64: case DataType::Type::kInt64: return Location::RegisterLocation(V0); @@ -350,7 +352,7 @@ class TypeCheckSlowPathMIPS64 : public SlowPathCodeMIPS64 { CodeGeneratorMIPS64* mips64_codegen = down_cast<CodeGeneratorMIPS64*>(codegen); __ Bind(GetEntryLabel()); - if (!is_fatal_) { + if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { SaveLiveRegisters(codegen, locations); } @@ -1079,6 +1081,10 @@ static dwarf::Reg DWARFReg(FpuRegister reg) { void CodeGeneratorMIPS64::GenerateFrameEntry() { __ Bind(&frame_entry_label_); + if (GetCompilerOptions().CountHotnessInCompiledCode()) { + LOG(WARNING) << "Unimplemented hotness update in mips64 backend"; + } + bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kMips64) || !IsLeafMethod(); @@ -2404,6 +2410,8 @@ void InstructionCodeGeneratorMIPS64::VisitArrayGet(HArrayGet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << instruction->GetType(); UNREACHABLE(); @@ -2707,6 +2715,8 @@ void InstructionCodeGeneratorMIPS64::VisitArraySet(HArraySet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << instruction->GetType(); UNREACHABLE(); @@ -2826,26 +2836,8 @@ static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { } void LocationsBuilderMIPS64::VisitCheckCast(HCheckCast* instruction) { - LocationSummary::CallKind call_kind = LocationSummary::kNoCall; - bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); - TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); - switch (type_check_kind) { - case TypeCheckKind::kExactCheck: - case TypeCheckKind::kAbstractClassCheck: - case TypeCheckKind::kClassHierarchyCheck: - case TypeCheckKind::kArrayObjectCheck: - call_kind = (throws_into_catch || kEmitCompilerReadBarrier) - ? LocationSummary::kCallOnSlowPath - : LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. - break; - case TypeCheckKind::kArrayCheck: - case TypeCheckKind::kUnresolvedCheck: - case TypeCheckKind::kInterfaceCheck: - call_kind = LocationSummary::kCallOnSlowPath; - break; - } - + LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); locations->SetInAt(0, Location::RequiresRegister()); @@ -2874,18 +2866,7 @@ void InstructionCodeGeneratorMIPS64::VisitCheckCast(HCheckCast* instruction) { mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); Mips64Label done; - // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases - // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding - // read barriers is done for performance and code size reasons. - bool is_type_check_slow_path_fatal = false; - if (!kEmitCompilerReadBarrier) { - is_type_check_slow_path_fatal = - (type_check_kind == TypeCheckKind::kExactCheck || - type_check_kind == TypeCheckKind::kAbstractClassCheck || - type_check_kind == TypeCheckKind::kClassHierarchyCheck || - type_check_kind == TypeCheckKind::kArrayObjectCheck) && - !instruction->CanThrowIntoCatchBlock(); - } + bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); SlowPathCodeMIPS64* slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathMIPS64( instruction, is_type_check_slow_path_fatal); @@ -4794,6 +4775,8 @@ void InstructionCodeGeneratorMIPS64::HandleFieldGet(HInstruction* instruction, case DataType::Type::kReference: load_type = kLoadUnsignedWord; break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -4887,6 +4870,8 @@ void InstructionCodeGeneratorMIPS64::HandleFieldSet(HInstruction* instruction, case DataType::Type::kFloat64: store_type = kStoreDoubleword; break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -5514,11 +5499,12 @@ void LocationsBuilderMIPS64::VisitInstanceOf(HInstanceOf* instruction) { case TypeCheckKind::kExactCheck: case TypeCheckKind::kAbstractClassCheck: case TypeCheckKind::kClassHierarchyCheck: - case TypeCheckKind::kArrayObjectCheck: - call_kind = - kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; - baker_read_barrier_slow_path = kUseBakerReadBarrier; + case TypeCheckKind::kArrayObjectCheck: { + bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); + call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; + baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; break; + } case TypeCheckKind::kArrayCheck: case TypeCheckKind::kUnresolvedCheck: case TypeCheckKind::kInterfaceCheck: @@ -5566,13 +5552,15 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { switch (type_check_kind) { case TypeCheckKind::kExactCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // Classes must be equal for the instanceof to succeed. __ Xor(out, out, cls); __ Sltiu(out, out, 1); @@ -5580,13 +5568,15 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { } case TypeCheckKind::kAbstractClassCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // If the class is abstract, we eagerly fetch the super class of the // object to avoid doing a comparison we know will fail. Mips64Label loop; @@ -5596,7 +5586,7 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { out_loc, super_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // If `out` is null, we use it for the result, and jump to `done`. __ Beqzc(out, &done); __ Bnec(out, cls, &loop); @@ -5605,13 +5595,15 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { } case TypeCheckKind::kClassHierarchyCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // Walk over the class hierarchy to find a match. Mips64Label loop, success; __ Bind(&loop); @@ -5621,7 +5613,7 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { out_loc, super_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); __ Bnezc(out, &loop); // If `out` is null, we use it for the result, and jump to `done`. __ Bc(&done); @@ -5631,13 +5623,15 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { } case TypeCheckKind::kArrayObjectCheck: { + ReadBarrierOption read_barrier_option = + CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); // /* HeapReference<Class> */ out = obj->klass_ GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // Do an exact check. Mips64Label success; __ Beqc(out, cls, &success); @@ -5647,7 +5641,7 @@ void InstructionCodeGeneratorMIPS64::VisitInstanceOf(HInstanceOf* instruction) { out_loc, component_offset, maybe_temp_loc, - kCompilerReadBarrierOption); + read_barrier_option); // If `out` is null, we use it for the result, and jump to `done`. __ Beqzc(out, &done); __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); diff --git a/compiler/optimizing/code_generator_vector_arm64.cc b/compiler/optimizing/code_generator_vector_arm64.cc index 152a59c208..174efdf115 100644 --- a/compiler/optimizing/code_generator_vector_arm64.cc +++ b/compiler/optimizing/code_generator_vector_arm64.cc @@ -606,22 +606,20 @@ void InstructionCodeGeneratorARM64::VisitVecMin(HVecMin* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ Smin(dst.V8H(), lhs.V8H(), rhs.V8H()); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ Umin(dst.V4S(), lhs.V4S(), rhs.V4S()); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Umin(dst.V4S(), lhs.V4S(), rhs.V4S()); - } else { - __ Smin(dst.V4S(), lhs.V4S(), rhs.V4S()); - } + __ Smin(dst.V4S(), lhs.V4S(), rhs.V4S()); break; case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ Fmin(dst.V4S(), lhs.V4S(), rhs.V4S()); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ Fmin(dst.V2D(), lhs.V2D(), rhs.V2D()); break; default: @@ -656,22 +654,20 @@ void InstructionCodeGeneratorARM64::VisitVecMax(HVecMax* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ Smax(dst.V8H(), lhs.V8H(), rhs.V8H()); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ Umax(dst.V4S(), lhs.V4S(), rhs.V4S()); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Umax(dst.V4S(), lhs.V4S(), rhs.V4S()); - } else { - __ Smax(dst.V4S(), lhs.V4S(), rhs.V4S()); - } + __ Smax(dst.V4S(), lhs.V4S(), rhs.V4S()); break; case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ Fmax(dst.V4S(), lhs.V4S(), rhs.V4S()); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ Fmax(dst.V2D(), lhs.V2D(), rhs.V2D()); break; default: diff --git a/compiler/optimizing/code_generator_vector_arm_vixl.cc b/compiler/optimizing/code_generator_vector_arm_vixl.cc index cc470ddb2e..7c3155ab73 100644 --- a/compiler/optimizing/code_generator_vector_arm_vixl.cc +++ b/compiler/optimizing/code_generator_vector_arm_vixl.cc @@ -431,13 +431,13 @@ void InstructionCodeGeneratorARMVIXL::VisitVecMin(HVecMin* instruction) { DCHECK_EQ(4u, instruction->GetVectorLength()); __ Vmin(DataTypeValue::S16, dst, lhs, rhs); break; + case DataType::Type::kUint32: + DCHECK_EQ(2u, instruction->GetVectorLength()); + __ Vmin(DataTypeValue::U32, dst, lhs, rhs); + break; case DataType::Type::kInt32: DCHECK_EQ(2u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Vmin(DataTypeValue::U32, dst, lhs, rhs); - } else { - __ Vmin(DataTypeValue::S32, dst, lhs, rhs); - } + __ Vmin(DataTypeValue::S32, dst, lhs, rhs); break; default: LOG(FATAL) << "Unsupported SIMD type"; @@ -471,13 +471,13 @@ void InstructionCodeGeneratorARMVIXL::VisitVecMax(HVecMax* instruction) { DCHECK_EQ(4u, instruction->GetVectorLength()); __ Vmax(DataTypeValue::S16, dst, lhs, rhs); break; + case DataType::Type::kUint32: + DCHECK_EQ(2u, instruction->GetVectorLength()); + __ Vmax(DataTypeValue::U32, dst, lhs, rhs); + break; case DataType::Type::kInt32: DCHECK_EQ(2u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Vmax(DataTypeValue::U32, dst, lhs, rhs); - } else { - __ Vmax(DataTypeValue::S32, dst, lhs, rhs); - } + __ Vmax(DataTypeValue::S32, dst, lhs, rhs); break; default: LOG(FATAL) << "Unsupported SIMD type"; diff --git a/compiler/optimizing/code_generator_vector_mips.cc b/compiler/optimizing/code_generator_vector_mips.cc index 3cf150a6b8..ed9de96496 100644 --- a/compiler/optimizing/code_generator_vector_mips.cc +++ b/compiler/optimizing/code_generator_vector_mips.cc @@ -613,32 +613,30 @@ void InstructionCodeGeneratorMIPS::VisitVecMin(HVecMin* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ Min_sH(dst, lhs, rhs); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ Min_uW(dst, lhs, rhs); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Min_uW(dst, lhs, rhs); - } else { - __ Min_sW(dst, lhs, rhs); - } + __ Min_sW(dst, lhs, rhs); + break; + case DataType::Type::kUint64: + DCHECK_EQ(2u, instruction->GetVectorLength()); + __ Min_uD(dst, lhs, rhs); break; case DataType::Type::kInt64: DCHECK_EQ(2u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Min_uD(dst, lhs, rhs); - } else { - __ Min_sD(dst, lhs, rhs); - } + __ Min_sD(dst, lhs, rhs); break; // When one of arguments is NaN, fmin.df returns other argument, but Java expects a NaN value. // TODO: Fix min(x, NaN) cases for float and double. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FminW(dst, lhs, rhs); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FminD(dst, lhs, rhs); break; default: @@ -673,32 +671,30 @@ void InstructionCodeGeneratorMIPS::VisitVecMax(HVecMax* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ Max_sH(dst, lhs, rhs); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ Max_uW(dst, lhs, rhs); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Max_uW(dst, lhs, rhs); - } else { - __ Max_sW(dst, lhs, rhs); - } + __ Max_sW(dst, lhs, rhs); + break; + case DataType::Type::kUint64: + DCHECK_EQ(2u, instruction->GetVectorLength()); + __ Max_uD(dst, lhs, rhs); break; case DataType::Type::kInt64: DCHECK_EQ(2u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Max_uD(dst, lhs, rhs); - } else { - __ Max_sD(dst, lhs, rhs); - } + __ Max_sD(dst, lhs, rhs); break; // When one of arguments is NaN, fmax.df returns other argument, but Java expects a NaN value. // TODO: Fix max(x, NaN) cases for float and double. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FmaxW(dst, lhs, rhs); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FmaxD(dst, lhs, rhs); break; default: diff --git a/compiler/optimizing/code_generator_vector_mips64.cc b/compiler/optimizing/code_generator_vector_mips64.cc index 2d69533f21..9ea55ec8d7 100644 --- a/compiler/optimizing/code_generator_vector_mips64.cc +++ b/compiler/optimizing/code_generator_vector_mips64.cc @@ -612,32 +612,30 @@ void InstructionCodeGeneratorMIPS64::VisitVecMin(HVecMin* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ Min_sH(dst, lhs, rhs); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ Min_uW(dst, lhs, rhs); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Min_uW(dst, lhs, rhs); - } else { - __ Min_sW(dst, lhs, rhs); - } + __ Min_sW(dst, lhs, rhs); + break; + case DataType::Type::kUint64: + DCHECK_EQ(2u, instruction->GetVectorLength()); + __ Min_uD(dst, lhs, rhs); break; case DataType::Type::kInt64: DCHECK_EQ(2u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Min_uD(dst, lhs, rhs); - } else { - __ Min_sD(dst, lhs, rhs); - } + __ Min_sD(dst, lhs, rhs); break; // When one of arguments is NaN, fmin.df returns other argument, but Java expects a NaN value. // TODO: Fix min(x, NaN) cases for float and double. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FminW(dst, lhs, rhs); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FminD(dst, lhs, rhs); break; default: @@ -672,32 +670,30 @@ void InstructionCodeGeneratorMIPS64::VisitVecMax(HVecMax* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ Max_sH(dst, lhs, rhs); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ Max_uW(dst, lhs, rhs); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Max_uW(dst, lhs, rhs); - } else { - __ Max_sW(dst, lhs, rhs); - } + __ Max_sW(dst, lhs, rhs); + break; + case DataType::Type::kUint64: + DCHECK_EQ(2u, instruction->GetVectorLength()); + __ Max_uD(dst, lhs, rhs); break; case DataType::Type::kInt64: DCHECK_EQ(2u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ Max_uD(dst, lhs, rhs); - } else { - __ Max_sD(dst, lhs, rhs); - } + __ Max_sD(dst, lhs, rhs); break; // When one of arguments is NaN, fmax.df returns other argument, but Java expects a NaN value. // TODO: Fix max(x, NaN) cases for float and double. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FmaxW(dst, lhs, rhs); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ FmaxD(dst, lhs, rhs); break; default: diff --git a/compiler/optimizing/code_generator_vector_x86.cc b/compiler/optimizing/code_generator_vector_x86.cc index 7b4b85d2fe..f2ffccc887 100644 --- a/compiler/optimizing/code_generator_vector_x86.cc +++ b/compiler/optimizing/code_generator_vector_x86.cc @@ -640,23 +640,21 @@ void InstructionCodeGeneratorX86::VisitVecMin(HVecMin* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ pminsw(dst, src); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ pminud(dst, src); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ pminud(dst, src); - } else { - __ pminsd(dst, src); - } + __ pminsd(dst, src); break; // Next cases are sloppy wrt 0.0 vs -0.0. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ minps(dst, src); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ minpd(dst, src); break; default: @@ -691,23 +689,21 @@ void InstructionCodeGeneratorX86::VisitVecMax(HVecMax* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ pmaxsw(dst, src); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ pmaxud(dst, src); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ pmaxud(dst, src); - } else { - __ pmaxsd(dst, src); - } + __ pmaxsd(dst, src); break; // Next cases are sloppy wrt 0.0 vs -0.0. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ maxps(dst, src); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ maxpd(dst, src); break; default: diff --git a/compiler/optimizing/code_generator_vector_x86_64.cc b/compiler/optimizing/code_generator_vector_x86_64.cc index 107030e6c2..e2b0485f89 100644 --- a/compiler/optimizing/code_generator_vector_x86_64.cc +++ b/compiler/optimizing/code_generator_vector_x86_64.cc @@ -623,23 +623,21 @@ void InstructionCodeGeneratorX86_64::VisitVecMin(HVecMin* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ pminsw(dst, src); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ pminud(dst, src); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ pminud(dst, src); - } else { - __ pminsd(dst, src); - } + __ pminsd(dst, src); break; // Next cases are sloppy wrt 0.0 vs -0.0. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ minps(dst, src); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ minpd(dst, src); break; default: @@ -674,23 +672,21 @@ void InstructionCodeGeneratorX86_64::VisitVecMax(HVecMax* instruction) { DCHECK_EQ(8u, instruction->GetVectorLength()); __ pmaxsw(dst, src); break; + case DataType::Type::kUint32: + DCHECK_EQ(4u, instruction->GetVectorLength()); + __ pmaxud(dst, src); + break; case DataType::Type::kInt32: DCHECK_EQ(4u, instruction->GetVectorLength()); - if (instruction->IsUnsigned()) { - __ pmaxud(dst, src); - } else { - __ pmaxsd(dst, src); - } + __ pmaxsd(dst, src); break; // Next cases are sloppy wrt 0.0 vs -0.0. case DataType::Type::kFloat32: DCHECK_EQ(4u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ maxps(dst, src); break; case DataType::Type::kFloat64: DCHECK_EQ(2u, instruction->GetVectorLength()); - DCHECK(!instruction->IsUnsigned()); __ maxpd(dst, src); break; default: diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index cbe9e0a35c..5fede80bc7 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -1061,6 +1061,11 @@ void CodeGeneratorX86::GenerateFrameEntry() { IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); + if (GetCompilerOptions().CountHotnessInCompiledCode()) { + __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), + Immediate(1)); + } + if (!skip_overflow_check) { size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); @@ -1129,9 +1134,11 @@ Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type case DataType::Type::kInt8: case DataType::Type::kUint16: case DataType::Type::kInt16: + case DataType::Type::kUint32: case DataType::Type::kInt32: return Location::RegisterLocation(EAX); + case DataType::Type::kUint64: case DataType::Type::kInt64: return Location::RegisterPairLocation(EAX, EDX); @@ -1201,6 +1208,8 @@ Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type ty } } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unexpected parameter type " << type; break; @@ -1357,6 +1366,12 @@ void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* suc HLoopInformation* info = block->GetLoopInformation(); if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { + if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { + __ pushl(EAX); + __ movl(EAX, Address(ESP, kX86WordSize)); + __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); + __ popl(EAX); + } GenerateSuspendCheck(info->GetSuspendCheck(), successor); return; } @@ -4833,6 +4848,8 @@ void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << load_type; UNREACHABLE(); @@ -5006,6 +5023,8 @@ void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << field_type; UNREACHABLE(); @@ -5309,6 +5328,8 @@ void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -5560,6 +5581,8 @@ void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << instruction->GetType(); UNREACHABLE(); diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index 510eec4f30..ae35ab5983 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -1268,6 +1268,12 @@ void CodeGeneratorX86_64::GenerateFrameEntry() { && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); + if (GetCompilerOptions().CountHotnessInCompiledCode()) { + __ addw(Address(CpuRegister(kMethodRegisterArgument), + ArtMethod::HotnessCountOffset().Int32Value()), + Immediate(1)); + } + if (!skip_overflow_check) { size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); @@ -1459,6 +1465,11 @@ void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* HLoopInformation* info = block->GetLoopInformation(); if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { + if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { + __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), 0)); + __ addw(Address(CpuRegister(TMP), ArtMethod::HotnessCountOffset().Int32Value()), + Immediate(1)); + } GenerateSuspendCheck(info->GetSuspendCheck(), successor); return; } @@ -2262,7 +2273,9 @@ Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Ty case DataType::Type::kInt8: case DataType::Type::kUint16: case DataType::Type::kInt16: + case DataType::Type::kUint32: case DataType::Type::kInt32: + case DataType::Type::kUint64: case DataType::Type::kInt64: return Location::RegisterLocation(RAX); @@ -2331,6 +2344,8 @@ Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type } } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unexpected parameter type " << type; break; @@ -4296,6 +4311,8 @@ void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << load_type; UNREACHABLE(); @@ -4459,6 +4476,8 @@ void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << field_type; UNREACHABLE(); @@ -4752,6 +4771,8 @@ void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << type; UNREACHABLE(); @@ -4991,6 +5012,8 @@ void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { break; } + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unreachable type " << instruction->GetType(); UNREACHABLE(); diff --git a/compiler/optimizing/data_type-inl.h b/compiler/optimizing/data_type-inl.h index e389bad3ad..e2cf7a80fe 100644 --- a/compiler/optimizing/data_type-inl.h +++ b/compiler/optimizing/data_type-inl.h @@ -53,7 +53,9 @@ constexpr char DataType::TypeId(DataType::Type type) { case DataType::Type::kInt8: return 'b'; // Java byte (B). case DataType::Type::kUint16: return 'c'; // Java char (C). case DataType::Type::kInt16: return 's'; // Java short (S). + case DataType::Type::kUint32: return 'u'; // Picked 'u' for unsigned. case DataType::Type::kInt32: return 'i'; // Java int (I). + case DataType::Type::kUint64: return 'w'; // Picked 'w' for long unsigned. case DataType::Type::kInt64: return 'j'; // Java long (J). case DataType::Type::kFloat32: return 'f'; // Java float (F). case DataType::Type::kFloat64: return 'd'; // Java double (D). diff --git a/compiler/optimizing/data_type.cc b/compiler/optimizing/data_type.cc index 3c99a76c17..cb354f46cc 100644 --- a/compiler/optimizing/data_type.cc +++ b/compiler/optimizing/data_type.cc @@ -25,7 +25,9 @@ static const char* kTypeNames[] = { "Int8", "Uint16", "Int16", + "Uint32", "Int32", + "Uint64", "Int64", "Float32", "Float64", diff --git a/compiler/optimizing/data_type.h b/compiler/optimizing/data_type.h index 548fe28cee..4a6c91459f 100644 --- a/compiler/optimizing/data_type.h +++ b/compiler/optimizing/data_type.h @@ -34,7 +34,9 @@ class DataType { kInt8, kUint16, kInt16, + kUint32, kInt32, + kUint64, kInt64, kFloat32, kFloat64, @@ -55,9 +57,11 @@ class DataType { case Type::kUint16: case Type::kInt16: return 1; + case Type::kUint32: case Type::kInt32: case Type::kFloat32: return 2; + case Type::kUint64: case Type::kInt64: case Type::kFloat64: return 3; @@ -80,9 +84,11 @@ class DataType { case Type::kUint16: case Type::kInt16: return 2; + case Type::kUint32: case Type::kInt32: case Type::kFloat32: return 4; + case Type::kUint64: case Type::kInt64: case Type::kFloat64: return 8; @@ -107,7 +113,9 @@ class DataType { case Type::kInt8: case Type::kUint16: case Type::kInt16: + case Type::kUint32: case Type::kInt32: + case Type::kUint64: case Type::kInt64: return true; default: @@ -120,11 +128,12 @@ class DataType { } static bool Is64BitType(Type type) { - return type == Type::kInt64 || type == Type::kFloat64; + return type == Type::kUint64 || type == Type::kInt64 || type == Type::kFloat64; } static bool IsUnsignedType(Type type) { - return type == Type::kBool || type == Type::kUint8 || type == Type::kUint16; + return type == Type::kBool || type == Type::kUint8 || type == Type::kUint16 || + type == Type::kUint32 || type == Type::kUint64; } // Return the general kind of `type`, fusing integer-like types as Type::kInt. @@ -133,10 +142,14 @@ class DataType { case Type::kBool: case Type::kUint8: case Type::kInt8: - case Type::kInt16: case Type::kUint16: + case Type::kInt16: + case Type::kUint32: case Type::kInt32: return Type::kInt32; + case Type::kUint64: + case Type::kInt64: + return Type::kInt64; default: return type; } @@ -154,8 +167,12 @@ class DataType { return std::numeric_limits<uint16_t>::min(); case Type::kInt16: return std::numeric_limits<int16_t>::min(); + case Type::kUint32: + return std::numeric_limits<uint32_t>::min(); case Type::kInt32: return std::numeric_limits<int32_t>::min(); + case Type::kUint64: + return std::numeric_limits<uint64_t>::min(); case Type::kInt64: return std::numeric_limits<int64_t>::min(); default: @@ -176,8 +193,12 @@ class DataType { return std::numeric_limits<uint16_t>::max(); case Type::kInt16: return std::numeric_limits<int16_t>::max(); + case Type::kUint32: + return std::numeric_limits<uint32_t>::max(); case Type::kInt32: return std::numeric_limits<int32_t>::max(); + case Type::kUint64: + return std::numeric_limits<uint64_t>::max(); case Type::kInt64: return std::numeric_limits<int64_t>::max(); default: diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc index 12c69889ab..6144162f68 100644 --- a/compiler/optimizing/graph_visualizer.cc +++ b/compiler/optimizing/graph_visualizer.cc @@ -533,20 +533,9 @@ class HGraphVisualizerPrinter : public HGraphDelegateVisitor { void VisitVecHalvingAdd(HVecHalvingAdd* hadd) OVERRIDE { VisitVecBinaryOperation(hadd); - StartAttributeStream("unsigned") << std::boolalpha << hadd->IsUnsigned() << std::noboolalpha; StartAttributeStream("rounded") << std::boolalpha << hadd->IsRounded() << std::noboolalpha; } - void VisitVecMin(HVecMin* min) OVERRIDE { - VisitVecBinaryOperation(min); - StartAttributeStream("unsigned") << std::boolalpha << min->IsUnsigned() << std::noboolalpha; - } - - void VisitVecMax(HVecMax* max) OVERRIDE { - VisitVecBinaryOperation(max); - StartAttributeStream("unsigned") << std::boolalpha << max->IsUnsigned() << std::noboolalpha; - } - void VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) OVERRIDE { VisitVecOperation(instruction); StartAttributeStream("kind") << instruction->GetOpKind(); diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 452be6feae..035e5ce3e1 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -392,8 +392,9 @@ ArtMethod* HInliner::TryCHADevirtualization(ArtMethod* resolved_method) { return single_impl; } -static bool AlwaysThrows(ArtMethod* method) { - CodeItemDataAccessor accessor(method); +static bool AlwaysThrows(ArtMethod* method) + REQUIRES_SHARED(Locks::mutator_lock_) { + CodeItemDataAccessor accessor(method->DexInstructionData()); // Skip native methods, methods with try blocks, and methods that are too large. if (!accessor.HasCodeItem() || accessor.TriesSize() != 0 || @@ -1418,7 +1419,7 @@ bool HInliner::TryBuildAndInline(HInvoke* invoke_instruction, bool same_dex_file = IsSameDexFile(*outer_compilation_unit_.GetDexFile(), *method->GetDexFile()); - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); if (!accessor.HasCodeItem()) { LOG_FAIL_NO_STAT() @@ -1697,7 +1698,7 @@ bool HInliner::TryBuildAndInlineHelper(HInvoke* invoke_instruction, const DexFile::CodeItem* code_item = resolved_method->GetCodeItem(); const DexFile& callee_dex_file = *resolved_method->GetDexFile(); uint32_t method_index = resolved_method->GetDexMethodIndex(); - CodeItemDebugInfoAccessor code_item_accessor(resolved_method); + CodeItemDebugInfoAccessor code_item_accessor(resolved_method->DexInstructionDebugInfo()); ClassLinker* class_linker = caller_compilation_unit_.GetClassLinker(); Handle<mirror::DexCache> dex_cache = NewHandleIfDifferent(resolved_method->GetDexCache(), caller_compilation_unit_.GetDexCache(), diff --git a/compiler/optimizing/loop_optimization.cc b/compiler/optimizing/loop_optimization.cc index 3dc1ef7534..899496328e 100644 --- a/compiler/optimizing/loop_optimization.cc +++ b/compiler/optimizing/loop_optimization.cc @@ -30,46 +30,6 @@ namespace art { -// TODO: Clean up the packed type detection so that we have the right type straight away -// and do not need to go through this normalization. -static inline void NormalizePackedType(/* inout */ DataType::Type* type, - /* inout */ bool* is_unsigned) { - switch (*type) { - case DataType::Type::kBool: - DCHECK(!*is_unsigned); - break; - case DataType::Type::kUint8: - case DataType::Type::kInt8: - if (*is_unsigned) { - *is_unsigned = false; - *type = DataType::Type::kUint8; - } else { - *type = DataType::Type::kInt8; - } - break; - case DataType::Type::kUint16: - case DataType::Type::kInt16: - if (*is_unsigned) { - *is_unsigned = false; - *type = DataType::Type::kUint16; - } else { - *type = DataType::Type::kInt16; - } - break; - case DataType::Type::kInt32: - case DataType::Type::kInt64: - // We do not have kUint32 and kUint64 at the moment. - break; - case DataType::Type::kFloat32: - case DataType::Type::kFloat64: - DCHECK(!*is_unsigned); - break; - default: - LOG(FATAL) << "Unexpected type " << *type; - UNREACHABLE(); - } -} - // Enables vectorization (SIMDization) in the loop optimizer. static constexpr bool kEnableVectorization = true; @@ -1362,8 +1322,10 @@ bool HLoopOptimization::VectorizeUse(LoopNode* node, } if (VectorizeUse(node, r, generate_code, type, restrictions)) { if (generate_code) { - NormalizePackedType(&type, &is_unsigned); - GenerateVecOp(instruction, vector_map_->Get(r), nullptr, type); + GenerateVecOp(instruction, + vector_map_->Get(r), + nullptr, + HVecOperation::ToProperType(type, is_unsigned)); } return true; } @@ -1865,18 +1827,26 @@ void HLoopOptimization::GenerateVecOp(HInstruction* org, case Intrinsics::kMathMinLongLong: case Intrinsics::kMathMinFloatFloat: case Intrinsics::kMathMinDoubleDouble: { - NormalizePackedType(&type, &is_unsigned); vector = new (global_allocator_) - HVecMin(global_allocator_, opa, opb, type, vector_length_, is_unsigned, dex_pc); + HVecMin(global_allocator_, + opa, + opb, + HVecOperation::ToProperType(type, is_unsigned), + vector_length_, + dex_pc); break; } case Intrinsics::kMathMaxIntInt: case Intrinsics::kMathMaxLongLong: case Intrinsics::kMathMaxFloatFloat: case Intrinsics::kMathMaxDoubleDouble: { - NormalizePackedType(&type, &is_unsigned); vector = new (global_allocator_) - HVecMax(global_allocator_, opa, opb, type, vector_length_, is_unsigned, dex_pc); + HVecMax(global_allocator_, + opa, + opb, + HVecOperation::ToProperType(type, is_unsigned), + vector_length_, + dex_pc); break; } default: @@ -1987,15 +1957,13 @@ bool HLoopOptimization::VectorizeHalvingAddIdiom(LoopNode* node, VectorizeUse(node, s, generate_code, type, restrictions)) { if (generate_code) { if (vector_mode_ == kVector) { - NormalizePackedType(&type, &is_unsigned); vector_map_->Put(instruction, new (global_allocator_) HVecHalvingAdd( global_allocator_, vector_map_->Get(r), vector_map_->Get(s), - type, + HVecOperation::ToProperType(type, is_unsigned), vector_length_, is_rounded, - is_unsigned, kNoDexPc)); MaybeRecordStat(stats_, MethodCompilationStat::kLoopVectorizedIdiom); } else { @@ -2086,7 +2054,7 @@ bool HLoopOptimization::VectorizeSADIdiom(LoopNode* node, VectorizeUse(node, r, generate_code, sub_type, restrictions) && VectorizeUse(node, s, generate_code, sub_type, restrictions)) { if (generate_code) { - NormalizePackedType(&reduction_type, &is_unsigned); + reduction_type = HVecOperation::ToProperType(reduction_type, is_unsigned); if (vector_mode_ == kVector) { vector_map_->Put(instruction, new (global_allocator_) HVecSADAccumulate( global_allocator_, diff --git a/compiler/optimizing/nodes_vector.h b/compiler/optimizing/nodes_vector.h index 87dff8403b..ecabdf3b76 100644 --- a/compiler/optimizing/nodes_vector.h +++ b/compiler/optimizing/nodes_vector.h @@ -131,8 +131,6 @@ class HVecOperation : public HVariableInputSizeInstruction { } // Maps an integral type to the same-size signed type and leaves other types alone. - // Can be used to test relaxed type consistency in which packed same-size integral - // types can co-exist, but other type mixes are an error. static DataType::Type ToSignedType(DataType::Type type) { switch (type) { case DataType::Type::kBool: // 1-byte storage unit @@ -160,6 +158,11 @@ class HVecOperation : public HVariableInputSizeInstruction { } } + // Maps an integral type to the same-size (un)signed type. Leaves other types alone. + static DataType::Type ToProperType(DataType::Type type, bool is_unsigned) { + return is_unsigned ? ToUnsignedType(type) : ToSignedType(type); + } + // Helper method to determine if an instruction returns a SIMD value. // TODO: This method is needed until we introduce SIMD as proper type. static bool ReturnsSIMDValue(HInstruction* instruction) { @@ -286,6 +289,8 @@ class HVecMemoryOperation : public HVecOperation { }; // Packed type consistency checker ("same vector length" integral types may mix freely). +// Tests relaxed type consistency in which packed same-size integral types can co-exist, +// but other type mixes are an error. inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type type) { if (input->IsPhi()) { return input->GetType() == HVecOperation::kSIMDType; // carries SIMD @@ -518,7 +523,7 @@ class HVecAdd FINAL : public HVecBinaryOperation { // Performs halving add on every component in the two vectors, viz. // rounded [ x1, .. , xn ] hradd [ y1, .. , yn ] = [ (x1 + y1 + 1) >> 1, .. , (xn + yn + 1) >> 1 ] // truncated [ x1, .. , xn ] hadd [ y1, .. , yn ] = [ (x1 + y1) >> 1, .. , (xn + yn ) >> 1 ] -// for either both signed or both unsigned operands x, y. +// for either both signed or both unsigned operands x, y (reflected in packed_type). class HVecHalvingAdd FINAL : public HVecBinaryOperation { public: HVecHalvingAdd(ArenaAllocator* allocator, @@ -527,21 +532,13 @@ class HVecHalvingAdd FINAL : public HVecBinaryOperation { DataType::Type packed_type, size_t vector_length, bool is_rounded, - bool is_unsigned, uint32_t dex_pc) : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) { - // The `is_unsigned` flag should be used exclusively with the Int32 or Int64. - // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types. - DCHECK(!is_unsigned || - packed_type == DataType::Type::kInt32 || - packed_type == DataType::Type::kInt64) << packed_type; DCHECK(HasConsistentPackedTypes(left, packed_type)); DCHECK(HasConsistentPackedTypes(right, packed_type)); - SetPackedFlag<kFieldHAddIsUnsigned>(is_unsigned); SetPackedFlag<kFieldHAddIsRounded>(is_rounded); } - bool IsUnsigned() const { return GetPackedFlag<kFieldHAddIsUnsigned>(); } bool IsRounded() const { return GetPackedFlag<kFieldHAddIsRounded>(); } bool CanBeMoved() const OVERRIDE { return true; } @@ -549,9 +546,7 @@ class HVecHalvingAdd FINAL : public HVecBinaryOperation { bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { DCHECK(other->IsVecHalvingAdd()); const HVecHalvingAdd* o = other->AsVecHalvingAdd(); - return HVecOperation::InstructionDataEquals(o) && - IsUnsigned() == o->IsUnsigned() && - IsRounded() == o->IsRounded(); + return HVecOperation::InstructionDataEquals(o) && IsRounded() == o->IsRounded(); } DECLARE_INSTRUCTION(VecHalvingAdd); @@ -561,8 +556,7 @@ class HVecHalvingAdd FINAL : public HVecBinaryOperation { private: // Additional packed bits. - static constexpr size_t kFieldHAddIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits; - static constexpr size_t kFieldHAddIsRounded = kFieldHAddIsUnsigned + 1; + static constexpr size_t kFieldHAddIsRounded = HVecOperation::kNumberOfVectorOpPackedBits; static constexpr size_t kNumberOfHAddPackedBits = kFieldHAddIsRounded + 1; static_assert(kNumberOfHAddPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); }; @@ -638,7 +632,7 @@ class HVecDiv FINAL : public HVecBinaryOperation { // Takes minimum of every component in the two vectors, // viz. MIN( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ min(x1, y1), .. , min(xn, yn) ] -// for either both signed or both unsigned operands x, y. +// for either both signed or both unsigned operands x, y (reflected in packed_type). class HVecMin FINAL : public HVecBinaryOperation { public: HVecMin(ArenaAllocator* allocator, @@ -646,44 +640,23 @@ class HVecMin FINAL : public HVecBinaryOperation { HInstruction* right, DataType::Type packed_type, size_t vector_length, - bool is_unsigned, uint32_t dex_pc) : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) { - // The `is_unsigned` flag should be used exclusively with the Int32 or Int64. - // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types. - DCHECK(!is_unsigned || - packed_type == DataType::Type::kInt32 || - packed_type == DataType::Type::kInt64) << packed_type; DCHECK(HasConsistentPackedTypes(left, packed_type)); DCHECK(HasConsistentPackedTypes(right, packed_type)); - SetPackedFlag<kFieldMinOpIsUnsigned>(is_unsigned); } - bool IsUnsigned() const { return GetPackedFlag<kFieldMinOpIsUnsigned>(); } - bool CanBeMoved() const OVERRIDE { return true; } - bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { - DCHECK(other->IsVecMin()); - const HVecMin* o = other->AsVecMin(); - return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned(); - } - DECLARE_INSTRUCTION(VecMin); protected: DEFAULT_COPY_CONSTRUCTOR(VecMin); - - private: - // Additional packed bits. - static constexpr size_t kFieldMinOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits; - static constexpr size_t kNumberOfMinOpPackedBits = kFieldMinOpIsUnsigned + 1; - static_assert(kNumberOfMinOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); }; // Takes maximum of every component in the two vectors, // viz. MAX( [ x1, .. , xn ] , [ y1, .. , yn ]) = [ max(x1, y1), .. , max(xn, yn) ] -// for either both signed or both unsigned operands x, y. +// for either both signed or both unsigned operands x, y (reflected in packed_type). class HVecMax FINAL : public HVecBinaryOperation { public: HVecMax(ArenaAllocator* allocator, @@ -691,39 +664,18 @@ class HVecMax FINAL : public HVecBinaryOperation { HInstruction* right, DataType::Type packed_type, size_t vector_length, - bool is_unsigned, uint32_t dex_pc) : HVecBinaryOperation(allocator, left, right, packed_type, vector_length, dex_pc) { - // The `is_unsigned` flag should be used exclusively with the Int32 or Int64. - // This flag is a temporary measure while we do not have the Uint32 and Uint64 data types. - DCHECK(!is_unsigned || - packed_type == DataType::Type::kInt32 || - packed_type == DataType::Type::kInt64) << packed_type; DCHECK(HasConsistentPackedTypes(left, packed_type)); DCHECK(HasConsistentPackedTypes(right, packed_type)); - SetPackedFlag<kFieldMaxOpIsUnsigned>(is_unsigned); } - bool IsUnsigned() const { return GetPackedFlag<kFieldMaxOpIsUnsigned>(); } - bool CanBeMoved() const OVERRIDE { return true; } - bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { - DCHECK(other->IsVecMax()); - const HVecMax* o = other->AsVecMax(); - return HVecOperation::InstructionDataEquals(o) && IsUnsigned() == o->IsUnsigned(); - } - DECLARE_INSTRUCTION(VecMax); protected: DEFAULT_COPY_CONSTRUCTOR(VecMax); - - private: - // Additional packed bits. - static constexpr size_t kFieldMaxOpIsUnsigned = HVecOperation::kNumberOfVectorOpPackedBits; - static constexpr size_t kNumberOfMaxOpPackedBits = kFieldMaxOpIsUnsigned + 1; - static_assert(kNumberOfMaxOpPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); }; // Bitwise-ands every component in the two vectors, diff --git a/compiler/optimizing/nodes_vector_test.cc b/compiler/optimizing/nodes_vector_test.cc index ab9d7594d9..af13449646 100644 --- a/compiler/optimizing/nodes_vector_test.cc +++ b/compiler/optimizing/nodes_vector_test.cc @@ -282,143 +282,53 @@ TEST_F(NodesVectorTest, VectorAlignmentMattersOnStore) { EXPECT_FALSE(v0->Equals(v1)); // no longer equal } -TEST_F(NodesVectorTest, VectorSignMattersOnMin) { - HVecOperation* p0 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int32_parameter_, DataType::Type::kInt32, 4, kNoDexPc); - HVecOperation* p1 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int8_parameter_, DataType::Type::kInt8, 4, kNoDexPc); - HVecOperation* p2 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int16_parameter_, DataType::Type::kInt16, 4, kNoDexPc); - - HVecMin* v0 = new (GetAllocator()) HVecMin( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, /*is_unsigned*/ true, kNoDexPc); - HVecMin* v1 = new (GetAllocator()) HVecMin( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, /*is_unsigned*/ false, kNoDexPc); - HVecMin* v2 = new (GetAllocator()) HVecMin( - GetAllocator(), p0, p0, DataType::Type::kInt32, 2, /*is_unsigned*/ true, kNoDexPc); - HVecMin* v3 = new (GetAllocator()) HVecMin( - GetAllocator(), p1, p1, DataType::Type::kUint8, 16, /*is_unsigned*/ false, kNoDexPc); - HVecMin* v4 = new (GetAllocator()) HVecMin( - GetAllocator(), p1, p1, DataType::Type::kInt8, 16, /*is_unsigned*/ false, kNoDexPc); - HVecMin* v5 = new (GetAllocator()) HVecMin( - GetAllocator(), p2, p2, DataType::Type::kUint16, 8, /*is_unsigned*/ false, kNoDexPc); - HVecMin* v6 = new (GetAllocator()) HVecMin( - GetAllocator(), p2, p2, DataType::Type::kInt16, 8, /*is_unsigned*/ false, kNoDexPc); - HVecMin* min_insns[] = { v0, v1, v2, v3, v4, v5, v6 }; - - EXPECT_FALSE(p0->CanBeMoved()); - EXPECT_FALSE(p1->CanBeMoved()); - EXPECT_FALSE(p2->CanBeMoved()); - - for (HVecMin* min_insn : min_insns) { - EXPECT_TRUE(min_insn->CanBeMoved()); - } - - // Deprecated; IsUnsigned() should be removed with the introduction of Uint32 and Uint64. - EXPECT_TRUE(v0->IsUnsigned()); - EXPECT_FALSE(v1->IsUnsigned()); - EXPECT_TRUE(v2->IsUnsigned()); - - for (HVecMin* min_insn1 : min_insns) { - for (HVecMin* min_insn2 : min_insns) { - EXPECT_EQ(min_insn1 == min_insn2, min_insn1->Equals(min_insn2)); - } - } -} - -TEST_F(NodesVectorTest, VectorSignMattersOnMax) { - HVecOperation* p0 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int32_parameter_, DataType::Type::kInt32, 4, kNoDexPc); - HVecOperation* p1 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int8_parameter_, DataType::Type::kInt8, 4, kNoDexPc); - HVecOperation* p2 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int16_parameter_, DataType::Type::kInt16, 4, kNoDexPc); - - HVecMax* v0 = new (GetAllocator()) HVecMax( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, /*is_unsigned*/ true, kNoDexPc); - HVecMax* v1 = new (GetAllocator()) HVecMax( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, /*is_unsigned*/ false, kNoDexPc); - HVecMax* v2 = new (GetAllocator()) HVecMax( - GetAllocator(), p0, p0, DataType::Type::kInt32, 2, /*is_unsigned*/ true, kNoDexPc); - HVecMax* v3 = new (GetAllocator()) HVecMax( - GetAllocator(), p1, p1, DataType::Type::kUint8, 16, /*is_unsigned*/ false, kNoDexPc); - HVecMax* v4 = new (GetAllocator()) HVecMax( - GetAllocator(), p1, p1, DataType::Type::kInt8, 16, /*is_unsigned*/ false, kNoDexPc); - HVecMax* v5 = new (GetAllocator()) HVecMax( - GetAllocator(), p2, p2, DataType::Type::kUint16, 8, /*is_unsigned*/ false, kNoDexPc); - HVecMax* v6 = new (GetAllocator()) HVecMax( - GetAllocator(), p2, p2, DataType::Type::kInt16, 8, /*is_unsigned*/ false, kNoDexPc); - HVecMax* max_insns[] = { v0, v1, v2, v3, v4, v5, v6 }; - - EXPECT_FALSE(p0->CanBeMoved()); - EXPECT_FALSE(p1->CanBeMoved()); - EXPECT_FALSE(p2->CanBeMoved()); - - for (HVecMax* max_insn : max_insns) { - EXPECT_TRUE(max_insn->CanBeMoved()); - } - - // Deprecated; IsUnsigned() should be removed with the introduction of Uint32 and Uint64. - EXPECT_TRUE(v0->IsUnsigned()); - EXPECT_FALSE(v1->IsUnsigned()); - EXPECT_TRUE(v2->IsUnsigned()); - - for (HVecMax* max_insn1 : max_insns) { - for (HVecMax* max_insn2 : max_insns) { - EXPECT_EQ(max_insn1 == max_insn2, max_insn1->Equals(max_insn2)); - } - } -} - TEST_F(NodesVectorTest, VectorAttributesMatterOnHalvingAdd) { + HVecOperation* u0 = new (GetAllocator()) + HVecReplicateScalar(GetAllocator(), int32_parameter_, DataType::Type::kUint32, 4, kNoDexPc); + HVecOperation* u1 = new (GetAllocator()) + HVecReplicateScalar(GetAllocator(), int16_parameter_, DataType::Type::kUint16, 8, kNoDexPc); + HVecOperation* u2 = new (GetAllocator()) + HVecReplicateScalar(GetAllocator(), int8_parameter_, DataType::Type::kUint8, 16, kNoDexPc); + HVecOperation* p0 = new (GetAllocator()) HVecReplicateScalar(GetAllocator(), int32_parameter_, DataType::Type::kInt32, 4, kNoDexPc); HVecOperation* p1 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int8_parameter_, DataType::Type::kInt8, 4, kNoDexPc); + HVecReplicateScalar(GetAllocator(), int16_parameter_, DataType::Type::kInt16, 8, kNoDexPc); HVecOperation* p2 = new (GetAllocator()) - HVecReplicateScalar(GetAllocator(), int16_parameter_, DataType::Type::kInt16, 4, kNoDexPc); + HVecReplicateScalar(GetAllocator(), int8_parameter_, DataType::Type::kInt8, 16, kNoDexPc); HVecHalvingAdd* v0 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, - /*is_rounded*/ true, /*is_unsigned*/ true, kNoDexPc); + GetAllocator(), u0, u0, DataType::Type::kUint32, 4, /*is_rounded*/ true, kNoDexPc); HVecHalvingAdd* v1 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, - /*is_rounded*/ false, /*is_unsigned*/ true, kNoDexPc); + GetAllocator(), u0, u0, DataType::Type::kUint32, 4, /*is_rounded*/ false, kNoDexPc); HVecHalvingAdd* v2 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, - /*is_rounded*/ true, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), p0, p0, DataType::Type::kInt32, 4, /*is_rounded*/ true, kNoDexPc); HVecHalvingAdd* v3 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p0, p0, DataType::Type::kInt32, 4, - /*is_rounded*/ false, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), p0, p0, DataType::Type::kInt32, 4, /*is_rounded*/ false, kNoDexPc); + HVecHalvingAdd* v4 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p0, p0, DataType::Type::kInt32, 2, - /*is_rounded*/ true, /*is_unsigned*/ true, kNoDexPc); + GetAllocator(), u1, u1, DataType::Type::kUint16, 8, /*is_rounded*/ true, kNoDexPc); HVecHalvingAdd* v5 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p1, p1, DataType::Type::kUint8, 16, - /*is_rounded*/ true, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), u1, u1, DataType::Type::kUint16, 8, /*is_rounded*/ false, kNoDexPc); HVecHalvingAdd* v6 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p1, p1, DataType::Type::kUint8, 16, - /*is_rounded*/ false, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), p1, p1, DataType::Type::kInt16, 8, /*is_rounded*/ true, kNoDexPc); HVecHalvingAdd* v7 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p1, p1, DataType::Type::kInt8, 16, - /*is_rounded*/ true, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), p1, p1, DataType::Type::kInt16, 8, /*is_rounded*/ false, kNoDexPc); + HVecHalvingAdd* v8 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p1, p1, DataType::Type::kInt8, 16, - /*is_rounded*/ false, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), u2, u2, DataType::Type::kUint8, 16, /*is_rounded*/ true, kNoDexPc); HVecHalvingAdd* v9 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p2, p2, DataType::Type::kUint16, 8, - /*is_rounded*/ true, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), u2, u2, DataType::Type::kUint8, 16, /*is_rounded*/ false, kNoDexPc); HVecHalvingAdd* v10 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p2, p2, DataType::Type::kUint16, 8, - /*is_rounded*/ false, /*is_unsigned*/ false, kNoDexPc); + GetAllocator(), p2, p2, DataType::Type::kInt8, 16, /*is_rounded*/ true, kNoDexPc); HVecHalvingAdd* v11 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p2, p2, DataType::Type::kInt16, 2, - /*is_rounded*/ true, /*is_unsigned*/ false, kNoDexPc); - HVecHalvingAdd* v12 = new (GetAllocator()) HVecHalvingAdd( - GetAllocator(), p2, p2, DataType::Type::kInt16, 2, - /*is_rounded*/ false, /*is_unsigned*/ false, kNoDexPc); - HVecHalvingAdd* hadd_insns[] = { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 }; + GetAllocator(), p2, p2, DataType::Type::kInt8, 16, /*is_rounded*/ false, kNoDexPc); + HVecHalvingAdd* hadd_insns[] = { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 }; + + EXPECT_FALSE(u0->CanBeMoved()); + EXPECT_FALSE(u1->CanBeMoved()); + EXPECT_FALSE(u2->CanBeMoved()); EXPECT_FALSE(p0->CanBeMoved()); EXPECT_FALSE(p1->CanBeMoved()); EXPECT_FALSE(p2->CanBeMoved()); @@ -427,26 +337,18 @@ TEST_F(NodesVectorTest, VectorAttributesMatterOnHalvingAdd) { EXPECT_TRUE(hadd_insn->CanBeMoved()); } - // Deprecated; IsUnsigned() should be removed with the introduction of Uint32 and Uint64. - EXPECT_TRUE(v0->IsUnsigned()); - EXPECT_TRUE(v1->IsUnsigned()); - EXPECT_TRUE(!v2->IsUnsigned()); - EXPECT_TRUE(!v3->IsUnsigned()); - EXPECT_TRUE(v4->IsUnsigned()); - EXPECT_TRUE(v0->IsRounded()); EXPECT_TRUE(!v1->IsRounded()); EXPECT_TRUE(v2->IsRounded()); EXPECT_TRUE(!v3->IsRounded()); EXPECT_TRUE(v4->IsRounded()); - EXPECT_TRUE(v5->IsRounded()); - EXPECT_TRUE(!v6->IsRounded()); - EXPECT_TRUE(v7->IsRounded()); - EXPECT_TRUE(!v8->IsRounded()); - EXPECT_TRUE(v9->IsRounded()); - EXPECT_TRUE(!v10->IsRounded()); - EXPECT_TRUE(v11->IsRounded()); - EXPECT_TRUE(!v12->IsRounded()); + EXPECT_TRUE(!v5->IsRounded()); + EXPECT_TRUE(v6->IsRounded()); + EXPECT_TRUE(!v7->IsRounded()); + EXPECT_TRUE(v8->IsRounded()); + EXPECT_TRUE(!v9->IsRounded()); + EXPECT_TRUE(v10->IsRounded()); + EXPECT_TRUE(!v11->IsRounded()); for (HVecHalvingAdd* hadd_insn1 : hadd_insns) { for (HVecHalvingAdd* hadd_insn2 : hadd_insns) { diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc index 47ef194574..b3f23a0dcd 100644 --- a/compiler/optimizing/optimizing_compiler.cc +++ b/compiler/optimizing/optimizing_compiler.cc @@ -1410,7 +1410,7 @@ void OptimizingCompiler::GenerateJitDebugInfo(ArtMethod* method, debug::MethodDe GetCompilerDriver()->GetInstructionSetFeatures(), mini_debug_info, ArrayRef<const debug::MethodDebugInfo>(&info, 1)); - MutexLock mu(Thread::Current(), g_jit_debug_mutex); + MutexLock mu(Thread::Current(), *Locks::native_debug_interface_lock_); JITCodeEntry* entry = CreateJITCodeEntry(elf_file); IncrementJITCodeEntryRefcount(entry, info.code_address); diff --git a/compiler/optimizing/register_allocation_resolver.cc b/compiler/optimizing/register_allocation_resolver.cc index 1d3fe0334d..27f9ac3990 100644 --- a/compiler/optimizing/register_allocation_resolver.cc +++ b/compiler/optimizing/register_allocation_resolver.cc @@ -103,6 +103,7 @@ void RegisterAllocationResolver::Resolve(ArrayRef<HInstruction* const> safepoint case DataType::Type::kFloat64: slot += long_spill_slots; FALLTHROUGH_INTENDED; + case DataType::Type::kUint64: case DataType::Type::kInt64: slot += float_spill_slots; FALLTHROUGH_INTENDED; @@ -110,6 +111,7 @@ void RegisterAllocationResolver::Resolve(ArrayRef<HInstruction* const> safepoint slot += int_spill_slots; FALLTHROUGH_INTENDED; case DataType::Type::kReference: + case DataType::Type::kUint32: case DataType::Type::kInt32: case DataType::Type::kUint16: case DataType::Type::kUint8: diff --git a/compiler/optimizing/register_allocator_graph_color.cc b/compiler/optimizing/register_allocator_graph_color.cc index ad5248e982..fa7ad82316 100644 --- a/compiler/optimizing/register_allocator_graph_color.cc +++ b/compiler/optimizing/register_allocator_graph_color.cc @@ -1972,6 +1972,8 @@ void RegisterAllocatorGraphColor::AllocateSpillSlots(ArrayRef<InterferenceNode* case DataType::Type::kInt16: int_intervals.push_back(parent); break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unexpected type for interval " << node->GetInterval()->GetType(); UNREACHABLE(); diff --git a/compiler/optimizing/register_allocator_linear_scan.cc b/compiler/optimizing/register_allocator_linear_scan.cc index cfe63bd758..216fb57a96 100644 --- a/compiler/optimizing/register_allocator_linear_scan.cc +++ b/compiler/optimizing/register_allocator_linear_scan.cc @@ -1131,6 +1131,8 @@ void RegisterAllocatorLinearScan::AllocateSpillSlotFor(LiveInterval* interval) { case DataType::Type::kInt16: spill_slots = &int_spill_slots_; break; + case DataType::Type::kUint32: + case DataType::Type::kUint64: case DataType::Type::kVoid: LOG(FATAL) << "Unexpected type for interval " << interval->GetType(); } diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp index 9876febfc5..ab06ddda2d 100644 --- a/dex2oat/Android.bp +++ b/dex2oat/Android.bp @@ -106,7 +106,6 @@ cc_defaults { compile_multilib: "prefer32", }, }, - header_libs: [ "dex2oat_headers", "art_cmdlineparser_headers", @@ -122,6 +121,7 @@ art_cc_binary { "libart-compiler", "libart-dexlayout", "libart", + "libdexfile", "libbase", "liblz4", "libsigchain", @@ -152,6 +152,7 @@ art_cc_binary { "libartd-compiler", "libartd-dexlayout", "libartd", + "libdexfile", "libbase", "liblz4", "libsigchain", diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 8555abf9fd..c4e53987eb 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -605,6 +605,7 @@ class Dex2Oat FINAL { input_vdex_fd_(-1), output_vdex_fd_(-1), input_vdex_file_(nullptr), + dm_fd_(-1), zip_fd_(-1), image_base_(0U), image_classes_zip_filename_(nullptr), @@ -757,6 +758,11 @@ class Dex2Oat FINAL { Usage("--oat-fd should not be used with --image"); } + if ((input_vdex_fd_ != -1 || !input_vdex_.empty()) && + (dm_fd_ != -1 || !dm_file_location_.empty())) { + Usage("An input vdex should not be passed with a .dm file"); + } + if (!parser_options->oat_symbols.empty() && parser_options->oat_symbols.size() != oat_filenames_.size()) { Usage("--oat-file arguments do not match --oat-symbols arguments"); @@ -1176,6 +1182,8 @@ class Dex2Oat FINAL { AssignIfExists(args, M::OutputVdexFd, &output_vdex_fd_); AssignIfExists(args, M::InputVdex, &input_vdex_); AssignIfExists(args, M::OutputVdex, &output_vdex_); + AssignIfExists(args, M::DmFd, &dm_fd_); + AssignIfExists(args, M::DmFile, &dm_file_location_); AssignIfExists(args, M::OatFd, &oat_fd_); AssignIfExists(args, M::OatLocation, &oat_location_); AssignIfExists(args, M::Watchdog, &parser_options->watch_dog_enabled); @@ -1389,6 +1397,42 @@ class Dex2Oat FINAL { } } + if (dm_fd_ != -1 || !dm_file_location_.empty()) { + std::string error_msg; + if (dm_fd_ != -1) { + dm_file_.reset(ZipArchive::OpenFromFd(dm_fd_, "DexMetadata", &error_msg)); + } else { + dm_file_.reset(ZipArchive::Open(dm_file_location_.c_str(), &error_msg)); + } + if (dm_file_ == nullptr) { + LOG(WARNING) << "Could not open DexMetadata archive " << error_msg; + } + } + + if (dm_file_ != nullptr) { + DCHECK(input_vdex_file_ == nullptr); + std::string error_msg; + static const char* kDexMetadata = "DexMetadata"; + std::unique_ptr<ZipEntry> zip_entry(dm_file_->Find(VdexFile::kVdexNameInDmFile, &error_msg)); + if (zip_entry == nullptr) { + LOG(INFO) << "No " << VdexFile::kVdexNameInDmFile << " file in DexMetadata archive. " + << "Not doing fast verification."; + } else { + std::unique_ptr<MemMap> input_file; + if (zip_entry->IsUncompressed()) { + input_file.reset(zip_entry->MapDirectlyFromFile(VdexFile::kVdexNameInDmFile, &error_msg)); + } else { + input_file.reset(zip_entry->ExtractToMemMap( + kDexMetadata, VdexFile::kVdexNameInDmFile, &error_msg)); + } + if (input_file == nullptr) { + LOG(WARNING) << "Could not open vdex file in DexMetadata archive: " << error_msg; + } else { + input_vdex_file_ = std::make_unique<VdexFile>(input_file.release()); + } + } + } + // Swap file handling // // If the swap fd is not -1, we assume this is the file descriptor of an open but unlinked file @@ -2240,7 +2284,7 @@ class Dex2Oat FINAL { } bool DoEagerUnquickeningOfVdex() const { - return MayInvalidateVdexMetadata(); + return MayInvalidateVdexMetadata() && dm_file_ == nullptr; } bool LoadProfile() { @@ -2790,6 +2834,9 @@ class Dex2Oat FINAL { std::string input_vdex_; std::string output_vdex_; std::unique_ptr<VdexFile> input_vdex_file_; + int dm_fd_; + std::string dm_file_location_; + std::unique_ptr<ZipArchive> dm_file_; std::vector<const char*> dex_filenames_; std::vector<const char*> dex_locations_; int zip_fd_; diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc index a2e2b48956..0eecc84605 100644 --- a/dex2oat/dex2oat_options.cc +++ b/dex2oat/dex2oat_options.cc @@ -86,6 +86,12 @@ static void AddGeneratedArtifactMappings(Builder& builder) { .Define("--output-vdex=_") .WithType<std::string>() .IntoKey(M::OutputVdex) + .Define("--dm-fd=_") + .WithType<int>() + .IntoKey(M::DmFd) + .Define("--dm-file=_") + .WithType<std::string>() + .IntoKey(M::DmFile) .Define("--oat-file=_") .WithType<std::vector<std::string>>().AppendValues() .IntoKey(M::OatFiles) diff --git a/dex2oat/dex2oat_options.def b/dex2oat/dex2oat_options.def index 9362a3df6f..9a8bdf4aee 100644 --- a/dex2oat/dex2oat_options.def +++ b/dex2oat/dex2oat_options.def @@ -43,6 +43,8 @@ DEX2OAT_OPTIONS_KEY (int, InputVdexFd) DEX2OAT_OPTIONS_KEY (std::string, InputVdex) DEX2OAT_OPTIONS_KEY (int, OutputVdexFd) DEX2OAT_OPTIONS_KEY (std::string, OutputVdex) +DEX2OAT_OPTIONS_KEY (int, DmFd) +DEX2OAT_OPTIONS_KEY (std::string, DmFile) DEX2OAT_OPTIONS_KEY (std::vector<std::string>, OatFiles) DEX2OAT_OPTIONS_KEY (std::vector<std::string>, OatSymbols) DEX2OAT_OPTIONS_KEY (int, OatFd) diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 6fcf6952e8..5614ac6458 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -783,7 +783,7 @@ class Dex2oatLayoutTest : public Dex2oatTest { app_image_file_name, /* use_fd */ true, /* num_profile_classes */ 1, - { input_vdex, output_vdex, kDisableCompactDex }); + { input_vdex, output_vdex }); EXPECT_GT(vdex_file1->GetLength(), 0u); } { @@ -904,7 +904,7 @@ class Dex2oatUnquickenTest : public Dex2oatTest { GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kQuicken, - { input_vdex, output_vdex, kDisableCompactDex }, + { input_vdex, output_vdex }, /* expect_success */ true, /* use_fd */ true); EXPECT_GT(vdex_file1->GetLength(), 0u); diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index c7e9cdaae0..d245cd1c63 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -3367,7 +3367,10 @@ bool OatWriter::WriteDexFiles(OutputStream* out, File* file, bool update_input_v // Write shared dex file data section and fix up the dex file headers. vdex_dex_shared_data_offset_ = vdex_size_; + uint32_t shared_data_size = 0u; + if (dex_container_ != nullptr) { + CHECK(!update_input_vdex) << "Update input vdex should have empty dex container"; DexContainer::Section* const section = dex_container_->GetDataSection(); if (section->Size() > 0) { const uint32_t shared_data_offset = vdex_size_; @@ -3376,7 +3379,7 @@ bool OatWriter::WriteDexFiles(OutputStream* out, File* file, bool update_input_v LOG(ERROR) << "Expected offset " << shared_data_offset << " but got " << existing_offset; return false; } - const uint32_t shared_data_size = section->Size(); + shared_data_size = section->Size(); if (!out->WriteFully(section->Begin(), shared_data_size)) { LOG(ERROR) << "Failed to write shared data!"; return false; @@ -3400,8 +3403,6 @@ bool OatWriter::WriteDexFiles(OutputStream* out, File* file, bool update_input_v return false; } } - vdex_size_ += shared_data_size; - size_dex_file_ += shared_data_size; section->Clear(); if (!out->Flush()) { PLOG(ERROR) << "Failed to flush after writing shared dex section."; @@ -3409,9 +3410,35 @@ bool OatWriter::WriteDexFiles(OutputStream* out, File* file, bool update_input_v } } dex_container_.reset(); + } else { + if (update_input_vdex) { + for (OatDexFile& oat_dex_file : oat_dex_files_) { + DexFile::Header header; + if (!file->PreadFully(&header, sizeof(header), oat_dex_file.dex_file_offset_)) { + PLOG(ERROR) << "Failed to read dex header"; + return false; + } + if (!CompactDexFile::IsMagicValid(header.magic_)) { + // Non compact dex does not have shared data section. + continue; + } + const uint32_t expected_data_off = vdex_dex_shared_data_offset_ - + oat_dex_file.dex_file_offset_; + if (header.data_off_ != expected_data_off) { + PLOG(ERROR) << "Shared data section offset " << header.data_off_ + << " does not match expected value " << expected_data_off; + return false; + } + // The different dex files currently can have different data sizes since + // the dex writer writes them one at a time into the shared section.:w + shared_data_size = std::max(shared_data_size, header.data_size_); + } + } } + vdex_size_ += shared_data_size; + size_dex_file_ += shared_data_size; } else { - vdex_dex_shared_data_offset_ = vdex_size_; + vdex_dex_shared_data_offset_ = vdex_size_; } return true; diff --git a/dexdump/Android.bp b/dexdump/Android.bp index eca08448bc..f6b7a6b68a 100644 --- a/dexdump/Android.bp +++ b/dexdump/Android.bp @@ -45,7 +45,6 @@ art_cc_binary { host_supported: true, device_supported: false, static_libs: [ - "libdexfile", "libbase", ] + art_static_dependencies, target: { diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc index 24f41aba2e..01b28b55cf 100644 --- a/dexdump/dexdump.cc +++ b/dexdump/dexdump.cc @@ -50,7 +50,7 @@ #include "android-base/logging.h" #include "android-base/stringprintf.h" -#include "dex/code_item_accessors-no_art-inl.h" +#include "dex/code_item_accessors-inl.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_exception_helpers.h" #include "dex/dex_file_loader.h" diff --git a/dexdump/dexdump_cfg.cc b/dexdump/dexdump_cfg.cc index 0e313572bc..69ee0682a3 100644 --- a/dexdump/dexdump_cfg.cc +++ b/dexdump/dexdump_cfg.cc @@ -25,7 +25,7 @@ #include <set> #include <sstream> -#include "dex/code_item_accessors-no_art-inl.h" +#include "dex/code_item_accessors-inl.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_exception_helpers.h" #include "dex/dex_instruction-inl.h" diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp index 63650bf121..3ea7f4ba82 100644 --- a/dexlayout/Android.bp +++ b/dexlayout/Android.bp @@ -26,7 +26,10 @@ art_cc_defaults { "dex_writer.cc", ], export_include_dirs: ["."], - shared_libs: ["libbase"], + shared_libs: [ + "libdexfile", + "libbase", + ], static_libs: ["libz"], } diff --git a/dexlayout/dex_ir.h b/dexlayout/dex_ir.h index 1a84d2307d..d28b824c7b 100644 --- a/dexlayout/dex_ir.h +++ b/dexlayout/dex_ir.h @@ -27,8 +27,8 @@ #include "base/stl_util.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_types.h" +#include "dex/utf.h" #include "leb128.h" -#include "utf.h" namespace art { namespace dex_ir { diff --git a/dexlayout/dex_writer.cc b/dexlayout/dex_writer.cc index 778681e7b7..808bfad029 100644 --- a/dexlayout/dex_writer.cc +++ b/dexlayout/dex_writer.cc @@ -25,8 +25,8 @@ #include "dex/dex_file_layout.h" #include "dex/dex_file_types.h" #include "dex/standard_dex_file.h" +#include "dex/utf.h" #include "dexlayout.h" -#include "utf.h" namespace art { diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc index ca02052299..31a146d90e 100644 --- a/dexlist/dexlist.cc +++ b/dexlist/dexlist.cc @@ -34,7 +34,7 @@ #include <android-base/logging.h> -#include "dex/code_item_accessors-no_art-inl.h" +#include "dex/code_item_accessors-inl.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_loader.h" diff --git a/oatdump/Android.bp b/oatdump/Android.bp index 4851722734..c93c172eb4 100644 --- a/oatdump/Android.bp +++ b/oatdump/Android.bp @@ -36,6 +36,7 @@ art_cc_binary { "libart", "libart-compiler", "libart-disassembler", + "libdexfile", "libbase", ], } @@ -50,6 +51,7 @@ art_cc_binary { "libartd", "libartd-compiler", "libartd-disassembler", + "libdexfile", "libbase", ], } diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index 4324dbad65..6c9f569b19 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -2548,7 +2548,7 @@ class ImageDumper { } } } else { - CodeItemDataAccessor code_item_accessor(method); + CodeItemDataAccessor code_item_accessor(method->DexInstructionData()); size_t dex_instruction_bytes = code_item_accessor.InsnsSizeInCodeUnits() * 2; stats_.dex_instruction_bytes += dex_instruction_bytes; diff --git a/openjdkjvmti/Android.bp b/openjdkjvmti/Android.bp index 0283999d54..1500bcae24 100644 --- a/openjdkjvmti/Android.bp +++ b/openjdkjvmti/Android.bp @@ -58,6 +58,7 @@ cc_defaults { "libopenjdkjvmti_headers", ], shared_libs: [ + "libdexfile", "libbase", ], } diff --git a/openjdkjvmti/ti_class_loader.h b/openjdkjvmti/ti_class_loader.h index 27ea3f5191..ceb7b331de 100644 --- a/openjdkjvmti/ti_class_loader.h +++ b/openjdkjvmti/ti_class_loader.h @@ -41,6 +41,7 @@ #include "base/array_slice.h" #include "class_linker.h" #include "dex/dex_file.h" +#include "dex/utf.h" #include "gc_root-inl.h" #include "globals.h" #include "jni_env_ext-inl.h" @@ -60,7 +61,6 @@ #include "thread_list.h" #include "ti_class_definition.h" #include "transform.h" -#include "utf.h" #include "utils/dex_cache_arrays_layout-inl.h" namespace openjdkjvmti { diff --git a/openjdkjvmti/ti_method.cc b/openjdkjvmti/ti_method.cc index 3f144c8f0f..83d64ef1d8 100644 --- a/openjdkjvmti/ti_method.cc +++ b/openjdkjvmti/ti_method.cc @@ -123,7 +123,7 @@ jvmtiError MethodUtil::GetBytecodes(jvmtiEnv* env, } art::ScopedObjectAccess soa(art::Thread::Current()); - art::CodeItemInstructionAccessor accessor(art_method); + art::CodeItemInstructionAccessor accessor(art_method->DexInstructions()); if (!accessor.HasCodeItem()) { *size_ptr = 0; *bytecode_ptr = nullptr; @@ -168,7 +168,7 @@ jvmtiError MethodUtil::GetArgumentsSize(jvmtiEnv* env ATTRIBUTE_UNUSED, } DCHECK_NE(art_method->GetCodeItemOffset(), 0u); - *size_ptr = art::CodeItemDataAccessor(art_method).InsSize(); + *size_ptr = art_method->DexInstructionData().InsSize(); return ERR(NONE); } @@ -200,7 +200,7 @@ jvmtiError MethodUtil::GetLocalVariableTable(jvmtiEnv* env, // TODO HasCodeItem == false means that the method is abstract (or native, but we check that // earlier). We should check what is returned by the RI in this situation since it's not clear // what the appropriate return value is from the spec. - art::CodeItemDebugInfoAccessor accessor(art_method); + art::CodeItemDebugInfoAccessor accessor(art_method->DexInstructionDebugInfo()); if (!accessor.HasCodeItem()) { return ERR(ABSENT_INFORMATION); } @@ -301,7 +301,7 @@ jvmtiError MethodUtil::GetMaxLocals(jvmtiEnv* env ATTRIBUTE_UNUSED, } DCHECK_NE(art_method->GetCodeItemOffset(), 0u); - *max_ptr = art::CodeItemDataAccessor(art_method).RegistersSize(); + *max_ptr = art_method->DexInstructionData().RegistersSize(); return ERR(NONE); } @@ -480,7 +480,7 @@ jvmtiError MethodUtil::GetLineNumberTable(jvmtiEnv* env, return ERR(NULL_POINTER); } - accessor = art::CodeItemDebugInfoAccessor(art_method); + accessor = art::CodeItemDebugInfoAccessor(art_method->DexInstructionDebugInfo()); dex_file = art_method->GetDexFile(); DCHECK(accessor.HasCodeItem()) << art_method->PrettyMethod() << " " << dex_file->GetLocation(); } @@ -567,7 +567,7 @@ class CommonLocalVariableClosure : public art::Closure { // TODO It might be useful to fake up support for get at least on proxy frames. result_ = ERR(OPAQUE_FRAME); return; - } else if (art::CodeItemDataAccessor(method).RegistersSize() <= slot_) { + } else if (method->DexInstructionData().RegistersSize() <= slot_) { result_ = ERR(INVALID_SLOT); return; } @@ -618,7 +618,7 @@ class CommonLocalVariableClosure : public art::Closure { if (dex_file == nullptr) { return ERR(OPAQUE_FRAME); } - art::CodeItemDebugInfoAccessor accessor(method); + art::CodeItemDebugInfoAccessor accessor(method->DexInstructionDebugInfo()); if (!accessor.HasCodeItem()) { return ERR(OPAQUE_FRAME); } diff --git a/openjdkjvmti/ti_redefine.h b/openjdkjvmti/ti_redefine.h index b537e1b01c..c920707afd 100644 --- a/openjdkjvmti/ti_redefine.h +++ b/openjdkjvmti/ti_redefine.h @@ -41,6 +41,7 @@ #include "base/array_ref.h" #include "class_linker.h" #include "dex/dex_file.h" +#include "dex/utf.h" #include "gc_root-inl.h" #include "globals.h" #include "jni_env_ext-inl.h" @@ -60,7 +61,6 @@ #include "thread_list.h" #include "ti_class_definition.h" #include "transform.h" -#include "utf.h" #include "utils/dex_cache_arrays_layout-inl.h" namespace openjdkjvmti { diff --git a/openjdkjvmti/ti_stack.cc b/openjdkjvmti/ti_stack.cc index bc77753f8f..373944f179 100644 --- a/openjdkjvmti/ti_stack.cc +++ b/openjdkjvmti/ti_stack.cc @@ -1045,7 +1045,7 @@ jvmtiError StackUtil::NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) if (shadow_frame == nullptr) { needs_instrument = true; const size_t frame_id = visitor.GetFrameId(); - const uint16_t num_regs = art::CodeItemDataAccessor(method).RegistersSize(); + const uint16_t num_regs = method->DexInstructionData().RegistersSize(); shadow_frame = target->FindOrCreateDebuggerShadowFrame(frame_id, num_regs, method, diff --git a/openjdkjvmti/transform.cc b/openjdkjvmti/transform.cc index 8445ecab16..af838d62b9 100644 --- a/openjdkjvmti/transform.cc +++ b/openjdkjvmti/transform.cc @@ -39,6 +39,7 @@ #include "class_linker.h" #include "dex/dex_file.h" #include "dex/dex_file_types.h" +#include "dex/utf.h" #include "events-inl.h" #include "gc_root-inl.h" #include "globals.h" @@ -58,7 +59,6 @@ #include "thread_list.h" #include "ti_redefine.h" #include "transform.h" -#include "utf.h" #include "utils/dex_cache_arrays_layout-inl.h" namespace openjdkjvmti { diff --git a/profman/Android.bp b/profman/Android.bp index ea682b40a0..6592b9dec0 100644 --- a/profman/Android.bp +++ b/profman/Android.bp @@ -31,6 +31,7 @@ cc_defaults { }, shared_libs: [ + "libdexfile", "libbase", ], } diff --git a/profman/profile_assistant.cc b/profman/profile_assistant.cc index ff02b5d59f..a00b1fa5bd 100644 --- a/profman/profile_assistant.cc +++ b/profman/profile_assistant.cc @@ -31,12 +31,13 @@ static constexpr const uint32_t kMinNewClassesPercentChangeForCompilation = 2; ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfilesInternal( const std::vector<ScopedFlock>& profile_files, - const ScopedFlock& reference_profile_file) { + const ScopedFlock& reference_profile_file, + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn) { DCHECK(!profile_files.empty()); ProfileCompilationInfo info; // Load the reference profile. - if (!info.Load(reference_profile_file->Fd())) { + if (!info.Load(reference_profile_file->Fd(), /*merge_classes*/ true, filter_fn)) { LOG(WARNING) << "Could not load reference profile file"; return kErrorBadProfiles; } @@ -48,7 +49,7 @@ ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfilesInternal( // Merge all current profiles. for (size_t i = 0; i < profile_files.size(); i++) { ProfileCompilationInfo cur_info; - if (!cur_info.Load(profile_files[i]->Fd())) { + if (!cur_info.Load(profile_files[i]->Fd(), /*merge_classes*/ true, filter_fn)) { LOG(WARNING) << "Could not load profile file at index " << i; return kErrorBadProfiles; } @@ -122,7 +123,8 @@ class ScopedFlockList { ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfiles( const std::vector<int>& profile_files_fd, - int reference_profile_file_fd) { + int reference_profile_file_fd, + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn) { DCHECK_GE(reference_profile_file_fd, 0); std::string error; @@ -143,12 +145,15 @@ ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfiles( return kErrorCannotLock; } - return ProcessProfilesInternal(profile_files.Get(), reference_profile_file); + return ProcessProfilesInternal(profile_files.Get(), + reference_profile_file, + filter_fn); } ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfiles( const std::vector<std::string>& profile_files, - const std::string& reference_profile_file) { + const std::string& reference_profile_file, + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn) { std::string error; ScopedFlockList profile_files_list(profile_files.size()); @@ -164,7 +169,9 @@ ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfiles( return kErrorCannotLock; } - return ProcessProfilesInternal(profile_files_list.Get(), locked_reference_profile_file); + return ProcessProfilesInternal(profile_files_list.Get(), + locked_reference_profile_file, + filter_fn); } } // namespace art diff --git a/profman/profile_assistant.h b/profman/profile_assistant.h index be703abda8..ee555840d7 100644 --- a/profman/profile_assistant.h +++ b/profman/profile_assistant.h @@ -53,16 +53,21 @@ class ProfileAssistant { // static ProcessingResult ProcessProfiles( const std::vector<std::string>& profile_files, - const std::string& reference_profile_file); + const std::string& reference_profile_file, + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn + = ProfileCompilationInfo::ProfileFilterFnAcceptAll); static ProcessingResult ProcessProfiles( const std::vector<int>& profile_files_fd_, - int reference_profile_file_fd); + int reference_profile_file_fd, + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn + = ProfileCompilationInfo::ProfileFilterFnAcceptAll); private: static ProcessingResult ProcessProfilesInternal( const std::vector<ScopedFlock>& profile_files, - const ScopedFlock& reference_profile_file); + const ScopedFlock& reference_profile_file, + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn); DISALLOW_COPY_AND_ASSIGN(ProfileAssistant); }; diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc index c75f3e9688..79310ac166 100644 --- a/profman/profile_assistant_test.cc +++ b/profman/profile_assistant_test.cc @@ -16,6 +16,7 @@ #include <gtest/gtest.h> +#include "android-base/strings.h" #include "art_method-inl.h" #include "base/unix_file/fd_file.h" #include "common_runtime_test.h" @@ -51,6 +52,28 @@ class ProfileAssistantTest : public CommonRuntimeTest { uint32_t dex_location_checksum1 = checksum; std::string dex_location2 = "location2" + id; uint32_t dex_location_checksum2 = 10 * checksum; + SetupProfile(dex_location1, + dex_location_checksum1, + dex_location2, + dex_location_checksum2, + number_of_methods, + number_of_classes, + profile, + info, + start_method_index, + reverse_dex_write_order); + } + + void SetupProfile(const std::string& dex_location1, + uint32_t dex_location_checksum1, + const std::string& dex_location2, + uint32_t dex_location_checksum2, + uint16_t number_of_methods, + uint16_t number_of_classes, + const ScratchFile& profile, + ProfileCompilationInfo* info, + uint16_t start_method_index = 0, + bool reverse_dex_write_order = false) { for (uint16_t i = start_method_index; i < start_method_index + number_of_methods; i++) { // reverse_dex_write_order controls the order in which the dex files will be added to // the profile and thus written to disk. @@ -1128,4 +1151,89 @@ TEST_F(ProfileAssistantTest, DumpOnly) { } } +TEST_F(ProfileAssistantTest, MergeProfilesWithFilter) { + ScratchFile profile1; + ScratchFile profile2; + ScratchFile reference_profile; + + std::vector<int> profile_fds({ + GetFd(profile1), + GetFd(profile2)}); + int reference_profile_fd = GetFd(reference_profile); + + // Use a real dex file to generate profile test data. + // The file will be used during merging to filter unwanted data. + std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles("ProfileTestMultiDex"); + const DexFile& d1 = *dex_files[0]; + const DexFile& d2 = *dex_files[1]; + // The new profile info will contain the methods with indices 0-100. + const uint16_t kNumberOfMethodsToEnableCompilation = 100; + ProfileCompilationInfo info1; + SetupProfile(d1.GetLocation(), d1.GetLocationChecksum(), "p1", 1, + kNumberOfMethodsToEnableCompilation, 0, profile1, &info1); + ProfileCompilationInfo info2; + SetupProfile(d2.GetLocation(), d2.GetLocationChecksum(), "p2", 2, + kNumberOfMethodsToEnableCompilation, 0, profile2, &info2); + + + // The reference profile info will contain the methods with indices 50-150. + const uint16_t kNumberOfMethodsAlreadyCompiled = 100; + ProfileCompilationInfo reference_info; + SetupProfile(d1.GetLocation(), d1.GetLocationChecksum(), "p1", 1, + kNumberOfMethodsAlreadyCompiled, 0, reference_profile, + &reference_info, kNumberOfMethodsToEnableCompilation / 2); + + // Run profman and pass the dex file with --apk-fd. + android::base::unique_fd apk_fd( + open(GetTestDexFileName("ProfileTestMultiDex").c_str(), O_RDONLY)); + ASSERT_GE(apk_fd.get(), 0); + + std::string profman_cmd = GetProfmanCmd(); + std::vector<std::string> argv_str; + argv_str.push_back(profman_cmd); + argv_str.push_back("--profile-file-fd=" + std::to_string(profile1.GetFd())); + argv_str.push_back("--profile-file-fd=" + std::to_string(profile2.GetFd())); + argv_str.push_back("--reference-profile-file-fd=" + std::to_string(reference_profile.GetFd())); + argv_str.push_back("--apk-fd=" + std::to_string(apk_fd.get())); + std::string error; + + EXPECT_EQ(ExecAndReturnCode(argv_str, &error), 0) << error; + + // Verify that we can load the result. + + ProfileCompilationInfo result; + ASSERT_TRUE(reference_profile.GetFile()->ResetOffset()); + ASSERT_TRUE(result.Load(reference_profile_fd)); + + + ASSERT_TRUE(profile1.GetFile()->ResetOffset()); + ASSERT_TRUE(profile2.GetFile()->ResetOffset()); + ASSERT_TRUE(reference_profile.GetFile()->ResetOffset()); + + // Verify that the result filtered out data not belonging to the dex file. + // This is equivalent to checking that the result is equal to the merging of + // all profiles while filtering out data not belonging to the dex file. + + ProfileCompilationInfo::ProfileLoadFilterFn filter_fn = + [&d1, &d2](const std::string& dex_location, uint32_t checksum) -> bool { + return (dex_location == ProfileCompilationInfo::GetProfileDexFileKey(d1.GetLocation()) + && checksum == d1.GetLocationChecksum()) + || (dex_location == ProfileCompilationInfo::GetProfileDexFileKey(d2.GetLocation()) + && checksum == d2.GetLocationChecksum()); + }; + + ProfileCompilationInfo info1_filter; + ProfileCompilationInfo info2_filter; + ProfileCompilationInfo expected; + + info2_filter.Load(profile1.GetFd(), /*merge_classes*/ true, filter_fn); + info2_filter.Load(profile2.GetFd(), /*merge_classes*/ true, filter_fn); + expected.Load(reference_profile.GetFd(), /*merge_classes*/ true, filter_fn); + + ASSERT_TRUE(expected.MergeWith(info1_filter)); + ASSERT_TRUE(expected.MergeWith(info2_filter)); + + ASSERT_TRUE(expected.Equals(result)); +} + } // namespace art diff --git a/profman/profman.cc b/profman/profman.cc index ea6c382a81..387ce8dfae 100644 --- a/profman/profman.cc +++ b/profman/profman.cc @@ -18,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> #include <sys/file.h> +#include <sys/param.h> #include <sys/stat.h> #include <unistd.h> @@ -297,6 +298,22 @@ class ProfMan FINAL { } } + struct ProfileFilterKey { + ProfileFilterKey(const std::string& dex_location, uint32_t checksum) + : dex_location_(dex_location), checksum_(checksum) {} + const std::string dex_location_; + uint32_t checksum_; + + bool operator==(const ProfileFilterKey& other) const { + return checksum_ == other.checksum_ && dex_location_ == other.dex_location_; + } + bool operator<(const ProfileFilterKey& other) const { + return checksum_ == other.checksum_ + ? dex_location_ < other.dex_location_ + : checksum_ < other.checksum_; + } + }; + ProfileAssistant::ProcessingResult ProcessProfiles() { // Validate that at least one profile file was passed, as well as a reference profile. if (profile_files_.empty() && profile_files_fd_.empty()) { @@ -310,6 +327,27 @@ class ProfMan FINAL { Usage("Options --profile-file-fd and --reference-profile-file-fd " "should only be used together"); } + + // Check if we have any apks which we should use to filter the profile data. + std::set<ProfileFilterKey> profile_filter_keys; + if (!GetProfileFilterKeyFromApks(&profile_filter_keys)) { + return ProfileAssistant::kErrorIO; + } + + // Build the profile filter function. If the set of keys is empty it means we + // don't have any apks; as such we do not filter anything. + const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn = + [profile_filter_keys](const std::string& dex_location, uint32_t checksum) { + if (profile_filter_keys.empty()) { + // No --apk was specified. Accept all dex files. + return true; + } else { + bool res = profile_filter_keys.find( + ProfileFilterKey(dex_location, checksum)) != profile_filter_keys.end(); + return res; + } + }; + ProfileAssistant::ProcessingResult result; if (profile_files_.empty()) { @@ -317,10 +355,13 @@ class ProfMan FINAL { // so don't check the usage. File file(reference_profile_file_fd_, false); result = ProfileAssistant::ProcessProfiles(profile_files_fd_, - reference_profile_file_fd_); + reference_profile_file_fd_, + filter_fn); CloseAllFds(profile_files_fd_, "profile_files_fd_"); } else { - result = ProfileAssistant::ProcessProfiles(profile_files_, reference_profile_file_); + result = ProfileAssistant::ProcessProfiles(profile_files_, + reference_profile_file_, + filter_fn); } return result; } @@ -329,18 +370,48 @@ class ProfMan FINAL { return skip_apk_verification_; } - void OpenApkFilesFromLocations(std::vector<std::unique_ptr<const DexFile>>* dex_files) const { + bool GetProfileFilterKeyFromApks(std::set<ProfileFilterKey>* profile_filter_keys) { + auto process_fn = [profile_filter_keys](std::unique_ptr<const DexFile>&& dex_file) { + // Store the profile key of the location instead of the location itself. + // This will make the matching in the profile filter method much easier. + profile_filter_keys->emplace(ProfileCompilationInfo::GetProfileDexFileKey( + dex_file->GetLocation()), dex_file->GetLocationChecksum()); + }; + return OpenApkFilesFromLocations(process_fn); + } + + bool OpenApkFilesFromLocations(std::vector<std::unique_ptr<const DexFile>>* dex_files) { + auto process_fn = [dex_files](std::unique_ptr<const DexFile>&& dex_file) { + dex_files->emplace_back(std::move(dex_file)); + }; + return OpenApkFilesFromLocations(process_fn); + } + + bool OpenApkFilesFromLocations( + std::function<void(std::unique_ptr<const DexFile>&&)> process_fn) { bool use_apk_fd_list = !apks_fd_.empty(); if (use_apk_fd_list) { // Get the APKs from the collection of FDs. - CHECK_EQ(dex_locations_.size(), apks_fd_.size()); + if (dex_locations_.empty()) { + // Try to compute the dex locations from the file paths of the descriptions. + // This will make it easier to invoke profman with --apk-fd and without + // being force to pass --dex-location when the location would be the apk path. + if (!ComputeDexLocationsFromApkFds()) { + return false; + } + } else { + if (dex_locations_.size() != apks_fd_.size()) { + Usage("The number of apk-fds must match the number of dex-locations."); + } + } } else if (!apk_files_.empty()) { - // Get the APKs from the collection of filenames. - CHECK_EQ(dex_locations_.size(), apk_files_.size()); + if (dex_locations_.size() != apk_files_.size()) { + Usage("The number of apk-fds must match the number of dex-locations."); + } } else { // No APKs were specified. CHECK(dex_locations_.empty()); - return; + return true; } static constexpr bool kVerifyChecksum = true; for (size_t i = 0; i < dex_locations_.size(); ++i) { @@ -355,8 +426,8 @@ class ProfMan FINAL { &error_msg, &dex_files_for_location)) { } else { - LOG(WARNING) << "OpenZip failed for '" << dex_locations_[i] << "' " << error_msg; - continue; + LOG(ERROR) << "OpenZip failed for '" << dex_locations_[i] << "' " << error_msg; + return false; } } else { if (dex_file_loader.Open(apk_files_[i].c_str(), @@ -366,14 +437,36 @@ class ProfMan FINAL { &error_msg, &dex_files_for_location)) { } else { - LOG(WARNING) << "Open failed for '" << dex_locations_[i] << "' " << error_msg; - continue; + LOG(ERROR) << "Open failed for '" << dex_locations_[i] << "' " << error_msg; + return false; } } for (std::unique_ptr<const DexFile>& dex_file : dex_files_for_location) { - dex_files->emplace_back(std::move(dex_file)); + process_fn(std::move(dex_file)); } } + return true; + } + + // Get the dex locations from the apk fds. + // The methods reads the links from /proc/self/fd/ to find the original apk paths + // and puts them in the dex_locations_ vector. + bool ComputeDexLocationsFromApkFds() { + // We can't use a char array of PATH_MAX size without exceeding the frame size. + // So we use a vector as the buffer for the path. + std::vector<char> buffer(PATH_MAX, 0); + for (size_t i = 0; i < apks_fd_.size(); ++i) { + std::string fd_path = "/proc/self/fd/" + std::to_string(apks_fd_[i]); + ssize_t len = readlink(fd_path.c_str(), buffer.data(), buffer.size() - 1); + if (len == -1) { + PLOG(ERROR) << "Could not open path from fd"; + return false; + } + + buffer[len] = '\0'; + dex_locations_.push_back(buffer.data()); + } + return true; } std::unique_ptr<const ProfileCompilationInfo> LoadProfile(const std::string& filename, int fd) { @@ -416,8 +509,6 @@ class ProfMan FINAL { static const char* kOrdinaryProfile = "=== profile ==="; static const char* kReferenceProfile = "=== reference profile ==="; - // Open apk/zip files and and read dex files. - MemMap::Init(); // for ZipArchive::OpenFromFd std::vector<std::unique_ptr<const DexFile>> dex_files; OpenApkFilesFromLocations(&dex_files); std::string dump; @@ -553,8 +644,7 @@ class ProfMan FINAL { reference_profile_file_.empty() && !FdIsValid(reference_profile_file_fd_)) { Usage("No profile files or reference profile specified."); } - // Open apk/zip files and and read dex files. - MemMap::Init(); // for ZipArchive::OpenFromFd + // Open the dex files to get the names for classes. std::vector<std::unique_ptr<const DexFile>> dex_files; OpenApkFilesFromLocations(&dex_files); @@ -948,8 +1038,6 @@ class ProfMan FINAL { Usage("Profile must be specified with --reference-profile-file or " "--reference-profile-file-fd"); } - // for ZipArchive::OpenFromFd - MemMap::Init(); // Open the profile output file if needed. int fd = OpenReferenceProfile(); if (!FdIsValid(fd)) { @@ -984,8 +1072,6 @@ class ProfMan FINAL { } int CreateBootProfile() { - // Initialize memmap since it's required to open dex files. - MemMap::Init(); // Open the profile output file. const int reference_fd = OpenReferenceProfile(); if (!FdIsValid(reference_fd)) { @@ -1065,8 +1151,6 @@ class ProfMan FINAL { test_profile_class_percentage_, test_profile_seed_); } else { - // Initialize MemMap for ZipArchive::OpenFromFd. - MemMap::Init(); // Open the dex files to look up classes and methods. std::vector<std::unique_ptr<const DexFile>> dex_files; OpenApkFilesFromLocations(&dex_files); @@ -1089,7 +1173,7 @@ class ProfMan FINAL { return copy_and_update_profile_key_; } - bool CopyAndUpdateProfileKey() const { + bool CopyAndUpdateProfileKey() { // Validate that at least one profile file was passed, as well as a reference profile. if (!(profile_files_.size() == 1 ^ profile_files_fd_.size() == 1)) { Usage("Only one profile file should be specified."); @@ -1133,7 +1217,8 @@ class ProfMan FINAL { static void CloseAllFds(const std::vector<int>& fds, const char* descriptor) { for (size_t i = 0; i < fds.size(); i++) { if (close(fds[i]) < 0) { - PLOG(WARNING) << "Failed to close descriptor for " << descriptor << " at index " << i; + PLOG(WARNING) << "Failed to close descriptor for " + << descriptor << " at index " << i << ": " << fds[i]; } } } @@ -1176,6 +1261,9 @@ static int profman(int argc, char** argv) { // Parse arguments. Argument mistakes will lead to exit(EXIT_FAILURE) in UsageError. profman.ParseArgs(argc, argv); + // Initialize MemMap for ZipArchive::OpenFromFd. + MemMap::Init(); + if (profman.ShouldGenerateTestProfile()) { return profman.GenerateTestProfile(); } diff --git a/runtime/Android.bp b/runtime/Android.bp index a759cf700f..db9bceaf29 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -21,6 +21,7 @@ cc_defaults { srcs: [ "dex/compact_dex_debug_info.cc", "dex/compact_dex_file.cc", + "dex/descriptors_names.cc", "dex/dex_file.cc", "dex/dex_file_exception_helpers.cc", "dex/dex_file_loader.cc", @@ -29,8 +30,7 @@ cc_defaults { "dex/dex_instruction.cc", "dex/modifiers.cc", "dex/standard_dex_file.cc", - "utf.cc", - "utils.cc", + "dex/utf.cc", ], target: { @@ -51,7 +51,7 @@ cc_defaults { ], }, }, - generated_sources: ["art_operator_srcs"], + generated_sources: ["dexfile_operator_srcs"], include_dirs: [ "external/zlib", ], @@ -133,19 +133,9 @@ cc_defaults { "common_throws.cc", "compiler_filter.cc", "debugger.cc", - "dex/compact_dex_debug_info.cc", - "dex/compact_dex_file.cc", - "dex/dex_file.cc", "dex/dex_file_annotations.cc", - "dex/dex_file_exception_helpers.cc", "dex/dex_file_layout.cc", - "dex/dex_file_loader.cc", "dex/art_dex_file_loader.cc", - "dex/dex_file_tracking_registrar.cc", - "dex/dex_file_verifier.cc", - "dex/dex_instruction.cc", - "dex/modifiers.cc", - "dex/standard_dex_file.cc", "dex_to_dex_decompiler.cc", "elf_file.cc", "exec_utils.cc", @@ -302,7 +292,6 @@ cc_defaults { "trace.cc", "transaction.cc", "type_lookup_table.cc", - "utf.cc", "utils.cc", "vdex_file.cc", "verifier/instruction_flags.cc", @@ -498,6 +487,7 @@ cc_defaults { "jni_platform_headers", ], shared_libs: [ + "libdexfile", "libnativebridge", "libnativeloader", "libbacktrace", @@ -534,11 +524,7 @@ gensrcs { "debugger.h", "base/unix_file/fd_file.h", "class_status.h", - "dex/dex_file.h", "dex/dex_file_layout.h", - "dex/dex_instruction.h", - "dex/dex_instruction_utils.h", - "dex/invoke_type.h", "gc_root.h", "gc/allocator_type.h", "gc/allocator/rosalloc.h", @@ -657,6 +643,7 @@ art_cc_test { "dex/dex_file_test.cc", "dex/dex_file_verifier_test.cc", "dex/dex_instruction_test.cc", + "dex/utf_test.cc", "entrypoints/math_entrypoints_test.cc", "entrypoints/quick/quick_trampoline_entrypoints_test.cc", "entrypoints_order_test.cc", @@ -710,7 +697,6 @@ art_cc_test { "thread_pool_test.cc", "transaction_test.cc", "type_lookup_table_test.cc", - "utf_test.cc", "utils_test.cc", "vdex_file_test.cc", "verifier/method_verifier_test.cc", diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 65bacd8237..e6e35c89c9 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -377,6 +377,22 @@ inline bool ArtMethod::HasSingleImplementation() { return (GetAccessFlags() & kAccSingleImplementation) != 0; } +inline bool ArtMethod::IsHiddenIntrinsic(uint32_t ordinal) { + switch (static_cast<Intrinsics>(ordinal)) { + case Intrinsics::kReferenceGetReferent: + case Intrinsics::kSystemArrayCopyChar: + case Intrinsics::kStringGetCharsNoCheck: + case Intrinsics::kVarHandleFullFence: + case Intrinsics::kVarHandleAcquireFence: + case Intrinsics::kVarHandleReleaseFence: + case Intrinsics::kVarHandleLoadLoadFence: + case Intrinsics::kVarHandleStoreStoreFence: + return true; + default: + return false; + } +} + inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { // Currently we only do intrinsics for static/final methods or methods of final // classes. We don't set kHasSingleImplementation for those methods. @@ -413,10 +429,14 @@ inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { DCHECK_EQ(is_default_conflict, IsDefaultConflicting()); DCHECK_EQ(is_compilable, IsCompilable()); DCHECK_EQ(must_count_locks, MustCountLocks()); - // We need to special case java.lang.ref.Reference.getRefererent. The Java method - // is hidden but we do not yet have a way of making intrinsics hidden. - if (intrinsic != static_cast<uint32_t>(Intrinsics::kReferenceGetReferent)) { - DCHECK_EQ(hidden_api_list, GetHiddenApiAccessFlags()); + if (kIsDebugBuild) { + if (IsHiddenIntrinsic(intrinsic)) { + // Special case some of our intrinsics because the access flags clash + // with the intrinsics ordinal. + DCHECK_EQ(HiddenApiAccessFlags::kWhitelist, GetHiddenApiAccessFlags()); + } else { + DCHECK_EQ(hidden_api_list, GetHiddenApiAccessFlags()); + } } } else { SetAccessFlags(new_value); @@ -466,7 +486,15 @@ inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize poi } inline CodeItemInstructionAccessor ArtMethod::DexInstructions() { - return CodeItemInstructionAccessor(this); + return CodeItemInstructionAccessor(*GetDexFile(), GetCodeItem()); +} + +inline CodeItemDataAccessor ArtMethod::DexInstructionData() { + return CodeItemDataAccessor(*GetDexFile(), GetCodeItem()); +} + +inline CodeItemDebugInfoAccessor ArtMethod::DexInstructionDebugInfo() { + return CodeItemDebugInfoAccessor(*GetDexFile(), GetCodeItem(), GetDexMethodIndex()); } } // namespace art diff --git a/runtime/art_method.cc b/runtime/art_method.cc index 96468bba60..efdf5991ec 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -272,7 +272,7 @@ uint32_t ArtMethod::FindCatchBlock(Handle<mirror::Class> exception_type, // Default to handler not found. uint32_t found_dex_pc = dex::kDexNoIndex; // Iterate over the catch handlers associated with dex_pc. - CodeItemDataAccessor accessor(this); + CodeItemDataAccessor accessor(DexInstructionData()); for (CatchHandlerIterator it(accessor, dex_pc); it.HasNext(); it.Next()) { dex::TypeIndex iter_type_idx = it.GetHandlerTypeIndex(); // Catch all case diff --git a/runtime/art_method.h b/runtime/art_method.h index ce8e8ac612..cec2ec4df2 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -667,6 +667,10 @@ class ArtMethod FINAL { return hotness_count_; } + static MemberOffset HotnessCountOffset() { + return MemberOffset(OFFSETOF_MEMBER(ArtMethod, hotness_count_)); + } + ArrayRef<const uint8_t> GetQuickenedInfo() REQUIRES_SHARED(Locks::mutator_lock_); // Returns the method header for the compiled code containing 'pc'. Note that runtime @@ -727,6 +731,14 @@ class ArtMethod FINAL { ALWAYS_INLINE CodeItemInstructionAccessor DexInstructions() REQUIRES_SHARED(Locks::mutator_lock_); + // Returns the dex code item data section of the DexFile for the art method. + ALWAYS_INLINE CodeItemDataAccessor DexInstructionData() + REQUIRES_SHARED(Locks::mutator_lock_); + + // Returns the dex code item debug info section of the DexFile for the art method. + ALWAYS_INLINE CodeItemDebugInfoAccessor DexInstructionDebugInfo() + REQUIRES_SHARED(Locks::mutator_lock_); + protected: // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". // The class we are a part of. @@ -753,7 +765,7 @@ class ArtMethod FINAL { // ifTable. uint16_t method_index_; - // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow + // The hotness we measure for this method. Not atomic, as we allow // missing increments: if the method is hot, we will see it eventually. uint16_t hotness_count_; @@ -846,6 +858,9 @@ class ArtMethod FINAL { } while (!access_flags_.compare_exchange_weak(old_access_flags, new_access_flags)); } + // Returns true if the given intrinsic is considered hidden. + bool IsHiddenIntrinsic(uint32_t ordinal); + DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits. }; diff --git a/runtime/base/file_utils.cc b/runtime/base/file_utils.cc index d22fd994ee..58990f344b 100644 --- a/runtime/base/file_utils.cc +++ b/runtime/base/file_utils.cc @@ -50,10 +50,10 @@ #include "dex/dex_file-inl.h" #include "dex/dex_file_loader.h" #include "dex/dex_instruction.h" +#include "dex/utf-inl.h" #include "oat_quick_method_header.h" #include "os.h" #include "scoped_thread_state_change-inl.h" -#include "utf-inl.h" #if defined(__APPLE__) #include <crt_externs.h> diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc index 9f17ad051c..a4c32dd814 100644 --- a/runtime/base/mutex.cc +++ b/runtime/base/mutex.cc @@ -74,6 +74,7 @@ Uninterruptible Roles::uninterruptible_; ReaderWriterMutex* Locks::jni_globals_lock_ = nullptr; Mutex* Locks::jni_weak_globals_lock_ = nullptr; ReaderWriterMutex* Locks::dex_lock_ = nullptr; +Mutex* Locks::native_debug_interface_lock_ = nullptr; std::vector<BaseMutex*> Locks::expected_mutexes_on_weak_ref_access_; Atomic<const BaseMutex*> Locks::expected_mutexes_on_weak_ref_access_guard_; @@ -1073,6 +1074,7 @@ void Locks::Init() { DCHECK(unexpected_signal_lock_ != nullptr); DCHECK(user_code_suspension_lock_ != nullptr); DCHECK(dex_lock_ != nullptr); + DCHECK(native_debug_interface_lock_ != nullptr); } else { // Create global locks in level order from highest lock level to lowest. LockLevel current_lock_level = kInstrumentEntrypointsLock; @@ -1228,6 +1230,10 @@ void Locks::Init() { DCHECK(unexpected_signal_lock_ == nullptr); unexpected_signal_lock_ = new Mutex("unexpected signal lock", current_lock_level, true); + UPDATE_CURRENT_LOCK_LEVEL(kNativeDebugInterfaceLock); + DCHECK(native_debug_interface_lock_ == nullptr); + native_debug_interface_lock_ = new Mutex("Native debug interface lock", current_lock_level); + UPDATE_CURRENT_LOCK_LEVEL(kLoggingLock); DCHECK(logging_lock_ == nullptr); logging_lock_ = new Mutex("logging lock", current_lock_level, true); diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h index d541b79a98..075122b6f8 100644 --- a/runtime/base/mutex.h +++ b/runtime/base/mutex.h @@ -58,6 +58,7 @@ class Thread; // [1] http://www.drdobbs.com/parallel/use-lock-hierarchies-to-avoid-deadlock/204801163 enum LockLevel { kLoggingLock = 0, + kNativeDebugInterfaceLock, kSwapMutexesLock, kUnexpectedSignalLock, kThreadSuspendCountLock, @@ -745,8 +746,11 @@ class Locks { // One unexpected signal at a time lock. static Mutex* unexpected_signal_lock_ ACQUIRED_AFTER(thread_suspend_count_lock_); + // Guards the magic global variables used by native tools (e.g. libunwind). + static Mutex* native_debug_interface_lock_ ACQUIRED_AFTER(unexpected_signal_lock_); + // Have an exclusive logging thread. - static Mutex* logging_lock_ ACQUIRED_AFTER(unexpected_signal_lock_); + static Mutex* logging_lock_ ACQUIRED_AFTER(native_debug_interface_lock_); // List of mutexes that we expect a thread may hold when accessing weak refs. This is used to // avoid a deadlock in the empty checkpoint while weak ref access is disabled (b/34964016). If we diff --git a/runtime/check_reference_map_visitor.h b/runtime/check_reference_map_visitor.h index 0c29e257a1..e2ad7fd83f 100644 --- a/runtime/check_reference_map_visitor.h +++ b/runtime/check_reference_map_visitor.h @@ -67,7 +67,7 @@ class CheckReferenceMapVisitor : public StackVisitor { CodeInfo code_info = GetCurrentOatQuickMethodHeader()->GetOptimizedCodeInfo(); CodeInfoEncoding encoding = code_info.ExtractEncoding(); StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset, encoding); - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); uint16_t number_of_dex_registers = accessor.RegistersSize(); DexRegisterMap dex_register_map = code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index af45a69bd5..c9ebed288c 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -53,6 +53,7 @@ #include "dex/dex_file-inl.h" #include "dex/dex_file_exception_helpers.h" #include "dex/dex_file_loader.h" +#include "dex/utf.h" #include "entrypoints/entrypoint_utils.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "experimental_flags.h" @@ -72,6 +73,7 @@ #include "intern_table.h" #include "interpreter/interpreter.h" #include "java_vm_ext.h" +#include "jit/debugger_interface.h" #include "jit/jit.h" #include "jit/jit_code_cache.h" #include "jit/profile_compilation_info.h" @@ -115,7 +117,6 @@ #include "thread-inl.h" #include "thread_list.h" #include "trace.h" -#include "utf.h" #include "utils.h" #include "utils/dex_cache_arrays_layout-inl.h" #include "verifier/method_verifier.h" @@ -3432,6 +3433,7 @@ void ClassLinker::RegisterDexFileLocked(const DexFile& dex_file, data.weak_root = dex_cache_jweak; data.dex_file = dex_cache->GetDexFile(); data.class_table = ClassTableForClassLoader(class_loader); + RegisterDexFileForNative(self, data.dex_file->Begin()); DCHECK(data.class_table != nullptr); // Make sure to hold the dex cache live in the class table. This case happens for the boot class // path dex caches without an image. @@ -4329,7 +4331,7 @@ void ClassLinker::ResolveClassExceptionHandlerTypes(Handle<mirror::Class> klass) void ClassLinker::ResolveMethodExceptionHandlerTypes(ArtMethod* method) { // similar to DexVerifier::ScanTryCatchBlocks and dex2oat's ResolveExceptionsForMethod. - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); if (!accessor.HasCodeItem()) { return; // native or abstract method } diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc index 03774f45cd..19e7f7686d 100644 --- a/runtime/common_throws.cc +++ b/runtime/common_throws.cc @@ -551,7 +551,7 @@ static bool IsValidImplicitCheck(uintptr_t addr, const Instruction& instr) void ThrowNullPointerExceptionFromDexPC(bool check_address, uintptr_t addr) { uint32_t throw_dex_pc; ArtMethod* method = Thread::Current()->GetCurrentMethod(&throw_dex_pc); - CodeItemInstructionAccessor accessor(method); + CodeItemInstructionAccessor accessor(method->DexInstructions()); CHECK_LT(throw_dex_pc, accessor.InsnsSizeInCodeUnits()); const Instruction& instr = accessor.InstructionAt(throw_dex_pc); if (check_address && !IsValidImplicitCheck(addr, instr)) { diff --git a/runtime/debugger.cc b/runtime/debugger.cc index 842cd7330c..61ad725b79 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -37,6 +37,7 @@ #include "dex/dex_file_annotations.h" #include "dex/dex_file_types.h" #include "dex/dex_instruction.h" +#include "dex/utf.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "gc/accounting/card_table-inl.h" #include "gc/allocation_record.h" @@ -66,7 +67,6 @@ #include "scoped_thread_state_change-inl.h" #include "stack.h" #include "thread_list.h" -#include "utf.h" #include "well_known_classes.h" namespace art { @@ -1533,7 +1533,7 @@ static uint32_t MangleAccessFlags(uint32_t accessFlags) { */ static uint16_t MangleSlot(uint16_t slot, ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_) { - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); if (!accessor.HasCodeItem()) { // We should not get here for a method without code (native, proxy or abstract). Log it and // return the slot as is since all registers are arguments. @@ -1564,7 +1564,7 @@ static size_t GetMethodNumArgRegistersIncludingThis(ArtMethod* method) */ static uint16_t DemangleSlot(uint16_t slot, ArtMethod* m, JDWP::JdwpError* error) REQUIRES_SHARED(Locks::mutator_lock_) { - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); if (!accessor.HasCodeItem()) { // We should not get here for a method without code (native, proxy or abstract). Log it and // return the slot as is since all registers are arguments. @@ -1675,7 +1675,7 @@ void Dbg::OutputLineTable(JDWP::RefTypeId, JDWP::MethodId method_id, JDWP::Expan } }; ArtMethod* m = FromMethodId(method_id); - CodeItemDebugInfoAccessor accessor(m); + CodeItemDebugInfoAccessor accessor(m->DexInstructionDebugInfo()); uint64_t start, end; if (!accessor.HasCodeItem()) { DCHECK(m->IsNative() || m->IsProxyMethod()); @@ -1741,7 +1741,7 @@ void Dbg::OutputVariableTable(JDWP::RefTypeId, JDWP::MethodId method_id, bool wi } }; ArtMethod* m = FromMethodId(method_id); - CodeItemDebugInfoAccessor accessor(m); + CodeItemDebugInfoAccessor accessor(m->DexInstructionDebugInfo()); // arg_count considers doubles and longs to take 2 units. // variable_count considers everything to take 1 unit. @@ -1791,7 +1791,7 @@ JDWP::JdwpError Dbg::GetBytecodes(JDWP::RefTypeId, JDWP::MethodId method_id, if (m == nullptr) { return JDWP::ERR_INVALID_METHODID; } - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); size_t byte_count = accessor.InsnsSizeInCodeUnits() * 2; const uint8_t* begin = reinterpret_cast<const uint8_t*>(accessor.Insns()); const uint8_t* end = begin + byte_count; @@ -3908,7 +3908,7 @@ JDWP::JdwpError Dbg::ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize // Note: if the thread is not running Java code (pure native thread), there is no "current" // method on the stack (and no line number either). if (m != nullptr && !m->IsNative()) { - CodeItemDebugInfoAccessor accessor(m); + CodeItemDebugInfoAccessor accessor(m->DexInstructionDebugInfo()); DebugCallbackContext context(single_step_control, line_number, accessor.InsnsSizeInCodeUnits()); m->GetDexFile()->DecodeDebugPositionInfo(accessor.DebugInfoOffset(), DebugCallbackContext::Callback, diff --git a/runtime/dex/code_item_accessors-inl.h b/runtime/dex/code_item_accessors-inl.h index 63fd120991..9c39935d3b 100644 --- a/runtime/dex/code_item_accessors-inl.h +++ b/runtime/dex/code_item_accessors-inl.h @@ -17,26 +17,187 @@ #ifndef ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_INL_H_ #define ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_INL_H_ -#include "code_item_accessors-no_art-inl.h" +#include "code_item_accessors.h" -#include "art_method-inl.h" #include "compact_dex_file.h" #include "dex_file-inl.h" -#include "oat_file.h" #include "standard_dex_file.h" +// The no ART version is used by binaries that don't include the whole runtime. namespace art { -inline CodeItemInstructionAccessor::CodeItemInstructionAccessor(ArtMethod* method) - : CodeItemInstructionAccessor(*method->GetDexFile(), method->GetCodeItem()) {} +inline void CodeItemInstructionAccessor::Init(uint32_t insns_size_in_code_units, + const uint16_t* insns) { + insns_size_in_code_units_ = insns_size_in_code_units; + insns_ = insns; +} -inline CodeItemDataAccessor::CodeItemDataAccessor(ArtMethod* method) - : CodeItemDataAccessor(*method->GetDexFile(), method->GetCodeItem()) {} +inline void CodeItemInstructionAccessor::Init(const CompactDexFile::CodeItem& code_item) { + uint32_t insns_size_in_code_units; + code_item.DecodeFields</*kDecodeOnlyInstructionCount*/ true>( + &insns_size_in_code_units, + /*registers_size*/ nullptr, + /*ins_size*/ nullptr, + /*outs_size*/ nullptr, + /*tries_size*/ nullptr); + Init(insns_size_in_code_units, code_item.insns_); +} -inline CodeItemDebugInfoAccessor::CodeItemDebugInfoAccessor(ArtMethod* method) - : CodeItemDebugInfoAccessor(*method->GetDexFile(), - method->GetCodeItem(), - method->GetDexMethodIndex()) {} +inline void CodeItemInstructionAccessor::Init(const StandardDexFile::CodeItem& code_item) { + Init(code_item.insns_size_in_code_units_, code_item.insns_); +} + +inline void CodeItemInstructionAccessor::Init(const DexFile& dex_file, + const DexFile::CodeItem* code_item) { + if (code_item != nullptr) { + DCHECK(dex_file.IsInDataSection(code_item)); + if (dex_file.IsCompactDexFile()) { + Init(down_cast<const CompactDexFile::CodeItem&>(*code_item)); + } else { + DCHECK(dex_file.IsStandardDexFile()); + Init(down_cast<const StandardDexFile::CodeItem&>(*code_item)); + } + } +} + +inline CodeItemInstructionAccessor::CodeItemInstructionAccessor( + const DexFile& dex_file, + const DexFile::CodeItem* code_item) { + Init(dex_file, code_item); +} + +inline DexInstructionIterator CodeItemInstructionAccessor::begin() const { + return DexInstructionIterator(insns_, 0u); +} + +inline DexInstructionIterator CodeItemInstructionAccessor::end() const { + return DexInstructionIterator(insns_, insns_size_in_code_units_); +} + +inline IterationRange<DexInstructionIterator> CodeItemInstructionAccessor::InstructionsFrom( + uint32_t start_dex_pc) const { + DCHECK_LT(start_dex_pc, InsnsSizeInCodeUnits()); + return { + DexInstructionIterator(insns_, start_dex_pc), + DexInstructionIterator(insns_, insns_size_in_code_units_) }; +} + +inline void CodeItemDataAccessor::Init(const CompactDexFile::CodeItem& code_item) { + uint32_t insns_size_in_code_units; + code_item.DecodeFields</*kDecodeOnlyInstructionCount*/ false>(&insns_size_in_code_units, + ®isters_size_, + &ins_size_, + &outs_size_, + &tries_size_); + CodeItemInstructionAccessor::Init(insns_size_in_code_units, code_item.insns_); +} + +inline void CodeItemDataAccessor::Init(const StandardDexFile::CodeItem& code_item) { + CodeItemInstructionAccessor::Init(code_item); + registers_size_ = code_item.registers_size_; + ins_size_ = code_item.ins_size_; + outs_size_ = code_item.outs_size_; + tries_size_ = code_item.tries_size_; +} + +inline void CodeItemDataAccessor::Init(const DexFile& dex_file, + const DexFile::CodeItem* code_item) { + if (code_item != nullptr) { + if (dex_file.IsCompactDexFile()) { + CodeItemDataAccessor::Init(down_cast<const CompactDexFile::CodeItem&>(*code_item)); + } else { + DCHECK(dex_file.IsStandardDexFile()); + CodeItemDataAccessor::Init(down_cast<const StandardDexFile::CodeItem&>(*code_item)); + } + } +} + +inline CodeItemDataAccessor::CodeItemDataAccessor(const DexFile& dex_file, + const DexFile::CodeItem* code_item) { + Init(dex_file, code_item); +} + +inline IterationRange<const DexFile::TryItem*> CodeItemDataAccessor::TryItems() const { + const DexFile::TryItem* try_items = DexFile::GetTryItems(end(), 0u); + return { + try_items, + try_items + TriesSize() }; +} + +inline const uint8_t* CodeItemDataAccessor::GetCatchHandlerData(size_t offset) const { + return DexFile::GetCatchHandlerData(end(), TriesSize(), offset); +} + +inline const DexFile::TryItem* CodeItemDataAccessor::FindTryItem(uint32_t try_dex_pc) const { + IterationRange<const DexFile::TryItem*> try_items(TryItems()); + int32_t index = DexFile::FindTryItem(try_items.begin(), + try_items.end() - try_items.begin(), + try_dex_pc); + return index != -1 ? &try_items.begin()[index] : nullptr; +} + +inline const void* CodeItemDataAccessor::CodeItemDataEnd() const { + const uint8_t* handler_data = GetCatchHandlerData(); + + if (TriesSize() == 0 || handler_data == nullptr) { + return &end().Inst(); + } + // Get the start of the handler data. + const uint32_t handlers_size = DecodeUnsignedLeb128(&handler_data); + // Manually read each handler. + for (uint32_t i = 0; i < handlers_size; ++i) { + int32_t uleb128_count = DecodeSignedLeb128(&handler_data) * 2; + if (uleb128_count <= 0) { + uleb128_count = -uleb128_count + 1; + } + for (int32_t j = 0; j < uleb128_count; ++j) { + DecodeUnsignedLeb128(&handler_data); + } + } + return reinterpret_cast<const void*>(handler_data); +} + +inline void CodeItemDebugInfoAccessor::Init(const DexFile& dex_file, + const DexFile::CodeItem* code_item, + uint32_t dex_method_index) { + if (code_item == nullptr) { + return; + } + dex_file_ = &dex_file; + if (dex_file.IsCompactDexFile()) { + Init(down_cast<const CompactDexFile::CodeItem&>(*code_item), dex_method_index); + } else { + DCHECK(dex_file.IsStandardDexFile()); + Init(down_cast<const StandardDexFile::CodeItem&>(*code_item)); + } +} + +inline void CodeItemDebugInfoAccessor::Init(const CompactDexFile::CodeItem& code_item, + uint32_t dex_method_index) { + debug_info_offset_ = down_cast<const CompactDexFile*>(dex_file_)->GetDebugInfoOffset( + dex_method_index); + CodeItemDataAccessor::Init(code_item); +} + +inline void CodeItemDebugInfoAccessor::Init(const StandardDexFile::CodeItem& code_item) { + debug_info_offset_ = code_item.debug_info_off_; + CodeItemDataAccessor::Init(code_item); +} + +template<typename NewLocalCallback> +inline bool CodeItemDebugInfoAccessor::DecodeDebugLocalInfo(bool is_static, + uint32_t method_idx, + NewLocalCallback new_local, + void* context) const { + return dex_file_->DecodeDebugLocalInfo(RegistersSize(), + InsSize(), + InsnsSizeInCodeUnits(), + DebugInfoOffset(), + is_static, + method_idx, + new_local, + context); +} } // namespace art diff --git a/runtime/dex/code_item_accessors-no_art-inl.h b/runtime/dex/code_item_accessors-no_art-inl.h index a243a4a6f4..8082be3818 100644 --- a/runtime/dex/code_item_accessors-no_art-inl.h +++ b/runtime/dex/code_item_accessors-no_art-inl.h @@ -17,188 +17,7 @@ #ifndef ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_NO_ART_INL_H_ #define ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_NO_ART_INL_H_ -#include "code_item_accessors.h" - -#include "compact_dex_file.h" -#include "dex_file-inl.h" -#include "standard_dex_file.h" - -// The no ART version is used by binaries that don't include the whole runtime. -namespace art { - -inline void CodeItemInstructionAccessor::Init(uint32_t insns_size_in_code_units, - const uint16_t* insns) { - insns_size_in_code_units_ = insns_size_in_code_units; - insns_ = insns; -} - -inline void CodeItemInstructionAccessor::Init(const CompactDexFile::CodeItem& code_item) { - uint32_t insns_size_in_code_units; - code_item.DecodeFields</*kDecodeOnlyInstructionCount*/ true>( - &insns_size_in_code_units, - /*registers_size*/ nullptr, - /*ins_size*/ nullptr, - /*outs_size*/ nullptr, - /*tries_size*/ nullptr); - Init(insns_size_in_code_units, code_item.insns_); -} - -inline void CodeItemInstructionAccessor::Init(const StandardDexFile::CodeItem& code_item) { - Init(code_item.insns_size_in_code_units_, code_item.insns_); -} - -inline void CodeItemInstructionAccessor::Init(const DexFile& dex_file, - const DexFile::CodeItem* code_item) { - if (code_item != nullptr) { - DCHECK(dex_file.IsInDataSection(code_item)); - if (dex_file.IsCompactDexFile()) { - Init(down_cast<const CompactDexFile::CodeItem&>(*code_item)); - } else { - DCHECK(dex_file.IsStandardDexFile()); - Init(down_cast<const StandardDexFile::CodeItem&>(*code_item)); - } - } -} - -inline CodeItemInstructionAccessor::CodeItemInstructionAccessor( - const DexFile& dex_file, - const DexFile::CodeItem* code_item) { - Init(dex_file, code_item); -} - -inline DexInstructionIterator CodeItemInstructionAccessor::begin() const { - return DexInstructionIterator(insns_, 0u); -} - -inline DexInstructionIterator CodeItemInstructionAccessor::end() const { - return DexInstructionIterator(insns_, insns_size_in_code_units_); -} - -inline IterationRange<DexInstructionIterator> CodeItemInstructionAccessor::InstructionsFrom( - uint32_t start_dex_pc) const { - DCHECK_LT(start_dex_pc, InsnsSizeInCodeUnits()); - return { - DexInstructionIterator(insns_, start_dex_pc), - DexInstructionIterator(insns_, insns_size_in_code_units_) }; -} - -inline void CodeItemDataAccessor::Init(const CompactDexFile::CodeItem& code_item) { - uint32_t insns_size_in_code_units; - code_item.DecodeFields</*kDecodeOnlyInstructionCount*/ false>(&insns_size_in_code_units, - ®isters_size_, - &ins_size_, - &outs_size_, - &tries_size_); - CodeItemInstructionAccessor::Init(insns_size_in_code_units, code_item.insns_); -} - -inline void CodeItemDataAccessor::Init(const StandardDexFile::CodeItem& code_item) { - CodeItemInstructionAccessor::Init(code_item); - registers_size_ = code_item.registers_size_; - ins_size_ = code_item.ins_size_; - outs_size_ = code_item.outs_size_; - tries_size_ = code_item.tries_size_; -} - -inline void CodeItemDataAccessor::Init(const DexFile& dex_file, - const DexFile::CodeItem* code_item) { - if (code_item != nullptr) { - if (dex_file.IsCompactDexFile()) { - CodeItemDataAccessor::Init(down_cast<const CompactDexFile::CodeItem&>(*code_item)); - } else { - DCHECK(dex_file.IsStandardDexFile()); - CodeItemDataAccessor::Init(down_cast<const StandardDexFile::CodeItem&>(*code_item)); - } - } -} - -inline CodeItemDataAccessor::CodeItemDataAccessor(const DexFile& dex_file, - const DexFile::CodeItem* code_item) { - Init(dex_file, code_item); -} - -inline IterationRange<const DexFile::TryItem*> CodeItemDataAccessor::TryItems() const { - const DexFile::TryItem* try_items = DexFile::GetTryItems(end(), 0u); - return { - try_items, - try_items + TriesSize() }; -} - -inline const uint8_t* CodeItemDataAccessor::GetCatchHandlerData(size_t offset) const { - return DexFile::GetCatchHandlerData(end(), TriesSize(), offset); -} - -inline const DexFile::TryItem* CodeItemDataAccessor::FindTryItem(uint32_t try_dex_pc) const { - IterationRange<const DexFile::TryItem*> try_items(TryItems()); - int32_t index = DexFile::FindTryItem(try_items.begin(), - try_items.end() - try_items.begin(), - try_dex_pc); - return index != -1 ? &try_items.begin()[index] : nullptr; -} - -inline const void* CodeItemDataAccessor::CodeItemDataEnd() const { - const uint8_t* handler_data = GetCatchHandlerData(); - - if (TriesSize() == 0 || handler_data == nullptr) { - return &end().Inst(); - } - // Get the start of the handler data. - const uint32_t handlers_size = DecodeUnsignedLeb128(&handler_data); - // Manually read each handler. - for (uint32_t i = 0; i < handlers_size; ++i) { - int32_t uleb128_count = DecodeSignedLeb128(&handler_data) * 2; - if (uleb128_count <= 0) { - uleb128_count = -uleb128_count + 1; - } - for (int32_t j = 0; j < uleb128_count; ++j) { - DecodeUnsignedLeb128(&handler_data); - } - } - return reinterpret_cast<const void*>(handler_data); -} - -inline void CodeItemDebugInfoAccessor::Init(const DexFile& dex_file, - const DexFile::CodeItem* code_item, - uint32_t dex_method_index) { - if (code_item == nullptr) { - return; - } - dex_file_ = &dex_file; - if (dex_file.IsCompactDexFile()) { - Init(down_cast<const CompactDexFile::CodeItem&>(*code_item), dex_method_index); - } else { - DCHECK(dex_file.IsStandardDexFile()); - Init(down_cast<const StandardDexFile::CodeItem&>(*code_item)); - } -} - -inline void CodeItemDebugInfoAccessor::Init(const CompactDexFile::CodeItem& code_item, - uint32_t dex_method_index) { - debug_info_offset_ = down_cast<const CompactDexFile*>(dex_file_)->GetDebugInfoOffset( - dex_method_index); - CodeItemDataAccessor::Init(code_item); -} - -inline void CodeItemDebugInfoAccessor::Init(const StandardDexFile::CodeItem& code_item) { - debug_info_offset_ = code_item.debug_info_off_; - CodeItemDataAccessor::Init(code_item); -} - -template<typename NewLocalCallback> -inline bool CodeItemDebugInfoAccessor::DecodeDebugLocalInfo(bool is_static, - uint32_t method_idx, - NewLocalCallback new_local, - void* context) const { - return dex_file_->DecodeDebugLocalInfo(RegistersSize(), - InsSize(), - InsnsSizeInCodeUnits(), - DebugInfoOffset(), - is_static, - method_idx, - new_local, - context); -} - -} // namespace art +// TODO: delete this file once system/core is updated. +#include "code_item_accessors-inl.h" #endif // ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_NO_ART_INL_H_ diff --git a/runtime/dex/code_item_accessors.h b/runtime/dex/code_item_accessors.h index 08f823cae8..beb78f6e4f 100644 --- a/runtime/dex/code_item_accessors.h +++ b/runtime/dex/code_item_accessors.h @@ -85,8 +85,6 @@ class CodeItemDataAccessor : public CodeItemInstructionAccessor { public: ALWAYS_INLINE CodeItemDataAccessor(const DexFile& dex_file, const DexFile::CodeItem* code_item); - ALWAYS_INLINE explicit CodeItemDataAccessor(ArtMethod* method); - uint16_t RegistersSize() const { return registers_size_; } diff --git a/runtime/dex/code_item_accessors_test.cc b/runtime/dex/code_item_accessors_test.cc index 8e2548bf3d..1bd12a6f09 100644 --- a/runtime/dex/code_item_accessors_test.cc +++ b/runtime/dex/code_item_accessors_test.cc @@ -16,6 +16,7 @@ #include "code_item_accessors-inl.h" +#include <sys/mman.h> #include <memory> #include "common_runtime_test.h" diff --git a/runtime/dex/compact_dex_file.cc b/runtime/dex/compact_dex_file.cc index 37f5d0074c..ce289d4d7b 100644 --- a/runtime/dex/compact_dex_file.cc +++ b/runtime/dex/compact_dex_file.cc @@ -16,7 +16,7 @@ #include "compact_dex_file.h" -#include "code_item_accessors-no_art-inl.h" +#include "code_item_accessors-inl.h" #include "dex_file-inl.h" #include "leb128.h" diff --git a/runtime/dex/descriptors_names.cc b/runtime/dex/descriptors_names.cc new file mode 100644 index 0000000000..8124e7256f --- /dev/null +++ b/runtime/dex/descriptors_names.cc @@ -0,0 +1,426 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "descriptors_names.h" + +#include "android-base/stringprintf.h" +#include "android-base/strings.h" + +#include "dex/utf-inl.h" + +namespace art { + +using android::base::StringAppendF; +using android::base::StringPrintf; + +void AppendPrettyDescriptor(const char* descriptor, std::string* result) { + // Count the number of '['s to get the dimensionality. + const char* c = descriptor; + size_t dim = 0; + while (*c == '[') { + dim++; + c++; + } + + // Reference or primitive? + if (*c == 'L') { + // "[[La/b/C;" -> "a.b.C[][]". + c++; // Skip the 'L'. + } else { + // "[[B" -> "byte[][]". + // To make life easier, we make primitives look like unqualified + // reference types. + switch (*c) { + case 'B': c = "byte;"; break; + case 'C': c = "char;"; break; + case 'D': c = "double;"; break; + case 'F': c = "float;"; break; + case 'I': c = "int;"; break; + case 'J': c = "long;"; break; + case 'S': c = "short;"; break; + case 'Z': c = "boolean;"; break; + case 'V': c = "void;"; break; // Used when decoding return types. + default: result->append(descriptor); return; + } + } + + // At this point, 'c' is a string of the form "fully/qualified/Type;" + // or "primitive;". Rewrite the type with '.' instead of '/': + const char* p = c; + while (*p != ';') { + char ch = *p++; + if (ch == '/') { + ch = '.'; + } + result->push_back(ch); + } + // ...and replace the semicolon with 'dim' "[]" pairs: + for (size_t i = 0; i < dim; ++i) { + result->append("[]"); + } +} + +std::string PrettyDescriptor(const char* descriptor) { + std::string result; + AppendPrettyDescriptor(descriptor, &result); + return result; +} + +std::string GetJniShortName(const std::string& class_descriptor, const std::string& method) { + // Remove the leading 'L' and trailing ';'... + std::string class_name(class_descriptor); + CHECK_EQ(class_name[0], 'L') << class_name; + CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name; + class_name.erase(0, 1); + class_name.erase(class_name.size() - 1, 1); + + std::string short_name; + short_name += "Java_"; + short_name += MangleForJni(class_name); + short_name += "_"; + short_name += MangleForJni(method); + return short_name; +} + +// See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules. +std::string MangleForJni(const std::string& s) { + std::string result; + size_t char_count = CountModifiedUtf8Chars(s.c_str()); + const char* cp = &s[0]; + for (size_t i = 0; i < char_count; ++i) { + uint32_t ch = GetUtf16FromUtf8(&cp); + if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) { + result.push_back(ch); + } else if (ch == '.' || ch == '/') { + result += "_"; + } else if (ch == '_') { + result += "_1"; + } else if (ch == ';') { + result += "_2"; + } else if (ch == '[') { + result += "_3"; + } else { + const uint16_t leading = GetLeadingUtf16Char(ch); + const uint32_t trailing = GetTrailingUtf16Char(ch); + + StringAppendF(&result, "_0%04x", leading); + if (trailing != 0) { + StringAppendF(&result, "_0%04x", trailing); + } + } + } + return result; +} + +std::string DotToDescriptor(const char* class_name) { + std::string descriptor(class_name); + std::replace(descriptor.begin(), descriptor.end(), '.', '/'); + if (descriptor.length() > 0 && descriptor[0] != '[') { + descriptor = "L" + descriptor + ";"; + } + return descriptor; +} + +std::string DescriptorToDot(const char* descriptor) { + size_t length = strlen(descriptor); + if (length > 1) { + if (descriptor[0] == 'L' && descriptor[length - 1] == ';') { + // Descriptors have the leading 'L' and trailing ';' stripped. + std::string result(descriptor + 1, length - 2); + std::replace(result.begin(), result.end(), '/', '.'); + return result; + } else { + // For arrays the 'L' and ';' remain intact. + std::string result(descriptor); + std::replace(result.begin(), result.end(), '/', '.'); + return result; + } + } + // Do nothing for non-class/array descriptors. + return descriptor; +} + +std::string DescriptorToName(const char* descriptor) { + size_t length = strlen(descriptor); + if (descriptor[0] == 'L' && descriptor[length - 1] == ';') { + std::string result(descriptor + 1, length - 2); + return result; + } + return descriptor; +} + +// Helper for IsValidPartOfMemberNameUtf8(), a bit vector indicating valid low ascii. +static uint32_t DEX_MEMBER_VALID_LOW_ASCII[4] = { + 0x00000000, // 00..1f low control characters; nothing valid + 0x03ff2010, // 20..3f digits and symbols; valid: '0'..'9', '$', '-' + 0x87fffffe, // 40..5f uppercase etc.; valid: 'A'..'Z', '_' + 0x07fffffe // 60..7f lowercase etc.; valid: 'a'..'z' +}; + +// Helper for IsValidPartOfMemberNameUtf8(); do not call directly. +static bool IsValidPartOfMemberNameUtf8Slow(const char** pUtf8Ptr) { + /* + * It's a multibyte encoded character. Decode it and analyze. We + * accept anything that isn't (a) an improperly encoded low value, + * (b) an improper surrogate pair, (c) an encoded '\0', (d) a high + * control character, or (e) a high space, layout, or special + * character (U+00a0, U+2000..U+200f, U+2028..U+202f, + * U+fff0..U+ffff). This is all specified in the dex format + * document. + */ + + const uint32_t pair = GetUtf16FromUtf8(pUtf8Ptr); + const uint16_t leading = GetLeadingUtf16Char(pair); + + // We have a surrogate pair resulting from a valid 4 byte UTF sequence. + // No further checks are necessary because 4 byte sequences span code + // points [U+10000, U+1FFFFF], which are valid codepoints in a dex + // identifier. Furthermore, GetUtf16FromUtf8 guarantees that each of + // the surrogate halves are valid and well formed in this instance. + if (GetTrailingUtf16Char(pair) != 0) { + return true; + } + + + // We've encountered a one, two or three byte UTF-8 sequence. The + // three byte UTF-8 sequence could be one half of a surrogate pair. + switch (leading >> 8) { + case 0x00: + // It's only valid if it's above the ISO-8859-1 high space (0xa0). + return (leading > 0x00a0); + case 0xd8: + case 0xd9: + case 0xda: + case 0xdb: + { + // We found a three byte sequence encoding one half of a surrogate. + // Look for the other half. + const uint32_t pair2 = GetUtf16FromUtf8(pUtf8Ptr); + const uint16_t trailing = GetLeadingUtf16Char(pair2); + + return (GetTrailingUtf16Char(pair2) == 0) && (0xdc00 <= trailing && trailing <= 0xdfff); + } + case 0xdc: + case 0xdd: + case 0xde: + case 0xdf: + // It's a trailing surrogate, which is not valid at this point. + return false; + case 0x20: + case 0xff: + // It's in the range that has spaces, controls, and specials. + switch (leading & 0xfff8) { + case 0x2000: + case 0x2008: + case 0x2028: + case 0xfff0: + case 0xfff8: + return false; + } + return true; + default: + return true; + } + + UNREACHABLE(); +} + +/* Return whether the pointed-at modified-UTF-8 encoded character is + * valid as part of a member name, updating the pointer to point past + * the consumed character. This will consume two encoded UTF-16 code + * points if the character is encoded as a surrogate pair. Also, if + * this function returns false, then the given pointer may only have + * been partially advanced. + */ +static bool IsValidPartOfMemberNameUtf8(const char** pUtf8Ptr) { + uint8_t c = (uint8_t) **pUtf8Ptr; + if (LIKELY(c <= 0x7f)) { + // It's low-ascii, so check the table. + uint32_t wordIdx = c >> 5; + uint32_t bitIdx = c & 0x1f; + (*pUtf8Ptr)++; + return (DEX_MEMBER_VALID_LOW_ASCII[wordIdx] & (1 << bitIdx)) != 0; + } + + // It's a multibyte encoded character. Call a non-inline function + // for the heavy lifting. + return IsValidPartOfMemberNameUtf8Slow(pUtf8Ptr); +} + +bool IsValidMemberName(const char* s) { + bool angle_name = false; + + switch (*s) { + case '\0': + // The empty string is not a valid name. + return false; + case '<': + angle_name = true; + s++; + break; + } + + while (true) { + switch (*s) { + case '\0': + return !angle_name; + case '>': + return angle_name && s[1] == '\0'; + } + + if (!IsValidPartOfMemberNameUtf8(&s)) { + return false; + } + } +} + +enum ClassNameType { kName, kDescriptor }; +template<ClassNameType kType, char kSeparator> +static bool IsValidClassName(const char* s) { + int arrayCount = 0; + while (*s == '[') { + arrayCount++; + s++; + } + + if (arrayCount > 255) { + // Arrays may have no more than 255 dimensions. + return false; + } + + ClassNameType type = kType; + if (type != kDescriptor && arrayCount != 0) { + /* + * If we're looking at an array of some sort, then it doesn't + * matter if what is being asked for is a class name; the + * format looks the same as a type descriptor in that case, so + * treat it as such. + */ + type = kDescriptor; + } + + if (type == kDescriptor) { + /* + * We are looking for a descriptor. Either validate it as a + * single-character primitive type, or continue on to check the + * embedded class name (bracketed by "L" and ";"). + */ + switch (*(s++)) { + case 'B': + case 'C': + case 'D': + case 'F': + case 'I': + case 'J': + case 'S': + case 'Z': + // These are all single-character descriptors for primitive types. + return (*s == '\0'); + case 'V': + // Non-array void is valid, but you can't have an array of void. + return (arrayCount == 0) && (*s == '\0'); + case 'L': + // Class name: Break out and continue below. + break; + default: + // Oddball descriptor character. + return false; + } + } + + /* + * We just consumed the 'L' that introduces a class name as part + * of a type descriptor, or we are looking for an unadorned class + * name. + */ + + bool sepOrFirst = true; // first character or just encountered a separator. + for (;;) { + uint8_t c = (uint8_t) *s; + switch (c) { + case '\0': + /* + * Premature end for a type descriptor, but valid for + * a class name as long as we haven't encountered an + * empty component (including the degenerate case of + * the empty string ""). + */ + return (type == kName) && !sepOrFirst; + case ';': + /* + * Invalid character for a class name, but the + * legitimate end of a type descriptor. In the latter + * case, make sure that this is the end of the string + * and that it doesn't end with an empty component + * (including the degenerate case of "L;"). + */ + return (type == kDescriptor) && !sepOrFirst && (s[1] == '\0'); + case '/': + case '.': + if (c != kSeparator) { + // The wrong separator character. + return false; + } + if (sepOrFirst) { + // Separator at start or two separators in a row. + return false; + } + sepOrFirst = true; + s++; + break; + default: + if (!IsValidPartOfMemberNameUtf8(&s)) { + return false; + } + sepOrFirst = false; + break; + } + } +} + +bool IsValidBinaryClassName(const char* s) { + return IsValidClassName<kName, '.'>(s); +} + +bool IsValidJniClassName(const char* s) { + return IsValidClassName<kName, '/'>(s); +} + +bool IsValidDescriptor(const char* s) { + return IsValidClassName<kDescriptor, '/'>(s); +} + +void Split(const std::string& s, char separator, std::vector<std::string>* result) { + const char* p = s.data(); + const char* end = p + s.size(); + while (p != end) { + if (*p == separator) { + ++p; + } else { + const char* start = p; + while (++p != end && *p != separator) { + // Skip to the next occurrence of the separator. + } + result->push_back(std::string(start, p - start)); + } + } +} + +std::string PrettyDescriptor(Primitive::Type type) { + return PrettyDescriptor(Primitive::Descriptor(type)); +} + +} // namespace art diff --git a/runtime/dex/descriptors_names.h b/runtime/dex/descriptors_names.h new file mode 100644 index 0000000000..22e9573556 --- /dev/null +++ b/runtime/dex/descriptors_names.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_DEX_DESCRIPTORS_NAMES_H_ +#define ART_RUNTIME_DEX_DESCRIPTORS_NAMES_H_ + +#include <string> + +#include "primitive.h" + +namespace art { + +// Used to implement PrettyClass, PrettyField, PrettyMethod, and PrettyTypeOf, +// one of which is probably more useful to you. +// Returns a human-readable equivalent of 'descriptor'. So "I" would be "int", +// "[[I" would be "int[][]", "[Ljava/lang/String;" would be +// "java.lang.String[]", and so forth. +void AppendPrettyDescriptor(const char* descriptor, std::string* result); +std::string PrettyDescriptor(const char* descriptor); +std::string PrettyDescriptor(Primitive::Type type); + +// Performs JNI name mangling as described in section 11.3 "Linking Native Methods" +// of the JNI spec. +std::string MangleForJni(const std::string& s); + +std::string GetJniShortName(const std::string& class_name, const std::string& method_name); + +// Turn "java.lang.String" into "Ljava/lang/String;". +std::string DotToDescriptor(const char* class_name); + +// Turn "Ljava/lang/String;" into "java.lang.String" using the conventions of +// java.lang.Class.getName(). +std::string DescriptorToDot(const char* descriptor); + +// Turn "Ljava/lang/String;" into "java/lang/String" using the opposite conventions of +// java.lang.Class.getName(). +std::string DescriptorToName(const char* descriptor); + +// Tests for whether 's' is a valid class name in the three common forms: +bool IsValidBinaryClassName(const char* s); // "java.lang.String" +bool IsValidJniClassName(const char* s); // "java/lang/String" +bool IsValidDescriptor(const char* s); // "Ljava/lang/String;" + +// Returns whether the given string is a valid field or method name, +// additionally allowing names that begin with '<' and end with '>'. +bool IsValidMemberName(const char* s); + +} // namespace art + +#endif // ART_RUNTIME_DEX_DESCRIPTORS_NAMES_H_ diff --git a/runtime/dex/dex_file.cc b/runtime/dex/dex_file.cc index f0209f7bec..18eb903551 100644 --- a/runtime/dex/dex_file.cc +++ b/runtime/dex/dex_file.cc @@ -30,11 +30,11 @@ #include "base/enums.h" #include "base/stl_util.h" +#include "descriptors_names.h" #include "dex_file-inl.h" #include "leb128.h" #include "standard_dex_file.h" #include "utf-inl.h" -#include "utils.h" namespace art { diff --git a/runtime/dex/dex_file_annotations.cc b/runtime/dex/dex_file_annotations.cc index 72b18fb420..e01890f541 100644 --- a/runtime/dex/dex_file_annotations.cc +++ b/runtime/dex/dex_file_annotations.cc @@ -1559,7 +1559,7 @@ int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t re return -2; } - CodeItemDebugInfoAccessor accessor(method); + CodeItemDebugInfoAccessor accessor(method->DexInstructionDebugInfo()); DCHECK(accessor.HasCodeItem()) << method->PrettyMethod() << " " << dex_file->GetLocation(); // A method with no line number info should return -1 diff --git a/runtime/dex/dex_file_exception_helpers.cc b/runtime/dex/dex_file_exception_helpers.cc index ad56eb0a0b..8e597fd3dd 100644 --- a/runtime/dex/dex_file_exception_helpers.cc +++ b/runtime/dex/dex_file_exception_helpers.cc @@ -16,7 +16,7 @@ #include "dex_file_exception_helpers.h" -#include "code_item_accessors-no_art-inl.h" +#include "code_item_accessors-inl.h" namespace art { diff --git a/runtime/dex/dex_file_layout.cc b/runtime/dex/dex_file_layout.cc index 1973440d55..312898d82f 100644 --- a/runtime/dex/dex_file_layout.cc +++ b/runtime/dex/dex_file_layout.cc @@ -19,8 +19,8 @@ #include <sys/mman.h> #include "base/file_utils.h" +#include "descriptors_names.h" #include "dex_file.h" -#include "utils.h" namespace art { diff --git a/runtime/dex/dex_file_test.cc b/runtime/dex/dex_file_test.cc index cb721af754..998bfd6c7f 100644 --- a/runtime/dex/dex_file_test.cc +++ b/runtime/dex/dex_file_test.cc @@ -25,13 +25,13 @@ #include "base/unix_file/fd_file.h" #include "code_item_accessors-inl.h" #include "common_runtime_test.h" +#include "descriptors_names.h" #include "dex_file-inl.h" #include "dex_file_loader.h" #include "mem_map.h" #include "os.h" #include "scoped_thread_state_change-inl.h" #include "thread-current-inl.h" -#include "utils.h" namespace art { diff --git a/runtime/dex/dex_file_verifier.cc b/runtime/dex/dex_file_verifier.cc index f7fdbb027c..62667052ad 100644 --- a/runtime/dex/dex_file_verifier.cc +++ b/runtime/dex/dex_file_verifier.cc @@ -23,14 +23,12 @@ #include "android-base/stringprintf.h" -#include "code_item_accessors-no_art-inl.h" +#include "code_item_accessors-inl.h" +#include "descriptors_names.h" #include "dex_file-inl.h" -#include "experimental_flags.h" #include "leb128.h" #include "modifiers.h" -#include "safe_map.h" #include "utf-inl.h" -#include "utils.h" namespace art { diff --git a/runtime/dex/dex_file_verifier_test.cc b/runtime/dex/dex_file_verifier_test.cc index 9759685961..d73a7fbfa3 100644 --- a/runtime/dex/dex_file_verifier_test.cc +++ b/runtime/dex/dex_file_verifier_test.cc @@ -27,6 +27,7 @@ #include "base/macros.h" #include "base/unix_file/fd_file.h" #include "common_runtime_test.h" +#include "descriptors_names.h" #include "dex_file-inl.h" #include "dex_file_loader.h" #include "dex_file_types.h" @@ -34,7 +35,6 @@ #include "scoped_thread_state_change-inl.h" #include "standard_dex_file.h" #include "thread-current-inl.h" -#include "utils.h" namespace art { diff --git a/runtime/dex/dex_instruction.cc b/runtime/dex/dex_instruction.cc index 6ebe2286e8..b84791ffae 100644 --- a/runtime/dex/dex_instruction.cc +++ b/runtime/dex/dex_instruction.cc @@ -24,7 +24,7 @@ #include "android-base/stringprintf.h" #include "dex_file-inl.h" -#include "utils.h" +#include "utf.h" namespace art { diff --git a/runtime/dex/standard_dex_file.cc b/runtime/dex/standard_dex_file.cc index 024f73b4e5..f7317eb997 100644 --- a/runtime/dex/standard_dex_file.cc +++ b/runtime/dex/standard_dex_file.cc @@ -17,7 +17,7 @@ #include "standard_dex_file.h" #include "base/casts.h" -#include "code_item_accessors-no_art-inl.h" +#include "code_item_accessors-inl.h" #include "dex_file-inl.h" #include "leb128.h" diff --git a/runtime/utf-inl.h b/runtime/dex/utf-inl.h index b2d6765fb0..4f626a8580 100644 --- a/runtime/utf-inl.h +++ b/runtime/dex/utf-inl.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ART_RUNTIME_UTF_INL_H_ -#define ART_RUNTIME_UTF_INL_H_ +#ifndef ART_RUNTIME_DEX_UTF_INL_H_ +#define ART_RUNTIME_DEX_UTF_INL_H_ #include "utf.h" @@ -96,4 +96,4 @@ inline int CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(const char* u } // namespace art -#endif // ART_RUNTIME_UTF_INL_H_ +#endif // ART_RUNTIME_DEX_UTF_INL_H_ diff --git a/runtime/utf.cc b/runtime/dex/utf.cc index 32ae187297..772a610140 100644 --- a/runtime/utf.cc +++ b/runtime/dex/utf.cc @@ -17,12 +17,17 @@ #include "utf.h" #include <android-base/logging.h> +#include <android-base/stringprintf.h> +#include <android-base/strings.h> #include "base/casts.h" #include "utf-inl.h" namespace art { +using android::base::StringAppendF; +using android::base::StringPrintf; + // This is used only from debugger and test code. size_t CountModifiedUtf8Chars(const char* utf8) { return CountModifiedUtf8Chars(utf8, strlen(utf8)); @@ -262,4 +267,55 @@ size_t CountUtf8Bytes(const uint16_t* chars, size_t char_count) { return result; } +static inline constexpr bool NeedsEscaping(uint16_t ch) { + return (ch < ' ' || ch > '~'); +} + +std::string PrintableChar(uint16_t ch) { + std::string result; + result += '\''; + if (NeedsEscaping(ch)) { + StringAppendF(&result, "\\u%04x", ch); + } else { + result += static_cast<std::string::value_type>(ch); + } + result += '\''; + return result; +} + +std::string PrintableString(const char* utf) { + std::string result; + result += '"'; + const char* p = utf; + size_t char_count = CountModifiedUtf8Chars(p); + for (size_t i = 0; i < char_count; ++i) { + uint32_t ch = GetUtf16FromUtf8(&p); + if (ch == '\\') { + result += "\\\\"; + } else if (ch == '\n') { + result += "\\n"; + } else if (ch == '\r') { + result += "\\r"; + } else if (ch == '\t') { + result += "\\t"; + } else { + const uint16_t leading = GetLeadingUtf16Char(ch); + + if (NeedsEscaping(leading)) { + StringAppendF(&result, "\\u%04x", leading); + } else { + result += static_cast<std::string::value_type>(leading); + } + + const uint32_t trailing = GetTrailingUtf16Char(ch); + if (trailing != 0) { + // All high surrogates will need escaping. + StringAppendF(&result, "\\u%04x", trailing); + } + } + } + result += '"'; + return result; +} + } // namespace art diff --git a/runtime/utf.h b/runtime/dex/utf.h index cbb32fa6cd..4adfc4af8c 100644 --- a/runtime/utf.h +++ b/runtime/dex/utf.h @@ -14,14 +14,16 @@ * limitations under the License. */ -#ifndef ART_RUNTIME_UTF_H_ -#define ART_RUNTIME_UTF_H_ +#ifndef ART_RUNTIME_DEX_UTF_H_ +#define ART_RUNTIME_DEX_UTF_H_ #include "base/macros.h" #include <stddef.h> #include <stdint.h> +#include <string> + /* * All UTF-8 in art is actually modified UTF-8. Mostly, this distinction * doesn't matter. @@ -121,6 +123,13 @@ ALWAYS_INLINE uint16_t GetLeadingUtf16Char(uint32_t maybe_pair); */ ALWAYS_INLINE uint16_t GetTrailingUtf16Char(uint32_t maybe_pair); +// Returns a printable (escaped) version of a character. +std::string PrintableChar(uint16_t ch); + +// Returns an ASCII string corresponding to the given UTF-8 string. +// Java escapes are used for non-ASCII characters. +std::string PrintableString(const char* utf8); + } // namespace art -#endif // ART_RUNTIME_UTF_H_ +#endif // ART_RUNTIME_DEX_UTF_H_ diff --git a/runtime/utf_test.cc b/runtime/dex/utf_test.cc index d1e97515d3..d1e97515d3 100644 --- a/runtime/utf_test.cc +++ b/runtime/dex/utf_test.cc diff --git a/runtime/entrypoints/quick/quick_throw_entrypoints.cc b/runtime/entrypoints/quick/quick_throw_entrypoints.cc index 565b4edcc3..9b0756b529 100644 --- a/runtime/entrypoints/quick/quick_throw_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_throw_entrypoints.cc @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "art_method-inl.h" #include "callee_save_frame.h" #include "common_throws.h" #include "mirror/object-inl.h" diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc index f727690c11..c5157ce9f4 100644 --- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc @@ -785,7 +785,7 @@ extern "C" uint64_t artQuickToInterpreterBridge(ArtMethod* method, Thread* self, uint32_t shorty_len = 0; ArtMethod* non_proxy_method = method->GetInterfaceMethodIfProxy(kRuntimePointerSize); DCHECK(non_proxy_method->GetCodeItem() != nullptr) << method->PrettyMethod(); - CodeItemDataAccessor accessor(non_proxy_method); + CodeItemDataAccessor accessor(non_proxy_method->DexInstructionData()); const char* shorty = non_proxy_method->GetShorty(&shorty_len); JValue result; @@ -1121,7 +1121,7 @@ extern "C" const void* artQuickResolutionTrampoline( // code. if (!found_stack_map || kIsDebugBuild) { uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp); - CodeItemInstructionAccessor accessor(caller); + CodeItemInstructionAccessor accessor(caller->DexInstructions()); CHECK_LT(dex_pc, accessor.InsnsSizeInCodeUnits()); const Instruction& instr = accessor.InstructionAt(dex_pc); Instruction::Code instr_code = instr.Opcode(); diff --git a/runtime/gc/heap-inl.h b/runtime/gc/heap-inl.h index 52dd104ac8..6735961591 100644 --- a/runtime/gc/heap-inl.h +++ b/runtime/gc/heap-inl.h @@ -106,8 +106,8 @@ inline mirror::Object* Heap::AllocObjectWithAllocator(Thread* self, pre_fence_visitor(obj, usable_size); QuasiAtomic::ThreadFenceForConstructor(); } else { - // bytes allocated that takes bulk thread-local buffer allocations into account. - size_t bytes_tl_bulk_allocated = 0; + // Bytes allocated that takes bulk thread-local buffer allocations into account. + size_t bytes_tl_bulk_allocated = 0u; obj = TryToAllocate<kInstrumented, false>(self, allocator, byte_count, &bytes_allocated, &usable_size, &bytes_tl_bulk_allocated); if (UNLIKELY(obj == nullptr)) { @@ -154,12 +154,13 @@ inline mirror::Object* Heap::AllocObjectWithAllocator(Thread* self, } pre_fence_visitor(obj, usable_size); QuasiAtomic::ThreadFenceForConstructor(); - new_num_bytes_allocated = num_bytes_allocated_.FetchAndAddRelaxed(bytes_tl_bulk_allocated) + - bytes_tl_bulk_allocated; + size_t num_bytes_allocated_before = + num_bytes_allocated_.FetchAndAddRelaxed(bytes_tl_bulk_allocated); + new_num_bytes_allocated = num_bytes_allocated_before + bytes_tl_bulk_allocated; if (bytes_tl_bulk_allocated > 0) { // Only trace when we get an increase in the number of bytes allocated. This happens when // obtaining a new TLAB and isn't often enough to hurt performance according to golem. - TraceHeapSize(new_num_bytes_allocated + bytes_tl_bulk_allocated); + TraceHeapSize(new_num_bytes_allocated); } } if (kIsDebugBuild && Runtime::Current()->IsStarted()) { diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h index de3a51a2ac..f476028d5f 100644 --- a/runtime/hidden_api.h +++ b/runtime/hidden_api.h @@ -24,144 +24,110 @@ namespace art { namespace hiddenapi { -// Returns true if member with `access flags` should only be accessed from -// boot class path. -inline bool IsMemberHidden(uint32_t access_flags) { - if (!Runtime::Current()->AreHiddenApiChecksEnabled()) { - return false; - } +enum Action { + kAllow, + kAllowButWarn, + kDeny +}; +inline Action GetMemberAction(uint32_t access_flags) { switch (HiddenApiAccessFlags::DecodeFromRuntime(access_flags)) { case HiddenApiAccessFlags::kWhitelist: + return kAllow; case HiddenApiAccessFlags::kLightGreylist: case HiddenApiAccessFlags::kDarkGreylist: - return false; + return kAllowButWarn; case HiddenApiAccessFlags::kBlacklist: - return true; + return kDeny; } } -// Returns true if we should warn about non-boot class path accessing member -// with `access_flags`. -inline bool ShouldWarnAboutMember(uint32_t access_flags) { - if (!Runtime::Current()->AreHiddenApiChecksEnabled()) { - return false; - } - - switch (HiddenApiAccessFlags::DecodeFromRuntime(access_flags)) { - case HiddenApiAccessFlags::kWhitelist: - return false; - case HiddenApiAccessFlags::kLightGreylist: - case HiddenApiAccessFlags::kDarkGreylist: - return true; - case HiddenApiAccessFlags::kBlacklist: - // We should never access a blacklisted member from non-boot class path, - // but this function is called before we establish the origin of the access. - // Return false here, we do not want to warn when boot class path accesses - // a blacklisted member. - return false; - } -} - -// Returns true if caller `num_frames` up the stack is in boot class path. -inline bool IsCallerInBootClassPath(Thread* self, size_t num_frames) - REQUIRES_SHARED(Locks::mutator_lock_) { - ObjPtr<mirror::Class> klass = GetCallingClass(self, num_frames); - if (klass == nullptr) { - // Unattached native thread. Assume that this is *not* boot class path. - return false; - } - return klass->IsBootStrapClassLoaded(); +// Issue a warning about field access. +inline void WarnAboutMemberAccess(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_) { + std::string tmp; + LOG(WARNING) << "Accessing hidden field " + << field->GetDeclaringClass()->GetDescriptor(&tmp) << "->" + << field->GetName() << ":" << field->GetTypeDescriptor(); } -// Returns true if `caller` should not be allowed to access member with `access_flags`. -inline bool ShouldBlockAccessToMember(uint32_t access_flags, mirror::Class* caller) - REQUIRES_SHARED(Locks::mutator_lock_) { - return IsMemberHidden(access_flags) && - !caller->IsBootStrapClassLoaded(); +// Issue a warning about method access. +inline void WarnAboutMemberAccess(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) { + std::string tmp; + LOG(WARNING) << "Accessing hidden method " + << method->GetDeclaringClass()->GetDescriptor(&tmp) << "->" + << method->GetName() << method->GetSignature().ToString(); } -// Returns true if `caller` should not be allowed to access `member`. +// Returns true if access to `member` should be denied to the caller of the +// reflective query. The decision is based on whether the caller is in boot +// class path or not. Because different users of this function determine this +// in a different way, `fn_caller_in_boot(self)` is called and should return +// true if the caller is in boot class path. +// This function might print warnings into the log if the member is greylisted. template<typename T> -inline bool ShouldBlockAccessToMember(T* member, ArtMethod* caller) +inline bool ShouldBlockAccessToMember(T* member, + Thread* self, + std::function<bool(Thread*)> fn_caller_in_boot) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK(member != nullptr); - DCHECK(!caller->IsRuntimeMethod()); - return ShouldBlockAccessToMember(member->GetAccessFlags(), caller->GetDeclaringClass()); -} -// Returns true if the caller `num_frames` up the stack should not be allowed -// to access `member`. -template<typename T> -inline bool ShouldBlockAccessToMember(T* member, Thread* self, size_t num_frames) - REQUIRES_SHARED(Locks::mutator_lock_) { - DCHECK(member != nullptr); - return IsMemberHidden(member->GetAccessFlags()) && - !IsCallerInBootClassPath(self, num_frames); // This is expensive. Save it for last. -} + if (!Runtime::Current()->AreHiddenApiChecksEnabled()) { + // Exit early. Nothing to enforce. + return false; + } -// Issue a warning about field access. -inline void WarnAboutMemberAccess(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_) { - Runtime::Current()->SetPendingHiddenApiWarning(true); - LOG(WARNING) << "Access to hidden field " << field->PrettyField(); -} + Action action = GetMemberAction(member->GetAccessFlags()); + if (action == kAllow) { + // Nothing to do. + return false; + } -// Issue a warning about method access. -inline void WarnAboutMemberAccess(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) { - Runtime::Current()->SetPendingHiddenApiWarning(true); - LOG(WARNING) << "Access to hidden method " << method->PrettyMethod(); -} + // Member is hidden. Walk the stack to find the caller. + // This can be *very* expensive. Save it for last. + if (fn_caller_in_boot(self)) { + // Caller in boot class path. Exit. + return false; + } -// Set access flags of `member` to be in hidden API whitelist. This can be disabled -// with a Runtime::SetDedupHiddenApiWarnings. -template<typename T> -inline void MaybeWhitelistMember(T* member) REQUIRES_SHARED(Locks::mutator_lock_) { - if (Runtime::Current()->ShouldDedupeHiddenApiWarnings()) { - member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime( - member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist)); - DCHECK(!ShouldWarnAboutMember(member->GetAccessFlags())); + // Member is hidden and we are not in the boot class path. Act accordingly. + if (action == kAllowButWarn) { + // Allow access to this member but print a warning. Depending on a runtime + // flag, we might move the member into whitelist and skip the warning the + // next time the member is used. + Runtime::Current()->SetPendingHiddenApiWarning(true); + if (Runtime::Current()->ShouldDedupeHiddenApiWarnings()) { + member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime( + member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist)); + } + WarnAboutMemberAccess(member); + return false; + } else { + DCHECK_EQ(action, hiddenapi::kDeny); + return true; } } -// Check if `caller` should be allowed to access `member` and warn if not. -template<typename T> -inline void MaybeWarnAboutMemberAccess(T* member, ArtMethod* caller) +// Returns true if access to member with `access_flags` should be denied to `caller`. +// This function should be called on statically linked uses of hidden API. +inline bool ShouldBlockAccessToMember(uint32_t access_flags, mirror::Class* caller) REQUIRES_SHARED(Locks::mutator_lock_) { - DCHECK(member != nullptr); - DCHECK(!caller->IsRuntimeMethod()); - if (!Runtime::Current()->AreHiddenApiChecksEnabled() || - member == nullptr || - !ShouldWarnAboutMember(member->GetAccessFlags()) || - caller->GetDeclaringClass()->IsBootStrapClassLoaded()) { - return; + if (!Runtime::Current()->AreHiddenApiChecksEnabled()) { + // Exit early. Nothing to enforce. + return false; } - WarnAboutMember(member); - MaybeWhitelistMember(member); -} - -// Check if the caller `num_frames` up the stack should be allowed to access -// `member` and warn if not. -template<typename T> -inline void MaybeWarnAboutMemberAccess(T* member, Thread* self, size_t num_frames) - REQUIRES_SHARED(Locks::mutator_lock_) { - if (!Runtime::Current()->AreHiddenApiChecksEnabled() || - member == nullptr || - !ShouldWarnAboutMember(member->GetAccessFlags())) { - return; + // Only continue if we want to deny access. Warnings are *not* printed. + if (GetMemberAction(access_flags) != kDeny) { + return false; } - // Walk the stack to find the caller. This is *very* expensive. Save it for last. - ObjPtr<mirror::Class> klass = GetCallingClass(self, num_frames); - if (klass == nullptr) { - // Unattached native thread, assume that this is *not* boot class path - // and enforce the rules. - } else if (klass->IsBootStrapClassLoaded()) { - return; + // Member is hidden. Check if the caller is in boot class path. + if (caller == nullptr) { + // The caller is unknown. We assume that this is *not* boot class path. + return true; } - WarnAboutMemberAccess(member); - MaybeWhitelistMember(member); + return !caller->IsBootStrapClassLoaded(); } } // namespace hiddenapi diff --git a/runtime/imtable-inl.h b/runtime/imtable-inl.h index 6237cca9e4..93346f6151 100644 --- a/runtime/imtable-inl.h +++ b/runtime/imtable-inl.h @@ -21,7 +21,7 @@ #include "art_method-inl.h" #include "dex/dex_file.h" -#include "utf.h" +#include "dex/utf.h" namespace art { diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc index 2101f6837b..24cedb093b 100644 --- a/runtime/instrumentation.cc +++ b/runtime/instrumentation.cc @@ -1384,8 +1384,8 @@ TwoWordReturn Instrumentation::PopInstrumentationStackFrame(Thread* self, reinterpret_cast<uintptr_t>(GetQuickDeoptimizationEntryPoint())); } else { if (deoptimize && !Runtime::Current()->IsAsyncDeoptimizeable(*return_pc)) { - LOG(WARNING) << "Got a deoptimization request on un-deoptimizable " << method->PrettyMethod() - << " at PC " << reinterpret_cast<void*>(*return_pc); + VLOG(deopt) << "Got a deoptimization request on un-deoptimizable " << method->PrettyMethod() + << " at PC " << reinterpret_cast<void*>(*return_pc); } if (kVerboseInstrumentation) { LOG(INFO) << "Returning from " << method->PrettyMethod() diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc index 5b93d3b873..4b964f648b 100644 --- a/runtime/intern_table.cc +++ b/runtime/intern_table.cc @@ -18,6 +18,7 @@ #include <memory> +#include "dex/utf.h" #include "gc/collector/garbage_collector.h" #include "gc/space/image_space.h" #include "gc/weak_root_state.h" @@ -30,7 +31,6 @@ #include "object_callbacks.h" #include "scoped_thread_state_change-inl.h" #include "thread.h" -#include "utf.h" namespace art { diff --git a/runtime/intern_table_test.cc b/runtime/intern_table_test.cc index 9c3ea8d864..b56c48d78c 100644 --- a/runtime/intern_table_test.cc +++ b/runtime/intern_table_test.cc @@ -18,12 +18,12 @@ #include "base/hash_set.h" #include "common_runtime_test.h" +#include "dex/utf.h" #include "gc_root-inl.h" #include "handle_scope-inl.h" #include "mirror/object.h" #include "mirror/string.h" #include "scoped_thread_state_change-inl.h" -#include "utf.h" namespace art { diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc index 54db87297d..735c0e815a 100644 --- a/runtime/interpreter/interpreter.cc +++ b/runtime/interpreter/interpreter.cc @@ -389,7 +389,7 @@ void EnterInterpreterFromInvoke(Thread* self, } const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke"); - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); uint16_t num_regs; uint16_t num_ins; if (accessor.HasCodeItem()) { @@ -499,7 +499,7 @@ void EnterInterpreterFromDeoptimize(Thread* self, DCHECK(!shadow_frame->GetMethod()->MustCountLocks()); self->SetTopOfShadowStack(shadow_frame); - CodeItemDataAccessor accessor(shadow_frame->GetMethod()); + CodeItemDataAccessor accessor(shadow_frame->GetMethod()->DexInstructionData()); const uint32_t dex_pc = shadow_frame->GetDexPC(); uint32_t new_dex_pc = dex_pc; if (UNLIKELY(self->IsExceptionPending())) { diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index 475f93803d..d53da215a2 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -1320,7 +1320,7 @@ static inline bool DoCallCommon(ArtMethod* called_method, } // Compute method information. - CodeItemDataAccessor accessor(called_method); + CodeItemDataAccessor accessor(called_method->DexInstructionData()); // Number of registers for the callee's call frame. uint16_t num_regs; // Test whether to use the interpreter or compiler entrypoint, and save that result to pass to diff --git a/runtime/interpreter/shadow_frame.cc b/runtime/interpreter/shadow_frame.cc index fe7e3e0a9b..264ec6a997 100644 --- a/runtime/interpreter/shadow_frame.cc +++ b/runtime/interpreter/shadow_frame.cc @@ -28,7 +28,7 @@ mirror::Object* ShadowFrame::GetThisObject() const { return GetVRegReference(0); } else { CHECK(m->GetCodeItem() != nullptr) << ArtMethod::PrettyMethod(m); - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); uint16_t reg = accessor.RegistersSize() - accessor.InsSize(); return GetVRegReference(reg); } diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc index b9b00519d1..85acc71377 100644 --- a/runtime/interpreter/unstarted_runtime.cc +++ b/runtime/interpreter/unstarted_runtime.cc @@ -176,6 +176,13 @@ static mirror::String* GetClassName(Thread* self, ShadowFrame* shadow_frame, siz return param->AsString(); } +template<typename T> +static ALWAYS_INLINE bool ShouldBlockAccessToMember(T* member, ShadowFrame* frame) + REQUIRES_SHARED(Locks::mutator_lock_) { + return hiddenapi::ShouldBlockAccessToMember( + member->GetAccessFlags(), frame->GetMethod()->GetDeclaringClass()); +} + void UnstartedRuntime::UnstartedClassForNameCommon(Thread* self, ShadowFrame* shadow_frame, JValue* result, @@ -267,8 +274,7 @@ void UnstartedRuntime::UnstartedClassNewInstance( auto* cl = Runtime::Current()->GetClassLinker(); if (cl->EnsureInitialized(self, h_klass, true, true)) { ArtMethod* cons = h_klass->FindConstructor("()V", cl->GetImagePointerSize()); - if (cons != nullptr && - hiddenapi::ShouldBlockAccessToMember(cons, shadow_frame->GetMethod())) { + if (cons != nullptr && ShouldBlockAccessToMember(cons, shadow_frame)) { cons = nullptr; } if (cons != nullptr) { @@ -313,8 +319,7 @@ void UnstartedRuntime::UnstartedClassGetDeclaredField( } } } - if (found != nullptr && - hiddenapi::ShouldBlockAccessToMember(found, shadow_frame->GetMethod())) { + if (found != nullptr && ShouldBlockAccessToMember(found, shadow_frame)) { found = nullptr; } if (found == nullptr) { @@ -379,8 +384,7 @@ void UnstartedRuntime::UnstartedClassGetDeclaredMethod( self, klass, name, args); } } - if (method != nullptr && - hiddenapi::ShouldBlockAccessToMember(method->GetArtMethod(), shadow_frame->GetMethod())) { + if (method != nullptr && ShouldBlockAccessToMember(method->GetArtMethod(), shadow_frame)) { method = nullptr; } result->SetL(method); @@ -418,8 +422,7 @@ void UnstartedRuntime::UnstartedClassGetDeclaredConstructor( } } if (constructor != nullptr && - hiddenapi::ShouldBlockAccessToMember( - constructor->GetArtMethod(), shadow_frame->GetMethod())) { + ShouldBlockAccessToMember(constructor->GetArtMethod(), shadow_frame)) { constructor = nullptr; } result->SetL(constructor); diff --git a/runtime/jdwp/jdwp_handler.cc b/runtime/jdwp/jdwp_handler.cc index 89eef88b88..90cac853ff 100644 --- a/runtime/jdwp/jdwp_handler.cc +++ b/runtime/jdwp/jdwp_handler.cc @@ -27,6 +27,7 @@ #include "base/logging.h" // For VLOG. #include "base/macros.h" #include "debugger.h" +#include "dex/utf.h" #include "jdwp/jdwp_constants.h" #include "jdwp/jdwp_event.h" #include "jdwp/jdwp_expand_buf.h" @@ -34,7 +35,6 @@ #include "runtime.h" #include "scoped_thread_state_change-inl.h" #include "thread-current-inl.h" -#include "utils.h" namespace art { diff --git a/runtime/jit/debugger_interface.cc b/runtime/jit/debugger_interface.cc index 0e295e2442..d60f70a54f 100644 --- a/runtime/jit/debugger_interface.cc +++ b/runtime/jit/debugger_interface.cc @@ -68,11 +68,65 @@ extern "C" { // Static initialization is necessary to prevent GDB from seeing // uninitialized descriptor. JITDescriptor __jit_debug_descriptor = { 1, JIT_NOACTION, nullptr, nullptr }; + + // Incremented whenever __jit_debug_descriptor is modified. + uint32_t __jit_debug_descriptor_timestamp = 0; + + struct DEXFileEntry { + DEXFileEntry* next_; + DEXFileEntry* prev_; + const void* dexfile_; + }; + + DEXFileEntry* __art_debug_dexfiles = nullptr; + + // Incremented whenever __art_debug_dexfiles is modified. + uint32_t __art_debug_dexfiles_timestamp = 0; } -Mutex g_jit_debug_mutex("JIT debug interface lock", kJitDebugInterfaceLock); +static size_t g_jit_debug_mem_usage + GUARDED_BY(Locks::native_debug_interface_lock_) = 0; + +static std::unordered_map<const void*, DEXFileEntry*> g_dexfile_entries + GUARDED_BY(Locks::native_debug_interface_lock_); + +void RegisterDexFileForNative(Thread* current_thread, const void* dexfile_header) { + MutexLock mu(current_thread, *Locks::native_debug_interface_lock_); + if (g_dexfile_entries.count(dexfile_header) == 0) { + DEXFileEntry* entry = new DEXFileEntry(); + CHECK(entry != nullptr); + entry->dexfile_ = dexfile_header; + entry->prev_ = nullptr; + entry->next_ = __art_debug_dexfiles; + if (entry->next_ != nullptr) { + entry->next_->prev_ = entry; + } + __art_debug_dexfiles = entry; + __art_debug_dexfiles_timestamp++; + g_dexfile_entries.emplace(dexfile_header, entry); + } +} -static size_t g_jit_debug_mem_usage = 0; +void DeregisterDexFileForNative(Thread* current_thread, const void* dexfile_header) { + MutexLock mu(current_thread, *Locks::native_debug_interface_lock_); + auto it = g_dexfile_entries.find(dexfile_header); + // We register dex files in the class linker and free them in DexFile_closeDexFile, + // but might be cases where we load the dex file without using it in the class linker. + if (it != g_dexfile_entries.end()) { + DEXFileEntry* entry = it->second; + if (entry->prev_ != nullptr) { + entry->prev_->next_ = entry->next_; + } else { + __art_debug_dexfiles = entry->next_; + } + if (entry->next_ != nullptr) { + entry->next_->prev_ = entry->prev_; + } + __art_debug_dexfiles_timestamp++; + delete entry; + g_dexfile_entries.erase(it); + } +} JITCodeEntry* CreateJITCodeEntry(const std::vector<uint8_t>& symfile) { DCHECK_NE(symfile.size(), 0u); @@ -96,6 +150,7 @@ JITCodeEntry* CreateJITCodeEntry(const std::vector<uint8_t>& symfile) { __jit_debug_descriptor.first_entry_ = entry; __jit_debug_descriptor.relevant_entry_ = entry; __jit_debug_descriptor.action_flag_ = JIT_REGISTER_FN; + __jit_debug_descriptor_timestamp++; (*__jit_debug_register_code_ptr)(); return entry; } @@ -114,6 +169,7 @@ void DeleteJITCodeEntry(JITCodeEntry* entry) { g_jit_debug_mem_usage -= sizeof(JITCodeEntry) + entry->symfile_size_; __jit_debug_descriptor.relevant_entry_ = entry; __jit_debug_descriptor.action_flag_ = JIT_UNREGISTER_FN; + __jit_debug_descriptor_timestamp++; (*__jit_debug_register_code_ptr)(); delete[] entry->symfile_addr_; delete entry; @@ -121,7 +177,7 @@ void DeleteJITCodeEntry(JITCodeEntry* entry) { // Mapping from code address to entry. Used to manage life-time of the entries. static std::unordered_map<uintptr_t, JITCodeEntry*> g_jit_code_entries - GUARDED_BY(g_jit_debug_mutex); + GUARDED_BY(Locks::native_debug_interface_lock_); void IncrementJITCodeEntryRefcount(JITCodeEntry* entry, uintptr_t code_address) { DCHECK(entry != nullptr); diff --git a/runtime/jit/debugger_interface.h b/runtime/jit/debugger_interface.h index 9aec988f67..8c4bb3fdf4 100644 --- a/runtime/jit/debugger_interface.h +++ b/runtime/jit/debugger_interface.h @@ -30,36 +30,42 @@ extern "C" { struct JITCodeEntry; } -extern Mutex g_jit_debug_mutex; +// Notify native tools (e.g. libunwind) that DEX file has been opened. +// The pointer needs to point the start of the dex data (not the DexFile* object). +void RegisterDexFileForNative(Thread* current_thread, const void* dexfile_header); + +// Notify native tools (e.g. libunwind) that DEX file has been closed. +// The pointer needs to point the start of the dex data (not the DexFile* object). +void DeregisterDexFileForNative(Thread* current_thread, const void* dexfile_header); // Notify native debugger about new JITed code by passing in-memory ELF. // It takes ownership of the in-memory ELF file. JITCodeEntry* CreateJITCodeEntry(const std::vector<uint8_t>& symfile) - REQUIRES(g_jit_debug_mutex); + REQUIRES(Locks::native_debug_interface_lock_); // Notify native debugger that JITed code has been removed. // It also releases the associated in-memory ELF file. void DeleteJITCodeEntry(JITCodeEntry* entry) - REQUIRES(g_jit_debug_mutex); + REQUIRES(Locks::native_debug_interface_lock_); // Helper method to track life-time of JITCodeEntry. // It registers given code address as being described by the given entry. void IncrementJITCodeEntryRefcount(JITCodeEntry* entry, uintptr_t code_address) - REQUIRES(g_jit_debug_mutex); + REQUIRES(Locks::native_debug_interface_lock_); // Helper method to track life-time of JITCodeEntry. // It de-registers given code address as being described by the given entry. void DecrementJITCodeEntryRefcount(JITCodeEntry* entry, uintptr_t code_address) - REQUIRES(g_jit_debug_mutex); + REQUIRES(Locks::native_debug_interface_lock_); // Find the registered JITCodeEntry for given code address. // There can be only one entry per address at any given time. JITCodeEntry* GetJITCodeEntry(uintptr_t code_address) - REQUIRES(g_jit_debug_mutex); + REQUIRES(Locks::native_debug_interface_lock_); // Returns approximate memory used by all JITCodeEntries. size_t GetJITCodeEntryMemUsage() - REQUIRES(g_jit_debug_mutex); + REQUIRES(Locks::native_debug_interface_lock_); } // namespace art diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 12bf79d7ca..1baa613bb5 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -467,7 +467,7 @@ bool Jit::MaybeDoOnStackReplacement(Thread* thread, // Fetch some data before looking up for an OSR method. We don't want thread // suspension once we hold an OSR method, as the JIT code cache could delete the OSR // method while we are being suspended. - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); const size_t number_of_vregs = accessor.RegistersSize(); const char* shorty = method->GetShorty(); std::string method_name(VLOG_IS_ON(jit) ? method->PrettyMethod() : ""); diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc index 7f0447732e..c8c13cb20f 100644 --- a/runtime/jit/jit_code_cache.cc +++ b/runtime/jit/jit_code_cache.cc @@ -549,7 +549,7 @@ void JitCodeCache::FreeCode(const void* code_ptr) { uintptr_t allocation = FromCodeToAllocation(code_ptr); // Notify native debugger that we are about to remove the code. // It does nothing if we are not using native debugger. - MutexLock mu(Thread::Current(), g_jit_debug_mutex); + MutexLock mu(Thread::Current(), *Locks::native_debug_interface_lock_); JITCodeEntry* entry = GetJITCodeEntry(reinterpret_cast<uintptr_t>(code_ptr)); if (entry != nullptr) { DecrementJITCodeEntryRefcount(entry, reinterpret_cast<uintptr_t>(code_ptr)); @@ -1825,7 +1825,7 @@ void JitCodeCache::FreeData(uint8_t* data) { void JitCodeCache::Dump(std::ostream& os) { MutexLock mu(Thread::Current(), lock_); - MutexLock mu2(Thread::Current(), g_jit_debug_mutex); + MutexLock mu2(Thread::Current(), *Locks::native_debug_interface_lock_); os << "Current JIT code cache size: " << PrettySize(used_memory_for_code_) << "\n" << "Current JIT data cache size: " << PrettySize(used_memory_for_data_) << "\n" << "Current JIT mini-debug-info size: " << PrettySize(GetJITCodeEntryMemUsage()) << "\n" diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index c40360f612..666fb98354 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -33,6 +33,7 @@ #include "base/stl_util.h" #include "class_linker-inl.h" #include "dex/dex_file-inl.h" +#include "dex/utf.h" #include "fault_handler.h" #include "hidden_api.h" #include "gc/accounting/card_table-inl.h" @@ -57,7 +58,6 @@ #include "safe_map.h" #include "scoped_thread_state_change-inl.h" #include "thread.h" -#include "utf.h" #include "well_known_classes.h" namespace { @@ -80,17 +80,28 @@ namespace art { // things not rendering correctly. E.g. b/16858794 static constexpr bool kWarnJniAbort = false; -// Helpers to check if we need to warn about accessing hidden API fields and to call instrumentation -// functions for them. These take jobjects so we don't need to set up handles for the rare case -// where these actually do something. Once these functions return it is possible there will be -// a pending exception if the instrumentation happens to throw one. +static bool IsCallerInBootClassPath(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { + ObjPtr<mirror::Class> klass = GetCallingClass(self, /* num_frames */ 1); + // If `klass` is null, it is an unattached native thread. Assume this is + // *not* boot class path. + return klass != nullptr && klass->IsBootStrapClassLoaded(); +} + +template<typename T> +ALWAYS_INLINE static bool ShouldBlockAccessToMember(T* member, Thread* self) + REQUIRES_SHARED(Locks::mutator_lock_) { + return hiddenapi::ShouldBlockAccessToMember(member, self, IsCallerInBootClassPath); +} + +// Helpers to call instrumentation functions for fields. These take jobjects so we don't need to set +// up handles for the rare case where these actually do something. Once these functions return it is +// possible there will be a pending exception if the instrumentation happens to throw one. static void NotifySetObjectField(ArtField* field, jobject obj, jobject jval) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK_EQ(field->GetTypeAsPrimitiveType(), Primitive::kPrimNot); - Thread* self = Thread::Current(); - hiddenapi::MaybeWarnAboutMemberAccess(field, self, /* num_frames */ 1); instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { + Thread* self = Thread::Current(); ArtMethod* cur_method = self->GetCurrentMethod(/*dex_pc*/ nullptr, /*check_suspended*/ true, /*abort_on_error*/ false); @@ -115,10 +126,9 @@ static void NotifySetObjectField(ArtField* field, jobject obj, jobject jval) static void NotifySetPrimitiveField(ArtField* field, jobject obj, JValue val) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK_NE(field->GetTypeAsPrimitiveType(), Primitive::kPrimNot); - Thread* self = Thread::Current(); - hiddenapi::MaybeWarnAboutMemberAccess(field, self, /* num_frames */ 1); instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { + Thread* self = Thread::Current(); ArtMethod* cur_method = self->GetCurrentMethod(/*dex_pc*/ nullptr, /*check_suspended*/ true, /*abort_on_error*/ false); @@ -140,10 +150,9 @@ static void NotifySetPrimitiveField(ArtField* field, jobject obj, JValue val) static void NotifyGetField(ArtField* field, jobject obj) REQUIRES_SHARED(Locks::mutator_lock_) { - Thread* self = Thread::Current(); - hiddenapi::MaybeWarnAboutMemberAccess(field, self, /* num_frames */ 1); instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); if (UNLIKELY(instrumentation->HasFieldReadListeners())) { + Thread* self = Thread::Current(); ArtMethod* cur_method = self->GetCurrentMethod(/*dex_pc*/ nullptr, /*check_suspended*/ true, /*abort_on_error*/ false); @@ -243,8 +252,7 @@ static jmethodID FindMethodID(ScopedObjectAccess& soa, jclass jni_class, } else { method = c->FindClassMethod(name, sig, pointer_size); } - if (method != nullptr && - hiddenapi::ShouldBlockAccessToMember(method, soa.Self(), /* num_frames */ 1)) { + if (method != nullptr && ShouldBlockAccessToMember(method, soa.Self())) { method = nullptr; } if (method == nullptr || method->IsStatic() != is_static) { @@ -323,8 +331,7 @@ static jfieldID FindFieldID(const ScopedObjectAccess& soa, jclass jni_class, con } else { field = c->FindInstanceField(name, field_type->GetDescriptor(&temp)); } - if (field != nullptr && - hiddenapi::ShouldBlockAccessToMember(field, soa.Self(), /* num_frames */ 1)) { + if (field != nullptr && ShouldBlockAccessToMember(field, soa.Self())) { field = nullptr; } if (field == nullptr) { diff --git a/runtime/method_handles.cc b/runtime/method_handles.cc index 8bb3bec9ac..2701ec66a4 100644 --- a/runtime/method_handles.cc +++ b/runtime/method_handles.cc @@ -415,7 +415,7 @@ static inline bool MethodHandleInvokeMethod(ArtMethod* called_method, const InstructionOperands* const operands, JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { // Compute method information. - CodeItemDataAccessor accessor(called_method); + CodeItemDataAccessor accessor(called_method->DexInstructionData()); // Number of registers for the callee's call frame. Note that for non-exact // invokes, we always derive this information from the callee method. We @@ -557,7 +557,7 @@ static inline bool MethodHandleInvokeTransform(ArtMethod* called_method, // - One for the only method argument (an EmulatedStackFrame). static constexpr size_t kNumRegsForTransform = 2; - CodeItemDataAccessor accessor(called_method); + CodeItemDataAccessor accessor(called_method->DexInstructionData()); DCHECK_EQ(kNumRegsForTransform, accessor.RegistersSize()); DCHECK_EQ(kNumRegsForTransform, accessor.InsSize()); @@ -1041,7 +1041,7 @@ static inline bool MethodHandleInvokeExactInternal( } // Compute method information. - CodeItemDataAccessor accessor(called_method); + CodeItemDataAccessor accessor(called_method->DexInstructionData()); uint16_t num_regs; size_t num_input_regs; size_t first_dest_reg; diff --git a/runtime/mirror/string-inl.h b/runtime/mirror/string-inl.h index 24c75ec0d8..8c2a49c5f6 100644 --- a/runtime/mirror/string-inl.h +++ b/runtime/mirror/string-inl.h @@ -24,11 +24,11 @@ #include "base/bit_utils.h" #include "class.h" #include "common_throws.h" +#include "dex/utf.h" #include "gc/heap-inl.h" #include "globals.h" #include "runtime.h" #include "thread.h" -#include "utf.h" #include "utils.h" namespace art { diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc index 82ff6ddead..cad84ceecb 100644 --- a/runtime/mirror/string.cc +++ b/runtime/mirror/string.cc @@ -21,6 +21,7 @@ #include "base/array_ref.h" #include "base/stl_util.h" #include "class-inl.h" +#include "dex/utf-inl.h" #include "gc/accounting/card_table-inl.h" #include "gc_root-inl.h" #include "handle_scope-inl.h" @@ -29,7 +30,6 @@ #include "runtime.h" #include "string-inl.h" #include "thread.h" -#include "utf-inl.h" namespace art { namespace mirror { diff --git a/runtime/monitor.cc b/runtime/monitor.cc index 325591fb53..0c9c65a401 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -1378,7 +1378,7 @@ void Monitor::VisitLocks(StackVisitor* stack_visitor, void (*callback)(mirror::O // Is there any reason to believe there's any synchronization in this method? CHECK(m->GetCodeItem() != nullptr) << m->PrettyMethod(); - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); if (accessor.TriesSize() == 0) { return; // No "tries" implies no synchronization, so no held locks to report. } diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc index 0f430874cf..6ea9a7ad62 100644 --- a/runtime/native/dalvik_system_DexFile.cc +++ b/runtime/native/dalvik_system_DexFile.cc @@ -30,6 +30,7 @@ #include "dex/art_dex_file_loader.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_loader.h" +#include "jit/debugger_interface.h" #include "jni_internal.h" #include "mirror/class_loader.h" #include "mirror/object-inl.h" @@ -331,6 +332,7 @@ static jboolean DexFile_closeDexFile(JNIEnv* env, jclass, jobject cookie) { int32_t i = kDexFileIndexStart; // Oat file is at index 0. for (const DexFile* dex_file : dex_files) { if (dex_file != nullptr) { + DeregisterDexFileForNative(soa.Self(), dex_file->Begin()); // Only delete the dex file if the dex cache is not found to prevent runtime crashes if there // are calls to DexFile.close while the ART DexFile is still in use. if (!class_linker->IsDexFileRegistered(soa.Self(), *dex_file)) { diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc index 779a6a6450..e58fd9dac9 100644 --- a/runtime/native/dalvik_system_ZygoteHooks.cc +++ b/runtime/native/dalvik_system_ZygoteHooks.cc @@ -174,6 +174,7 @@ enum { DISABLE_VERIFIER = 1 << 9, ONLY_USE_SYSTEM_OAT_FILES = 1 << 10, DISABLE_HIDDEN_API_CHECKS = 1 << 11, + DEBUG_GENERATE_MINI_DEBUG_INFO = 1 << 12, }; static uint32_t EnableDebugFeatures(uint32_t runtime_flags) { @@ -210,12 +211,6 @@ static uint32_t EnableDebugFeatures(uint32_t runtime_flags) { runtime_flags &= ~DEBUG_ENABLE_SAFEMODE; } - const bool generate_debug_info = (runtime_flags & DEBUG_GENERATE_DEBUG_INFO) != 0; - if (generate_debug_info) { - runtime->AddCompilerOption("--generate-debug-info"); - runtime_flags &= ~DEBUG_GENERATE_DEBUG_INFO; - } - // This is for backwards compatibility with Dalvik. runtime_flags &= ~DEBUG_ENABLE_ASSERT; @@ -229,8 +224,7 @@ static uint32_t EnableDebugFeatures(uint32_t runtime_flags) { bool needs_non_debuggable_classes = false; if ((runtime_flags & DEBUG_JAVA_DEBUGGABLE) != 0) { runtime->AddCompilerOption("--debuggable"); - // Generate native debug information to allow backtracing through JITed code. - runtime->AddCompilerOption("--generate-mini-debug-info"); + runtime_flags |= DEBUG_GENERATE_MINI_DEBUG_INFO; runtime->SetJavaDebuggable(true); // Deoptimize the boot image as it may be non-debuggable. runtime->DeoptimizeBootImage(); @@ -243,12 +237,23 @@ static uint32_t EnableDebugFeatures(uint32_t runtime_flags) { if ((runtime_flags & DEBUG_NATIVE_DEBUGGABLE) != 0) { runtime->AddCompilerOption("--debuggable"); - // Generate all native debug information we can (e.g. line-numbers). - runtime->AddCompilerOption("--generate-debug-info"); + runtime_flags |= DEBUG_GENERATE_DEBUG_INFO; runtime->SetNativeDebuggable(true); runtime_flags &= ~DEBUG_NATIVE_DEBUGGABLE; } + if ((runtime_flags & DEBUG_GENERATE_MINI_DEBUG_INFO) != 0) { + // Generate native minimal debug information to allow backtracing. + runtime->AddCompilerOption("--generate-mini-debug-info"); + runtime_flags &= ~DEBUG_GENERATE_MINI_DEBUG_INFO; + } + + if ((runtime_flags & DEBUG_GENERATE_DEBUG_INFO) != 0) { + // Generate all native debug information we can (e.g. line-numbers). + runtime->AddCompilerOption("--generate-debug-info"); + runtime_flags &= ~DEBUG_GENERATE_DEBUG_INFO; + } + return runtime_flags; } @@ -277,6 +282,7 @@ static void ZygoteHooks_nativePostForkChild(JNIEnv* env, // Our system thread ID, etc, has changed so reset Thread state. thread->InitAfterFork(); runtime_flags = EnableDebugFeatures(runtime_flags); + bool do_hidden_api_checks = true; if ((runtime_flags & DISABLE_VERIFIER) != 0) { Runtime::Current()->DisableVerifier(); @@ -289,7 +295,7 @@ static void ZygoteHooks_nativePostForkChild(JNIEnv* env, } if ((runtime_flags & DISABLE_HIDDEN_API_CHECKS) != 0) { - Runtime::Current()->SetHiddenApiChecksEnabled(false); + do_hidden_api_checks = false; runtime_flags &= ~DISABLE_HIDDEN_API_CHECKS; } @@ -340,8 +346,9 @@ static void ZygoteHooks_nativePostForkChild(JNIEnv* env, } } - DCHECK(!is_system_server || !Runtime::Current()->AreHiddenApiChecksEnabled()) + DCHECK(!is_system_server || !do_hidden_api_checks) << "SystemServer should be forked with DISABLE_HIDDEN_API_CHECKS"; + Runtime::Current()->SetHiddenApiChecksEnabled(do_hidden_api_checks); if (instruction_set != nullptr && !is_system_server) { ScopedUtfChars isa_string(env, instruction_set); diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 5544275984..2091a27ffd 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -25,6 +25,7 @@ #include "common_throws.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_annotations.h" +#include "dex/utf.h" #include "hidden_api.h" #include "jni_internal.h" #include "mirror/class-inl.h" @@ -43,17 +44,12 @@ #include "reflection.h" #include "scoped_fast_native_object_access-inl.h" #include "scoped_thread_state_change-inl.h" -#include "utf.h" #include "well_known_classes.h" namespace art { -ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self) - REQUIRES_SHARED(Locks::mutator_lock_) { - if (!Runtime::Current()->AreHiddenApiChecksEnabled()) { - return false; - } - +// Returns true if the first non-ClassClass caller up the stack is in boot class path. +static bool IsCallerInBootClassPath(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { // Walk the stack and find the first frame not from java.lang.Class. // This is very expensive. Save this till the last. struct FirstNonClassClassCallerVisitor : public StackVisitor { @@ -84,8 +80,16 @@ ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self) FirstNonClassClassCallerVisitor visitor(self); visitor.WalkStack(); - return visitor.caller == nullptr || - !visitor.caller->GetDeclaringClass()->IsBootStrapClassLoaded(); + return visitor.caller != nullptr && + visitor.caller->GetDeclaringClass()->IsBootStrapClassLoaded(); +} + +// Returns true if the first non-ClassClass caller up the stack is not allowed to +// access hidden APIs. This can be *very* expensive. Never call this in a loop. +ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self) + REQUIRES_SHARED(Locks::mutator_lock_) { + return Runtime::Current()->AreHiddenApiChecksEnabled() && + !IsCallerInBootClassPath(self); } // Returns true if the first non-ClassClass caller up the stack should not be @@ -93,9 +97,7 @@ ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self) template<typename T> ALWAYS_INLINE static bool ShouldBlockAccessToMember(T* member, Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { - DCHECK(member != nullptr); - return hiddenapi::IsMemberHidden(member->GetAccessFlags()) && - ShouldEnforceHiddenApi(self); + return hiddenapi::ShouldBlockAccessToMember(member, self, IsCallerInBootClassPath); } // Returns true if a class member should be discoverable with reflection given @@ -109,14 +111,13 @@ ALWAYS_INLINE static bool IsDiscoverable(bool public_only, return false; } - if (enforce_hidden_api && hiddenapi::IsMemberHidden(access_flags)) { + if (enforce_hidden_api && hiddenapi::GetMemberAction(access_flags) == hiddenapi::kDeny) { return false; } return true; } - ALWAYS_INLINE static inline ObjPtr<mirror::Class> DecodeClass( const ScopedFastNativeObjectAccess& soa, jobject java_class) REQUIRES_SHARED(Locks::mutator_lock_) { @@ -831,7 +832,6 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) { return nullptr; } } - hiddenapi::MaybeWarnAboutMemberAccess(constructor, soa.Self(), /* num_frames */ 1); // Invoke the constructor. JValue result; uint32_t args[1] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(receiver.Get())) }; diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc index db7f4bb18c..f990c0421d 100644 --- a/runtime/native/java_lang_reflect_Field.cc +++ b/runtime/native/java_lang_reflect_Field.cc @@ -25,7 +25,6 @@ #include "common_throws.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_annotations.h" -#include "hidden_api.h" #include "jni_internal.h" #include "mirror/class-inl.h" #include "mirror/field-inl.h" @@ -162,9 +161,6 @@ static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) { DCHECK(soa.Self()->IsExceptionPending()); return nullptr; } - - hiddenapi::MaybeWarnAboutMemberAccess(f->GetArtField(), soa.Self(), /* num_frames */ 1); - // We now don't expect suspension unless an exception is thrown. // Get the field's value, boxing if necessary. Primitive::Type field_type = f->GetTypeAsPrimitiveType(); @@ -187,14 +183,13 @@ ALWAYS_INLINE inline static JValue GetPrimitiveField(JNIEnv* env, DCHECK(soa.Self()->IsExceptionPending()); return JValue(); } + // If field is not set to be accessible, verify it can be accessed by the caller. if (!f->IsAccessible() && !VerifyFieldAccess<false>(soa.Self(), f, o)) { DCHECK(soa.Self()->IsExceptionPending()); return JValue(); } - hiddenapi::MaybeWarnAboutMemberAccess(f->GetArtField(), soa.Self(), /* num_frames */ 1); - // We now don't expect suspension unless an exception is thrown. // Read the value. Primitive::Type field_type = f->GetTypeAsPrimitiveType(); @@ -356,15 +351,11 @@ static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject j DCHECK(soa.Self()->IsExceptionPending()); return; } - // If field is not set to be accessible, verify it can be accessed by the caller. if (!f->IsAccessible() && !VerifyFieldAccess<true>(soa.Self(), f, o)) { DCHECK(soa.Self()->IsExceptionPending()); return; } - - hiddenapi::MaybeWarnAboutMemberAccess(f->GetArtField(), soa.Self(), /* num_frames */ 1); - SetFieldValue(o, f, field_prim_type, true, unboxed_value); } @@ -400,8 +391,6 @@ static void SetPrimitiveField(JNIEnv* env, return; } - hiddenapi::MaybeWarnAboutMemberAccess(f->GetArtField(), soa.Self(), /* num_frames */ 1); - // Write the value. SetFieldValue(o, f, field_type, false, wide_value); } diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index 307f7b96ed..dc4bae3415 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -47,6 +47,7 @@ #include "dex/dex_file_loader.h" #include "dex/dex_file_types.h" #include "dex/standard_dex_file.h" +#include "dex/utf-inl.h" #include "elf_file.h" #include "elf_utils.h" #include "gc_root.h" @@ -60,7 +61,6 @@ #include "os.h" #include "runtime.h" #include "type_lookup_table.h" -#include "utf-inl.h" #include "utils.h" #include "vdex_file.h" diff --git a/runtime/oat_file.h b/runtime/oat_file.h index 50a706d1ba..46c692e568 100644 --- a/runtime/oat_file.h +++ b/runtime/oat_file.h @@ -28,12 +28,12 @@ #include "compiler_filter.h" #include "dex/dex_file.h" #include "dex/dex_file_layout.h" +#include "dex/utf.h" #include "index_bss_mapping.h" #include "mirror/object.h" #include "oat.h" #include "os.h" #include "type_lookup_table.h" -#include "utf.h" #include "utils.h" namespace art { diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc index 3a7640fa8b..006405f095 100644 --- a/runtime/quick_exception_handler.cc +++ b/runtime/quick_exception_handler.cc @@ -222,7 +222,7 @@ void QuickExceptionHandler::SetCatchEnvironmentForOptimizedHandler(StackVisitor* self_->DumpStack(LOG_STREAM(INFO) << "Setting catch phis: "); } - CodeItemDataAccessor accessor(handler_method_); + CodeItemDataAccessor accessor(handler_method_->DexInstructionData()); const size_t number_of_vregs = accessor.RegistersSize(); CodeInfo code_info = handler_method_header_->GetOptimizedCodeInfo(); CodeInfoEncoding encoding = code_info.ExtractEncoding(); @@ -360,7 +360,7 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor { const size_t frame_id = GetFrameId(); ShadowFrame* new_frame = GetThread()->FindDebuggerShadowFrame(frame_id); const bool* updated_vregs; - CodeItemDataAccessor accessor(method); + CodeItemDataAccessor accessor(method->DexInstructionData()); const size_t num_regs = accessor.RegistersSize(); if (new_frame == nullptr) { new_frame = ShadowFrame::CreateDeoptimizedFrame(num_regs, nullptr, method, GetDexPc()); @@ -408,7 +408,7 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor { uintptr_t native_pc_offset = method_header->NativeQuickPcOffset(GetCurrentQuickFramePc()); CodeInfoEncoding encoding = code_info.ExtractEncoding(); StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset, encoding); - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); const size_t number_of_vregs = accessor.RegistersSize(); uint32_t register_mask = code_info.GetRegisterMaskOf(encoding, stack_map); BitMemoryRegion stack_mask = code_info.GetStackMaskOf(encoding, stack_map); diff --git a/runtime/reflection.cc b/runtime/reflection.cc index 6ffafe02f1..635a03afe0 100644 --- a/runtime/reflection.cc +++ b/runtime/reflection.cc @@ -465,9 +465,6 @@ JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, jobject o } ArtMethod* method = jni::DecodeArtMethod(mid); - - hiddenapi::MaybeWarnAboutMemberAccess(method, soa.Self(), /* num_frames */ 1); - bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); if (is_string_init) { // Replace calls to String.<init> with equivalent StringFactory call. @@ -499,9 +496,6 @@ JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, jobject o } ArtMethod* method = jni::DecodeArtMethod(mid); - - hiddenapi::MaybeWarnAboutMemberAccess(method, soa.Self(), /* num_frames */ 1); - bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); if (is_string_init) { // Replace calls to String.<init> with equivalent StringFactory call. @@ -534,9 +528,6 @@ JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnab ObjPtr<mirror::Object> receiver = soa.Decode<mirror::Object>(obj); ArtMethod* method = FindVirtualMethod(receiver, jni::DecodeArtMethod(mid)); - - hiddenapi::MaybeWarnAboutMemberAccess(method, soa.Self(), /* num_frames */ 1); - bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); if (is_string_init) { // Replace calls to String.<init> with equivalent StringFactory call. @@ -569,9 +560,6 @@ JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnab ObjPtr<mirror::Object> receiver = soa.Decode<mirror::Object>(obj); ArtMethod* method = FindVirtualMethod(receiver, jni::DecodeArtMethod(mid)); - - hiddenapi::MaybeWarnAboutMemberAccess(method, soa.Self(), /* num_frames */ 1); - bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); if (is_string_init) { // Replace calls to String.<init> with equivalent StringFactory call. @@ -616,8 +604,6 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM } } - hiddenapi::MaybeWarnAboutMemberAccess(m, soa.Self(), num_frames); - ObjPtr<mirror::Object> receiver; if (!m->IsStatic()) { // Replace calls to String.<init> with equivalent StringFactory call. diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 77f1fb9718..5a3a6f0cf4 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -265,7 +265,7 @@ Runtime::Runtime() oat_file_manager_(nullptr), is_low_memory_mode_(false), safe_mode_(false), - do_hidden_api_checks_(false), + do_hidden_api_checks_(true), pending_hidden_api_warning_(false), dedupe_hidden_api_warnings_(true), dump_native_stack_on_sig_quit_(true), @@ -1171,7 +1171,9 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) { target_sdk_version_ = runtime_options.GetOrDefault(Opt::TargetSdkVersion); - if (runtime_options.Exists(Opt::NoHiddenApiChecks)) { + // Check whether to enforce hidden API access checks. Zygote needs to be exempt + // but checks may be enabled for forked processes (see dalvik_system_ZygoteHooks). + if (is_zygote_ || runtime_options.Exists(Opt::NoHiddenApiChecks)) { do_hidden_api_checks_ = false; } @@ -1253,7 +1255,20 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) { jdwp_provider_ = runtime_options.GetOrDefault(Opt::JdwpProvider); switch (jdwp_provider_) { case JdwpProvider::kNone: { - LOG(WARNING) << "Disabling all JDWP support."; + LOG(INFO) << "Disabling all JDWP support."; + if (!jdwp_options_.empty()) { + bool has_transport = jdwp_options_.find("transport") != std::string::npos; + const char* transport_internal = !has_transport ? "transport=dt_android_adb," : ""; + std::string adb_connection_args = + std::string(" -XjdwpProvider:adbconnection -XjdwpOptions:") + jdwp_options_; + LOG(WARNING) << "Jdwp options given when jdwp is disabled! You probably want to enable " + << "jdwp with one of:" << std::endl + << " -XjdwpProvider:internal " + << "-XjdwpOptions:" << transport_internal << jdwp_options_ << std::endl + << " -Xplugin:libopenjdkjvmti" << (kIsDebugBuild ? "d" : "") << ".so " + << "-agentpath:libjdwp.so=" << jdwp_options_ << std::endl + << (has_transport ? "" : adb_connection_args); + } break; } case JdwpProvider::kInternal: { diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def index 6e1a68b07d..e78d952c1c 100644 --- a/runtime/runtime_options.def +++ b/runtime/runtime_options.def @@ -44,7 +44,7 @@ RUNTIME_OPTIONS_KEY (std::string, Image) RUNTIME_OPTIONS_KEY (Unit, CheckJni) RUNTIME_OPTIONS_KEY (Unit, JniOptsForceCopy) RUNTIME_OPTIONS_KEY (std::string, JdwpOptions, "") -RUNTIME_OPTIONS_KEY (JdwpProvider, JdwpProvider, JdwpProvider::kInternal) +RUNTIME_OPTIONS_KEY (JdwpProvider, JdwpProvider, JdwpProvider::kNone) RUNTIME_OPTIONS_KEY (MemoryKiB, MemoryMaximumSize, gc::Heap::kDefaultMaximumSize) // -Xmx RUNTIME_OPTIONS_KEY (MemoryKiB, MemoryInitialSize, gc::Heap::kDefaultInitialSize) // -Xms RUNTIME_OPTIONS_KEY (MemoryKiB, HeapGrowthLimit) // Default is 0 for unlimited diff --git a/runtime/stack.cc b/runtime/stack.cc index dfdea28ae8..229238e0f7 100644 --- a/runtime/stack.cc +++ b/runtime/stack.cc @@ -154,7 +154,7 @@ mirror::Object* StackVisitor::GetThisObject() const { return cur_shadow_frame_->GetVRegReference(0); } } else { - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); if (!accessor.HasCodeItem()) { UNIMPLEMENTED(ERROR) << "Failed to determine this object of abstract or proxy method: " << ArtMethod::PrettyMethod(m); @@ -225,7 +225,7 @@ bool StackVisitor::GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKin DCHECK_EQ(m, GetMethod()); // Can't be null or how would we compile its instructions? DCHECK(m->GetCodeItem() != nullptr) << m->PrettyMethod(); - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); uint16_t number_of_dex_registers = accessor.RegistersSize(); DCHECK_LT(vreg, number_of_dex_registers); const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader(); @@ -395,7 +395,7 @@ bool StackVisitor::SetVReg(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind) { - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); if (!accessor.HasCodeItem()) { return false; } @@ -432,7 +432,7 @@ bool StackVisitor::SetVRegPair(ArtMethod* m, LOG(FATAL) << "Expected long or double: kind_lo=" << kind_lo << ", kind_hi=" << kind_hi; UNREACHABLE(); } - CodeItemDataAccessor accessor(m); + CodeItemDataAccessor accessor(m->DexInstructionData()); if (!accessor.HasCodeItem()) { return false; } diff --git a/runtime/string_reference.h b/runtime/string_reference.h index 97661c6019..1ee5d6d53a 100644 --- a/runtime/string_reference.h +++ b/runtime/string_reference.h @@ -24,7 +24,7 @@ #include "dex/dex_file-inl.h" #include "dex/dex_file_reference.h" #include "dex/dex_file_types.h" -#include "utf-inl.h" +#include "dex/utf-inl.h" namespace art { diff --git a/runtime/thread.cc b/runtime/thread.cc index 14375f7bcd..9dc92f3788 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -3628,7 +3628,7 @@ class ReferenceMapVisitor : public StackVisitor { const CodeInfoEncoding& _encoding, const StackMap& map, RootVisitor& _visitor) - : number_of_dex_registers(CodeItemDataAccessor(method).RegistersSize()), + : number_of_dex_registers(method->DexInstructionData().RegistersSize()), code_info(_code_info), encoding(_encoding), dex_register_map(code_info.GetDexRegisterMapOf(map, diff --git a/runtime/type_lookup_table.cc b/runtime/type_lookup_table.cc index 649a4f9547..925a9089cb 100644 --- a/runtime/type_lookup_table.cc +++ b/runtime/type_lookup_table.cc @@ -21,7 +21,7 @@ #include "base/bit_utils.h" #include "dex/dex_file-inl.h" -#include "utf-inl.h" +#include "dex/utf-inl.h" #include "utils.h" namespace art { diff --git a/runtime/type_lookup_table.h b/runtime/type_lookup_table.h index 50c93ad9f0..a1f9519f18 100644 --- a/runtime/type_lookup_table.h +++ b/runtime/type_lookup_table.h @@ -18,8 +18,8 @@ #define ART_RUNTIME_TYPE_LOOKUP_TABLE_H_ #include "dex/dex_file_types.h" +#include "dex/utf.h" #include "leb128.h" -#include "utf.h" namespace art { diff --git a/runtime/type_lookup_table_test.cc b/runtime/type_lookup_table_test.cc index d04652a8e7..b6ab6da78c 100644 --- a/runtime/type_lookup_table_test.cc +++ b/runtime/type_lookup_table_test.cc @@ -20,8 +20,8 @@ #include "common_runtime_test.h" #include "dex/dex_file-inl.h" +#include "dex/utf-inl.h" #include "scoped_thread_state_change-inl.h" -#include "utf-inl.h" namespace art { diff --git a/runtime/utils.cc b/runtime/utils.cc index b2ec669f32..393b18e1b3 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -30,8 +30,8 @@ #include "android-base/stringprintf.h" #include "android-base/strings.h" +#include "dex/utf-inl.h" #include "os.h" -#include "utf-inl.h" #if defined(__APPLE__) #include <crt_externs.h> @@ -151,57 +151,6 @@ std::string PrettySize(int64_t byte_count) { negative_str, byte_count / kBytesPerUnit[i], kUnitStrings[i]); } -static inline constexpr bool NeedsEscaping(uint16_t ch) { - return (ch < ' ' || ch > '~'); -} - -std::string PrintableChar(uint16_t ch) { - std::string result; - result += '\''; - if (NeedsEscaping(ch)) { - StringAppendF(&result, "\\u%04x", ch); - } else { - result += static_cast<std::string::value_type>(ch); - } - result += '\''; - return result; -} - -std::string PrintableString(const char* utf) { - std::string result; - result += '"'; - const char* p = utf; - size_t char_count = CountModifiedUtf8Chars(p); - for (size_t i = 0; i < char_count; ++i) { - uint32_t ch = GetUtf16FromUtf8(&p); - if (ch == '\\') { - result += "\\\\"; - } else if (ch == '\n') { - result += "\\n"; - } else if (ch == '\r') { - result += "\\r"; - } else if (ch == '\t') { - result += "\\t"; - } else { - const uint16_t leading = GetLeadingUtf16Char(ch); - - if (NeedsEscaping(leading)) { - StringAppendF(&result, "\\u%04x", leading); - } else { - result += static_cast<std::string::value_type>(leading); - } - - const uint32_t trailing = GetTrailingUtf16Char(ch); - if (trailing != 0) { - // All high surrogates will need escaping. - StringAppendF(&result, "\\u%04x", trailing); - } - } - } - result += '"'; - return result; -} - std::string GetJniShortName(const std::string& class_descriptor, const std::string& method) { // Remove the leading 'L' and trailing ';'... std::string class_name(class_descriptor); diff --git a/runtime/utils.h b/runtime/utils.h index abdafcc9f7..443b0cc398 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -67,12 +67,6 @@ static inline uint32_t PointerToLowMemUInt32(const void* p) { return intp & 0xFFFFFFFFU; } -std::string PrintableChar(uint16_t ch); - -// Returns an ASCII string corresponding to the given UTF-8 string. -// Java escapes are used for non-ASCII characters. -std::string PrintableString(const char* utf8); - // Used to implement PrettyClass, PrettyField, PrettyMethod, and PrettyTypeOf, // one of which is probably more useful to you. // Returns a human-readable equivalent of 'descriptor'. So "I" would be "int", diff --git a/runtime/vdex_file.h b/runtime/vdex_file.h index b9fd467017..0f347952c9 100644 --- a/runtime/vdex_file.h +++ b/runtime/vdex_file.h @@ -87,8 +87,8 @@ class VdexFile { private: static constexpr uint8_t kVdexMagic[] = { 'v', 'd', 'e', 'x' }; - // Last update: Separate section for compact dex data. - static constexpr uint8_t kVdexVersion[] = { '0', '1', '6', '\0' }; + // Last update: Fix separate section for compact dex data. + static constexpr uint8_t kVdexVersion[] = { '0', '1', '7', '\0' }; uint8_t magic_[4]; uint8_t version_[4]; @@ -101,6 +101,9 @@ class VdexFile { friend class VdexFile; }; + // Note: The file is called "primary" to match the naming with profiles. + static const constexpr char* kVdexNameInDmFile = "primary.vdex"; + typedef uint32_t VdexChecksum; using QuickeningTableOffsetType = uint32_t; diff --git a/test/004-ThreadStress/src-art/Main.java b/test/004-ThreadStress/src-art/Main.java index 0d469fb8d9..a142934638 100644 --- a/test/004-ThreadStress/src-art/Main.java +++ b/test/004-ThreadStress/src-art/Main.java @@ -315,9 +315,11 @@ public class Main implements Runnable { Map<Operation, Double> frequencyMap = new HashMap<Operation, Double>(); frequencyMap.put(new OOM(), 0.005); // 1/200 frequencyMap.put(new SigQuit(), 0.095); // 19/200 - frequencyMap.put(new Alloc(), 0.2); // 40/200 + frequencyMap.put(new Alloc(), 0.225); // 45/200 frequencyMap.put(new LargeAlloc(), 0.05); // 10/200 - frequencyMap.put(new NonMovingAlloc(), 0.025); // 5/200 + // TODO: NonMovingAlloc operations fail an assertion with the + // GSS collector (see b/72738921); disable them for now. + frequencyMap.put(new NonMovingAlloc(), 0.0); // 0/200 frequencyMap.put(new StackTrace(), 0.1); // 20/200 frequencyMap.put(new Exit(), 0.225); // 45/200 frequencyMap.put(new Sleep(), 0.125); // 25/200 diff --git a/test/044-proxy/src/Main.java b/test/044-proxy/src/Main.java index e44c122e3d..7b70e65b8c 100644 --- a/test/044-proxy/src/Main.java +++ b/test/044-proxy/src/Main.java @@ -54,4 +54,8 @@ public class Main { private static final HashMap<String, String> proxyClassNameMap = new HashMap<String, String>(); private static int uniqueTestProxyClassNum = 0; + + static native void startJit(); + static native void stopJit(); + static native void waitForCompilation(); } diff --git a/test/044-proxy/src/OOMEOnDispatch.java b/test/044-proxy/src/OOMEOnDispatch.java index 94f267980d..2ee57926ae 100644 --- a/test/044-proxy/src/OOMEOnDispatch.java +++ b/test/044-proxy/src/OOMEOnDispatch.java @@ -32,6 +32,11 @@ public class OOMEOnDispatch implements InvocationHandler { OOMEInterface.class.getClassLoader(), new Class[] { OOMEInterface.class }, handler); + // Stop the JIT to be sure nothing is running that could be resolving classes or causing + // verification. + Main.stopJit(); + Main.waitForCompilation(); + int l = 1024 * 1024; while (l > 8) { try { @@ -40,17 +45,6 @@ public class OOMEOnDispatch implements InvocationHandler { l = l/2; } } - // Have an extra run with the exact size of Method objects. The above loop should have - // filled with enough large objects for simplicity and speed, but ensure exact allocation - // size. - final int methodAsByteArrayLength = 40 - 12; // Method size - byte array overhead. - for (;;) { - try { - storage.add(new byte[methodAsByteArrayLength]); - } catch (OutOfMemoryError e) { - break; - } - } try { inf.foo(); @@ -60,6 +54,8 @@ public class OOMEOnDispatch implements InvocationHandler { storage.clear(); System.out.println("Received OOME"); } + + Main.startJit(); } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { diff --git a/test/141-class-unload/jni_unload.cc b/test/141-class-unload/jni_unload.cc index 355457d68d..894ae8b0d7 100644 --- a/test/141-class-unload/jni_unload.cc +++ b/test/141-class-unload/jni_unload.cc @@ -32,19 +32,5 @@ extern "C" JNIEXPORT void JNICALL Java_IntHolder_waitForCompilation(JNIEnv*, jcl } } -extern "C" JNIEXPORT void JNICALL Java_Main_stopJit(JNIEnv*, jclass) { - jit::Jit* jit = Runtime::Current()->GetJit(); - if (jit != nullptr) { - jit->Stop(); - } -} - -extern "C" JNIEXPORT void JNICALL Java_Main_startJit(JNIEnv*, jclass) { - jit::Jit* jit = Runtime::Current()->GetJit(); - if (jit != nullptr) { - jit->Start(); - } -} - } // namespace } // namespace art diff --git a/test/466-get-live-vreg/get_live_vreg_jni.cc b/test/466-get-live-vreg/get_live_vreg_jni.cc index aeb9e44541..44ea0c9877 100644 --- a/test/466-get-live-vreg/get_live_vreg_jni.cc +++ b/test/466-get-live-vreg/get_live_vreg_jni.cc @@ -42,7 +42,8 @@ class TestVisitor : public StackVisitor { CHECK(GetVReg(m, 0, kIntVReg, &value)); CHECK_EQ(value, 42u); } else if (m_name.compare("$opt$noinline$testIntervalHole") == 0) { - uint32_t number_of_dex_registers = CodeItemDataAccessor(m).RegistersSize(); + uint32_t number_of_dex_registers = + CodeItemDataAccessor(m->DexInstructionData()).RegistersSize(); uint32_t dex_register_of_first_parameter = number_of_dex_registers - 2; found_method_ = true; uint32_t value = 0; diff --git a/test/603-checker-instanceof/src/Main.java b/test/603-checker-instanceof/src/Main.java index 1487969c03..2c97bedbaa 100644 --- a/test/603-checker-instanceof/src/Main.java +++ b/test/603-checker-instanceof/src/Main.java @@ -59,7 +59,7 @@ public class Main { /// CHECK: InstanceOf check_kind:exact_check /// CHECK-NOT: {{.*gs:.*}} - /// CHECK-START-{ARM,ARM64}: boolean Main.$noinline$instanceOfString(java.lang.Object) disassembly (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64}: boolean Main.$noinline$instanceOfString(java.lang.Object) disassembly (after) /// CHECK: InstanceOf check_kind:exact_check // For ARM and ARM64, the marking register (r8 and x20, respectively) can be used in // non-CC configs for any other purpose, so we'd need a config-specific checker test. diff --git a/test/651-checker-int-simd-minmax/src/Main.java b/test/651-checker-int-simd-minmax/src/Main.java index 66343adaa8..cfa0ae7dca 100644 --- a/test/651-checker-int-simd-minmax/src/Main.java +++ b/test/651-checker-int-simd-minmax/src/Main.java @@ -27,10 +27,10 @@ public class Main { /// CHECK-DAG: ArraySet [{{l\d+}},<<Phi>>,<<Min>>] loop:<<Loop>> outer_loop:none // /// CHECK-START-{ARM,ARM64,MIPS64}: void Main.doitMin(int[], int[], int[]) loop_optimization (after) - /// CHECK-DAG: <<Get1:d\d+>> VecLoad loop:<<Loop:B\d+>> outer_loop:none - /// CHECK-DAG: <<Get2:d\d+>> VecLoad loop:<<Loop>> outer_loop:none - /// CHECK-DAG: <<Min:d\d+>> VecMin [<<Get1>>,<<Get2>>] unsigned:false loop:<<Loop>> outer_loop:none - /// CHECK-DAG: VecStore [{{l\d+}},{{i\d+}},<<Min>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Get1:d\d+>> VecLoad loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Get2:d\d+>> VecLoad loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Min:d\d+>> VecMin [<<Get1>>,<<Get2>>] packed_type:Int32 loop:<<Loop>> outer_loop:none + /// CHECK-DAG: VecStore [{{l\d+}},{{i\d+}},<<Min>>] loop:<<Loop>> outer_loop:none private static void doitMin(int[] x, int[] y, int[] z) { int min = Math.min(x.length, Math.min(y.length, z.length)); for (int i = 0; i < min; i++) { @@ -46,10 +46,10 @@ public class Main { /// CHECK-DAG: ArraySet [{{l\d+}},<<Phi>>,<<Max>>] loop:<<Loop>> outer_loop:none // /// CHECK-START-{ARM,ARM64,MIPS64}: void Main.doitMax(int[], int[], int[]) loop_optimization (after) - /// CHECK-DAG: <<Get1:d\d+>> VecLoad loop:<<Loop:B\d+>> outer_loop:none - /// CHECK-DAG: <<Get2:d\d+>> VecLoad loop:<<Loop>> outer_loop:none - /// CHECK-DAG: <<Max:d\d+>> VecMax [<<Get1>>,<<Get2>>] unsigned:false loop:<<Loop>> outer_loop:none - /// CHECK-DAG: VecStore [{{l\d+}},{{i\d+}},<<Max>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Get1:d\d+>> VecLoad loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Get2:d\d+>> VecLoad loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Max:d\d+>> VecMax [<<Get1>>,<<Get2>>] packed_type:Int32 loop:<<Loop>> outer_loop:none + /// CHECK-DAG: VecStore [{{l\d+}},{{i\d+}},<<Max>>] loop:<<Loop>> outer_loop:none private static void doitMax(int[] x, int[] y, int[] z) { int min = Math.min(x.length, Math.min(y.length, z.length)); for (int i = 0; i < min; i++) { diff --git a/test/674-HelloWorld-Dm/expected.txt b/test/674-HelloWorld-Dm/expected.txt new file mode 100644 index 0000000000..af5626b4a1 --- /dev/null +++ b/test/674-HelloWorld-Dm/expected.txt @@ -0,0 +1 @@ +Hello, world! diff --git a/test/674-HelloWorld-Dm/info.txt b/test/674-HelloWorld-Dm/info.txt new file mode 100644 index 0000000000..3a769c48a6 --- /dev/null +++ b/test/674-HelloWorld-Dm/info.txt @@ -0,0 +1 @@ +Hello World test with --dm-file passed to dex2oat. diff --git a/test/674-HelloWorld-Dm/run b/test/674-HelloWorld-Dm/run new file mode 100644 index 0000000000..199ffc31e1 --- /dev/null +++ b/test/674-HelloWorld-Dm/run @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright (C) 2018 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +exec ${RUN} --dm "${@}" diff --git a/test/674-HelloWorld-Dm/src/Main.java b/test/674-HelloWorld-Dm/src/Main.java new file mode 100644 index 0000000000..1ef6289559 --- /dev/null +++ b/test/674-HelloWorld-Dm/src/Main.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2011 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 Main { + public static void main(String[] args) { + System.out.println("Hello, world!"); + } +} diff --git a/test/674-hotness-compiled/expected.txt b/test/674-hotness-compiled/expected.txt new file mode 100644 index 0000000000..6a5618ebc6 --- /dev/null +++ b/test/674-hotness-compiled/expected.txt @@ -0,0 +1 @@ +JNI_OnLoad called diff --git a/test/674-hotness-compiled/info.txt b/test/674-hotness-compiled/info.txt new file mode 100644 index 0000000000..e2cf59a093 --- /dev/null +++ b/test/674-hotness-compiled/info.txt @@ -0,0 +1 @@ +Test for the --count-hotness-in-compiled-code compiler option. diff --git a/test/674-hotness-compiled/run b/test/674-hotness-compiled/run new file mode 100755 index 0000000000..85e8e3b13f --- /dev/null +++ b/test/674-hotness-compiled/run @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright (C) 2018 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +${RUN} "$@" -Xcompiler-option --count-hotness-in-compiled-code diff --git a/test/674-hotness-compiled/src/Main.java b/test/674-hotness-compiled/src/Main.java new file mode 100644 index 0000000000..76ec92777f --- /dev/null +++ b/test/674-hotness-compiled/src/Main.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class Main { + public static void $noinline$hotnessCount() { + } + + public static void $noinline$hotnessCountWithLoop() { + for (int i = 0; i < 100; i++) { + $noinline$hotnessCount(); + } + } + + public static void main(String[] args) { + System.loadLibrary(args[0]); + if (!isAotCompiled(Main.class, "main")) { + return; + } + $noinline$hotnessCount(); + int counter = getHotnessCounter(Main.class, "$noinline$hotnessCount"); + if (counter == 0) { + throw new Error("Expected hotness counter to be updated"); + } + + $noinline$hotnessCountWithLoop(); + if (getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop") <= counter) { + throw new Error("Expected hotness counter of a loop to be greater than without loop"); + } + } + + public static native int getHotnessCounter(Class<?> cls, String methodName); + public static native boolean isAotCompiled(Class<?> cls, String methodName); +} diff --git a/test/Android.bp b/test/Android.bp index 730818c4f2..72e8eee95a 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -62,6 +62,7 @@ art_cc_defaults { "libvixld-arm", "libvixld-arm64", "libart-gtest", + "libdexfile", "libbase", "libicuuc", @@ -113,6 +114,7 @@ art_cc_defaults { shared_libs: [ "libartd", "libartd-compiler", + "libdexfile", ], static_libs: [ "libgtest", @@ -149,6 +151,7 @@ art_cc_library { shared_libs: [ "libartd", "libartd-compiler", + "libdexfile", "libbase", "libbacktrace", ], @@ -166,6 +169,7 @@ cc_defaults { "art_defaults", ], shared_libs: [ + "libdexfile", "libbacktrace", "libbase", "libnativehelper", @@ -264,6 +268,7 @@ art_cc_defaults { "1943-suspend-raw-monitor-wait/native_suspend_monitor.cc", ], shared_libs: [ + "libdexfile", "libbase", ], header_libs: [ @@ -394,6 +399,7 @@ cc_defaults { "708-jit-cache-churn/jit.cc", ], shared_libs: [ + "libdexfile", "libbacktrace", "libbase", "libnativehelper", diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc index c2408b0d2f..298a2f0033 100644 --- a/test/common/runtime_state.cc +++ b/test/common/runtime_state.cc @@ -251,13 +251,6 @@ extern "C" JNIEXPORT int JNICALL Java_Main_getHotnessCounter(JNIEnv* env, jclass, jclass cls, jstring method_name) { - jit::Jit* jit = Runtime::Current()->GetJit(); - if (jit == nullptr) { - // The hotness counter is valid only under JIT. - // If we don't JIT return 0 to match test expectations. - return 0; - } - ArtMethod* method = nullptr; { ScopedObjectAccess soa(Thread::Current()); @@ -297,4 +290,25 @@ extern "C" JNIEXPORT jboolean JNICALL Java_Main_isClassMoveable(JNIEnv*, return runtime->GetHeap()->IsMovableObject(klass); } +extern "C" JNIEXPORT void JNICALL Java_Main_waitForCompilation(JNIEnv*, jclass) { + jit::Jit* jit = Runtime::Current()->GetJit(); + if (jit != nullptr) { + jit->WaitForCompilationToFinish(Thread::Current()); + } +} + +extern "C" JNIEXPORT void JNICALL Java_Main_stopJit(JNIEnv*, jclass) { + jit::Jit* jit = Runtime::Current()->GetJit(); + if (jit != nullptr) { + jit->Stop(); + } +} + +extern "C" JNIEXPORT void JNICALL Java_Main_startJit(JNIEnv*, jclass) { + jit::Jit* jit = Runtime::Current()->GetJit(); + if (jit != nullptr) { + jit->Start(); + } +} + } // namespace art diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar index 5e40b86aa0..02438701b8 100755 --- a/test/etc/run-test-jar +++ b/test/etc/run-test-jar @@ -64,6 +64,7 @@ ARGS="" EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS. DRY_RUN="n" # if y prepare to run the test but don't run it. TEST_VDEX="n" +TEST_DM="n" TEST_IS_NDEBUG="n" APP_IMAGE="y" JVMTI_STRESS="n" @@ -346,6 +347,9 @@ while true; do elif [ "x$1" = "x--vdex" ]; then TEST_VDEX="y" shift + elif [ "x$1" = "x--dm" ]; then + TEST_DM="y" + shift elif [ "x$1" = "x--vdex-filter" ]; then shift option="$1" @@ -436,7 +440,13 @@ if [ "$DEBUGGER" = "y" ]; then msg " adb forward tcp:$PORT tcp:$PORT" fi msg " jdb -attach localhost:$PORT" - DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" + if [ "$USE_JVM" = "n" ]; then + # TODO We should switch over to using the jvmti agent by default. + # Need to tell the runtime to enable the internal jdwp implementation. + DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal" + else + DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" + fi elif [ "$DEBUGGER" = "agent" ]; then PORT=12345 # TODO Support ddms connection and support target. @@ -672,6 +682,7 @@ fi profman_cmdline="true" dex2oat_cmdline="true" vdex_cmdline="true" +dm_cmdline="true" mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/dalvik-cache/$ISA" strip_cmdline="true" sync_cmdline="true" @@ -735,6 +746,10 @@ if [ "$PREBUILD" = "y" ]; then vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex" elif [ "$TEST_VDEX" = "y" ]; then vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex" + elif [ "$TEST_DM" = "y" ]; then + dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex" + dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex" + vdex_cmdline="${dex2oat_cmdline} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm" elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex" fi @@ -782,6 +797,7 @@ dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \ # Remove whitespace. dex2oat_cmdline=$(echo $dex2oat_cmdline) dalvikvm_cmdline=$(echo $dalvikvm_cmdline) +dm_cmdline=$(echo $dm_cmdline) vdex_cmdline=$(echo $vdex_cmdline) profman_cmdline=$(echo $profman_cmdline) @@ -833,7 +849,7 @@ if [ "$HOST" = "n" ]; then fi # System libraries needed by libarttestd.so - PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libbase.so:libnativehelper.so + PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libdexfile.so:libbase.so:libnativehelper.so # Create a script with the command. The command can get longer than the longest # allowed adb command and there is no way to get the exit status from a adb shell @@ -851,6 +867,7 @@ if [ "$HOST" = "n" ]; then export PATH=$ANDROID_ROOT/bin:$PATH && \ $profman_cmdline && \ $dex2oat_cmdline && \ + $dm_cmdline && \ $vdex_cmdline && \ $strip_cmdline && \ $sync_cmdline && \ @@ -927,7 +944,7 @@ else fi if [ "$DEV_MODE" = "y" ]; then - echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline" + echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $dm_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline" fi cd $ANDROID_BUILD_TOP @@ -943,6 +960,7 @@ else mkdir -p ${mkdir_locations} || exit 1 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; } $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; } + $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; } $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; } $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; } $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; } diff --git a/test/knownfailures.json b/test/knownfailures.json index 3a21753f99..83ac068109 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -656,6 +656,10 @@ "tests": "661-oat-writer-layout", "variant": "interp-ac | interpreter | jit | no-dex2oat | no-prebuild | no-image | trace | redefine-stress | jvmti-stress", "description": ["Test is designed to only check --compiler-filter=speed"] + }, + { + "tests": "674-HelloWorld-Dm", + "variant": "target", + "description": ["Requires zip, which isn't available on device"] } - ] diff --git a/test/run-test b/test/run-test index a453f22e29..6bcb9cdabb 100755 --- a/test/run-test +++ b/test/run-test @@ -427,6 +427,9 @@ while true; do elif [ "x$1" = "x--vdex" ]; then run_args="${run_args} --vdex" shift + elif [ "x$1" = "x--dm" ]; then + run_args="${run_args} --dm" + shift elif [ "x$1" = "x--vdex-filter" ]; then shift filter=$1 diff --git a/test/testrunner/target_config.py b/test/testrunner/target_config.py index 414e3e5037..3064c76ffd 100644 --- a/test/testrunner/target_config.py +++ b/test/testrunner/target_config.py @@ -327,27 +327,20 @@ target_config = { 'ART_USE_READ_BARRIER' : 'false' } }, - 'art-gtest-heap-poisoning': { - 'make' : 'valgrind-test-art-host64', - 'env' : { - 'ART_HEAP_POISONING' : 'true', - 'ART_USE_READ_BARRIER' : 'false' - } - }, # ASAN (host) configurations. # These configurations need detect_leaks=0 to work in non-setup environments like build bots, # as our build tools leak. b/37751350 - 'art-gtest-asan': { + 'art-gtest-asan': { 'make' : 'test-art-host-gtest', 'env': { 'SANITIZE_HOST' : 'address', 'ASAN_OPTIONS' : 'detect_leaks=0' } - }, - 'art-asan': { + }, + 'art-asan': { 'run-test' : ['--interpreter', '--optimizing', '--jit'], @@ -355,7 +348,16 @@ target_config = { 'SANITIZE_HOST' : 'address', 'ASAN_OPTIONS' : 'detect_leaks=0' } - }, + }, + 'art-gtest-heap-poisoning': { + 'make' : 'test-art-host-gtest', + 'env' : { + 'ART_HEAP_POISONING' : 'true', + 'ART_USE_READ_BARRIER' : 'false', + 'SANITIZE_HOST' : 'address', + 'ASAN_OPTIONS' : 'detect_leaks=0' + } + }, # ART Golem build targets used by go/lem (continuous ART benchmarking), # (art-opt-cc is used by default since it mimics the default preopt config), diff --git a/tools/hiddenapi/Android.bp b/tools/hiddenapi/Android.bp index a78bc43aa4..f9824f1fa3 100644 --- a/tools/hiddenapi/Android.bp +++ b/tools/hiddenapi/Android.bp @@ -30,6 +30,7 @@ cc_defaults { }, shared_libs: [ + "libdexfile", "libbase", ], } diff --git a/tools/prebuilt_libjdwp_art_failures.txt b/tools/prebuilt_libjdwp_art_failures.txt index eaa99a3bf8..7a8a4dd35f 100644 --- a/tools/prebuilt_libjdwp_art_failures.txt +++ b/tools/prebuilt_libjdwp_art_failures.txt @@ -124,6 +124,6 @@ result: EXEC_FAILED, bug: 70958370, names: [ "org.apache.harmony.jpda.tests.jdwp.ObjectReference.EnableCollectionTest#testEnableCollection001", - "org.apache.harmony.jpda.tests.jdwp.MultiSession.EnableCollectionTest.testEnableCollection001" ] + "org.apache.harmony.jpda.tests.jdwp.MultiSession.EnableCollectionTest#testEnableCollection001" ] } ] diff --git a/tools/public.libraries.buildbot.txt b/tools/public.libraries.buildbot.txt index 4b01796a0a..734fd1e50b 100644 --- a/tools/public.libraries.buildbot.txt +++ b/tools/public.libraries.buildbot.txt @@ -1,5 +1,6 @@ libart.so libartd.so +libdexfile.so libbacktrace.so libc.so libc++.so diff --git a/tools/run-jdwp-tests.sh b/tools/run-jdwp-tests.sh index 2cf614d795..b512612175 100755 --- a/tools/run-jdwp-tests.sh +++ b/tools/run-jdwp-tests.sh @@ -286,6 +286,10 @@ fi if [[ $mode != "ri" ]]; then toolchain_args="--toolchain d8 --language CUR" + if [[ "x$with_jdwp_path" == "x" ]]; then + # Need to enable the internal jdwp implementation. + art_debugee="${art_debugee} -XjdwpProvider:internal" + fi else toolchain_args="--toolchain javac --language CUR" fi |