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

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

Issue 474033002: Ensure that hash for a symbol is not set to 0 when it is made external. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 17024 matching lines...) Expand 10 before | Expand all | Expand 10 after
17035 intptr_t length, 17035 intptr_t length,
17036 void* peer, 17036 void* peer,
17037 Dart_PeerFinalizer cback) const { 17037 Dart_PeerFinalizer cback) const {
17038 String& result = String::Handle(); 17038 String& result = String::Handle();
17039 void* external_data; 17039 void* external_data;
17040 Dart_WeakPersistentHandleFinalizer finalizer; 17040 Dart_WeakPersistentHandleFinalizer finalizer;
17041 { 17041 {
17042 NoGCScope no_gc; 17042 NoGCScope no_gc;
17043 ASSERT(array != NULL); 17043 ASSERT(array != NULL);
17044 intptr_t str_length = this->Length(); 17044 intptr_t str_length = this->Length();
17045 ASSERT(length >= (str_length * this->CharSize())); 17045 RELEASE_ASSERT(length >= (str_length * this->CharSize()));
17046 intptr_t class_id = raw()->GetClassId(); 17046 intptr_t class_id = raw()->GetClassId();
17047 intptr_t used_size = 0; 17047 intptr_t used_size = 0;
17048 intptr_t original_size = 0; 17048 intptr_t original_size = 0;
17049 uword tags = raw_ptr()->tags_; 17049 uword tags = raw_ptr()->tags_;
17050 17050
17051 ASSERT(!InVMHeap()); 17051 ASSERT(!InVMHeap());
17052 if (class_id == kOneByteStringCid) { 17052 if (class_id == kOneByteStringCid) {
17053 used_size = ExternalOneByteString::InstanceSize(); 17053 used_size = ExternalOneByteString::InstanceSize();
17054 original_size = OneByteString::InstanceSize(str_length); 17054 original_size = OneByteString::InstanceSize(str_length);
17055 ASSERT(original_size >= used_size); 17055 ASSERT(original_size >= used_size);
17056 17056
17057 // Copy the data into the external array. 17057 // Copy the data into the external array.
17058 if (str_length > 0) { 17058 if (str_length > 0) {
17059 memmove(array, OneByteString::CharAddr(*this, 0), str_length); 17059 memmove(array, OneByteString::CharAddr(*this, 0), str_length);
17060 } 17060 }
17061 17061
17062 // Update the class information of the object. 17062 // Update the class information of the object.
17063 const intptr_t class_id = kExternalOneByteStringCid; 17063 const intptr_t class_id = kExternalOneByteStringCid;
17064 tags = RawObject::SizeTag::update(used_size, tags); 17064 tags = RawObject::SizeTag::update(used_size, tags);
17065 tags = RawObject::ClassIdTag::update(class_id, tags); 17065 tags = RawObject::ClassIdTag::update(class_id, tags);
17066 raw_ptr()->tags_ = tags; 17066 raw_ptr()->tags_ = tags;
17067 result = this->raw(); 17067 result = this->raw();
17068 const uint8_t* ext_array = reinterpret_cast<const uint8_t*>(array);
17068 ExternalStringData<uint8_t>* ext_data = new ExternalStringData<uint8_t>( 17069 ExternalStringData<uint8_t>* ext_data = new ExternalStringData<uint8_t>(
17069 reinterpret_cast<const uint8_t*>(array), peer, cback); 17070 ext_array, peer, cback);
17070 result.SetLength(str_length); 17071 RELEASE_ASSERT(result.Length() == str_length);
17071 result.SetHash(0); 17072 RELEASE_ASSERT(!result.HasHash() ||
Ivan Posva 2014/08/14 20:42:12 We are aware that this makes the externalization o
siva 2014/08/14 21:04:57 Will change it to a plain ASSERT.
17073 (result.Hash() == String::Hash(ext_array, str_length)));
koda 2014/08/14 20:43:30 This is costly to always run in release mode, and
siva 2014/08/14 21:04:57 See above changing to a plain ASSERT
17072 ExternalOneByteString::SetExternalData(result, ext_data); 17074 ExternalOneByteString::SetExternalData(result, ext_data);
17073 external_data = ext_data; 17075 external_data = ext_data;
17074 finalizer = ExternalOneByteString::Finalize; 17076 finalizer = ExternalOneByteString::Finalize;
17075 } else { 17077 } else {
17076 ASSERT(class_id == kTwoByteStringCid); 17078 ASSERT(class_id == kTwoByteStringCid);
17077 used_size = ExternalTwoByteString::InstanceSize(); 17079 used_size = ExternalTwoByteString::InstanceSize();
17078 original_size = TwoByteString::InstanceSize(str_length); 17080 original_size = TwoByteString::InstanceSize(str_length);
17079 ASSERT(original_size >= used_size); 17081 ASSERT(original_size >= used_size);
17080 17082
17081 // Copy the data into the external array. 17083 // Copy the data into the external array.
17082 if (str_length > 0) { 17084 if (str_length > 0) {
17083 memmove(array, 17085 memmove(array,
17084 TwoByteString::CharAddr(*this, 0), 17086 TwoByteString::CharAddr(*this, 0),
17085 (str_length * kTwoByteChar)); 17087 (str_length * kTwoByteChar));
17086 } 17088 }
17087 17089
17088 // Update the class information of the object. 17090 // Update the class information of the object.
17089 const intptr_t class_id = kExternalTwoByteStringCid; 17091 const intptr_t class_id = kExternalTwoByteStringCid;
17090 tags = RawObject::SizeTag::update(used_size, tags); 17092 tags = RawObject::SizeTag::update(used_size, tags);
17091 tags = RawObject::ClassIdTag::update(class_id, tags); 17093 tags = RawObject::ClassIdTag::update(class_id, tags);
17092 raw_ptr()->tags_ = tags; 17094 raw_ptr()->tags_ = tags;
17093 result = this->raw(); 17095 result = this->raw();
17096 const uint16_t* ext_array = reinterpret_cast<const uint16_t*>(array);
17094 ExternalStringData<uint16_t>* ext_data = new ExternalStringData<uint16_t>( 17097 ExternalStringData<uint16_t>* ext_data = new ExternalStringData<uint16_t>(
17095 reinterpret_cast<const uint16_t*>(array), peer, cback); 17098 ext_array, peer, cback);
17096 result.SetLength(str_length); 17099 RELEASE_ASSERT(result.Length() == str_length);
17097 result.SetHash(0); 17100 RELEASE_ASSERT(!result.HasHash() ||
17101 (result.Hash() == String::Hash(ext_array, str_length)));
17098 ExternalTwoByteString::SetExternalData(result, ext_data); 17102 ExternalTwoByteString::SetExternalData(result, ext_data);
17099 external_data = ext_data; 17103 external_data = ext_data;
17100 finalizer = ExternalTwoByteString::Finalize; 17104 finalizer = ExternalTwoByteString::Finalize;
17101 } 17105 }
17102 17106
17103 // If there is any left over space fill it with either an Array object or 17107 // If there is any left over space fill it with either an Array object or
17104 // just a plain object (depending on the amount of left over space) so 17108 // just a plain object (depending on the amount of left over space) so
17105 // that it can be traversed over successfully during garbage collection. 17109 // that it can be traversed over successfully during garbage collection.
17106 Object::MakeUnusedSpaceTraversable(*this, original_size, used_size); 17110 Object::MakeUnusedSpaceTraversable(*this, original_size, used_size);
17107 } // NoGCScope 17111 } // NoGCScope
(...skipping 2308 matching lines...) Expand 10 before | Expand all | Expand 10 after
19416 return tag_label.ToCString(); 19420 return tag_label.ToCString();
19417 } 19421 }
19418 19422
19419 19423
19420 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 19424 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
19421 Instance::PrintJSONImpl(stream, ref); 19425 Instance::PrintJSONImpl(stream, ref);
19422 } 19426 }
19423 19427
19424 19428
19425 } // namespace dart 19429 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/symbols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698