| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( | 1854 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 1855 Assembler::kMinimalBufferSize, &actual_size, true)); | 1855 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 1856 CHECK(buffer); | 1856 CHECK(buffer); |
| 1857 HandleScope handles(isolate); | 1857 HandleScope handles(isolate); |
| 1858 | 1858 |
| 1859 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), | 1859 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 1860 v8::internal::CodeObjectRequired::kYes); | 1860 v8::internal::CodeObjectRequired::kYes); |
| 1861 assembler.enable_serializer(); | 1861 assembler.enable_serializer(); |
| 1862 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(0.3); | 1862 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(0.3); |
| 1863 CHECK(isolate->heap()->InNewSpace(*number)); | 1863 CHECK(isolate->heap()->InNewSpace(*number)); |
| 1864 MacroAssembler* masm = &assembler; | 1864 Handle<Code> code; |
| 1865 masm->MoveHeapObject(rax, number); | 1865 { |
| 1866 masm->ret(0); | 1866 MacroAssembler* masm = &assembler; |
| 1867 CodeDesc desc; | 1867 Handle<Cell> cell = isolate->factory()->NewCell(number); |
| 1868 masm->GetCode(&desc); | 1868 masm->Move(rax, cell, RelocInfo::CELL); |
| 1869 Handle<Code> code = isolate->factory()->NewCode( | 1869 masm->movp(rax, Operand(rax, 0)); |
| 1870 desc, Code::ComputeFlags(Code::FUNCTION), masm->CodeObject()); | 1870 masm->ret(0); |
| 1871 code->set_has_reloc_info_for_serialization(true); | 1871 CodeDesc desc; |
| 1872 | 1872 masm->GetCode(&desc); |
| 1873 code = isolate->factory()->NewCode(desc, Code::ComputeFlags(Code::FUNCTION), |
| 1874 masm->CodeObject()); |
| 1875 code->set_has_reloc_info_for_serialization(true); |
| 1876 } |
| 1873 RelocIterator rit1(*code, 1 << RelocInfo::CELL); | 1877 RelocIterator rit1(*code, 1 << RelocInfo::CELL); |
| 1874 CHECK_EQ(*number, rit1.rinfo()->target_cell()->value()); | 1878 CHECK_EQ(*number, rit1.rinfo()->target_cell()->value()); |
| 1875 | 1879 |
| 1876 Handle<String> source = isolate->factory()->empty_string(); | 1880 Handle<String> source = isolate->factory()->empty_string(); |
| 1877 Handle<SharedFunctionInfo> sfi = | 1881 Handle<SharedFunctionInfo> sfi = |
| 1878 isolate->factory()->NewSharedFunctionInfo(source, code, false); | 1882 isolate->factory()->NewSharedFunctionInfo(source, code, false); |
| 1879 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); | 1883 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); |
| 1880 | 1884 |
| 1881 Handle<SharedFunctionInfo> copy = | 1885 Handle<SharedFunctionInfo> copy = |
| 1882 CodeSerializer::Deserialize(isolate, script_data, source) | 1886 CodeSerializer::Deserialize(isolate, script_data, source) |
| 1883 .ToHandleChecked(); | 1887 .ToHandleChecked(); |
| 1884 RelocIterator rit2(copy->code(), 1 << RelocInfo::CELL); | 1888 RelocIterator rit2(copy->code(), 1 << RelocInfo::CELL); |
| 1885 CHECK(rit2.rinfo()->target_cell()->IsCell()); | 1889 CHECK(rit2.rinfo()->target_cell()->IsCell()); |
| 1886 Handle<Cell> cell(rit2.rinfo()->target_cell()); | 1890 Handle<Cell> cell(rit2.rinfo()->target_cell()); |
| 1887 CHECK(cell->value()->IsHeapNumber()); | 1891 CHECK(cell->value()->IsHeapNumber()); |
| 1888 CHECK_EQ(0.3, HeapNumber::cast(cell->value())->value()); | 1892 CHECK_EQ(0.3, HeapNumber::cast(cell->value())->value()); |
| 1889 | 1893 |
| 1890 delete script_data; | 1894 delete script_data; |
| 1891 } | 1895 } |
| 1892 #endif // V8_TARGET_ARCH_X64 | 1896 #endif // V8_TARGET_ARCH_X64 |
| 1893 | 1897 |
| 1894 TEST(SerializationMemoryStats) { | 1898 TEST(SerializationMemoryStats) { |
| 1895 FLAG_profile_deserialization = true; | 1899 FLAG_profile_deserialization = true; |
| 1896 FLAG_always_opt = false; | 1900 FLAG_always_opt = false; |
| 1897 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 1901 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 1898 delete[] blob.data; | 1902 delete[] blob.data; |
| 1899 } | 1903 } |
| OLD | NEW |