| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // Read object back from the snapshot into a C structure. | 248 // Read object back from the snapshot into a C structure. |
| 249 ApiMessageReader api_reader(buffer, buffer_len); | 249 ApiMessageReader api_reader(buffer, buffer_len); |
| 250 Dart_CObject* root = api_reader.ReadMessage(); | 250 Dart_CObject* root = api_reader.ReadMessage(); |
| 251 EXPECT_NOTNULL(root); | 251 EXPECT_NOTNULL(root); |
| 252 CheckEncodeDecodeMessage(root); | 252 CheckEncodeDecodeMessage(root); |
| 253 return root; | 253 return root; |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| 257 void CheckMint(int64_t value) { | 257 void CheckMint(int64_t value) { |
| 258 ApiNativeScope scope; |
| 258 StackZone zone(Thread::Current()); | 259 StackZone zone(Thread::Current()); |
| 259 | 260 |
| 260 Mint& mint = Mint::Handle(); | 261 Mint& mint = Mint::Handle(); |
| 261 mint ^= Integer::New(value); | 262 mint ^= Integer::New(value); |
| 262 ApiNativeScope scope; | |
| 263 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint); | 263 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint); |
| 264 // On 64-bit platforms mints always require 64-bits as the smi range | 264 // On 64-bit platforms mints always require 64-bits as the smi range |
| 265 // here covers most of the 64-bit range. On 32-bit platforms the smi | 265 // here covers most of the 64-bit range. On 32-bit platforms the smi |
| 266 // range covers most of the 32-bit range and values outside that | 266 // range covers most of the 32-bit range and values outside that |
| 267 // range are also represented as mints. | 267 // range are also represented as mints. |
| 268 #if defined(ARCH_IS_64_BIT) | 268 #if defined(ARCH_IS_64_BIT) |
| 269 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); | 269 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type); |
| 270 EXPECT_EQ(value, mint_cobject->value.as_int64); | 270 EXPECT_EQ(value, mint_cobject->value.as_int64); |
| 271 #else | 271 #else |
| 272 if (kMinInt32 < value && value < kMaxInt32) { | 272 if (kMinInt32 < value && value < kMaxInt32) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 ApiMessageReader api_reader(buffer, buffer_len); | 469 ApiMessageReader api_reader(buffer, buffer_len); |
| 470 Dart_CObject* root = api_reader.ReadMessage(); | 470 Dart_CObject* root = api_reader.ReadMessage(); |
| 471 // Bigint not supported. | 471 // Bigint not supported. |
| 472 EXPECT_NOTNULL(root); | 472 EXPECT_NOTNULL(root); |
| 473 CheckEncodeDecodeMessage(root); | 473 CheckEncodeDecodeMessage(root); |
| 474 return root; | 474 return root; |
| 475 } | 475 } |
| 476 | 476 |
| 477 | 477 |
| 478 void CheckBigint(const char* bigint_value) { | 478 void CheckBigint(const char* bigint_value) { |
| 479 ApiNativeScope scope; |
| 479 StackZone zone(Thread::Current()); | 480 StackZone zone(Thread::Current()); |
| 480 Bigint& bigint = Bigint::Handle(); | 481 Bigint& bigint = Bigint::Handle(); |
| 481 bigint ^= Bigint::NewFromCString(bigint_value); | 482 bigint ^= Bigint::NewFromCString(bigint_value); |
| 482 ApiNativeScope scope; | |
| 483 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); | 483 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); |
| 484 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); | 484 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); |
| 485 char* hex_value = TestCase::BigintToHexValue(bigint_cobject); | 485 char* hex_value = TestCase::BigintToHexValue(bigint_cobject); |
| 486 EXPECT_STREQ(bigint_value, hex_value); | 486 EXPECT_STREQ(bigint_value, hex_value); |
| 487 free(hex_value); | 487 free(hex_value); |
| 488 } | 488 } |
| 489 | 489 |
| 490 | 490 |
| 491 TEST_CASE(SerializeBigint2) { | 491 TEST_CASE(SerializeBigint2) { |
| 492 CheckBigint("0x0"); | 492 CheckBigint("0x0"); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 EXPECT(root->value.as_typed_data.values == NULL); | 824 EXPECT(root->value.as_typed_data.values == NULL); |
| 825 CheckEncodeDecodeMessage(root); | 825 CheckEncodeDecodeMessage(root); |
| 826 } | 826 } |
| 827 | 827 |
| 828 | 828 |
| 829 class TestSnapshotWriter : public SnapshotWriter { | 829 class TestSnapshotWriter : public SnapshotWriter { |
| 830 public: | 830 public: |
| 831 static const intptr_t kInitialSize = 64 * KB; | 831 static const intptr_t kInitialSize = 64 * KB; |
| 832 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 832 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
| 833 : SnapshotWriter(Snapshot::kScript, | 833 : SnapshotWriter(Snapshot::kScript, |
| 834 Thread::Current(), |
| 834 buffer, | 835 buffer, |
| 835 alloc, | 836 alloc, |
| 836 kInitialSize, | 837 kInitialSize, |
| 837 &forward_list_, | 838 &forward_list_, |
| 838 NULL, /* test_writer */ | 839 NULL, /* test_writer */ |
| 839 true, /* can_send_any_object */ | 840 true, /* can_send_any_object */ |
| 840 false, /* snapshot_code */ | 841 false, /* snapshot_code */ |
| 841 true /* vm_isolate_is_symbolic */), | 842 true /* vm_isolate_is_symbolic */), |
| 842 forward_list_(kMaxPredefinedObjectIds) { | 843 forward_list_(thread(), kMaxPredefinedObjectIds) { |
| 843 ASSERT(buffer != NULL); | 844 ASSERT(buffer != NULL); |
| 844 ASSERT(alloc != NULL); | 845 ASSERT(alloc != NULL); |
| 845 } | 846 } |
| 846 ~TestSnapshotWriter() { } | 847 ~TestSnapshotWriter() { } |
| 847 | 848 |
| 848 // Writes just a script object | 849 // Writes just a script object |
| 849 void WriteScript(const Script& script) { | 850 void WriteScript(const Script& script) { |
| 850 WriteObject(script.raw()); | 851 WriteObject(script.raw()); |
| 851 UnmarkAll(); | |
| 852 } | 852 } |
| 853 | 853 |
| 854 private: | 854 private: |
| 855 ForwardList forward_list_; | 855 ForwardList forward_list_; |
| 856 | 856 |
| 857 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); | 857 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); |
| 858 }; | 858 }; |
| 859 | 859 |
| 860 | 860 |
| 861 static void GenerateSourceAndCheck(const Script& script) { | 861 static void GenerateSourceAndCheck(const Script& script) { |
| (...skipping 2134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2996 StackZone zone(Thread::Current()); | 2996 StackZone zone(Thread::Current()); |
| 2997 uint8_t* buffer; | 2997 uint8_t* buffer; |
| 2998 MessageWriter writer(&buffer, &zone_allocator, true); | 2998 MessageWriter writer(&buffer, &zone_allocator, true); |
| 2999 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2999 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
| 3000 // For performance, we'd like single-byte headers when ids are omitted. | 3000 // For performance, we'd like single-byte headers when ids are omitted. |
| 3001 // If this starts failing, consider renumbering the snapshot ids. | 3001 // If this starts failing, consider renumbering the snapshot ids. |
| 3002 EXPECT_EQ(1, writer.BytesWritten()); | 3002 EXPECT_EQ(1, writer.BytesWritten()); |
| 3003 } | 3003 } |
| 3004 | 3004 |
| 3005 } // namespace dart | 3005 } // namespace dart |
| OLD | NEW |