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

Unified Diff: runtime/vm/code_generator.cc

Issue 22851003: Initial support for length guards on final fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_generator.cc
diff --git a/runtime/vm/code_generator.cc b/runtime/vm/code_generator.cc
index 7aaf5bc0cb39a1f88c90c58d377980cf6a1d6898..5e8b81f60f91e25e68948c1ca08ec44ebf15ea32 100644
--- a/runtime/vm/code_generator.cc
+++ b/runtime/vm/code_generator.cc
@@ -1861,6 +1861,32 @@ double DartModulo(double left, double right) {
}
+static intptr_t GetListLength(const Object& value) {
+ const intptr_t cid = value.GetClassId();
+ ASSERT(RawObject::IsBuiltinListClassId(cid));
+ intptr_t list_length = Field::kNoLength;
srdjan 2013/08/14 17:01:08 You can eliminate list_length variable and return
Cutch 2013/08/15 16:39:12 Done.
+ // Extract list length.
+ if (value.IsTypedData()) {
+ const TypedData& list = TypedData::Cast(value);
+ list_length = list.Length();
+ } else if (value.IsArray()) {
+ const Array& list = Array::Cast(value);
+ list_length = list.Length();
+ } else if (value.IsGrowableObjectArray()) {
+ // List length is variable.
+ } else if (value.IsExternalTypedData()) {
+ const ExternalTypedData& list = ExternalTypedData::Cast(value);
+ list_length = list.Length();
+ } else if (RawObject::IsTypedDataViewClassId(cid)) {
+ const Instance& list = Instance::Cast(value);
+ list_length = Smi::Value(TypedDataView::Length(list));
+ } else {
+ UNIMPLEMENTED();
+ }
+ return list_length;
+}
+
+
// Update global type feedback recorded for a field recording the assignment
// of the given value.
// Arg0: Field object;
@@ -1869,8 +1895,14 @@ DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) {
ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count());
const Field& field = Field::CheckedHandle(arguments.ArgAt(0));
const Object& value = Object::Handle(arguments.ArgAt(1));
-
- field.UpdateCid(value.GetClassId());
+ const intptr_t cid = value.GetClassId();
+ field.UpdateCid(cid);
+ intptr_t list_length = Field::kNoLength;
+ if ((field.guarded_cid() != kDynamicCid) &&
+ field.is_final() && RawObject::IsBuiltinListClassId(cid)) {
+ list_length = GetListLength(value);
+ }
srdjan 2013/08/14 17:01:08 ASSERT(!field.is_final) ?
+ field.UpdateLength(list_length);
}
} // namespace dart
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698