Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: src/bootstrapper.cc

Issue 2807023003: [snapshot] encode resource before serializing. (Closed)
Patch Set: fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/bootstrapper.h ('k') | src/heap/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 17 matching lines...) Expand all
28 #endif // V8_I18N_SUPPORT 28 #endif // V8_I18N_SUPPORT
29 29
30 namespace v8 { 30 namespace v8 {
31 namespace internal { 31 namespace internal {
32 32
33 Bootstrapper::Bootstrapper(Isolate* isolate) 33 Bootstrapper::Bootstrapper(Isolate* isolate)
34 : isolate_(isolate), 34 : isolate_(isolate),
35 nesting_(0), 35 nesting_(0),
36 extensions_cache_(Script::TYPE_EXTENSION) {} 36 extensions_cache_(Script::TYPE_EXTENSION) {}
37 37
38 template <class Source> 38 Handle<String> Bootstrapper::GetNativeSource(NativeType type, int index) {
39 Handle<String> Bootstrapper::SourceLookup(int index) { 39 NativesExternalStringResource* resource =
40 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); 40 new NativesExternalStringResource(type, index);
41 Heap* heap = isolate_->heap(); 41 Handle<ExternalOneByteString> source_code =
42 if (Source::GetSourceCache(heap)->get(index)->IsUndefined(isolate_)) { 42 isolate_->factory()->NewNativeSourceString(resource);
43 // We can use external strings for the natives. 43 isolate_->heap()->RegisterExternalString(*source_code);
44 Vector<const char> source = Source::GetScriptSource(index); 44 DCHECK(source_code->is_short());
45 NativesExternalStringResource* resource = 45 return source_code;
46 new NativesExternalStringResource(source.start(), source.length());
47 Handle<ExternalOneByteString> source_code =
48 isolate_->factory()->NewNativeSourceString(resource);
49 // Mark this external string with a special map.
50 DCHECK(source_code->is_short());
51 Source::GetSourceCache(heap)->set(index, *source_code);
52 }
53 Handle<Object> cached_source(Source::GetSourceCache(heap)->get(index),
54 isolate_);
55 return Handle<String>::cast(cached_source);
56 } 46 }
57 47
58
59 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index);
60 template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>(
61 int index);
62 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index);
63
64
65 void Bootstrapper::Initialize(bool create_heap_objects) { 48 void Bootstrapper::Initialize(bool create_heap_objects) {
66 extensions_cache_.Initialize(isolate_, create_heap_objects); 49 extensions_cache_.Initialize(isolate_, create_heap_objects);
67 } 50 }
68 51
69 52
70 static const char* GCFunctionName() { 53 static const char* GCFunctionName() {
71 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; 54 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0;
72 return flag_given ? FLAG_expose_gc_as : "gc"; 55 return flag_given ? FLAG_expose_gc_as : "gc";
73 } 56 }
74 57
(...skipping 29 matching lines...) Expand all
104 delete externalize_string_extension_; 87 delete externalize_string_extension_;
105 externalize_string_extension_ = NULL; 88 externalize_string_extension_ = NULL;
106 delete statistics_extension_; 89 delete statistics_extension_;
107 statistics_extension_ = NULL; 90 statistics_extension_ = NULL;
108 delete trigger_failure_extension_; 91 delete trigger_failure_extension_;
109 trigger_failure_extension_ = NULL; 92 trigger_failure_extension_ = NULL;
110 delete ignition_statistics_extension_; 93 delete ignition_statistics_extension_;
111 ignition_statistics_extension_ = NULL; 94 ignition_statistics_extension_ = NULL;
112 } 95 }
113 96
114
115 void DeleteNativeSources(Object* maybe_array) {
116 if (maybe_array->IsFixedArray()) {
117 FixedArray* array = FixedArray::cast(maybe_array);
118 Isolate* isolate = array->GetIsolate();
119 for (int i = 0; i < array->length(); i++) {
120 Object* natives_source = array->get(i);
121 if (!natives_source->IsUndefined(isolate)) {
122 const NativesExternalStringResource* resource =
123 reinterpret_cast<const NativesExternalStringResource*>(
124 ExternalOneByteString::cast(natives_source)->resource());
125 delete resource;
126 }
127 }
128 }
129 }
130
131
132 void Bootstrapper::TearDown() { 97 void Bootstrapper::TearDown() {
133 DeleteNativeSources(Natives::GetSourceCache(isolate_->heap()));
134 DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap()));
135 DeleteNativeSources(
136 ExperimentalExtraNatives::GetSourceCache(isolate_->heap()));
137
138 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical 98 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
139 } 99 }
140 100
141 101
142 class Genesis BASE_EMBEDDED { 102 class Genesis BASE_EMBEDDED {
143 public: 103 public:
144 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, 104 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
145 v8::Local<v8::ObjectTemplate> global_proxy_template, 105 v8::Local<v8::ObjectTemplate> global_proxy_template,
146 size_t context_snapshot_index, 106 size_t context_snapshot_index,
147 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer, 107 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
(...skipping 3070 matching lines...) Expand 10 before | Expand all | Expand 10 after
3218 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) 3178 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
3219 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) 3179 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
3220 #undef FEATURE_INITIALIZE_GLOBAL 3180 #undef FEATURE_INITIALIZE_GLOBAL
3221 3181
3222 InitializeGlobal_experimental_fast_array_builtins(); 3182 InitializeGlobal_experimental_fast_array_builtins();
3223 } 3183 }
3224 3184
3225 bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) { 3185 bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
3226 Vector<const char> name = Natives::GetScriptName(index); 3186 Vector<const char> name = Natives::GetScriptName(index);
3227 Handle<String> source_code = 3187 Handle<String> source_code =
3228 isolate->bootstrapper()->SourceLookup<Natives>(index); 3188 isolate->bootstrapper()->GetNativeSource(CORE, index);
3229 3189
3230 // We pass in extras_utils so that builtin code can set it up for later use 3190 // We pass in extras_utils so that builtin code can set it up for later use
3231 // by actual extras code, compiled with CompileExtraBuiltin. 3191 // by actual extras code, compiled with CompileExtraBuiltin.
3232 Handle<Object> global = isolate->global_object(); 3192 Handle<Object> global = isolate->global_object();
3233 Handle<Object> utils = isolate->natives_utils_object(); 3193 Handle<Object> utils = isolate->natives_utils_object();
3234 Handle<Object> extras_utils = isolate->extras_utils_object(); 3194 Handle<Object> extras_utils = isolate->extras_utils_object();
3235 Handle<Object> args[] = {global, utils, extras_utils}; 3195 Handle<Object> args[] = {global, utils, extras_utils};
3236 3196
3237 return Bootstrapper::CompileNative(isolate, name, source_code, 3197 return Bootstrapper::CompileNative(isolate, name, source_code,
3238 arraysize(args), args, NATIVES_CODE); 3198 arraysize(args), args, NATIVES_CODE);
3239 } 3199 }
3240 3200
3241 3201
3242 bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) { 3202 bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) {
3243 HandleScope scope(isolate); 3203 HandleScope scope(isolate);
3244 Vector<const char> name = ExtraNatives::GetScriptName(index); 3204 Vector<const char> name = ExtraNatives::GetScriptName(index);
3245 Handle<String> source_code = 3205 Handle<String> source_code =
3246 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); 3206 isolate->bootstrapper()->GetNativeSource(EXTRAS, index);
3247 Handle<Object> global = isolate->global_object(); 3207 Handle<Object> global = isolate->global_object();
3248 Handle<Object> binding = isolate->extras_binding_object(); 3208 Handle<Object> binding = isolate->extras_binding_object();
3249 Handle<Object> extras_utils = isolate->extras_utils_object(); 3209 Handle<Object> extras_utils = isolate->extras_utils_object();
3250 Handle<Object> args[] = {global, binding, extras_utils}; 3210 Handle<Object> args[] = {global, binding, extras_utils};
3251 return Bootstrapper::CompileNative(isolate, name, source_code, 3211 return Bootstrapper::CompileNative(isolate, name, source_code,
3252 arraysize(args), args, EXTENSION_CODE); 3212 arraysize(args), args, EXTENSION_CODE);
3253 } 3213 }
3254 3214
3255 3215
3256 bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate, 3216 bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate,
3257 int index) { 3217 int index) {
3258 HandleScope scope(isolate); 3218 HandleScope scope(isolate);
3259 Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index); 3219 Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index);
3260 Handle<String> source_code = 3220 Handle<String> source_code =
3261 isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index); 3221 isolate->bootstrapper()->GetNativeSource(EXPERIMENTAL_EXTRAS, index);
3262 Handle<Object> global = isolate->global_object(); 3222 Handle<Object> global = isolate->global_object();
3263 Handle<Object> binding = isolate->extras_binding_object(); 3223 Handle<Object> binding = isolate->extras_binding_object();
3264 Handle<Object> extras_utils = isolate->extras_utils_object(); 3224 Handle<Object> extras_utils = isolate->extras_utils_object();
3265 Handle<Object> args[] = {global, binding, extras_utils}; 3225 Handle<Object> args[] = {global, binding, extras_utils};
3266 return Bootstrapper::CompileNative(isolate, name, source_code, 3226 return Bootstrapper::CompileNative(isolate, name, source_code,
3267 arraysize(args), args, EXTENSION_CODE); 3227 arraysize(args), args, EXTENSION_CODE);
3268 } 3228 }
3269 3229
3270 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, 3230 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
3271 Handle<String> source, int argc, 3231 Handle<String> source, int argc,
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after
5287 } 5247 }
5288 5248
5289 5249
5290 // Called when the top-level V8 mutex is destroyed. 5250 // Called when the top-level V8 mutex is destroyed.
5291 void Bootstrapper::FreeThreadResources() { 5251 void Bootstrapper::FreeThreadResources() {
5292 DCHECK(!IsActive()); 5252 DCHECK(!IsActive());
5293 } 5253 }
5294 5254
5295 } // namespace internal 5255 } // namespace internal
5296 } // namespace v8 5256 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698