2012-07-16 10:13:51 +02:00
|
|
|
# HG changeset patch
|
|
|
|
# Parent 831eeca7b7cfa9ae2458d9efafe168027259965f
|
|
|
|
# User Landry Breuil <landry@openbsd.org>
|
|
|
|
Bug 691898 - Use YARR regexp interpreter instead of PCRE on platforms where YARR JIT is not supported r=dmandelin
|
|
|
|
PCRE doesn't build anyway.
|
|
|
|
|
2012-02-07 19:15:47 +01:00
|
|
|
diff --git a/js/src/Makefile.in b/js/src/Makefile.in
|
|
|
|
--- a/js/src/Makefile.in
|
|
|
|
+++ b/js/src/Makefile.in
|
2012-07-16 10:13:51 +02:00
|
|
|
@@ -315,30 +315,33 @@ ifeq (mips, $(findstring mips,$(TARGET_C
|
|
|
|
CPPSRCS += TrampolineMIPS.cpp
|
|
|
|
endif
|
2012-06-05 20:01:53 +02:00
|
|
|
#
|
2012-07-16 10:13:51 +02:00
|
|
|
# END enclude sources for the method JIT
|
2012-03-01 10:09:12 +01:00
|
|
|
#############################################
|
|
|
|
|
2012-07-16 10:13:51 +02:00
|
|
|
endif
|
|
|
|
|
2012-06-05 20:01:53 +02:00
|
|
|
-# For architectures without YARR JIT, PCRE is faster than the YARR
|
|
|
|
-# interpreter (bug 684559).
|
|
|
|
-
|
2012-03-01 10:09:12 +01:00
|
|
|
ifeq (,$(filter arm% sparc %86 x86_64 mips%,$(TARGET_CPU)))
|
2012-02-07 19:15:47 +01:00
|
|
|
|
|
|
|
-VPATH += $(srcdir)/yarr/pcre \
|
2012-06-05 20:01:53 +02:00
|
|
|
+VPATH += $(srcdir)/assembler \
|
|
|
|
+ $(srcdir)/assembler/wtf \
|
|
|
|
+ $(srcdir)/assembler/jit \
|
|
|
|
+ $(srcdir)/yarr \
|
2012-02-07 19:15:47 +01:00
|
|
|
$(NULL)
|
|
|
|
|
2012-06-05 20:01:53 +02:00
|
|
|
-CPPSRCS += \
|
2012-02-07 19:15:47 +01:00
|
|
|
- pcre_compile.cpp \
|
|
|
|
- pcre_exec.cpp \
|
|
|
|
- pcre_tables.cpp \
|
|
|
|
- pcre_xclass.cpp \
|
|
|
|
- pcre_ucp_searchfuncs.cpp \
|
2012-06-05 20:01:53 +02:00
|
|
|
+CPPSRCS += ExecutableAllocator.cpp \
|
|
|
|
+ ExecutableAllocatorPosix.cpp \
|
|
|
|
+ OSAllocatorOS2.cpp \
|
|
|
|
+ OSAllocatorPosix.cpp \
|
|
|
|
+ OSAllocatorWin.cpp \
|
|
|
|
+ PageBlock.cpp \
|
|
|
|
+ YarrInterpreter.cpp \
|
|
|
|
+ YarrPattern.cpp \
|
|
|
|
+ YarrSyntaxChecker.cpp \
|
2012-02-07 19:15:47 +01:00
|
|
|
$(NULL)
|
|
|
|
else
|
|
|
|
|
2012-03-01 10:09:12 +01:00
|
|
|
###############################################
|
|
|
|
# BEGIN include sources for the Nitro assembler
|
|
|
|
#
|
|
|
|
|
|
|
|
ENABLE_YARR_JIT = 1
|
2012-06-05 20:01:53 +02:00
|
|
|
diff --git a/js/src/assembler/jit/ExecutableAllocator.h b/js/src/assembler/jit/ExecutableAllocator.h
|
|
|
|
--- a/js/src/assembler/jit/ExecutableAllocator.h
|
|
|
|
+++ b/js/src/assembler/jit/ExecutableAllocator.h
|
|
|
|
@@ -462,18 +462,16 @@ public:
|
|
|
|
: "r" (code), "r" (reinterpret_cast<char*>(code) + size)
|
|
|
|
: "r0", "r1", "r2");
|
2012-03-01 10:09:12 +01:00
|
|
|
}
|
2012-06-05 20:01:53 +02:00
|
|
|
#elif WTF_CPU_SPARC
|
|
|
|
static void cacheFlush(void* code, size_t size)
|
|
|
|
{
|
|
|
|
sync_instruction_memory((caddr_t)code, size);
|
2012-03-01 10:09:12 +01:00
|
|
|
}
|
2012-06-05 20:01:53 +02:00
|
|
|
-#else
|
|
|
|
- #error "The cacheFlush support is missing on this platform."
|
|
|
|
#endif
|
2012-03-01 10:09:12 +01:00
|
|
|
|
2012-06-05 20:01:53 +02:00
|
|
|
private:
|
2012-03-01 10:09:12 +01:00
|
|
|
|
2012-06-05 20:01:53 +02:00
|
|
|
#if ENABLE_ASSEMBLER_WX_EXCLUSIVE
|
|
|
|
static void reprotectRegion(void*, size_t, ProtectionSetting);
|
|
|
|
#endif
|
2012-03-01 10:09:12 +01:00
|
|
|
|
2012-02-07 19:15:47 +01:00
|
|
|
diff --git a/js/src/vm/RegExpObject-inl.h b/js/src/vm/RegExpObject-inl.h
|
|
|
|
--- a/js/src/vm/RegExpObject-inl.h
|
|
|
|
+++ b/js/src/vm/RegExpObject-inl.h
|
2012-07-16 10:13:51 +02:00
|
|
|
@@ -132,26 +132,28 @@ RegExpObject::setMultiline(bool enabled)
|
2012-03-01 10:09:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
RegExpObject::setSticky(bool enabled)
|
|
|
|
{
|
|
|
|
setSlot(STICKY_FLAG_SLOT, BooleanValue(enabled));
|
2012-02-07 19:15:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+#if ENABLE_YARR_JIT
|
|
|
|
/* This function should be deleted once bad Android platforms phase out. See bug 604774. */
|
|
|
|
inline bool
|
2012-03-01 10:09:12 +01:00
|
|
|
detail::RegExpCode::isJITRuntimeEnabled(JSContext *cx)
|
|
|
|
{
|
|
|
|
#if defined(ANDROID) && defined(JS_METHODJIT)
|
|
|
|
return cx->methodJitEnabled;
|
|
|
|
#else
|
2012-02-07 19:15:47 +01:00
|
|
|
return true;
|
2012-07-16 10:13:51 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
RegExpToShared(JSContext *cx, JSObject &obj, RegExpGuard *g)
|
|
|
|
{
|
|
|
|
JS_ASSERT(ObjectClassIs(obj, ESClass_RegExp, cx));
|
|
|
|
if (obj.isRegExp())
|
|
|
|
return obj.asRegExp().getShared(cx, g);
|
|
|
|
return Proxy::regexp_toShared(cx, &obj, g);
|
2012-03-01 10:09:12 +01:00
|
|
|
diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp
|
|
|
|
--- a/js/src/vm/RegExpObject.cpp
|
|
|
|
+++ b/js/src/vm/RegExpObject.cpp
|
2012-07-16 10:13:51 +02:00
|
|
|
@@ -163,17 +163,16 @@ MatchPairs::checkAgainst(size_t inputLen
|
2012-03-01 10:09:12 +01:00
|
|
|
continue;
|
|
|
|
JS_ASSERT(size_t(p.limit) <= inputLength);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* detail::RegExpCode */
|
|
|
|
|
|
|
|
-#if ENABLE_YARR_JIT
|
|
|
|
void
|
|
|
|
RegExpCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error)
|
|
|
|
{
|
|
|
|
switch (error) {
|
|
|
|
case JSC::Yarr::NoError:
|
|
|
|
JS_NOT_REACHED("Called reportYarrError with value for no error");
|
|
|
|
return;
|
|
|
|
#define COMPILE_EMSG(__code, __msg) \
|
2012-07-16 10:13:51 +02:00
|
|
|
@@ -195,73 +194,36 @@ RegExpCode::reportYarrError(JSContext *c
|
2012-03-01 10:09:12 +01:00
|
|
|
COMPILE_EMSG(QuantifierTooLarge, JSMSG_BAD_QUANTIFIER);
|
|
|
|
COMPILE_EMSG(EscapeUnterminated, JSMSG_TRAILING_SLASH);
|
|
|
|
#undef COMPILE_EMSG
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("Unknown Yarr error code");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-#else /* !ENABLE_YARR_JIT */
|
|
|
|
-
|
|
|
|
-void
|
|
|
|
-RegExpCode::reportPCREError(JSContext *cx, int error)
|
|
|
|
-{
|
|
|
|
-#define REPORT(msg_) \
|
|
|
|
- JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, msg_); \
|
|
|
|
- return
|
|
|
|
- switch (error) {
|
|
|
|
- case -2: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- case 0: JS_NOT_REACHED("Precondition violation: an error must have occurred.");
|
|
|
|
- case 1: REPORT(JSMSG_TRAILING_SLASH);
|
|
|
|
- case 2: REPORT(JSMSG_TRAILING_SLASH);
|
|
|
|
- case 3: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- case 4: REPORT(JSMSG_BAD_QUANTIFIER);
|
|
|
|
- case 5: REPORT(JSMSG_BAD_QUANTIFIER);
|
|
|
|
- case 6: REPORT(JSMSG_BAD_CLASS_RANGE);
|
|
|
|
- case 7: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- case 8: REPORT(JSMSG_BAD_CLASS_RANGE);
|
|
|
|
- case 9: REPORT(JSMSG_BAD_QUANTIFIER);
|
|
|
|
- case 10: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN);
|
|
|
|
- case 11: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- case 12: REPORT(JSMSG_UNMATCHED_RIGHT_PAREN);
|
|
|
|
- case 13: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- case 14: REPORT(JSMSG_MISSING_PAREN);
|
|
|
|
- case 15: REPORT(JSMSG_BAD_BACKREF);
|
|
|
|
- case 16: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- case 17: REPORT(JSMSG_REGEXP_TOO_COMPLEX);
|
|
|
|
- default:
|
|
|
|
- JS_NOT_REACHED("Precondition violation: unknown PCRE error code.");
|
|
|
|
- }
|
|
|
|
-#undef REPORT
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#endif /* ENABLE_YARR_JIT */
|
|
|
|
-
|
|
|
|
bool
|
2012-06-05 20:01:53 +02:00
|
|
|
RegExpCode::compile(JSContext *cx, JSLinearString &pattern, unsigned *parenCount, RegExpFlag flags)
|
2012-02-07 19:15:47 +01:00
|
|
|
{
|
2012-07-16 10:13:51 +02:00
|
|
|
-#if ENABLE_YARR_JIT
|
2012-02-07 19:15:47 +01:00
|
|
|
/* Parse the pattern. */
|
|
|
|
ErrorCode yarrError;
|
|
|
|
YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag),
|
2012-03-01 10:09:12 +01:00
|
|
|
&yarrError);
|
2012-07-16 10:13:51 +02:00
|
|
|
if (yarrError) {
|
|
|
|
reportYarrError(cx, NULL, yarrError);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*parenCount = yarrPattern.m_numSubpatterns;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The YARR JIT compiler attempts to compile the parsed pattern. If
|
|
|
|
* it cannot, it informs us via |codeBlock.isFallBack()|, in which
|
|
|
|
* case we have to bytecode compile it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
-#ifdef JS_METHODJIT
|
|
|
|
+#if ENABLE_YARR_JIT && defined(JS_METHODJIT)
|
|
|
|
if (isJITRuntimeEnabled(cx) && !yarrPattern.m_containsBackreferences) {
|
|
|
|
JSC::ExecutableAllocator *execAlloc = cx->runtime->getExecutableAllocator(cx);
|
|
|
|
if (!execAlloc) {
|
|
|
|
js_ReportOutOfMemory(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSGlobalData globalData(execAlloc);
|
|
|
|
@@ -272,58 +234,41 @@ RegExpCode::compile(JSContext *cx, JSLin
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WTF::BumpPointerAllocator *bumpAlloc = cx->runtime->getBumpPointerAllocator(cx);
|
|
|
|
if (!bumpAlloc) {
|
|
|
|
js_ReportOutOfMemory(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if ENABLE_YARR_JIT
|
|
|
|
codeBlock.setFallBack(true);
|
|
|
|
+#endif
|
|
|
|
byteCode = byteCompile(yarrPattern, bumpAlloc).get();
|
|
|
|
return true;
|
|
|
|
-#else /* !defined(ENABLE_YARR_JIT) */
|
|
|
|
- int error = 0;
|
|
|
|
- compiled = jsRegExpCompile(pattern.chars(), pattern.length(),
|
|
|
|
- ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase,
|
|
|
|
- multiline() ? JSRegExpMultiline : JSRegExpSingleLine,
|
|
|
|
- parenCount, &error);
|
|
|
|
- if (error) {
|
|
|
|
- reportPCREError(cx, error);
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
-#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
RegExpRunStatus
|
|
|
|
RegExpCode::execute(JSContext *cx, const jschar *chars, size_t length, size_t start,
|
|
|
|
int *output, size_t outputCount)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
#if ENABLE_YARR_JIT
|
|
|
|
(void) cx; /* Unused. */
|
|
|
|
if (codeBlock.isFallBack())
|
|
|
|
result = JSC::Yarr::interpret(byteCode, chars, start, length, output);
|
|
|
|
else
|
|
|
|
result = JSC::Yarr::execute(codeBlock, chars, start, length, output);
|
|
|
|
#else
|
|
|
|
- result = jsRegExpExecute(cx, compiled, chars, length, start, output, outputCount);
|
|
|
|
+ result = JSC::Yarr::interpret(byteCode, chars, start, length, output);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (result == -1)
|
|
|
|
return RegExpRunStatus_Success_NotFound;
|
|
|
|
|
|
|
|
-#if !ENABLE_YARR_JIT
|
|
|
|
- if (result < 0) {
|
|
|
|
- reportPCREError(cx, result);
|
|
|
|
- return RegExpRunStatus_Error;
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
JS_ASSERT(result >= 0);
|
|
|
|
return RegExpRunStatus_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RegExpObject */
|
|
|
|
|
|
|
|
static void
|
|
|
|
regexp_trace(JSTracer *trc, JSObject *obj)
|
2012-02-07 19:15:47 +01:00
|
|
|
diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h
|
|
|
|
--- a/js/src/vm/RegExpObject.h
|
|
|
|
+++ b/js/src/vm/RegExpObject.h
|
2012-07-16 10:13:51 +02:00
|
|
|
@@ -47,20 +47,18 @@
|
|
|
|
#include "jscntxt.h"
|
2012-03-01 10:09:12 +01:00
|
|
|
#include "jsobj.h"
|
|
|
|
|
|
|
|
#include "js/TemplateLib.h"
|
|
|
|
|
2012-02-07 19:15:47 +01:00
|
|
|
#include "yarr/Yarr.h"
|
|
|
|
#if ENABLE_YARR_JIT
|
|
|
|
#include "yarr/YarrJIT.h"
|
2012-03-01 10:09:12 +01:00
|
|
|
+#endif
|
|
|
|
#include "yarr/YarrSyntaxChecker.h"
|
2012-02-07 19:15:47 +01:00
|
|
|
-#else
|
|
|
|
-#include "yarr/pcre/pcre.h"
|
2012-03-01 10:09:12 +01:00
|
|
|
-#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JavaScript Regular Expressions
|
|
|
|
*
|
|
|
|
* There are several engine concepts associated with a single logical regexp:
|
|
|
|
*
|
|
|
|
* RegExpObject - The JS-visible object whose .[[Class]] equals "RegExp"
|
|
|
|
*
|
2012-07-16 10:13:51 +02:00
|
|
|
@@ -108,78 +106,61 @@ class RegExpObjectBuilder
|
|
|
|
|
|
|
|
JSObject *
|
|
|
|
CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto);
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
class RegExpCode
|
|
|
|
{
|
|
|
|
-#if ENABLE_YARR_JIT
|
|
|
|
typedef JSC::Yarr::BytecodePattern BytecodePattern;
|
|
|
|
typedef JSC::Yarr::ErrorCode ErrorCode;
|
|
|
|
+ typedef JSC::Yarr::YarrPattern YarrPattern;
|
|
|
|
+#if ENABLE_YARR_JIT
|
|
|
|
typedef JSC::Yarr::JSGlobalData JSGlobalData;
|
|
|
|
typedef JSC::Yarr::YarrCodeBlock YarrCodeBlock;
|
|
|
|
- typedef JSC::Yarr::YarrPattern YarrPattern;
|
|
|
|
|
|
|
|
/* Note: Native code is valid only if |codeBlock.isFallBack() == false|. */
|
|
|
|
YarrCodeBlock codeBlock;
|
|
|
|
+#endif
|
|
|
|
BytecodePattern *byteCode;
|
|
|
|
-#else
|
|
|
|
- JSRegExp *compiled;
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
RegExpCode()
|
|
|
|
:
|
|
|
|
#if ENABLE_YARR_JIT
|
|
|
|
codeBlock(),
|
|
|
|
+#endif
|
|
|
|
byteCode(NULL)
|
|
|
|
-#else
|
|
|
|
- compiled(NULL)
|
|
|
|
-#endif
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~RegExpCode() {
|
|
|
|
#if ENABLE_YARR_JIT
|
|
|
|
codeBlock.release();
|
|
|
|
+#endif
|
|
|
|
if (byteCode)
|
|
|
|
Foreground::delete_<BytecodePattern>(byteCode);
|
|
|
|
-#else
|
|
|
|
- if (compiled)
|
|
|
|
- jsRegExpFree(compiled);
|
|
|
|
-#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool checkSyntax(JSContext *cx, TokenStream *tokenStream, JSLinearString *source) {
|
|
|
|
-#if ENABLE_YARR_JIT
|
|
|
|
ErrorCode error = JSC::Yarr::checkSyntax(*source);
|
|
|
|
if (error == JSC::Yarr::NoError)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
reportYarrError(cx, tokenStream, error);
|
|
|
|
return false;
|
|
|
|
-#else
|
|
|
|
-# error "Syntax checking not implemented for !ENABLE_YARR_JIT"
|
|
|
|
-#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE_YARR_JIT
|
|
|
|
static inline bool isJITRuntimeEnabled(JSContext *cx);
|
|
|
|
+#endif
|
|
|
|
static void reportYarrError(JSContext *cx, TokenStream *ts, JSC::Yarr::ErrorCode error);
|
|
|
|
-#else
|
|
|
|
- static void reportPCREError(JSContext *cx, int error);
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
static size_t getOutputSize(size_t pairCount) {
|
|
|
|
-#if ENABLE_YARR_JIT
|
|
|
|
return pairCount * 2;
|
|
|
|
-#else
|
|
|
|
- return pairCount * 3; /* Should be x2, but PCRE has... needs. */
|
|
|
|
-#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compile(JSContext *cx, JSLinearString &pattern, unsigned *parenCount, RegExpFlag flags);
|
|
|
|
|
|
|
|
|
|
|
|
RegExpRunStatus
|
|
|
|
execute(JSContext *cx, const jschar *chars, size_t length, size_t start,
|
|
|
|
int *output, size_t outputCount);
|
2012-02-07 19:15:47 +01:00
|
|
|
diff --git a/js/src/yarr/wtfbridge.h b/js/src/yarr/wtfbridge.h
|
|
|
|
--- a/js/src/yarr/wtfbridge.h
|
|
|
|
+++ b/js/src/yarr/wtfbridge.h
|
2012-03-01 10:09:12 +01:00
|
|
|
@@ -44,19 +44,17 @@
|
|
|
|
* WTF compatibility layer. This file provides various type and data
|
|
|
|
* definitions for use by Yarr.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jsstr.h"
|
2012-02-07 19:15:47 +01:00
|
|
|
#include "jsprvtd.h"
|
|
|
|
#include "vm/String.h"
|
|
|
|
#include "assembler/wtf/Platform.h"
|
|
|
|
-#if ENABLE_YARR_JIT
|
|
|
|
#include "assembler/jit/ExecutableAllocator.h"
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
namespace JSC { namespace Yarr {
|
|
|
|
|
2012-03-01 10:09:12 +01:00
|
|
|
/*
|
|
|
|
* Basic type definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef jschar UChar;
|