| 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 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1955 DisableAlwaysOpt(); | 1955 DisableAlwaysOpt(); |
| 1956 v8::StartupData blob; | 1956 v8::StartupData blob; |
| 1957 { | 1957 { |
| 1958 v8::SnapshotCreator creator; | 1958 v8::SnapshotCreator creator; |
| 1959 v8::Isolate* isolate = creator.GetIsolate(); | 1959 v8::Isolate* isolate = creator.GetIsolate(); |
| 1960 { | 1960 { |
| 1961 v8::HandleScope handle_scope(isolate); | 1961 v8::HandleScope handle_scope(isolate); |
| 1962 v8::Local<v8::Context> context = v8::Context::New(isolate); | 1962 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 1963 v8::Context::Scope context_scope(context); | 1963 v8::Context::Scope context_scope(context); |
| 1964 CompileRun("var f = function() { return 1; }"); | 1964 CompileRun("var f = function() { return 1; }"); |
| 1965 CHECK_EQ(0, creator.AddContext(context)); | 1965 CHECK_EQ(0u, creator.AddContext(context)); |
| 1966 } | 1966 } |
| 1967 { | 1967 { |
| 1968 v8::HandleScope handle_scope(isolate); | 1968 v8::HandleScope handle_scope(isolate); |
| 1969 v8::Local<v8::Context> context = v8::Context::New(isolate); | 1969 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 1970 v8::Context::Scope context_scope(context); | 1970 v8::Context::Scope context_scope(context); |
| 1971 CompileRun("var f = function() { return 2; }"); | 1971 CompileRun("var f = function() { return 2; }"); |
| 1972 CHECK_EQ(1, creator.AddContext(context)); | 1972 CHECK_EQ(1u, creator.AddContext(context)); |
| 1973 } | 1973 } |
| 1974 { | 1974 { |
| 1975 v8::HandleScope handle_scope(isolate); | 1975 v8::HandleScope handle_scope(isolate); |
| 1976 v8::Local<v8::Context> context = v8::Context::New(isolate); | 1976 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 1977 CHECK_EQ(2, creator.AddContext(context)); | 1977 CHECK_EQ(2u, creator.AddContext(context)); |
| 1978 } | 1978 } |
| 1979 blob = | 1979 blob = |
| 1980 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 1980 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
| 1981 } | 1981 } |
| 1982 | 1982 |
| 1983 v8::Isolate::CreateParams params; | 1983 v8::Isolate::CreateParams params; |
| 1984 params.snapshot_blob = &blob; | 1984 params.snapshot_blob = &blob; |
| 1985 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1985 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 1986 v8::Isolate* isolate = v8::Isolate::New(params); | 1986 v8::Isolate* isolate = v8::Isolate::New(params); |
| 1987 { | 1987 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 { | 2037 { |
| 2038 v8::HandleScope handle_scope(isolate); | 2038 v8::HandleScope handle_scope(isolate); |
| 2039 v8::Local<v8::Context> context = v8::Context::New(isolate); | 2039 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 2040 v8::Context::Scope context_scope(context); | 2040 v8::Context::Scope context_scope(context); |
| 2041 v8::Local<v8::FunctionTemplate> callback = | 2041 v8::Local<v8::FunctionTemplate> callback = |
| 2042 v8::FunctionTemplate::New(isolate, SerializedCallback); | 2042 v8::FunctionTemplate::New(isolate, SerializedCallback); |
| 2043 v8::Local<v8::Value> function = | 2043 v8::Local<v8::Value> function = |
| 2044 callback->GetFunction(context).ToLocalChecked(); | 2044 callback->GetFunction(context).ToLocalChecked(); |
| 2045 CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust()); | 2045 CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust()); |
| 2046 ExpectInt32("f()", 42); | 2046 ExpectInt32("f()", 42); |
| 2047 CHECK_EQ(0, creator.AddContext(context)); | 2047 CHECK_EQ(0u, creator.AddContext(context)); |
| 2048 } | 2048 } |
| 2049 blob = | 2049 blob = |
| 2050 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 2050 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
| 2051 } | 2051 } |
| 2052 | 2052 |
| 2053 // Deserialize with the original external reference. | 2053 // Deserialize with the original external reference. |
| 2054 { | 2054 { |
| 2055 v8::Isolate::CreateParams params; | 2055 v8::Isolate::CreateParams params; |
| 2056 params.snapshot_blob = &blob; | 2056 params.snapshot_blob = &blob; |
| 2057 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2057 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 v8::Local<v8::Context> context = v8::Context::New(isolate); | 2097 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 2098 v8::Context::Scope context_scope(context); | 2098 v8::Context::Scope context_scope(context); |
| 2099 | 2099 |
| 2100 v8::Local<v8::FunctionTemplate> callback = | 2100 v8::Local<v8::FunctionTemplate> callback = |
| 2101 v8::FunctionTemplate::New(isolate, SerializedCallback); | 2101 v8::FunctionTemplate::New(isolate, SerializedCallback); |
| 2102 v8::Local<v8::Value> function = | 2102 v8::Local<v8::Value> function = |
| 2103 callback->GetFunction(context).ToLocalChecked(); | 2103 callback->GetFunction(context).ToLocalChecked(); |
| 2104 CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust()); | 2104 CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust()); |
| 2105 ExpectInt32("f()", 42); | 2105 ExpectInt32("f()", 42); |
| 2106 | 2106 |
| 2107 CHECK_EQ(0, creator.AddContext(context)); | 2107 CHECK_EQ(0u, creator.AddContext(context)); |
| 2108 } | 2108 } |
| 2109 v8::StartupData blob = | 2109 v8::StartupData blob = |
| 2110 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 2110 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
| 2111 | 2111 |
| 2112 delete[] blob.data; | 2112 delete[] blob.data; |
| 2113 } | 2113 } |
| 2114 | 2114 |
| 2115 struct InternalFieldData { | 2115 struct InternalFieldData { |
| 2116 uint32_t data; | 2116 uint32_t data; |
| 2117 }; | 2117 }; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2170 v8::Local<v8::Object> c = | 2170 v8::Local<v8::Object> c = |
| 2171 object_template->NewInstance(context).ToLocalChecked(); | 2171 object_template->NewInstance(context).ToLocalChecked(); |
| 2172 a->SetInternalField(0, b); | 2172 a->SetInternalField(0, b); |
| 2173 a->SetAlignedPointerInInternalField(1, a1); | 2173 a->SetAlignedPointerInInternalField(1, a1); |
| 2174 b->SetAlignedPointerInInternalField(0, b0); | 2174 b->SetAlignedPointerInInternalField(0, b0); |
| 2175 b->SetInternalField(1, c); | 2175 b->SetInternalField(1, c); |
| 2176 c->SetAlignedPointerInInternalField(0, c0); | 2176 c->SetAlignedPointerInInternalField(0, c0); |
| 2177 c->SetAlignedPointerInInternalField(1, c1); | 2177 c->SetAlignedPointerInInternalField(1, c1); |
| 2178 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); | 2178 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); |
| 2179 | 2179 |
| 2180 CHECK_EQ(0, creator.AddContext(context)); | 2180 CHECK_EQ(0u, creator.AddContext(context)); |
| 2181 CHECK_EQ(0, creator.AddTemplate(callback)); | 2181 CHECK_EQ(0u, creator.AddTemplate(callback)); |
| 2182 CHECK_EQ(1, creator.AddTemplate(global_template)); | 2182 CHECK_EQ(1u, creator.AddTemplate(global_template)); |
| 2183 } | 2183 } |
| 2184 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, | 2184 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, |
| 2185 SerializeInternalFields); | 2185 SerializeInternalFields); |
| 2186 | 2186 |
| 2187 delete a1; | 2187 delete a1; |
| 2188 delete b0; | 2188 delete b0; |
| 2189 delete c1; | 2189 delete c1; |
| 2190 delete c0; | 2190 delete c0; |
| 2191 } | 2191 } |
| 2192 | 2192 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 a->GetAlignedPointerFromInternalField(1)); | 2241 a->GetAlignedPointerFromInternalField(1)); |
| 2242 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>( | 2242 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>( |
| 2243 b->GetAlignedPointerFromInternalField(0)); | 2243 b->GetAlignedPointerFromInternalField(0)); |
| 2244 v8::Local<v8::Object> c = | 2244 v8::Local<v8::Object> c = |
| 2245 b->GetInternalField(1)->ToObject(context).ToLocalChecked(); | 2245 b->GetInternalField(1)->ToObject(context).ToLocalChecked(); |
| 2246 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>( | 2246 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>( |
| 2247 c->GetAlignedPointerFromInternalField(0)); | 2247 c->GetAlignedPointerFromInternalField(0)); |
| 2248 InternalFieldData* c1 = reinterpret_cast<InternalFieldData*>( | 2248 InternalFieldData* c1 = reinterpret_cast<InternalFieldData*>( |
| 2249 c->GetAlignedPointerFromInternalField(1)); | 2249 c->GetAlignedPointerFromInternalField(1)); |
| 2250 | 2250 |
| 2251 CHECK_EQ(11, a1->data); | 2251 CHECK_EQ(11u, a1->data); |
| 2252 CHECK_EQ(20, b0->data); | 2252 CHECK_EQ(20u, b0->data); |
| 2253 CHECK_EQ(30, c0->data); | 2253 CHECK_EQ(30u, c0->data); |
| 2254 CHECK_EQ(31, c1->data); | 2254 CHECK_EQ(31u, c1->data); |
| 2255 | 2255 |
| 2256 // Accessing out of bound returns empty MaybeHandle. | 2256 // Accessing out of bound returns empty MaybeHandle. |
| 2257 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); | 2257 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
| 2258 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); | 2258 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
| 2259 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty()); | 2259 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty()); |
| 2260 | 2260 |
| 2261 delete a1; | 2261 delete a1; |
| 2262 delete b0; | 2262 delete b0; |
| 2263 delete c1; | 2263 delete c1; |
| 2264 delete c0; | 2264 delete c0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2286 } | 2286 } |
| 2287 delete[] blob.data; | 2287 delete[] blob.data; |
| 2288 } | 2288 } |
| 2289 | 2289 |
| 2290 TEST(SerializationMemoryStats) { | 2290 TEST(SerializationMemoryStats) { |
| 2291 FLAG_profile_deserialization = true; | 2291 FLAG_profile_deserialization = true; |
| 2292 FLAG_always_opt = false; | 2292 FLAG_always_opt = false; |
| 2293 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2293 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 2294 delete[] blob.data; | 2294 delete[] blob.data; |
| 2295 } | 2295 } |
| OLD | NEW |