| 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 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1930 where_to_point, skip); | 1930 where_to_point, skip); |
| 1931 return; | 1931 return; |
| 1932 } | 1932 } |
| 1933 | 1933 |
| 1934 if (heap_object->IsCode()) { | 1934 if (heap_object->IsCode()) { |
| 1935 Code* code_object = Code::cast(heap_object); | 1935 Code* code_object = Code::cast(heap_object); |
| 1936 if (code_object->kind() == Code::BUILTIN) { | 1936 if (code_object->kind() == Code::BUILTIN) { |
| 1937 SerializeBuiltin(code_object, how_to_code, where_to_point, skip); | 1937 SerializeBuiltin(code_object, how_to_code, where_to_point, skip); |
| 1938 return; | 1938 return; |
| 1939 } | 1939 } |
| 1940 // TODO(yangguo) figure out whether other code kinds can be handled smarter. |
| 1940 } | 1941 } |
| 1941 | 1942 |
| 1942 if (heap_object == source_) { | 1943 if (heap_object == source_) { |
| 1943 SerializeSourceObject(how_to_code, where_to_point, skip); | 1944 SerializeSourceObject(how_to_code, where_to_point, skip); |
| 1944 return; | 1945 return; |
| 1945 } | 1946 } |
| 1946 | 1947 |
| 1947 if (skip != 0) { | 1948 if (skip != 0) { |
| 1948 sink_->Put(kSkip, "SkipFromSerializeObject"); | 1949 sink_->Put(kSkip, "SkipFromSerializeObject"); |
| 1949 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); | 1950 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); |
| 1950 } | 1951 } |
| 1951 // Object has not yet been serialized. Serialize it here. | 1952 // Object has not yet been serialized. Serialize it here. |
| 1952 ObjectSerializer serializer(this, heap_object, sink_, how_to_code, | 1953 ObjectSerializer serializer(this, heap_object, sink_, how_to_code, |
| 1953 where_to_point); | 1954 where_to_point); |
| 1954 serializer.Serialize(); | 1955 serializer.Serialize(); |
| 1955 } | 1956 } |
| 1956 | 1957 |
| 1957 | 1958 |
| 1958 void CodeSerializer::SerializeBuiltin(Code* builtin, HowToCode how_to_code, | 1959 void CodeSerializer::SerializeBuiltin(Code* builtin, HowToCode how_to_code, |
| 1959 WhereToPoint where_to_point, int skip) { | 1960 WhereToPoint where_to_point, int skip) { |
| 1960 if (skip != 0) { | 1961 if (skip != 0) { |
| 1961 sink_->Put(kSkip, "SkipFromSerializeBuiltin"); | 1962 sink_->Put(kSkip, "SkipFromSerializeBuiltin"); |
| 1962 sink_->PutInt(skip, "SkipDistanceFromSerializeBuiltin"); | 1963 sink_->PutInt(skip, "SkipDistanceFromSerializeBuiltin"); |
| 1963 } | 1964 } |
| 1964 | 1965 |
| 1965 ASSERT((how_to_code == kPlain && where_to_point == kStartOfObject) || | 1966 ASSERT((how_to_code == kPlain && where_to_point == kStartOfObject) || |
| 1966 (how_to_code == kFromCode && where_to_point == kInnerPointer)); | 1967 (how_to_code == kFromCode && where_to_point == kInnerPointer)); |
| 1967 int id = 0; | 1968 int builtin_index = builtin->builtin_index(); |
| 1968 do { // Look for existing builtins in the list. | 1969 ASSERT_LT(builtin_index, Builtins::builtin_count); |
| 1969 Code* b = isolate()->builtins()->builtin(static_cast<Builtins::Name>(id)); | 1970 ASSERT_LE(0, builtin_index); |
| 1970 if (builtin == b) break; | |
| 1971 } while (++id < Builtins::builtin_count); | |
| 1972 ASSERT(id < Builtins::builtin_count); // We must have found a one. | |
| 1973 | |
| 1974 sink_->Put(kBuiltin + how_to_code + where_to_point, "Builtin"); | 1971 sink_->Put(kBuiltin + how_to_code + where_to_point, "Builtin"); |
| 1975 sink_->PutInt(id, "builtin_index"); | 1972 sink_->PutInt(builtin_index, "builtin_index"); |
| 1976 } | 1973 } |
| 1977 | 1974 |
| 1978 | 1975 |
| 1979 void CodeSerializer::SerializeSourceObject(HowToCode how_to_code, | 1976 void CodeSerializer::SerializeSourceObject(HowToCode how_to_code, |
| 1980 WhereToPoint where_to_point, | 1977 WhereToPoint where_to_point, |
| 1981 int skip) { | 1978 int skip) { |
| 1982 if (skip != 0) { | 1979 if (skip != 0) { |
| 1983 sink_->Put(kSkip, "SkipFromSerializeSourceObject"); | 1980 sink_->Put(kSkip, "SkipFromSerializeSourceObject"); |
| 1984 sink_->PutInt(skip, "SkipDistanceFromSerializeSourceObject"); | 1981 sink_->PutInt(skip, "SkipDistanceFromSerializeSourceObject"); |
| 1985 } | 1982 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i)); | 2027 SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i)); |
| 2031 } | 2028 } |
| 2032 } | 2029 } |
| 2033 | 2030 |
| 2034 | 2031 |
| 2035 bool SerializedCodeData::IsSane() { | 2032 bool SerializedCodeData::IsSane() { |
| 2036 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && | 2033 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && |
| 2037 PayloadLength() >= SharedFunctionInfo::kSize; | 2034 PayloadLength() >= SharedFunctionInfo::kSize; |
| 2038 } | 2035 } |
| 2039 } } // namespace v8::internal | 2036 } } // namespace v8::internal |
| OLD | NEW |