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

Unified Diff: runtime/vm/raw_object_snapshot.cc

Issue 12183014: Resubmit reverted r17962, but, for now, only report error about unfinalized (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/raw_object_snapshot.cc
===================================================================
--- runtime/vm/raw_object_snapshot.cc (revision 18032)
+++ runtime/vm/raw_object_snapshot.cc (working copy)
@@ -11,6 +11,9 @@
namespace dart {
+DECLARE_FLAG(bool, error_on_malformed_type);
+
+
#define NEW_OBJECT(type) \
((kind == Snapshot::kFull) ? reader->New##type() : type::New())
@@ -112,12 +115,27 @@
}
+static const char* RawOneByteStringToCString(RawOneByteString* str) {
+ const char* start = reinterpret_cast<char*>(str) - kHeapObjectTag +
+ OneByteString::data_offset();
+ const int len = Smi::Value(*reinterpret_cast<RawSmi**>(
+ reinterpret_cast<uword>(str) - kHeapObjectTag + String::length_offset()));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
+ memmove(chars, start, len);
+ chars[len] = '\0';
+ return chars;
+}
+
+
RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader,
intptr_t object_id,
intptr_t tags,
Snapshot::Kind kind) {
ASSERT(reader != NULL);
+ // Only resolved and finalized types should be written to a snapshot.
+ // TODO(regis): Replace this code by an UNREACHABLE().
+
// Allocate parameterized type object.
UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle(
reader->isolate(), NEW_OBJECT(UnresolvedClass));
@@ -147,6 +165,19 @@
Snapshot::Kind kind) {
ASSERT(writer != NULL);
+ // Only resolved and finalized types should be written to a snapshot.
+ // TODO(regis): Replace this code by an UNREACHABLE().
+ if (FLAG_error_on_malformed_type) {
+ // Print the name of the unresolved class, as well as the token location
+ // from where it is referred to, making sure not to allocate any handles.
+ // Unfortunately, we cannot print the script name.
+ OS::Print("Snapshotting unresolved class '%s' at token pos %"Pd"\n",
+ RawOneByteStringToCString(
+ reinterpret_cast<RawOneByteString*>(ptr()->ident_)),
+ ptr()->token_pos_);
+ UNREACHABLE();
+ }
+
// Write out the serialization header value for this object.
writer->WriteInlinedObjectHeader(object_id);
@@ -219,6 +250,36 @@
Snapshot::Kind kind) {
ASSERT(writer != NULL);
+ // Only resolved and finalized types should be written to a snapshot.
+ // TODO(regis): Replace the test below by an ASSERT().
+ if (FLAG_error_on_malformed_type &&
+ (ptr()->type_state_ != RawType::kFinalizedInstantiated) &&
+ (ptr()->type_state_ != RawType::kFinalizedUninstantiated)) {
+ // Print the name of the class of the unfinalized type, as well as the
+ // token location from where it is referred to, making sure not
+ // to allocate any handles. Unfortunately, we cannot print the script name.
+ const intptr_t cid = ClassIdTag::decode(*reinterpret_cast<uword*>(
+ reinterpret_cast<uword>(ptr()->type_class_) - kHeapObjectTag +
+ Object::tags_offset()));
+ if (cid == kUnresolvedClassCid) {
+ OS::Print("Snapshotting unresolved type '%s' at token pos %"Pd"\n",
+ RawOneByteStringToCString(
+ reinterpret_cast<RawOneByteString*>(
+ reinterpret_cast<RawUnresolvedClass*>(
+ ptr()->type_class_)->ptr()->ident_)),
+ ptr()->token_pos_);
+ } else {
+ // Assume cid == kClassId, but it can also be kIllegalCid.
+ OS::Print("Snapshotting unfinalized type '%s' at token pos %"Pd"\n",
+ RawOneByteStringToCString(
+ reinterpret_cast<RawOneByteString*>(
+ reinterpret_cast<RawClass*>(
+ ptr()->type_class_)->ptr()->name_)),
+ ptr()->token_pos_);
+ }
+ UNREACHABLE();
+ }
+
// Write out the serialization header value for this object.
writer->WriteInlinedObjectHeader(object_id);
@@ -244,7 +305,7 @@
// Allocate type parameter object.
TypeParameter& type_parameter = TypeParameter::ZoneHandle(
- reader->isolate(), NEW_OBJECT(TypeParameter));
+ reader->isolate(), NEW_OBJECT(TypeParameter));
reader->AddBackRef(object_id, &type_parameter, kIsDeserialized);
// Set the object tags.
@@ -274,6 +335,26 @@
Snapshot::Kind kind) {
ASSERT(writer != NULL);
+ // Only finalized type parameters should be written to a snapshot.
+ // TODO(regis): Replace the test below by an ASSERT().
+ if (FLAG_error_on_malformed_type &&
+ (ptr()->type_state_ != RawTypeParameter::kFinalizedUninstantiated)) {
+ // Print the name of the unfinalized type parameter, the name of the class
+ // it parameterizes, as well as the token location from where it is referred
+ // to, making sure not to allocate any handles. Unfortunately, we cannot
+ // print the script name.
+ OS::Print("Snapshotting unfinalized type parameter '%s' of class '%s' at "
+ "token pos %"Pd"\n",
+ RawOneByteStringToCString(
+ reinterpret_cast<RawOneByteString*>(ptr()->name_)),
+ RawOneByteStringToCString(
+ reinterpret_cast<RawOneByteString*>(
+ reinterpret_cast<RawClass*>(
+ ptr()->parameterized_class_)->ptr()->name_)),
+ ptr()->token_pos_);
+ UNREACHABLE();
+ }
+
// Write out the serialization header value for this object.
writer->WriteInlinedObjectHeader(object_id);
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698