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

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

Issue 2720123004: VM: Make Dart::FeaturesString respect isolate flags controlling asserts and type checks. (Closed)
Patch Set: Created 3 years, 9 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/clustered_snapshot.h ('k') | runtime/vm/dart.h » ('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 4630 matching lines...) Expand 10 before | Expand all | Expand 10 after
4641 cluster->Trace(this, object); 4641 cluster->Trace(this, object);
4642 } 4642 }
4643 4643
4644 4644
4645 void Serializer::WriteVersionAndFeatures() { 4645 void Serializer::WriteVersionAndFeatures() {
4646 const char* expected_version = Version::SnapshotString(); 4646 const char* expected_version = Version::SnapshotString();
4647 ASSERT(expected_version != NULL); 4647 ASSERT(expected_version != NULL);
4648 const intptr_t version_len = strlen(expected_version); 4648 const intptr_t version_len = strlen(expected_version);
4649 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len); 4649 WriteBytes(reinterpret_cast<const uint8_t*>(expected_version), version_len);
4650 4650
4651 const char* expected_features = Dart::FeaturesString(kind_); 4651 const char* expected_features =
4652 Dart::FeaturesString(Isolate::Current(), kind_);
4652 ASSERT(expected_features != NULL); 4653 ASSERT(expected_features != NULL);
4653 const intptr_t features_len = strlen(expected_features); 4654 const intptr_t features_len = strlen(expected_features);
4654 WriteBytes(reinterpret_cast<const uint8_t*>(expected_features), 4655 WriteBytes(reinterpret_cast<const uint8_t*>(expected_features),
4655 features_len + 1); 4656 features_len + 1);
4656 free(const_cast<char*>(expected_features)); 4657 free(const_cast<char*>(expected_features));
4657 } 4658 }
4658 4659
4659 4660
4660 #if defined(DEBUG) 4661 #if defined(DEBUG)
4661 static const int32_t kSectionMarker = 0xABAB; 4662 static const int32_t kSectionMarker = 0xABAB;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
4979 } 4980 }
4980 } 4981 }
4981 default: 4982 default:
4982 break; 4983 break;
4983 } 4984 }
4984 FATAL1("No cluster defined for cid %" Pd, cid); 4985 FATAL1("No cluster defined for cid %" Pd, cid);
4985 return NULL; 4986 return NULL;
4986 } 4987 }
4987 4988
4988 4989
4989 RawApiError* Deserializer::VerifyVersionAndFeatures() { 4990 RawApiError* Deserializer::VerifyVersionAndFeatures(Isolate* isolate) {
4990 // If the version string doesn't match, return an error. 4991 // If the version string doesn't match, return an error.
4991 // Note: New things are allocated only if we're going to return an error. 4992 // Note: New things are allocated only if we're going to return an error.
4992 4993
4993 const char* expected_version = Version::SnapshotString(); 4994 const char* expected_version = Version::SnapshotString();
4994 ASSERT(expected_version != NULL); 4995 ASSERT(expected_version != NULL);
4995 const intptr_t version_len = strlen(expected_version); 4996 const intptr_t version_len = strlen(expected_version);
4996 if (PendingBytes() < version_len) { 4997 if (PendingBytes() < version_len) {
4997 const intptr_t kMessageBufferSize = 128; 4998 const intptr_t kMessageBufferSize = 128;
4998 char message_buffer[kMessageBufferSize]; 4999 char message_buffer[kMessageBufferSize];
4999 OS::SNPrint(message_buffer, kMessageBufferSize, 5000 OS::SNPrint(message_buffer, kMessageBufferSize,
(...skipping 16 matching lines...) Expand all
5016 (Snapshot::IsFull(kind_)) ? "full" : "script", expected_version, 5017 (Snapshot::IsFull(kind_)) ? "full" : "script", expected_version,
5017 actual_version); 5018 actual_version);
5018 free(actual_version); 5019 free(actual_version);
5019 // This can also fail while bringing up the VM isolate, so make sure to 5020 // This can also fail while bringing up the VM isolate, so make sure to
5020 // allocate the error message in old space. 5021 // allocate the error message in old space.
5021 const String& msg = String::Handle(String::New(message_buffer, Heap::kOld)); 5022 const String& msg = String::Handle(String::New(message_buffer, Heap::kOld));
5022 return ApiError::New(msg, Heap::kOld); 5023 return ApiError::New(msg, Heap::kOld);
5023 } 5024 }
5024 Advance(version_len); 5025 Advance(version_len);
5025 5026
5026 const char* expected_features = Dart::FeaturesString(kind_); 5027 const char* expected_features = Dart::FeaturesString(isolate, kind_);
5027 ASSERT(expected_features != NULL); 5028 ASSERT(expected_features != NULL);
5028 const intptr_t expected_len = strlen(expected_features); 5029 const intptr_t expected_len = strlen(expected_features);
5029 5030
5030 const char* features = reinterpret_cast<const char*>(CurrentBufferAddress()); 5031 const char* features = reinterpret_cast<const char*>(CurrentBufferAddress());
5031 ASSERT(features != NULL); 5032 ASSERT(features != NULL);
5032 intptr_t buffer_len = OS::StrNLen(features, PendingBytes()); 5033 intptr_t buffer_len = OS::StrNLen(features, PendingBytes());
5033 if ((buffer_len != expected_len) || 5034 if ((buffer_len != expected_len) ||
5034 strncmp(features, expected_features, expected_len)) { 5035 strncmp(features, expected_features, expected_len)) {
5035 const intptr_t kMessageBufferSize = 256; 5036 const intptr_t kMessageBufferSize = 256;
5036 char message_buffer[kMessageBufferSize]; 5037 char message_buffer[kMessageBufferSize];
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
5468 instructions_buffer_(instructions_buffer), 5469 instructions_buffer_(instructions_buffer),
5469 data_buffer_(DataBuffer(snapshot)) { 5470 data_buffer_(DataBuffer(snapshot)) {
5470 thread->isolate()->set_compilation_allowed(kind_ != Snapshot::kAppAOT); 5471 thread->isolate()->set_compilation_allowed(kind_ != Snapshot::kAppAOT);
5471 } 5472 }
5472 5473
5473 5474
5474 RawApiError* FullSnapshotReader::ReadVMSnapshot() { 5475 RawApiError* FullSnapshotReader::ReadVMSnapshot() {
5475 Deserializer deserializer(thread_, kind_, buffer_, size_, 5476 Deserializer deserializer(thread_, kind_, buffer_, size_,
5476 instructions_buffer_, data_buffer_); 5477 instructions_buffer_, data_buffer_);
5477 5478
5478 RawApiError* error = deserializer.VerifyVersionAndFeatures(); 5479 RawApiError* error = deserializer.VerifyVersionAndFeatures(/*isolate=*/NULL);
5479 if (error != ApiError::null()) { 5480 if (error != ApiError::null()) {
5480 return error; 5481 return error;
5481 } 5482 }
5482 5483
5483 if (Snapshot::IncludesCode(kind_)) { 5484 if (Snapshot::IncludesCode(kind_)) {
5484 ASSERT(instructions_buffer_ != NULL); 5485 ASSERT(instructions_buffer_ != NULL);
5485 thread_->isolate()->SetupImagePage(instructions_buffer_, 5486 thread_->isolate()->SetupImagePage(instructions_buffer_,
5486 /* is_executable */ true); 5487 /* is_executable */ true);
5487 ASSERT(data_buffer_ != NULL); 5488 ASSERT(data_buffer_ != NULL);
5488 thread_->isolate()->SetupImagePage(data_buffer_, 5489 thread_->isolate()->SetupImagePage(data_buffer_,
5489 /* is_executable */ false); 5490 /* is_executable */ false);
5490 } 5491 }
5491 5492
5492 deserializer.ReadVMSnapshot(); 5493 deserializer.ReadVMSnapshot();
5493 5494
5494 return ApiError::null(); 5495 return ApiError::null();
5495 } 5496 }
5496 5497
5497 5498
5498 RawApiError* FullSnapshotReader::ReadIsolateSnapshot() { 5499 RawApiError* FullSnapshotReader::ReadIsolateSnapshot() {
5499 Deserializer deserializer(thread_, kind_, buffer_, size_, 5500 Deserializer deserializer(thread_, kind_, buffer_, size_,
5500 instructions_buffer_, data_buffer_); 5501 instructions_buffer_, data_buffer_);
5501 5502
5502 RawApiError* error = deserializer.VerifyVersionAndFeatures(); 5503 RawApiError* error =
5504 deserializer.VerifyVersionAndFeatures(thread_->isolate());
5503 if (error != ApiError::null()) { 5505 if (error != ApiError::null()) {
5504 return error; 5506 return error;
5505 } 5507 }
5506 5508
5507 if (Snapshot::IncludesCode(kind_)) { 5509 if (Snapshot::IncludesCode(kind_)) {
5508 ASSERT(instructions_buffer_ != NULL); 5510 ASSERT(instructions_buffer_ != NULL);
5509 thread_->isolate()->SetupImagePage(instructions_buffer_, 5511 thread_->isolate()->SetupImagePage(instructions_buffer_,
5510 /* is_executable */ true); 5512 /* is_executable */ true);
5511 ASSERT(data_buffer_ != NULL); 5513 ASSERT(data_buffer_ != NULL);
5512 thread_->isolate()->SetupImagePage(data_buffer_, 5514 thread_->isolate()->SetupImagePage(data_buffer_,
5513 /* is_executable */ false); 5515 /* is_executable */ false);
5514 } 5516 }
5515 5517
5516 deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store()); 5518 deserializer.ReadIsolateSnapshot(thread_->isolate()->object_store());
5517 5519
5518 return ApiError::null(); 5520 return ApiError::null();
5519 } 5521 }
5520 5522
5521 } // namespace dart 5523 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/clustered_snapshot.h ('k') | runtime/vm/dart.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698