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

Side by Side Diff: src/regexp-macro-assembler.cc

Issue 1034173002: Always update raw pointers when handling interrupts inside RegExp code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/assembler.h" 7 #include "src/assembler.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/regexp-macro-assembler.h" 9 #include "src/regexp-macro-assembler.h"
10 #include "src/regexp-stack.h" 10 #include "src/regexp-stack.h"
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 37
38 bool NativeRegExpMacroAssembler::CanReadUnaligned() { 38 bool NativeRegExpMacroAssembler::CanReadUnaligned() {
39 return FLAG_enable_unaligned_accesses && !slow_safe(); 39 return FLAG_enable_unaligned_accesses && !slow_safe();
40 } 40 }
41 41
42 const byte* NativeRegExpMacroAssembler::StringCharacterPosition( 42 const byte* NativeRegExpMacroAssembler::StringCharacterPosition(
43 String* subject, 43 String* subject,
44 int start_index) { 44 int start_index) {
45 // Not just flat, but ultra flat. 45 if (subject->IsConsString()) {
46 DCHECK(subject->IsExternalString() || subject->IsSeqString()); 46 subject = ConsString::cast(subject)->first();
47 } else if (subject->IsSlicedString()) {
48 start_index += SlicedString::cast(subject)->offset();
49 subject = SlicedString::cast(subject)->parent();
50 }
47 DCHECK(start_index >= 0); 51 DCHECK(start_index >= 0);
48 DCHECK(start_index <= subject->length()); 52 DCHECK(start_index <= subject->length());
49 if (subject->IsOneByteRepresentation()) { 53 if (subject->IsSeqOneByteString()) {
50 const byte* address; 54 return reinterpret_cast<const byte*>(
51 if (StringShape(subject).IsExternal()) { 55 SeqOneByteString::cast(subject)->GetChars() + start_index);
52 const uint8_t* data = ExternalOneByteString::cast(subject)->GetChars(); 56 } else if (subject->IsSeqTwoByteString()) {
53 address = reinterpret_cast<const byte*>(data); 57 return reinterpret_cast<const byte*>(
54 } else { 58 SeqTwoByteString::cast(subject)->GetChars() + start_index);
55 DCHECK(subject->IsSeqOneByteString()); 59 } else if (subject->IsExternalOneByteString()) {
56 const uint8_t* data = SeqOneByteString::cast(subject)->GetChars(); 60 return reinterpret_cast<const byte*>(
57 address = reinterpret_cast<const byte*>(data); 61 ExternalOneByteString::cast(subject)->GetChars() + start_index);
58 } 62 } else {
59 return address + start_index; 63 return reinterpret_cast<const byte*>(
64 ExternalTwoByteString::cast(subject)->GetChars() + start_index);
60 } 65 }
61 const uc16* data;
62 if (StringShape(subject).IsExternal()) {
63 data = ExternalTwoByteString::cast(subject)->GetChars();
64 } else {
65 DCHECK(subject->IsSeqTwoByteString());
66 data = SeqTwoByteString::cast(subject)->GetChars();
67 }
68 return reinterpret_cast<const byte*>(data + start_index);
69 } 66 }
70 67
71 68
69 int NativeRegExpMacroAssembler::CheckStackGuardState(
70 Isolate* isolate, int start_index, bool is_direct_call,
71 Address* return_address, Code* re_code, String** subject,
72 const byte** input_start, const byte** input_end) {
73 DCHECK(re_code->instruction_start() <= *return_address);
74 DCHECK(*return_address <= re_code->instruction_end());
75 int return_value = 0;
76 // Prepare for possible GC.
77 HandleScope handles(isolate);
78 Handle<Code> code_handle(re_code);
79 Handle<String> subject_handle(*subject);
80 bool is_one_byte = subject_handle->IsOneByteRepresentationUnderneath();
81
82 StackLimitCheck check(isolate);
83 if (check.JsHasOverflowed()) {
84 isolate->StackOverflow();
85 return_value = EXCEPTION;
86 } else if (is_direct_call) {
87 // If not real stack overflow the stack guard was used to interrupt
88 // execution for another purpose. If this is a direct call from JavaScript
89 // retry the RegExp forcing the call through the runtime system.
90 // Currently the direct call cannot handle a GC.
91 return_value = RETRY;
92 } else {
93 Object* result = isolate->stack_guard()->HandleInterrupts();
94 if (!result->IsUndefined()) return_value = EXCEPTION;
95 }
96
97 DisallowHeapAllocation no_gc;
98
99 if (*code_handle != re_code) { // Return address no longer valid
100 int delta = code_handle->address() - re_code->address();
101 // Overwrite the return address on the stack.
102 *return_address += delta;
103 }
104
105 // String encoding might have changed.
106 if (subject_handle->IsOneByteRepresentationUnderneath() != is_one_byte) {
107 // If we changed between an LATIN1 and an UC16 string, the specialized
108 // code cannot be used, and we need to restart regexp matching from
109 // scratch (including, potentially, compiling a new version of the code).
110 return_value = RETRY;
111 }
112
113 *subject = *subject_handle;
114 intptr_t byte_length = *input_end - *input_start;
115 *input_start = StringCharacterPosition(*subject, start_index);
116 *input_end = *input_start + byte_length;
117 return return_value;
118 }
119
120
72 NativeRegExpMacroAssembler::Result NativeRegExpMacroAssembler::Match( 121 NativeRegExpMacroAssembler::Result NativeRegExpMacroAssembler::Match(
73 Handle<Code> regexp_code, 122 Handle<Code> regexp_code,
74 Handle<String> subject, 123 Handle<String> subject,
75 int* offsets_vector, 124 int* offsets_vector,
76 int offsets_vector_length, 125 int offsets_vector_length,
77 int previous_index, 126 int previous_index,
78 Isolate* isolate) { 127 Isolate* isolate) {
79 128
80 DCHECK(subject->IsFlat()); 129 DCHECK(subject->IsFlat());
81 DCHECK(previous_index >= 0); 130 DCHECK(previous_index >= 0);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return NULL; 298 return NULL;
250 } 299 }
251 *stack_base = new_stack_base; 300 *stack_base = new_stack_base;
252 intptr_t stack_content_size = old_stack_base - stack_pointer; 301 intptr_t stack_content_size = old_stack_base - stack_pointer;
253 return new_stack_base - stack_content_size; 302 return new_stack_base - stack_content_size;
254 } 303 }
255 304
256 #endif // V8_INTERPRETED_REGEXP 305 #endif // V8_INTERPRETED_REGEXP
257 306
258 } } // namespace v8::internal 307 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698