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

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

Issue 22314017: Do not use guarded cid on externalizable cid-s (one and two byte strings). (Closed) Base URL: http://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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/flow_graph_type_propagator.cc » ('j') | runtime/vm/object.h » ('J')
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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 7098 matching lines...) Expand 10 before | Expand all | Expand 10 after
7109 Dart_ExitScope(); 7109 Dart_ExitScope();
7110 } 7110 }
7111 7111
7112 7112
7113 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( 7113 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup(
7114 Dart_Handle name, int argument_count) { 7114 Dart_Handle name, int argument_count) {
7115 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); 7115 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native);
7116 } 7116 }
7117 7117
7118 7118
7119 // Do not use guarding mechanism on externalizable classes, since their class
7120 // can change on the fly,
7121 TEST_CASE(GuardExternalizedString) {
7122 const char* kScriptChars =
7123 "main() {\n"
7124 " var a = new A('hello');\n"
7125 " var res = runOne(a);\n"
7126 " if (res != 10640000) return -1;\n"
7127 " change_str(a.f);\n"
7128 " res = runOne(a);\n"
7129 " return res;\n"
7130 "}\n"
7131 "runOne(a) {\n"
7132 " var sum = 0;\n"
7133 " for (int i = 0; i < 20000; i++) {\n"
7134 " for (int j = 0; j < a.f.length; j++) {\n"
7135 " sum += a.f.codeUnitAt(j);\n"
7136 " }\n"
7137 " }\n"
7138 " return sum;\n"
7139 "}\n"
7140 "class A {\n"
7141 " var f;\n"
7142 " A(this.f);\n"
7143 "}\n"
7144 "change_str(String s) native 'A_change_str';\n"
7145 "";
7146 Dart_Handle lib =
7147 TestCase::LoadTestScript(kScriptChars,
7148 &ExternalStringDeoptimize_native_lookup);
7149 Dart_Handle result = Dart_Invoke(lib,
7150 NewString("main"),
7151 0,
7152 NULL);
7153 int64_t value = 0;
7154 result = Dart_IntegerToInt64(result, &value);
7155 EXPECT_VALID(result);
7156 EXPECT_EQ(10640000, value);
7157 }
7158
7159
7119 TEST_CASE(ExternalStringDeoptimize) { 7160 TEST_CASE(ExternalStringDeoptimize) {
7120 const char* kScriptChars = 7161 const char* kScriptChars =
7121 "String str = 'A';\n" 7162 "String str = 'A';\n"
7122 "class A {\n" 7163 "class A {\n"
7123 " static change_str(String s) native 'A_change_str';\n" 7164 " static change_str(String s) native 'A_change_str';\n"
7124 "}\n" 7165 "}\n"
7125 "sum_chars(String s, bool b) {\n" 7166 "sum_chars(String s, bool b) {\n"
7126 " var result = 0;\n" 7167 " var result = 0;\n"
7127 " for (var i = 0; i < s.length; i++) {\n" 7168 " for (var i = 0; i < s.length; i++) {\n"
7128 " if (b && i == 0) A.change_str(str);\n" 7169 " if (b && i == 0) A.change_str(str);\n"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
7202 NewString("main"), 7243 NewString("main"),
7203 0, 7244 0,
7204 NULL); 7245 NULL);
7205 int64_t value = 0; 7246 int64_t value = 0;
7206 result = Dart_IntegerToInt64(result, &value); 7247 result = Dart_IntegerToInt64(result, &value);
7207 EXPECT_VALID(result); 7248 EXPECT_VALID(result);
7208 EXPECT_EQ(8, value); 7249 EXPECT_EQ(8, value);
7209 } 7250 }
7210 7251
7211 } // namespace dart 7252 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_type_propagator.cc » ('j') | runtime/vm/object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698