| OLD | NEW |
| 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/utils/random-number-generator.h" | 9 #include "src/base/utils/random-number-generator.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| 11 #include "src/extensions/externalize-string-extension.h" | 11 #include "src/extensions/externalize-string-extension.h" |
| 12 #include "src/extensions/free-buffer-extension.h" | 12 #include "src/extensions/free-buffer-extension.h" |
| 13 #include "src/extensions/gc-extension.h" | 13 #include "src/extensions/gc-extension.h" |
| 14 #include "src/extensions/statistics-extension.h" | 14 #include "src/extensions/statistics-extension.h" |
| 15 #include "src/extensions/trigger-failure-extension.h" | 15 #include "src/extensions/trigger-failure-extension.h" |
| 16 #include "src/snapshot/natives.h" | 16 #include "src/snapshot/natives.h" |
| 17 #include "src/snapshot/snapshot.h" | 17 #include "src/snapshot/snapshot.h" |
| 18 #include "third_party/fdlibm/fdlibm.h" | 18 #include "third_party/fdlibm/fdlibm.h" |
| 19 | 19 |
| 20 namespace v8 { | 20 namespace v8 { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 Bootstrapper::Bootstrapper(Isolate* isolate) | 23 Bootstrapper::Bootstrapper(Isolate* isolate) |
| 24 : isolate_(isolate), | 24 : isolate_(isolate), |
| 25 nesting_(0), | 25 nesting_(0), |
| 26 extensions_cache_(Script::TYPE_EXTENSION) {} | 26 extensions_cache_(Script::TYPE_EXTENSION) {} |
| 27 | 27 |
| 28 | 28 |
| 29 Handle<String> Bootstrapper::NativesSourceLookup(int index) { | 29 template <class Source> |
| 30 DCHECK(0 <= index && index < Natives::GetBuiltinsCount()); | 30 inline FixedArray* GetCache(Heap* heap); |
| 31 |
| 32 |
| 33 template <> |
| 34 FixedArray* GetCache<Natives>(Heap* heap) { |
| 35 return heap->natives_source_cache(); |
| 36 } |
| 37 |
| 38 |
| 39 template <> |
| 40 FixedArray* GetCache<ExperimentalNatives>(Heap* heap) { |
| 41 return heap->experimental_natives_source_cache(); |
| 42 } |
| 43 |
| 44 |
| 45 template <class Source> |
| 46 Handle<String> Bootstrapper::SourceLookup(int index) { |
| 47 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); |
| 31 Heap* heap = isolate_->heap(); | 48 Heap* heap = isolate_->heap(); |
| 32 if (heap->natives_source_cache()->get(index)->IsUndefined()) { | 49 if (GetCache<Source>(heap)->get(index)->IsUndefined()) { |
| 33 // We can use external strings for the natives. | 50 // We can use external strings for the natives. |
| 34 Vector<const char> source = Natives::GetScriptSource(index); | 51 Vector<const char> source = Source::GetScriptSource(index); |
| 35 NativesExternalStringResource* resource = | 52 NativesExternalStringResource* resource = |
| 36 new NativesExternalStringResource(source.start(), source.length()); | 53 new NativesExternalStringResource(source.start(), source.length()); |
| 37 // We do not expect this to throw an exception. Change this if it does. | 54 // We do not expect this to throw an exception. Change this if it does. |
| 38 Handle<String> source_code = isolate_->factory() | 55 Handle<String> source_code = isolate_->factory() |
| 39 ->NewExternalStringFromOneByte(resource) | 56 ->NewExternalStringFromOneByte(resource) |
| 40 .ToHandleChecked(); | 57 .ToHandleChecked(); |
| 41 // Mark this external string with a special map. | 58 // Mark this external string with a special map. |
| 42 source_code->set_map(isolate_->heap()->native_source_string_map()); | 59 source_code->set_map(isolate_->heap()->native_source_string_map()); |
| 43 heap->natives_source_cache()->set(index, *source_code); | 60 GetCache<Source>(heap)->set(index, *source_code); |
| 44 } | 61 } |
| 45 Handle<Object> cached_source(heap->natives_source_cache()->get(index), | 62 Handle<Object> cached_source(GetCache<Source>(heap)->get(index), isolate_); |
| 46 isolate_); | |
| 47 return Handle<String>::cast(cached_source); | 63 return Handle<String>::cast(cached_source); |
| 48 } | 64 } |
| 49 | 65 |
| 50 | 66 |
| 67 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); |
| 68 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( |
| 69 int index); |
| 70 |
| 71 |
| 51 void Bootstrapper::Initialize(bool create_heap_objects) { | 72 void Bootstrapper::Initialize(bool create_heap_objects) { |
| 52 extensions_cache_.Initialize(isolate_, create_heap_objects); | 73 extensions_cache_.Initialize(isolate_, create_heap_objects); |
| 53 } | 74 } |
| 54 | 75 |
| 55 | 76 |
| 56 static const char* GCFunctionName() { | 77 static const char* GCFunctionName() { |
| 57 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; | 78 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; |
| 58 return flag_given ? FLAG_expose_gc_as : "gc"; | 79 return flag_given ? FLAG_expose_gc_as : "gc"; |
| 59 } | 80 } |
| 60 | 81 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 87 gc_extension_ = NULL; | 108 gc_extension_ = NULL; |
| 88 delete externalize_string_extension_; | 109 delete externalize_string_extension_; |
| 89 externalize_string_extension_ = NULL; | 110 externalize_string_extension_ = NULL; |
| 90 delete statistics_extension_; | 111 delete statistics_extension_; |
| 91 statistics_extension_ = NULL; | 112 statistics_extension_ = NULL; |
| 92 delete trigger_failure_extension_; | 113 delete trigger_failure_extension_; |
| 93 trigger_failure_extension_ = NULL; | 114 trigger_failure_extension_ = NULL; |
| 94 } | 115 } |
| 95 | 116 |
| 96 | 117 |
| 97 void Bootstrapper::TearDown() { | 118 void DeleteNativeSources(Object* maybe_array) { |
| 98 Object* natives_source_cache = isolate_->heap()->natives_source_cache(); | 119 if (maybe_array->IsFixedArray()) { |
| 99 if (natives_source_cache->IsFixedArray()) { | 120 FixedArray* array = FixedArray::cast(maybe_array); |
| 100 FixedArray* natives_source_array = FixedArray::cast(natives_source_cache); | 121 for (int i = 0; i < array->length(); i++) { |
| 101 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 122 Object* natives_source = array->get(i); |
| 102 Object* natives_source = natives_source_array->get(i); | |
| 103 if (!natives_source->IsUndefined()) { | 123 if (!natives_source->IsUndefined()) { |
| 104 const NativesExternalStringResource* resource = | 124 const NativesExternalStringResource* resource = |
| 105 reinterpret_cast<const NativesExternalStringResource*>( | 125 reinterpret_cast<const NativesExternalStringResource*>( |
| 106 ExternalOneByteString::cast(natives_source)->resource()); | 126 ExternalOneByteString::cast(natives_source)->resource()); |
| 107 delete resource; | 127 delete resource; |
| 108 } | 128 } |
| 109 } | 129 } |
| 110 } | 130 } |
| 131 } |
| 111 | 132 |
| 133 |
| 134 void Bootstrapper::TearDown() { |
| 135 DeleteNativeSources(isolate_->heap()->natives_source_cache()); |
| 136 DeleteNativeSources(isolate_->heap()->experimental_natives_source_cache()); |
| 112 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 137 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
| 113 } | 138 } |
| 114 | 139 |
| 115 | 140 |
| 116 class Genesis BASE_EMBEDDED { | 141 class Genesis BASE_EMBEDDED { |
| 117 public: | 142 public: |
| 118 Genesis(Isolate* isolate, | 143 Genesis(Isolate* isolate, |
| 119 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 144 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 120 v8::Handle<v8::ObjectTemplate> global_proxy_template, | 145 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 121 v8::ExtensionConfiguration* extensions); | 146 v8::ExtensionConfiguration* extensions); |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) | 1426 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) |
| 1402 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) | 1427 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) |
| 1403 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) | 1428 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) |
| 1404 #undef FEATURE_INITIALIZE_GLOBAL | 1429 #undef FEATURE_INITIALIZE_GLOBAL |
| 1405 } | 1430 } |
| 1406 | 1431 |
| 1407 | 1432 |
| 1408 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { | 1433 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { |
| 1409 Vector<const char> name = Natives::GetScriptName(index); | 1434 Vector<const char> name = Natives::GetScriptName(index); |
| 1410 Handle<String> source_code = | 1435 Handle<String> source_code = |
| 1411 isolate->bootstrapper()->NativesSourceLookup(index); | 1436 isolate->bootstrapper()->SourceLookup<Natives>(index); |
| 1412 return CompileNative(isolate, name, source_code); | 1437 return CompileNative(isolate, name, source_code); |
| 1413 } | 1438 } |
| 1414 | 1439 |
| 1415 | 1440 |
| 1416 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { | 1441 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { |
| 1417 Vector<const char> name = ExperimentalNatives::GetScriptName(index); | 1442 Vector<const char> name = ExperimentalNatives::GetScriptName(index); |
| 1418 Factory* factory = isolate->factory(); | 1443 Handle<String> source_code = |
| 1419 Handle<String> source_code; | 1444 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); |
| 1420 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
| 1421 isolate, source_code, | |
| 1422 factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)), | |
| 1423 false); | |
| 1424 return CompileNative(isolate, name, source_code); | 1445 return CompileNative(isolate, name, source_code); |
| 1425 } | 1446 } |
| 1426 | 1447 |
| 1427 | 1448 |
| 1428 bool Genesis::CompileNative(Isolate* isolate, | 1449 bool Genesis::CompileNative(Isolate* isolate, |
| 1429 Vector<const char> name, | 1450 Vector<const char> name, |
| 1430 Handle<String> source) { | 1451 Handle<String> source) { |
| 1431 HandleScope scope(isolate); | 1452 HandleScope scope(isolate); |
| 1432 SuppressDebug compiling_natives(isolate->debug()); | 1453 SuppressDebug compiling_natives(isolate->debug()); |
| 1433 // During genesis, the boilerplate for stack overflow won't work until the | 1454 // During genesis, the boilerplate for stack overflow won't work until the |
| (...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2959 return from + sizeof(NestingCounterType); | 2980 return from + sizeof(NestingCounterType); |
| 2960 } | 2981 } |
| 2961 | 2982 |
| 2962 | 2983 |
| 2963 // Called when the top-level V8 mutex is destroyed. | 2984 // Called when the top-level V8 mutex is destroyed. |
| 2964 void Bootstrapper::FreeThreadResources() { | 2985 void Bootstrapper::FreeThreadResources() { |
| 2965 DCHECK(!IsActive()); | 2986 DCHECK(!IsActive()); |
| 2966 } | 2987 } |
| 2967 | 2988 |
| 2968 } } // namespace v8::internal | 2989 } } // namespace v8::internal |
| OLD | NEW |