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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 11867020: Fix bug in optimization in the presence of externalized strings. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 7 years, 11 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_optimizer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
===================================================================
--- runtime/vm/dart_api_impl_test.cc (revision 17269)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -7451,6 +7451,71 @@
EXPECT_VALID(result);
}
+
+// Test external strings and optimized code.
+static void ExternalStringDeoptimize_Finalize(void* peer) {
+ delete[] reinterpret_cast<char*>(peer);
+}
+
+
+static void A_change_str_native(Dart_NativeArguments args) {
+ Dart_EnterScope();
+ Dart_Handle str = Dart_GetNativeArgument(args, 0);
+ EXPECT(Dart_IsString(str));
+ intptr_t size = 0;
+ EXPECT_VALID(Dart_StringStorageSize(str, &size));
+ char* str_data = new char[size];
+ Dart_Handle result =
+ Dart_MakeExternalString(str,
+ str_data,
+ size,
+ str_data,
+ &ExternalStringDeoptimize_Finalize);
+ EXPECT_VALID(result);
+ Dart_ExitScope();
+}
+
+
+static Dart_NativeFunction ExternalStringDeoptimize_native_lookup(
+ Dart_Handle name, int argument_count) {
+ return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native);
+}
+
+
+TEST_CASE(ExternalStringDeoptimize) {
+ const char* kScriptChars =
+ "String str = 'A';\n"
+ "class A {\n"
+ " static change_str(String s) native 'A_change_str';\n"
+ "}\n"
+ "sum_chars(String s, bool b) {\n"
+ " var result = 0;\n"
+ " for (var i = 0; i < s.length; i++) {\n"
+ " if (b && i == 0) A.change_str(str);\n"
+ " result += s.charCodeAt(i);"
+ " }\n"
+ " return result;\n"
+ "}\n"
+ "main() {\n"
+ " str = '$str$str';\n"
+ " for (var i = 0; i < 2000; i++) sum_chars(str, false);\n"
+ " var x = sum_chars(str, false);\n"
+ " var y = sum_chars(str, true);\n"
+ " return x + y;\n"
+ "}\n";
+ Dart_Handle lib =
+ TestCase::LoadTestScript(kScriptChars,
+ &ExternalStringDeoptimize_native_lookup);
+ Dart_Handle result = Dart_Invoke(lib,
+ NewString("main"),
+ 0,
+ NULL);
+ int64_t value = 0;
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(260, value);
+}
+
#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
} // namespace dart
« no previous file with comments | « no previous file | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698