summaryrefslogtreecommitdiffstats
path: root/runtime/mirror/string.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/mirror/string.cc')
-rw-r--r--runtime/mirror/string.cc16
1 files changed, 11 insertions, 5 deletions
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc
index 6f4ead9a7a..cd63c39b1d 100644
--- a/runtime/mirror/string.cc
+++ b/runtime/mirror/string.cc
@@ -33,7 +33,7 @@ CharArray* String::GetCharArray() {
return GetFieldObject<CharArray>(ValueOffset(), false);
}
-void String::ComputeHashCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+void String::ComputeHashCode() {
SetHashCode(ComputeUtf16Hash(GetCharArray(), GetOffset(), GetLength()));
}
@@ -59,9 +59,10 @@ int32_t String::FastIndexOf(int32_t ch, int32_t start) {
return -1;
}
-void String::SetArray(CharArray* new_array) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+template<bool kTransactionActive>
+void String::SetArray(CharArray* new_array) {
DCHECK(new_array != NULL);
- SetFieldObject(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false);
+ SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false);
}
// TODO: get global references for these
@@ -169,8 +170,13 @@ String* String::Alloc(Thread* self, const SirtRef<CharArray>& array) {
// Hold reference in case AllocObject causes GC.
String* string = down_cast<String*>(GetJavaLangString()->AllocObject(self));
if (LIKELY(string != nullptr)) {
- string->SetArray(array.get());
- string->SetCount(array->GetLength());
+ if (Runtime::Current()->IsActiveTransaction()) {
+ string->SetArray<true>(array.get());
+ string->SetCount<true>(array->GetLength());
+ } else {
+ string->SetArray<false>(array.get());
+ string->SetCount<false>(array->GetLength());
+ }
}
return string;
}