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

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

Issue 2893553002: More compact string representation on 64 bit. (Closed)
Patch Set: Slava feedback Created 3 years, 7 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/assembler_x64.cc ('k') | runtime/vm/dart.cc » ('j') | 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 "vm/clustered_snapshot.h" 5 #include "vm/clustered_snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 explicit RODataSerializationCluster(intptr_t cid) : cid_(cid) {} 1904 explicit RODataSerializationCluster(intptr_t cid) : cid_(cid) {}
1905 virtual ~RODataSerializationCluster() {} 1905 virtual ~RODataSerializationCluster() {}
1906 1906
1907 void Trace(Serializer* s, RawObject* object) { 1907 void Trace(Serializer* s, RawObject* object) {
1908 objects_.Add(object); 1908 objects_.Add(object);
1909 1909
1910 // A string's hash must already be computed when we write it because it 1910 // A string's hash must already be computed when we write it because it
1911 // will be loaded into read-only memory. 1911 // will be loaded into read-only memory.
1912 if (cid_ == kOneByteStringCid) { 1912 if (cid_ == kOneByteStringCid) {
1913 RawOneByteString* str = static_cast<RawOneByteString*>(object); 1913 RawOneByteString* str = static_cast<RawOneByteString*>(object);
1914 if (str->ptr()->hash_ == Smi::New(0)) { 1914 if (String::GetCachedHash(str) == 0) {
1915 intptr_t hash = 1915 intptr_t hash =
1916 String::Hash(str->ptr()->data(), Smi::Value(str->ptr()->length_)); 1916 String::Hash(str->ptr()->data(), Smi::Value(str->ptr()->length_));
1917 str->ptr()->hash_ = Smi::New(hash); 1917 String::SetCachedHash(str, hash);
1918 } 1918 }
1919 ASSERT(str->ptr()->hash_ != Smi::New(0)); 1919 ASSERT(String::GetCachedHash(str) != 0);
1920 } else if (cid_ == kTwoByteStringCid) { 1920 } else if (cid_ == kTwoByteStringCid) {
1921 RawTwoByteString* str = static_cast<RawTwoByteString*>(object); 1921 RawTwoByteString* str = static_cast<RawTwoByteString*>(object);
1922 if (str->ptr()->hash_ == Smi::New(0)) { 1922 if (String::GetCachedHash(str) == 0) {
1923 intptr_t hash = String::Hash(str->ptr()->data(), 1923 intptr_t hash = String::Hash(str->ptr()->data(),
1924 Smi::Value(str->ptr()->length_) * 2); 1924 Smi::Value(str->ptr()->length_) * 2);
1925 str->ptr()->hash_ = Smi::New(hash); 1925 String::SetCachedHash(str, hash);
1926 } 1926 }
1927 ASSERT(str->ptr()->hash_ != Smi::New(0)); 1927 ASSERT(String::GetCachedHash(str) != 0);
1928 } 1928 }
1929 } 1929 }
1930 1930
1931 void WriteAlloc(Serializer* s) { 1931 void WriteAlloc(Serializer* s) {
1932 s->WriteCid(cid_); 1932 s->WriteCid(cid_);
1933 intptr_t count = objects_.length(); 1933 intptr_t count = objects_.length();
1934 s->Write<int32_t>(count); 1934 s->Write<int32_t>(count);
1935 for (intptr_t i = 0; i < count; i++) { 1935 for (intptr_t i = 0; i < count; i++) {
1936 RawObject* object = objects_[i]; 1936 RawObject* object = objects_[i];
1937 int32_t rodata_offset = s->GetDataOffset(object); 1937 int32_t rodata_offset = s->GetDataOffset(object);
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4352 } 4352 }
4353 } 4353 }
4354 4354
4355 void WriteFill(Serializer* s) { 4355 void WriteFill(Serializer* s) {
4356 intptr_t count = objects_.length(); 4356 intptr_t count = objects_.length();
4357 for (intptr_t i = 0; i < count; i++) { 4357 for (intptr_t i = 0; i < count; i++) {
4358 RawOneByteString* str = objects_[i]; 4358 RawOneByteString* str = objects_[i];
4359 intptr_t length = Smi::Value(str->ptr()->length_); 4359 intptr_t length = Smi::Value(str->ptr()->length_);
4360 s->Write<int32_t>(length); 4360 s->Write<int32_t>(length);
4361 s->Write<bool>(str->IsCanonical()); 4361 s->Write<bool>(str->IsCanonical());
4362 intptr_t hash = Smi::Value(str->ptr()->hash_); 4362 intptr_t hash = String::GetCachedHash(str);
4363 s->Write<int32_t>(hash); 4363 s->Write<int32_t>(hash);
4364 s->WriteBytes(str->ptr()->data(), length); 4364 s->WriteBytes(str->ptr()->data(), length);
4365 } 4365 }
4366 } 4366 }
4367 4367
4368 private: 4368 private:
4369 GrowableArray<RawOneByteString*> objects_; 4369 GrowableArray<RawOneByteString*> objects_;
4370 }; 4370 };
4371 #endif // !DART_PRECOMPILED_RUNTIME 4371 #endif // !DART_PRECOMPILED_RUNTIME
4372 4372
(...skipping 19 matching lines...) Expand all
4392 bool is_vm_object = d->isolate() == Dart::vm_isolate(); 4392 bool is_vm_object = d->isolate() == Dart::vm_isolate();
4393 4393
4394 for (intptr_t id = start_index_; id < stop_index_; id++) { 4394 for (intptr_t id = start_index_; id < stop_index_; id++) {
4395 RawOneByteString* str = reinterpret_cast<RawOneByteString*>(d->Ref(id)); 4395 RawOneByteString* str = reinterpret_cast<RawOneByteString*>(d->Ref(id));
4396 intptr_t length = d->Read<int32_t>(); 4396 intptr_t length = d->Read<int32_t>();
4397 bool is_canonical = d->Read<bool>(); 4397 bool is_canonical = d->Read<bool>();
4398 Deserializer::InitializeHeader(str, kOneByteStringCid, 4398 Deserializer::InitializeHeader(str, kOneByteStringCid,
4399 OneByteString::InstanceSize(length), 4399 OneByteString::InstanceSize(length),
4400 is_vm_object, is_canonical); 4400 is_vm_object, is_canonical);
4401 str->ptr()->length_ = Smi::New(length); 4401 str->ptr()->length_ = Smi::New(length);
4402 str->ptr()->hash_ = Smi::New(d->Read<int32_t>()); 4402 String::SetCachedHash(str, d->Read<int32_t>());
4403 for (intptr_t j = 0; j < length; j++) { 4403 for (intptr_t j = 0; j < length; j++) {
4404 str->ptr()->data()[j] = d->Read<uint8_t>(); 4404 str->ptr()->data()[j] = d->Read<uint8_t>();
4405 } 4405 }
4406 } 4406 }
4407 } 4407 }
4408 }; 4408 };
4409 4409
4410 4410
4411 #if !defined(DART_PRECOMPILED_RUNTIME) 4411 #if !defined(DART_PRECOMPILED_RUNTIME)
4412 class TwoByteStringSerializationCluster : public SerializationCluster { 4412 class TwoByteStringSerializationCluster : public SerializationCluster {
(...skipping 18 matching lines...) Expand all
4431 } 4431 }
4432 } 4432 }
4433 4433
4434 void WriteFill(Serializer* s) { 4434 void WriteFill(Serializer* s) {
4435 intptr_t count = objects_.length(); 4435 intptr_t count = objects_.length();
4436 for (intptr_t i = 0; i < count; i++) { 4436 for (intptr_t i = 0; i < count; i++) {
4437 RawTwoByteString* str = objects_[i]; 4437 RawTwoByteString* str = objects_[i];
4438 intptr_t length = Smi::Value(str->ptr()->length_); 4438 intptr_t length = Smi::Value(str->ptr()->length_);
4439 s->Write<int32_t>(length); 4439 s->Write<int32_t>(length);
4440 s->Write<bool>(str->IsCanonical()); 4440 s->Write<bool>(str->IsCanonical());
4441 intptr_t hash = Smi::Value(str->ptr()->hash_); 4441 intptr_t hash = String::GetCachedHash(str);
4442 s->Write<int32_t>(hash); 4442 s->Write<int32_t>(hash);
4443 s->WriteBytes(reinterpret_cast<uint8_t*>(str->ptr()->data()), length * 2); 4443 s->WriteBytes(reinterpret_cast<uint8_t*>(str->ptr()->data()), length * 2);
4444 } 4444 }
4445 } 4445 }
4446 4446
4447 private: 4447 private:
4448 GrowableArray<RawTwoByteString*> objects_; 4448 GrowableArray<RawTwoByteString*> objects_;
4449 }; 4449 };
4450 #endif // !DART_PRECOMPILED_RUNTIME 4450 #endif // !DART_PRECOMPILED_RUNTIME
4451 4451
(...skipping 19 matching lines...) Expand all
4471 bool is_vm_object = d->isolate() == Dart::vm_isolate(); 4471 bool is_vm_object = d->isolate() == Dart::vm_isolate();
4472 4472
4473 for (intptr_t id = start_index_; id < stop_index_; id++) { 4473 for (intptr_t id = start_index_; id < stop_index_; id++) {
4474 RawTwoByteString* str = reinterpret_cast<RawTwoByteString*>(d->Ref(id)); 4474 RawTwoByteString* str = reinterpret_cast<RawTwoByteString*>(d->Ref(id));
4475 intptr_t length = d->Read<int32_t>(); 4475 intptr_t length = d->Read<int32_t>();
4476 bool is_canonical = d->Read<bool>(); 4476 bool is_canonical = d->Read<bool>();
4477 Deserializer::InitializeHeader(str, kTwoByteStringCid, 4477 Deserializer::InitializeHeader(str, kTwoByteStringCid,
4478 TwoByteString::InstanceSize(length), 4478 TwoByteString::InstanceSize(length),
4479 is_vm_object, is_canonical); 4479 is_vm_object, is_canonical);
4480 str->ptr()->length_ = Smi::New(length); 4480 str->ptr()->length_ = Smi::New(length);
4481 str->ptr()->hash_ = Smi::New(d->Read<int32_t>()); 4481 String::SetCachedHash(str, d->Read<int32_t>());
4482 uint8_t* cdata = reinterpret_cast<uint8_t*>(str->ptr()->data()); 4482 uint8_t* cdata = reinterpret_cast<uint8_t*>(str->ptr()->data());
4483 d->ReadBytes(cdata, length * 2); 4483 d->ReadBytes(cdata, length * 2);
4484 } 4484 }
4485 } 4485 }
4486 }; 4486 };
4487 4487
4488 4488
4489 Serializer::Serializer(Thread* thread, 4489 Serializer::Serializer(Thread* thread,
4490 Snapshot::Kind kind, 4490 Snapshot::Kind kind,
4491 uint8_t** buffer, 4491 uint8_t** buffer,
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
5635 thread_->isolate()->SetupImagePage(data_buffer_, 5635 thread_->isolate()->SetupImagePage(data_buffer_,
5636 /* is_executable */ false); 5636 /* is_executable */ false);
5637 } 5637 }
5638 5638
5639 deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store()); 5639 deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store());
5640 5640
5641 return ApiError::null(); 5641 return ApiError::null();
5642 } 5642 }
5643 5643
5644 } // namespace dart 5644 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/assembler_x64.cc ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698