Index: src/x64/code-stubs-x64.cc |
diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc |
index 1a6efcbd61acc781addb3f175e7c5e7f6cd1dd6b..26dd38d4c520c72822ebe4e90b4a7bbfaaf46dd3 100644 |
--- a/src/x64/code-stubs-x64.cc |
+++ b/src/x64/code-stubs-x64.cc |
@@ -2303,7 +2303,6 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
__ testq(kScratchRegister, kScratchRegister); |
__ j(zero, &runtime); |
- |
// Check that the first argument is a JSRegExp object. |
__ movq(rax, Operand(rsp, kJSRegExpOffset)); |
__ JumpIfSmi(rax, &runtime); |
@@ -2386,28 +2385,42 @@ void RegExpExecStub::Generate(MacroAssembler* masm) { |
STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
__ j(zero, &seq_two_byte_string, Label::kNear); |
// Any other flat string must be a flat ascii string. |
- __ testb(rbx, Immediate(kIsNotStringMask | kStringRepresentationMask)); |
+ __ andb(rbx, Immediate(kIsNotStringMask | kStringRepresentationMask)); |
__ j(zero, &seq_ascii_string, Label::kNear); |
- // Check for flat cons string. |
+ // Check for flat cons string or truncated sliced string. |
// A flat cons string is a cons string where the second part is the empty |
// string. In that case the subject string is just the first part of the cons |
// string. Also in this case the first part of the cons string is known to be |
// a sequential string or an external string. |
- STATIC_ASSERT(kExternalStringTag !=0); |
- STATIC_ASSERT((kConsStringTag & kExternalStringTag) == 0); |
- __ testb(rbx, Immediate(kIsNotStringMask | kExternalStringTag)); |
- __ j(not_zero, &runtime); |
- // String is a cons string. |
+ // A truncated sliced string has the offset 0 and the same length as the |
+ // parent string. |
+ Label cons_string, encoding; |
+ __ cmpq(rbx, Immediate(kConsStringTag)); |
+ __ j(equal, &cons_string, Label::kNear); |
+ __ cmpq(rbx, Immediate(kSlicedStringTag)); |
+ // If subject is not a sliced string, it can only be a non-string or an |
+ // external string. |
+ __ j(not_equal, &runtime); |
+ // String is sliced, check whether it is truncated. |
+ __ movq(rbx, FieldOperand(rdi, SlicedString::kLengthOffset)); |
+ __ movq(rdi, FieldOperand(rdi, SlicedString::kParentOffset)); |
+ // rbx: length of sliced string. |
+ // rdi: parent string. |
+ __ cmpq(rbx, FieldOperand(rdi, SlicedString::kLengthOffset)); |
+ __ j(not_equal, &runtime); |
+ __ jmp(&encoding, Label::kNear); |
+ // String is a cons string, check whether it is flat. |
+ __ bind(&cons_string); |
__ CompareRoot(FieldOperand(rdi, ConsString::kSecondOffset), |
Heap::kEmptyStringRootIndex); |
__ j(not_equal, &runtime); |
__ movq(rdi, FieldOperand(rdi, ConsString::kFirstOffset)); |
+ // rdi: first part of cons string or parent of sliced string. |
+ // rbx: map of first part of cons string or map of parent of sliced string. |
+ // Is first part of cons or parent of slice a flat two byte string? |
+ __ bind(&encoding); |
__ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset)); |
- // String is a cons string with empty second part. |
- // rdi: first part of cons string. |
- // rbx: map of first part of cons string. |
- // Is first part a flat two byte string? |
__ testb(FieldOperand(rbx, Map::kInstanceTypeOffset), |
Immediate(kStringRepresentationMask | kStringEncodingMask)); |
STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
@@ -3780,6 +3793,7 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
Label flat_string; |
Label ascii_string; |
Label got_char_code; |
+ Label sliced_string; |
// If the receiver is a smi trigger the non-string case. |
__ JumpIfSmi(object_, receiver_not_string_); |
@@ -3808,8 +3822,11 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
__ j(zero, &flat_string); |
// Handle non-flat strings. |
- __ testb(result_, Immediate(kIsConsStringMask)); |
- __ j(zero, &call_runtime_); |
+ __ and_(result_, Immediate(kStringRepresentationMask)); |
+ __ cmpb(result_, Immediate(kSlicedStringTag)); |
+ __ j(equal, &sliced_string); |
+ __ cmpb(result_, Immediate(kExternalStringTag)); |
+ __ j(equal, &call_runtime_); |
// ConsString. |
// Check whether the right hand side is the empty string (i.e. if |
@@ -3827,6 +3844,14 @@ void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
STATIC_ASSERT(kSeqStringTag == 0); |
__ testb(result_, Immediate(kStringRepresentationMask)); |
__ j(not_zero, &call_runtime_); |
+ __ jmp(&flat_string); |
+ |
+ // SlicedString, unpack and add offset. |
+ __ bind(&sliced_string); |
+ __ addq(scratch_, FieldOperand(object_, SlicedString::kOffsetOffset)); |
+ __ movq(object_, FieldOperand(object_, SlicedString::kParentOffset)); |
+ __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
+ __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
// Check for 1-byte or 2-byte string. |
__ bind(&flat_string); |
@@ -4137,6 +4162,8 @@ void StringAddStub::Generate(MacroAssembler* masm) { |
__ and_(rcx, Immediate(kStringRepresentationMask)); |
__ cmpl(rcx, Immediate(kExternalStringTag)); |
__ j(equal, &string_add_runtime); |
+ // We cannot encounter sliced strings here since: |
+ STATIC_ASSERT(SlicedString::kMinLength >= String::kMinNonFlatLength); |
// Now check if both strings are ascii strings. |
// rax: first string |
// rbx: length of resulting flat string |
@@ -4529,6 +4556,9 @@ void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
void SubStringStub::Generate(MacroAssembler* masm) { |
Label runtime; |
+ if (FLAG_string_slices) { |
+ __ jmp(&runtime); |
+ } |
// Stack frame on entry. |
// rsp[0]: return address |
// rsp[8]: to |