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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include <sys/stat.h> | 30 #include <sys/stat.h> |
31 | 31 |
32 #include "src/v8.h" | 32 #include "src/v8.h" |
33 | 33 |
34 #include "src/ast/scopeinfo.h" | 34 #include "src/ast/scopeinfo.h" |
35 #include "src/bootstrapper.h" | 35 #include "src/bootstrapper.h" |
36 #include "src/compilation-cache.h" | 36 #include "src/compilation-cache.h" |
37 #include "src/debug/debug.h" | 37 #include "src/debug/debug.h" |
38 #include "src/heap/spaces.h" | 38 #include "src/heap/spaces.h" |
| 39 #include "src/macro-assembler.h" |
39 #include "src/objects.h" | 40 #include "src/objects.h" |
40 #include "src/parsing/parser.h" | 41 #include "src/parsing/parser.h" |
41 #include "src/runtime/runtime.h" | 42 #include "src/runtime/runtime.h" |
42 #include "src/snapshot/code-serializer.h" | 43 #include "src/snapshot/code-serializer.h" |
43 #include "src/snapshot/deserializer.h" | 44 #include "src/snapshot/deserializer.h" |
44 #include "src/snapshot/natives.h" | 45 #include "src/snapshot/natives.h" |
45 #include "src/snapshot/partial-serializer.h" | 46 #include "src/snapshot/partial-serializer.h" |
46 #include "src/snapshot/snapshot.h" | 47 #include "src/snapshot/snapshot.h" |
47 #include "src/snapshot/startup-serializer.h" | 48 #include "src/snapshot/startup-serializer.h" |
48 #include "test/cctest/cctest.h" | 49 #include "test/cctest/cctest.h" |
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 &script_data, v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE, | 1827 &script_data, v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE, |
1827 false); | 1828 false); |
1828 delete script_data; | 1829 delete script_data; |
1829 | 1830 |
1830 SimulateIncrementalMarking(isolate->heap()); | 1831 SimulateIncrementalMarking(isolate->heap()); |
1831 | 1832 |
1832 script_data = CodeSerializer::Serialize(isolate, shared, source); | 1833 script_data = CodeSerializer::Serialize(isolate, shared, source); |
1833 delete script_data; | 1834 delete script_data; |
1834 } | 1835 } |
1835 | 1836 |
| 1837 #if V8_TARGET_ARCH_X64 |
| 1838 TEST(CodeSerializerCell) { |
| 1839 FLAG_serialize_toplevel = true; |
| 1840 LocalContext context; |
| 1841 Isolate* isolate = CcTest::i_isolate(); |
| 1842 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1843 |
| 1844 v8::HandleScope scope(CcTest::isolate()); |
| 1845 |
| 1846 size_t actual_size; |
| 1847 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 1848 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 1849 CHECK(buffer); |
| 1850 HandleScope handles(isolate); |
| 1851 |
| 1852 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 1853 v8::internal::CodeObjectRequired::kYes); |
| 1854 assembler.enable_serializer(); |
| 1855 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(0.3); |
| 1856 CHECK(isolate->heap()->InNewSpace(*number)); |
| 1857 MacroAssembler* masm = &assembler; |
| 1858 masm->MoveHeapObject(rax, number); |
| 1859 masm->ret(0); |
| 1860 CodeDesc desc; |
| 1861 masm->GetCode(&desc); |
| 1862 Handle<Code> code = isolate->factory()->NewCode( |
| 1863 desc, Code::ComputeFlags(Code::FUNCTION), masm->CodeObject()); |
| 1864 code->set_has_reloc_info_for_serialization(true); |
| 1865 |
| 1866 RelocIterator rit1(*code, 1 << RelocInfo::CELL); |
| 1867 CHECK_EQ(*number, rit1.rinfo()->target_cell()->value()); |
| 1868 |
| 1869 Handle<String> source = isolate->factory()->empty_string(); |
| 1870 Handle<SharedFunctionInfo> sfi = |
| 1871 isolate->factory()->NewSharedFunctionInfo(source, code, false); |
| 1872 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); |
| 1873 |
| 1874 Handle<SharedFunctionInfo> copy = |
| 1875 CodeSerializer::Deserialize(isolate, script_data, source) |
| 1876 .ToHandleChecked(); |
| 1877 RelocIterator rit2(copy->code(), 1 << RelocInfo::CELL); |
| 1878 CHECK(rit2.rinfo()->target_cell()->IsCell()); |
| 1879 Handle<Cell> cell(rit2.rinfo()->target_cell()); |
| 1880 CHECK(cell->value()->IsHeapNumber()); |
| 1881 CHECK_EQ(0.3, HeapNumber::cast(cell->value())->value()); |
| 1882 |
| 1883 delete script_data; |
| 1884 } |
| 1885 #endif // V8_TARGET_ARCH_X64 |
1836 | 1886 |
1837 TEST(SerializationMemoryStats) { | 1887 TEST(SerializationMemoryStats) { |
1838 FLAG_profile_deserialization = true; | 1888 FLAG_profile_deserialization = true; |
1839 FLAG_always_opt = false; | 1889 FLAG_always_opt = false; |
1840 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 1890 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
1841 delete[] blob.data; | 1891 delete[] blob.data; |
1842 } | 1892 } |
OLD | NEW |