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

Unified Diff: runtime/vm/code_generator.cc

Issue 10095037: Redo r6764. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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/code_generator_ia32.h » ('j') | runtime/vm/code_generator_ia32.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_generator.cc
===================================================================
--- runtime/vm/code_generator.cc (revision 6775)
+++ runtime/vm/code_generator.cc (working copy)
@@ -412,20 +412,22 @@
// Check that the type of the given instance is a subtype of the given type and
// can therefore be assigned.
// Arg0: index of the token of the assignment (source location).
+// Arg1: node-id of the assignemnt.
// Arg1: instance being assigned.
// Arg2: type being assigned to.
// Arg3: type arguments of the instantiator of the type being assigned to.
// Arg4: name of variable being assigned to.
// Return value: instance if a subtype, otherwise throw a TypeError.
-DEFINE_RUNTIME_ENTRY(TypeCheck, 5) {
+DEFINE_RUNTIME_ENTRY(TypeCheck, 6) {
ASSERT(arguments.Count() == kTypeCheckRuntimeEntry.argument_count());
// TODO(regis): Get the token index from the PcDesc (via DartFrame).
intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value();
- const Instance& src_instance = Instance::CheckedHandle(arguments.At(1));
- const AbstractType& dst_type = AbstractType::CheckedHandle(arguments.At(2));
+ intptr_t node_id = Smi::CheckedHandle(arguments.At(1)).Value();
+ const Instance& src_instance = Instance::CheckedHandle(arguments.At(2));
+ const AbstractType& dst_type = AbstractType::CheckedHandle(arguments.At(3));
const AbstractTypeArguments& dst_type_instantiator =
- AbstractTypeArguments::CheckedHandle(arguments.At(3));
- const String& dst_name = String::CheckedHandle(arguments.At(4));
+ AbstractTypeArguments::CheckedHandle(arguments.At(4));
+ const String& dst_name = String::CheckedHandle(arguments.At(5));
ASSERT(!dst_type.IsDynamicType()); // No need to check assignment.
ASSERT(!dst_type.IsMalformed()); // Already checked in code generator.
ASSERT(!src_instance.IsNull()); // Already checked in inlined code.
@@ -482,6 +484,39 @@
dst_name, malformed_error_message);
UNREACHABLE();
}
+ // Update cache: add class of instance and result.
+ if (dst_type.IsInstantiated() &&
+ !Class::Handle(dst_type.type_class()).HasTypeArguments()) {
+ DartFrameIterator iterator;
+ DartFrame* caller_frame = iterator.NextFrame();
+ ASSERT(caller_frame != NULL);
+ const Code& code = Code::Handle(caller_frame->LookupDartCode());
+ ASSERT(!code.IsNull());
+ uword loc = code.GetTypeTestAtNodeId(node_id);
+ if (loc != 0) {
+ // Found type test cache.
+ Array& value = Array::Handle(CodePatcher::GetTypeTestArray(loc));
+ const Class& src_instance_class = Class::Handle(src_instance.clazz());
+
+#if defined(DEBUG)
+ // Check for duplicate entries.
+ Class& last_checked = Class::Handle();
+ for (intptr_t i = 0; i < value.Length(); i += 2) {
+ last_checked ^= value.At(i);
+ ASSERT(last_checked.raw() != src_instance_class.raw());
+ }
+ // Array must be null terminated.
+ ASSERT(last_checked.IsNull());
+#endif
+
+ ASSERT(!value.IsNull());
+ intptr_t old_len = value.Length();
+ value = value.Grow(value, old_len + 2);
+ value.SetAt(old_len - 2, src_instance_class);
+ value.SetAt(old_len - 1, Bool::ZoneHandle(Bool::True()));
+ CodePatcher::SetTypeTestArray(loc, value);
+ }
+ }
arguments.SetReturn(src_instance);
}
« no previous file with comments | « no previous file | runtime/vm/code_generator_ia32.h » ('j') | runtime/vm/code_generator_ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698