| OLD | NEW |
| 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 6533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6544 if (static_cast<uint32_t>(indices.length()) < limit) { | 6544 if (static_cast<uint32_t>(indices.length()) < limit) { |
| 6545 indices.Add(subject_length, zone_scope.zone()); | 6545 indices.Add(subject_length, zone_scope.zone()); |
| 6546 } | 6546 } |
| 6547 | 6547 |
| 6548 // The list indices now contains the end of each part to create. | 6548 // The list indices now contains the end of each part to create. |
| 6549 | 6549 |
| 6550 // Create JSArray of substrings separated by separator. | 6550 // Create JSArray of substrings separated by separator. |
| 6551 int part_count = indices.length(); | 6551 int part_count = indices.length(); |
| 6552 | 6552 |
| 6553 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); | 6553 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); |
| 6554 MaybeObject* maybe_result = result->EnsureCanContainHeapObjectElements(); | 6554 JSObject::EnsureCanContainHeapObjectElements(result); |
| 6555 if (maybe_result->IsFailure()) return maybe_result; | |
| 6556 result->set_length(Smi::FromInt(part_count)); | 6555 result->set_length(Smi::FromInt(part_count)); |
| 6557 | 6556 |
| 6558 ASSERT(result->HasFastObjectElements()); | 6557 ASSERT(result->HasFastObjectElements()); |
| 6559 | 6558 |
| 6560 if (part_count == 1 && indices.at(0) == subject_length) { | 6559 if (part_count == 1 && indices.at(0) == subject_length) { |
| 6561 FixedArray::cast(result->elements())->set(0, *subject); | 6560 FixedArray::cast(result->elements())->set(0, *subject); |
| 6562 return *result; | 6561 return *result; |
| 6563 } | 6562 } |
| 6564 | 6563 |
| 6565 Handle<FixedArray> elements(FixedArray::cast(result->elements())); | 6564 Handle<FixedArray> elements(FixedArray::cast(result->elements())); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6938 String* string = String::cast(element); | 6937 String* string = String::cast(element); |
| 6939 int element_length = string->length(); | 6938 int element_length = string->length(); |
| 6940 String::WriteToFlat(string, sink + position, 0, element_length); | 6939 String::WriteToFlat(string, sink + position, 0, element_length); |
| 6941 position += element_length; | 6940 position += element_length; |
| 6942 } | 6941 } |
| 6943 } | 6942 } |
| 6944 } | 6943 } |
| 6945 | 6944 |
| 6946 | 6945 |
| 6947 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) { | 6946 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) { |
| 6948 SealHandleScope shs(isolate); | 6947 HandleScope scope(isolate); |
| 6949 ASSERT(args.length() == 3); | 6948 ASSERT(args.length() == 3); |
| 6950 CONVERT_ARG_CHECKED(JSArray, array, 0); | 6949 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); |
| 6951 if (!args[1]->IsSmi()) { | 6950 if (!args[1]->IsSmi()) { |
| 6952 isolate->context()->mark_out_of_memory(); | 6951 isolate->context()->mark_out_of_memory(); |
| 6953 return Failure::OutOfMemoryException(0x14); | 6952 return Failure::OutOfMemoryException(0x14); |
| 6954 } | 6953 } |
| 6955 int array_length = args.smi_at(1); | 6954 int array_length = args.smi_at(1); |
| 6956 CONVERT_ARG_CHECKED(String, special, 2); | 6955 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); |
| 6957 | 6956 |
| 6958 // This assumption is used by the slice encoding in one or two smis. | 6957 // This assumption is used by the slice encoding in one or two smis. |
| 6959 ASSERT(Smi::kMaxValue >= String::kMaxLength); | 6958 ASSERT(Smi::kMaxValue >= String::kMaxLength); |
| 6960 | 6959 |
| 6961 MaybeObject* maybe_result = array->EnsureCanContainHeapObjectElements(); | 6960 JSObject::EnsureCanContainHeapObjectElements(array); |
| 6962 if (maybe_result->IsFailure()) return maybe_result; | |
| 6963 | 6961 |
| 6964 int special_length = special->length(); | 6962 int special_length = special->length(); |
| 6965 if (!array->HasFastObjectElements()) { | 6963 if (!array->HasFastObjectElements()) { |
| 6966 return isolate->Throw(isolate->heap()->illegal_argument_string()); | 6964 return isolate->Throw(isolate->heap()->illegal_argument_string()); |
| 6967 } | 6965 } |
| 6968 FixedArray* fixed_array = FixedArray::cast(array->elements()); | 6966 FixedArray* fixed_array = FixedArray::cast(array->elements()); |
| 6969 if (fixed_array->length() < array_length) { | 6967 if (fixed_array->length() < array_length) { |
| 6970 array_length = fixed_array->length(); | 6968 array_length = fixed_array->length(); |
| 6971 } | 6969 } |
| 6972 | 6970 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7034 | 7032 |
| 7035 int length = position; | 7033 int length = position; |
| 7036 Object* object; | 7034 Object* object; |
| 7037 | 7035 |
| 7038 if (one_byte) { | 7036 if (one_byte) { |
| 7039 { MaybeObject* maybe_object = | 7037 { MaybeObject* maybe_object = |
| 7040 isolate->heap()->AllocateRawOneByteString(length); | 7038 isolate->heap()->AllocateRawOneByteString(length); |
| 7041 if (!maybe_object->ToObject(&object)) return maybe_object; | 7039 if (!maybe_object->ToObject(&object)) return maybe_object; |
| 7042 } | 7040 } |
| 7043 SeqOneByteString* answer = SeqOneByteString::cast(object); | 7041 SeqOneByteString* answer = SeqOneByteString::cast(object); |
| 7044 StringBuilderConcatHelper(special, | 7042 StringBuilderConcatHelper(*special, |
| 7045 answer->GetChars(), | 7043 answer->GetChars(), |
| 7046 fixed_array, | 7044 fixed_array, |
| 7047 array_length); | 7045 array_length); |
| 7048 return answer; | 7046 return answer; |
| 7049 } else { | 7047 } else { |
| 7050 { MaybeObject* maybe_object = | 7048 { MaybeObject* maybe_object = |
| 7051 isolate->heap()->AllocateRawTwoByteString(length); | 7049 isolate->heap()->AllocateRawTwoByteString(length); |
| 7052 if (!maybe_object->ToObject(&object)) return maybe_object; | 7050 if (!maybe_object->ToObject(&object)) return maybe_object; |
| 7053 } | 7051 } |
| 7054 SeqTwoByteString* answer = SeqTwoByteString::cast(object); | 7052 SeqTwoByteString* answer = SeqTwoByteString::cast(object); |
| 7055 StringBuilderConcatHelper(special, | 7053 StringBuilderConcatHelper(*special, |
| 7056 answer->GetChars(), | 7054 answer->GetChars(), |
| 7057 fixed_array, | 7055 fixed_array, |
| 7058 array_length); | 7056 array_length); |
| 7059 return answer; | 7057 return answer; |
| 7060 } | 7058 } |
| 7061 } | 7059 } |
| 7062 | 7060 |
| 7063 | 7061 |
| 7064 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderJoin) { | 7062 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderJoin) { |
| 7065 SealHandleScope shs(isolate); | 7063 SealHandleScope shs(isolate); |
| (...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8311 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyRecompile) { | 8309 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyRecompile) { |
| 8312 HandleScope scope(isolate); | 8310 HandleScope scope(isolate); |
| 8313 ASSERT(args.length() == 1); | 8311 ASSERT(args.length() == 1); |
| 8314 Handle<JSFunction> function = args.at<JSFunction>(0); | 8312 Handle<JSFunction> function = args.at<JSFunction>(0); |
| 8315 | 8313 |
| 8316 if (!AllowOptimization(isolate, function)) { | 8314 if (!AllowOptimization(isolate, function)) { |
| 8317 function->ReplaceCode(function->shared()->code()); | 8315 function->ReplaceCode(function->shared()->code()); |
| 8318 return function->code(); | 8316 return function->code(); |
| 8319 } | 8317 } |
| 8320 function->shared()->code()->set_profiler_ticks(0); | 8318 function->shared()->code()->set_profiler_ticks(0); |
| 8321 if (JSFunction::CompileOptimized(function, | 8319 if (JSFunction::CompileOptimized(function, CLEAR_EXCEPTION)) { |
| 8322 BailoutId::None(), | |
| 8323 CLEAR_EXCEPTION)) { | |
| 8324 return function->code(); | 8320 return function->code(); |
| 8325 } | 8321 } |
| 8326 if (FLAG_trace_opt) { | 8322 if (FLAG_trace_opt) { |
| 8327 PrintF("[failed to optimize "); | 8323 PrintF("[failed to optimize "); |
| 8328 function->PrintName(); | 8324 function->PrintName(); |
| 8329 PrintF(": optimized compilation failed]\n"); | 8325 PrintF(": optimized compilation failed]\n"); |
| 8330 } | 8326 } |
| 8331 function->ReplaceCode(function->shared()->code()); | 8327 function->ReplaceCode(function->shared()->code()); |
| 8332 return function->code(); | 8328 return function->code(); |
| 8333 } | 8329 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8408 ASSERT(optimized_code->kind() == Code::OPTIMIZED_FUNCTION); | 8404 ASSERT(optimized_code->kind() == Code::OPTIMIZED_FUNCTION); |
| 8409 ASSERT(type == deoptimizer->bailout_type()); | 8405 ASSERT(type == deoptimizer->bailout_type()); |
| 8410 | 8406 |
| 8411 // Make sure to materialize objects before causing any allocation. | 8407 // Make sure to materialize objects before causing any allocation. |
| 8412 JavaScriptFrameIterator it(isolate); | 8408 JavaScriptFrameIterator it(isolate); |
| 8413 deoptimizer->MaterializeHeapObjects(&it); | 8409 deoptimizer->MaterializeHeapObjects(&it); |
| 8414 delete deoptimizer; | 8410 delete deoptimizer; |
| 8415 | 8411 |
| 8416 JavaScriptFrame* frame = it.frame(); | 8412 JavaScriptFrame* frame = it.frame(); |
| 8417 RUNTIME_ASSERT(frame->function()->IsJSFunction()); | 8413 RUNTIME_ASSERT(frame->function()->IsJSFunction()); |
| 8414 ASSERT(frame->function() == *function); |
| 8418 | 8415 |
| 8419 // Avoid doing too much work when running with --always-opt and keep | 8416 // Avoid doing too much work when running with --always-opt and keep |
| 8420 // the optimized code around. | 8417 // the optimized code around. |
| 8421 if (FLAG_always_opt || type == Deoptimizer::LAZY) { | 8418 if (FLAG_always_opt || type == Deoptimizer::LAZY) { |
| 8422 return isolate->heap()->undefined_value(); | 8419 return isolate->heap()->undefined_value(); |
| 8423 } | 8420 } |
| 8424 | 8421 |
| 8425 // Search for other activations of the same function and code. | 8422 // Search for other activations of the same function and code. |
| 8426 ActivationsFinder activations_finder(*optimized_code); | 8423 ActivationsFinder activations_finder(*optimized_code); |
| 8427 activations_finder.VisitFrames(&it); | 8424 activations_finder.VisitFrames(&it); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8585 | 8582 |
| 8586 | 8583 |
| 8587 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileForOnStackReplacement) { | 8584 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileForOnStackReplacement) { |
| 8588 HandleScope scope(isolate); | 8585 HandleScope scope(isolate); |
| 8589 ASSERT(args.length() == 1); | 8586 ASSERT(args.length() == 1); |
| 8590 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8587 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 8591 | 8588 |
| 8592 // We're not prepared to handle a function with arguments object. | 8589 // We're not prepared to handle a function with arguments object. |
| 8593 ASSERT(!function->shared()->uses_arguments()); | 8590 ASSERT(!function->shared()->uses_arguments()); |
| 8594 | 8591 |
| 8595 // If the optimization attempt succeeded, return the AST id tagged as a | 8592 // If the optimization attempt succeeds, return the code object which |
| 8596 // smi. This tells the builtin that we need to translate the unoptimized | 8593 // the unoptimized code can jump into. |
| 8597 // frame to an optimized one. | 8594 Handle<Code> code = |
| 8598 BailoutId ast_id = | |
| 8599 (FLAG_concurrent_recompilation && FLAG_concurrent_osr) | 8595 (FLAG_concurrent_recompilation && FLAG_concurrent_osr) |
| 8600 ? Compiler::CompileForConcurrentOSR(function) | 8596 ? Compiler::CompileForConcurrentOSR(function) |
| 8601 : Compiler::CompileForOnStackReplacement(function); | 8597 : Compiler::CompileForOnStackReplacement(function); |
| 8602 if (!ast_id.IsNone()) { | 8598 if (!code.is_null()) { |
| 8603 ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION); | 8599 #if DEBUG |
| 8604 return Smi::FromInt(ast_id.ToInt()); | 8600 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 8601 DeoptimizationInputData* data = |
| 8602 DeoptimizationInputData::cast(code->deoptimization_data()); |
| 8603 ASSERT(!BailoutId(data->OsrAstId()->value()).IsNone()); |
| 8604 #endif |
| 8605 // TODO(titzer): this is a massive hack to make the deopt counts |
| 8606 // match. Fix heuristics for reenabling optimizations! |
| 8607 function->shared()->increment_deopt_count(); |
| 8608 return *code; |
| 8605 } else { | 8609 } else { |
| 8606 if (function->IsMarkedForLazyRecompilation() || | 8610 if (function->IsMarkedForLazyRecompilation() || |
| 8607 function->IsMarkedForConcurrentRecompilation()) { | 8611 function->IsMarkedForConcurrentRecompilation()) { |
| 8608 function->ReplaceCode(function->shared()->code()); | 8612 function->ReplaceCode(function->shared()->code()); |
| 8609 } | 8613 } |
| 8610 return Smi::FromInt(-1); | 8614 return NULL; |
| 8611 } | 8615 } |
| 8612 } | 8616 } |
| 8613 | 8617 |
| 8614 | 8618 |
| 8615 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) { | 8619 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) { |
| 8616 SealHandleScope shs(isolate); | 8620 SealHandleScope shs(isolate); |
| 8617 ASSERT(args.length() == 2); | 8621 ASSERT(args.length() == 2); |
| 8618 #ifdef DEBUG | 8622 #ifdef DEBUG |
| 8619 CONVERT_SMI_ARG_CHECKED(interval, 0); | 8623 CONVERT_SMI_ARG_CHECKED(interval, 0); |
| 8620 CONVERT_SMI_ARG_CHECKED(timeout, 1); | 8624 CONVERT_SMI_ARG_CHECKED(timeout, 1); |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9404 | 9408 |
| 9405 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) { | 9409 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) { |
| 9406 HandleScope scope(isolate); | 9410 HandleScope scope(isolate); |
| 9407 ASSERT(args.length() == 2); | 9411 ASSERT(args.length() == 2); |
| 9408 | 9412 |
| 9409 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); | 9413 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); |
| 9410 FlattenString(str); | 9414 FlattenString(str); |
| 9411 | 9415 |
| 9412 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); | 9416 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); |
| 9413 | 9417 |
| 9414 MaybeObject* maybe_result_array = | 9418 JSObject::EnsureCanContainHeapObjectElements(output); |
| 9415 output->EnsureCanContainHeapObjectElements(); | |
| 9416 if (maybe_result_array->IsFailure()) return maybe_result_array; | |
| 9417 RUNTIME_ASSERT(output->HasFastObjectElements()); | 9419 RUNTIME_ASSERT(output->HasFastObjectElements()); |
| 9418 | 9420 |
| 9419 DisallowHeapAllocation no_gc; | 9421 DisallowHeapAllocation no_gc; |
| 9420 | 9422 |
| 9421 FixedArray* output_array = FixedArray::cast(output->elements()); | 9423 FixedArray* output_array = FixedArray::cast(output->elements()); |
| 9422 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); | 9424 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); |
| 9423 bool result; | 9425 bool result; |
| 9424 String::FlatContent str_content = str->GetFlatContent(); | 9426 String::FlatContent str_content = str->GetFlatContent(); |
| 9425 if (str_content.IsAscii()) { | 9427 if (str_content.IsAscii()) { |
| 9426 result = DateParser::Parse(str_content.ToOneByteVector(), | 9428 result = DateParser::Parse(str_content.ToOneByteVector(), |
| (...skipping 5247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14674 // Handle last resort GC and make sure to allow future allocations | 14676 // Handle last resort GC and make sure to allow future allocations |
| 14675 // to grow the heap without causing GCs (if possible). | 14677 // to grow the heap without causing GCs (if possible). |
| 14676 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14678 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14677 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14679 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14678 "Runtime::PerformGC"); | 14680 "Runtime::PerformGC"); |
| 14679 } | 14681 } |
| 14680 } | 14682 } |
| 14681 | 14683 |
| 14682 | 14684 |
| 14683 } } // namespace v8::internal | 14685 } } // namespace v8::internal |
| OLD | NEW |