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

Side by Side Diff: src/runtime.cc

Issue 238273006: Remove some direct uses of heap allocators from runtime.cc (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/factory.cc ('k') | no next file » | 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); 601 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2);
602 602
603 return CreateArrayLiteralImpl(isolate, literals, literals_index, elements, 603 return CreateArrayLiteralImpl(isolate, literals, literals_index, elements,
604 ArrayLiteral::kShallowElements); 604 ArrayLiteral::kShallowElements);
605 } 605 }
606 606
607 607
608 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { 608 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) {
609 HandleScope scope(isolate); 609 HandleScope scope(isolate);
610 ASSERT(args.length() == 1); 610 ASSERT(args.length() == 1);
611 Handle<Object> name(args[0], isolate); 611 Handle<Object> name = args.at<Object>(0);
612 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); 612 RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
613 Symbol* symbol; 613 Handle<Symbol> symbol = isolate->factory()->NewSymbol();
614 MaybeObject* maybe = isolate->heap()->AllocateSymbol();
615 if (!maybe->To(&symbol)) return maybe;
616 if (name->IsString()) symbol->set_name(*name); 614 if (name->IsString()) symbol->set_name(*name);
617 return symbol; 615 return *symbol;
618 } 616 }
619 617
620 618
621 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreatePrivateSymbol) { 619 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreatePrivateSymbol) {
622 HandleScope scope(isolate); 620 HandleScope scope(isolate);
623 ASSERT(args.length() == 1); 621 ASSERT(args.length() == 1);
624 Handle<Object> name(args[0], isolate); 622 Handle<Object> name = args.at<Object>(0);
625 RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); 623 RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
626 Symbol* symbol; 624 Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
627 MaybeObject* maybe = isolate->heap()->AllocatePrivateSymbol();
628 if (!maybe->To(&symbol)) return maybe;
629 if (name->IsString()) symbol->set_name(*name); 625 if (name->IsString()) symbol->set_name(*name);
630 return symbol; 626 return *symbol;
631 } 627 }
632 628
633 629
634 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateGlobalPrivateSymbol) { 630 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateGlobalPrivateSymbol) {
635 HandleScope scope(isolate); 631 HandleScope scope(isolate);
636 ASSERT(args.length() == 1); 632 ASSERT(args.length() == 1);
637 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 633 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
638 Handle<JSObject> registry = isolate->GetSymbolRegistry(); 634 Handle<JSObject> registry = isolate->GetSymbolRegistry();
639 Handle<String> part = isolate->factory()->private_intern_string(); 635 Handle<String> part = isolate->factory()->private_intern_string();
640 Handle<Object> privates; 636 Handle<Object> privates;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 675
680 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolIsPrivate) { 676 RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolIsPrivate) {
681 SealHandleScope shs(isolate); 677 SealHandleScope shs(isolate);
682 ASSERT(args.length() == 1); 678 ASSERT(args.length() == 1);
683 CONVERT_ARG_CHECKED(Symbol, symbol, 0); 679 CONVERT_ARG_CHECKED(Symbol, symbol, 0);
684 return isolate->heap()->ToBoolean(symbol->is_private()); 680 return isolate->heap()->ToBoolean(symbol->is_private());
685 } 681 }
686 682
687 683
688 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) { 684 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) {
689 SealHandleScope shs(isolate); 685 HandleScope scope(isolate);
690 ASSERT(args.length() == 2); 686 ASSERT(args.length() == 2);
691 CONVERT_ARG_CHECKED(JSReceiver, handler, 0); 687 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 0);
692 Object* prototype = args[1]; 688 Handle<Object> prototype = args.at<Object>(1);
693 Object* used_prototype = 689 if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value();
694 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); 690 return *isolate->factory()->NewJSProxy(handler, prototype);
695 return isolate->heap()->AllocateJSProxy(handler, used_prototype);
696 } 691 }
697 692
698 693
699 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) { 694 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) {
700 SealHandleScope shs(isolate); 695 HandleScope scope(isolate);
701 ASSERT(args.length() == 4); 696 ASSERT(args.length() == 4);
702 CONVERT_ARG_CHECKED(JSReceiver, handler, 0); 697 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 0);
703 Object* call_trap = args[1]; 698 Handle<Object> call_trap = args.at<Object>(1);
704 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy()); 699 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy());
705 CONVERT_ARG_CHECKED(JSFunction, construct_trap, 2); 700 CONVERT_ARG_HANDLE_CHECKED(JSFunction, construct_trap, 2);
706 Object* prototype = args[3]; 701 Handle<Object> prototype = args.at<Object>(3);
707 Object* used_prototype = 702 if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value();
708 prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); 703 return *isolate->factory()->NewJSFunctionProxy(
709 return isolate->heap()->AllocateJSFunctionProxy( 704 handler, call_trap, construct_trap, prototype);
710 handler, call_trap, construct_trap, used_prototype);
711 } 705 }
712 706
713 707
714 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSProxy) { 708 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsJSProxy) {
715 SealHandleScope shs(isolate); 709 SealHandleScope shs(isolate);
716 ASSERT(args.length() == 1); 710 ASSERT(args.length() == 1);
717 Object* obj = args[0]; 711 Object* obj = args[0];
718 return isolate->heap()->ToBoolean(obj->IsJSProxy()); 712 return isolate->heap()->ToBoolean(obj->IsJSProxy());
719 } 713 }
720 714
(...skipping 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 generator->set_receiver(frame->receiver()); 3108 generator->set_receiver(frame->receiver());
3115 generator->set_continuation(0); 3109 generator->set_continuation(0);
3116 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); 3110 generator->set_operand_stack(isolate->heap()->empty_fixed_array());
3117 generator->set_stack_handler_index(-1); 3111 generator->set_stack_handler_index(-1);
3118 3112
3119 return *generator; 3113 return *generator;
3120 } 3114 }
3121 3115
3122 3116
3123 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_SuspendJSGeneratorObject) { 3117 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_SuspendJSGeneratorObject) {
3124 SealHandleScope shs(isolate); 3118 HandleScope handle_scope(isolate);
3125 ASSERT(args.length() == 1); 3119 ASSERT(args.length() == 1);
3126 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); 3120 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0);
3127 3121
3128 JavaScriptFrameIterator stack_iterator(isolate); 3122 JavaScriptFrameIterator stack_iterator(isolate);
3129 JavaScriptFrame* frame = stack_iterator.frame(); 3123 JavaScriptFrame* frame = stack_iterator.frame();
3130 RUNTIME_ASSERT(frame->function()->shared()->is_generator()); 3124 RUNTIME_ASSERT(frame->function()->shared()->is_generator());
3131 ASSERT_EQ(frame->function(), generator_object->function()); 3125 ASSERT_EQ(frame->function(), generator_object->function());
3132 3126
3133 // The caller should have saved the context and continuation already. 3127 // The caller should have saved the context and continuation already.
3134 ASSERT_EQ(generator_object->context(), Context::cast(frame->context())); 3128 ASSERT_EQ(generator_object->context(), Context::cast(frame->context()));
3135 ASSERT_LT(0, generator_object->continuation()); 3129 ASSERT_LT(0, generator_object->continuation());
3136 3130
3137 // We expect there to be at least two values on the operand stack: the return 3131 // We expect there to be at least two values on the operand stack: the return
3138 // value of the yield expression, and the argument to this runtime call. 3132 // value of the yield expression, and the argument to this runtime call.
3139 // Neither of those should be saved. 3133 // Neither of those should be saved.
3140 int operands_count = frame->ComputeOperandsCount(); 3134 int operands_count = frame->ComputeOperandsCount();
3141 ASSERT_GE(operands_count, 2); 3135 ASSERT_GE(operands_count, 2);
3142 operands_count -= 2; 3136 operands_count -= 2;
3143 3137
3144 if (operands_count == 0) { 3138 if (operands_count == 0) {
3145 // Although it's semantically harmless to call this function with an 3139 // Although it's semantically harmless to call this function with an
3146 // operands_count of zero, it is also unnecessary. 3140 // operands_count of zero, it is also unnecessary.
3147 ASSERT_EQ(generator_object->operand_stack(), 3141 ASSERT_EQ(generator_object->operand_stack(),
3148 isolate->heap()->empty_fixed_array()); 3142 isolate->heap()->empty_fixed_array());
3149 ASSERT_EQ(generator_object->stack_handler_index(), -1); 3143 ASSERT_EQ(generator_object->stack_handler_index(), -1);
3150 // If there are no operands on the stack, there shouldn't be a handler 3144 // If there are no operands on the stack, there shouldn't be a handler
3151 // active either. 3145 // active either.
3152 ASSERT(!frame->HasHandler()); 3146 ASSERT(!frame->HasHandler());
3153 } else { 3147 } else {
3154 int stack_handler_index = -1; 3148 int stack_handler_index = -1;
3155 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count); 3149 Handle<FixedArray> operand_stack =
3156 FixedArray* operand_stack; 3150 isolate->factory()->NewFixedArray(operands_count);
3157 if (!alloc->To(&operand_stack)) return alloc; 3151 frame->SaveOperandStack(*operand_stack, &stack_handler_index);
3158 frame->SaveOperandStack(operand_stack, &stack_handler_index); 3152 generator_object->set_operand_stack(*operand_stack);
3159 generator_object->set_operand_stack(operand_stack);
3160 generator_object->set_stack_handler_index(stack_handler_index); 3153 generator_object->set_stack_handler_index(stack_handler_index);
3161 } 3154 }
3162 3155
3163 return isolate->heap()->undefined_value(); 3156 return isolate->heap()->undefined_value();
3164 } 3157 }
3165 3158
3166 3159
3167 // Note that this function is the slow path for resuming generators. It is only 3160 // Note that this function is the slow path for resuming generators. It is only
3168 // called if the suspended activation had operands on the stack, stack handlers 3161 // called if the suspended activation had operands on the stack, stack handlers
3169 // needing rewinding, or if the resume should throw an exception. The fast path 3162 // needing rewinding, or if the resume should throw an exception. The fast path
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
4765 return SearchRegExpMultiple<false>( 4758 return SearchRegExpMultiple<false>(
4766 isolate, subject, regexp, last_match_info, result_array); 4759 isolate, subject, regexp, last_match_info, result_array);
4767 } else { 4760 } else {
4768 return SearchRegExpMultiple<true>( 4761 return SearchRegExpMultiple<true>(
4769 isolate, subject, regexp, last_match_info, result_array); 4762 isolate, subject, regexp, last_match_info, result_array);
4770 } 4763 }
4771 } 4764 }
4772 4765
4773 4766
4774 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) { 4767 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) {
4775 SealHandleScope shs(isolate); 4768 HandleScope scope(isolate);
4776 ASSERT(args.length() == 2); 4769 ASSERT(args.length() == 2);
4777 CONVERT_SMI_ARG_CHECKED(radix, 1); 4770 CONVERT_SMI_ARG_CHECKED(radix, 1);
4778 RUNTIME_ASSERT(2 <= radix && radix <= 36); 4771 RUNTIME_ASSERT(2 <= radix && radix <= 36);
4779 4772
4780 // Fast case where the result is a one character string. 4773 // Fast case where the result is a one character string.
4781 if (args[0]->IsSmi()) { 4774 if (args[0]->IsSmi()) {
4782 int value = args.smi_at(0); 4775 int value = args.smi_at(0);
4783 if (value >= 0 && value < radix) { 4776 if (value >= 0 && value < radix) {
4784 // Character array used for conversion. 4777 // Character array used for conversion.
4785 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 4778 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
4786 return isolate->heap()-> 4779 return *isolate->factory()->
4787 LookupSingleCharacterStringFromCode(kCharTable[value]); 4780 LookupSingleCharacterStringFromCode(kCharTable[value]);
4788 } 4781 }
4789 } 4782 }
4790 4783
4791 // Slow case. 4784 // Slow case.
4792 CONVERT_DOUBLE_ARG_CHECKED(value, 0); 4785 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
4793 if (std::isnan(value)) { 4786 if (std::isnan(value)) {
4794 return *isolate->factory()->nan_string(); 4787 return isolate->heap()->nan_string();
4795 } 4788 }
4796 if (std::isinf(value)) { 4789 if (std::isinf(value)) {
4797 if (value < 0) { 4790 if (value < 0) {
4798 return *isolate->factory()->minus_infinity_string(); 4791 return isolate->heap()->minus_infinity_string();
4799 } 4792 }
4800 return *isolate->factory()->infinity_string(); 4793 return isolate->heap()->infinity_string();
4801 } 4794 }
4802 char* str = DoubleToRadixCString(value, radix); 4795 char* str = DoubleToRadixCString(value, radix);
4803 MaybeObject* result = 4796 Handle<String> result =
4804 isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); 4797 isolate->factory()->NewStringFromOneByte(OneByteVector(str));
4805 DeleteArray(str); 4798 DeleteArray(str);
4806 return result; 4799 return *result;
4807 } 4800 }
4808 4801
4809 4802
4810 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToFixed) { 4803 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToFixed) {
4811 SealHandleScope shs(isolate); 4804 HandleScope scope(isolate);
4812 ASSERT(args.length() == 2); 4805 ASSERT(args.length() == 2);
4813 4806
4814 CONVERT_DOUBLE_ARG_CHECKED(value, 0); 4807 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
4815 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); 4808 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
4816 int f = FastD2IChecked(f_number); 4809 int f = FastD2IChecked(f_number);
4817 RUNTIME_ASSERT(f >= 0); 4810 RUNTIME_ASSERT(f >= 0);
4818 char* str = DoubleToFixedCString(value, f); 4811 char* str = DoubleToFixedCString(value, f);
4819 MaybeObject* res = 4812 Handle<String> result =
4820 isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); 4813 isolate->factory()->NewStringFromOneByte(OneByteVector(str));
4821 DeleteArray(str); 4814 DeleteArray(str);
4822 return res; 4815 return *result;
4823 } 4816 }
4824 4817
4825 4818
4826 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToExponential) { 4819 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToExponential) {
4827 SealHandleScope shs(isolate); 4820 HandleScope scope(isolate);
4828 ASSERT(args.length() == 2); 4821 ASSERT(args.length() == 2);
4829 4822
4830 CONVERT_DOUBLE_ARG_CHECKED(value, 0); 4823 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
4831 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); 4824 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
4832 int f = FastD2IChecked(f_number); 4825 int f = FastD2IChecked(f_number);
4833 RUNTIME_ASSERT(f >= -1 && f <= 20); 4826 RUNTIME_ASSERT(f >= -1 && f <= 20);
4834 char* str = DoubleToExponentialCString(value, f); 4827 char* str = DoubleToExponentialCString(value, f);
4835 MaybeObject* res = 4828 Handle<String> result =
4836 isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); 4829 isolate->factory()->NewStringFromOneByte(OneByteVector(str));
4837 DeleteArray(str); 4830 DeleteArray(str);
4838 return res; 4831 return *result;
4839 } 4832 }
4840 4833
4841 4834
4842 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToPrecision) { 4835 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToPrecision) {
4843 SealHandleScope shs(isolate); 4836 HandleScope scope(isolate);
4844 ASSERT(args.length() == 2); 4837 ASSERT(args.length() == 2);
4845 4838
4846 CONVERT_DOUBLE_ARG_CHECKED(value, 0); 4839 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
4847 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); 4840 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
4848 int f = FastD2IChecked(f_number); 4841 int f = FastD2IChecked(f_number);
4849 RUNTIME_ASSERT(f >= 1 && f <= 21); 4842 RUNTIME_ASSERT(f >= 1 && f <= 21);
4850 char* str = DoubleToPrecisionCString(value, f); 4843 char* str = DoubleToPrecisionCString(value, f);
4851 MaybeObject* res = 4844 Handle<String> result =
4852 isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); 4845 isolate->factory()->NewStringFromOneByte(OneByteVector(str));
4853 DeleteArray(str); 4846 DeleteArray(str);
4854 return res; 4847 return *result;
4855 } 4848 }
4856 4849
4857 4850
4858 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsValidSmi) { 4851 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsValidSmi) {
4859 HandleScope shs(isolate); 4852 SealHandleScope shs(isolate);
4860 ASSERT(args.length() == 1); 4853 ASSERT(args.length() == 1);
4861 4854
4862 CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]); 4855 CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]);
4863 if (Smi::IsValid(number)) { 4856 if (Smi::IsValid(number)) {
4864 return isolate->heap()->true_value(); 4857 return isolate->heap()->true_value();
4865 } else { 4858 } else {
4866 return isolate->heap()->false_value(); 4859 return isolate->heap()->false_value();
4867 } 4860 }
4868 } 4861 }
4869 4862
(...skipping 10234 matching lines...) Expand 10 before | Expand all | Expand 10 after
15104 } 15097 }
15105 } 15098 }
15106 15099
15107 15100
15108 void Runtime::OutOfMemory() { 15101 void Runtime::OutOfMemory() {
15109 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); 15102 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);
15110 UNREACHABLE(); 15103 UNREACHABLE();
15111 } 15104 }
15112 15105
15113 } } // namespace v8::internal 15106 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698