| 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 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( | 1847 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 1848 Assembler::kMinimalBufferSize, &actual_size, true)); | 1848 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 1849 CHECK(buffer); | 1849 CHECK(buffer); |
| 1850 HandleScope handles(isolate); | 1850 HandleScope handles(isolate); |
| 1851 | 1851 |
| 1852 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), | 1852 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 1853 v8::internal::CodeObjectRequired::kYes); | 1853 v8::internal::CodeObjectRequired::kYes); |
| 1854 assembler.enable_serializer(); | 1854 assembler.enable_serializer(); |
| 1855 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(0.3); | 1855 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(0.3); |
| 1856 CHECK(isolate->heap()->InNewSpace(*number)); | 1856 CHECK(isolate->heap()->InNewSpace(*number)); |
| 1857 MacroAssembler* masm = &assembler; | 1857 Handle<Code> code; |
| 1858 masm->MoveHeapObject(rax, number); | 1858 { |
| 1859 masm->ret(0); | 1859 MacroAssembler* masm = &assembler; |
| 1860 CodeDesc desc; | 1860 Handle<Cell> cell = isolate->factory()->NewCell(number); |
| 1861 masm->GetCode(&desc); | 1861 masm->Move(rax, cell, RelocInfo::CELL); |
| 1862 Handle<Code> code = isolate->factory()->NewCode( | 1862 masm->movp(rax, Operand(rax, 0)); |
| 1863 desc, Code::ComputeFlags(Code::FUNCTION), masm->CodeObject()); | 1863 masm->ret(0); |
| 1864 code->set_has_reloc_info_for_serialization(true); | 1864 CodeDesc desc; |
| 1865 | 1865 masm->GetCode(&desc); |
| 1866 code = isolate->factory()->NewCode(desc, Code::ComputeFlags(Code::FUNCTION), |
| 1867 masm->CodeObject()); |
| 1868 code->set_has_reloc_info_for_serialization(true); |
| 1869 } |
| 1866 RelocIterator rit1(*code, 1 << RelocInfo::CELL); | 1870 RelocIterator rit1(*code, 1 << RelocInfo::CELL); |
| 1867 CHECK_EQ(*number, rit1.rinfo()->target_cell()->value()); | 1871 CHECK_EQ(*number, rit1.rinfo()->target_cell()->value()); |
| 1868 | 1872 |
| 1869 Handle<String> source = isolate->factory()->empty_string(); | 1873 Handle<String> source = isolate->factory()->empty_string(); |
| 1870 Handle<SharedFunctionInfo> sfi = | 1874 Handle<SharedFunctionInfo> sfi = |
| 1871 isolate->factory()->NewSharedFunctionInfo(source, code, false); | 1875 isolate->factory()->NewSharedFunctionInfo(source, code, false); |
| 1872 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); | 1876 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); |
| 1873 | 1877 |
| 1874 Handle<SharedFunctionInfo> copy = | 1878 Handle<SharedFunctionInfo> copy = |
| 1875 CodeSerializer::Deserialize(isolate, script_data, source) | 1879 CodeSerializer::Deserialize(isolate, script_data, source) |
| 1876 .ToHandleChecked(); | 1880 .ToHandleChecked(); |
| 1877 RelocIterator rit2(copy->code(), 1 << RelocInfo::CELL); | 1881 RelocIterator rit2(copy->code(), 1 << RelocInfo::CELL); |
| 1878 CHECK(rit2.rinfo()->target_cell()->IsCell()); | 1882 CHECK(rit2.rinfo()->target_cell()->IsCell()); |
| 1879 Handle<Cell> cell(rit2.rinfo()->target_cell()); | 1883 Handle<Cell> cell(rit2.rinfo()->target_cell()); |
| 1880 CHECK(cell->value()->IsHeapNumber()); | 1884 CHECK(cell->value()->IsHeapNumber()); |
| 1881 CHECK_EQ(0.3, HeapNumber::cast(cell->value())->value()); | 1885 CHECK_EQ(0.3, HeapNumber::cast(cell->value())->value()); |
| 1882 | 1886 |
| 1883 delete script_data; | 1887 delete script_data; |
| 1884 } | 1888 } |
| 1885 #endif // V8_TARGET_ARCH_X64 | 1889 #endif // V8_TARGET_ARCH_X64 |
| 1886 | 1890 |
| 1887 TEST(SerializationMemoryStats) { | 1891 TEST(SerializationMemoryStats) { |
| 1888 FLAG_profile_deserialization = true; | 1892 FLAG_profile_deserialization = true; |
| 1889 FLAG_always_opt = false; | 1893 FLAG_always_opt = false; |
| 1890 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 1894 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 1891 delete[] blob.data; | 1895 delete[] blob.data; |
| 1892 } | 1896 } |
| OLD | NEW |