blob: 0ce45b855b98474c7c57db375492b095c8b4ac31 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Gampefd63bbf2018-10-29 12:55:35 -070017#include "string-alloc-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080018
Andreas Gampe4d0589c2014-06-10 16:10:56 -070019#include "arch/memcmp16.h"
Andreas Gampe8e0f0432018-10-24 13:38:03 -070020#include "array-alloc-inl.h"
Andreas Gampe2ff3b972017-06-05 18:14:53 -070021#include "base/array_ref.h"
Andreas Gampe5678db52017-06-08 14:11:18 -070022#include "base/stl_util.h"
Hiroshi Yamauchi967a0ad2013-09-10 16:24:21 -070023#include "class-inl.h"
David Sehrb2ec9f52018-02-21 13:20:31 -080024#include "dex/descriptors_names.h"
David Sehr0225f8e2018-01-31 08:52:24 +000025#include "dex/utf-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070026#include "gc/accounting/card_table-inl.h"
Jeff Hao848f70a2014-01-15 13:49:50 -080027#include "handle_scope-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028#include "intern_table.h"
29#include "object-inl.h"
30#include "runtime.h"
Jeff Hao848f70a2014-01-15 13:49:50 -080031#include "string-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "thread.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033
34namespace art {
35namespace mirror {
36
Ian Rogersef7d42f2014-01-06 12:55:46 -080037int32_t String::FastIndexOf(int32_t ch, int32_t start) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038 int32_t count = GetLength();
39 if (start < 0) {
40 start = 0;
41 } else if (start > count) {
42 start = count;
43 }
jessicahandojo3aaa37b2016-07-29 14:46:37 -070044 if (IsCompressed()) {
45 return FastIndexOf<uint8_t>(GetValueCompressed(), ch, start);
46 } else {
47 return FastIndexOf<uint16_t>(GetValue(), ch, start);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049}
50
Jeff Hao848f70a2014-01-15 13:49:50 -080051int String::ComputeHashCode() {
jessicahandojo3aaa37b2016-07-29 14:46:37 -070052 int32_t hash_code = 0;
53 if (IsCompressed()) {
54 hash_code = ComputeUtf16Hash(GetValueCompressed(), GetLength());
55 } else {
56 hash_code = ComputeUtf16Hash(GetValue(), GetLength());
57 }
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -070058 SetHashCode(hash_code);
59 return hash_code;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060}
61
Vladimir Marko92907f32017-02-20 14:08:30 +000062inline bool String::AllASCIIExcept(const uint16_t* chars, int32_t length, uint16_t non_ascii) {
63 DCHECK(!IsASCII(non_ascii));
64 for (int32_t i = 0; i < length; ++i) {
65 if (!IsASCII(chars[i]) && chars[i] != non_ascii) {
66 return false;
67 }
jessicahandojo3aaa37b2016-07-29 14:46:37 -070068 }
Vladimir Marko92907f32017-02-20 14:08:30 +000069 return true;
70}
71
Vladimir Marko9e57aba2017-03-16 10:45:40 +000072ObjPtr<String> String::DoReplace(Thread* self, Handle<String> src, uint16_t old_c, uint16_t new_c) {
73 int32_t length = src->GetLength();
74 DCHECK(src->IsCompressed()
75 ? ContainsElement(ArrayRef<uint8_t>(src->value_compressed_, length), old_c)
76 : ContainsElement(ArrayRef<uint16_t>(src->value_, length), old_c));
Vladimir Marko92907f32017-02-20 14:08:30 +000077 bool compressible =
78 kUseStringCompression &&
79 IsASCII(new_c) &&
Vladimir Marko9e57aba2017-03-16 10:45:40 +000080 (src->IsCompressed() || (!IsASCII(old_c) && AllASCIIExcept(src->value_, length, old_c)));
Vladimir Marko92907f32017-02-20 14:08:30 +000081 gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
Vladimir Marko9e57aba2017-03-16 10:45:40 +000082 const int32_t length_with_flag = String::GetFlaggedCount(length, compressible);
Vladimir Marko76295482020-10-26 12:28:37 +000083
84 auto visitor = [=](ObjPtr<Object> obj, size_t usable_size) REQUIRES_SHARED(Locks::mutator_lock_) {
85 SetStringCountVisitor set_string_count_visitor(length_with_flag);
86 set_string_count_visitor(obj, usable_size);
87 ObjPtr<String> new_string = obj->AsString();
88 if (compressible) {
89 auto replace = [old_c, new_c](uint16_t c) {
90 return dchecked_integral_cast<uint8_t>((old_c != c) ? c : new_c);
91 };
92 uint8_t* out = new_string->value_compressed_;
93 if (LIKELY(src->IsCompressed())) { // LIKELY(compressible == src->IsCompressed())
94 std::transform(src->value_compressed_, src->value_compressed_ + length, out, replace);
95 } else {
96 std::transform(src->value_, src->value_ + length, out, replace);
97 }
98 DCHECK(kUseStringCompression && AllASCII(out, length));
Vladimir Marko92907f32017-02-20 14:08:30 +000099 } else {
Vladimir Marko76295482020-10-26 12:28:37 +0000100 auto replace = [old_c, new_c](uint16_t c) {
101 return (old_c != c) ? c : new_c;
102 };
103 uint16_t* out = new_string->value_;
104 if (UNLIKELY(src->IsCompressed())) { // LIKELY(compressible == src->IsCompressed())
105 std::transform(src->value_compressed_, src->value_compressed_ + length, out, replace);
106 } else {
107 std::transform(src->value_, src->value_ + length, out, replace);
108 }
109 DCHECK(!kUseStringCompression || !AllASCII(out, length));
Vladimir Marko92907f32017-02-20 14:08:30 +0000110 }
Vladimir Marko76295482020-10-26 12:28:37 +0000111 };
112 return Alloc(self, length_with_flag, allocator_type, visitor);
Jeff Hao848f70a2014-01-15 13:49:50 -0800113}
114
Vladimir Marko036b0702020-10-27 10:36:06 +0000115ObjPtr<String> String::DoConcat(Thread* self, Handle<String> h_this, Handle<String> h_arg) {
116 int32_t length_this = h_this->GetLength();
117 int32_t length_arg = h_arg->GetLength();
Jeff Hao848f70a2014-01-15 13:49:50 -0800118 gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
Vladimir Marko036b0702020-10-27 10:36:06 +0000119 const bool compressible =
120 kUseStringCompression && (h_this->IsCompressed() && h_arg->IsCompressed());
121 const int32_t length_with_flag = String::GetFlaggedCount(length_this + length_arg, compressible);
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700122
Vladimir Marko76295482020-10-26 12:28:37 +0000123 auto visitor = [=](ObjPtr<Object> obj, size_t usable_size) REQUIRES_SHARED(Locks::mutator_lock_) {
124 SetStringCountVisitor set_string_count_visitor(length_with_flag);
125 set_string_count_visitor(obj, usable_size);
126 ObjPtr<String> new_string = obj->AsString();
127 if (compressible) {
128 uint8_t* new_value = new_string->GetValueCompressed();
Vladimir Marko036b0702020-10-27 10:36:06 +0000129 memcpy(new_value, h_this->GetValueCompressed(), length_this * sizeof(uint8_t));
130 memcpy(new_value + length_this, h_arg->GetValueCompressed(), length_arg * sizeof(uint8_t));
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700131 } else {
Vladimir Marko76295482020-10-26 12:28:37 +0000132 uint16_t* new_value = new_string->GetValue();
Vladimir Marko036b0702020-10-27 10:36:06 +0000133 if (h_this->IsCompressed()) {
134 const uint8_t* value_this = h_this->GetValueCompressed();
135 for (int i = 0; i < length_this; ++i) {
136 new_value[i] = value_this[i];
Vladimir Marko76295482020-10-26 12:28:37 +0000137 }
138 } else {
Vladimir Marko036b0702020-10-27 10:36:06 +0000139 memcpy(new_value, h_this->GetValue(), length_this * sizeof(uint16_t));
chapin15efe162020-10-23 19:20:31 +0000140 }
Vladimir Marko036b0702020-10-27 10:36:06 +0000141 if (h_arg->IsCompressed()) {
142 const uint8_t* value_arg = h_arg->GetValueCompressed();
143 for (int i = 0; i < length_arg; ++i) {
144 new_value[i + length_this] = value_arg[i];
Vladimir Marko76295482020-10-26 12:28:37 +0000145 }
146 } else {
Vladimir Marko036b0702020-10-27 10:36:06 +0000147 memcpy(new_value + length_this, h_arg->GetValue(), length_arg * sizeof(uint16_t));
Vladimir Marko76295482020-10-26 12:28:37 +0000148 }
chapin15efe162020-10-23 19:20:31 +0000149 }
Vladimir Marko76295482020-10-26 12:28:37 +0000150 };
151 return Alloc(self, length_with_flag, allocator_type, visitor);
Jeff Hao848f70a2014-01-15 13:49:50 -0800152}
153
Vladimir Marko179b7c62019-03-22 13:38:57 +0000154ObjPtr<String> String::AllocFromUtf16(Thread* self,
155 int32_t utf16_length,
156 const uint16_t* utf16_data_in) {
Ian Rogers4069d332014-01-03 10:28:27 -0800157 CHECK(utf16_data_in != nullptr || utf16_length == 0);
Jeff Hao848f70a2014-01-15 13:49:50 -0800158 gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700159 const bool compressible = kUseStringCompression &&
160 String::AllASCII<uint16_t>(utf16_data_in, utf16_length);
Vladimir Markofdaf0f42016-10-13 19:29:53 +0100161 int32_t length_with_flag = String::GetFlaggedCount(utf16_length, compressible);
Vladimir Marko76295482020-10-26 12:28:37 +0000162
163 auto visitor = [=](ObjPtr<Object> obj, size_t usable_size) REQUIRES_SHARED(Locks::mutator_lock_) {
164 SetStringCountVisitor set_string_count_visitor(length_with_flag);
165 set_string_count_visitor(obj, usable_size);
166 ObjPtr<String> new_string = obj->AsString();
167 if (compressible) {
168 uint8_t* value = new_string->GetValueCompressed();
169 for (int i = 0; i < utf16_length; ++i) {
170 value[i] = static_cast<uint8_t>(utf16_data_in[i]);
171 }
172 } else {
173 memcpy(new_string->GetValue(), utf16_data_in, utf16_length * sizeof(uint16_t));
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700174 }
Vladimir Marko76295482020-10-26 12:28:37 +0000175 };
176 return Alloc(self, length_with_flag, allocator_type, visitor);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177}
178
Vladimir Marko179b7c62019-03-22 13:38:57 +0000179ObjPtr<String> String::AllocFromModifiedUtf8(Thread* self, const char* utf) {
Mathieu Chartiered0fc1d2014-03-21 14:09:35 -0700180 DCHECK(utf != nullptr);
Bruce Hoult1646d7a2015-10-28 15:06:12 +0300181 size_t byte_count = strlen(utf);
182 size_t char_count = CountModifiedUtf8Chars(utf, byte_count);
183 return AllocFromModifiedUtf8(self, char_count, utf, byte_count);
184}
185
Vladimir Marko179b7c62019-03-22 13:38:57 +0000186ObjPtr<String> String::AllocFromModifiedUtf8(Thread* self,
187 int32_t utf16_length,
188 const char* utf8_data_in) {
Bruce Hoult1646d7a2015-10-28 15:06:12 +0300189 return AllocFromModifiedUtf8(self, utf16_length, utf8_data_in, strlen(utf8_data_in));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190}
191
Vladimir Marko179b7c62019-03-22 13:38:57 +0000192ObjPtr<String> String::AllocFromModifiedUtf8(Thread* self,
193 int32_t utf16_length,
194 const char* utf8_data_in,
195 int32_t utf8_length) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800196 gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700197 const bool compressible = kUseStringCompression && (utf16_length == utf8_length);
Vladimir Marko76295482020-10-26 12:28:37 +0000198 const int32_t length_with_flag = String::GetFlaggedCount(utf16_length, compressible);
199
200 auto visitor = [=](ObjPtr<Object> obj, size_t usable_size) REQUIRES_SHARED(Locks::mutator_lock_) {
201 SetStringCountVisitor set_string_count_visitor(length_with_flag);
202 set_string_count_visitor(obj, usable_size);
203 ObjPtr<String> new_string = obj->AsString();
204 if (compressible) {
205 memcpy(new_string->GetValueCompressed(), utf8_data_in, utf16_length * sizeof(uint8_t));
206 } else {
207 uint16_t* utf16_data_out = new_string->GetValue();
208 ConvertModifiedUtf8ToUtf16(utf16_data_out, utf16_length, utf8_data_in, utf8_length);
209 }
210 };
211 return Alloc(self, length_with_flag, allocator_type, visitor);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212}
213
Mathieu Chartier31e88222016-10-14 18:43:19 -0700214bool String::Equals(ObjPtr<String> that) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 if (this == that) {
216 // Quick reference equality test
217 return true;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700218 } else if (that == nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 // Null isn't an instanceof anything
220 return false;
Vladimir Marko76295482020-10-26 12:28:37 +0000221 } else if (this->GetCount() != that->GetCount()) {
222 // Quick length and compression inequality test
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223 return false;
224 } else {
225 // Note: don't short circuit on hash code as we're presumably here as the
226 // hash code was already equal
Vladimir Marko76295482020-10-26 12:28:37 +0000227 if (this->IsCompressed()) {
228 return memcmp(this->GetValueCompressed(), that->GetValueCompressed(), this->GetLength()) == 0;
229 } else {
230 return memcmp(this->GetValue(), that->GetValue(), sizeof(uint16_t) * this->GetLength()) == 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 }
233}
234
Ian Rogersef7d42f2014-01-06 12:55:46 -0800235bool String::Equals(const char* modified_utf8) {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000236 const int32_t length = GetLength();
Vladimir Marko76295482020-10-26 12:28:37 +0000237 if (IsCompressed()) {
238 return strlen(modified_utf8) == dchecked_integral_cast<uint32_t>(length) &&
239 memcmp(modified_utf8, GetValueCompressed(), length) == 0;
240 }
241 const uint16_t* value = GetValue();
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000242 int32_t i = 0;
243 while (i < length) {
244 const uint32_t ch = GetUtf16FromUtf8(&modified_utf8);
245 if (ch == '\0') {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246 return false;
247 }
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000248
Vladimir Marko76295482020-10-26 12:28:37 +0000249 if (GetLeadingUtf16Char(ch) != value[i++]) {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000250 return false;
251 }
252
253 const uint16_t trailing = GetTrailingUtf16Char(ch);
254 if (trailing != 0) {
255 if (i == length) {
256 return false;
257 }
258
Vladimir Marko76295482020-10-26 12:28:37 +0000259 if (value[i++] != trailing) {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000260 return false;
261 }
262 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800263 }
264 return *modified_utf8 == '\0';
265}
266
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800267// Create a modified UTF-8 encoded std::string from a java/lang/String object.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268std::string String::ToModifiedUtf8() {
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700269 if (IsCompressed()) {
Vladimir Marko76295482020-10-26 12:28:37 +0000270 return std::string(reinterpret_cast<const char*>(GetValueCompressed()), GetLength());
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700271 } else {
Vladimir Marko76295482020-10-26 12:28:37 +0000272 size_t byte_count = GetUtfLength();
273 std::string result(byte_count, static_cast<char>(0));
274 ConvertUtf16ToModifiedUtf8(&result[0], byte_count, GetValue(), GetLength());
275 return result;
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700276 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277}
278
Mathieu Chartier31e88222016-10-14 18:43:19 -0700279int32_t String::CompareTo(ObjPtr<String> rhs) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800280 // Quick test for comparison of a string with itself.
Mathieu Chartier31e88222016-10-14 18:43:19 -0700281 ObjPtr<String> lhs = this;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 if (lhs == rhs) {
283 return 0;
284 }
Vladimir Marko9c9883b2016-10-17 14:45:29 +0100285 int32_t lhs_count = lhs->GetLength();
286 int32_t rhs_count = rhs->GetLength();
287 int32_t count_diff = lhs_count - rhs_count;
288 int32_t min_count = (count_diff < 0) ? lhs_count : rhs_count;
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700289 if (lhs->IsCompressed() && rhs->IsCompressed()) {
Vladimir Marko9c9883b2016-10-17 14:45:29 +0100290 const uint8_t* lhs_chars = lhs->GetValueCompressed();
291 const uint8_t* rhs_chars = rhs->GetValueCompressed();
292 for (int32_t i = 0; i < min_count; ++i) {
293 int32_t char_diff = static_cast<int32_t>(lhs_chars[i]) - static_cast<int32_t>(rhs_chars[i]);
294 if (char_diff != 0) {
295 return char_diff;
296 }
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700297 }
298 } else if (lhs->IsCompressed() || rhs->IsCompressed()) {
Vladimir Marko9c9883b2016-10-17 14:45:29 +0100299 const uint8_t* compressed_chars =
300 lhs->IsCompressed() ? lhs->GetValueCompressed() : rhs->GetValueCompressed();
301 const uint16_t* uncompressed_chars = lhs->IsCompressed() ? rhs->GetValue() : lhs->GetValue();
302 for (int32_t i = 0; i < min_count; ++i) {
303 int32_t char_diff =
304 static_cast<int32_t>(compressed_chars[i]) - static_cast<int32_t>(uncompressed_chars[i]);
305 if (char_diff != 0) {
306 return lhs->IsCompressed() ? char_diff : -char_diff;
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700307 }
308 }
309 } else {
Vladimir Marko9c9883b2016-10-17 14:45:29 +0100310 const uint16_t* lhs_chars = lhs->GetValue();
311 const uint16_t* rhs_chars = rhs->GetValue();
312 // FIXME: The MemCmp16() name is misleading. It returns the char difference on mismatch
313 // where memcmp() only guarantees that the returned value has the same sign.
314 int32_t char_diff = MemCmp16(lhs_chars, rhs_chars, min_count);
315 if (char_diff != 0) {
316 return char_diff;
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700317 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318 }
Vladimir Marko9c9883b2016-10-17 14:45:29 +0100319 return count_diff;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320}
321
Vladimir Marko3068d582019-05-28 16:39:29 +0100322ObjPtr<CharArray> String::ToCharArray(Handle<String> h_this, Thread* self) {
323 ObjPtr<CharArray> result = CharArray::Alloc(self, h_this->GetLength());
Mathieu Chartier04e983a2015-11-13 08:36:59 -0800324 if (result != nullptr) {
Vladimir Marko3068d582019-05-28 16:39:29 +0100325 if (h_this->IsCompressed()) {
326 int32_t length = h_this->GetLength();
Vladimir Marko76295482020-10-26 12:28:37 +0000327 const uint8_t* src = h_this->GetValueCompressed();
328 uint16_t* dest = result->GetData();
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700329 for (int i = 0; i < length; ++i) {
Vladimir Marko76295482020-10-26 12:28:37 +0000330 dest[i] = src[i];
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700331 }
332 } else {
Vladimir Marko3068d582019-05-28 16:39:29 +0100333 memcpy(result->GetData(), h_this->GetValue(), h_this->GetLength() * sizeof(uint16_t));
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700334 }
Mathieu Chartier04e983a2015-11-13 08:36:59 -0800335 } else {
336 self->AssertPendingOOMException();
337 }
Vladimir Marko179b7c62019-03-22 13:38:57 +0000338 return result;
Jeff Hao848f70a2014-01-15 13:49:50 -0800339}
340
341void String::GetChars(int32_t start, int32_t end, Handle<CharArray> array, int32_t index) {
342 uint16_t* data = array->GetData() + index;
Vladimir Marko76295482020-10-26 12:28:37 +0000343 DCHECK_LE(start, end);
344 int32_t length = end - start;
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700345 if (IsCompressed()) {
Vladimir Marko76295482020-10-26 12:28:37 +0000346 const uint8_t* value = GetValueCompressed() + start;
347 for (int i = 0; i < length; ++i) {
348 data[i] = value[i];
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700349 }
350 } else {
351 uint16_t* value = GetValue() + start;
Vladimir Marko76295482020-10-26 12:28:37 +0000352 memcpy(data, value, length * sizeof(uint16_t));
jessicahandojo3aaa37b2016-07-29 14:46:37 -0700353 }
354}
355
356bool String::IsValueNull() {
357 return (IsCompressed()) ? (GetValueCompressed() == nullptr) : (GetValue() == nullptr);
Jeff Hao848f70a2014-01-15 13:49:50 -0800358}
359
David Sehr709b0702016-10-13 09:12:37 -0700360std::string String::PrettyStringDescriptor(ObjPtr<mirror::String> java_descriptor) {
361 if (java_descriptor == nullptr) {
362 return "null";
363 }
364 return java_descriptor->PrettyStringDescriptor();
365}
366
367std::string String::PrettyStringDescriptor() {
368 return PrettyDescriptor(ToModifiedUtf8().c_str());
369}
370
Andreas Gampeb2d18fa2017-06-06 20:46:10 -0700371ObjPtr<String> String::Intern() {
372 return Runtime::Current()->GetInternTable()->InternWeak(this);
373}
374
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375} // namespace mirror
376} // namespace art