Avoid copying and strlen(3) in the FindClass path.
Change-Id: I789f3c883596d1852a2c1954ce7a207e6f937117
diff --git a/src/class_linker.cc b/src/class_linker.cc
index e922d4c..df2e971 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -136,6 +136,15 @@
env->Throw(eiie.get());
}
+static size_t Hash(const char* s) {
+ // This is the java.lang.String hashcode for convenience, not interoperability.
+ size_t hash = 0;
+ for (; *s != '\0'; ++s) {
+ hash = hash * 31 + *s;
+ }
+ return hash;
+}
+
} // namespace
const char* ClassLinker::class_roots_descriptors_[] = {
@@ -812,8 +821,8 @@
if (obj->IsClass()) {
// restore class to ClassLinker::classes_ table
Class* klass = obj->AsClass();
- std::string descriptor(ClassHelper(klass, class_linker).GetDescriptor());
- bool success = class_linker->InsertClass(descriptor, klass, true);
+ ClassHelper kh(klass, class_linker);
+ bool success = class_linker->InsertClass(kh.GetDescriptor(), klass, true);
DCHECK(success);
return;
}
@@ -984,13 +993,12 @@
return klass;
}
-Class* ClassLinker::FindClass(const std::string& descriptor,
- const ClassLoader* class_loader) {
- CHECK_NE(descriptor.size(), 0U);
+Class* ClassLinker::FindClass(const char* descriptor, const ClassLoader* class_loader) {
+ DCHECK(*descriptor != '\0') << "descriptor is empty string";
Thread* self = Thread::Current();
DCHECK(self != NULL);
CHECK(!self->IsExceptionPending()) << PrettyTypeOf(self->GetException());
- if (descriptor.size() == 1) {
+ if (descriptor[1] == '\0') {
// only the descriptors of primitive types should be 1 character long, also avoid class lookup
// for primitive classes that aren't backed by dex files.
return FindPrimitiveClass(descriptor[0]);
@@ -1050,11 +1058,11 @@
}
}
- ThrowNoClassDefFoundError("Class %s not found", PrintableString(descriptor).c_str());
+ ThrowNoClassDefFoundError("Class %s not found", PrintableString(StringPiece(descriptor)).c_str());
return NULL;
}
-Class* ClassLinker::DefineClass(const std::string& descriptor,
+Class* ClassLinker::DefineClass(const StringPiece& descriptor,
const ClassLoader* class_loader,
const DexFile& dex_file,
const DexFile::ClassDef& dex_class_def) {
@@ -1094,7 +1102,7 @@
if (!success) {
// We may fail to insert if we raced with another thread.
klass->SetClinitThreadId(0);
- klass.reset(LookupClass(descriptor, class_loader));
+ klass.reset(LookupClass(descriptor.data(), class_loader));
CHECK(klass.get() != NULL);
return klass.get();
}
@@ -1454,12 +1462,11 @@
// array class; that always comes from the base element class.
//
// Returns NULL with an exception raised on failure.
-Class* ClassLinker::CreateArrayClass(const std::string& descriptor,
- const ClassLoader* class_loader) {
+Class* ClassLinker::CreateArrayClass(const std::string& descriptor, const ClassLoader* class_loader) {
CHECK_EQ('[', descriptor[0]);
// Identify the underlying component type
- Class* component_type = FindClass(descriptor.substr(1), class_loader);
+ Class* component_type = FindClass(descriptor.substr(1).c_str(), class_loader);
if (component_type == NULL) {
DCHECK(Thread::Current()->IsExceptionPending());
return NULL;
@@ -1483,7 +1490,7 @@
// class to the hash table --- necessary because of possible races with
// other threads.)
if (class_loader != component_type->GetClassLoader()) {
- Class* new_class = LookupClass(descriptor, component_type->GetClassLoader());
+ Class* new_class = LookupClass(descriptor.c_str(), component_type->GetClassLoader());
if (new_class != NULL) {
return new_class;
}
@@ -1564,7 +1571,7 @@
// (Yes, this happens.)
// Grab the winning class.
- Class* other_class = LookupClass(descriptor, component_type->GetClassLoader());
+ Class* other_class = LookupClass(descriptor.c_str(), component_type->GetClassLoader());
DCHECK(other_class != NULL);
return other_class;
}
@@ -1597,7 +1604,7 @@
return NULL;
}
-bool ClassLinker::InsertClass(const std::string& descriptor, Class* klass, bool image_class) {
+bool ClassLinker::InsertClass(const StringPiece& descriptor, Class* klass, bool image_class) {
if (VLOG_IS_ON(class_linker)) {
DexCache* dex_cache = klass->GetDexCache();
std::string source;
@@ -1620,8 +1627,8 @@
return ((*it).second == klass);
}
-bool ClassLinker::RemoveClass(const std::string& descriptor, const ClassLoader* class_loader) {
- size_t hash = StringPieceHash()(descriptor);
+bool ClassLinker::RemoveClass(const char* descriptor, const ClassLoader* class_loader) {
+ size_t hash = Hash(descriptor);
MutexLock mu(classes_lock_);
typedef Table::const_iterator It; // TODO: C++0x auto
// TODO: determine if its better to search classes_ or image_classes_ first
@@ -1629,7 +1636,7 @@
for (It it = classes_.find(hash), end = classes_.end(); it != end; ++it) {
Class* klass = it->second;
kh.ChangeClass(klass);
- if (kh.GetDescriptor() == descriptor && klass->GetClassLoader() == class_loader) {
+ if (strcmp(kh.GetDescriptor(), descriptor) == 0 && klass->GetClassLoader() == class_loader) {
classes_.erase(it);
return true;
}
@@ -1637,7 +1644,7 @@
for (It it = image_classes_.find(hash), end = image_classes_.end(); it != end; ++it) {
Class* klass = it->second;
kh.ChangeClass(klass);
- if (kh.GetDescriptor() == descriptor && klass->GetClassLoader() == class_loader) {
+ if (strcmp(kh.GetDescriptor(), descriptor) == 0 && klass->GetClassLoader() == class_loader) {
image_classes_.erase(it);
return true;
}
@@ -1645,8 +1652,8 @@
return false;
}
-Class* ClassLinker::LookupClass(const std::string& descriptor, const ClassLoader* class_loader) {
- size_t hash = StringPieceHash()(descriptor);
+Class* ClassLinker::LookupClass(const char* descriptor, const ClassLoader* class_loader) {
+ size_t hash = Hash(descriptor);
MutexLock mu(classes_lock_);
typedef Table::const_iterator It; // TODO: C++0x auto
// TODO: determine if its better to search classes_ or image_classes_ first
@@ -1654,23 +1661,23 @@
for (It it = classes_.find(hash), end = classes_.end(); it != end; ++it) {
Class* klass = it->second;
kh.ChangeClass(klass);
- if (descriptor == kh.GetDescriptor() && klass->GetClassLoader() == class_loader) {
+ if (strcmp(descriptor, kh.GetDescriptor()) == 0 && klass->GetClassLoader() == class_loader) {
return klass;
}
}
for (It it = image_classes_.find(hash), end = image_classes_.end(); it != end; ++it) {
Class* klass = it->second;
kh.ChangeClass(klass);
- if (descriptor == kh.GetDescriptor() && klass->GetClassLoader() == class_loader) {
+ if (strcmp(descriptor, kh.GetDescriptor()) == 0 && klass->GetClassLoader() == class_loader) {
return klass;
}
}
return NULL;
}
-void ClassLinker::LookupClasses(const std::string& descriptor, std::vector<Class*>& classes) {
+void ClassLinker::LookupClasses(const char* descriptor, std::vector<Class*>& classes) {
classes.clear();
- size_t hash = StringPieceHash()(descriptor);
+ size_t hash = Hash(descriptor);
MutexLock mu(classes_lock_);
typedef Table::const_iterator It; // TODO: C++0x auto
// TODO: determine if its better to search classes_ or image_classes_ first
@@ -1678,14 +1685,14 @@
for (It it = classes_.find(hash), end = classes_.end(); it != end; ++it) {
Class* klass = it->second;
kh.ChangeClass(klass);
- if (descriptor == kh.GetDescriptor()) {
+ if (strcmp(descriptor, kh.GetDescriptor()) == 0) {
classes.push_back(klass);
}
}
for (It it = image_classes_.find(hash), end = image_classes_.end(); it != end; ++it) {
Class* klass = it->second;
kh.ChangeClass(klass);
- if (descriptor == kh.GetDescriptor()) {
+ if (strcmp(descriptor, kh.GetDescriptor()) == 0) {
classes.push_back(klass);
}
}
diff --git a/src/class_linker.h b/src/class_linker.h
index bb9f7f5..6feacc0 100644
--- a/src/class_linker.h
+++ b/src/class_linker.h
@@ -55,28 +55,28 @@
// Finds a class by its descriptor, loading it if necessary.
// If class_loader is null, searches boot_class_path_.
- Class* FindClass(const std::string& descriptor, const ClassLoader* class_loader);
+ Class* FindClass(const char* descriptor, const ClassLoader* class_loader);
- Class* FindSystemClass(const std::string& descriptor) {
+ Class* FindSystemClass(const char* descriptor) {
return FindClass(descriptor, NULL);
}
// Define a new a class based on a ClassDef from a DexFile
- Class* DefineClass(const std::string& descriptor, const ClassLoader* class_loader,
+ Class* DefineClass(const StringPiece& descriptor, const ClassLoader* class_loader,
const DexFile& dex_file, const DexFile::ClassDef& dex_class_def);
// Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
// by the given 'class_loader'.
- Class* LookupClass(const std::string& descriptor, const ClassLoader* class_loader);
+ Class* LookupClass(const char* descriptor, const ClassLoader* class_loader);
// Finds all the classes with the given descriptor, regardless of ClassLoader.
- void LookupClasses(const std::string& descriptor, std::vector<Class*>& classes);
+ void LookupClasses(const char* descriptor, std::vector<Class*>& classes);
Class* FindPrimitiveClass(char type);
// General class unloading is not supported, this is used to prune
// unwanted classes during image writing.
- bool RemoveClass(const std::string& descriptor, const ClassLoader* class_loader);
+ bool RemoveClass(const char* descriptor, const ClassLoader* class_loader);
void DumpAllClasses(int flags) const;
@@ -309,8 +309,7 @@
Primitive::Type type);
- Class* CreateArrayClass(const std::string& descriptor,
- const ClassLoader* class_loader);
+ Class* CreateArrayClass(const std::string& descriptor, const ClassLoader* class_loader);
void AppendToBootClassPath(const DexFile& dex_file);
void AppendToBootClassPath(const DexFile& dex_file, SirtRef<DexCache>& dex_cache);
@@ -334,7 +333,7 @@
// Inserts a class into the class table. Returns true if the class
// was inserted.
- bool InsertClass(const std::string& descriptor, Class* klass, bool image_class);
+ bool InsertClass(const StringPiece& descriptor, Class* klass, bool image_class);
void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<DexCache>& dex_cache);
bool IsDexFileRegisteredLocked(const DexFile& dex_file) const;
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index 0129dbd..4f94e50 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -16,7 +16,7 @@
class ClassLinkerTest : public CommonTest {
protected:
void AssertNonExistentClass(const std::string& descriptor) {
- EXPECT_TRUE(class_linker_->FindSystemClass(descriptor) == NULL);
+ EXPECT_TRUE(class_linker_->FindSystemClass(descriptor.c_str()) == NULL);
Thread* self = Thread::Current();
EXPECT_TRUE(self->IsExceptionPending());
Object* exception = self->GetException();
@@ -26,7 +26,7 @@
}
void AssertPrimitiveClass(const std::string& descriptor) {
- AssertPrimitiveClass(descriptor, class_linker_->FindSystemClass(descriptor));
+ AssertPrimitiveClass(descriptor, class_linker_->FindSystemClass(descriptor.c_str()));
}
void AssertPrimitiveClass(const std::string& descriptor, const Class* primitive) {
@@ -66,7 +66,7 @@
void AssertArrayClass(const std::string& array_descriptor,
const std::string& component_type,
const ClassLoader* class_loader) {
- Class* array = class_linker_->FindClass(array_descriptor, class_loader);
+ Class* array = class_linker_->FindClass(array_descriptor.c_str(), class_loader);
ClassHelper array_component_ch(array->GetComponentType());
EXPECT_STREQ(component_type.c_str(), array_component_ch.GetDescriptor());
EXPECT_EQ(class_loader, array->GetClassLoader());
@@ -277,7 +277,7 @@
void AssertDexFileClass(ClassLoader* class_loader, const std::string& descriptor) {
ASSERT_TRUE(descriptor != NULL);
- Class* klass = class_linker_->FindSystemClass(descriptor);
+ Class* klass = class_linker_->FindSystemClass(descriptor.c_str());
ASSERT_TRUE(klass != NULL);
EXPECT_STREQ(descriptor.c_str(), ClassHelper(klass).GetDescriptor());
EXPECT_EQ(class_loader, klass->GetClassLoader());
@@ -328,7 +328,7 @@
std::vector<CheckOffset> offsets;
bool Check() {
- Class* klass = Runtime::Current()->GetClassLinker()->FindSystemClass(class_descriptor);
+ Class* klass = Runtime::Current()->GetClassLinker()->FindSystemClass(class_descriptor.c_str());
CHECK(klass != NULL) << class_descriptor;
bool error = false;
diff --git a/src/common_test.h b/src/common_test.h
index 5093976..396cda5 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -331,7 +331,7 @@
void CompileClass(const ClassLoader* class_loader, const char* class_name) {
std::string class_descriptor(DotToDescriptor(class_name));
- Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
+ Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
CHECK(klass != NULL) << "Class not found " << class_name;
for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
CompileMethod(klass->GetDirectMethod(i));
@@ -354,7 +354,7 @@
const char* method_name,
const char* signature) {
std::string class_descriptor(DotToDescriptor(class_name));
- Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
+ Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
CHECK(klass != NULL) << "Class not found " << class_name;
Method* method = klass->FindDirectMethod(method_name, signature);
CHECK(method != NULL) << "Direct method not found: "
@@ -367,7 +367,7 @@
const char* method_name,
const char* signature) {
std::string class_descriptor(DotToDescriptor(class_name));
- Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
+ Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
CHECK(klass != NULL) << "Class not found " << class_name;
Method* method = klass->FindVirtualMethod(method_name, signature);
CHECK(method != NULL) << "Virtual method not found: "
diff --git a/src/dalvik_system_VMRuntime.cc b/src/dalvik_system_VMRuntime.cc
index f8be881..de5252d 100644
--- a/src/dalvik_system_VMRuntime.cc
+++ b/src/dalvik_system_VMRuntime.cc
@@ -67,7 +67,7 @@
std::string descriptor;
descriptor += "[";
descriptor += ClassHelper(element_class).GetDescriptor();
- Class* array_class = class_linker->FindClass(descriptor, NULL);
+ Class* array_class = class_linker->FindClass(descriptor.c_str(), NULL);
Array* result = Array::Alloc(array_class, length);
if (result == NULL) {
return NULL;
diff --git a/src/debugger.cc b/src/debugger.cc
index 4cfc34e..7561560 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -550,7 +550,7 @@
return true;
}
-void Dbg::FindLoadedClassBySignature(const std::string& descriptor, std::vector<JDWP::RefTypeId>& ids) {
+void Dbg::FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids) {
std::vector<Class*> classes;
Runtime::Current()->GetClassLinker()->LookupClasses(descriptor, classes);
ids.clear();
diff --git a/src/debugger.h b/src/debugger.h
index bcc5d79..f8657fe 100644
--- a/src/debugger.h
+++ b/src/debugger.h
@@ -137,7 +137,7 @@
static void GetClassList(std::vector<JDWP::RefTypeId>& classes);
static void GetVisibleClassList(JDWP::ObjectId classLoaderId, uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf);
static bool GetClassInfo(JDWP::RefTypeId classId, JDWP::JdwpTypeTag* pTypeTag, uint32_t* pStatus, std::string* pDescriptor);
- static void FindLoadedClassBySignature(const std::string& descriptor, std::vector<JDWP::RefTypeId>& ids);
+ static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids);
static void GetObjectType(JDWP::ObjectId objectId, JDWP::JdwpTypeTag* pRefTypeTag, JDWP::RefTypeId* pRefTypeId);
static uint8_t GetClassObjectType(JDWP::RefTypeId refTypeId);
static bool GetSignature(JDWP::RefTypeId refTypeId, std::string& signature);
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index ab63a48..a63d4ab 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -99,7 +99,7 @@
continue;
}
std::string descriptor(DotToDescriptor(dot.c_str()));
- SirtRef<Class> klass(class_linker->FindSystemClass(descriptor));
+ SirtRef<Class> klass(class_linker->FindSystemClass(descriptor.c_str()));
if (klass.get() == NULL) {
LOG(WARNING) << "Failed to find class " << descriptor;
Thread::Current()->ClearException();
diff --git a/src/dex_verifier.cc b/src/dex_verifier.cc
index e463f47..2f91dcd 100644
--- a/src/dex_verifier.cc
+++ b/src/dex_verifier.cc
@@ -348,7 +348,7 @@
if (entry == NULL) {
Class* klass = NULL;
if (descriptor.size() != 0) {
- klass = Runtime::Current()->GetClassLinker()->FindSystemClass(descriptor);
+ klass = Runtime::Current()->GetClassLinker()->FindSystemClass(descriptor.c_str());
}
entry = new RegType(type, klass, 0, type);
entries_[type] = entry;
@@ -370,7 +370,7 @@
return *cur_entry;
}
}
- Class* klass = Runtime::Current()->GetClassLinker()->FindClass(descriptor, loader);
+ Class* klass = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str(), loader);
if (klass != NULL) {
// Able to resolve so create resolved register type
RegType* entry = new RegType(type, klass, 0, entries_.size());
diff --git a/src/dex_verifier_test.cc b/src/dex_verifier_test.cc
index a074b72..1c804af 100644
--- a/src/dex_verifier_test.cc
+++ b/src/dex_verifier_test.cc
@@ -16,7 +16,7 @@
protected:
void VerifyClass(ClassLoader* class_loader, const std::string& descriptor) {
ASSERT_TRUE(descriptor != NULL);
- Class* klass = class_linker_->FindSystemClass(descriptor);
+ Class* klass = class_linker_->FindSystemClass(descriptor.c_str());
// Verify the class
ASSERT_TRUE(DexVerifier::VerifyClass(klass));
diff --git a/src/image_writer.cc b/src/image_writer.cc
index 34ad955..8a03392 100644
--- a/src/image_writer.cc
+++ b/src/image_writer.cc
@@ -99,7 +99,7 @@
while (klass->IsArrayClass()) {
klass = klass->GetComponentType();
}
- if (klass->IsPrimitive()) {
+ if (klass->IsPrimitive()) {
return true;
}
const std::string descriptor(ClassHelper(klass).GetDescriptor());
@@ -127,7 +127,7 @@
typedef std::set<std::string>::const_iterator ClassIt; // TODO: C++0x auto
for (ClassIt it = non_image_classes.begin(), end = non_image_classes.end(); it != end; ++it) {
- class_linker->RemoveClass(*it, NULL);
+ class_linker->RemoveClass((*it).c_str(), NULL);
}
typedef Set::const_iterator CacheIt; // TODO: C++0x auto
@@ -179,7 +179,18 @@
return;
}
Class* klass = obj->AsClass();
- CHECK(image_writer->IsImageClass(klass)) << PrettyDescriptor(klass);
+ if (!image_writer->IsImageClass(klass)) {
+ image_writer->DumpImageClasses();
+ CHECK(image_writer->IsImageClass(klass)) << ClassHelper(klass).GetDescriptor()
+ << " " << PrettyDescriptor(klass);
+ }
+}
+
+void ImageWriter::DumpImageClasses() {
+ typedef std::set<std::string>::const_iterator It; // TODO: C++0x auto
+ for (It it = image_classes_->begin(), end = image_classes_->end(); it != end; ++it) {
+ LOG(INFO) << " " << *it;
+ }
}
void ImageWriter::CalculateNewObjectOffsetsCallback(Object* obj, void* arg) {
@@ -479,7 +490,7 @@
}
// if it was unresolved or a resolved static method in an uninit class, use a resolution stub
// we need to use the stub in the static method case to ensure <clinit> is run.
- if (orig_method == NULL
+ if (orig_method == NULL
|| (orig_method->IsStatic() && !orig_method->GetDeclaringClass()->IsInitialized())) {
uint32_t orig_res_stub_code = orig_cadms->Get(CodeAndDirectMethods::CodeIndex(i));
if (orig_res_stub_code == 0) {
diff --git a/src/image_writer.h b/src/image_writer.h
index b6b02f4..d27333a 100644
--- a/src/image_writer.h
+++ b/src/image_writer.h
@@ -98,6 +98,7 @@
}
bool IsImageClass(const Class* klass);
+ void DumpImageClasses();
void PruneNonImageClasses();
static bool NonImageClassesVisitor(Class* c, void* arg);
diff --git a/src/java_lang_reflect_Array.cc b/src/java_lang_reflect_Array.cc
index 1d8b526..3bf2680 100644
--- a/src/java_lang_reflect_Array.cc
+++ b/src/java_lang_reflect_Array.cc
@@ -46,7 +46,7 @@
}
std::string sub_array_descriptor(ClassHelper(array_class).GetDescriptor() + 1);
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- Class* sub_array_class = class_linker->FindClass(sub_array_descriptor,
+ Class* sub_array_class = class_linker->FindClass(sub_array_descriptor.c_str(),
array_class->GetClassLoader());
if (sub_array_class == NULL) {
CHECK(Thread::Current()->IsExceptionPending());
@@ -106,7 +106,7 @@
// Find/generate the array class.
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- Class* array_class = class_linker->FindClass(descriptor, element_class->GetClassLoader());
+ Class* array_class = class_linker->FindClass(descriptor.c_str(), element_class->GetClassLoader());
if (array_class == NULL) {
CHECK(Thread::Current()->IsExceptionPending());
return NULL;
@@ -134,7 +134,7 @@
descriptor += ClassHelper(element_class).GetDescriptor();
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- Class* array_class = class_linker->FindClass(descriptor, element_class->GetClassLoader());
+ Class* array_class = class_linker->FindClass(descriptor.c_str(), element_class->GetClassLoader());
if (array_class == NULL) {
CHECK(Thread::Current()->IsExceptionPending());
return NULL;
diff --git a/src/jdwp/jdwp_handler.cc b/src/jdwp/jdwp_handler.cc
index 1b2ac43..e7730e5 100644
--- a/src/jdwp/jdwp_handler.cc
+++ b/src/jdwp/jdwp_handler.cc
@@ -198,7 +198,7 @@
VLOG(jdwp) << " Req for class by signature '" << classDescriptor << "'";
std::vector<RefTypeId> ids;
- Dbg::FindLoadedClassBySignature(classDescriptor, ids);
+ Dbg::FindLoadedClassBySignature(classDescriptor.c_str(), ids);
expandBufAdd4BE(pReply, ids.size());
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 82d826e..e6c7410 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -714,9 +714,9 @@
Class* c = NULL;
if (runtime->IsStarted()) {
const ClassLoader* cl = GetClassLoader(ts.Self());
- c = class_linker->FindClass(descriptor, cl);
+ c = class_linker->FindClass(descriptor.c_str(), cl);
} else {
- c = class_linker->FindSystemClass(descriptor);
+ c = class_linker->FindSystemClass(descriptor.c_str());
}
return AddLocalReference<jclass>(env, c);
}
diff --git a/src/object.cc b/src/object.cc
index 10d4289..b98235b 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -307,15 +307,15 @@
++p; // Either the ';' or the primitive type.
std::string descriptor(start, (p - start));
- return class_linker->FindClass(descriptor, cl);
+ return class_linker->FindClass(descriptor.c_str(), cl);
} else if (*p == 'L') {
const char* start = p;
while (*p != ';') {
++p;
}
++p;
- StringPiece descriptor(start, (p - start));
- return class_linker->FindClass(descriptor.ToString(), cl);
+ std::string descriptor(start, (p - start));
+ return class_linker->FindClass(descriptor.c_str(), cl);
} else {
return class_linker->FindPrimitiveClass(*p++);
}
diff --git a/src/stringpiece.h b/src/stringpiece.h
index 1338ed9..f61219f 100644
--- a/src/stringpiece.h
+++ b/src/stringpiece.h
@@ -205,7 +205,7 @@
size_t operator()(const art::StringPiece& string_piece) const {
size_t string_size = string_piece.size();
const char* string_data = string_piece.data();
- // this is the java.lang.String hashcode for convenience, not interoperability
+ // This is the java.lang.String hashcode for convenience, not interoperability.
size_t hash = 0;
while (string_size--) {
hash = hash * 31 + *string_data++;
diff --git a/src/utils.cc b/src/utils.cc
index ced68de..bfc2272 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -268,10 +268,10 @@
return descriptor;
}
-std::string DescriptorToDot(const std::string& descriptor) {
+std::string DescriptorToDot(const StringPiece& descriptor) {
DCHECK_EQ(descriptor[0], 'L');
DCHECK_EQ(descriptor[descriptor.size()-1], ';');
- std::string dot(descriptor.substr(1, descriptor.size() - 2));
+ std::string dot(descriptor.substr(1, descriptor.size() - 2).ToString());
std::replace(dot.begin(), dot.end(), '/', '.');
return dot;
}
diff --git a/src/utils.h b/src/utils.h
index b402b46..22afd5d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -191,7 +191,7 @@
std::string DotToDescriptor(const char* class_name);
// Turn "Ljava/lang/String;" into "java.lang.String".
-std::string DescriptorToDot(const std::string& descriptor);
+std::string DescriptorToDot(const StringPiece& descriptor);
// Tests for whether 's' is a valid class name in the three common forms:
bool IsValidBinaryClassName(const char* s); // "java.lang.String"