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 "vm/assembler.h" | 5 #include "vm/assembler.h" |
6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 2446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 static_cast<int32_t>(entry_point), 0, 0, 0, 0)); | 2457 static_cast<int32_t>(entry_point), 0, 0, 0, 0)); |
2458 #else | 2458 #else |
2459 typedef intptr_t (*IncrementCode)(); | 2459 typedef intptr_t (*IncrementCode)(); |
2460 retval = reinterpret_cast<IncrementCode>(entry_point)(); | 2460 retval = reinterpret_cast<IncrementCode>(entry_point)(); |
2461 #endif | 2461 #endif |
2462 EXPECT_EQ(2, retval); | 2462 EXPECT_EQ(2, retval); |
2463 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point)); | 2463 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point)); |
2464 } | 2464 } |
2465 | 2465 |
2466 | 2466 |
| 2467 // Test for immutability of generated instructions. The test crashes with a |
| 2468 // segmentation fault when writing into it. |
| 2469 TEST_CASE(CodeImmutability) { |
| 2470 extern void GenerateIncrement(Assembler* assembler); |
| 2471 Assembler _assembler_; |
| 2472 GenerateIncrement(&_assembler_); |
| 2473 Code& code = Code::Handle(Code::FinalizeCode( |
| 2474 *CreateFunction("Test_Code"), &_assembler_)); |
| 2475 Instructions& instructions = Instructions::Handle(code.instructions()); |
| 2476 uword entry_point = instructions.EntryPoint(); |
| 2477 // Try writing into the generated code, expected to crash. |
| 2478 *(reinterpret_cast<char*>(entry_point) + 1) = 1; |
| 2479 intptr_t retval = 0; |
| 2480 #if defined(USING_SIMULATOR) |
| 2481 retval = bit_copy<intptr_t, int64_t>(Simulator::Current()->Call( |
| 2482 static_cast<int32_t>(entry_point), 0, 0, 0, 0)); |
| 2483 #else |
| 2484 typedef intptr_t (*IncrementCode)(); |
| 2485 retval = reinterpret_cast<IncrementCode>(entry_point)(); |
| 2486 #endif |
| 2487 EXPECT_EQ(3, retval); |
| 2488 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point)); |
| 2489 } |
| 2490 |
| 2491 |
2467 // Test for Embedded String object in the instructions. | 2492 // Test for Embedded String object in the instructions. |
2468 TEST_CASE(EmbedStringInCode) { | 2493 TEST_CASE(EmbedStringInCode) { |
2469 extern void GenerateEmbedStringInCode(Assembler* assembler, const char* str); | 2494 extern void GenerateEmbedStringInCode(Assembler* assembler, const char* str); |
2470 const char* kHello = "Hello World!"; | 2495 const char* kHello = "Hello World!"; |
2471 word expected_length = static_cast<word>(strlen(kHello)); | 2496 word expected_length = static_cast<word>(strlen(kHello)); |
2472 Assembler _assembler_; | 2497 Assembler _assembler_; |
2473 GenerateEmbedStringInCode(&_assembler_, kHello); | 2498 GenerateEmbedStringInCode(&_assembler_, kHello); |
2474 Code& code = Code::Handle(Code::FinalizeCode( | 2499 Code& code = Code::Handle(Code::FinalizeCode( |
2475 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); | 2500 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); |
2476 Instructions& instructions = Instructions::Handle(code.instructions()); | 2501 Instructions& instructions = Instructions::Handle(code.instructions()); |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3982 // Simple map. | 4007 // Simple map. |
3983 // | 4008 // |
3984 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} | 4009 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} |
3985 result = Dart_GetField(lib, NewString("simple_map")); | 4010 result = Dart_GetField(lib, NewString("simple_map")); |
3986 EXPECT_VALID(result); | 4011 EXPECT_VALID(result); |
3987 obj ^= Api::UnwrapHandle(result); | 4012 obj ^= Api::UnwrapHandle(result); |
3988 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); | 4013 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); |
3989 } | 4014 } |
3990 | 4015 |
3991 } // namespace dart | 4016 } // namespace dart |
OLD | NEW |