From a0755834791dafd95b728393d65ab8fd1e0617a2 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 14 Jun 2012 17:06:16 +0000 Subject: [PATCH] Unbreak interpreted regexp. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10535164 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11825 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/regexp-macro-assembler-arm.h | 9 +------ src/ia32/regexp-macro-assembler-ia32.h | 9 +------ src/jsregexp.cc | 37 +++++++++++--------------- src/jsregexp.h | 18 +++++-------- src/mips/regexp-macro-assembler-mips.h | 8 +----- src/regexp-macro-assembler-irregexp.cc | 6 +++-- src/regexp-macro-assembler-irregexp.h | 2 +- src/runtime.cc | 36 +++++++++---------------- test/cctest/test-regexp.cc | 3 ++- 9 files changed, 43 insertions(+), 85 deletions(-) diff --git a/src/arm/regexp-macro-assembler-arm.h b/src/arm/regexp-macro-assembler-arm.h index 9bebb4d406..f723fa212f 100644 --- a/src/arm/regexp-macro-assembler-arm.h +++ b/src/arm/regexp-macro-assembler-arm.h @@ -35,14 +35,7 @@ namespace v8 { namespace internal { -#ifdef V8_INTERPRETED_REGEXP -class RegExpMacroAssemblerARM: public RegExpMacroAssembler { - public: - RegExpMacroAssemblerARM(); - virtual ~RegExpMacroAssemblerARM(); -}; - -#else // V8_INTERPRETED_REGEXP +#ifndef V8_INTERPRETED_REGEXP class RegExpMacroAssemblerARM: public NativeRegExpMacroAssembler { public: RegExpMacroAssemblerARM(Mode mode, int registers_to_save, Zone* zone); diff --git a/src/ia32/regexp-macro-assembler-ia32.h b/src/ia32/regexp-macro-assembler-ia32.h index 760fadc77d..7aea385863 100644 --- a/src/ia32/regexp-macro-assembler-ia32.h +++ b/src/ia32/regexp-macro-assembler-ia32.h @@ -34,14 +34,7 @@ namespace v8 { namespace internal { -#ifdef V8_INTERPRETED_REGEXP -class RegExpMacroAssemblerIA32: public RegExpMacroAssembler { - public: - RegExpMacroAssemblerIA32() { } - virtual ~RegExpMacroAssemblerIA32() { } -}; - -#else // V8_INTERPRETED_REGEXP +#ifndef V8_INTERPRETED_REGEXP class RegExpMacroAssemblerIA32: public NativeRegExpMacroAssembler { public: RegExpMacroAssemblerIA32(Mode mode, int registers_to_save, Zone* zone); diff --git a/src/jsregexp.cc b/src/jsregexp.cc index cd51db80a4..bf8e00a0fe 100644 --- a/src/jsregexp.cc +++ b/src/jsregexp.cc @@ -231,14 +231,13 @@ Handle RegExpImpl::Compile(Handle re, Handle RegExpImpl::Exec(Handle regexp, Handle subject, int index, - Handle last_match_info, - Zone* zone) { + Handle last_match_info) { switch (regexp->TypeTag()) { case JSRegExp::ATOM: return AtomExec(regexp, subject, index, last_match_info); case JSRegExp::IRREGEXP: { Handle result = - IrregexpExec(regexp, subject, index, last_match_info, zone); + IrregexpExec(regexp, subject, index, last_match_info); ASSERT(!result.is_null() || regexp->GetIsolate()->has_pending_exception()); return result; @@ -345,8 +344,7 @@ Handle RegExpImpl::AtomExec(Handle re, // If compilation fails, an exception is thrown and this function // returns false. bool RegExpImpl::EnsureCompiledIrregexp( - Handle re, Handle sample_subject, bool is_ascii, - Zone* zone) { + Handle re, Handle sample_subject, bool is_ascii) { Object* compiled_code = re->DataAt(JSRegExp::code_index(is_ascii)); #ifdef V8_INTERPRETED_REGEXP if (compiled_code->IsByteArray()) return true; @@ -362,7 +360,7 @@ bool RegExpImpl::EnsureCompiledIrregexp( ASSERT(compiled_code->IsSmi()); return true; } - return CompileIrregexp(re, sample_subject, is_ascii, zone); + return CompileIrregexp(re, sample_subject, is_ascii); } @@ -384,8 +382,7 @@ static bool CreateRegExpErrorObjectAndThrow(Handle re, bool RegExpImpl::CompileIrregexp(Handle re, Handle sample_subject, - bool is_ascii, - Zone* zone) { + bool is_ascii) { // Compile the RegExp. Isolate* isolate = re->GetIsolate(); ZoneScope zone_scope(isolate, DELETE_ON_EXIT); @@ -437,7 +434,7 @@ bool RegExpImpl::CompileIrregexp(Handle re, pattern, sample_subject, is_ascii, - zone); + isolate->zone()); if (result.error_message != NULL) { // Unable to compile regexp. Handle error_message = @@ -502,13 +499,12 @@ void RegExpImpl::IrregexpInitialize(Handle re, int RegExpImpl::IrregexpPrepare(Handle regexp, - Handle subject, - Zone* zone) { + Handle subject) { if (!subject->IsFlat()) FlattenString(subject); // Check the asciiness of the underlying storage. bool is_ascii = subject->IsAsciiRepresentationUnderneath(); - if (!EnsureCompiledIrregexp(regexp, subject, is_ascii, zone)) return -1; + if (!EnsureCompiledIrregexp(regexp, subject, is_ascii)) return -1; #ifdef V8_INTERPRETED_REGEXP // Byte-code regexp needs space allocated for all its registers. @@ -541,8 +537,7 @@ int RegExpImpl::IrregexpExecRaw( Handle regexp, Handle subject, int index, - Vector output, - Zone* zone) { + Vector output) { Isolate* isolate = regexp->GetIsolate(); Handle irregexp(FixedArray::cast(regexp->data()), isolate); @@ -556,7 +551,7 @@ int RegExpImpl::IrregexpExecRaw( #ifndef V8_INTERPRETED_REGEXP ASSERT(output.length() >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); do { - EnsureCompiledIrregexp(regexp, subject, is_ascii, zone); + EnsureCompiledIrregexp(regexp, subject, is_ascii); Handle code(IrregexpNativeCode(*irregexp, is_ascii), isolate); NativeRegExpMacroAssembler::Result res = NativeRegExpMacroAssembler::Match(code, @@ -582,7 +577,7 @@ int RegExpImpl::IrregexpExecRaw( // the, potentially, different subject (the string can switch between // being internal and external, and even between being ASCII and UC16, // but the characters are always the same). - IrregexpPrepare(regexp, subject, zone); + IrregexpPrepare(regexp, subject); is_ascii = subject->IsAsciiRepresentationUnderneath(); } while (true); UNREACHABLE(); @@ -617,8 +612,7 @@ int RegExpImpl::IrregexpExecRaw( Handle RegExpImpl::IrregexpExec(Handle jsregexp, Handle subject, int previous_index, - Handle last_match_info, - Zone* zone) { + Handle last_match_info) { Isolate* isolate = jsregexp->GetIsolate(); ASSERT_EQ(jsregexp->TypeTag(), JSRegExp::IRREGEXP); @@ -632,7 +626,7 @@ Handle RegExpImpl::IrregexpExec(Handle jsregexp, } #endif #endif - int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject, zone); + int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject); if (required_registers < 0) { // Compiling failed with an exception. ASSERT(isolate->has_pending_exception()); @@ -643,8 +637,7 @@ Handle RegExpImpl::IrregexpExec(Handle jsregexp, int res = RegExpImpl::IrregexpExecRaw(jsregexp, subject, previous_index, Vector(registers.vector(), - registers.length()), - zone); + registers.length())); if (res == RE_SUCCESS) { int capture_register_count = (IrregexpNumberOfCaptures(FixedArray::cast(jsregexp->data())) + 1) * 2; @@ -5987,7 +5980,7 @@ RegExpEngine::CompilationResult RegExpEngine::Compile( #else // V8_INTERPRETED_REGEXP // Interpreted regexp implementation. EmbeddedVector codes; - RegExpMacroAssemblerIrregexp macro_assembler(codes); + RegExpMacroAssemblerIrregexp macro_assembler(codes, zone); #endif // V8_INTERPRETED_REGEXP // Inserted here, instead of in Assembler, because it depends on information diff --git a/src/jsregexp.h b/src/jsregexp.h index 782c5b0b20..548179240d 100644 --- a/src/jsregexp.h +++ b/src/jsregexp.h @@ -78,8 +78,7 @@ class RegExpImpl { static Handle Exec(Handle regexp, Handle subject, int index, - Handle lastMatchInfo, - Zone* zone); + Handle lastMatchInfo); // Prepares a JSRegExp object with Irregexp-specific data. static void IrregexpInitialize(Handle re, @@ -108,8 +107,7 @@ class RegExpImpl { // as its "registers" argument. If the regexp cannot be compiled, // an exception is set as pending, and this function returns negative. static int IrregexpPrepare(Handle regexp, - Handle subject, - Zone* zone); + Handle subject); // Calculate the size of offsets vector for the case of global regexp // and the number of matches this vector is able to store. @@ -126,8 +124,7 @@ class RegExpImpl { static int IrregexpExecRaw(Handle regexp, Handle subject, int index, - Vector registers, - Zone* zone); + Vector registers); // Execute an Irregexp bytecode pattern. // On a successful match, the result is a JSArray containing @@ -136,8 +133,7 @@ class RegExpImpl { static Handle IrregexpExec(Handle regexp, Handle subject, int index, - Handle lastMatchInfo, - Zone* zone); + Handle lastMatchInfo); // Array index in the lastMatchInfo array. static const int kLastCaptureCount = 0; @@ -202,11 +198,9 @@ class RegExpImpl { static String* two_byte_cached_string_; static bool CompileIrregexp( - Handle re, Handle sample_subject, bool is_ascii, - Zone* zone); + Handle re, Handle sample_subject, bool is_ascii); static inline bool EnsureCompiledIrregexp( - Handle re, Handle sample_subject, bool is_ascii, - Zone* zone); + Handle re, Handle sample_subject, bool is_ascii); // Set the subject cache. The previous string buffer is not deleted, so the diff --git a/src/mips/regexp-macro-assembler-mips.h b/src/mips/regexp-macro-assembler-mips.h index d3fff0db2b..5446f52439 100644 --- a/src/mips/regexp-macro-assembler-mips.h +++ b/src/mips/regexp-macro-assembler-mips.h @@ -38,13 +38,7 @@ namespace v8 { namespace internal { -#ifdef V8_INTERPRETED_REGEXP -class RegExpMacroAssemblerMIPS: public RegExpMacroAssembler { - public: - RegExpMacroAssemblerMIPS(); - virtual ~RegExpMacroAssemblerMIPS(); -}; -#else // V8_INTERPRETED_REGEXP +#ifndef V8_INTERPRETED_REGEXP class RegExpMacroAssemblerMIPS: public NativeRegExpMacroAssembler { public: RegExpMacroAssemblerMIPS(Mode mode, int registers_to_save, Zone* zone); diff --git a/src/regexp-macro-assembler-irregexp.cc b/src/regexp-macro-assembler-irregexp.cc index d2cd22e9ad..16766cab09 100644 --- a/src/regexp-macro-assembler-irregexp.cc +++ b/src/regexp-macro-assembler-irregexp.cc @@ -38,8 +38,10 @@ namespace internal { #ifdef V8_INTERPRETED_REGEXP -RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector buffer) - : buffer_(buffer), +RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector buffer, + Zone* zone) + : RegExpMacroAssembler(zone), + buffer_(buffer), pc_(0), own_buffer_(false), advance_current_end_(kInvalidPC) { diff --git a/src/regexp-macro-assembler-irregexp.h b/src/regexp-macro-assembler-irregexp.h index 7232342dc5..4bc29809bd 100644 --- a/src/regexp-macro-assembler-irregexp.h +++ b/src/regexp-macro-assembler-irregexp.h @@ -48,7 +48,7 @@ class RegExpMacroAssemblerIrregexp: public RegExpMacroAssembler { // for code generation and assumes its size to be buffer_size. If the buffer // is too small, a fatal error occurs. No deallocation of the buffer is done // upon destruction of the assembler. - explicit RegExpMacroAssemblerIrregexp(Vector); + RegExpMacroAssemblerIrregexp(Vector, Zone* zone); virtual ~RegExpMacroAssemblerIrregexp(); // The byte-code interpreter checks on each push anyway. virtual int stack_limit_slack() { return 1; } diff --git a/src/runtime.cc b/src/runtime.cc index 60c67d07f7..95bc313d22 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1754,8 +1754,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExec) { Handle result = RegExpImpl::Exec(regexp, subject, index, - last_match_info, - isolate->zone()); + last_match_info); if (result.is_null()) return Failure::Exception(); return *result; } @@ -3089,8 +3088,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( Handle match = RegExpImpl::Exec(regexp_handle, subject_handle, 0, - last_match_info_handle, - isolate->zone()); + last_match_info_handle); if (match.is_null()) { return Failure::Exception(); } @@ -3191,8 +3189,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( match = RegExpImpl::Exec(regexp_handle, subject_handle, next, - last_match_info_handle, - isolate->zone()); + last_match_info_handle); if (match.is_null()) { return Failure::Exception(); } @@ -3248,8 +3245,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( Handle match = RegExpImpl::Exec(regexp_handle, subject_handle, 0, - last_match_info_handle, - isolate->zone()); + last_match_info_handle); if (match.is_null()) return Failure::Exception(); if (match->IsNull()) return *subject_handle; @@ -3323,8 +3319,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( match = RegExpImpl::Exec(regexp_handle, subject_handle, next, - last_match_info_handle, - isolate->zone()); + last_match_info_handle); if (match.is_null()) return Failure::Exception(); if (match->IsNull()) break; @@ -3739,8 +3734,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); HandleScope handles; - Handle match = RegExpImpl::Exec(regexp, subject, 0, regexp_info, - isolate->zone()); + Handle match = RegExpImpl::Exec(regexp, subject, 0, regexp_info); if (match.is_null()) { return Failure::Exception(); @@ -3765,8 +3759,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { offsets.Add(start, zone); offsets.Add(end, zone); if (start == end) if (++end > length) break; - match = RegExpImpl::Exec(regexp, subject, end, regexp_info, - isolate->zone()); + match = RegExpImpl::Exec(regexp, subject, end, regexp_info); if (match.is_null()) { return Failure::Exception(); } @@ -3864,8 +3857,7 @@ static int SearchRegExpNoCaptureMultiple( int match_start = -1; int match_end = 0; int pos = 0; - int registers_per_match = RegExpImpl::IrregexpPrepare(regexp, subject, - isolate->zone()); + int registers_per_match = RegExpImpl::IrregexpPrepare(regexp, subject); if (registers_per_match < 0) return RegExpImpl::RE_EXCEPTION; int max_matches; @@ -3880,8 +3872,7 @@ static int SearchRegExpNoCaptureMultiple( int num_matches = RegExpImpl::IrregexpExecRaw(regexp, subject, pos, - register_vector, - isolate->zone()); + register_vector); if (num_matches > 0) { for (int match_index = 0; match_index < num_matches; match_index++) { int32_t* current_match = ®ister_vector[match_index * 2]; @@ -3951,8 +3942,7 @@ static int SearchRegExpMultiple( FixedArrayBuilder* builder) { ASSERT(subject->IsFlat()); - int registers_per_match = RegExpImpl::IrregexpPrepare(regexp, subject, - isolate->zone()); + int registers_per_match = RegExpImpl::IrregexpPrepare(regexp, subject); if (registers_per_match < 0) return RegExpImpl::RE_EXCEPTION; int max_matches; @@ -3965,8 +3955,7 @@ static int SearchRegExpMultiple( int num_matches = RegExpImpl::IrregexpExecRaw(regexp, subject, 0, - register_vector, - isolate->zone()); + register_vector); int capture_count = regexp->CaptureCount(); int subject_length = subject->length(); @@ -4052,8 +4041,7 @@ static int SearchRegExpMultiple( num_matches = RegExpImpl::IrregexpExecRaw(regexp, subject, pos, - register_vector, - isolate->zone()); + register_vector); } while (num_matches > 0); if (num_matches != RegExpImpl::RE_EXCEPTION) { diff --git a/test/cctest/test-regexp.cc b/test/cctest/test-regexp.cc index 325c686063..10c9242a6a 100644 --- a/test/cctest/test-regexp.cc +++ b/test/cctest/test-regexp.cc @@ -1341,7 +1341,8 @@ TEST(MacroAssemblerNativeLotsOfRegisters) { TEST(MacroAssembler) { V8::Initialize(NULL); byte codes[1024]; - RegExpMacroAssemblerIrregexp m(Vector(codes, 1024)); + RegExpMacroAssemblerIrregexp m(Vector(codes, 1024), + Isolate::Current()->zone()); // ^f(o)o. Label fail, fail2, start; uc16 foo_chars[3];