1
From: Mike Hommey <mh@glandium.org>
2
Date: Sat, 24 Dec 2011 09:56:58 +0100
3
Subject: Bug 691898 - Use YARR interpreter instead of PCRE on platforms where
4
YARR JIT is not supported
7
js/src/Makefile.in | 21 +++++++++++++--------
8
js/src/vm/RegExpObject-inl.h | 28 ++++++----------------------
9
js/src/vm/RegExpObject.cpp | 36 ------------------------------------
10
js/src/vm/RegExpObject.h | 27 ++++++---------------------
11
js/src/yarr/wtfbridge.h | 2 --
12
5 files changed, 25 insertions(+), 89 deletions(-)
14
diff --git a/js/src/Makefile.in b/js/src/Makefile.in
15
index fc48cbd..49f0bdc 100644
16
--- a/js/src/Makefile.in
17
+++ b/js/src/Makefile.in
18
@@ -416,15 +416,20 @@ CPPSRCS += checks.cc \
20
ifeq (,$(filter arm% sparc %86 x86_64,$(TARGET_CPU)))
22
-VPATH += $(srcdir)/yarr/pcre \
23
+VPATH += $(srcdir)/assembler \
24
+ $(srcdir)/assembler/wtf \
33
- pcre_ucp_searchfuncs.cpp \
35
+ OSAllocatorOS2.cpp \
36
+ OSAllocatorPosix.cpp \
37
+ OSAllocatorWin.cpp \
39
+ YarrInterpreter.cpp \
41
+ YarrSyntaxChecker.cpp \
45
@@ -1015,10 +1020,10 @@ endif
46
# Needed to "configure" it correctly. Unfortunately these
47
# flags wind up being applied to all code in js/src, not just
48
# the code in js/src/assembler.
49
-CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 -DENABLE_ASSEMBLER=1
50
+CXXFLAGS += -DUSE_SYSTEM_MALLOC=1
52
ifneq (,$(ENABLE_YARR_JIT)$(ENABLE_TRACEJIT)$(ENABLE_METHODJIT))
53
-CXXFLAGS += -DENABLE_JIT=1
54
+CXXFLAGS += -DENABLE_JIT=1 -DENABLE_ASSEMBLER=1
57
INCLUDES += -I$(srcdir)/assembler -I$(srcdir)/yarr
58
diff --git a/js/src/vm/RegExpObject-inl.h b/js/src/vm/RegExpObject-inl.h
59
index 5f7817d..91108a7 100644
60
--- a/js/src/vm/RegExpObject-inl.h
61
+++ b/js/src/vm/RegExpObject-inl.h
62
@@ -327,6 +327,7 @@ RegExpPrivate::create(JSContext *cx, JSString *source, RegExpFlag flags, TokenSt
67
/* This function should be deleted once bad Android platforms phase out. See bug 604774. */
69
RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx)
70
@@ -337,12 +338,12 @@ RegExpPrivateCode::isJITRuntimeEnabled(JSContext *cx)
77
RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts,
78
uintN *parenCount, RegExpFlag flags)
81
/* Parse the pattern. */
83
YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag),
84
@@ -359,7 +360,7 @@ RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *
85
* case we have to bytecode compile it.
89
+#if ENABLE_YARR_JIT && defined(JS_METHODJIT)
90
if (isJITRuntimeEnabled(cx) && !yarrPattern.m_containsBackreferences) {
91
if (!cx->compartment->ensureJaegerCompartmentExists(cx))
93
@@ -371,21 +372,11 @@ RegExpPrivateCode::compile(JSContext *cx, JSLinearString &pattern, TokenStream *
98
codeBlock.setFallBack(true);
100
byteCode = byteCompile(yarrPattern, cx->compartment->regExpAllocator).get();
102
-#else /* !defined(ENABLE_YARR_JIT) */
104
- compiled = jsRegExpCompile(pattern.chars(), pattern.length(),
105
- ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase,
106
- multiline() ? JSRegExpMultiline : JSRegExpSingleLine,
107
- parenCount, &error);
109
- reportPCREError(cx, error);
117
@@ -431,19 +422,12 @@ RegExpPrivateCode::execute(JSContext *cx, const jschar *chars, size_t start, siz
119
result = JSC::Yarr::execute(codeBlock, chars, start, length, output);
121
- result = jsRegExpExecute(cx, compiled, chars, length, start, output, outputCount);
122
+ result = JSC::Yarr::interpret(byteCode, chars, start, length, output);
126
return Success_NotFound;
128
-#if !ENABLE_YARR_JIT
130
- reportPCREError(cx, result);
135
JS_ASSERT(result >= 0);
138
diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp
139
index f75c6a5..7631dd5 100644
140
--- a/js/src/vm/RegExpObject.cpp
141
+++ b/js/src/vm/RegExpObject.cpp
142
@@ -251,7 +251,6 @@ Class js::RegExpClass = {
148
RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error)
150
@@ -283,41 +282,6 @@ RegExpPrivateCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode err
154
-#else /* !ENABLE_YARR_JIT */
157
-RegExpPrivateCode::reportPCREError(JSContext *cx, int error)
159
-#define REPORT(msg_) \
160
- JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, msg_); \
163
- case -2: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
164
- case 0: JS_NOT_REACHED("Precondition violation: an error must have occurred.");
165
- case 1: REPORT(JSMSG_TRAILING_SLASH);
166
- case 2: REPORT(JSMSG_TRAILING_SLASH);
167
- case 3: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
168
- case 4: REPORT(JSMSG_BAD_QUANTIFIER);
169
- case 5: REPORT(JSMSG_BAD_QUANTIFIER);
170
- case 6: REPORT(JSMSG_BAD_CLASS_RANGE);
171
- case 7: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
172
- case 8: REPORT(JSMSG_BAD_CLASS_RANGE);
173
- case 9: REPORT(JSMSG_BAD_QUANTIFIER);
174
- case 10: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN);
175
- case 11: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
176
- case 12: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN);
177
- case 13: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
178
- case 14: REPORT(JSMSG_MISSING_PAREN);
179
- case 15: REPORT(JSMSG_BAD_BACKREF);
180
- case 16: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
181
- case 17: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
183
- JS_NOT_REACHED("Precondition violation: unknown PCRE error code.");
187
-#endif /* ENABLE_YARR_JIT */
190
js::ParseRegExpFlags(JSContext *cx, JSString *flagStr, RegExpFlag *flagsOut)
192
diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h
193
index 1449d56..279f3c0 100644
194
--- a/js/src/vm/RegExpObject.h
195
+++ b/js/src/vm/RegExpObject.h
197
#include "yarr/Yarr.h"
199
#include "yarr/YarrJIT.h"
201
-#include "yarr/pcre/pcre.h"
205
@@ -153,48 +151,39 @@ ResetRegExpObject(JSContext *cx, AlreadyIncRefed<RegExpPrivate> rep);
206
/* Abstracts away the gross |RegExpPrivate| backend details. */
207
class RegExpPrivateCode
210
typedef JSC::Yarr::BytecodePattern BytecodePattern;
211
typedef JSC::Yarr::ErrorCode ErrorCode;
212
+ typedef JSC::Yarr::YarrPattern YarrPattern;
214
typedef JSC::Yarr::JSGlobalData JSGlobalData;
215
typedef JSC::Yarr::YarrCodeBlock YarrCodeBlock;
216
- typedef JSC::Yarr::YarrPattern YarrPattern;
218
/* Note: Native code is valid only if |codeBlock.isFallBack() == false|. */
219
YarrCodeBlock codeBlock;
220
- BytecodePattern *byteCode;
222
- JSRegExp *compiled;
224
+ BytecodePattern *byteCode;
238
~RegExpPrivateCode() {
243
Foreground::delete_<BytecodePattern>(byteCode);
246
- jsRegExpFree(compiled);
251
static inline bool isJITRuntimeEnabled(JSContext *cx);
252
- void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error);
254
- void reportPCREError(JSContext *cx, int error);
256
+ void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error);
258
inline bool compile(JSContext *cx, JSLinearString &pattern, TokenStream *ts, uintN *parenCount,
260
@@ -205,11 +194,7 @@ class RegExpPrivateCode
261
int *output, size_t outputCount);
263
static size_t getOutputSize(size_t pairCount) {
265
return pairCount * 2;
267
- return pairCount * 3; /* Should be x2, but PCRE has... needs. */
272
diff --git a/js/src/yarr/wtfbridge.h b/js/src/yarr/wtfbridge.h
273
index ac41d08..fb8eb86 100644
274
--- a/js/src/yarr/wtfbridge.h
275
+++ b/js/src/yarr/wtfbridge.h
278
#include "vm/String.h"
279
#include "assembler/wtf/Platform.h"
281
#include "assembler/jit/ExecutableAllocator.h"
284
namespace JSC { namespace Yarr {