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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
11 #include "src/extensions/free-buffer-extension.h" | 11 #include "src/extensions/free-buffer-extension.h" |
12 #include "src/extensions/gc-extension.h" | 12 #include "src/extensions/gc-extension.h" |
13 #include "src/extensions/statistics-extension.h" | 13 #include "src/extensions/statistics-extension.h" |
14 #include "src/extensions/trigger-failure-extension.h" | 14 #include "src/extensions/trigger-failure-extension.h" |
15 #include "src/isolate-inl.h" | 15 #include "src/isolate-inl.h" |
16 #include "src/natives.h" | 16 #include "src/natives.h" |
17 #include "src/snapshot.h" | 17 #include "src/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 NativesExternalStringResource::NativesExternalStringResource( | |
24 Bootstrapper* bootstrapper, | |
25 const char* source, | |
26 size_t length) | |
27 : data_(source), length_(length) { | |
28 if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { | |
29 bootstrapper->delete_these_non_arrays_on_tear_down_ = new List<char*>(2); | |
30 } | |
31 // The resources are small objects and we only make a fixed number of | |
32 // them, but let's clean them up on exit for neatness. | |
33 bootstrapper->delete_these_non_arrays_on_tear_down_-> | |
34 Add(reinterpret_cast<char*>(this)); | |
35 } | |
36 | |
37 | |
38 Bootstrapper::Bootstrapper(Isolate* isolate) | 23 Bootstrapper::Bootstrapper(Isolate* isolate) |
39 : isolate_(isolate), | 24 : isolate_(isolate), |
40 nesting_(0), | 25 nesting_(0), |
41 extensions_cache_(Script::TYPE_EXTENSION), | 26 extensions_cache_(Script::TYPE_EXTENSION) {} |
42 delete_these_non_arrays_on_tear_down_(NULL), | |
43 delete_these_arrays_on_tear_down_(NULL) { | |
44 } | |
45 | 27 |
46 | 28 |
47 Handle<String> Bootstrapper::NativesSourceLookup(int index) { | 29 Handle<String> Bootstrapper::NativesSourceLookup(int index) { |
48 DCHECK(0 <= index && index < Natives::GetBuiltinsCount()); | 30 DCHECK(0 <= index && index < Natives::GetBuiltinsCount()); |
49 Heap* heap = isolate_->heap(); | 31 Heap* heap = isolate_->heap(); |
50 if (heap->natives_source_cache()->get(index)->IsUndefined()) { | 32 if (heap->natives_source_cache()->get(index)->IsUndefined()) { |
51 // We can use external strings for the natives. | 33 // We can use external strings for the natives. |
52 Vector<const char> source = Natives::GetScriptSource(index); | 34 Vector<const char> source = Natives::GetScriptSource(index); |
53 NativesExternalStringResource* resource = | 35 NativesExternalStringResource* resource = |
54 new NativesExternalStringResource(this, | 36 new NativesExternalStringResource(source.start(), source.length()); |
55 source.start(), | |
56 source.length()); | |
57 // We do not expect this to throw an exception. Change this if it does. | 37 // We do not expect this to throw an exception. Change this if it does. |
58 Handle<String> source_code = isolate_->factory() | 38 Handle<String> source_code = isolate_->factory() |
59 ->NewExternalStringFromOneByte(resource) | 39 ->NewExternalStringFromOneByte(resource) |
60 .ToHandleChecked(); | 40 .ToHandleChecked(); |
61 // Mark this external string with a special map. | 41 // Mark this external string with a special map. |
62 source_code->set_map(isolate_->heap()->native_source_string_map()); | 42 source_code->set_map(isolate_->heap()->native_source_string_map()); |
63 heap->natives_source_cache()->set(index, *source_code); | 43 heap->natives_source_cache()->set(index, *source_code); |
64 } | 44 } |
65 Handle<Object> cached_source(heap->natives_source_cache()->get(index), | 45 Handle<Object> cached_source(heap->natives_source_cache()->get(index), |
66 isolate_); | 46 isolate_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 gc_extension_ = NULL; | 87 gc_extension_ = NULL; |
108 delete externalize_string_extension_; | 88 delete externalize_string_extension_; |
109 externalize_string_extension_ = NULL; | 89 externalize_string_extension_ = NULL; |
110 delete statistics_extension_; | 90 delete statistics_extension_; |
111 statistics_extension_ = NULL; | 91 statistics_extension_ = NULL; |
112 delete trigger_failure_extension_; | 92 delete trigger_failure_extension_; |
113 trigger_failure_extension_ = NULL; | 93 trigger_failure_extension_ = NULL; |
114 } | 94 } |
115 | 95 |
116 | 96 |
117 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { | |
118 char* memory = new char[bytes]; | |
119 if (memory != NULL) { | |
120 if (delete_these_arrays_on_tear_down_ == NULL) { | |
121 delete_these_arrays_on_tear_down_ = new List<char*>(2); | |
122 } | |
123 delete_these_arrays_on_tear_down_->Add(memory); | |
124 } | |
125 return memory; | |
126 } | |
127 | |
128 | |
129 void Bootstrapper::TearDown() { | 97 void Bootstrapper::TearDown() { |
130 if (delete_these_non_arrays_on_tear_down_ != NULL) { | 98 Object* natives_source_cache = isolate_->heap()->natives_source_cache(); |
131 int len = delete_these_non_arrays_on_tear_down_->length(); | 99 if (natives_source_cache->IsFixedArray()) { |
132 DCHECK(len < 1000); // Don't use this mechanism for unbounded allocations. | 100 FixedArray* natives_source_array = FixedArray::cast(natives_source_cache); |
133 for (int i = 0; i < len; i++) { | 101 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
134 delete delete_these_non_arrays_on_tear_down_->at(i); | 102 Object* natives_source = natives_source_array->get(i); |
135 delete_these_non_arrays_on_tear_down_->at(i) = NULL; | 103 if (!natives_source->IsUndefined()) { |
| 104 const NativesExternalStringResource* resource = |
| 105 reinterpret_cast<const NativesExternalStringResource*>( |
| 106 ExternalOneByteString::cast(natives_source)->resource()); |
| 107 delete resource; |
| 108 } |
136 } | 109 } |
137 delete delete_these_non_arrays_on_tear_down_; | |
138 delete_these_non_arrays_on_tear_down_ = NULL; | |
139 } | |
140 | |
141 if (delete_these_arrays_on_tear_down_ != NULL) { | |
142 int len = delete_these_arrays_on_tear_down_->length(); | |
143 DCHECK(len < 1000); // Don't use this mechanism for unbounded allocations. | |
144 for (int i = 0; i < len; i++) { | |
145 delete[] delete_these_arrays_on_tear_down_->at(i); | |
146 delete_these_arrays_on_tear_down_->at(i) = NULL; | |
147 } | |
148 delete delete_these_arrays_on_tear_down_; | |
149 delete_these_arrays_on_tear_down_ = NULL; | |
150 } | 110 } |
151 | 111 |
152 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 112 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
153 } | 113 } |
154 | 114 |
155 | 115 |
156 class Genesis BASE_EMBEDDED { | 116 class Genesis BASE_EMBEDDED { |
157 public: | 117 public: |
158 Genesis(Isolate* isolate, | 118 Genesis(Isolate* isolate, |
159 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 119 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
(...skipping 2740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2900 return from + sizeof(NestingCounterType); | 2860 return from + sizeof(NestingCounterType); |
2901 } | 2861 } |
2902 | 2862 |
2903 | 2863 |
2904 // Called when the top-level V8 mutex is destroyed. | 2864 // Called when the top-level V8 mutex is destroyed. |
2905 void Bootstrapper::FreeThreadResources() { | 2865 void Bootstrapper::FreeThreadResources() { |
2906 DCHECK(!IsActive()); | 2866 DCHECK(!IsActive()); |
2907 } | 2867 } |
2908 | 2868 |
2909 } } // namespace v8::internal | 2869 } } // namespace v8::internal |
OLD | NEW |