Merge changes I14c7cddd,I4a39d0e8,I3f24c8f4,I9699f138
* changes:
Replace StringPiece with std::string_view in art/runtime/.
Replace StringPiece with std::string_view in HashSet.
Replace StringPiece with std::string_view in Signature.
Replace StringPiece with std::string_view in class.h.
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index d46cffb..56333b6 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -17,13 +17,15 @@
#include "compiler_driver.h"
#include <unistd.h>
-#include <unordered_set>
-#include <vector>
#ifndef __APPLE__
#include <malloc.h> // For mallinfo
#endif
+#include <string_view>
+#include <unordered_set>
+#include <vector>
+
#include "android-base/logging.h"
#include "android-base/strings.h"
@@ -35,6 +37,7 @@
#include "base/enums.h"
#include "base/logging.h" // For VLOG
#include "base/stl_util.h"
+#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/time_utils.h"
#include "base/timing_logger.h"
@@ -1154,7 +1157,7 @@
const PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
while (!klass->IsObjectClass()) {
const char* descriptor = klass->GetDescriptor(&temp);
- if (image_classes->find(StringPiece(descriptor)) != image_classes->end()) {
+ if (image_classes->find(std::string_view(descriptor)) != image_classes->end()) {
break; // Previously inserted.
}
image_classes->insert(descriptor);
@@ -1236,7 +1239,7 @@
bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_) {
std::string temp;
- StringPiece name(klass->GetDescriptor(&temp));
+ std::string_view name(klass->GetDescriptor(&temp));
auto it = data_->image_class_descriptors_->find(name);
if (it != data_->image_class_descriptors_->end()) {
if (LIKELY(klass->IsResolved())) {
@@ -2226,7 +2229,7 @@
// We need to initialize static fields, we only do this for image classes that aren't
// marked with the $NoPreloadHolder (which implies this should not be initialized
// early).
- can_init_static_fields = !StringPiece(descriptor).ends_with("$NoPreloadHolder;");
+ can_init_static_fields = !EndsWith(std::string_view(descriptor), "$NoPreloadHolder;");
} else {
CHECK(is_app_image);
// The boot image case doesn't need to recursively initialize the dependencies with
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc
index 8d1ae3d..7dd743f 100644
--- a/compiler/driver/compiler_options.cc
+++ b/compiler/driver/compiler_options.cc
@@ -17,6 +17,7 @@
#include "compiler_options.h"
#include <fstream>
+#include <string_view>
#include "android-base/stringprintf.h"
@@ -144,7 +145,7 @@
// Historical note: We used to hold the set indirectly and there was a distinction between an
// empty set and a null, null meaning to include all classes. However, the distiction has been
// removed; if we don't have a profile, we treat it as an empty set of classes. b/77340429
- return image_classes_.find(StringPiece(descriptor)) != image_classes_.end();
+ return image_classes_.find(std::string_view(descriptor)) != image_classes_.end();
}
const VerificationResults* CompilerOptions::GetVerificationResults() const {
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index bd12bf7..fccd9ca 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -361,13 +361,6 @@
private:
bool ParseDumpInitFailures(const std::string& option, std::string* error_msg);
- void ParseDumpCfgPasses(const StringPiece& option, UsageFn Usage);
- void ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage);
- void ParseNumDexMethods(const StringPiece& option, UsageFn Usage);
- void ParseTinyMethodMax(const StringPiece& option, UsageFn Usage);
- void ParseSmallMethodMax(const StringPiece& option, UsageFn Usage);
- void ParseLargeMethodMax(const StringPiece& option, UsageFn Usage);
- void ParseHugeMethodMax(const StringPiece& option, UsageFn Usage);
bool ParseRegisterAllocationStrategy(const std::string& option, std::string* error_msg);
CompilerFilter::Filter compiler_filter_;
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h
index 8c9dfb8..431ab90 100644
--- a/dex2oat/linker/image_test.h
+++ b/dex2oat/linker/image_test.h
@@ -21,6 +21,7 @@
#include <memory>
#include <string>
+#include <string_view>
#include <vector>
#include "android-base/stringprintf.h"
@@ -498,7 +499,7 @@
ObjPtr<mirror::Class> klass = class_linker_->FindSystemClass(soa.Self(), descriptor);
EXPECT_TRUE(klass != nullptr) << descriptor;
uint8_t* raw_klass = reinterpret_cast<uint8_t*>(klass.Ptr());
- if (image_classes.find(StringPiece(descriptor)) == image_classes.end()) {
+ if (image_classes.find(std::string_view(descriptor)) == image_classes.end()) {
EXPECT_TRUE(raw_klass >= image_end || raw_klass < image_begin) << descriptor;
} else {
// Image classes should be located inside the image.
diff --git a/libartbase/base/hash_set.h b/libartbase/base/hash_set.h
index 42aa46f..99b3df4 100644
--- a/libartbase/base/hash_set.h
+++ b/libartbase/base/hash_set.h
@@ -139,7 +139,8 @@
std::hash<T>>::type;
struct DefaultStringEquals {
- // Allow comparison with anything that can be compared to std::string, for example StringPiece.
+ // Allow comparison with anything that can be compared to std::string,
+ // for example std::string_view.
template <typename T>
bool operator()(const std::string& lhs, const T& rhs) const {
return lhs == rhs;
diff --git a/libartbase/base/hash_set_test.cc b/libartbase/base/hash_set_test.cc
index 782a68b..0646967 100644
--- a/libartbase/base/hash_set_test.cc
+++ b/libartbase/base/hash_set_test.cc
@@ -20,12 +20,12 @@
#include <map>
#include <sstream>
#include <string>
+#include <string_view>
#include <unordered_set>
#include <vector>
#include <gtest/gtest.h>
-#include "base/stringpiece.h"
#include "hash_map.h"
namespace art {
@@ -365,11 +365,11 @@
ASSERT_EQ(*it, *cit);
}
-TEST_F(HashSetTest, StringSearchyStringPiece) {
+TEST_F(HashSetTest, StringSearchyStringView) {
const char* test_string = "dummy";
HashSet<std::string> hash_set;
HashSet<std::string>::iterator insert_pos = hash_set.insert(test_string);
- HashSet<std::string>::iterator it = hash_set.find(StringPiece(test_string));
+ HashSet<std::string>::iterator it = hash_set.find(std::string_view(test_string));
ASSERT_TRUE(it == insert_pos);
}
diff --git a/libartbase/base/string_view_cpp20.h b/libartbase/base/string_view_cpp20.h
new file mode 100644
index 0000000..2c11a2f
--- /dev/null
+++ b/libartbase/base/string_view_cpp20.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019 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_LIBARTBASE_BASE_STRING_VIEW_CPP20_H_
+#define ART_LIBARTBASE_BASE_STRING_VIEW_CPP20_H_
+
+#include <string_view>
+
+namespace art {
+
+// Replacement functions for std::string_view::starts_with(), ends_with()
+// which shall be available in C++20.
+#if __cplusplus >= 202000L
+#error "When upgrading to C++20, remove this error and file a bug to remove this workaround."
+#endif
+
+inline bool StartsWith(std::string_view sv, std::string_view prefix) {
+ return sv.substr(0u, prefix.size()) == prefix;
+}
+
+inline bool EndsWith(std::string_view sv, std::string_view suffix) {
+ return sv.size() >= suffix.size() && sv.substr(sv.size() - suffix.size()) == suffix;
+}
+
+} // namespace art
+
+#endif // ART_LIBARTBASE_BASE_STRING_VIEW_CPP20_H_
diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h
index 2af1e04..15ba9cc 100644
--- a/libdexfile/dex/dex_file-inl.h
+++ b/libdexfile/dex/dex_file-inl.h
@@ -22,7 +22,6 @@
#include "base/casts.h"
#include "base/iteration_range.h"
#include "base/leb128.h"
-#include "base/stringpiece.h"
#include "base/utils.h"
#include "class_iterator.h"
#include "compact_dex_file.h"
diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc
index 39377a3..7db4de0 100644
--- a/libdexfile/dex/dex_file.cc
+++ b/libdexfile/dex/dex_file.cc
@@ -400,7 +400,7 @@
}
// Given a signature place the type ids into the given vector
-bool DexFile::CreateTypeList(const StringPiece& signature,
+bool DexFile::CreateTypeList(std::string_view signature,
dex::TypeIndex* return_type_idx,
std::vector<dex::TypeIndex>* param_type_idxs) const {
if (signature[0] != '(') {
@@ -450,20 +450,6 @@
return false; // failed to correctly parse return type
}
-const Signature DexFile::CreateSignature(const StringPiece& signature) const {
- dex::TypeIndex return_type_idx;
- std::vector<dex::TypeIndex> param_type_indices;
- bool success = CreateTypeList(signature, &return_type_idx, ¶m_type_indices);
- if (!success) {
- return Signature::NoSignature();
- }
- const ProtoId* proto_id = FindProtoId(return_type_idx, param_type_indices);
- if (proto_id == nullptr) {
- return Signature::NoSignature();
- }
- return Signature(this, *proto_id);
-}
-
int32_t DexFile::FindTryItem(const TryItem* try_items, uint32_t tries_size, uint32_t address) {
uint32_t min = 0;
uint32_t max = tries_size;
diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h
index 8ea3c09..4dae1c0 100644
--- a/libdexfile/dex/dex_file.h
+++ b/libdexfile/dex/dex_file.h
@@ -19,6 +19,7 @@
#include <memory>
#include <string>
+#include <string_view>
#include <vector>
#include <android-base/logging.h>
@@ -44,7 +45,6 @@
class MemMap;
class OatDexFile;
class StandardDexFile;
-class StringPiece;
class ZipArchive;
// Some instances of DexFile own the storage referred to by DexFile. Clients who create
@@ -479,14 +479,10 @@
}
// Given a signature place the type ids into the given vector, returns true on success
- bool CreateTypeList(const StringPiece& signature,
+ bool CreateTypeList(std::string_view signature,
dex::TypeIndex* return_type_idx,
std::vector<dex::TypeIndex>* param_type_idxs) const;
- // Create a Signature from the given string signature or return Signature::NoSignature if not
- // possible.
- const Signature CreateSignature(const StringPiece& signature) const;
-
// Returns the short form method descriptor for the given prototype.
const char* GetShorty(dex::ProtoIndex proto_idx) const;
diff --git a/libdexfile/dex/signature-inl.h b/libdexfile/dex/signature-inl.h
index ccc7ea9..12ad1b3 100644
--- a/libdexfile/dex/signature-inl.h
+++ b/libdexfile/dex/signature-inl.h
@@ -19,7 +19,6 @@
#include "signature.h"
-#include "base/stringpiece.h"
#include "dex_file-inl.h"
namespace art {
@@ -37,13 +36,13 @@
uint32_t lhs_shorty_len; // For a shorty utf16 length == mutf8 length.
const char* lhs_shorty_data = dex_file_->StringDataAndUtf16LengthByIdx(proto_id_->shorty_idx_,
&lhs_shorty_len);
- StringPiece lhs_shorty(lhs_shorty_data, lhs_shorty_len);
+ std::string_view lhs_shorty(lhs_shorty_data, lhs_shorty_len);
{
uint32_t rhs_shorty_len;
const char* rhs_shorty_data =
rhs.dex_file_->StringDataAndUtf16LengthByIdx(rhs.proto_id_->shorty_idx_,
&rhs_shorty_len);
- StringPiece rhs_shorty(rhs_shorty_data, rhs_shorty_len);
+ std::string_view rhs_shorty(rhs_shorty_data, rhs_shorty_len);
if (lhs_shorty != rhs_shorty) {
return false; // Shorty mismatch.
}
@@ -57,7 +56,7 @@
return false; // Return type mismatch.
}
}
- if (lhs_shorty.find('L', 1) != StringPiece::npos) {
+ if (lhs_shorty.find('L', 1) != std::string_view::npos) {
const dex::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
const dex::TypeList* rhs_params = rhs.dex_file_->GetProtoParameters(*rhs.proto_id_);
// We found a reference parameter in the matching shorty, so both lists must be non-empty.
diff --git a/libdexfile/dex/signature.cc b/libdexfile/dex/signature.cc
index 34b4b55..ac00428 100644
--- a/libdexfile/dex/signature.cc
+++ b/libdexfile/dex/signature.cc
@@ -21,6 +21,8 @@
#include <ostream>
#include <type_traits>
+#include "base/string_view_cpp20.h"
+
namespace art {
using dex::TypeList;
@@ -55,26 +57,26 @@
return strcmp(return_type, "V") == 0;
}
-bool Signature::operator==(const StringPiece& rhs) const {
+bool Signature::operator==(std::string_view rhs) const {
if (dex_file_ == nullptr) {
return false;
}
- StringPiece tail(rhs);
- if (!tail.starts_with("(")) {
+ std::string_view tail(rhs);
+ if (!StartsWith(tail, "(")) {
return false; // Invalid signature
}
tail.remove_prefix(1); // "(";
const TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
if (params != nullptr) {
for (uint32_t i = 0; i < params->Size(); ++i) {
- StringPiece param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_));
- if (!tail.starts_with(param)) {
+ std::string_view param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_));
+ if (!StartsWith(tail, param)) {
return false;
}
tail.remove_prefix(param.length());
}
}
- if (!tail.starts_with(")")) {
+ if (!StartsWith(tail, ")")) {
return false;
}
tail.remove_prefix(1); // ")";
diff --git a/libdexfile/dex/signature.h b/libdexfile/dex/signature.h
index 235f37c..3fbb543 100644
--- a/libdexfile/dex/signature.h
+++ b/libdexfile/dex/signature.h
@@ -19,6 +19,7 @@
#include <iosfwd>
#include <string>
+#include <string_view>
#include <android-base/logging.h>
@@ -30,7 +31,6 @@
struct ProtoId;
} // namespace dex
class DexFile;
-class StringPiece;
// Abstract the signature of a method.
class Signature : public ValueObject {
@@ -49,7 +49,7 @@
return !(*this == rhs);
}
- bool operator==(const StringPiece& rhs) const;
+ bool operator==(std::string_view rhs) const;
private:
Signature(const DexFile* dex, const dex::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) {
diff --git a/openjdkjvmti/ti_class.cc b/openjdkjvmti/ti_class.cc
index a8e220c..3ad1112 100644
--- a/openjdkjvmti/ti_class.cc
+++ b/openjdkjvmti/ti_class.cc
@@ -34,6 +34,7 @@
#include "android-base/stringprintf.h"
#include <mutex>
+#include <string_view>
#include <unordered_set>
#include "art_jvmti.h"
@@ -872,7 +873,7 @@
/*out*/jint* count_ptr,
/*out*/char*** classes) {
jvmtiError res = OK;
- std::set<art::StringPiece> unique_descriptors;
+ std::set<std::string_view> unique_descriptors;
std::vector<const char*> descriptors;
auto add_descriptor = [&](const char* desc) {
// Don't add duplicates.
diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc
index 3d175a8..eb4bada 100644
--- a/openjdkjvmti/ti_redefine.cc
+++ b/openjdkjvmti/ti_redefine.cc
@@ -32,6 +32,7 @@
#include "ti_redefine.h"
#include <limits>
+#include <string_view>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
@@ -40,7 +41,6 @@
#include "art_jvmti.h"
#include "art_method-inl.h"
#include "base/array_ref.h"
-#include "base/stringpiece.h"
#include "class_linker-inl.h"
#include "class_root.h"
#include "debugger.h"
@@ -597,7 +597,7 @@
// Try and get the declared method. First try to get a virtual method then a direct method if that's
// not found.
static art::ArtMethod* FindMethod(art::Handle<art::mirror::Class> klass,
- art::StringPiece name,
+ std::string_view name,
art::Signature sig) REQUIRES_SHARED(art::Locks::mutator_lock_) {
DCHECK(!klass->IsProxyClass());
for (art::ArtMethod& m : klass->GetDeclaredMethodsSlice(art::kRuntimePointerSize)) {
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 2f37123..c9bdbda 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -18,6 +18,7 @@
#include <memory>
#include <string>
+#include <string_view>
#include "android-base/strings.h"
@@ -509,7 +510,7 @@
for (size_t i = 0; i < offsets.size(); i++) {
ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
- StringPiece field_name(field->GetName());
+ std::string_view field_name(field->GetName());
if (field_name != offsets[i].java_name) {
error = true;
}
@@ -518,7 +519,7 @@
for (size_t i = 0; i < offsets.size(); i++) {
CheckOffset& offset = offsets[i];
ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
- StringPiece field_name(field->GetName());
+ std::string_view field_name(field->GetName());
if (field_name != offsets[i].java_name) {
LOG(ERROR) << "JAVA FIELD ORDER MISMATCH NEXT LINE:";
}
@@ -1254,7 +1255,7 @@
EXPECT_TRUE(K->IsAssignableFrom(B.Get()));
EXPECT_TRUE(J->IsAssignableFrom(B.Get()));
- const Signature void_sig = I->GetDexCache()->GetDexFile()->CreateSignature("()V");
+ const std::string_view void_sig("()V");
ArtMethod* Ii = I->FindClassMethod("i", void_sig, kRuntimePointerSize);
ArtMethod* Jj1 = J->FindClassMethod("j1", void_sig, kRuntimePointerSize);
ArtMethod* Jj2 = J->FindClassMethod("j2", void_sig, kRuntimePointerSize);
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 62788b1..499bf28 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -390,8 +390,10 @@
// NoSuchFieldError
-void ThrowNoSuchFieldError(const StringPiece& scope, ObjPtr<mirror::Class> c,
- const StringPiece& type, const StringPiece& name) {
+void ThrowNoSuchFieldError(std::string_view scope,
+ ObjPtr<mirror::Class> c,
+ std::string_view type,
+ std::string_view name) {
std::ostringstream msg;
std::string temp;
msg << "No " << scope << "field " << name << " of type " << type
@@ -399,7 +401,7 @@
ThrowException("Ljava/lang/NoSuchFieldError;", c, msg.str().c_str());
}
-void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name) {
+void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, std::string_view name) {
std::ostringstream msg;
std::string temp;
msg << "No field " << name << " in class " << c->GetDescriptor(&temp);
@@ -408,7 +410,9 @@
// NoSuchMethodError
-void ThrowNoSuchMethodError(InvokeType type, ObjPtr<mirror::Class> c, const StringPiece& name,
+void ThrowNoSuchMethodError(InvokeType type,
+ ObjPtr<mirror::Class> c,
+ std::string_view name,
const Signature& signature) {
std::ostringstream msg;
std::string temp;
diff --git a/runtime/common_throws.h b/runtime/common_throws.h
index ca9c96a..c167d1b 100644
--- a/runtime/common_throws.h
+++ b/runtime/common_throws.h
@@ -17,6 +17,8 @@
#ifndef ART_RUNTIME_COMMON_THROWS_H_
#define ART_RUNTIME_COMMON_THROWS_H_
+#include <string_view>
+
#include "base/locks.h"
#include "obj_ptr.h"
@@ -31,7 +33,6 @@
class DexFile;
enum InvokeType : uint32_t;
class Signature;
-class StringPiece;
// AbstractMethodError
@@ -196,20 +197,20 @@
// NoSuchFieldError
-void ThrowNoSuchFieldError(const StringPiece& scope,
+void ThrowNoSuchFieldError(std::string_view scope,
ObjPtr<mirror::Class> c,
- const StringPiece& type,
- const StringPiece& name)
+ std::string_view type,
+ std::string_view name)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
-void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name)
+void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, std::string_view name)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
// NoSuchMethodError
void ThrowNoSuchMethodError(InvokeType type,
ObjPtr<mirror::Class> c,
- const StringPiece& name,
+ std::string_view name,
const Signature& signature)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc
index 2e41a9d..aa11562 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -17,6 +17,7 @@
#include "interpreter.h"
#include <limits>
+#include <string_view>
#include "common_dex_operations.h"
#include "common_throws.h"
@@ -46,7 +47,7 @@
static void InterpreterJni(Thread* self,
ArtMethod* method,
- const StringPiece& shorty,
+ std::string_view shorty,
ObjPtr<mirror::Object> receiver,
uint32_t* args,
JValue* result)
diff --git a/runtime/jni/java_vm_ext.cc b/runtime/jni/java_vm_ext.cc
index e54b807..df96d28 100644
--- a/runtime/jni/java_vm_ext.cc
+++ b/runtime/jni/java_vm_ext.cc
@@ -17,6 +17,7 @@
#include "java_vm_ext.h"
#include <dlfcn.h>
+#include <string_view>
#include "android-base/stringprintf.h"
@@ -25,6 +26,7 @@
#include "base/mutex-inl.h"
#include "base/sdk_version.h"
#include "base/stl_util.h"
+#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "check_jni.h"
#include "dex/dex_file-inl.h"
@@ -566,8 +568,8 @@
return false;
}
// Perform checks based on class name.
- StringPiece class_name(method->GetDeclaringClassDescriptor());
- if (!trace_.empty() && class_name.find(trace_) != std::string::npos) {
+ std::string_view class_name(method->GetDeclaringClassDescriptor());
+ if (!trace_.empty() && class_name.find(trace_) != std::string_view::npos) {
return true;
}
if (!VLOG_IS_ON(third_party_jni)) {
@@ -575,7 +577,7 @@
}
// Return true if we're trying to log all third-party JNI activity and 'method' doesn't look
// like part of Android.
- static const char* gBuiltInPrefixes[] = {
+ static const char* const gBuiltInPrefixes[] = {
"Landroid/",
"Lcom/android/",
"Lcom/google/android/",
@@ -586,7 +588,7 @@
"Lorg/apache/harmony/",
};
for (size_t i = 0; i < arraysize(gBuiltInPrefixes); ++i) {
- if (class_name.starts_with(gBuiltInPrefixes[i])) {
+ if (StartsWith(class_name, gBuiltInPrefixes[i])) {
return false;
}
}
diff --git a/runtime/jni/jni_internal.cc b/runtime/jni/jni_internal.cc
index af86cc0..7c0db30 100644
--- a/runtime/jni/jni_internal.cc
+++ b/runtime/jni/jni_internal.cc
@@ -442,8 +442,8 @@
template <bool kNative>
static ArtMethod* FindMethod(ObjPtr<mirror::Class> c,
- const StringPiece& name,
- const StringPiece& sig)
+ std::string_view name,
+ std::string_view sig)
REQUIRES_SHARED(Locks::mutator_lock_) {
auto pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
for (auto& method : c->GetMethods(pointer_size)) {
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index fcd3714..872095a 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -389,14 +389,14 @@
new_reference_offsets);
}
-bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) {
+bool Class::IsInSamePackage(std::string_view descriptor1, std::string_view descriptor2) {
size_t i = 0;
size_t min_length = std::min(descriptor1.size(), descriptor2.size());
while (i < min_length && descriptor1[i] == descriptor2[i]) {
++i;
}
- if (descriptor1.find('/', i) != StringPiece::npos ||
- descriptor2.find('/', i) != StringPiece::npos) {
+ if (descriptor1.find('/', i) != std::string_view::npos ||
+ descriptor2.find('/', i) != std::string_view::npos) {
return false;
} else {
return true;
@@ -435,7 +435,7 @@
template <typename SignatureType>
static inline ArtMethod* FindInterfaceMethodWithSignature(ObjPtr<Class> klass,
- const StringPiece& name,
+ std::string_view name,
const SignatureType& signature,
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -478,13 +478,13 @@
return nullptr;
}
-ArtMethod* Class::FindInterfaceMethod(const StringPiece& name,
- const StringPiece& signature,
+ArtMethod* Class::FindInterfaceMethod(std::string_view name,
+ std::string_view signature,
PointerSize pointer_size) {
return FindInterfaceMethodWithSignature(this, name, signature, pointer_size);
}
-ArtMethod* Class::FindInterfaceMethod(const StringPiece& name,
+ArtMethod* Class::FindInterfaceMethod(std::string_view name,
const Signature& signature,
PointerSize pointer_size) {
return FindInterfaceMethodWithSignature(this, name, signature, pointer_size);
@@ -496,7 +496,7 @@
// 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);
- StringPiece name = dex_file.StringDataByIdx(method_id.name_idx_);
+ std::string_view name = dex_file.StringDataByIdx(method_id.name_idx_);
const Signature signature = dex_file.GetMethodSignature(method_id);
return FindInterfaceMethod(name, signature, pointer_size);
}
@@ -537,7 +537,7 @@
template <typename SignatureType>
static inline ArtMethod* FindClassMethodWithSignature(ObjPtr<Class> this_klass,
- const StringPiece& name,
+ std::string_view name,
const SignatureType& signature,
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -591,13 +591,13 @@
}
-ArtMethod* Class::FindClassMethod(const StringPiece& name,
- const StringPiece& signature,
+ArtMethod* Class::FindClassMethod(std::string_view name,
+ std::string_view signature,
PointerSize pointer_size) {
return FindClassMethodWithSignature(this, name, signature, pointer_size);
}
-ArtMethod* Class::FindClassMethod(const StringPiece& name,
+ArtMethod* Class::FindClassMethod(std::string_view name,
const Signature& signature,
PointerSize pointer_size) {
return FindClassMethodWithSignature(this, name, signature, pointer_size);
@@ -624,7 +624,7 @@
const DexFile& dex_file = *dex_cache->GetDexFile();
const dex::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
const Signature signature = dex_file.GetMethodSignature(method_id);
- StringPiece name; // Delay strlen() until actually needed.
+ std::string_view name; // Delay strlen() until actually needed.
// If we do not have a dex_cache match, try to find the declared method in this class now.
if (this_dex_cache != dex_cache && !GetDeclaredMethodsSlice(pointer_size).empty()) {
DCHECK(name.empty());
@@ -701,10 +701,10 @@
return uninherited_method; // Return the `uninherited_method` if any.
}
-ArtMethod* Class::FindConstructor(const StringPiece& signature, PointerSize pointer_size) {
+ArtMethod* Class::FindConstructor(std::string_view signature, PointerSize pointer_size) {
// Internal helper, never called on proxy classes. We can skip GetInterfaceMethodIfProxy().
DCHECK(!IsProxyClass());
- StringPiece name("<init>");
+ std::string_view name("<init>");
for (ArtMethod& method : GetDirectMethodsSliceUnchecked(pointer_size)) {
if (method.GetName() == name && method.GetSignature() == signature) {
return &method;
@@ -713,8 +713,7 @@
return nullptr;
}
-ArtMethod* Class::FindDeclaredDirectMethodByName(const StringPiece& name,
- PointerSize pointer_size) {
+ArtMethod* Class::FindDeclaredDirectMethodByName(std::string_view name, PointerSize pointer_size) {
for (auto& method : GetDirectMethods(pointer_size)) {
ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
if (name == np_method->GetName()) {
@@ -724,8 +723,7 @@
return nullptr;
}
-ArtMethod* Class::FindDeclaredVirtualMethodByName(const StringPiece& name,
- PointerSize pointer_size) {
+ArtMethod* Class::FindDeclaredVirtualMethodByName(std::string_view name, PointerSize pointer_size) {
for (auto& method : GetVirtualMethods(pointer_size)) {
ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
if (name == np_method->GetName()) {
@@ -813,8 +811,8 @@
// Custom binary search to avoid double comparisons from std::binary_search.
static ArtField* FindFieldByNameAndType(LengthPrefixedArray<ArtField>* fields,
- const StringPiece& name,
- const StringPiece& type)
+ std::string_view name,
+ std::string_view type)
REQUIRES_SHARED(Locks::mutator_lock_) {
if (fields == nullptr) {
return nullptr;
@@ -827,9 +825,12 @@
ArtField& field = fields->At(mid);
// 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 in the same class name due to proguard.
- int result = StringPiece(field.GetName()).Compare(name);
+ // 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 result = std::string_view(field.GetName()).compare(name);
if (result == 0) {
- result = StringPiece(field.GetTypeDescriptor()).Compare(type);
+ result = std::string_view(field.GetTypeDescriptor()).compare(type);
}
if (result < 0) {
low = mid + 1;
@@ -853,7 +854,7 @@
return ret;
}
-ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) {
+ArtField* Class::FindDeclaredInstanceField(std::string_view name, std::string_view type) {
// Binary search by name. Interfaces are not relevant because they can't contain instance fields.
return FindFieldByNameAndType(GetIFieldsPtr(), name, type);
}
@@ -869,7 +870,7 @@
return nullptr;
}
-ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) {
+ArtField* Class::FindInstanceField(std::string_view name, std::string_view type) {
// Is the field in this class, or any of its superclasses?
// Interfaces are not relevant because they can't contain instance fields.
for (ObjPtr<Class> c = this; c != nullptr; c = c->GetSuperClass()) {
@@ -893,8 +894,8 @@
return nullptr;
}
-ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) {
- DCHECK(type != nullptr);
+ArtField* Class::FindDeclaredStaticField(std::string_view name, std::string_view type) {
+ DCHECK(!type.empty());
return FindFieldByNameAndType(GetSFieldsPtr(), name, type);
}
@@ -911,8 +912,8 @@
ArtField* Class::FindStaticField(Thread* self,
ObjPtr<Class> klass,
- const StringPiece& name,
- const StringPiece& type) {
+ std::string_view name,
+ std::string_view type) {
// Is the field in this class (or its interfaces), or any of its
// superclasses (or their interfaces)?
for (ObjPtr<Class> k = klass; k != nullptr; k = k->GetSuperClass()) {
@@ -962,8 +963,8 @@
ArtField* Class::FindField(Thread* self,
ObjPtr<Class> klass,
- const StringPiece& name,
- const StringPiece& type) {
+ std::string_view name,
+ std::string_view type) {
// Find a field using the JLS field resolution order
for (ObjPtr<Class> k = klass; k != nullptr; k = k->GetSuperClass()) {
// Is the field in this class?
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index c9c542d..bde9b03 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -17,6 +17,8 @@
#ifndef ART_RUNTIME_MIRROR_CLASS_H_
#define ART_RUNTIME_MIRROR_CLASS_H_
+#include <string_view>
+
#include "base/bit_utils.h"
#include "base/casts.h"
#include "base/stride_iterator.h"
@@ -53,7 +55,6 @@
template<typename T> class LengthPrefixedArray;
enum class PointerSize : size_t;
class Signature;
-class StringPiece;
template<size_t kNumReferences> class PACKED(4) StackHandleScope;
class Thread;
@@ -556,7 +557,7 @@
// Returns true if this class is in the same packages as that class.
bool IsInSamePackage(ObjPtr<Class> that) REQUIRES_SHARED(Locks::mutator_lock_);
- static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
+ static bool IsInSamePackage(std::string_view descriptor1, std::string_view descriptor2);
// Returns true if this class can access that class.
bool CanAccess(ObjPtr<Class> that) REQUIRES_SHARED(Locks::mutator_lock_);
@@ -861,12 +862,12 @@
// in an interface without superinterfaces, see JLS 9.2, can be inherited, see JLS 9.4.1).
// TODO: Implement search for a unique maximally-specific non-abstract superinterface method.
- ArtMethod* FindInterfaceMethod(const StringPiece& name,
- const StringPiece& signature,
+ ArtMethod* FindInterfaceMethod(std::string_view name,
+ std::string_view signature,
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtMethod* FindInterfaceMethod(const StringPiece& name,
+ ArtMethod* FindInterfaceMethod(std::string_view name,
const Signature& signature,
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -900,12 +901,12 @@
// does not satisfy the request. Special consideration should be given to the case where this
// function returns a method that's not inherited (found in step 2, returned in step 4).
- ArtMethod* FindClassMethod(const StringPiece& name,
- const StringPiece& signature,
+ ArtMethod* FindClassMethod(std::string_view name,
+ std::string_view signature,
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtMethod* FindClassMethod(const StringPiece& name,
+ ArtMethod* FindClassMethod(std::string_view name,
const Signature& signature,
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -915,13 +916,13 @@
PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtMethod* FindConstructor(const StringPiece& signature, PointerSize pointer_size)
+ ArtMethod* FindConstructor(std::string_view signature, PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name, PointerSize pointer_size)
+ ArtMethod* FindDeclaredVirtualMethodByName(std::string_view name, PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name, PointerSize pointer_size)
+ ArtMethod* FindDeclaredDirectMethodByName(std::string_view name, PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
ArtMethod* FindClassInitializer(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
@@ -1036,12 +1037,12 @@
// Find a static or instance field using the JLS resolution order
static ArtField* FindField(Thread* self,
ObjPtr<Class> klass,
- const StringPiece& name,
- const StringPiece& type)
+ std::string_view name,
+ std::string_view type)
REQUIRES_SHARED(Locks::mutator_lock_);
// Finds the given instance field in this class or a superclass.
- ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
+ ArtField* FindInstanceField(std::string_view name, std::string_view type)
REQUIRES_SHARED(Locks::mutator_lock_);
// Finds the given instance field in this class or a superclass, only searches classes that
@@ -1049,7 +1050,7 @@
ArtField* FindInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
+ ArtField* FindDeclaredInstanceField(std::string_view name, std::string_view type)
REQUIRES_SHARED(Locks::mutator_lock_);
ArtField* FindDeclaredInstanceField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
@@ -1058,8 +1059,8 @@
// Finds the given static field in this class or a superclass.
static ArtField* FindStaticField(Thread* self,
ObjPtr<Class> klass,
- const StringPiece& name,
- const StringPiece& type)
+ std::string_view name,
+ std::string_view type)
REQUIRES_SHARED(Locks::mutator_lock_);
// Finds the given static field in this class or superclass, only searches classes that
@@ -1070,7 +1071,7 @@
uint32_t dex_field_idx)
REQUIRES_SHARED(Locks::mutator_lock_);
- ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
+ ArtField* FindDeclaredStaticField(std::string_view name, std::string_view type)
REQUIRES_SHARED(Locks::mutator_lock_);
ArtField* FindDeclaredStaticField(ObjPtr<DexCache> dex_cache, uint32_t dex_field_idx)
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 6fd691f..f516d0d 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -24,7 +24,6 @@
#include "base/file_utils.h"
#include "base/macros.h"
-#include "base/stringpiece.h"
#include "base/utils.h"
#include "debugger.h"
#include "gc/heap.h"
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 8f89f52..1465b14 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1180,8 +1180,8 @@
compiler_executable_ = runtime_options.ReleaseOrDefault(Opt::Compiler);
compiler_options_ = runtime_options.ReleaseOrDefault(Opt::CompilerOptions);
- for (StringPiece option : Runtime::Current()->GetCompilerOptions()) {
- if (option.starts_with("--debuggable")) {
+ for (const std::string& option : Runtime::Current()->GetCompilerOptions()) {
+ if (option == "--debuggable") {
SetJavaDebuggable(true);
break;
}
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
index bdcadd9..b758159 100644
--- a/runtime/verifier/verifier_deps.cc
+++ b/runtime/verifier/verifier_deps.cc
@@ -966,8 +966,9 @@
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
for (const auto& entry : fields) {
const dex::FieldId& field_id = dex_file.GetFieldId(entry.GetDexFieldIndex());
- StringPiece name(dex_file.StringDataByIdx(field_id.name_idx_));
- StringPiece type(dex_file.StringDataByIdx(dex_file.GetTypeId(field_id.type_idx_).descriptor_idx_));
+ std::string_view name(dex_file.StringDataByIdx(field_id.name_idx_));
+ std::string_view type(
+ dex_file.StringDataByIdx(dex_file.GetTypeId(field_id.type_idx_).descriptor_idx_));
// Only use field_id.class_idx_ when the entry is unresolved, which is rare.
// Otherwise, we might end up resolving an application class, which is expensive.
std::string expected_decl_klass = entry.IsResolved()
diff --git a/test/004-StackWalk/stack_walk_jni.cc b/test/004-StackWalk/stack_walk_jni.cc
index 81c27ec..6e53f30 100644
--- a/test/004-StackWalk/stack_walk_jni.cc
+++ b/test/004-StackWalk/stack_walk_jni.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <string_view>
+
#include "art_method-inl.h"
#include "check_reference_map_visitor.h"
#include "jni.h"
@@ -38,7 +40,7 @@
return true;
}
ArtMethod* m = GetMethod();
- StringPiece m_name(m->GetName());
+ std::string_view m_name(m->GetName());
// Given the method name and the number of times the method has been called,
// we know the Dex registers with live reference values. Assert that what we