Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 7433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7444 | 7444 |
| 7445 Dart_Handle source = NewString(kLoadSecond); | 7445 Dart_Handle source = NewString(kLoadSecond); |
| 7446 Dart_Handle url = NewString(TestCase::url()); | 7446 Dart_Handle url = NewString(TestCase::url()); |
| 7447 Dart_LoadSource(TestCase::lib(), url, source); | 7447 Dart_LoadSource(TestCase::lib(), url, source); |
| 7448 | 7448 |
| 7449 dart_args[0] = Dart_NewInteger(1); | 7449 dart_args[0] = Dart_NewInteger(1); |
| 7450 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 7450 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
| 7451 EXPECT_VALID(result); | 7451 EXPECT_VALID(result); |
| 7452 } | 7452 } |
| 7453 | 7453 |
| 7454 | |
| 7455 // Test external strings and optimized code. | |
|
Vyacheslav Egorov (Google)
2013/01/18 13:34:44
I don't like this static thingies. How about alloc
Florian Schneider
2013/01/18 16:22:38
Done.
| |
| 7456 static int peer = 12345; // Not used. | |
| 7457 static char str_data[100]; | |
| 7458 | |
| 7459 | |
| 7460 static void A_change_str_native(Dart_NativeArguments args) { | |
| 7461 Dart_EnterScope(); | |
| 7462 Dart_Handle str = Dart_GetNativeArgument(args, 0); | |
| 7463 EXPECT(Dart_IsString(str)); | |
| 7464 Dart_Handle result = Dart_MakeExternalString(str, | |
| 7465 &str_data, | |
| 7466 sizeof(str_data), | |
| 7467 &peer, | |
| 7468 NULL); | |
| 7469 EXPECT_VALID(result); | |
| 7470 Dart_ExitScope(); | |
| 7471 } | |
| 7472 | |
| 7473 | |
| 7474 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( | |
| 7475 Dart_Handle name, int argument_count) { | |
| 7476 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); | |
| 7477 } | |
| 7478 | |
| 7479 | |
| 7480 TEST_CASE(ExternalStringDeoptimize) { | |
| 7481 const char* kScriptChars = | |
| 7482 "String str = 'A';\n" | |
| 7483 "class A {\n" | |
| 7484 " static change_str(String s) native 'A_change_str';\n" | |
| 7485 "}\n" | |
| 7486 "sum_chars(String s, bool b) {\n" | |
| 7487 " var result = 0;\n" | |
| 7488 " for (var i = 0; i < s.length; i++) {\n" | |
| 7489 " if (b && i == 0) A.change_str(str);\n" | |
| 7490 " result += s.charCodeAt(i);" | |
| 7491 " }\n" | |
| 7492 " return result;\n" | |
| 7493 "}\n" | |
| 7494 "main() {\n" | |
| 7495 " str = '$str$str';\n" | |
| 7496 " for (var i = 0; i < 2000; i++) sum_chars(str, false);\n" | |
| 7497 " var x = sum_chars(str, false);\n" | |
| 7498 " var y = sum_chars(str, true);\n" | |
| 7499 " return x + y;\n" | |
| 7500 "}\n"; | |
| 7501 Dart_Handle lib = | |
| 7502 TestCase::LoadTestScript(kScriptChars, | |
| 7503 &ExternalStringDeoptimize_native_lookup); | |
| 7504 Dart_Handle result = Dart_Invoke(lib, | |
| 7505 NewString("main"), | |
| 7506 0, | |
| 7507 NULL); | |
| 7508 int64_t value = 0; | |
| 7509 result = Dart_IntegerToInt64(result, &value); | |
| 7510 EXPECT_VALID(result); | |
| 7511 EXPECT_EQ(260, value); | |
| 7512 } | |
| 7513 | |
| 7454 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7514 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 7455 | 7515 |
| 7456 } // namespace dart | 7516 } // namespace dart |
| OLD | NEW |