blob: 9ec29b9d4d365477eada258142a6d096bdae45b6 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/runtime/runtime-utils.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006
7#include "src/arguments.h"
8#include "src/deoptimizer.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/frames-inl.h"
10#include "src/full-codegen/full-codegen.h"
Ben Murdochc5610432016-08-08 18:44:38 +010011#include "src/isolate-inl.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/snapshot/natives.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040013
14namespace v8 {
15namespace internal {
16
Ben Murdoch61f157c2016-09-16 13:49:30 +010017RUNTIME_FUNCTION(Runtime_ConstructDouble) {
18 HandleScope scope(isolate);
19 DCHECK(args.length() == 2);
20 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]);
21 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]);
22 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo;
23 return *isolate->factory()->NewNumber(uint64_to_double(result));
24}
25
Emily Bernierd0a1eb72015-03-24 16:35:39 -040026RUNTIME_FUNCTION(Runtime_DeoptimizeFunction) {
27 HandleScope scope(isolate);
28 DCHECK(args.length() == 1);
Ben Murdochc5610432016-08-08 18:44:38 +010029
30 // This function is used by fuzzers to get coverage in compiler.
31 // Ignore calls on non-function objects to avoid runtime errors.
32 CONVERT_ARG_HANDLE_CHECKED(Object, function_object, 0);
33 // If it is not a JSFunction, just return.
34 if (!function_object->IsJSFunction()) {
35 return isolate->heap()->undefined_value();
36 }
37 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
38
Emily Bernierd0a1eb72015-03-24 16:35:39 -040039 if (!function->IsOptimized()) return isolate->heap()->undefined_value();
40
41 // TODO(turbofan): Deoptimization is not supported yet.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042 if (function->code()->is_turbofanned() &&
43 function->shared()->asm_function() && !FLAG_turbo_asm_deoptimization) {
44 return isolate->heap()->undefined_value();
45 }
46
47 Deoptimizer::DeoptimizeFunction(*function);
48
49 return isolate->heap()->undefined_value();
50}
51
52
53RUNTIME_FUNCTION(Runtime_DeoptimizeNow) {
54 HandleScope scope(isolate);
55 DCHECK(args.length() == 0);
56
57 Handle<JSFunction> function;
58
59 // If the argument is 'undefined', deoptimize the topmost
60 // function.
61 JavaScriptFrameIterator it(isolate);
62 while (!it.done()) {
63 if (it.frame()->is_java_script()) {
64 function = Handle<JSFunction>(it.frame()->function());
65 break;
66 }
67 }
68 if (function.is_null()) return isolate->heap()->undefined_value();
69
70 if (!function->IsOptimized()) return isolate->heap()->undefined_value();
71
72 // TODO(turbofan): Deoptimization is not supported yet.
73 if (function->code()->is_turbofanned() &&
74 function->shared()->asm_function() && !FLAG_turbo_asm_deoptimization) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040075 return isolate->heap()->undefined_value();
76 }
77
78 Deoptimizer::DeoptimizeFunction(*function);
79
80 return isolate->heap()->undefined_value();
81}
82
83
84RUNTIME_FUNCTION(Runtime_RunningInSimulator) {
85 SealHandleScope shs(isolate);
86 DCHECK(args.length() == 0);
87#if defined(USE_SIMULATOR)
88 return isolate->heap()->true_value();
89#else
90 return isolate->heap()->false_value();
91#endif
92}
93
94
95RUNTIME_FUNCTION(Runtime_IsConcurrentRecompilationSupported) {
96 SealHandleScope shs(isolate);
97 DCHECK(args.length() == 0);
98 return isolate->heap()->ToBoolean(
99 isolate->concurrent_recompilation_enabled());
100}
101
102
103RUNTIME_FUNCTION(Runtime_OptimizeFunctionOnNextCall) {
104 HandleScope scope(isolate);
105 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2);
Ben Murdochc5610432016-08-08 18:44:38 +0100106
107 // This function is used by fuzzers to get coverage for optimizations
108 // in compiler. Ignore calls on non-function objects to avoid runtime errors.
109 CONVERT_ARG_HANDLE_CHECKED(Object, function_object, 0);
110 // If it is not a JSFunction, just return.
111 if (!function_object->IsJSFunction()) {
112 return isolate->heap()->undefined_value();
113 }
114 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
115
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116 // The following assertion was lifted from the DCHECK inside
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400117 // JSFunction::MarkForOptimization().
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400118 RUNTIME_ASSERT(function->shared()->allows_lazy_compilation() ||
119 (function->code()->kind() == Code::FUNCTION &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000120 !function->shared()->optimization_disabled()));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400121
122 // If the function is already optimized, just return.
123 if (function->IsOptimized()) return isolate->heap()->undefined_value();
124
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400125 function->MarkForOptimization();
126
127 Code* unoptimized = function->shared()->code();
128 if (args.length() == 2 && unoptimized->kind() == Code::FUNCTION) {
129 CONVERT_ARG_HANDLE_CHECKED(String, type, 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000130 if (type->IsOneByteEqualTo(STATIC_CHAR_VECTOR("concurrent")) &&
131 isolate->concurrent_recompilation_enabled()) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400132 function->AttemptConcurrentOptimization();
133 }
134 }
135
136 return isolate->heap()->undefined_value();
137}
138
139
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140RUNTIME_FUNCTION(Runtime_OptimizeOsr) {
141 HandleScope scope(isolate);
142 RUNTIME_ASSERT(args.length() == 0 || args.length() == 1);
143 Handle<JSFunction> function = Handle<JSFunction>::null();
144
145 if (args.length() == 0) {
146 // Find the JavaScript function on the top of the stack.
147 JavaScriptFrameIterator it(isolate);
148 while (!it.done()) {
149 if (it.frame()->is_java_script()) {
150 function = Handle<JSFunction>(it.frame()->function());
151 break;
152 }
153 }
154 if (function.is_null()) return isolate->heap()->undefined_value();
155 } else {
156 // Function was passed as an argument.
157 CONVERT_ARG_HANDLE_CHECKED(JSFunction, arg, 0);
158 function = arg;
159 }
160
161 // The following assertion was lifted from the DCHECK inside
162 // JSFunction::MarkForOptimization().
163 RUNTIME_ASSERT(function->shared()->allows_lazy_compilation() ||
164 !function->shared()->optimization_disabled());
165
Ben Murdochc5610432016-08-08 18:44:38 +0100166 // If function is interpreted, just return. OSR is not supported.
167 // TODO(4764): Remove this check when OSR is enabled in the interpreter.
168 if (function->shared()->HasBytecodeArray()) {
169 return isolate->heap()->undefined_value();
170 }
171
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172 // If the function is already optimized, just return.
173 if (function->IsOptimized()) return isolate->heap()->undefined_value();
174
175 Code* unoptimized = function->shared()->code();
176 if (unoptimized->kind() == Code::FUNCTION) {
177 DCHECK(BackEdgeTable::Verify(isolate, unoptimized));
178 isolate->runtime_profiler()->AttemptOnStackReplacement(
179 *function, Code::kMaxLoopNestingMarker);
180 }
181
182 return isolate->heap()->undefined_value();
183}
184
185
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400186RUNTIME_FUNCTION(Runtime_NeverOptimizeFunction) {
187 HandleScope scope(isolate);
188 DCHECK(args.length() == 1);
189 CONVERT_ARG_CHECKED(JSFunction, function, 0);
Ben Murdochc5610432016-08-08 18:44:38 +0100190 function->shared()->set_disable_optimization_reason(
191 kOptimizationDisabledForTest);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400192 function->shared()->set_optimization_disabled(true);
193 return isolate->heap()->undefined_value();
194}
195
196
197RUNTIME_FUNCTION(Runtime_GetOptimizationStatus) {
198 HandleScope scope(isolate);
199 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2);
200 if (!isolate->use_crankshaft()) {
201 return Smi::FromInt(4); // 4 == "never".
202 }
203 bool sync_with_compiler_thread = true;
204 if (args.length() == 2) {
205 CONVERT_ARG_HANDLE_CHECKED(String, sync, 1);
206 if (sync->IsOneByteEqualTo(STATIC_CHAR_VECTOR("no sync"))) {
207 sync_with_compiler_thread = false;
208 }
209 }
210 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
211 if (isolate->concurrent_recompilation_enabled() &&
212 sync_with_compiler_thread) {
213 while (function->IsInOptimizationQueue()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000214 isolate->optimizing_compile_dispatcher()->InstallOptimizedFunctions();
215 base::OS::Sleep(base::TimeDelta::FromMilliseconds(50));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400216 }
217 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000218 if (FLAG_always_opt || FLAG_prepare_always_opt) {
219 // With --always-opt, optimization status expectations might not
220 // match up, so just return a sentinel.
221 return Smi::FromInt(3); // 3 == "always".
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400222 }
223 if (FLAG_deopt_every_n_times) {
224 return Smi::FromInt(6); // 6 == "maybe deopted".
225 }
226 if (function->IsOptimized() && function->code()->is_turbofanned()) {
227 return Smi::FromInt(7); // 7 == "TurboFan compiler".
228 }
229 return function->IsOptimized() ? Smi::FromInt(1) // 1 == "yes".
230 : Smi::FromInt(2); // 2 == "no".
231}
232
233
234RUNTIME_FUNCTION(Runtime_UnblockConcurrentRecompilation) {
235 DCHECK(args.length() == 0);
236 RUNTIME_ASSERT(FLAG_block_concurrent_recompilation);
237 RUNTIME_ASSERT(isolate->concurrent_recompilation_enabled());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000238 isolate->optimizing_compile_dispatcher()->Unblock();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400239 return isolate->heap()->undefined_value();
240}
241
242
243RUNTIME_FUNCTION(Runtime_GetOptimizationCount) {
244 HandleScope scope(isolate);
245 DCHECK(args.length() == 1);
246 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
247 return Smi::FromInt(function->shared()->opt_count());
248}
249
250
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000251RUNTIME_FUNCTION(Runtime_GetUndetectable) {
252 HandleScope scope(isolate);
253 DCHECK(args.length() == 0);
254 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
255
256 Local<v8::ObjectTemplate> desc = v8::ObjectTemplate::New(v8_isolate);
257 desc->MarkAsUndetectable();
258 Local<v8::Object> obj;
259 if (!desc->NewInstance(v8_isolate->GetCurrentContext()).ToLocal(&obj)) {
260 return nullptr;
261 }
262 return *Utils::OpenHandle(*obj);
263}
264
265
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400266RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) {
267 HandleScope scope(isolate);
268 DCHECK(args.length() == 1);
269 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100270 function->ClearTypeFeedbackInfo();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400271 Code* unoptimized = function->shared()->code();
272 if (unoptimized->kind() == Code::FUNCTION) {
273 unoptimized->ClearInlineCaches();
274 }
275 return isolate->heap()->undefined_value();
276}
277
278
279RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) {
280 HandleScope scope(isolate);
281 DCHECK(args.length() == 0);
282 isolate->heap()->NotifyContextDisposed(true);
283 return isolate->heap()->undefined_value();
284}
285
286
287RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) {
288 SealHandleScope shs(isolate);
289 DCHECK(args.length() == 2 || args.length() == 3);
290#ifdef DEBUG
291 CONVERT_SMI_ARG_CHECKED(interval, 0);
292 CONVERT_SMI_ARG_CHECKED(timeout, 1);
293 isolate->heap()->set_allocation_timeout(timeout);
294 FLAG_gc_interval = interval;
295 if (args.length() == 3) {
296 // Enable/disable inline allocation if requested.
297 CONVERT_BOOLEAN_ARG_CHECKED(inline_allocation, 2);
298 if (inline_allocation) {
299 isolate->heap()->EnableInlineAllocation();
300 } else {
301 isolate->heap()->DisableInlineAllocation();
302 }
303 }
304#endif
305 return isolate->heap()->undefined_value();
306}
307
308
309RUNTIME_FUNCTION(Runtime_DebugPrint) {
310 SealHandleScope shs(isolate);
311 DCHECK(args.length() == 1);
312
313 OFStream os(stdout);
314#ifdef DEBUG
315 if (args[0]->IsString()) {
316 // If we have a string, assume it's a code "marker"
317 // and print some interesting cpu debugging info.
318 JavaScriptFrameIterator it(isolate);
319 JavaScriptFrame* frame = it.frame();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000320 os << "fp = " << static_cast<void*>(frame->fp())
321 << ", sp = " << static_cast<void*>(frame->sp())
322 << ", caller_sp = " << static_cast<void*>(frame->caller_sp()) << ": ";
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400323 } else {
324 os << "DebugPrint: ";
325 }
326 args[0]->Print(os);
327 if (args[0]->IsHeapObject()) {
328 os << "\n";
329 HeapObject::cast(args[0])->map()->Print(os);
330 }
331#else
332 // ShortPrint is available in release mode. Print is not.
333 os << Brief(args[0]);
334#endif
335 os << std::endl;
336
337 return args[0]; // return TOS
338}
339
340
341RUNTIME_FUNCTION(Runtime_DebugTrace) {
342 SealHandleScope shs(isolate);
343 DCHECK(args.length() == 0);
344 isolate->PrintStack(stdout);
345 return isolate->heap()->undefined_value();
346}
347
348
349// This will not allocate (flatten the string), but it may run
350// very slowly for very deeply nested ConsStrings. For debugging use only.
351RUNTIME_FUNCTION(Runtime_GlobalPrint) {
352 SealHandleScope shs(isolate);
353 DCHECK(args.length() == 1);
354
355 CONVERT_ARG_CHECKED(String, string, 0);
356 StringCharacterStream stream(string);
357 while (stream.HasMore()) {
358 uint16_t character = stream.GetNext();
359 PrintF("%c", character);
360 }
361 return string;
362}
363
364
365RUNTIME_FUNCTION(Runtime_SystemBreak) {
366 // The code below doesn't create handles, but when breaking here in GDB
367 // having a handle scope might be useful.
368 HandleScope scope(isolate);
369 DCHECK(args.length() == 0);
370 base::OS::DebugBreak();
371 return isolate->heap()->undefined_value();
372}
373
374
375// Sets a v8 flag.
376RUNTIME_FUNCTION(Runtime_SetFlags) {
377 SealHandleScope shs(isolate);
378 DCHECK(args.length() == 1);
379 CONVERT_ARG_CHECKED(String, arg, 0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000380 base::SmartArrayPointer<char> flags =
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400381 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
382 FlagList::SetFlagsFromString(flags.get(), StrLength(flags.get()));
383 return isolate->heap()->undefined_value();
384}
385
386
387RUNTIME_FUNCTION(Runtime_Abort) {
388 SealHandleScope shs(isolate);
389 DCHECK(args.length() == 1);
390 CONVERT_SMI_ARG_CHECKED(message_id, 0);
391 const char* message =
392 GetBailoutReason(static_cast<BailoutReason>(message_id));
393 base::OS::PrintError("abort: %s\n", message);
394 isolate->PrintStack(stderr);
395 base::OS::Abort();
396 UNREACHABLE();
397 return NULL;
398}
399
400
401RUNTIME_FUNCTION(Runtime_AbortJS) {
402 HandleScope scope(isolate);
403 DCHECK(args.length() == 1);
404 CONVERT_ARG_HANDLE_CHECKED(String, message, 0);
405 base::OS::PrintError("abort: %s\n", message->ToCString().get());
406 isolate->PrintStack(stderr);
407 base::OS::Abort();
408 UNREACHABLE();
409 return NULL;
410}
411
412
413RUNTIME_FUNCTION(Runtime_NativeScriptsCount) {
414 DCHECK(args.length() == 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100415 return Smi::FromInt(Natives::GetBuiltinsCount());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400416}
417
418
419// Returns V8 version as a string.
420RUNTIME_FUNCTION(Runtime_GetV8Version) {
421 HandleScope scope(isolate);
422 DCHECK(args.length() == 0);
423
424 const char* version_string = v8::V8::GetVersion();
425
426 return *isolate->factory()->NewStringFromAsciiChecked(version_string);
427}
428
429
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000430RUNTIME_FUNCTION(Runtime_DisassembleFunction) {
431 HandleScope scope(isolate);
432#ifdef DEBUG
433 DCHECK(args.length() == 1);
434 // Get the function and make sure it is compiled.
435 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0);
Ben Murdochda12d292016-06-02 14:46:10 +0100436 if (!Compiler::Compile(func, Compiler::KEEP_EXCEPTION)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437 return isolate->heap()->exception();
438 }
439 OFStream os(stdout);
440 func->code()->Print(os);
441 os << std::endl;
442#endif // DEBUG
443 return isolate->heap()->undefined_value();
444}
445
Ben Murdoch097c5b22016-05-18 11:27:45 +0100446namespace {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000447
Ben Murdoch097c5b22016-05-18 11:27:45 +0100448int StackSize(Isolate* isolate) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400449 int n = 0;
450 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) n++;
451 return n;
452}
453
Ben Murdoch097c5b22016-05-18 11:27:45 +0100454void PrintIndentation(Isolate* isolate) {
455 const int nmax = 80;
456 int n = StackSize(isolate);
457 if (n <= nmax) {
458 PrintF("%4d:%*s", n, n, "");
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400459 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100460 PrintF("%4d:%*s", n, nmax, "...");
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400461 }
462}
463
Ben Murdoch097c5b22016-05-18 11:27:45 +0100464} // namespace
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400465
466RUNTIME_FUNCTION(Runtime_TraceEnter) {
467 SealHandleScope shs(isolate);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100468 DCHECK_EQ(0, args.length());
469 PrintIndentation(isolate);
470 JavaScriptFrame::PrintTop(isolate, stdout, true, false);
471 PrintF(" {\n");
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400472 return isolate->heap()->undefined_value();
473}
474
475
476RUNTIME_FUNCTION(Runtime_TraceExit) {
477 SealHandleScope shs(isolate);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100478 DCHECK_EQ(1, args.length());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400479 CONVERT_ARG_CHECKED(Object, obj, 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100480 PrintIndentation(isolate);
481 PrintF("} -> ");
482 obj->ShortPrint();
483 PrintF("\n");
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400484 return obj; // return TOS
485}
486
Ben Murdoch097c5b22016-05-18 11:27:45 +0100487RUNTIME_FUNCTION(Runtime_TraceTailCall) {
488 SealHandleScope shs(isolate);
489 DCHECK_EQ(0, args.length());
490 PrintIndentation(isolate);
491 PrintF("} -> tail call ->\n");
492 return isolate->heap()->undefined_value();
493}
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400494
Ben Murdochc5610432016-08-08 18:44:38 +0100495RUNTIME_FUNCTION(Runtime_GetExceptionDetails) {
496 HandleScope shs(isolate);
497 DCHECK(args.length() == 1);
498 CONVERT_ARG_HANDLE_CHECKED(JSObject, exception_obj, 0);
499
500 Factory* factory = isolate->factory();
501 Handle<JSMessageObject> message_obj =
502 isolate->CreateMessage(exception_obj, nullptr);
503
504 Handle<JSObject> message = factory->NewJSObject(isolate->object_function());
505
506 Handle<String> key;
507 Handle<Object> value;
508
509 key = factory->NewStringFromAsciiChecked("start_pos");
510 value = handle(Smi::FromInt(message_obj->start_position()), isolate);
511 JSObject::SetProperty(message, key, value, STRICT).Assert();
512
513 key = factory->NewStringFromAsciiChecked("end_pos");
514 value = handle(Smi::FromInt(message_obj->end_position()), isolate);
515 JSObject::SetProperty(message, key, value, STRICT).Assert();
516
517 return *message;
518}
519
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400520RUNTIME_FUNCTION(Runtime_HaveSameMap) {
521 SealHandleScope shs(isolate);
522 DCHECK(args.length() == 2);
523 CONVERT_ARG_CHECKED(JSObject, obj1, 0);
524 CONVERT_ARG_CHECKED(JSObject, obj2, 1);
525 return isolate->heap()->ToBoolean(obj1->map() == obj2->map());
526}
527
528
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000529RUNTIME_FUNCTION(Runtime_InNewSpace) {
530 SealHandleScope shs(isolate);
531 DCHECK(args.length() == 1);
532 CONVERT_ARG_CHECKED(Object, obj, 0);
533 return isolate->heap()->ToBoolean(isolate->heap()->InNewSpace(obj));
534}
535
536
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400537#define ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(Name) \
538 RUNTIME_FUNCTION(Runtime_Has##Name) { \
539 CONVERT_ARG_CHECKED(JSObject, obj, 0); \
540 return isolate->heap()->ToBoolean(obj->Has##Name()); \
541 }
542
543ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastSmiElements)
544ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastObjectElements)
545ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastSmiOrObjectElements)
546ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastDoubleElements)
547ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastHoleyElements)
548ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(DictionaryElements)
549ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(SloppyArgumentsElements)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000550ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FixedTypedArrayElements)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400551// Properties test sitting with elements tests - not fooling anyone.
552ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastProperties)
553
554#undef ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION
555
556
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400557#define FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION(Type, type, TYPE, ctype, s) \
558 RUNTIME_FUNCTION(Runtime_HasFixed##Type##Elements) { \
559 CONVERT_ARG_CHECKED(JSObject, obj, 0); \
560 return isolate->heap()->ToBoolean(obj->HasFixed##Type##Elements()); \
561 }
562
563TYPED_ARRAYS(FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION)
564
565#undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION
Ben Murdochda12d292016-06-02 14:46:10 +0100566
567
568RUNTIME_FUNCTION(Runtime_SpeciesProtector) {
569 SealHandleScope shs(isolate);
570 DCHECK_EQ(0, args.length());
571 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact());
572}
573
574
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000575} // namespace internal
576} // namespace v8