OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 return; | 2039 return; |
2040 } | 2040 } |
2041 } | 2041 } |
2042 } | 2042 } |
2043 // One of the strings in the natives cache should match the resource. We | 2043 // One of the strings in the natives cache should match the resource. We |
2044 // don't expect any other kinds of external strings here. | 2044 // don't expect any other kinds of external strings here. |
2045 UNREACHABLE(); | 2045 UNREACHABLE(); |
2046 } | 2046 } |
2047 | 2047 |
2048 | 2048 |
2049 static Code* CloneCodeObject(HeapObject* code) { | 2049 Address Serializer::ObjectSerializer::PrepareCode() { |
2050 Address copy = new byte[code->Size()]; | 2050 // To make snapshots reproducible, we make a copy of the code object |
2051 MemCopy(copy, code->address(), code->Size()); | 2051 // and wipe all pointers in the copy, which we then serialize. |
2052 return Code::cast(HeapObject::FromAddress(copy)); | 2052 Code* code = serializer_->CopyCode(Code::cast(object_)); |
2053 } | 2053 // Code age headers are not serializable. |
2054 | 2054 code->MakeYoung(serializer_->isolate()); |
2055 | |
2056 static void WipeOutRelocations(Code* code) { | |
2057 int mode_mask = | 2055 int mode_mask = |
2058 RelocInfo::kCodeTargetMask | | 2056 RelocInfo::kCodeTargetMask | |
2059 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | | 2057 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | |
2060 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | | 2058 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | |
2061 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); | 2059 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); |
2062 for (RelocIterator it(code, mode_mask); !it.done(); it.next()) { | 2060 for (RelocIterator it(code, mode_mask); !it.done(); it.next()) { |
2063 if (!(FLAG_enable_ool_constant_pool && it.rinfo()->IsInConstantPool())) { | 2061 if (!(FLAG_enable_ool_constant_pool && it.rinfo()->IsInConstantPool())) { |
2064 it.rinfo()->WipeOut(); | 2062 it.rinfo()->WipeOut(); |
2065 } | 2063 } |
2066 } | 2064 } |
| 2065 // We need to wipe out the header fields *after* wiping out the |
| 2066 // relocations, because some of these fields are needed for the latter. |
| 2067 code->WipeOutHeader(); |
| 2068 return code->address(); |
2067 } | 2069 } |
2068 | 2070 |
2069 | 2071 |
2070 int Serializer::ObjectSerializer::OutputRawData( | 2072 int Serializer::ObjectSerializer::OutputRawData( |
2071 Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) { | 2073 Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) { |
2072 Address object_start = object_->address(); | 2074 Address object_start = object_->address(); |
2073 int base = bytes_processed_so_far_; | 2075 int base = bytes_processed_so_far_; |
2074 int up_to_offset = static_cast<int>(up_to - object_start); | 2076 int up_to_offset = static_cast<int>(up_to - object_start); |
2075 int to_skip = up_to_offset - bytes_processed_so_far_; | 2077 int to_skip = up_to_offset - bytes_processed_so_far_; |
2076 int bytes_to_output = to_skip; | 2078 int bytes_to_output = to_skip; |
(...skipping 17 matching lines...) Expand all Loading... |
2094 to_skip = 0; /* This insn already skips. */ \ | 2096 to_skip = 0; /* This insn already skips. */ \ |
2095 } else /* NOLINT */ | 2097 } else /* NOLINT */ |
2096 COMMON_RAW_LENGTHS(RAW_CASE) | 2098 COMMON_RAW_LENGTHS(RAW_CASE) |
2097 #undef RAW_CASE | 2099 #undef RAW_CASE |
2098 { /* NOLINT */ | 2100 { /* NOLINT */ |
2099 // We always end up here if we are outputting the code of a code object. | 2101 // We always end up here if we are outputting the code of a code object. |
2100 sink_->Put(kRawData, "RawData"); | 2102 sink_->Put(kRawData, "RawData"); |
2101 sink_->PutInt(bytes_to_output, "length"); | 2103 sink_->PutInt(bytes_to_output, "length"); |
2102 } | 2104 } |
2103 | 2105 |
2104 // To make snapshots reproducible, we need to wipe out all pointers in code. | 2106 if (code_object_) object_start = PrepareCode(); |
2105 if (code_object_) { | |
2106 Code* code = CloneCodeObject(object_); | |
2107 // Code age headers are not serializable. | |
2108 code->MakeYoung(serializer_->isolate()); | |
2109 WipeOutRelocations(code); | |
2110 // We need to wipe out the header fields *after* wiping out the | |
2111 // relocations, because some of these fields are needed for the latter. | |
2112 code->WipeOutHeader(); | |
2113 object_start = code->address(); | |
2114 } | |
2115 | 2107 |
2116 const char* description = code_object_ ? "Code" : "Byte"; | 2108 const char* description = code_object_ ? "Code" : "Byte"; |
2117 #ifdef MEMORY_SANITIZER | 2109 #ifdef MEMORY_SANITIZER |
2118 // Object sizes are usually rounded up with uninitialized padding space. | 2110 // Object sizes are usually rounded up with uninitialized padding space. |
2119 MSAN_MEMORY_IS_INITIALIZED(object_start + base, bytes_to_output); | 2111 MSAN_MEMORY_IS_INITIALIZED(object_start + base, bytes_to_output); |
2120 #endif // MEMORY_SANITIZER | 2112 #endif // MEMORY_SANITIZER |
2121 sink_->PutRaw(object_start + base, bytes_to_output, description); | 2113 sink_->PutRaw(object_start + base, bytes_to_output, description); |
2122 if (code_object_) delete[] object_start; | |
2123 } | 2114 } |
2124 if (to_skip != 0 && return_skip == kIgnoringReturn) { | 2115 if (to_skip != 0 && return_skip == kIgnoringReturn) { |
2125 sink_->Put(kSkip, "Skip"); | 2116 sink_->Put(kSkip, "Skip"); |
2126 sink_->PutInt(to_skip, "SkipDistance"); | 2117 sink_->PutInt(to_skip, "SkipDistance"); |
2127 to_skip = 0; | 2118 to_skip = 0; |
2128 } | 2119 } |
2129 return to_skip; | 2120 return to_skip; |
2130 } | 2121 } |
2131 | 2122 |
2132 | 2123 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2171 } | 2162 } |
2172 } | 2163 } |
2173 | 2164 |
2174 | 2165 |
2175 void Serializer::InitializeCodeAddressMap() { | 2166 void Serializer::InitializeCodeAddressMap() { |
2176 isolate_->InitializeLoggingAndCounters(); | 2167 isolate_->InitializeLoggingAndCounters(); |
2177 code_address_map_ = new CodeAddressMap(isolate_); | 2168 code_address_map_ = new CodeAddressMap(isolate_); |
2178 } | 2169 } |
2179 | 2170 |
2180 | 2171 |
| 2172 Code* Serializer::CopyCode(Code* code) { |
| 2173 code_buffer_.Rewind(0); // Clear buffer without deleting backing store. |
| 2174 int size = code->CodeSize(); |
| 2175 code_buffer_.AddAll(Vector<byte>(code->address(), size)); |
| 2176 return Code::cast(HeapObject::FromAddress(&code_buffer_.first())); |
| 2177 } |
| 2178 |
| 2179 |
2181 ScriptData* CodeSerializer::Serialize(Isolate* isolate, | 2180 ScriptData* CodeSerializer::Serialize(Isolate* isolate, |
2182 Handle<SharedFunctionInfo> info, | 2181 Handle<SharedFunctionInfo> info, |
2183 Handle<String> source) { | 2182 Handle<String> source) { |
2184 base::ElapsedTimer timer; | 2183 base::ElapsedTimer timer; |
2185 if (FLAG_profile_deserialization) timer.Start(); | 2184 if (FLAG_profile_deserialization) timer.Start(); |
2186 if (FLAG_trace_serializer) { | 2185 if (FLAG_trace_serializer) { |
2187 PrintF("[Serializing from"); | 2186 PrintF("[Serializing from"); |
2188 Object* script = info->script(); | 2187 Object* script = info->script(); |
2189 if (script->IsScript()) Script::cast(script)->name()->ShortPrint(); | 2188 if (script->IsScript()) Script::cast(script)->name()->ShortPrint(); |
2190 PrintF("]\n"); | 2189 PrintF("]\n"); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2653 DisallowHeapAllocation no_gc; | 2652 DisallowHeapAllocation no_gc; |
2654 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2653 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2655 SanityCheckResult r = scd->SanityCheck(source); | 2654 SanityCheckResult r = scd->SanityCheck(source); |
2656 if (r == CHECK_SUCCESS) return scd; | 2655 if (r == CHECK_SUCCESS) return scd; |
2657 cached_data->Reject(); | 2656 cached_data->Reject(); |
2658 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2657 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2659 delete scd; | 2658 delete scd; |
2660 return NULL; | 2659 return NULL; |
2661 } | 2660 } |
2662 } } // namespace v8::internal | 2661 } } // namespace v8::internal |
OLD | NEW |