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

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

Issue 10693044: Enhance raw object validation check and enable checks in release builds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | 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) 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/raw_object.h" 5 #include "vm/raw_object.h"
6 6
7 #include "vm/class_table.h" 7 #include "vm/class_table.h"
8 #include "vm/freelist.h" 8 #include "vm/freelist.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/visitor.h" 11 #include "vm/visitor.h"
12 12
13 13
14 namespace dart { 14 namespace dart {
15 15
16 void RawObject::Validate(Isolate* isolate) const { 16 void RawObject::Validate(Isolate* isolate) const {
17 // Validation only happens in DEBUG builds.
18 #if defined(DEBUG)
19 if (Object::null_class_ == reinterpret_cast<RawClass*>(kHeapObjectTag)) { 17 if (Object::null_class_ == reinterpret_cast<RawClass*>(kHeapObjectTag)) {
20 // Validation relies on properly initialized class classes. Skip if the 18 // Validation relies on properly initialized class classes. Skip if the
21 // VM is still being initialized. 19 // VM is still being initialized.
22 return; 20 return;
23 } 21 }
24 // All Smi values are valid. 22 // All Smi values are valid.
25 if (!IsHeapObject()) { 23 if (!IsHeapObject()) {
26 return; 24 return;
27 } 25 }
28 // Validate that the tags_ field is sensible. 26 // Validate that the tags_ field is sensible.
29 uword tags = ptr()->tags_; 27 uword tags = ptr()->tags_;
30 ASSERT((tags & 0x000000f0) == 0); 28 uword reserved = 0;
31 #endif 29 reserved |= (1 << kReservedBit10K);
30 reserved |= (1 << kReservedBit100K);
31 reserved |= (1 << kReservedBit1M);
32 reserved |= (1 << kReservedBit10M);
33 if ((tags & reserved) != 0) {
34 FATAL1("Invalid tags field encountered %#lx\n", tags);
35 }
36 intptr_t class_id = ClassIdTag::decode(tags);
37 if (!isolate->class_table()->IsValidIndex(class_id)) {
38 FATAL1("Invalid class id encountered %d\n", class_id);
39 }
40 intptr_t size = SizeTag::decode(tags);
41 if (size != 0 && size != SizeFromClass()) {
42 FATAL1("Inconsistent class size encountered %d\n", size);
43 }
32 } 44 }
33 45
34 46
35 intptr_t RawObject::SizeFromClass() const { 47 intptr_t RawObject::SizeFromClass() const {
36 Isolate* isolate = Isolate::Current(); 48 Isolate* isolate = Isolate::Current();
37 NoHandleScope no_handles(isolate); 49 NoHandleScope no_handles(isolate);
38 50
39 // Only reasonable to be called on heap objects. 51 // Only reasonable to be called on heap objects.
40 ASSERT(IsHeapObject()); 52 ASSERT(IsHeapObject());
41 53
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, 953 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj,
942 ObjectPointerVisitor* visitor) { 954 ObjectPointerVisitor* visitor) {
943 // Make sure that we got here with the tagged pointer as this. 955 // Make sure that we got here with the tagged pointer as this.
944 ASSERT(raw_obj->IsHeapObject()); 956 ASSERT(raw_obj->IsHeapObject());
945 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); 957 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_);
946 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 958 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
947 return JSRegExp::InstanceSize(length); 959 return JSRegExp::InstanceSize(length);
948 } 960 }
949 961
950 } // namespace dart 962 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698