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

Side by Side Diff: src/ia32/code-stubs-ia32.cc

Issue 1901573003: [regexp] do not assume short external strings have a minimum size. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mips port. functional mips64 port not available yet. Created 4 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
« no previous file with comments | « src/arm64/code-stubs-arm64.cc ('k') | src/mips/code-stubs-mips.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_IA32 5 #if V8_TARGET_ARCH_IA32
6 6
7 #include "src/code-stubs.h" 7 #include "src/code-stubs.h"
8 #include "src/api-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); 769 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
770 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); 770 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
771 __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); 771 __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
772 __ j(above, &runtime); 772 __ j(above, &runtime);
773 773
774 // Reset offset for possibly sliced string. 774 // Reset offset for possibly sliced string.
775 __ Move(edi, Immediate(0)); 775 __ Move(edi, Immediate(0));
776 __ mov(eax, Operand(esp, kSubjectOffset)); 776 __ mov(eax, Operand(esp, kSubjectOffset));
777 __ JumpIfSmi(eax, &runtime); 777 __ JumpIfSmi(eax, &runtime);
778 __ mov(edx, eax); // Make a copy of the original subject string. 778 __ mov(edx, eax); // Make a copy of the original subject string.
779 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
780 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
781 779
782 // eax: subject string 780 // eax: subject string
783 // edx: subject string 781 // edx: subject string
784 // ebx: subject string instance type
785 // ecx: RegExp data (FixedArray) 782 // ecx: RegExp data (FixedArray)
786 // Handle subject string according to its encoding and representation: 783 // Handle subject string according to its encoding and representation:
787 // (1) Sequential two byte? If yes, go to (9). 784 // (1) Sequential two byte? If yes, go to (9).
788 // (2) Sequential one byte? If yes, go to (6). 785 // (2) Sequential one byte? If yes, go to (5).
789 // (3) Anything but sequential or cons? If yes, go to (7). 786 // (3) Sequential or cons? If not, go to (6).
790 // (4) Cons string. If the string is flat, replace subject with first string. 787 // (4) Cons string. If the string is flat, replace subject with first string
791 // Otherwise bailout. 788 // and go to (1). Otherwise bail out to runtime.
792 // (5a) Is subject sequential two byte? If yes, go to (9). 789 // (5) One byte sequential. Load regexp code for one byte.
793 // (5b) Is subject external? If yes, go to (8).
794 // (6) One byte sequential. Load regexp code for one byte.
795 // (E) Carry on. 790 // (E) Carry on.
796 /// [...] 791 /// [...]
797 792
798 // Deferred code at the end of the stub: 793 // Deferred code at the end of the stub:
799 // (7) Not a long external string? If yes, go to (10). 794 // (6) Long external string? If not, go to (10).
800 // (8) External string. Make it, offset-wise, look like a sequential string. 795 // (7) External string. Make it, offset-wise, look like a sequential string.
801 // (8a) Is the external string one byte? If yes, go to (6). 796 // (8) Is the external string one byte? If yes, go to (5).
802 // (9) Two byte sequential. Load regexp code for one byte. Go to (E). 797 // (9) Two byte sequential. Load regexp code for two byte. Go to (E).
803 // (10) Short external string or not a string? If yes, bail out to runtime. 798 // (10) Short external string or not a string? If yes, bail out to runtime.
804 // (11) Sliced string. Replace subject with parent. Go to (5a). 799 // (11) Sliced string. Replace subject with parent. Go to (1).
805 800
806 Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, 801 Label seq_one_byte_string /* 5 */, seq_two_byte_string /* 9 */,
807 external_string /* 8 */, check_underlying /* 5a */, 802 external_string /* 7 */, check_underlying /* 1 */,
808 not_seq_nor_cons /* 7 */, check_code /* E */, 803 not_seq_nor_cons /* 6 */, check_code /* E */, not_long_external /* 10 */;
809 not_long_external /* 10 */;
810 804
805 __ bind(&check_underlying);
811 // (1) Sequential two byte? If yes, go to (9). 806 // (1) Sequential two byte? If yes, go to (9).
807 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
808 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
809
812 __ and_(ebx, kIsNotStringMask | 810 __ and_(ebx, kIsNotStringMask |
813 kStringRepresentationMask | 811 kStringRepresentationMask |
814 kStringEncodingMask | 812 kStringEncodingMask |
815 kShortExternalStringMask); 813 kShortExternalStringMask);
816 STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); 814 STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
817 __ j(zero, &seq_two_byte_string); // Go to (9). 815 __ j(zero, &seq_two_byte_string); // Go to (9).
818 816
819 // (2) Sequential one byte? If yes, go to (6). 817 // (2) Sequential one byte? If yes, go to (5).
820 // Any other sequential string must be one byte. 818 // Any other sequential string must be one byte.
821 __ and_(ebx, Immediate(kIsNotStringMask | 819 __ and_(ebx, Immediate(kIsNotStringMask |
822 kStringRepresentationMask | 820 kStringRepresentationMask |
823 kShortExternalStringMask)); 821 kShortExternalStringMask));
824 __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). 822 __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (5).
825 823
826 // (3) Anything but sequential or cons? If yes, go to (7). 824 // (3) Sequential or cons? If not, go to (6).
827 // We check whether the subject string is a cons, since sequential strings 825 // We check whether the subject string is a cons, since sequential strings
828 // have already been covered. 826 // have already been covered.
829 STATIC_ASSERT(kConsStringTag < kExternalStringTag); 827 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
830 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); 828 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
831 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); 829 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
832 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); 830 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
833 __ cmp(ebx, Immediate(kExternalStringTag)); 831 __ cmp(ebx, Immediate(kExternalStringTag));
834 __ j(greater_equal, &not_seq_nor_cons); // Go to (7). 832 __ j(greater_equal, &not_seq_nor_cons); // Go to (6).
835 833
836 // (4) Cons string. Check that it's flat. 834 // (4) Cons string. Check that it's flat.
837 // Replace subject with first string and reload instance type. 835 // Replace subject with first string and reload instance type.
838 __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); 836 __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string());
839 __ j(not_equal, &runtime); 837 __ j(not_equal, &runtime);
840 __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); 838 __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset));
841 __ bind(&check_underlying); 839 __ jmp(&check_underlying);
842 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
843 __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
844
845 // (5a) Is subject sequential two byte? If yes, go to (9).
846 __ test_b(ebx, Immediate(kStringRepresentationMask | kStringEncodingMask));
847 STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0);
848 __ j(zero, &seq_two_byte_string); // Go to (9).
849 // (5b) Is subject external? If yes, go to (8).
850 __ test_b(ebx, Immediate(kStringRepresentationMask));
851 // The underlying external string is never a short external string.
852 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
853 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
854 __ j(not_zero, &external_string); // Go to (8).
855 840
856 // eax: sequential subject string (or look-alike, external string) 841 // eax: sequential subject string (or look-alike, external string)
857 // edx: original subject string 842 // edx: original subject string
858 // ecx: RegExp data (FixedArray) 843 // ecx: RegExp data (FixedArray)
859 // (6) One byte sequential. Load regexp code for one byte. 844 // (5) One byte sequential. Load regexp code for one byte.
860 __ bind(&seq_one_byte_string); 845 __ bind(&seq_one_byte_string);
861 // Load previous index and check range before edx is overwritten. We have 846 // Load previous index and check range before edx is overwritten. We have
862 // to use edx instead of eax here because it might have been only made to 847 // to use edx instead of eax here because it might have been only made to
863 // look like a sequential string when it actually is an external string. 848 // look like a sequential string when it actually is an external string.
864 __ mov(ebx, Operand(esp, kPreviousIndexOffset)); 849 __ mov(ebx, Operand(esp, kPreviousIndexOffset));
865 __ JumpIfNotSmi(ebx, &runtime); 850 __ JumpIfNotSmi(ebx, &runtime);
866 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); 851 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset));
867 __ j(above_equal, &runtime); 852 __ j(above_equal, &runtime);
868 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataOneByteCodeOffset)); 853 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataOneByteCodeOffset));
869 __ Move(ecx, Immediate(1)); // Type is one byte. 854 __ Move(ecx, Immediate(1)); // Type is one byte.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 1061
1077 // Return last match info. 1062 // Return last match info.
1078 __ mov(eax, Operand(esp, kLastMatchInfoOffset)); 1063 __ mov(eax, Operand(esp, kLastMatchInfoOffset));
1079 __ ret(4 * kPointerSize); 1064 __ ret(4 * kPointerSize);
1080 1065
1081 // Do the runtime call to execute the regexp. 1066 // Do the runtime call to execute the regexp.
1082 __ bind(&runtime); 1067 __ bind(&runtime);
1083 __ TailCallRuntime(Runtime::kRegExpExec); 1068 __ TailCallRuntime(Runtime::kRegExpExec);
1084 1069
1085 // Deferred code for string handling. 1070 // Deferred code for string handling.
1086 // (7) Not a long external string? If yes, go to (10). 1071 // (6) Long external string? If not, go to (10).
1087 __ bind(&not_seq_nor_cons); 1072 __ bind(&not_seq_nor_cons);
1088 // Compare flags are still set from (3). 1073 // Compare flags are still set from (3).
1089 __ j(greater, &not_long_external, Label::kNear); // Go to (10). 1074 __ j(greater, &not_long_external, Label::kNear); // Go to (10).
1090 1075
1091 // (8) External string. Short external strings have been ruled out. 1076 // (7) External string. Short external strings have been ruled out.
1092 __ bind(&external_string); 1077 __ bind(&external_string);
1093 // Reload instance type. 1078 // Reload instance type.
1094 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); 1079 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
1095 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); 1080 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
1096 if (FLAG_debug_code) { 1081 if (FLAG_debug_code) {
1097 // Assert that we do not have a cons or slice (indirect strings) here. 1082 // Assert that we do not have a cons or slice (indirect strings) here.
1098 // Sequential strings have already been ruled out. 1083 // Sequential strings have already been ruled out.
1099 __ test_b(ebx, Immediate(kIsIndirectStringMask)); 1084 __ test_b(ebx, Immediate(kIsIndirectStringMask));
1100 __ Assert(zero, kExternalStringExpectedButNotFound); 1085 __ Assert(zero, kExternalStringExpectedButNotFound);
1101 } 1086 }
1102 __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); 1087 __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset));
1103 // Move the pointer so that offset-wise, it looks like a sequential string. 1088 // Move the pointer so that offset-wise, it looks like a sequential string.
1104 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); 1089 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
1105 __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); 1090 __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
1106 STATIC_ASSERT(kTwoByteStringTag == 0); 1091 STATIC_ASSERT(kTwoByteStringTag == 0);
1107 // (8a) Is the external string one byte? If yes, go to (6). 1092 // (8) Is the external string one byte? If yes, go to (5).
1108 __ test_b(ebx, Immediate(kStringEncodingMask)); 1093 __ test_b(ebx, Immediate(kStringEncodingMask));
1109 __ j(not_zero, &seq_one_byte_string); // Goto (6). 1094 __ j(not_zero, &seq_one_byte_string); // Go to (5).
1110 1095
1111 // eax: sequential subject string (or look-alike, external string) 1096 // eax: sequential subject string (or look-alike, external string)
1112 // edx: original subject string 1097 // edx: original subject string
1113 // ecx: RegExp data (FixedArray) 1098 // ecx: RegExp data (FixedArray)
1114 // (9) Two byte sequential. Load regexp code for one byte. Go to (E). 1099 // (9) Two byte sequential. Load regexp code for two byte. Go to (E).
1115 __ bind(&seq_two_byte_string); 1100 __ bind(&seq_two_byte_string);
1116 // Load previous index and check range before edx is overwritten. We have 1101 // Load previous index and check range before edx is overwritten. We have
1117 // to use edx instead of eax here because it might have been only made to 1102 // to use edx instead of eax here because it might have been only made to
1118 // look like a sequential string when it actually is an external string. 1103 // look like a sequential string when it actually is an external string.
1119 __ mov(ebx, Operand(esp, kPreviousIndexOffset)); 1104 __ mov(ebx, Operand(esp, kPreviousIndexOffset));
1120 __ JumpIfNotSmi(ebx, &runtime); 1105 __ JumpIfNotSmi(ebx, &runtime);
1121 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); 1106 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset));
1122 __ j(above_equal, &runtime); 1107 __ j(above_equal, &runtime);
1123 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); 1108 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset));
1124 __ Move(ecx, Immediate(0)); // Type is two byte. 1109 __ Move(ecx, Immediate(0)); // Type is two byte.
1125 __ jmp(&check_code); // Go to (E). 1110 __ jmp(&check_code); // Go to (E).
1126 1111
1127 // (10) Not a string or a short external string? If yes, bail out to runtime. 1112 // (10) Not a string or a short external string? If yes, bail out to runtime.
1128 __ bind(&not_long_external); 1113 __ bind(&not_long_external);
1129 // Catch non-string subject or short external string. 1114 // Catch non-string subject or short external string.
1130 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); 1115 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
1131 __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); 1116 __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag));
1132 __ j(not_zero, &runtime); 1117 __ j(not_zero, &runtime);
1133 1118
1134 // (11) Sliced string. Replace subject with parent. Go to (5a). 1119 // (11) Sliced string. Replace subject with parent. Go to (1).
1135 // Load offset into edi and replace subject string with parent. 1120 // Load offset into edi and replace subject string with parent.
1136 __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); 1121 __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset));
1137 __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); 1122 __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset));
1138 __ jmp(&check_underlying); // Go to (5a). 1123 __ jmp(&check_underlying); // Go to (1).
1139 #endif // V8_INTERPRETED_REGEXP 1124 #endif // V8_INTERPRETED_REGEXP
1140 } 1125 }
1141 1126
1142 1127
1143 static int NegativeComparisonResult(Condition cc) { 1128 static int NegativeComparisonResult(Condition cc) {
1144 DCHECK(cc != equal); 1129 DCHECK(cc != equal);
1145 DCHECK((cc == less) || (cc == less_equal) 1130 DCHECK((cc == less) || (cc == less_equal)
1146 || (cc == greater) || (cc == greater_equal)); 1131 || (cc == greater) || (cc == greater_equal));
1147 return (cc == greater || cc == greater_equal) ? LESS : GREATER; 1132 return (cc == greater || cc == greater_equal) ? LESS : GREATER;
1148 } 1133 }
(...skipping 4712 matching lines...) Expand 10 before | Expand all | Expand 10 after
5861 kStackUnwindSpace, nullptr, return_value_operand, 5846 kStackUnwindSpace, nullptr, return_value_operand,
5862 NULL); 5847 NULL);
5863 } 5848 }
5864 5849
5865 #undef __ 5850 #undef __
5866 5851
5867 } // namespace internal 5852 } // namespace internal
5868 } // namespace v8 5853 } // namespace v8
5869 5854
5870 #endif // V8_TARGET_ARCH_IA32 5855 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/arm64/code-stubs-arm64.cc ('k') | src/mips/code-stubs-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698