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

Side by Side Diff: src/runtime/runtime-internal.cc

Issue 638423003: Split off remaining runtime functions in runtime.cc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/runtime/runtime-numbers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/arguments.h"
8 #include "src/bootstrapper.h"
9 #include "src/debug.h"
10 #include "src/runtime/runtime.h"
11 #include "src/runtime/runtime-utils.h"
12
13 namespace v8 {
14 namespace internal {
15
16 RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
17 SealHandleScope shs(isolate);
18 DCHECK(args.length() == 0);
19 RUNTIME_ASSERT(isolate->bootstrapper()->IsActive());
20 return isolate->heap()->undefined_value();
21 }
22
23
24 RUNTIME_FUNCTION(Runtime_Throw) {
25 HandleScope scope(isolate);
26 DCHECK(args.length() == 1);
27
28 return isolate->Throw(args[0]);
29 }
30
31
32 RUNTIME_FUNCTION(Runtime_ReThrow) {
33 HandleScope scope(isolate);
34 DCHECK(args.length() == 1);
35
36 return isolate->ReThrow(args[0]);
37 }
38
39
40 RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
41 SealHandleScope shs(isolate);
42 DCHECK(args.length() == 0);
43 return isolate->PromoteScheduledException();
44 }
45
46
47 RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
48 HandleScope scope(isolate);
49 DCHECK(args.length() == 1);
50 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
51 THROW_NEW_ERROR_RETURN_FAILURE(
52 isolate, NewReferenceError("not_defined", HandleVector(&name, 1)));
53 }
54
55
56 RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) {
57 DCHECK(args.length() == 3);
58 HandleScope scope(isolate);
59 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
60 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
61 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2);
62 if (debug_event) isolate->debug()->OnPromiseReject(promise, value);
63 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol();
64 // Do not report if we actually have a handler.
65 if (JSObject::GetDataProperty(promise, key)->IsUndefined()) {
66 isolate->ReportPromiseReject(promise, value,
67 v8::kPromiseRejectWithNoHandler);
68 }
69 return isolate->heap()->undefined_value();
70 }
71
72
73 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
74 DCHECK(args.length() == 1);
75 HandleScope scope(isolate);
76 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
77 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol();
78 // At this point, no revocation has been issued before
79 RUNTIME_ASSERT(JSObject::GetDataProperty(promise, key)->IsUndefined());
80 isolate->ReportPromiseReject(promise, Handle<Object>(),
81 v8::kPromiseHandlerAddedAfterReject);
82 return isolate->heap()->undefined_value();
83 }
84
85
86 RUNTIME_FUNCTION(Runtime_PromiseHasHandlerSymbol) {
87 DCHECK(args.length() == 0);
88 return isolate->heap()->promise_has_handler_symbol();
89 }
90
91
92 RUNTIME_FUNCTION(Runtime_StackGuard) {
93 SealHandleScope shs(isolate);
94 DCHECK(args.length() == 0);
95
96 // First check if this is a real stack overflow.
97 StackLimitCheck check(isolate);
98 if (check.JsHasOverflowed()) {
99 return isolate->StackOverflow();
100 }
101
102 return isolate->stack_guard()->HandleInterrupts();
103 }
104
105
106 RUNTIME_FUNCTION(Runtime_Interrupt) {
107 SealHandleScope shs(isolate);
108 DCHECK(args.length() == 0);
109 return isolate->stack_guard()->HandleInterrupts();
110 }
111
112
113 RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
114 HandleScope scope(isolate);
115 DCHECK(args.length() == 1);
116 CONVERT_SMI_ARG_CHECKED(size, 0);
117 RUNTIME_ASSERT(IsAligned(size, kPointerSize));
118 RUNTIME_ASSERT(size > 0);
119 RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize);
120 return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
121 }
122
123
124 RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
125 HandleScope scope(isolate);
126 DCHECK(args.length() == 2);
127 CONVERT_SMI_ARG_CHECKED(size, 0);
128 CONVERT_SMI_ARG_CHECKED(flags, 1);
129 RUNTIME_ASSERT(IsAligned(size, kPointerSize));
130 RUNTIME_ASSERT(size > 0);
131 RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize);
132 bool double_align = AllocateDoubleAlignFlag::decode(flags);
133 AllocationSpace space = AllocateTargetSpace::decode(flags);
134 return *isolate->factory()->NewFillerObject(size, double_align, space);
135 }
136
137
138 // Collect the raw data for a stack trace. Returns an array of 4
139 // element segments each containing a receiver, function, code and
140 // native code offset.
141 RUNTIME_FUNCTION(Runtime_CollectStackTrace) {
142 HandleScope scope(isolate);
143 DCHECK(args.length() == 2);
144 CONVERT_ARG_HANDLE_CHECKED(JSObject, error_object, 0);
145 CONVERT_ARG_HANDLE_CHECKED(Object, caller, 1);
146
147 if (!isolate->bootstrapper()->IsActive()) {
148 // Optionally capture a more detailed stack trace for the message.
149 isolate->CaptureAndSetDetailedStackTrace(error_object);
150 // Capture a simple stack trace for the stack property.
151 isolate->CaptureAndSetSimpleStackTrace(error_object, caller);
152 }
153 return isolate->heap()->undefined_value();
154 }
155
156
157 RUNTIME_FUNCTION(Runtime_GetFromCache) {
158 SealHandleScope shs(isolate);
159 // This is only called from codegen, so checks might be more lax.
160 CONVERT_ARG_CHECKED(JSFunctionResultCache, cache, 0);
161 CONVERT_ARG_CHECKED(Object, key, 1);
162
163 {
164 DisallowHeapAllocation no_alloc;
165
166 int finger_index = cache->finger_index();
167 Object* o = cache->get(finger_index);
168 if (o == key) {
169 // The fastest case: hit the same place again.
170 return cache->get(finger_index + 1);
171 }
172
173 for (int i = finger_index - 2; i >= JSFunctionResultCache::kEntriesIndex;
174 i -= 2) {
175 o = cache->get(i);
176 if (o == key) {
177 cache->set_finger_index(i);
178 return cache->get(i + 1);
179 }
180 }
181
182 int size = cache->size();
183 DCHECK(size <= cache->length());
184
185 for (int i = size - 2; i > finger_index; i -= 2) {
186 o = cache->get(i);
187 if (o == key) {
188 cache->set_finger_index(i);
189 return cache->get(i + 1);
190 }
191 }
192 }
193
194 // There is no value in the cache. Invoke the function and cache result.
195 HandleScope scope(isolate);
196
197 Handle<JSFunctionResultCache> cache_handle(cache);
198 Handle<Object> key_handle(key, isolate);
199 Handle<Object> value;
200 {
201 Handle<JSFunction> factory(JSFunction::cast(
202 cache_handle->get(JSFunctionResultCache::kFactoryIndex)));
203 // TODO(antonm): consider passing a receiver when constructing a cache.
204 Handle<JSObject> receiver(isolate->global_proxy());
205 // This handle is nor shared, nor used later, so it's safe.
206 Handle<Object> argv[] = {key_handle};
207 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
208 isolate, value,
209 Execution::Call(isolate, factory, receiver, arraysize(argv), argv));
210 }
211
212 #ifdef VERIFY_HEAP
213 if (FLAG_verify_heap) {
214 cache_handle->JSFunctionResultCacheVerify();
215 }
216 #endif
217
218 // Function invocation may have cleared the cache. Reread all the data.
219 int finger_index = cache_handle->finger_index();
220 int size = cache_handle->size();
221
222 // If we have spare room, put new data into it, otherwise evict post finger
223 // entry which is likely to be the least recently used.
224 int index = -1;
225 if (size < cache_handle->length()) {
226 cache_handle->set_size(size + JSFunctionResultCache::kEntrySize);
227 index = size;
228 } else {
229 index = finger_index + JSFunctionResultCache::kEntrySize;
230 if (index == cache_handle->length()) {
231 index = JSFunctionResultCache::kEntriesIndex;
232 }
233 }
234
235 DCHECK(index % 2 == 0);
236 DCHECK(index >= JSFunctionResultCache::kEntriesIndex);
237 DCHECK(index < cache_handle->length());
238
239 cache_handle->set(index, *key_handle);
240 cache_handle->set(index + 1, *value);
241 cache_handle->set_finger_index(index);
242
243 #ifdef VERIFY_HEAP
244 if (FLAG_verify_heap) {
245 cache_handle->JSFunctionResultCacheVerify();
246 }
247 #endif
248
249 return *value;
250 }
251
252
253 RUNTIME_FUNCTION(Runtime_MessageGetStartPosition) {
254 SealHandleScope shs(isolate);
255 DCHECK(args.length() == 1);
256 CONVERT_ARG_CHECKED(JSMessageObject, message, 0);
257 return Smi::FromInt(message->start_position());
258 }
259
260
261 RUNTIME_FUNCTION(Runtime_MessageGetScript) {
262 SealHandleScope shs(isolate);
263 DCHECK(args.length() == 1);
264 CONVERT_ARG_CHECKED(JSMessageObject, message, 0);
265 return message->script();
266 }
267
268
269 RUNTIME_FUNCTION(Runtime_IS_VAR) {
270 UNREACHABLE(); // implemented as macro in the parser
271 return NULL;
272 }
273
274
275 RUNTIME_FUNCTION(RuntimeReference_GetFromCache) {
276 HandleScope scope(isolate);
277 DCHECK(args.length() == 2);
278 CONVERT_SMI_ARG_CHECKED(id, 0);
279 args[0] = isolate->native_context()->jsfunction_result_caches()->get(id);
280 return __RT_impl_Runtime_GetFromCache(args, isolate);
281 }
282 }
283 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/runtime/runtime-numbers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698