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

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

Issue 12473002: Complete implementation of bounds checking in the vm, by introducing a vm object (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/heap_profiler.cc » ('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) 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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/code_descriptors.h" 9 #include "vm/code_descriptors.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 const Instance& literal_value = node->left()->AsLiteralNode()->literal(); 1055 const Instance& literal_value = node->left()->AsLiteralNode()->literal();
1056 const Class& cls = Class::Handle(literal_value.clazz()); 1056 const Class& cls = Class::Handle(literal_value.clazz());
1057 ConstantInstr* result = NULL; 1057 ConstantInstr* result = NULL;
1058 if (cls.IsNullClass()) { 1058 if (cls.IsNullClass()) {
1059 // A null object is only an instance of Object and dynamic, which has 1059 // A null object is only an instance of Object and dynamic, which has
1060 // already been checked above (if the type is instantiated). So we can 1060 // already been checked above (if the type is instantiated). So we can
1061 // return false here if the instance is null (and if the type is 1061 // return false here if the instance is null (and if the type is
1062 // instantiated). 1062 // instantiated).
1063 result = new ConstantInstr(negate_result ? Bool::True() : Bool::False()); 1063 result = new ConstantInstr(negate_result ? Bool::True() : Bool::False());
1064 } else { 1064 } else {
1065 if (literal_value.IsInstanceOf(type, TypeArguments::Handle(), NULL)) { 1065 Error& malformed_error = Error::Handle();
1066 if (literal_value.IsInstanceOf(type,
1067 TypeArguments::Handle(),
1068 &malformed_error)) {
1066 result = new ConstantInstr(negate_result ? 1069 result = new ConstantInstr(negate_result ?
1067 Bool::False() : Bool::True()); 1070 Bool::False() : Bool::True());
1068 } else { 1071 } else {
1069 result = new ConstantInstr(negate_result ? 1072 result = new ConstantInstr(negate_result ?
1070 Bool::True() : Bool::False()); 1073 Bool::True() : Bool::False());
1071 } 1074 }
1075 ASSERT(malformed_error.IsNull());
1072 } 1076 }
1073 ReturnDefinition(result); 1077 ReturnDefinition(result);
1074 return; 1078 return;
1075 } 1079 }
1076 1080
1077 ValueGraphVisitor for_left_value(owner(), temp_index()); 1081 ValueGraphVisitor for_left_value(owner(), temp_index());
1078 node->left()->Visit(&for_left_value); 1082 node->left()->Visit(&for_left_value);
1079 Append(for_left_value); 1083 Append(for_left_value);
1080 PushArgumentInstr* push_left = PushArgument(for_left_value.value()); 1084 PushArgumentInstr* push_left = PushArgument(for_left_value.value());
1081 PushArgumentInstr* push_instantiator = NULL; 1085 PushArgumentInstr* push_instantiator = NULL;
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 const Class& cls = Class::ZoneHandle(node->constructor().Owner()); 1924 const Class& cls = Class::ZoneHandle(node->constructor().Owner());
1921 const bool requires_type_arguments = cls.HasTypeArguments(); 1925 const bool requires_type_arguments = cls.HasTypeArguments();
1922 1926
1923 // In checked mode, if the type arguments are uninstantiated, they may need to 1927 // In checked mode, if the type arguments are uninstantiated, they may need to
1924 // be checked against declared bounds at run time. 1928 // be checked against declared bounds at run time.
1925 Definition* allocate_comp = NULL; 1929 Definition* allocate_comp = NULL;
1926 if (FLAG_enable_type_checks && 1930 if (FLAG_enable_type_checks &&
1927 requires_type_arguments && 1931 requires_type_arguments &&
1928 !node->type_arguments().IsNull() && 1932 !node->type_arguments().IsNull() &&
1929 !node->type_arguments().IsInstantiated() && 1933 !node->type_arguments().IsInstantiated() &&
1930 !node->type_arguments().IsWithinBoundsOf(cls, 1934 node->type_arguments().IsBounded()) {
1931 node->type_arguments(),
1932 NULL)) {
1933 Value* type_arguments = NULL; 1935 Value* type_arguments = NULL;
1934 Value* instantiator = NULL; 1936 Value* instantiator = NULL;
1935 BuildConstructorTypeArguments(node, &type_arguments, &instantiator, NULL); 1937 BuildConstructorTypeArguments(node, &type_arguments, &instantiator, NULL);
1936 1938
1937 // The uninstantiated type arguments cannot be verified to be within their 1939 // The uninstantiated type arguments cannot be verified to be within their
1938 // bounds at compile time, so verify them at runtime. 1940 // bounds at compile time, so verify them at runtime.
1939 // Although the type arguments may be uninstantiated at compile time, they
1940 // may represent the identity vector and may be replaced by the instantiated
1941 // type arguments of the instantiator at run time.
1942 allocate_comp = new AllocateObjectWithBoundsCheckInstr(node, 1941 allocate_comp = new AllocateObjectWithBoundsCheckInstr(node,
1943 type_arguments, 1942 type_arguments,
1944 instantiator); 1943 instantiator);
1945 } else { 1944 } else {
1946 ZoneGrowableArray<PushArgumentInstr*>* allocate_arguments = 1945 ZoneGrowableArray<PushArgumentInstr*>* allocate_arguments =
1947 new ZoneGrowableArray<PushArgumentInstr*>(); 1946 new ZoneGrowableArray<PushArgumentInstr*>();
1948 1947
1949 if (requires_type_arguments) { 1948 if (requires_type_arguments) {
1950 BuildConstructorTypeArguments(node, NULL, NULL, allocate_arguments); 1949 BuildConstructorTypeArguments(node, NULL, NULL, allocate_arguments);
1951 } 1950 }
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; 3290 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
3292 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 3291 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
3293 OS::SNPrint(chars, len, kFormat, function_name, reason); 3292 OS::SNPrint(chars, len, kFormat, function_name, reason);
3294 const Error& error = Error::Handle( 3293 const Error& error = Error::Handle(
3295 LanguageError::New(String::Handle(String::New(chars)))); 3294 LanguageError::New(String::Handle(String::New(chars))));
3296 Isolate::Current()->long_jump_base()->Jump(1, error); 3295 Isolate::Current()->long_jump_base()->Jump(1, error);
3297 } 3296 }
3298 3297
3299 3298
3300 } // namespace dart 3299 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/heap_profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698