Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: runtime/vm/kernel_to_il.cc

Issue 3003023002: Avoid triggering an ASSERT in TypedData (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <set> 5 #include <set>
6 6
7 #include "vm/kernel_to_il.h" 7 #include "vm/kernel_to_il.h"
8 8
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/intermediate_language.h" 10 #include "vm/intermediate_language.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 intptr_t TranslationHelper::StringSize(StringIndex index) const { 129 intptr_t TranslationHelper::StringSize(StringIndex index) const {
130 return StringOffset(StringIndex(index + 1)) - StringOffset(index); 130 return StringOffset(StringIndex(index + 1)) - StringOffset(index);
131 } 131 }
132 132
133 uint8_t TranslationHelper::CharacterAt(StringIndex string_index, 133 uint8_t TranslationHelper::CharacterAt(StringIndex string_index,
134 intptr_t index) { 134 intptr_t index) {
135 ASSERT(index < StringSize(string_index)); 135 ASSERT(index < StringSize(string_index));
136 return string_data_.GetUint8(StringOffset(string_index) + index); 136 return string_data_.GetUint8(StringOffset(string_index) + index);
137 } 137 }
138 138
139 uint8_t* TranslationHelper::StringBuffer(StringIndex string_index) const {
140 // Though this implementation appears like it could be replaced by
141 // string_data_.DataAddr(StringOffset(string_index)), it can't quite. If the
142 // last string in the string table is a zero length string, then the latter
143 // expression will try to return the address that is one past the backing
144 // store of the string_data_ table. Though this is safe in C++ as long as the
145 // address is not dereferenced, it will trigger the assert in
146 // TypedData::DataAddr.
147 ASSERT(Thread::Current()->no_safepoint_scope_depth() > 0);
148 return reinterpret_cast<uint8_t*>(string_data_.DataAddr(0)) +
149 StringOffset(string_index);
150 }
151
139 bool TranslationHelper::StringEquals(StringIndex string_index, 152 bool TranslationHelper::StringEquals(StringIndex string_index,
140 const char* other) { 153 const char* other) {
154 intptr_t length = strlen(other);
155 if (length != StringSize(string_index)) return false;
156
141 NoSafepointScope no_safepoint; 157 NoSafepointScope no_safepoint;
142 intptr_t length = strlen(other); 158 return memcmp(StringBuffer(string_index), other, length) == 0;
143 return (length == StringSize(string_index)) &&
144 (memcmp(string_data_.DataAddr(StringOffset(string_index)), other,
145 length) == 0);
146 } 159 }
147 160
148 NameIndex TranslationHelper::CanonicalNameParent(NameIndex name) { 161 NameIndex TranslationHelper::CanonicalNameParent(NameIndex name) {
149 // Canonical names are pairs of 4-byte parent and string indexes, so the size 162 // Canonical names are pairs of 4-byte parent and string indexes, so the size
150 // of an entry is 8 bytes. The parent is biased: 0 represents the root name 163 // of an entry is 8 bytes. The parent is biased: 0 represents the root name
151 // and N+1 represents the name with index N. 164 // and N+1 represents the name with index N.
152 return NameIndex(static_cast<intptr_t>(canonical_names_.GetUint32(8 * name)) - 165 return NameIndex(static_cast<intptr_t>(canonical_names_.GetUint32(8 * name)) -
153 1); 166 1);
154 } 167 }
155 168
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 Heap::Space space) { 317 Heap::Space space) {
305 return String::ZoneHandle(Z, String::New(content, space)); 318 return String::ZoneHandle(Z, String::New(content, space));
306 } 319 }
307 320
308 String& TranslationHelper::DartString(StringIndex string_index, 321 String& TranslationHelper::DartString(StringIndex string_index,
309 Heap::Space space) { 322 Heap::Space space) {
310 intptr_t length = StringSize(string_index); 323 intptr_t length = StringSize(string_index);
311 uint8_t* buffer = Z->Alloc<uint8_t>(length); 324 uint8_t* buffer = Z->Alloc<uint8_t>(length);
312 { 325 {
313 NoSafepointScope no_safepoint; 326 NoSafepointScope no_safepoint;
314 memmove(buffer, string_data_.DataAddr(StringOffset(string_index)), length); 327 memmove(buffer, StringBuffer(string_index), length);
315 } 328 }
316 return String::ZoneHandle(Z, String::FromUTF8(buffer, length, space)); 329 return String::ZoneHandle(Z, String::FromUTF8(buffer, length, space));
317 } 330 }
318 331
319 String& TranslationHelper::DartString(const uint8_t* utf8_array, 332 String& TranslationHelper::DartString(const uint8_t* utf8_array,
320 intptr_t len, 333 intptr_t len,
321 Heap::Space space) { 334 Heap::Space space) {
322 return String::ZoneHandle(Z, String::FromUTF8(utf8_array, len, space)); 335 return String::ZoneHandle(Z, String::FromUTF8(utf8_array, len, space));
323 } 336 }
324 337
325 const String& TranslationHelper::DartSymbol(const char* content) const { 338 const String& TranslationHelper::DartSymbol(const char* content) const {
326 return String::ZoneHandle(Z, Symbols::New(thread_, content)); 339 return String::ZoneHandle(Z, Symbols::New(thread_, content));
327 } 340 }
328 341
329 String& TranslationHelper::DartSymbol(StringIndex string_index) const { 342 String& TranslationHelper::DartSymbol(StringIndex string_index) const {
330 intptr_t length = StringSize(string_index); 343 intptr_t length = StringSize(string_index);
331 uint8_t* buffer = Z->Alloc<uint8_t>(length); 344 uint8_t* buffer = Z->Alloc<uint8_t>(length);
332 { 345 {
333 NoSafepointScope no_safepoint; 346 NoSafepointScope no_safepoint;
334 memmove(buffer, string_data_.DataAddr(StringOffset(string_index)), length); 347 memmove(buffer, StringBuffer(string_index), length);
335 } 348 }
336 return String::ZoneHandle(Z, Symbols::FromUTF8(thread_, buffer, length)); 349 return String::ZoneHandle(Z, Symbols::FromUTF8(thread_, buffer, length));
337 } 350 }
338 351
339 String& TranslationHelper::DartSymbol(const uint8_t* utf8_array, 352 String& TranslationHelper::DartSymbol(const uint8_t* utf8_array,
340 intptr_t len) const { 353 intptr_t len) const {
341 return String::ZoneHandle(Z, Symbols::FromUTF8(thread_, utf8_array, len)); 354 return String::ZoneHandle(Z, Symbols::FromUTF8(thread_, utf8_array, len));
342 } 355 }
343 356
344 const String& TranslationHelper::DartClassName(NameIndex kernel_class) { 357 const String& TranslationHelper::DartClassName(NameIndex kernel_class) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // => In order to be consistent, we remove the `=` always and adopt the VM 394 // => In order to be consistent, we remove the `=` always and adopt the VM
382 // conventions. 395 // conventions.
383 intptr_t size = StringSize(setter); 396 intptr_t size = StringSize(setter);
384 ASSERT(size > 0); 397 ASSERT(size > 0);
385 if (CharacterAt(setter, size - 1) == '=') { 398 if (CharacterAt(setter, size - 1) == '=') {
386 --size; 399 --size;
387 } 400 }
388 uint8_t* buffer = Z->Alloc<uint8_t>(size); 401 uint8_t* buffer = Z->Alloc<uint8_t>(size);
389 { 402 {
390 NoSafepointScope no_safepoint; 403 NoSafepointScope no_safepoint;
391 memmove(buffer, string_data_.DataAddr(StringOffset(setter)), size); 404 memmove(buffer, StringBuffer(setter), size);
392 } 405 }
393 String& name = 406 String& name =
394 String::ZoneHandle(Z, String::FromUTF8(buffer, size, allocation_space_)); 407 String::ZoneHandle(Z, String::FromUTF8(buffer, size, allocation_space_));
395 ManglePrivateName(parent, &name, false); 408 ManglePrivateName(parent, &name, false);
396 name = Field::SetterSymbol(name); 409 name = Field::SetterSymbol(name);
397 return name; 410 return name;
398 } 411 }
399 412
400 const String& TranslationHelper::DartGetterName(NameIndex getter) { 413 const String& TranslationHelper::DartGetterName(NameIndex getter) {
401 return DartGetterName(CanonicalNameParent(getter), 414 return DartGetterName(CanonicalNameParent(getter),
(...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 array_object = AsSortedDuplicateFreeArray(&token_positions); 2414 array_object = AsSortedDuplicateFreeArray(&token_positions);
2402 script.set_debug_positions(array_object); 2415 script.set_debug_positions(array_object);
2403 array_object = AsSortedDuplicateFreeArray(&yield_positions); 2416 array_object = AsSortedDuplicateFreeArray(&yield_positions);
2404 script.set_yield_positions(array_object); 2417 script.set_yield_positions(array_object);
2405 } 2418 }
2406 2419
2407 } // namespace kernel 2420 } // namespace kernel
2408 } // namespace dart 2421 } // namespace dart
2409 2422
2410 #endif // !defined(DART_PRECOMPILED_RUNTIME) 2423 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698