summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/debug/elf_debug_info_writer.h6
-rw-r--r--compiler/exception_test.cc6
-rw-r--r--compiler/optimizing/constant_folding.cc3
-rw-r--r--compiler/optimizing/instruction_builder.cc17
-rw-r--r--compiler/optimizing/instruction_simplifier.cc2
-rw-r--r--compiler/optimizing/intrinsics_arm64.cc2
-rw-r--r--compiler/optimizing/intrinsics_arm_vixl.cc2
-rw-r--r--compiler/optimizing/sharpening.cc12
-rw-r--r--dex2oat/driver/compiler_driver.cc6
-rw-r--r--dex2oat/linker/image_writer.cc4
-rw-r--r--dexdump/dexdump.cc68
-rw-r--r--dexlayout/dexlayout.cc6
-rw-r--r--dexlist/dexlist.cc6
-rw-r--r--libdexfile/dex/art_dex_file_loader_test.cc12
-rw-r--r--libdexfile/dex/class_accessor-inl.h2
-rw-r--r--libdexfile/dex/class_accessor_test.cc2
-rw-r--r--libdexfile/dex/code_item_accessors-inl.h2
-rw-r--r--libdexfile/dex/dex_file-inl.h109
-rw-r--r--libdexfile/dex/dex_file.cc4
-rw-r--r--libdexfile/dex/dex_file.h25
-rw-r--r--libdexfile/dex/dex_file_loader_test.cc7
-rw-r--r--libdexfile/dex/dex_file_verifier.cc14
-rw-r--r--libdexfile/dex/dex_instruction.cc4
-rw-r--r--libdexfile/dex/method_reference.h7
-rw-r--r--libdexfile/dex/signature.cc8
-rw-r--r--libprofile/profile/profile_compilation_info.cc2
-rw-r--r--libprofile/profile/profile_compilation_info.h2
-rw-r--r--libprofile/profile/profile_test_helper.h2
-rw-r--r--oatdump/oatdump.cc2
-rw-r--r--openjdkjvmti/ti_redefine.cc8
-rw-r--r--profman/profile_assistant_test.cc3
-rw-r--r--runtime/art_method-inl.h2
-rw-r--r--runtime/art_method.cc2
-rw-r--r--runtime/class_linker-inl.h2
-rw-r--r--runtime/class_linker.cc20
-rw-r--r--runtime/dex/dex_file_annotations.cc12
-rw-r--r--runtime/entrypoints/entrypoint_utils-inl.h7
-rw-r--r--runtime/jit/profile_saver.cc2
-rw-r--r--runtime/mirror/class.cc10
-rw-r--r--runtime/native/java_lang_reflect_Executable.cc15
-rw-r--r--runtime/vdex_file.cc2
-rw-r--r--runtime/verifier/method_verifier.cc36
-rw-r--r--runtime/verifier/verifier_deps.cc2
-rw-r--r--tools/dexanalyze/dexanalyze_experiments.cc6
-rw-r--r--tools/dexanalyze/dexanalyze_strings.cc2
-rw-r--r--tools/hiddenapi/hiddenapi.cc4
-rw-r--r--tools/veridex/flow_analysis.h4
-rw-r--r--tools/veridex/hidden_api.cc4
-rw-r--r--tools/veridex/hidden_api_finder.cc4
-rw-r--r--tools/veridex/resolver.cc2
50 files changed, 233 insertions, 260 deletions
diff --git a/compiler/debug/elf_debug_info_writer.h b/compiler/debug/elf_debug_info_writer.h
index 50d3f2b6c8..ae4cbd85ab 100644
--- a/compiler/debug/elf_debug_info_writer.h
+++ b/compiler/debug/elf_debug_info_writer.h
@@ -48,8 +48,8 @@ static std::vector<const char*> GetParamNames(const MethodDebugInfo* mi) {
DCHECK(mi->dex_file != nullptr);
CodeItemDebugInfoAccessor accessor(*mi->dex_file, mi->code_item, mi->dex_method_index);
if (accessor.HasCodeItem()) {
- accessor.VisitParameterNames([&](const dex::StringIndex& id) {
- names.push_back(mi->dex_file->StringDataByIdx(id));
+ accessor.VisitParameterNames([&](dex::StringIndex string_idx) {
+ names.push_back(string_idx.IsValid() ? mi->dex_file->GetStringData(string_idx) : nullptr);
});
}
return names;
@@ -225,7 +225,7 @@ class ElfCompilationUnitWriter {
WriteName(param_names[i]);
}
// Write the type.
- const char* type_desc = dex->StringByTypeIdx(dex_params->GetTypeItem(i).type_idx_);
+ const char* type_desc = dex->GetTypeDescriptor(dex_params->GetTypeItem(i).type_idx_);
WriteLazyType(type_desc);
const bool is64bitValue = type_desc[0] == 'D' || type_desc[0] == 'J';
if (accessor.HasCodeItem()) {
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc
index 3c7ff0a984..89fe56dda0 100644
--- a/compiler/exception_test.cc
+++ b/compiler/exception_test.cc
@@ -159,17 +159,17 @@ TEST_F(ExceptionTest, FindCatchHandler) {
EXPECT_LE(t0.start_addr_, t1.start_addr_);
{
CatchHandlerIterator iter(accessor, 4 /* Dex PC in the first try block */);
- EXPECT_STREQ("Ljava/io/IOException;", dex_->StringByTypeIdx(iter.GetHandlerTypeIndex()));
+ EXPECT_STREQ("Ljava/io/IOException;", dex_->GetTypeDescriptor(iter.GetHandlerTypeIndex()));
ASSERT_TRUE(iter.HasNext());
iter.Next();
- EXPECT_STREQ("Ljava/lang/Exception;", dex_->StringByTypeIdx(iter.GetHandlerTypeIndex()));
+ EXPECT_STREQ("Ljava/lang/Exception;", dex_->GetTypeDescriptor(iter.GetHandlerTypeIndex()));
ASSERT_TRUE(iter.HasNext());
iter.Next();
EXPECT_FALSE(iter.HasNext());
}
{
CatchHandlerIterator iter(accessor, 8 /* Dex PC in the second try block */);
- EXPECT_STREQ("Ljava/io/IOException;", dex_->StringByTypeIdx(iter.GetHandlerTypeIndex()));
+ EXPECT_STREQ("Ljava/io/IOException;", dex_->GetTypeDescriptor(iter.GetHandlerTypeIndex()));
ASSERT_TRUE(iter.HasNext());
iter.Next();
EXPECT_FALSE(iter.HasNext());
diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc
index 52cbfe8322..e31de9e1da 100644
--- a/compiler/optimizing/constant_folding.cc
+++ b/compiler/optimizing/constant_folding.cc
@@ -596,7 +596,8 @@ void HConstantFoldingVisitor::VisitArrayLength(HArrayLength* inst) {
HLoadString* load_string = input->AsLoadString();
const DexFile& dex_file = load_string->GetDexFile();
const dex::StringId& string_id = dex_file.GetStringId(load_string->GetStringIndex());
- inst->ReplaceWith(GetGraph()->GetIntConstant(dex_file.GetStringLength(string_id)));
+ inst->ReplaceWith(GetGraph()->GetIntConstant(
+ dchecked_integral_cast<int32_t>(dex_file.GetStringUtf16Length(string_id))));
}
}
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index c3918683ce..3e9c42ba70 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -60,7 +60,7 @@ class SamePackageCompare {
const DexFile* dex_file = dex_compilation_unit_.GetDexFile();
uint32_t referrers_method_idx = dex_compilation_unit_.GetDexMethodIndex();
referrers_descriptor_ =
- dex_file->StringByTypeIdx(dex_file->GetMethodId(referrers_method_idx).class_idx_);
+ dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(referrers_method_idx));
referrers_package_length_ = PackageLength(referrers_descriptor_);
}
std::string temp;
@@ -2439,7 +2439,7 @@ HNewArray* HInstructionBuilder::BuildFilledNewArray(uint32_t dex_pc,
HInstruction* length = graph_->GetIntConstant(number_of_operands, dex_pc);
HNewArray* new_array = BuildNewArray(dex_pc, type_index, length);
- const char* descriptor = dex_file_->StringByTypeIdx(type_index);
+ const char* descriptor = dex_file_->GetTypeDescriptor(type_index);
DCHECK_EQ(descriptor[0], '[') << descriptor;
char primitive = descriptor[1];
DCHECK(primitive == 'I'
@@ -2657,14 +2657,11 @@ bool HInstructionBuilder::LoadClassNeedsAccessCheck(dex::TypeIndex type_index,
return true;
}
} else {
- uint32_t outer_utf16_length;
- const char* outer_descriptor =
- outer_dex_file->StringByTypeIdx(outer_class_def.class_idx_, &outer_utf16_length);
- uint32_t target_utf16_length;
- const char* target_descriptor =
- inner_dex_file->StringByTypeIdx(type_index, &target_utf16_length);
- if (outer_utf16_length != target_utf16_length ||
- strcmp(outer_descriptor, target_descriptor) != 0) {
+ const std::string_view outer_descriptor =
+ outer_dex_file->GetTypeDescriptorView(outer_class_def.class_idx_);
+ const std::string_view target_descriptor =
+ inner_dex_file->GetTypeDescriptorView(type_index);
+ if (outer_descriptor != target_descriptor) {
return true;
}
}
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index ae778b421a..2710f49ef2 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -2716,7 +2716,7 @@ void InstructionSimplifierVisitor::SimplifyStringIndexOf(HInvoke* invoke) {
const DexFile& dex_file = load_string->GetDexFile();
uint32_t utf16_length;
const char* data =
- dex_file.StringDataAndUtf16LengthByIdx(load_string->GetStringIndex(), &utf16_length);
+ dex_file.GetStringDataAndUtf16Length(load_string->GetStringIndex(), &utf16_length);
if (utf16_length == 0) {
invoke->ReplaceWith(GetGraph()->GetIntConstant(-1));
invoke->GetBlock()->RemoveInstruction(invoke);
diff --git a/compiler/optimizing/intrinsics_arm64.cc b/compiler/optimizing/intrinsics_arm64.cc
index 4de6d5d582..3dde811958 100644
--- a/compiler/optimizing/intrinsics_arm64.cc
+++ b/compiler/optimizing/intrinsics_arm64.cc
@@ -2053,7 +2053,7 @@ static const char* GetConstString(HInstruction* candidate, uint32_t* utf16_lengt
if (candidate->IsLoadString()) {
HLoadString* load_string = candidate->AsLoadString();
const DexFile& dex_file = load_string->GetDexFile();
- return dex_file.StringDataAndUtf16LengthByIdx(load_string->GetStringIndex(), utf16_length);
+ return dex_file.GetStringDataAndUtf16Length(load_string->GetStringIndex(), utf16_length);
}
return nullptr;
}
diff --git a/compiler/optimizing/intrinsics_arm_vixl.cc b/compiler/optimizing/intrinsics_arm_vixl.cc
index c763721aec..ea7b65181a 100644
--- a/compiler/optimizing/intrinsics_arm_vixl.cc
+++ b/compiler/optimizing/intrinsics_arm_vixl.cc
@@ -838,7 +838,7 @@ static const char* GetConstString(HInstruction* candidate, uint32_t* utf16_lengt
if (candidate->IsLoadString()) {
HLoadString* load_string = candidate->AsLoadString();
const DexFile& dex_file = load_string->GetDexFile();
- return dex_file.StringDataAndUtf16LengthByIdx(load_string->GetStringIndex(), utf16_length);
+ return dex_file.GetStringDataAndUtf16Length(load_string->GetStringIndex(), utf16_length);
}
return nullptr;
}
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index 5a697e32a1..e900b3ef3a 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -54,7 +54,7 @@ static bool BootImageAOTCanEmbedMethod(ArtMethod* method, const CompilerOptions&
ObjPtr<mirror::Class> klass = method->GetDeclaringClass();
DCHECK(klass != nullptr);
const DexFile& dex_file = klass->GetDexFile();
- return compiler_options.IsImageClass(dex_file.StringByTypeIdx(klass->GetDexTypeIndex()));
+ return compiler_options.IsImageClass(dex_file.GetTypeDescriptor(klass->GetDexTypeIndex()));
}
HInvokeStaticOrDirect::DispatchInfo HSharpening::SharpenLoadMethod(
@@ -173,7 +173,7 @@ HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(
auto is_class_in_current_boot_image = [&]() {
return (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) &&
- compiler_options.IsImageClass(dex_file.StringByTypeIdx(type_index));
+ compiler_options.IsImageClass(dex_file.GetTypeDescriptor(type_index));
};
bool is_in_boot_image = false;
@@ -210,12 +210,12 @@ HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(
const char* slash_pos = strrchr(descriptor, '/');
return (slash_pos != nullptr) ? static_cast<size_t>(slash_pos - descriptor) : 0u;
};
- const char* klass_descriptor = dex_file.StringByTypeIdx(type_index);
+ const char* klass_descriptor = dex_file.GetTypeDescriptor(type_index);
const uint32_t klass_package_length = package_length(klass_descriptor);
const DexFile* referrer_dex_file = dex_compilation_unit.GetDexFile();
const dex::TypeIndex referrer_type_index =
referrer_dex_file->GetClassDef(dex_compilation_unit.GetClassDefIndex()).class_idx_;
- const char* referrer_descriptor = referrer_dex_file->StringByTypeIdx(referrer_type_index);
+ const char* referrer_descriptor = referrer_dex_file->GetTypeDescriptor(referrer_type_index);
const uint32_t referrer_package_length = package_length(referrer_descriptor);
bool same_package =
(referrer_package_length == klass_package_length) &&
@@ -240,7 +240,7 @@ HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(
is_in_boot_image = true;
desired_load_kind = HLoadClass::LoadKind::kBootImageRelRo;
} else if ((klass != nullptr) &&
- compiler_options.IsImageClass(dex_file.StringByTypeIdx(type_index))) {
+ compiler_options.IsImageClass(dex_file.GetTypeDescriptor(type_index))) {
is_in_boot_image = true;
desired_load_kind = HLoadClass::LoadKind::kBootImageLinkTimePcRelative;
} else {
@@ -317,7 +317,7 @@ static inline bool CanUseTypeCheckBitstring(ObjPtr<mirror::Class> klass, CodeGen
if (compiler_options.IsJitCompiler()) {
// If we're JITting, try to assign a type check bitstring (fall through).
} else if (codegen->GetCompilerOptions().IsBootImage()) {
- const char* descriptor = klass->GetDexFile().StringByTypeIdx(klass->GetDexTypeIndex());
+ const char* descriptor = klass->GetDexFile().GetTypeDescriptor(klass->GetDexTypeIndex());
if (!codegen->GetCompilerOptions().IsImageClass(descriptor)) {
return false;
}
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 3415efae3d..4386f671fc 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -687,7 +687,7 @@ static void InitializeTypeCheckBitstrings(CompilerDriver* driver,
case Instruction::INSTANCE_OF: {
dex::TypeIndex type_index(
(inst->Opcode() == Instruction::CHECK_CAST) ? inst->VRegB_21c() : inst->VRegC_22c());
- const char* descriptor = dex_file.StringByTypeIdx(type_index);
+ const char* descriptor = dex_file.GetTypeDescriptor(type_index);
// We currently do not use the bitstring type check for array or final (including
// primitive) classes. We may reconsider this in future if it's deemed to be beneficial.
// And we cannot use it for classes outside the boot image as we do not know the runtime
@@ -2097,7 +2097,7 @@ class InitializeClassVisitor : public CompilationVisitor {
const DexFile& dex_file = *manager_->GetDexFile();
const dex::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
const dex::TypeId& class_type_id = dex_file.GetTypeId(class_def.class_idx_);
- const char* descriptor = dex_file.StringDataByIdx(class_type_id.descriptor_idx_);
+ const char* descriptor = dex_file.GetStringData(class_type_id.descriptor_idx_);
ScopedObjectAccess soa(Thread::Current());
StackHandleScope<3> hs(soa.Self());
@@ -2124,7 +2124,7 @@ class InitializeClassVisitor : public CompilationVisitor {
const DexFile& dex_file = klass->GetDexFile();
const dex::ClassDef* class_def = klass->GetClassDef();
const dex::TypeId& class_type_id = dex_file.GetTypeId(class_def->class_idx_);
- const char* descriptor = dex_file.StringDataByIdx(class_type_id.descriptor_idx_);
+ const char* descriptor = dex_file.GetStringData(class_type_id.descriptor_idx_);
StackHandleScope<3> hs(self);
ClassLinker* const class_linker = manager_->GetClassLinker();
Runtime* const runtime = Runtime::Current();
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index c9be7de2c2..63ac71fc12 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -2078,8 +2078,8 @@ void ImageWriter::LayoutHelper::ProcessInterns(Thread* self) {
// Assign bin slots for strings defined in this dex file in StringId (lexicographical) order.
for (size_t i = 0, count = dex_file->NumStringIds(); i != count; ++i) {
uint32_t utf16_length;
- const char* utf8_data = dex_file->StringDataAndUtf16LengthByIdx(dex::StringIndex(i),
- &utf16_length);
+ const char* utf8_data = dex_file->GetStringDataAndUtf16Length(dex::StringIndex(i),
+ &utf16_length);
uint32_t hash = InternTable::Utf8String::Hash(utf16_length, utf8_data);
auto intern_it =
intern_set.FindWithHash(InternTable::Utf8String(utf16_length, utf8_data), hash);
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc
index 0ed3c52c07..fd42454007 100644
--- a/dexdump/dexdump.cc
+++ b/dexdump/dexdump.cc
@@ -578,28 +578,28 @@ static void dumpEncodedValue(const DexFile* pDexFile, const u1** data, u1 type,
case DexFile::kDexAnnotationString: {
const u4 idx = static_cast<u4>(readVarWidth(data, arg, false));
if (gOptions.outputFormat == OUTPUT_PLAIN) {
- dumpEscapedString(pDexFile->StringViewByIdx(dex::StringIndex(idx)));
+ dumpEscapedString(pDexFile->GetStringView(dex::StringIndex(idx)));
} else {
- dumpXmlAttribute(pDexFile->StringViewByIdx(dex::StringIndex(idx)));
+ dumpXmlAttribute(pDexFile->GetStringView(dex::StringIndex(idx)));
}
break;
}
case DexFile::kDexAnnotationType: {
const u4 str_idx = static_cast<u4>(readVarWidth(data, arg, false));
- fputs(pDexFile->StringByTypeIdx(dex::TypeIndex(str_idx)), gOutFile);
+ fputs(pDexFile->GetTypeDescriptor(dex::TypeIndex(str_idx)), gOutFile);
break;
}
case DexFile::kDexAnnotationField:
case DexFile::kDexAnnotationEnum: {
const u4 field_idx = static_cast<u4>(readVarWidth(data, arg, false));
const dex::FieldId& pFieldId = pDexFile->GetFieldId(field_idx);
- fputs(pDexFile->StringDataByIdx(pFieldId.name_idx_), gOutFile);
+ fputs(pDexFile->GetStringData(pFieldId.name_idx_), gOutFile);
break;
}
case DexFile::kDexAnnotationMethod: {
const u4 method_idx = static_cast<u4>(readVarWidth(data, arg, false));
const dex::MethodId& pMethodId = pDexFile->GetMethodId(method_idx);
- fputs(pDexFile->StringDataByIdx(pMethodId.name_idx_), gOutFile);
+ fputs(pDexFile->GetStringData(pMethodId.name_idx_), gOutFile);
break;
}
case DexFile::kDexAnnotationArray: {
@@ -615,13 +615,13 @@ static void dumpEncodedValue(const DexFile* pDexFile, const u1** data, u1 type,
}
case DexFile::kDexAnnotationAnnotation: {
const u4 type_idx = DecodeUnsignedLeb128(data);
- fputs(pDexFile->StringByTypeIdx(dex::TypeIndex(type_idx)), gOutFile);
+ fputs(pDexFile->GetTypeDescriptor(dex::TypeIndex(type_idx)), gOutFile);
// Decode and display all name=value pairs.
const u4 size = DecodeUnsignedLeb128(data);
for (u4 i = 0; i < size; i++) {
const u4 name_idx = DecodeUnsignedLeb128(data);
fputc(' ', gOutFile);
- fputs(pDexFile->StringDataByIdx(dex::StringIndex(name_idx)), gOutFile);
+ fputs(pDexFile->GetStringData(dex::StringIndex(name_idx)), gOutFile);
fputc('=', gOutFile);
dumpEncodedValue(pDexFile, data);
}
@@ -772,7 +772,7 @@ static void dumpClassAnnotations(const DexFile* pDexFile, int idx) {
for (u4 i = 0; i < dir->fields_size_; i++) {
const u4 field_idx = fields[i].field_idx_;
const dex::FieldId& pFieldId = pDexFile->GetFieldId(field_idx);
- const char* field_name = pDexFile->StringDataByIdx(pFieldId.name_idx_);
+ const char* field_name = pDexFile->GetStringData(pFieldId.name_idx_);
fprintf(gOutFile, "Annotations on field #%u '%s'\n", field_idx, field_name);
dumpAnnotationSetItem(pDexFile, pDexFile->GetFieldAnnotationSetItem(fields[i]));
}
@@ -783,7 +783,7 @@ static void dumpClassAnnotations(const DexFile* pDexFile, int idx) {
for (u4 i = 0; i < dir->methods_size_; i++) {
const u4 method_idx = methods[i].method_idx_;
const dex::MethodId& pMethodId = pDexFile->GetMethodId(method_idx);
- const char* method_name = pDexFile->StringDataByIdx(pMethodId.name_idx_);
+ const char* method_name = pDexFile->GetStringData(pMethodId.name_idx_);
fprintf(gOutFile, "Annotations on method #%u '%s'\n", method_idx, method_name);
dumpAnnotationSetItem(pDexFile, pDexFile->GetMethodAnnotationSetItem(methods[i]));
}
@@ -794,7 +794,7 @@ static void dumpClassAnnotations(const DexFile* pDexFile, int idx) {
for (u4 i = 0; i < dir->parameters_size_; i++) {
const u4 method_idx = pars[i].method_idx_;
const dex::MethodId& pMethodId = pDexFile->GetMethodId(method_idx);
- const char* method_name = pDexFile->StringDataByIdx(pMethodId.name_idx_);
+ const char* method_name = pDexFile->GetStringData(pMethodId.name_idx_);
fprintf(gOutFile, "Annotations on method #%u '%s' parameters\n", method_idx, method_name);
const dex::AnnotationSetRefList*
list = pDexFile->GetParameterAnnotationSetRefList(&pars[i]);
@@ -814,7 +814,7 @@ static void dumpClassAnnotations(const DexFile* pDexFile, int idx) {
* Dumps an interface that a class declares to implement.
*/
static void dumpInterface(const DexFile* pDexFile, const dex::TypeItem& pTypeItem, int i) {
- const char* interfaceName = pDexFile->StringByTypeIdx(pTypeItem.type_idx_);
+ const char* interfaceName = pDexFile->GetTypeDescriptor(pTypeItem.type_idx_);
if (gOptions.outputFormat == OUTPUT_PLAIN) {
fprintf(gOutFile, " #%d : '%s'\n", i, interfaceName);
} else {
@@ -844,7 +844,7 @@ static void dumpCatches(const DexFile* pDexFile, const dex::CodeItem* pCode) {
fprintf(gOutFile, " 0x%04x - 0x%04x\n", start, end);
for (CatchHandlerIterator it(accessor, try_item); it.HasNext(); it.Next()) {
const dex::TypeIndex tidx = it.GetHandlerTypeIndex();
- const char* descriptor = (!tidx.IsValid()) ? "<any>" : pDexFile->StringByTypeIdx(tidx);
+ const char* descriptor = (!tidx.IsValid()) ? "<any>" : pDexFile->GetTypeDescriptor(tidx);
fprintf(gOutFile, " %s -> 0x%04x\n", descriptor, it.GetHandlerAddress());
} // for
} // for
@@ -910,7 +910,7 @@ static std::unique_ptr<char[]> indexString(const DexFile* pDexFile,
break;
case Instruction::kIndexTypeRef:
if (index < pDexFile->GetHeader().type_ids_size_) {
- const char* tp = pDexFile->StringByTypeIdx(dex::TypeIndex(index));
+ const char* tp = pDexFile->GetTypeDescriptor(dex::TypeIndex(index));
outSize = snprintf(buf.get(), bufSize, "%s // type@%0*x", tp, width, index);
} else {
outSize = snprintf(buf.get(), bufSize, "<type?> // type@%0*x", width, index);
@@ -918,7 +918,7 @@ static std::unique_ptr<char[]> indexString(const DexFile* pDexFile,
break;
case Instruction::kIndexStringRef:
if (index < pDexFile->GetHeader().string_ids_size_) {
- const char* st = pDexFile->StringDataByIdx(dex::StringIndex(index));
+ const char* st = pDexFile->GetStringData(dex::StringIndex(index));
if (needsEscape(std::string_view(st))) {
std::string escaped = escapeString(st);
outSize =
@@ -933,9 +933,9 @@ static std::unique_ptr<char[]> indexString(const DexFile* pDexFile,
case Instruction::kIndexMethodRef:
if (index < pDexFile->GetHeader().method_ids_size_) {
const dex::MethodId& pMethodId = pDexFile->GetMethodId(index);
- const char* name = pDexFile->StringDataByIdx(pMethodId.name_idx_);
+ const char* name = pDexFile->GetStringData(pMethodId.name_idx_);
const Signature signature = pDexFile->GetMethodSignature(pMethodId);
- const char* backDescriptor = pDexFile->StringByTypeIdx(pMethodId.class_idx_);
+ const char* backDescriptor = pDexFile->GetTypeDescriptor(pMethodId.class_idx_);
outSize = snprintf(buf.get(), bufSize, "%s.%s:%s // method@%0*x",
backDescriptor, name, signature.ToString().c_str(), width, index);
} else {
@@ -945,9 +945,9 @@ static std::unique_ptr<char[]> indexString(const DexFile* pDexFile,
case Instruction::kIndexFieldRef:
if (index < pDexFile->GetHeader().field_ids_size_) {
const dex::FieldId& pFieldId = pDexFile->GetFieldId(index);
- const char* name = pDexFile->StringDataByIdx(pFieldId.name_idx_);
- const char* typeDescriptor = pDexFile->StringByTypeIdx(pFieldId.type_idx_);
- const char* backDescriptor = pDexFile->StringByTypeIdx(pFieldId.class_idx_);
+ const char* name = pDexFile->GetStringData(pFieldId.name_idx_);
+ const char* typeDescriptor = pDexFile->GetTypeDescriptor(pFieldId.type_idx_);
+ const char* backDescriptor = pDexFile->GetTypeDescriptor(pFieldId.class_idx_);
outSize = snprintf(buf.get(), bufSize, "%s.%s:%s // field@%0*x",
backDescriptor, name, typeDescriptor, width, index);
} else {
@@ -966,9 +966,9 @@ static std::unique_ptr<char[]> indexString(const DexFile* pDexFile,
std::string proto("<proto?>");
if (index < pDexFile->GetHeader().method_ids_size_) {
const dex::MethodId& pMethodId = pDexFile->GetMethodId(index);
- const char* name = pDexFile->StringDataByIdx(pMethodId.name_idx_);
+ const char* name = pDexFile->GetStringData(pMethodId.name_idx_);
const Signature signature = pDexFile->GetMethodSignature(pMethodId);
- const char* backDescriptor = pDexFile->StringByTypeIdx(pMethodId.class_idx_);
+ const char* backDescriptor = pDexFile->GetTypeDescriptor(pMethodId.class_idx_);
method = android::base::StringPrintf("%s.%s:%s",
backDescriptor,
name,
@@ -1237,9 +1237,9 @@ static void dumpInstruction(const DexFile* pDexFile,
static void dumpBytecodes(const DexFile* pDexFile, u4 idx,
const dex::CodeItem* pCode, u4 codeOffset) {
const dex::MethodId& pMethodId = pDexFile->GetMethodId(idx);
- const char* name = pDexFile->StringDataByIdx(pMethodId.name_idx_);
+ const char* name = pDexFile->GetStringData(pMethodId.name_idx_);
const Signature signature = pDexFile->GetMethodSignature(pMethodId);
- const char* backDescriptor = pDexFile->StringByTypeIdx(pMethodId.class_idx_);
+ const char* backDescriptor = pDexFile->GetTypeDescriptor(pMethodId.class_idx_);
// Generate header.
std::unique_ptr<char[]> dot(descriptorToDot(backDescriptor));
@@ -1353,10 +1353,10 @@ static void dumpMethod(const ClassAccessor::Method& method, int i) {
const DexFile& dex_file = method.GetDexFile();
const dex::MethodId& pMethodId = dex_file.GetMethodId(method.GetIndex());
- const char* name = dex_file.StringDataByIdx(pMethodId.name_idx_);
+ const char* name = dex_file.GetStringData(pMethodId.name_idx_);
const Signature signature = dex_file.GetMethodSignature(pMethodId);
char* typeDescriptor = strdup(signature.ToString().c_str());
- const char* backDescriptor = dex_file.StringByTypeIdx(pMethodId.class_idx_);
+ const char* backDescriptor = dex_file.GetTypeDescriptor(pMethodId.class_idx_);
char* accessStr = createAccessFlagStr(flags, kAccessForMethod);
const uint32_t hiddenapiFlags = method.GetHiddenapiFlags();
@@ -1474,9 +1474,9 @@ static void dumpField(const ClassAccessor::Field& field, int i, const u1** data
const DexFile& dex_file = field.GetDexFile();
const dex::FieldId& field_id = dex_file.GetFieldId(field.GetIndex());
- const char* name = dex_file.StringDataByIdx(field_id.name_idx_);
- const char* typeDescriptor = dex_file.StringByTypeIdx(field_id.type_idx_);
- const char* backDescriptor = dex_file.StringByTypeIdx(field_id.class_idx_);
+ const char* name = dex_file.GetStringData(field_id.name_idx_);
+ const char* typeDescriptor = dex_file.GetTypeDescriptor(field_id.type_idx_);
+ const char* backDescriptor = dex_file.GetTypeDescriptor(field_id.class_idx_);
char* accessStr = createAccessFlagStr(flags, kAccessForField);
const uint32_t hiddenapiFlags = field.GetHiddenapiFlags();
@@ -1565,7 +1565,7 @@ static void dumpClass(const DexFile* pDexFile, int idx, char** pLastPackage) {
// up the classes, sort them, and dump them alphabetically so the
// package name wouldn't jump around, but that's not a great plan
// for something that needs to run on the device.
- const char* classDescriptor = pDexFile->StringByTypeIdx(pClassDef.class_idx_);
+ const char* classDescriptor = pDexFile->GetTypeDescriptor(pClassDef.class_idx_);
if (!(classDescriptor[0] == 'L' &&
classDescriptor[strlen(classDescriptor)-1] == ';')) {
// Arrays and primitives should not be defined explicitly. Keep going?
@@ -1607,7 +1607,7 @@ static void dumpClass(const DexFile* pDexFile, int idx, char** pLastPackage) {
if (!pClassDef.superclass_idx_.IsValid()) {
superclassDescriptor = nullptr;
} else {
- superclassDescriptor = pDexFile->StringByTypeIdx(pClassDef.superclass_idx_);
+ superclassDescriptor = pDexFile->GetTypeDescriptor(pClassDef.superclass_idx_);
}
if (gOptions.outputFormat == OUTPUT_PLAIN) {
fprintf(gOutFile, "Class #%d -\n", idx);
@@ -1693,7 +1693,7 @@ static void dumpClass(const DexFile* pDexFile, int idx, char** pLastPackage) {
if (gOptions.outputFormat == OUTPUT_PLAIN) {
const char* fileName;
if (pClassDef.source_file_idx_.IsValid()) {
- fileName = pDexFile->StringDataByIdx(pClassDef.source_file_idx_);
+ fileName = pDexFile->GetStringData(pClassDef.source_file_idx_);
} else {
fileName = "unknown";
}
@@ -1803,7 +1803,7 @@ static void dumpCallSite(const DexFile* pDexFile, u4 idx) {
uint32_t method_handle_idx = static_cast<uint32_t>(it.GetJavaValue().i);
it.Next();
dex::StringIndex method_name_idx = static_cast<dex::StringIndex>(it.GetJavaValue().i);
- const char* method_name = pDexFile->StringDataByIdx(method_name_idx);
+ const char* method_name = pDexFile->GetStringData(method_name_idx);
it.Next();
dex::ProtoIndex method_type_idx = static_cast<dex::ProtoIndex>(it.GetJavaValue().i);
const dex::ProtoId& method_type_id = pDexFile->GetProtoId(method_type_idx);
@@ -1864,7 +1864,7 @@ static void dumpCallSite(const DexFile* pDexFile, u4 idx) {
case EncodedArrayValueIterator::ValueType::kString: {
type = "String";
dex::StringIndex string_idx = static_cast<dex::StringIndex>(it.GetJavaValue().i);
- value = pDexFile->StringDataByIdx(string_idx);
+ value = pDexFile->GetStringData(string_idx);
break;
}
case EncodedArrayValueIterator::ValueType::kType: {
@@ -1925,7 +1925,7 @@ static void dumpStrings(const DexFile* pDexFile) {
for (uint32_t i = 0; i < pHeader.string_ids_size_; i++) {
dex::StringIndex idx = static_cast<dex::StringIndex>(i);
- const char* string = pDexFile->StringDataByIdx(idx);
+ const char* string = pDexFile->GetStringData(idx);
if (!isPrintable(string)) {
string = "skipped (not printable)";
}
diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc
index d674fd2ebc..f43ded0251 100644
--- a/dexlayout/dexlayout.cc
+++ b/dexlayout/dexlayout.cc
@@ -1119,7 +1119,7 @@ void DexLayout::DumpBytecodes(uint32_t idx, const dex_ir::CodeItem* code, uint32
/*
* Lookup functions.
*/
-static const char* StringDataByIdx(uint32_t idx, dex_ir::Header* header) {
+static const char* GetStringData(uint32_t idx, dex_ir::Header* header) {
dex_ir::StringId* string_id = header->GetStringIdOrNullPtr(idx);
if (string_id == nullptr) {
return nullptr;
@@ -1170,7 +1170,7 @@ void DexLayout::DumpCode(uint32_t idx,
if (debug_info != nullptr) {
DexFile::DecodeDebugPositionInfo(debug_info->GetDebugInfo(),
[this](uint32_t idx) {
- return StringDataByIdx(idx, this->header_);
+ return GetStringData(idx, this->header_);
},
[&](const DexFile::PositionInfo& entry) {
fprintf(out_file_,
@@ -1202,7 +1202,7 @@ void DexLayout::DumpCode(uint32_t idx,
code->InsSize(),
code->InsnsSize(),
[this](uint32_t idx) {
- return StringDataByIdx(idx, this->header_);
+ return GetStringData(idx, this->header_);
},
[this](uint32_t idx) {
return
diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc
index 553e364c5e..ed717803ca 100644
--- a/dexlist/dexlist.cc
+++ b/dexlist/dexlist.cc
@@ -97,8 +97,8 @@ static void dumpMethod(const DexFile* pDexFile,
// Method information.
const dex::MethodId& pMethodId = pDexFile->GetMethodId(idx);
- const char* methodName = pDexFile->StringDataByIdx(pMethodId.name_idx_);
- const char* classDescriptor = pDexFile->StringByTypeIdx(pMethodId.class_idx_);
+ const char* methodName = pDexFile->GetStringData(pMethodId.name_idx_);
+ const char* classDescriptor = pDexFile->GetTypeDescriptor(pMethodId.class_idx_);
std::unique_ptr<char[]> className(descriptorToDot(classDescriptor));
const u4 insnsOff = codeOffset + 0x10;
@@ -142,7 +142,7 @@ void dumpClass(const DexFile* pDexFile, u4 idx) {
const char* fileName = nullptr;
if (class_def.source_file_idx_.IsValid()) {
- fileName = pDexFile->StringDataByIdx(class_def.source_file_idx_);
+ fileName = pDexFile->GetStringData(class_def.source_file_idx_);
}
ClassAccessor accessor(*pDexFile, class_def);
diff --git a/libdexfile/dex/art_dex_file_loader_test.cc b/libdexfile/dex/art_dex_file_loader_test.cc
index 23ffad6e78..384452cd4c 100644
--- a/libdexfile/dex/art_dex_file_loader_test.cc
+++ b/libdexfile/dex/art_dex_file_loader_test.cc
@@ -175,7 +175,7 @@ TEST_F(ArtDexFileLoaderTest, GetMethodSignature) {
{
ASSERT_EQ(1U, accessor.NumDirectMethods());
const dex::MethodId& method_id = raw->GetMethodId(cur_method->GetIndex());
- const char* name = raw->StringDataByIdx(method_id.name_idx_);
+ const char* name = raw->GetStringData(method_id.name_idx_);
ASSERT_STREQ("<init>", name);
std::string signature(raw->GetMethodSignature(method_id).ToString());
ASSERT_EQ("()V", signature);
@@ -250,7 +250,7 @@ TEST_F(ArtDexFileLoaderTest, GetMethodSignature) {
ASSERT_TRUE(cur_method != methods.end());
const dex::MethodId& method_id = raw->GetMethodId(cur_method->GetIndex());
- const char* name = raw->StringDataByIdx(method_id.name_idx_);
+ const char* name = raw->GetStringData(method_id.name_idx_);
ASSERT_STREQ(r.name, name);
std::string signature(raw->GetMethodSignature(method_id).ToString());
@@ -281,7 +281,7 @@ TEST_F(ArtDexFileLoaderTest, FindStringId) {
TEST_F(ArtDexFileLoaderTest, FindTypeId) {
for (size_t i = 0; i < java_lang_dex_file_->NumTypeIds(); i++) {
- const char* type_str = java_lang_dex_file_->StringByTypeIdx(dex::TypeIndex(i));
+ const char* type_str = java_lang_dex_file_->GetTypeDescriptor(dex::TypeIndex(i));
const dex::StringId* type_str_id = java_lang_dex_file_->FindStringId(type_str);
ASSERT_TRUE(type_str_id != nullptr);
dex::StringIndex type_str_idx = java_lang_dex_file_->GetIndexForStringId(*type_str_id);
@@ -317,7 +317,7 @@ TEST_F(ArtDexFileLoaderTest, FindMethodId) {
const dex::ProtoId& signature = java_lang_dex_file_->GetProtoId(to_find.proto_idx_);
const dex::MethodId* found = java_lang_dex_file_->FindMethodId(klass, name, signature);
ASSERT_TRUE(found != nullptr) << "Didn't find method " << i << ": "
- << java_lang_dex_file_->StringByTypeIdx(to_find.class_idx_) << "."
+ << java_lang_dex_file_->GetTypeDescriptor(to_find.class_idx_) << "."
<< java_lang_dex_file_->GetStringData(name)
<< java_lang_dex_file_->GetMethodSignature(to_find);
EXPECT_EQ(java_lang_dex_file_->GetIndexForMethodId(*found), i);
@@ -332,8 +332,8 @@ TEST_F(ArtDexFileLoaderTest, FindFieldId) {
const dex::TypeId& type = java_lang_dex_file_->GetTypeId(to_find.type_idx_);
const dex::FieldId* found = java_lang_dex_file_->FindFieldId(klass, name, type);
ASSERT_TRUE(found != nullptr) << "Didn't find field " << i << ": "
- << java_lang_dex_file_->StringByTypeIdx(to_find.type_idx_) << " "
- << java_lang_dex_file_->StringByTypeIdx(to_find.class_idx_) << "."
+ << java_lang_dex_file_->GetTypeDescriptor(to_find.type_idx_) << " "
+ << java_lang_dex_file_->GetTypeDescriptor(to_find.class_idx_) << "."
<< java_lang_dex_file_->GetStringData(name);
EXPECT_EQ(java_lang_dex_file_->GetIndexForFieldId(*found), i);
}
diff --git a/libdexfile/dex/class_accessor-inl.h b/libdexfile/dex/class_accessor-inl.h
index f224a29fc4..4239da97a8 100644
--- a/libdexfile/dex/class_accessor-inl.h
+++ b/libdexfile/dex/class_accessor-inl.h
@@ -151,7 +151,7 @@ inline CodeItemDataAccessor ClassAccessor::Method::GetInstructionsAndData() cons
}
inline const char* ClassAccessor::GetDescriptor() const {
- return dex_file_.StringByTypeIdx(GetClassIdx());
+ return dex_file_.GetTypeDescriptor(GetClassIdx());
}
inline const dex::CodeItem* ClassAccessor::Method::GetCodeItem() const {
diff --git a/libdexfile/dex/class_accessor_test.cc b/libdexfile/dex/class_accessor_test.cc
index 9f2ee23327..cb50096084 100644
--- a/libdexfile/dex/class_accessor_test.cc
+++ b/libdexfile/dex/class_accessor_test.cc
@@ -31,7 +31,7 @@ TEST_F(ClassAccessorTest, TestVisiting) {
ASSERT_GT(dex_file->NumClassDefs(), 0u);
for (ClassAccessor accessor : dex_file->GetClasses()) {
const dex::ClassDef& class_def = dex_file->GetClassDef(accessor.GetClassDefIndex());
- EXPECT_EQ(accessor.GetDescriptor(), dex_file->StringByTypeIdx(class_def.class_idx_));
+ EXPECT_EQ(accessor.GetDescriptor(), dex_file->GetTypeDescriptor(class_def.class_idx_));
EXPECT_EQ(class_def_idx, accessor.GetClassDefIndex());
++class_def_idx;
// Check iterators against visitors.
diff --git a/libdexfile/dex/code_item_accessors-inl.h b/libdexfile/dex/code_item_accessors-inl.h
index 4586a0ff7a..8fa6ea3fd8 100644
--- a/libdexfile/dex/code_item_accessors-inl.h
+++ b/libdexfile/dex/code_item_accessors-inl.h
@@ -239,7 +239,7 @@ inline bool CodeItemDebugInfoAccessor::DecodeDebugPositionInfo(Visitor&& visitor
return dex_file_->DecodeDebugPositionInfo(
dex_file_->GetDebugInfoStream(DebugInfoOffset()),
[this](uint32_t idx) {
- return dex_file_->StringDataByIdx(dex::StringIndex(idx));
+ return dex_file_->GetStringData(dex::StringIndex(idx));
},
std::forward<Visitor>(visitor));
}
diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h
index 8ad065b494..2cd3781023 100644
--- a/libdexfile/dex/dex_file-inl.h
+++ b/libdexfile/dex/dex_file-inl.h
@@ -39,11 +39,6 @@ inline std::string_view StringViewFromUtf16Length(const char* utf8_data, size_t
return std::string_view(utf8_data, utf8_length);
}
-inline int32_t DexFile::GetStringLength(const dex::StringId& string_id) const {
- const uint8_t* ptr = DataBegin() + string_id.string_data_off_;
- return DecodeUnsignedLeb128(&ptr);
-}
-
ALWAYS_INLINE
inline const char* DexFile::GetStringDataAndUtf16Length(const dex::StringId& string_id,
uint32_t* utf16_length) const {
@@ -54,64 +49,55 @@ inline const char* DexFile::GetStringDataAndUtf16Length(const dex::StringId& str
}
ALWAYS_INLINE
-inline const char* DexFile::GetStringData(const dex::StringId& string_id) const {
- uint32_t ignored;
- return GetStringDataAndUtf16Length(string_id, &ignored);
+inline const char* DexFile::GetStringDataAndUtf16Length(const dex::StringIndex string_idx,
+ uint32_t* utf16_length) const {
+ return GetStringDataAndUtf16Length(GetStringId(string_idx), utf16_length);
}
ALWAYS_INLINE
-inline std::string_view DexFile::GetStringView(const dex::StringId& string_id) const {
+inline uint32_t DexFile::GetStringUtf16Length(const dex::StringId& string_id) const {
uint32_t utf16_length;
- const char* data = GetStringDataAndUtf16Length(string_id, &utf16_length);
- return StringViewFromUtf16Length(data, utf16_length);
+ GetStringDataAndUtf16Length(string_id, &utf16_length);
+ return utf16_length;
}
ALWAYS_INLINE
-inline const char* DexFile::StringDataAndUtf16LengthByIdx(dex::StringIndex idx,
- uint32_t* utf16_length) const {
- if (!idx.IsValid()) {
- *utf16_length = 0;
- return nullptr;
- }
- const dex::StringId& string_id = GetStringId(idx);
- return GetStringDataAndUtf16Length(string_id, utf16_length);
+inline const char* DexFile::GetStringData(const dex::StringId& string_id) const {
+ uint32_t ignored;
+ return GetStringDataAndUtf16Length(string_id, &ignored);
}
ALWAYS_INLINE
-inline const char* DexFile::StringDataByIdx(dex::StringIndex idx) const {
- uint32_t unicode_length;
- return StringDataAndUtf16LengthByIdx(idx, &unicode_length);
+inline const char* DexFile::GetStringData(dex::StringIndex string_idx) const {
+ return GetStringData(GetStringId(string_idx));
}
ALWAYS_INLINE
-inline std::string_view DexFile::StringViewByIdx(dex::StringIndex idx) const {
- uint32_t unicode_length;
- const char* data = StringDataAndUtf16LengthByIdx(idx, &unicode_length);
- return data != nullptr ? StringViewFromUtf16Length(data, unicode_length) : std::string_view("");
+inline std::string_view DexFile::GetStringView(const dex::StringId& string_id) const {
+ uint32_t utf16_length;
+ const char* data = GetStringDataAndUtf16Length(string_id, &utf16_length);
+ return StringViewFromUtf16Length(data, utf16_length);
}
-inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx, uint32_t* unicode_length) const {
- if (!idx.IsValid()) {
- return nullptr;
- }
- const dex::TypeId& type_id = GetTypeId(idx);
- return StringDataAndUtf16LengthByIdx(type_id.descriptor_idx_, unicode_length);
+ALWAYS_INLINE
+inline std::string_view DexFile::GetStringView(dex::StringIndex string_idx) const {
+ return GetStringView(GetStringId(string_idx));
}
-inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx) const {
- if (!idx.IsValid()) {
- return nullptr;
- }
- const dex::TypeId& type_id = GetTypeId(idx);
- return StringDataByIdx(type_id.descriptor_idx_);
+inline const char* DexFile::GetTypeDescriptor(const dex::TypeId& type_id) const {
+ return GetStringData(type_id.descriptor_idx_);
}
-inline const char* DexFile::GetTypeDescriptor(const dex::TypeId& type_id) const {
- return StringDataByIdx(type_id.descriptor_idx_);
+inline const char* DexFile::GetTypeDescriptor(dex::TypeIndex type_idx) const {
+ return GetTypeDescriptor(GetTypeId(type_idx));
}
inline std::string_view DexFile::GetTypeDescriptorView(const dex::TypeId& type_id) const {
- return StringViewByIdx(type_id.descriptor_idx_);
+ return GetStringView(type_id.descriptor_idx_);
+}
+
+inline std::string_view DexFile::GetTypeDescriptorView(dex::TypeIndex type_idx) const {
+ return GetTypeDescriptorView(GetTypeId(type_idx));
}
inline const char* DexFile::GetFieldTypeDescriptor(const dex::FieldId& field_id) const {
@@ -125,11 +111,11 @@ inline std::string_view DexFile::GetFieldTypeDescriptorView(const dex::FieldId&
}
inline const char* DexFile::GetFieldName(const dex::FieldId& field_id) const {
- return StringDataByIdx(field_id.name_idx_);
+ return GetStringData(field_id.name_idx_);
}
inline std::string_view DexFile::GetFieldNameView(const dex::FieldId& field_id) const {
- return StringViewByIdx(field_id.name_idx_);
+ return GetStringView(field_id.name_idx_);
}
inline const char* DexFile::GetMethodDeclaringClassDescriptor(const dex::MethodId& method_id)
@@ -147,25 +133,25 @@ inline const Signature DexFile::GetProtoSignature(const dex::ProtoId& proto_id)
}
inline const char* DexFile::GetMethodName(const dex::MethodId& method_id) const {
- return StringDataByIdx(method_id.name_idx_);
+ return GetStringData(method_id.name_idx_);
}
inline const char* DexFile::GetMethodName(const dex::MethodId& method_id, uint32_t* utf_length)
const {
- return StringDataAndUtf16LengthByIdx(method_id.name_idx_, utf_length);
+ return GetStringDataAndUtf16Length(method_id.name_idx_, utf_length);
}
inline const char* DexFile::GetMethodName(uint32_t idx) const {
- return StringDataByIdx(GetMethodId(idx).name_idx_);
+ return GetStringData(GetMethodId(idx).name_idx_);
}
inline const char* DexFile::GetMethodName(uint32_t idx, uint32_t* utf_length) const {
- return StringDataAndUtf16LengthByIdx(GetMethodId(idx).name_idx_, utf_length);
+ return GetStringDataAndUtf16Length(GetMethodId(idx).name_idx_, utf_length);
}
ALWAYS_INLINE
inline std::string_view DexFile::GetMethodNameView(const dex::MethodId& method_id) const {
- return StringViewByIdx(method_id.name_idx_);
+ return GetStringView(method_id.name_idx_);
}
ALWAYS_INLINE
@@ -182,13 +168,13 @@ inline std::string_view DexFile::GetMethodShortyView(uint32_t idx) const {
}
inline const char* DexFile::GetMethodShorty(const dex::MethodId& method_id) const {
- return StringDataByIdx(GetProtoId(method_id.proto_idx_).shorty_idx_);
+ return GetStringData(GetProtoId(method_id.proto_idx_).shorty_idx_);
}
inline const char* DexFile::GetMethodShorty(const dex::MethodId& method_id, uint32_t* length)
const {
// Using the UTF16 length is safe here as shorties are guaranteed to be ASCII characters.
- return StringDataAndUtf16LengthByIdx(GetProtoId(method_id.proto_idx_).shorty_idx_, length);
+ return GetStringDataAndUtf16Length(GetProtoId(method_id.proto_idx_).shorty_idx_, length);
}
inline std::string_view DexFile::GetMethodShortyView(const dex::MethodId& method_id) const {
@@ -196,16 +182,16 @@ inline std::string_view DexFile::GetMethodShortyView(const dex::MethodId& method
}
inline const char* DexFile::GetClassDescriptor(const dex::ClassDef& class_def) const {
- return StringByTypeIdx(class_def.class_idx_);
+ return GetTypeDescriptor(class_def.class_idx_);
}
inline const char* DexFile::GetReturnTypeDescriptor(const dex::ProtoId& proto_id) const {
- return StringByTypeIdx(proto_id.return_type_idx_);
+ return GetTypeDescriptor(proto_id.return_type_idx_);
}
inline const char* DexFile::GetShorty(dex::ProtoIndex proto_idx) const {
const dex::ProtoId& proto_id = GetProtoId(proto_idx);
- return StringDataByIdx(proto_id.shorty_idx_);
+ return GetStringData(proto_id.shorty_idx_);
}
ALWAYS_INLINE
@@ -216,7 +202,7 @@ inline std::string_view DexFile::GetShortyView(dex::ProtoIndex proto_idx) const
ALWAYS_INLINE
inline std::string_view DexFile::GetShortyView(const dex::ProtoId& proto_id) const {
uint32_t shorty_len;
- const char* shorty_data = StringDataAndUtf16LengthByIdx(proto_id.shorty_idx_, &shorty_len);
+ const char* shorty_data = GetStringDataAndUtf16Length(proto_id.shorty_idx_, &shorty_len);
DCHECK_EQ(shorty_data[shorty_len], '\0'); // For a shorty utf16 length == mutf8 length.
return std::string_view(shorty_data, shorty_len);
}
@@ -231,9 +217,9 @@ inline const dex::TryItem* DexFile::GetTryItems(const DexInstructionIterator& co
inline bool DexFile::StringEquals(const DexFile* df1, dex::StringIndex sidx1,
const DexFile* df2, dex::StringIndex sidx2) {
uint32_t s1_len; // Note: utf16 length != mutf8 length.
- const char* s1_data = df1->StringDataAndUtf16LengthByIdx(sidx1, &s1_len);
+ const char* s1_data = df1->GetStringDataAndUtf16Length(sidx1, &s1_len);
uint32_t s2_len;
- const char* s2_data = df2->StringDataAndUtf16LengthByIdx(sidx2, &s2_len);
+ const char* s2_data = df2->GetStringDataAndUtf16Length(sidx2, &s2_len);
return (s1_len == s2_len) && (strcmp(s1_data, s2_data) == 0);
}
@@ -349,7 +335,7 @@ bool DexFile::DecodeDebugLocalInfo(const uint8_t* stream,
}
local_in_reg[reg].name_ = index_to_string_data(name_idx);
- local_in_reg[reg].descriptor_ = type_index_to_string_data(descriptor_idx);;
+ local_in_reg[reg].descriptor_ = type_index_to_string_data(descriptor_idx);
local_in_reg[reg].signature_ = index_to_string_data(signature_idx);
local_in_reg[reg].start_address_ = address;
local_in_reg[reg].reg_ = reg;
@@ -427,11 +413,12 @@ bool DexFile::DecodeDebugLocalInfo(uint32_t registers_size,
ins_size,
insns_size_in_code_units,
[this](uint32_t idx) {
- return StringDataByIdx(dex::StringIndex(idx));
+ dex::StringIndex string_idx(idx);
+ return string_idx.IsValid() ? GetStringData(string_idx) : nullptr;
},
- [this](uint32_t idx) {
- return StringByTypeIdx(dex::TypeIndex(
- dchecked_integral_cast<uint16_t>(idx)));
+ [this](uint16_t idx) {
+ dex::TypeIndex type_idx(idx);
+ return type_idx.IsValid() ? GetTypeDescriptor(type_idx) : nullptr;
},
new_local_callback);
}
diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc
index 927adddfad..9940cc0458 100644
--- a/libdexfile/dex/dex_file.cc
+++ b/libdexfile/dex/dex_file.cc
@@ -666,7 +666,7 @@ void DexFile::AppendPrettyMethod(uint32_t method_idx,
const MethodId& method_id = GetMethodId(method_idx);
const ProtoId* proto_id = with_signature ? &GetProtoId(method_id.proto_idx_) : nullptr;
if (with_signature) {
- AppendPrettyDescriptor(StringByTypeIdx(proto_id->return_type_idx_), result);
+ AppendPrettyDescriptor(GetTypeDescriptor(proto_id->return_type_idx_), result);
result->push_back(' ');
}
AppendPrettyDescriptor(GetMethodDeclaringClassDescriptor(method_id), result);
@@ -680,7 +680,7 @@ void DexFile::AppendPrettyMethod(uint32_t method_idx,
for (uint32_t i = 0u, size = params->Size(); i != size; ++i) {
result->append(separator);
separator = ", ";
- AppendPrettyDescriptor(StringByTypeIdx(params->GetTypeItem(i).type_idx_), result);
+ AppendPrettyDescriptor(GetTypeDescriptor(params->GetTypeItem(i).type_idx_), result);
}
}
result->push_back(')');
diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h
index ed3bdcd036..5d67c6cca4 100644
--- a/libdexfile/dex/dex_file.h
+++ b/libdexfile/dex/dex_file.h
@@ -340,23 +340,21 @@ class DexFile {
return dex::StringIndex(&string_id - string_ids_);
}
- int32_t GetStringLength(const dex::StringId& string_id) const;
-
// Returns a pointer to the UTF-8 string data referred to by the given string_id as well as the
// length of the string when decoded as a UTF-16 string. Note the UTF-16 length is not the same
// as the string length of the string data.
const char* GetStringDataAndUtf16Length(const dex::StringId& string_id,
uint32_t* utf16_length) const;
+ const char* GetStringDataAndUtf16Length(dex::StringIndex string_idx,
+ uint32_t* utf16_length) const;
+
+ uint32_t GetStringUtf16Length(const dex::StringId& string_id) const;
const char* GetStringData(const dex::StringId& string_id) const;
+ const char* GetStringData(dex::StringIndex string_idx) const;
std::string_view GetStringView(const dex::StringId& string_id) const;
-
- // Index version of GetStringDataAndUtf16Length.
- const char* StringDataAndUtf16LengthByIdx(dex::StringIndex idx, uint32_t* utf16_length) const;
-
- const char* StringDataByIdx(dex::StringIndex idx) const;
- std::string_view StringViewByIdx(dex::StringIndex idx) const;
+ std::string_view GetStringView(dex::StringIndex string_idx) const;
// Looks up a string id for a given modified utf8 string.
const dex::StringId* FindStringId(const char* string) const;
@@ -390,14 +388,11 @@ class DexFile {
return dex::TypeIndex(static_cast<uint16_t>(result));
}
- // Get the descriptor string associated with a given type index.
- const char* StringByTypeIdx(dex::TypeIndex idx, uint32_t* unicode_length) const;
-
- const char* StringByTypeIdx(dex::TypeIndex idx) const;
-
// Returns the type descriptor string of a type id.
const char* GetTypeDescriptor(const dex::TypeId& type_id) const;
+ const char* GetTypeDescriptor(dex::TypeIndex type_idx) const;
std::string_view GetTypeDescriptorView(const dex::TypeId& type_id) const;
+ std::string_view GetTypeDescriptorView(dex::TypeIndex type_idx) const;
// Looks up a type for the given string index
const dex::TypeId* FindTypeId(dex::StringIndex string_idx) const;
@@ -799,7 +794,7 @@ class DexFile {
if (!class_def.source_file_idx_.IsValid()) {
return nullptr;
} else {
- return StringDataByIdx(class_def.source_file_idx_);
+ return GetStringData(class_def.source_file_idx_);
}
}
@@ -1041,7 +1036,7 @@ class DexFileParameterIterator {
return type_list_->GetTypeItem(pos_).type_idx_;
}
const char* GetDescriptor() {
- return dex_file_.StringByTypeIdx(dex::TypeIndex(GetTypeIdx()));
+ return dex_file_.GetTypeDescriptor(dex::TypeIndex(GetTypeIdx()));
}
private:
const DexFile& dex_file_;
diff --git a/libdexfile/dex/dex_file_loader_test.cc b/libdexfile/dex/dex_file_loader_test.cc
index 48e31785a4..3de1103256 100644
--- a/libdexfile/dex/dex_file_loader_test.cc
+++ b/libdexfile/dex/dex_file_loader_test.cc
@@ -608,13 +608,6 @@ TEST_F(DexFileLoaderTest, OpenDexBadMapOffset) {
EXPECT_EQ(raw, nullptr);
}
-TEST_F(DexFileLoaderTest, GetStringWithNoIndex) {
- std::vector<uint8_t> dex_bytes;
- std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kRawDex, kLocationString, &dex_bytes));
- dex::TypeIndex idx;
- EXPECT_EQ(raw->StringByTypeIdx(idx), nullptr);
-}
-
TEST_F(DexFileLoaderTest, OpenDexDebugInfoLocalNullType) {
std::vector<uint8_t> dex_bytes;
std::unique_ptr<const DexFile> raw = OpenDexFileInMemoryBase64(kRawDexDebugInfoLocalNullType,
diff --git a/libdexfile/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc
index ba3472015d..007181b1d7 100644
--- a/libdexfile/dex/dex_file_verifier.cc
+++ b/libdexfile/dex/dex_file_verifier.cc
@@ -481,14 +481,14 @@ bool DexFileVerifier::VerifyTypeDescriptor(dex::TypeIndex idx,
char cached_char = verified_type_descriptors_[idx.index_];
if (cached_char != 0) {
if (!extra_check(cached_char)) {
- const char* descriptor = dex_file_->StringByTypeIdx(idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(idx);
ErrorStringPrintf("%s: '%s'", error_msg, descriptor);
return false;
}
return true;
}
- const char* descriptor = dex_file_->StringByTypeIdx(idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(idx);
if (UNLIKELY(!IsValidDescriptor(descriptor))) {
ErrorStringPrintf("%s: '%s'", error_msg, descriptor);
return false;
@@ -2698,7 +2698,7 @@ bool DexFileVerifier::CheckInterTypeIdItem() {
bool DexFileVerifier::CheckInterProtoIdItem() {
const dex::ProtoId* item = reinterpret_cast<const dex::ProtoId*>(ptr_);
- const char* shorty = dex_file_->StringDataByIdx(item->shorty_idx_);
+ const char* shorty = dex_file_->GetStringData(item->shorty_idx_);
if (item->parameters_off_ != 0 &&
!CheckOffsetToTypeMap(item->parameters_off_, DexFile::kDexTypeTypeList)) {
@@ -2712,7 +2712,7 @@ bool DexFileVerifier::CheckInterProtoIdItem() {
return false;
}
// Check the return type and advance the shorty.
- const char* return_type = dex_file_->StringByTypeIdx(item->return_type_idx_);
+ const char* return_type = dex_file_->GetTypeDescriptor(item->return_type_idx_);
if (!CheckShortyDescriptorMatch(*shorty, return_type, true)) {
return false;
}
@@ -2794,7 +2794,7 @@ bool DexFileVerifier::CheckInterFieldIdItem() {
}
// Check that the name is valid.
- const char* field_name = dex_file_->StringDataByIdx(item->name_idx_);
+ const char* field_name = dex_file_->GetStringData(item->name_idx_);
if (UNLIKELY(!IsValidMemberName(field_name))) {
ErrorStringPrintf("Invalid field name: '%s'", field_name);
return false;
@@ -2834,7 +2834,7 @@ bool DexFileVerifier::CheckInterMethodIdItem() {
}
// Check that the name is valid.
- const char* method_name = dex_file_->StringDataByIdx(item->name_idx_);
+ const char* method_name = dex_file_->GetStringData(item->name_idx_);
if (UNLIKELY(!IsValidMemberName(method_name))) {
ErrorStringPrintf("Invalid method name: '%s'", method_name);
return false;
@@ -2997,7 +2997,7 @@ bool DexFileVerifier::CheckInterClassDefItem() {
for (uint32_t j =0; j < i; j++) {
dex::TypeIndex idx2 = interfaces->GetTypeItem(j).type_idx_;
if (UNLIKELY(idx1 == idx2)) {
- ErrorStringPrintf("Duplicate interface: '%s'", dex_file_->StringByTypeIdx(idx1));
+ ErrorStringPrintf("Duplicate interface: '%s'", dex_file_->GetTypeDescriptor(idx1));
return false;
}
}
diff --git a/libdexfile/dex/dex_instruction.cc b/libdexfile/dex/dex_instruction.cc
index 8b8b6a71cc..c1bc34b602 100644
--- a/libdexfile/dex/dex_instruction.cc
+++ b/libdexfile/dex/dex_instruction.cc
@@ -207,7 +207,7 @@ std::string Instruction::DumpString(const DexFile* file) const {
os << StringPrintf(
"const-string v%d, %s // string@%d",
VRegA_21c(),
- PrintableString(file->StringDataByIdx(dex::StringIndex(string_idx))).c_str(),
+ PrintableString(file->GetStringData(dex::StringIndex(string_idx))).c_str(),
string_idx);
} else {
os << StringPrintf("const-string v%d, <<invalid-string-idx-%d>> // string@%d",
@@ -333,7 +333,7 @@ std::string Instruction::DumpString(const DexFile* file) const {
"%s v%d, %s // string@%d",
opcode,
VRegA_31c(),
- PrintableString(file->StringDataByIdx(dex::StringIndex(string_idx))).c_str(),
+ PrintableString(file->GetStringData(dex::StringIndex(string_idx))).c_str(),
string_idx);
} else {
os << StringPrintf("%s v%d, <<invalid-string-idx-%d>> // string@%d",
diff --git a/libdexfile/dex/method_reference.h b/libdexfile/dex/method_reference.h
index 9d4eabef2a..0472f2d492 100644
--- a/libdexfile/dex/method_reference.h
+++ b/libdexfile/dex/method_reference.h
@@ -56,8 +56,11 @@ struct MethodReferenceValueComparator {
// Compare the class descriptors first.
const dex::MethodId& mid1 = mr1.GetMethodId();
const dex::MethodId& mid2 = mr2.GetMethodId();
- int descriptor_diff = strcmp(mr1.dex_file->StringByTypeIdx(mid1.class_idx_),
- mr2.dex_file->StringByTypeIdx(mid2.class_idx_));
+ // Note: `std::string_view::compare()` uses lexicographical comparison and treats the `char`
+ // as unsigned; for Modified-UTF-8 without embedded nulls this is consistent with the
+ // `CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues()` ordering.
+ int descriptor_diff = mr1.dex_file->GetTypeDescriptorView(mid1.class_idx_).compare(
+ mr2.dex_file->GetTypeDescriptorView(mid2.class_idx_));
if (descriptor_diff != 0) {
return descriptor_diff < 0;
}
diff --git a/libdexfile/dex/signature.cc b/libdexfile/dex/signature.cc
index ac004286f2..1ab232dabf 100644
--- a/libdexfile/dex/signature.cc
+++ b/libdexfile/dex/signature.cc
@@ -39,11 +39,11 @@ std::string Signature::ToString() const {
} else {
result += "(";
for (uint32_t i = 0; i < params->Size(); ++i) {
- result += dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_);
+ result += dex_file_->GetTypeDescriptorView(params->GetTypeItem(i).type_idx_);
}
result += ")";
}
- result += dex_file_->StringByTypeIdx(proto_id_->return_type_idx_);
+ result += dex_file_->GetTypeDescriptorView(proto_id_->return_type_idx_);
return result;
}
@@ -69,7 +69,7 @@ bool Signature::operator==(std::string_view rhs) const {
const TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
if (params != nullptr) {
for (uint32_t i = 0; i < params->Size(); ++i) {
- std::string_view param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_));
+ std::string_view param = dex_file_->GetTypeDescriptorView(params->GetTypeItem(i).type_idx_);
if (!StartsWith(tail, param)) {
return false;
}
@@ -80,7 +80,7 @@ bool Signature::operator==(std::string_view rhs) const {
return false;
}
tail.remove_prefix(1); // ")";
- return tail == dex_file_->StringByTypeIdx(proto_id_->return_type_idx_);
+ return tail == dex_file_->GetTypeDescriptorView(proto_id_->return_type_idx_);
}
std::ostream& operator<<(std::ostream& os, const Signature& sig) {
diff --git a/libprofile/profile/profile_compilation_info.cc b/libprofile/profile/profile_compilation_info.cc
index e6c1619217..21dc675e54 100644
--- a/libprofile/profile/profile_compilation_info.cc
+++ b/libprofile/profile/profile_compilation_info.cc
@@ -694,7 +694,7 @@ dex::TypeIndex ProfileCompilationInfo::FindOrCreateTypeIndex(const DexFile& dex_
return class_ref.TypeIndex();
}
// Try to find a `TypeId` in the method's dex file.
- const char* descriptor = class_ref.dex_file->StringByTypeIdx(class_ref.TypeIndex());
+ const char* descriptor = class_ref.dex_file->GetTypeDescriptor(class_ref.TypeIndex());
return FindOrCreateTypeIndex(dex_file, descriptor);
}
diff --git a/libprofile/profile/profile_compilation_info.h b/libprofile/profile/profile_compilation_info.h
index 2da33a0c02..745b9a2401 100644
--- a/libprofile/profile/profile_compilation_info.h
+++ b/libprofile/profile/profile_compilation_info.h
@@ -684,7 +684,7 @@ class ProfileCompilationInfo {
DCHECK(type_index.IsValid());
uint32_t num_type_ids = dex_file->NumTypeIds();
if (type_index.index_ < num_type_ids) {
- return dex_file->StringByTypeIdx(type_index);
+ return dex_file->GetTypeDescriptor(type_index);
} else {
return extra_descriptors_[type_index.index_ - num_type_ids].c_str();
}
diff --git a/libprofile/profile/profile_test_helper.h b/libprofile/profile/profile_test_helper.h
index 1140ee7bbe..fdb062b744 100644
--- a/libprofile/profile/profile_test_helper.h
+++ b/libprofile/profile/profile_test_helper.h
@@ -134,7 +134,7 @@ class ProfileTestHelper {
return type_index == type_ref.TypeIndex();
} else {
const char* expected_descriptor =
- type_ref.dex_file->StringByTypeIdx(type_ref.TypeIndex());
+ type_ref.dex_file->GetTypeDescriptor(type_ref.TypeIndex());
const char* descriptor = info.GetTypeDescriptor(dex_file, type_index);
return strcmp(expected_descriptor, descriptor) == 0;
}
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index b597494e04..0c362d9c1a 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1772,7 +1772,7 @@ class OatDumper {
string_bss_mapping,
dex_file->NumStringIds(),
sizeof(GcRoot<mirror::Class>),
- [=](uint32_t index) { return dex_file->StringDataByIdx(dex::StringIndex(index)); });
+ [=](uint32_t index) { return dex_file->GetStringData(dex::StringIndex(index)); });
}
void DumpBssOffsets(std::ostream& os, const char* slot_type, const IndexBssMapping* mapping) {
diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc
index 9be55e54e9..3282432cee 100644
--- a/openjdkjvmti/ti_redefine.cc
+++ b/openjdkjvmti/ti_redefine.cc
@@ -1091,7 +1091,7 @@ bool Redefiner::ClassRedefinition::CheckClass() {
// Check class name.
// These should have been checked by the dexfile verifier on load.
DCHECK_NE(def.class_idx_, art::dex::TypeIndex::Invalid()) << "Invalid type index";
- const char* descriptor = dex_file_->StringByTypeIdx(def.class_idx_);
+ const char* descriptor = dex_file_->GetTypeDescriptor(def.class_idx_);
DCHECK(descriptor != nullptr) << "Invalid dex file structure!";
if (!current_class->DescriptorEquals(descriptor)) {
std::string storage;
@@ -1107,7 +1107,7 @@ bool Redefiner::ClassRedefinition::CheckClass() {
return false;
}
} else {
- const char* super_descriptor = dex_file_->StringByTypeIdx(def.superclass_idx_);
+ const char* super_descriptor = dex_file_->GetTypeDescriptor(def.superclass_idx_);
DCHECK(descriptor != nullptr) << "Invalid dex file structure!";
if (!current_class->GetSuperClass()->DescriptorEquals(super_descriptor)) {
RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED), "Superclass changed");
@@ -1133,8 +1133,8 @@ bool Redefiner::ClassRedefinition::CheckClass() {
const art::DexFile& orig_dex_file = current_class->GetDexFile();
for (uint32_t i = 0; i < interfaces->Size(); i++) {
if (strcmp(
- dex_file_->StringByTypeIdx(interfaces->GetTypeItem(i).type_idx_),
- orig_dex_file.StringByTypeIdx(current_interfaces->GetTypeItem(i).type_idx_)) != 0) {
+ dex_file_->GetTypeDescriptor(interfaces->GetTypeItem(i).type_idx_),
+ orig_dex_file.GetTypeDescriptor(current_interfaces->GetTypeItem(i).type_idx_)) != 0) {
RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED),
"Interfaces changed or re-ordered");
return false;
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index d31df20c1c..2a8dc84a85 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -399,7 +399,8 @@ class ProfileAssistantTest : public CommonRuntimeTest, public ProfileTestHelper
}
} else {
// Match by descriptor.
- const char* expected_descriptor = type_ref.dex_file->StringByTypeIdx(type_ref.TypeIndex());
+ const char* expected_descriptor =
+ type_ref.dex_file->GetTypeDescriptor(type_ref.TypeIndex());
for (dex::TypeIndex type_index : dex_pc_data.classes) {
ASSERT_TRUE(type_index.IsValid());
const char* descriptor = info.GetTypeDescriptor(dex_file, type_index);
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index e957d6a1c2..024272a10d 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -451,7 +451,7 @@ inline bool ArtMethod::NameEquals(ObjPtr<mirror::String> name) {
const dex::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
const dex::StringIndex name_idx = method_id.name_idx_;
uint32_t utf16_length;
- const char* utf8_name = dex_file->StringDataAndUtf16LengthByIdx(name_idx, &utf16_length);
+ const char* utf8_name = dex_file->GetStringDataAndUtf16Length(name_idx, &utf16_length);
return dchecked_integral_cast<uint32_t>(name->GetLength()) == utf16_length &&
name->Equals(utf8_name);
}
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 8ad4b63dc7..c8b16990b2 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -302,7 +302,7 @@ uint32_t ArtMethod::FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfil
if (dexfile == &other_dexfile) {
return dex_method_idx;
}
- const char* mid_declaring_class_descriptor = dexfile->StringByTypeIdx(mid.class_idx_);
+ const char* mid_declaring_class_descriptor = dexfile->GetTypeDescriptor(mid.class_idx_);
const dex::TypeId* other_type_id = other_dexfile.FindTypeId(mid_declaring_class_descriptor);
if (other_type_id != nullptr) {
const dex::MethodId* other_mid = other_dexfile.FindMethodId(
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index e771341d5a..6951e35791 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -418,7 +418,7 @@ inline ArtMethod* ClassLinker::ResolveMethod(uint32_t method_idx,
ThrowIncompatibleClassChangeError(type, resolved->GetInvokeType(), resolved, referrer);
} else {
// We failed to find the method (using all lookup types), so throw a NoSuchMethodError.
- const char* name = dex_file.StringDataByIdx(method_id.name_idx_);
+ const char* name = dex_file.GetStringData(method_id.name_idx_);
const Signature signature = dex_file.GetMethodSignature(method_id);
ThrowNoSuchMethodError(type, klass, name, signature);
}
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index ac9dda637a..d7c0582e7b 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -3363,7 +3363,7 @@ ObjPtr<mirror::Class> ClassLinker::FindClass(Thread* self,
// capable class loaders. (All class loaders are considered parallel capable on Android.)
ObjPtr<mirror::Class> loader_class = class_loader->GetClass();
const char* loader_class_name =
- loader_class->GetDexFile().StringByTypeIdx(loader_class->GetDexTypeIndex());
+ loader_class->GetDexFile().GetTypeDescriptor(loader_class->GetDexTypeIndex());
LOG(WARNING) << "Initiating class loader of type " << DescriptorToDot(loader_class_name)
<< " is not well-behaved; it returned a different Class for racing loadClass(\""
<< DescriptorToDot(descriptor) << "\").";
@@ -4082,8 +4082,8 @@ void ClassLinker::LoadMethod(const DexFile& dex_file,
const uint32_t dex_method_idx = method.GetIndex();
const dex::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
uint32_t name_utf16_length;
- const char* method_name = dex_file.StringDataAndUtf16LengthByIdx(method_id.name_idx_,
- &name_utf16_length);
+ const char* method_name = dex_file.GetStringDataAndUtf16Length(method_id.name_idx_,
+ &name_utf16_length);
std::string_view shorty = dex_file.GetShortyView(dex_file.GetProtoId(method_id.proto_idx_));
dst->SetDexMethodIndex(dex_method_idx);
@@ -6595,7 +6595,7 @@ class MethodNameAndSignatureComparator final : public ValueObject {
ALWAYS_INLINE std::string_view GetNameView() {
if (name_view_.empty()) {
- name_view_ = dex_file_->StringViewByIdx(mid_->name_idx_);
+ name_view_ = dex_file_->GetStringView(mid_->name_idx_);
}
return name_view_;
}
@@ -6608,7 +6608,7 @@ class MethodNameAndSignatureComparator final : public ValueObject {
if (dex_file_ == other_dex_file) {
return mid_->name_idx_ == other_mid.name_idx_ && mid_->proto_idx_ == other_mid.proto_idx_;
}
- return GetNameView() == other_dex_file->StringViewByIdx(other_mid.name_idx_) &&
+ return GetNameView() == other_dex_file->GetStringView(other_mid.name_idx_) &&
dex_file_->GetMethodSignature(*mid_) == other_dex_file->GetMethodSignature(other_mid);
}
@@ -7310,7 +7310,7 @@ void CheckVTableHasNoDuplicates(Thread* self, Handle<mirror::Class> klass)
// This call writes `name_len` and it is therefore necessary that the
// initializer for `name_len` comes before it, otherwise the value
// from the call would be overwritten by that initializer.
- name(dex_file->StringDataAndUtf16LengthByIdx(mid.name_idx_, &name_len)),
+ name(dex_file->GetStringDataAndUtf16Length(mid.name_idx_, &name_len)),
signature(dex_file->GetMethodSignature(mid)) {
// The `name_len` has been initialized to the UTF16 length. Calculate length in bytes.
if (name[name_len] != 0) {
@@ -9896,7 +9896,7 @@ ObjPtr<mirror::String> ClassLinker::DoResolveString(dex::StringIndex string_idx,
Handle<mirror::DexCache> dex_cache) {
const DexFile& dex_file = *dex_cache->GetDexFile();
uint32_t utf16_length;
- const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length);
+ const char* utf8_data = dex_file.GetStringDataAndUtf16Length(string_idx, &utf16_length);
ObjPtr<mirror::String> string = intern_table_->InternStrong(utf16_length, utf8_data);
if (string != nullptr) {
dex_cache->SetResolvedString(string_idx, string);
@@ -9909,7 +9909,7 @@ ObjPtr<mirror::String> ClassLinker::DoLookupString(dex::StringIndex string_idx,
DCHECK(dex_cache != nullptr);
const DexFile& dex_file = *dex_cache->GetDexFile();
uint32_t utf16_length;
- const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length);
+ const char* utf8_data = dex_file.GetStringDataAndUtf16Length(string_idx, &utf16_length);
ObjPtr<mirror::String> string =
intern_table_->LookupStrong(Thread::Current(), utf16_length, utf8_data);
if (string != nullptr) {
@@ -9928,7 +9928,7 @@ ObjPtr<mirror::Class> ClassLinker::DoLookupResolvedType(dex::TypeIndex type_idx,
ObjPtr<mirror::ClassLoader> class_loader) {
DCHECK(dex_cache->GetClassLoader() == class_loader);
const DexFile& dex_file = *dex_cache->GetDexFile();
- const char* descriptor = dex_file.StringByTypeIdx(type_idx);
+ const char* descriptor = dex_file.GetTypeDescriptor(type_idx);
ObjPtr<mirror::Class> type = LookupResolvedType(descriptor, class_loader);
if (type != nullptr) {
DCHECK(type->IsResolved());
@@ -9976,7 +9976,7 @@ ObjPtr<mirror::Class> ClassLinker::DoResolveType(dex::TypeIndex type_idx,
Handle<mirror::ClassLoader> class_loader) {
DCHECK(dex_cache->GetClassLoader() == class_loader.Get());
Thread* self = Thread::Current();
- const char* descriptor = dex_cache->GetDexFile()->StringByTypeIdx(type_idx);
+ const char* descriptor = dex_cache->GetDexFile()->GetTypeDescriptor(type_idx);
ObjPtr<mirror::Class> resolved = FindClass(self, descriptor, class_loader);
if (resolved != nullptr) {
// TODO: we used to throw here if resolved's class loader was not the
diff --git a/runtime/dex/dex_file_annotations.cc b/runtime/dex/dex_file_annotations.cc
index 8488993ae4..3d334e70fd 100644
--- a/runtime/dex/dex_file_annotations.cc
+++ b/runtime/dex/dex_file_annotations.cc
@@ -193,7 +193,7 @@ const AnnotationItem* SearchAnnotationSet(const DexFile& dex_file,
const uint8_t* annotation = annotation_item->annotation_;
uint32_t type_index = DecodeUnsignedLeb128(&annotation);
- if (strcmp(descriptor, dex_file.StringByTypeIdx(dex::TypeIndex(type_index))) == 0) {
+ if (strcmp(descriptor, dex_file.GetTypeDescriptor(dex::TypeIndex(type_index))) == 0) {
result = annotation_item;
break;
}
@@ -495,7 +495,7 @@ bool ProcessAnnotationValue(const ClassData& klass,
if (element_object == nullptr) {
CHECK(self->IsExceptionPending());
if (result_style == DexFile::kAllObjects) {
- const char* msg = dex_file.StringByTypeIdx(type_index);
+ const char* msg = dex_file.GetTypeDescriptor(type_index);
self->ThrowNewWrappedException("Ljava/lang/TypeNotPresentException;", msg);
element_object = self->GetException();
self->ClearException();
@@ -701,7 +701,7 @@ ObjPtr<mirror::Object> CreateAnnotationMember(const ClassData& klass,
ScopedObjectAccessUnchecked soa(self);
StackHandleScope<5> hs(self);
uint32_t element_name_index = DecodeUnsignedLeb128(annotation);
- const char* name = dex_file.StringDataByIdx(dex::StringIndex(element_name_index));
+ const char* name = dex_file.GetStringData(dex::StringIndex(element_name_index));
PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
ArtMethod* annotation_method =
@@ -1286,7 +1286,7 @@ static bool IsMethodBuildAnnotationPresent(const DexFile& dex_file,
}
const uint8_t* annotation = annotation_item->annotation_;
uint32_t type_index = DecodeUnsignedLeb128(&annotation);
- const char* descriptor = dex_file.StringByTypeIdx(dex::TypeIndex(type_index));
+ const char* descriptor = dex_file.GetTypeDescriptor(dex::TypeIndex(type_index));
if (strcmp(descriptor, annotation_descriptor) == 0) {
DCheckNativeAnnotation(descriptor, annotation_class);
return true;
@@ -1754,7 +1754,7 @@ const char* GetSourceDebugExtension(Handle<mirror::Class> klass) {
return nullptr;
}
dex::StringIndex index(static_cast<uint32_t>(annotation_value.value_.GetI()));
- return data.GetDexFile().StringDataByIdx(index);
+ return data.GetDexFile().GetStringData(index);
}
ObjPtr<mirror::Class> GetNestHost(Handle<mirror::Class> klass) {
@@ -1994,7 +1994,7 @@ void VisitClassAnnotations(Handle<mirror::Class> klass, AnnotationVisitor* visit
uint8_t visibility = annotation_item->visibility_;
const uint8_t* annotation = annotation_item->annotation_;
uint32_t type_index = DecodeUnsignedLeb128(&annotation);
- const char* annotation_descriptor = dex_file.StringByTypeIdx(dex::TypeIndex(type_index));
+ const char* annotation_descriptor = dex_file.GetTypeDescriptor(dex::TypeIndex(type_index));
VisitorStatus status = visitor->VisitAnnotation(annotation_descriptor, visibility);
switch (status) {
case VisitorStatus::kVisitBreak:
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index 6cda30ee9d..b0d0ab4b07 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -485,15 +485,14 @@ EXPLICIT_FIND_FIELD_FROM_CODE_TEMPLATE_DECL(StaticPrimitiveWrite);
static inline bool IsStringInit(const DexFile* dex_file, uint32_t method_idx)
REQUIRES_SHARED(Locks::mutator_lock_) {
const dex::MethodId& method_id = dex_file->GetMethodId(method_idx);
- const char* class_name = dex_file->StringByTypeIdx(method_id.class_idx_);
- const char* method_name = dex_file->GetMethodName(method_id);
+ const std::string_view class_name = dex_file->GetTypeDescriptorView(method_id.class_idx_);
+ const std::string_view method_name = dex_file->GetMethodNameView(method_id);
// Instead of calling ResolveMethod() which has suspend point and can trigger
// GC, look up the method symbolically.
// Compare method's class name and method name against string init.
// It's ok since it's not allowed to create your own java/lang/String.
// TODO: verify that assumption.
- if ((strcmp(class_name, "Ljava/lang/String;") == 0) &&
- (strcmp(method_name, "<init>") == 0)) {
+ if (class_name == "Ljava/lang/String;" && method_name == "<init>") {
return true;
}
return false;
diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc
index 3acf5c8050..942d2923fc 100644
--- a/runtime/jit/profile_saver.cc
+++ b/runtime/jit/profile_saver.cc
@@ -660,7 +660,7 @@ void ProfileSaver::GetClassesAndMethodsHelper::UpdateProfile(const std::set<std:
DCHECK(ShouldCollectClasses(startup));
DCHECK(class_record.methods == nullptr); // No methods to process.
array_class_descriptor.assign(class_record.array_dimension, '[');
- array_class_descriptor += dex_file->StringByTypeIdx(class_record.type_index);
+ array_class_descriptor += dex_file->GetTypeDescriptorView(class_record.type_index);
dex::TypeIndex type_index =
profile_info->FindOrCreateTypeIndex(*dex_file, array_class_descriptor.c_str());
if (type_index.IsValid()) {
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index 7811302a13..828ab968a3 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -573,7 +573,7 @@ ArtMethod* Class::FindInterfaceMethod(ObjPtr<DexCache> dex_cache,
// We always search by name and signature, ignoring the type index in the MethodId.
const DexFile& dex_file = *dex_cache->GetDexFile();
const dex::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
- std::string_view name = dex_file.StringViewByIdx(method_id.name_idx_);
+ std::string_view name = dex_file.GetStringView(method_id.name_idx_);
const Signature signature = dex_file.GetMethodSignature(method_id);
return FindInterfaceMethod(name, signature, pointer_size);
}
@@ -913,7 +913,7 @@ ArtMethod* Class::FindClassMethod(ObjPtr<DexCache> dex_cache,
for (klass = this; klass != end_klass; klass = klass->GetSuperClass()) {
ArraySlice<ArtMethod> copied_methods = klass->GetCopiedMethodsSlice(pointer_size);
if (!copied_methods.empty() && name.empty()) {
- name = dex_file.StringDataByIdx(method_id.name_idx_);
+ name = dex_file.GetMethodNameView(method_id);
}
for (ArtMethod& method : copied_methods) {
if (method.GetNameView() == name && method.GetSignature() == signature) {
@@ -1043,9 +1043,9 @@ static std::tuple<bool, ArtField*> FindFieldByNameAndType(const DexFile& dex_fil
// Fields are sorted by class, then name, then type descriptor. This is verified in dex file
// verifier. There can be multiple fields with the same name in the same class due to proguard.
- // Note: std::string_view::compare() uses lexicographical comparison and treats the `char` as
- // unsigned; for Modified-UTF-8 without embedded nulls this is consistent with the
- // CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues() ordering.
+ // Note: `std::string_view::compare()` uses lexicographical comparison and treats the `char`
+ // as unsigned; for Modified-UTF-8 without embedded nulls this is consistent with the
+ // `CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues()` ordering.
auto get_field_id = [&](uint32_t mid) REQUIRES_SHARED(Locks::mutator_lock_) ALWAYS_INLINE
-> const dex::FieldId& {
ArtField& field = fields->At(mid);
diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc
index 3f3b648ecf..e9b7545926 100644
--- a/runtime/native/java_lang_reflect_Executable.cc
+++ b/runtime/native/java_lang_reflect_Executable.cc
@@ -278,18 +278,15 @@ static jint Executable_compareMethodParametersInternal(JNIEnv* env,
}
for (int32_t i = 0; i < this_size; ++i) {
- const dex::TypeId& lhs = this_method->GetDexFile()->GetTypeId(
+ const std::string_view lhs_data = this_method->GetDexFile()->GetTypeDescriptorView(
this_list->GetTypeItem(i).type_idx_);
- const dex::TypeId& rhs = other_method->GetDexFile()->GetTypeId(
+ const std::string_view rhs_data = other_method->GetDexFile()->GetTypeDescriptorView(
other_list->GetTypeItem(i).type_idx_);
- uint32_t lhs_len, rhs_len;
- const char* lhs_data = this_method->GetDexFile()->StringDataAndUtf16LengthByIdx(
- lhs.descriptor_idx_, &lhs_len);
- const char* rhs_data = other_method->GetDexFile()->StringDataAndUtf16LengthByIdx(
- rhs.descriptor_idx_, &rhs_len);
-
- int cmp = strcmp(lhs_data, rhs_data);
+ // Note: `std::string_view::compare()` uses lexicographical comparison and treats the `char`
+ // as unsigned; for Modified-UTF-8 without embedded nulls this is consistent with the
+ // `CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues()` ordering.
+ int cmp = lhs_data.compare(rhs_data);
if (cmp != 0) {
return (cmp < 0) ? -1 : 1;
}
diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc
index b67786c2a7..6702970c68 100644
--- a/runtime/vdex_file.cc
+++ b/runtime/vdex_file.cc
@@ -410,7 +410,7 @@ static const char* GetStringFromId(const DexFile& dex_file,
const uint8_t* verifier_deps) {
uint32_t num_ids_in_dex = dex_file.NumStringIds();
if (string_id.index_ < num_ids_in_dex) {
- return dex_file.StringDataByIdx(string_id);
+ return dex_file.GetStringData(string_id);
} else {
CHECK_LT(string_id.index_ - num_ids_in_dex, number_of_extra_strings);
uint32_t offset = extra_strings_offsets[string_id.index_ - num_ids_in_dex];
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 8de83f4dd6..aca2b477fc 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -851,9 +851,9 @@ bool MethodVerifier<kVerifierDebug>::Verify() {
// Some older code doesn't correctly mark constructors as such. Test for this case by looking at
// the name.
const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
- const char* method_name = dex_file_->StringDataByIdx(method_id.name_idx_);
- bool instance_constructor_by_name = strcmp("<init>", method_name) == 0;
- bool static_constructor_by_name = strcmp("<clinit>", method_name) == 0;
+ const std::string_view method_name = dex_file_->GetStringView(method_id.name_idx_);
+ bool instance_constructor_by_name = method_name == "<init>";
+ bool static_constructor_by_name = method_name == "<clinit>";
bool constructor_by_name = instance_constructor_by_name || static_constructor_by_name;
// Check that only constructors are tagged, and check for bad code that doesn't tag constructors.
if ((method_access_flags_ & kAccConstructor) != 0) {
@@ -1286,11 +1286,11 @@ inline bool MethodVerifier<kVerifierDebug>::CheckNewInstance(dex::TypeIndex idx)
return false;
}
// We don't need the actual class, just a pointer to the class name.
- const char* descriptor = dex_file_->StringByTypeIdx(idx);
+ const std::string_view descriptor = dex_file_->GetTypeDescriptorView(idx);
if (UNLIKELY(descriptor[0] != 'L')) {
Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "can't call new-instance on type '" << descriptor << "'";
return false;
- } else if (UNLIKELY(strcmp(descriptor, "Ljava/lang/Class;") == 0)) {
+ } else if (UNLIKELY(descriptor == "Ljava/lang/Class;")) {
// An unlikely new instance on Class is not allowed. Fall back to interpreter to ensure an
// exception is thrown when this statement is executed (compiled code would not do that).
Fail(VERIFY_ERROR_INSTANTIATION);
@@ -1306,7 +1306,7 @@ bool MethodVerifier<kVerifierDebug>::CheckNewArray(dex::TypeIndex idx) {
return false;
}
int bracket_count = 0;
- const char* descriptor = dex_file_->StringByTypeIdx(idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(idx);
const char* cp = descriptor;
while (*cp++ == '[') {
bracket_count++;
@@ -2372,7 +2372,7 @@ bool MethodVerifier<kVerifierDebug>::CodeFlowVerifyInstruction(uint32_t* start_g
type_idx, dex_cache_.Get(), class_loader_.Get());
if (klass != nullptr && klass->IsPrimitive()) {
Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "using primitive type "
- << dex_file_->StringByTypeIdx(type_idx) << " in instanceof in "
+ << dex_file_->GetTypeDescriptorView(type_idx) << " in instanceof in "
<< GetDeclaringClass();
break;
}
@@ -2877,7 +2877,7 @@ bool MethodVerifier<kVerifierDebug>::CodeFlowVerifyInstruction(uint32_t* start_g
const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx);
dex::TypeIndex return_type_idx =
dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_;
- const char* descriptor = dex_file_->StringByTypeIdx(return_type_idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(return_type_idx);
return_type = &reg_types_.FromDescriptor(class_loader_.Get(), descriptor, false);
}
if (!return_type->IsLowHalf()) {
@@ -2898,10 +2898,10 @@ bool MethodVerifier<kVerifierDebug>::CodeFlowVerifyInstruction(uint32_t* start_g
if (called_method == nullptr) {
uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx);
- is_constructor = strcmp("<init>", dex_file_->StringDataByIdx(method_id.name_idx_)) == 0;
+ is_constructor = dex_file_->GetStringView(method_id.name_idx_) == "<init>";
dex::TypeIndex return_type_idx =
dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_;
- return_type_descriptor = dex_file_->StringByTypeIdx(return_type_idx);
+ return_type_descriptor = dex_file_->GetTypeDescriptor(return_type_idx);
} else {
is_constructor = called_method->IsConstructor();
return_type_descriptor = called_method->GetReturnTypeDescriptor();
@@ -2980,7 +2980,7 @@ bool MethodVerifier<kVerifierDebug>::CodeFlowVerifyInstruction(uint32_t* start_g
const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx);
dex::TypeIndex return_type_idx =
dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_;
- descriptor = dex_file_->StringByTypeIdx(return_type_idx);
+ descriptor = dex_file_->GetTypeDescriptor(return_type_idx);
} else {
descriptor = called_method->GetReturnTypeDescriptor();
}
@@ -3037,7 +3037,7 @@ bool MethodVerifier<kVerifierDebug>::CodeFlowVerifyInstruction(uint32_t* start_g
const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx);
dex::TypeIndex return_type_idx =
dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_;
- descriptor = dex_file_->StringByTypeIdx(return_type_idx);
+ descriptor = dex_file_->GetTypeDescriptor(return_type_idx);
} else {
descriptor = abs_method->GetReturnTypeDescriptor();
}
@@ -3607,22 +3607,22 @@ const RegType& MethodVerifier<kVerifierDebug>::ResolveClass(dex::TypeIndex class
if (klass != nullptr) {
bool precise = klass->CannotBeAssignedFromOtherTypes();
if (precise && !IsInstantiableOrPrimitive(klass)) {
- const char* descriptor = dex_file_->StringByTypeIdx(class_idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(class_idx);
UninstantiableError(descriptor);
precise = false;
}
result = reg_types_.FindClass(klass, precise);
if (result == nullptr) {
- const char* descriptor = dex_file_->StringByTypeIdx(class_idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(class_idx);
result = reg_types_.InsertClass(descriptor, klass, precise);
}
} else {
- const char* descriptor = dex_file_->StringByTypeIdx(class_idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(class_idx);
result = &reg_types_.FromDescriptor(class_loader_.Get(), descriptor, false);
}
DCHECK(result != nullptr);
if (result->IsConflict()) {
- const char* descriptor = dex_file_->StringByTypeIdx(class_idx);
+ const char* descriptor = dex_file_->GetTypeDescriptor(class_idx);
Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "accessing broken descriptor '" << descriptor
<< "' in " << GetDeclaringClass();
return *result;
@@ -3943,7 +3943,7 @@ ArtMethod* MethodVerifier<kVerifierDebug>::VerifyInvocationArgsFromIterator(
const dex::TypeIndex class_idx = dex_file_->GetMethodId(method_idx).class_idx_;
res_method_class = &reg_types_.FromDescriptor(
class_loader_.Get(),
- dex_file_->StringByTypeIdx(class_idx),
+ dex_file_->GetTypeDescriptor(class_idx),
false);
}
if (!res_method_class->IsAssignableFrom(adjusted_type, this)) {
@@ -4141,7 +4141,7 @@ ArtMethod* MethodVerifier<kVerifierDebug>::VerifyInvocationArgs(
dex::TypeIndex class_idx = dex_file_->GetMethodId(method_idx).class_idx_;
const RegType& reference_type = reg_types_.FromDescriptor(
class_loader_.Get(),
- dex_file_->StringByTypeIdx(class_idx),
+ dex_file_->GetTypeDescriptor(class_idx),
false);
if (reference_type.IsUnresolvedTypes()) {
// We cannot differentiate on whether this is a class change error or just
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
index ffd5206cbe..e09e007d93 100644
--- a/runtime/verifier/verifier_deps.cc
+++ b/runtime/verifier/verifier_deps.cc
@@ -176,7 +176,7 @@ std::string VerifierDeps::GetStringFromId(const DexFile& dex_file,
dex::StringIndex string_id) const {
uint32_t num_ids_in_dex = dex_file.NumStringIds();
if (string_id.index_ < num_ids_in_dex) {
- return std::string(dex_file.StringDataByIdx(string_id));
+ return std::string(dex_file.GetStringView(string_id));
} else {
const DexFileDeps* deps = GetDexFileDeps(dex_file);
DCHECK(deps != nullptr);
diff --git a/tools/dexanalyze/dexanalyze_experiments.cc b/tools/dexanalyze/dexanalyze_experiments.cc
index 384ab374cd..62098783f0 100644
--- a/tools/dexanalyze/dexanalyze_experiments.cc
+++ b/tools/dexanalyze/dexanalyze_experiments.cc
@@ -217,13 +217,13 @@ void CountDexIndices::ProcessDexFiles(
for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
for (size_t i = 0; i < dex_file->NumTypeIds(); ++i) {
unique_type_names.insert(
- dex_file->StringDataByIdx(dex_file->GetTypeId(dex::TypeIndex(i)).descriptor_idx_));
+ dex_file->GetStringData(dex_file->GetTypeId(dex::TypeIndex(i)).descriptor_idx_));
}
for (size_t i = 0; i < dex_file->NumFieldIds(); ++i) {
- unique_field_names.insert(dex_file->StringDataByIdx(dex_file->GetFieldId(i).name_idx_));
+ unique_field_names.insert(dex_file->GetStringData(dex_file->GetFieldId(i).name_idx_));
}
for (size_t i = 0; i < dex_file->NumMethodIds(); ++i) {
- unique_method_names.insert(dex_file->StringDataByIdx(dex_file->GetMethodId(i).name_idx_));
+ unique_method_names.insert(dex_file->GetStringData(dex_file->GetMethodId(i).name_idx_));
}
ProcessDexFile(*dex_file);
}
diff --git a/tools/dexanalyze/dexanalyze_strings.cc b/tools/dexanalyze/dexanalyze_strings.cc
index dcadb59e35..155240a0d5 100644
--- a/tools/dexanalyze/dexanalyze_strings.cc
+++ b/tools/dexanalyze/dexanalyze_strings.cc
@@ -425,7 +425,7 @@ void AnalyzeStrings::ProcessDexFiles(const std::vector<std::unique_ptr<const Dex
for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
for (size_t i = 0; i < dex_file->NumStringIds(); ++i) {
uint32_t length = 0;
- const char* data = dex_file->StringDataAndUtf16LengthByIdx(dex::StringIndex(i), &length);
+ const char* data = dex_file->GetStringDataAndUtf16Length(dex::StringIndex(i), &length);
// Analyze if the string has any UTF16 chars.
bool have_wide_char = false;
const char* ptr = data;
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index a1fea05f82..85be3ed555 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -133,14 +133,14 @@ class DexClass : public ClassAccessor {
bool HasSuperclass() const { return dex_file_.IsTypeIndexValid(GetSuperclassIndex()); }
std::string_view GetSuperclassDescriptor() const {
- return HasSuperclass() ? dex_file_.StringByTypeIdx(GetSuperclassIndex()) : "";
+ return HasSuperclass() ? dex_file_.GetTypeDescriptorView(GetSuperclassIndex()) : "";
}
std::set<std::string_view> GetInterfaceDescriptors() const {
std::set<std::string_view> list;
const dex::TypeList* ifaces = dex_file_.GetInterfacesList(GetClassDef());
for (uint32_t i = 0; ifaces != nullptr && i < ifaces->Size(); ++i) {
- list.insert(dex_file_.StringByTypeIdx(ifaces->GetTypeItem(i).type_idx_));
+ list.insert(dex_file_.GetTypeDescriptorView(ifaces->GetTypeItem(i).type_idx_));
}
return list;
}
diff --git a/tools/veridex/flow_analysis.h b/tools/veridex/flow_analysis.h
index 2151a41725..2476668749 100644
--- a/tools/veridex/flow_analysis.h
+++ b/tools/veridex/flow_analysis.h
@@ -77,7 +77,7 @@ class RegisterValue {
std::string ToString() const {
switch (source_) {
case RegisterSource::kString: {
- const char* str = reference_.dex_file->StringDataByIdx(dex::StringIndex(reference_.index));
+ const char* str = reference_.dex_file->GetStringData(dex::StringIndex(reference_.index));
if (type_ == VeriClass::class_) {
// Class names at the Java level are of the form x.y.z, but the list encodes
// them of the form Lx/y/z;. Inner classes have '$' for both Java level class
@@ -88,7 +88,7 @@ class RegisterValue {
}
}
case RegisterSource::kClass:
- return reference_.dex_file->StringByTypeIdx(dex::TypeIndex(reference_.index));
+ return reference_.dex_file->GetTypeDescriptor(dex::TypeIndex(reference_.index));
case RegisterSource::kParameter:
return std::string("Parameter of ") + reference_.dex_file->PrettyMethod(reference_.index);
default:
diff --git a/tools/veridex/hidden_api.cc b/tools/veridex/hidden_api.cc
index 69e6fe403f..4156aa954b 100644
--- a/tools/veridex/hidden_api.cc
+++ b/tools/veridex/hidden_api.cc
@@ -82,7 +82,7 @@ void HiddenApi::AddSignatureToApiList(const std::string& signature, hiddenapi::A
std::string HiddenApi::GetApiMethodName(const DexFile& dex_file, uint32_t method_index) {
std::stringstream ss;
const dex::MethodId& method_id = dex_file.GetMethodId(method_index);
- ss << dex_file.StringByTypeIdx(method_id.class_idx_)
+ ss << dex_file.GetTypeDescriptorView(method_id.class_idx_)
<< "->"
<< dex_file.GetMethodName(method_id)
<< dex_file.GetMethodSignature(method_id).ToString();
@@ -92,7 +92,7 @@ std::string HiddenApi::GetApiMethodName(const DexFile& dex_file, uint32_t method
std::string HiddenApi::GetApiFieldName(const DexFile& dex_file, uint32_t field_index) {
std::stringstream ss;
const dex::FieldId& field_id = dex_file.GetFieldId(field_index);
- ss << dex_file.StringByTypeIdx(field_id.class_idx_)
+ ss << dex_file.GetTypeDescriptorView(field_id.class_idx_)
<< "->"
<< dex_file.GetFieldName(field_id)
<< ":"
diff --git a/tools/veridex/hidden_api_finder.cc b/tools/veridex/hidden_api_finder.cc
index 0f9ed52e3d..9455b0f10b 100644
--- a/tools/veridex/hidden_api_finder.cc
+++ b/tools/veridex/hidden_api_finder.cc
@@ -53,7 +53,7 @@ void HiddenApiFinder::CollectAccesses(VeridexResolver* resolver,
// Look at all types referenced in this dex file. Any of these
// types can lead to being used through reflection.
for (uint32_t i = 0; i < dex_file.NumTypeIds(); ++i) {
- std::string name(dex_file.StringByTypeIdx(dex::TypeIndex(i)));
+ std::string name(dex_file.GetTypeDescriptorView(dex::TypeIndex(i)));
classes_.insert(name);
}
// Note: we collect strings constants only referenced in code items as the string table
@@ -72,7 +72,7 @@ void HiddenApiFinder::CollectAccesses(VeridexResolver* resolver,
switch (inst->Opcode()) {
case Instruction::CONST_STRING: {
dex::StringIndex string_index(inst->VRegB_21c());
- const auto& name = std::string(dex_file.StringDataByIdx(string_index));
+ const std::string name(dex_file.GetStringView(string_index));
// Cheap filtering on the string literal. We know it cannot be a field/method/class
// if it contains a space.
if (name.find(' ') == std::string::npos) {
diff --git a/tools/veridex/resolver.cc b/tools/veridex/resolver.cc
index df097b6263..a56ea6e5ae 100644
--- a/tools/veridex/resolver.cc
+++ b/tools/veridex/resolver.cc
@@ -76,7 +76,7 @@ VeriClass* VeridexResolver::GetVeriClass(dex::TypeIndex index) {
VeriClass* cls = &type_infos_[index.index_];
if (cls->IsUninitialized()) {
// Class is defined in another dex file. Lookup in the global cache.
- std::string name(dex_file_.StringByTypeIdx(index));
+ std::string name(dex_file_.GetTypeDescriptorView(index));
auto existing = type_map_.find(name);
if (existing == type_map_.end()) {
// Class hasn't been defined, so check if it's an array class.