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

Side by Side Diff: src/runtime.cc

Issue 148593004: A64: Synchronize with r18084. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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.h ('k') | src/serialize.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 547
548 literals->set(literals_index, *site); 548 literals->set(literals_index, *site);
549 } else { 549 } else {
550 site = Handle<AllocationSite>::cast(literal_site); 550 site = Handle<AllocationSite>::cast(literal_site);
551 } 551 }
552 552
553 return site; 553 return site;
554 } 554 }
555 555
556 556
557 static MaybeObject* CreateArrayLiteralImpl(Isolate* isolate,
558 Handle<FixedArray> literals,
559 int literals_index,
560 Handle<FixedArray> elements,
561 int flags) {
562 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals,
563 literals_index, elements);
564 RETURN_IF_EMPTY_HANDLE(isolate, site);
565
566 bool enable_mementos = (flags & ArrayLiteral::kDisableMementos) == 0;
567 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info()));
568 AllocationSiteUsageContext usage_context(isolate, site, enable_mementos);
569 usage_context.EnterNewScope();
570 JSObject::DeepCopyHints hints = (flags & ArrayLiteral::kShallowElements) == 0
571 ? JSObject::kNoHints
572 : JSObject::kObjectIsShallowArray;
573 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &usage_context,
574 hints);
575 usage_context.ExitScope(site, boilerplate);
576 RETURN_IF_EMPTY_HANDLE(isolate, copy);
577 return *copy;
578 }
579
580
557 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { 581 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) {
558 HandleScope scope(isolate); 582 HandleScope scope(isolate);
583 ASSERT(args.length() == 4);
584 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0);
585 CONVERT_SMI_ARG_CHECKED(literals_index, 1);
586 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2);
587 CONVERT_SMI_ARG_CHECKED(flags, 3);
588
589 return CreateArrayLiteralImpl(isolate, literals, literals_index, elements,
590 flags);
591 }
592
593
594 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralStubBailout) {
595 HandleScope scope(isolate);
559 ASSERT(args.length() == 3); 596 ASSERT(args.length() == 3);
560 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); 597 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0);
561 CONVERT_SMI_ARG_CHECKED(literals_index, 1); 598 CONVERT_SMI_ARG_CHECKED(literals_index, 1);
562 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); 599 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2);
563 600
564 Handle<AllocationSite> site = GetLiteralAllocationSite(isolate, literals, 601 return CreateArrayLiteralImpl(isolate, literals, literals_index, elements,
565 literals_index, elements); 602 ArrayLiteral::kShallowElements);
566 RETURN_IF_EMPTY_HANDLE(isolate, site);
567
568 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info()));
569 AllocationSiteUsageContext usage_context(isolate, site, true);
570 usage_context.EnterNewScope();
571 Handle<JSObject> copy = JSObject::DeepCopy(boilerplate, &usage_context);
572 usage_context.ExitScope(site, boilerplate);
573 RETURN_IF_EMPTY_HANDLE(isolate, copy);
574 return *copy;
575 } 603 }
576 604
577 605
578 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { 606 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) {
579 HandleScope scope(isolate); 607 HandleScope scope(isolate);
580 ASSERT(args.length() == 1); 608 ASSERT(args.length() == 1);
581 Handle<Object> name(args[0], isolate); 609 Handle<Object> name(args[0], isolate);
582 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); 610 RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
583 Symbol* symbol; 611 Symbol* symbol;
584 MaybeObject* maybe = isolate->heap()->AllocateSymbol(); 612 MaybeObject* maybe = isolate->heap()->AllocateSymbol();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 HandleScope scope(isolate); 715 HandleScope scope(isolate);
688 ASSERT(args.length() == 1); 716 ASSERT(args.length() == 1);
689 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0); 717 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0);
690 JSProxy::Fix(proxy); 718 JSProxy::Fix(proxy);
691 return isolate->heap()->undefined_value(); 719 return isolate->heap()->undefined_value();
692 } 720 }
693 721
694 722
695 void Runtime::FreeArrayBuffer(Isolate* isolate, 723 void Runtime::FreeArrayBuffer(Isolate* isolate,
696 JSArrayBuffer* phantom_array_buffer) { 724 JSArrayBuffer* phantom_array_buffer) {
725 if (phantom_array_buffer->should_be_freed()) {
726 ASSERT(phantom_array_buffer->is_external());
727 free(phantom_array_buffer->backing_store());
728 }
697 if (phantom_array_buffer->is_external()) return; 729 if (phantom_array_buffer->is_external()) return;
698 730
699 size_t allocated_length = NumberToSize( 731 size_t allocated_length = NumberToSize(
700 isolate, phantom_array_buffer->byte_length()); 732 isolate, phantom_array_buffer->byte_length());
701 733
702 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( 734 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
703 -static_cast<intptr_t>(allocated_length)); 735 -static_cast<int64_t>(allocated_length));
704 CHECK(V8::ArrayBufferAllocator() != NULL); 736 CHECK(V8::ArrayBufferAllocator() != NULL);
705 V8::ArrayBufferAllocator()->Free( 737 V8::ArrayBufferAllocator()->Free(
706 phantom_array_buffer->backing_store(), 738 phantom_array_buffer->backing_store(),
707 allocated_length); 739 allocated_length);
708 } 740 }
709 741
710 742
711 void Runtime::SetupArrayBuffer(Isolate* isolate, 743 void Runtime::SetupArrayBuffer(Isolate* isolate,
712 Handle<JSArrayBuffer> array_buffer, 744 Handle<JSArrayBuffer> array_buffer,
713 bool is_external, 745 bool is_external,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) { 856 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) {
825 HandleScope scope(isolate); 857 HandleScope scope(isolate);
826 ASSERT(args.length() == 1); 858 ASSERT(args.length() == 1);
827 CONVERT_ARG_CHECKED(Object, object, 0); 859 CONVERT_ARG_CHECKED(Object, object, 0);
828 return object->IsJSArrayBufferView() 860 return object->IsJSArrayBufferView()
829 ? isolate->heap()->true_value() 861 ? isolate->heap()->true_value()
830 : isolate->heap()->false_value(); 862 : isolate->heap()->false_value();
831 } 863 }
832 864
833 865
834 enum TypedArrayId { 866 void Runtime::ArrayIdToTypeAndSize(
835 // arrayIds below should be synchromized with typedarray.js natives.
836 ARRAY_ID_UINT8 = 1,
837 ARRAY_ID_INT8 = 2,
838 ARRAY_ID_UINT16 = 3,
839 ARRAY_ID_INT16 = 4,
840 ARRAY_ID_UINT32 = 5,
841 ARRAY_ID_INT32 = 6,
842 ARRAY_ID_FLOAT32 = 7,
843 ARRAY_ID_FLOAT64 = 8,
844 ARRAY_ID_UINT8C = 9
845 };
846
847 static void ArrayIdToTypeAndSize(
848 int arrayId, ExternalArrayType* array_type, size_t* element_size) { 867 int arrayId, ExternalArrayType* array_type, size_t* element_size) {
849 switch (arrayId) { 868 switch (arrayId) {
850 case ARRAY_ID_UINT8: 869 case ARRAY_ID_UINT8:
851 *array_type = kExternalUnsignedByteArray; 870 *array_type = kExternalUnsignedByteArray;
852 *element_size = 1; 871 *element_size = 1;
853 break; 872 break;
854 case ARRAY_ID_INT8: 873 case ARRAY_ID_INT8:
855 *array_type = kExternalByteArray; 874 *array_type = kExternalByteArray;
856 *element_size = 1; 875 *element_size = 1;
857 break; 876 break;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); 918 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4);
900 919
901 ASSERT(holder->GetInternalFieldCount() == 920 ASSERT(holder->GetInternalFieldCount() ==
902 v8::ArrayBufferView::kInternalFieldCount); 921 v8::ArrayBufferView::kInternalFieldCount);
903 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 922 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
904 holder->SetInternalField(i, Smi::FromInt(0)); 923 holder->SetInternalField(i, Smi::FromInt(0));
905 } 924 }
906 925
907 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. 926 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
908 size_t element_size = 1; // Bogus initialization. 927 size_t element_size = 1; // Bogus initialization.
909 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); 928 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
910 929
911 holder->set_buffer(*buffer); 930 holder->set_buffer(*buffer);
912 holder->set_byte_offset(*byte_offset_object); 931 holder->set_byte_offset(*byte_offset_object);
913 holder->set_byte_length(*byte_length_object); 932 holder->set_byte_length(*byte_length_object);
914 933
915 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); 934 size_t byte_offset = NumberToSize(isolate, *byte_offset_object);
916 size_t byte_length = NumberToSize(isolate, *byte_length_object); 935 size_t byte_length = NumberToSize(isolate, *byte_length_object);
917 ASSERT(byte_length % element_size == 0); 936 ASSERT(byte_length % element_size == 0);
918 size_t length = byte_length / element_size; 937 size_t length = byte_length / element_size;
919 938
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3); 970 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3);
952 971
953 ASSERT(holder->GetInternalFieldCount() == 972 ASSERT(holder->GetInternalFieldCount() ==
954 v8::ArrayBufferView::kInternalFieldCount); 973 v8::ArrayBufferView::kInternalFieldCount);
955 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 974 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
956 holder->SetInternalField(i, Smi::FromInt(0)); 975 holder->SetInternalField(i, Smi::FromInt(0));
957 } 976 }
958 977
959 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. 978 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
960 size_t element_size = 1; // Bogus initialization. 979 size_t element_size = 1; // Bogus initialization.
961 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); 980 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
962 981
963 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 982 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
964 size_t length = NumberToSize(isolate, *length_obj); 983 size_t length = NumberToSize(isolate, *length_obj);
965 984
966 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || 985 if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
967 (length > (kMaxInt / element_size))) { 986 (length > (kMaxInt / element_size))) {
968 return isolate->Throw(*isolate->factory()-> 987 return isolate->Throw(*isolate->factory()->
969 NewRangeError("invalid_typed_array_length", 988 NewRangeError("invalid_typed_array_length",
970 HandleVector<Object>(NULL, 0))); 989 HandleVector<Object>(NULL, 0)));
971 } 990 }
(...skipping 3465 matching lines...) Expand 10 before | Expand all | Expand 10 after
4437 } else { 4456 } else {
4438 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); 4457 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1);
4439 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); 4458 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2);
4440 start = FastD2IChecked(from_number); 4459 start = FastD2IChecked(from_number);
4441 end = FastD2IChecked(to_number); 4460 end = FastD2IChecked(to_number);
4442 } 4461 }
4443 RUNTIME_ASSERT(end >= start); 4462 RUNTIME_ASSERT(end >= start);
4444 RUNTIME_ASSERT(start >= 0); 4463 RUNTIME_ASSERT(start >= 0);
4445 RUNTIME_ASSERT(end <= value->length()); 4464 RUNTIME_ASSERT(end <= value->length());
4446 isolate->counters()->sub_string_runtime()->Increment(); 4465 isolate->counters()->sub_string_runtime()->Increment();
4447 if (end - start == 1) {
4448 return isolate->heap()->LookupSingleCharacterStringFromCode(
4449 value->Get(start));
4450 }
4451 return value->SubString(start, end); 4466 return value->SubString(start, end);
4452 } 4467 }
4453 4468
4454 4469
4455 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { 4470 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) {
4456 HandleScope handles(isolate); 4471 HandleScope handles(isolate);
4457 ASSERT_EQ(3, args.length()); 4472 ASSERT_EQ(3, args.length());
4458 4473
4459 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 4474 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
4460 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 4475 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
(...skipping 3214 matching lines...) Expand 10 before | Expand all | Expand 10 after
7675 int multiplier = (x < 0) ? -1 : 1; 7690 int multiplier = (x < 0) ? -1 : 1;
7676 if (y < 0) multiplier *= 3; 7691 if (y < 0) multiplier *= 3;
7677 result = multiplier * kPiDividedBy4; 7692 result = multiplier * kPiDividedBy4;
7678 } else { 7693 } else {
7679 result = atan2(x, y); 7694 result = atan2(x, y);
7680 } 7695 }
7681 return isolate->heap()->AllocateHeapNumber(result); 7696 return isolate->heap()->AllocateHeapNumber(result);
7682 } 7697 }
7683 7698
7684 7699
7685 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_ceil) {
7686 SealHandleScope shs(isolate);
7687 ASSERT(args.length() == 1);
7688 isolate->counters()->math_ceil()->Increment();
7689
7690 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7691 return isolate->heap()->NumberFromDouble(ceiling(x));
7692 }
7693
7694
7695 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_cos) { 7700 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_cos) {
7696 SealHandleScope shs(isolate); 7701 SealHandleScope shs(isolate);
7697 ASSERT(args.length() == 1); 7702 ASSERT(args.length() == 1);
7698 isolate->counters()->math_cos()->Increment(); 7703 isolate->counters()->math_cos()->Increment();
7699 7704
7700 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7705 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7701 return isolate->transcendental_cache()->Get(TranscendentalCache::COS, x); 7706 return isolate->transcendental_cache()->Get(TranscendentalCache::COS, x);
7702 } 7707 }
7703 7708
7704 7709
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
7841 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) { 7846 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) {
7842 SealHandleScope shs(isolate); 7847 SealHandleScope shs(isolate);
7843 ASSERT(args.length() == 1); 7848 ASSERT(args.length() == 1);
7844 isolate->counters()->math_tan()->Increment(); 7849 isolate->counters()->math_tan()->Increment();
7845 7850
7846 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7851 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7847 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x); 7852 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
7848 } 7853 }
7849 7854
7850 7855
7851 RUNTIME_FUNCTION(MaybeObject*, Runtime_PopulateTrigonometricTable) {
7852 HandleScope scope(isolate);
7853 ASSERT(args.length() == 3);
7854 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sin_table, 0);
7855 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, cos_table, 1);
7856 CONVERT_SMI_ARG_CHECKED(samples, 2);
7857 RUNTIME_ASSERT(sin_table->type() == kExternalDoubleArray);
7858 RUNTIME_ASSERT(cos_table->type() == kExternalDoubleArray);
7859 double* sin_buffer = reinterpret_cast<double*>(
7860 JSArrayBuffer::cast(sin_table->buffer())->backing_store());
7861 double* cos_buffer = reinterpret_cast<double*>(
7862 JSArrayBuffer::cast(cos_table->buffer())->backing_store());
7863
7864 static const double pi_half = 3.1415926535897932 / 2;
7865 double interval = pi_half / samples;
7866 for (int i = 0; i < samples + 1; i++) {
7867 double sample = sin(i * interval);
7868 sin_buffer[i] = sample;
7869 cos_buffer[samples - i] = sample * interval;
7870 }
7871
7872 // Fill this to catch out of bound accesses when calculating Math.sin(pi/2).
7873 sin_buffer[samples + 1] = sin(pi_half + interval);
7874 cos_buffer[samples + 1] = cos(pi_half + interval) * interval;
7875
7876 return isolate->heap()->undefined_value();
7877 }
7878
7879
7880 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { 7856 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) {
7881 SealHandleScope shs(isolate); 7857 SealHandleScope shs(isolate);
7882 ASSERT(args.length() == 2); 7858 ASSERT(args.length() == 2);
7883 7859
7884 CONVERT_SMI_ARG_CHECKED(year, 0); 7860 CONVERT_SMI_ARG_CHECKED(year, 0);
7885 CONVERT_SMI_ARG_CHECKED(month, 1); 7861 CONVERT_SMI_ARG_CHECKED(month, 1);
7886 7862
7887 return Smi::FromInt(isolate->date_cache()->DaysFromYearMonth(year, month)); 7863 return Smi::FromInt(isolate->date_cache()->DaysFromYearMonth(year, month));
7888 } 7864 }
7889 7865
(...skipping 7027 matching lines...) Expand 10 before | Expand all | Expand 10 after
14917 // Handle last resort GC and make sure to allow future allocations 14893 // Handle last resort GC and make sure to allow future allocations
14918 // to grow the heap without causing GCs (if possible). 14894 // to grow the heap without causing GCs (if possible).
14919 isolate->counters()->gc_last_resort_from_js()->Increment(); 14895 isolate->counters()->gc_last_resort_from_js()->Increment();
14920 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14896 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14921 "Runtime::PerformGC"); 14897 "Runtime::PerformGC");
14922 } 14898 }
14923 } 14899 }
14924 14900
14925 14901
14926 } } // namespace v8::internal 14902 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698