mozilla-yarr-pcre.patch
branchfirefox14
changeset 475 b0df28e752fd
parent 401 aafdccaf5ded
equal deleted inserted replaced
474:5b24d3e8461e 475:b0df28e752fd
     1 # HG changeset patch
     1 # HG changeset patch
     2 # Parent 58dd942011a81f3149d9bc34e808806bda099056
     2 # Parent 831eeca7b7cfa9ae2458d9efafe168027259965f
     3 # User Landry Breuil <landry@openbsd.org>
     3 # User Landry Breuil <landry@openbsd.org>
     4 Use YARR interpreter instead of PCRE on platforms where YARR JIT is not
     4 Bug 691898 - Use YARR regexp interpreter instead of PCRE on platforms where YARR JIT is not supported r=dmandelin
     5 supported
     5 PCRE doesn't build anyway.
     6 
     6 
     7 diff --git a/js/src/Makefile.in b/js/src/Makefile.in
     7 diff --git a/js/src/Makefile.in b/js/src/Makefile.in
     8 --- a/js/src/Makefile.in
     8 --- a/js/src/Makefile.in
     9 +++ b/js/src/Makefile.in
     9 +++ b/js/src/Makefile.in
    10 @@ -335,25 +335,29 @@ CPPSRCS += 	checks.cc \
    10 @@ -315,30 +315,33 @@ ifeq (mips, $(findstring mips,$(TARGET_C
    11  # END enclude sources for V8 dtoa
    11  CPPSRCS +=	TrampolineMIPS.cpp
       
    12  endif
       
    13  #
       
    14  # END enclude sources for the method JIT
    12  #############################################
    15  #############################################
    13  
    16  
    14  # For architectures without YARR JIT, PCRE is faster than the YARR
    17  endif
    15  # interpreter (bug 684559).
    18  
    16  
    19 -# For architectures without YARR JIT, PCRE is faster than the YARR
       
    20 -# interpreter (bug 684559).
       
    21 -
    17  ifeq (,$(filter arm% sparc %86 x86_64 mips%,$(TARGET_CPU)))
    22  ifeq (,$(filter arm% sparc %86 x86_64 mips%,$(TARGET_CPU)))
    18  
    23  
    19 -VPATH +=        $(srcdir)/yarr/pcre \
    24 -VPATH +=        $(srcdir)/yarr/pcre \
    20 +VPATH +=        $(srcdir)/assembler \
    25 +VPATH +=	$(srcdir)/assembler \
    21 +                $(srcdir)/assembler/wtf \
    26 +		$(srcdir)/assembler/wtf \
    22 +                $(srcdir)/yarr \
    27 +		$(srcdir)/assembler/jit \
       
    28 +		$(srcdir)/yarr \
    23  		$(NULL)
    29  		$(NULL)
    24  
    30  
    25  CPPSRCS += \
    31 -CPPSRCS += \
    26 -                pcre_compile.cpp \
    32 -                pcre_compile.cpp \
    27 -                pcre_exec.cpp \
    33 -                pcre_exec.cpp \
    28 -                pcre_tables.cpp \
    34 -                pcre_tables.cpp \
    29 -                pcre_xclass.cpp \
    35 -                pcre_xclass.cpp \
    30 -                pcre_ucp_searchfuncs.cpp \
    36 -                pcre_ucp_searchfuncs.cpp \
    31 +                OSAllocatorOS2.cpp \
    37 +CPPSRCS +=	ExecutableAllocator.cpp \
    32 +                OSAllocatorPosix.cpp \
    38 +		ExecutableAllocatorPosix.cpp \
    33 +                OSAllocatorWin.cpp \
    39 +		OSAllocatorOS2.cpp \
    34 +                PageBlock.cpp \
    40 +		OSAllocatorPosix.cpp \
    35 +                YarrInterpreter.cpp \
    41 +		OSAllocatorWin.cpp \
    36 +                YarrPattern.cpp \
    42 +		PageBlock.cpp \
    37 +                YarrSyntaxChecker.cpp \
    43 +		YarrInterpreter.cpp \
       
    44 +		YarrPattern.cpp \
       
    45 +		YarrSyntaxChecker.cpp \
    38  		$(NULL)
    46  		$(NULL)
    39  else
    47  else
    40  
    48  
    41  ###############################################
    49  ###############################################
    42  # BEGIN include sources for the Nitro assembler
    50  # BEGIN include sources for the Nitro assembler
    43  #
    51  #
    44  
    52  
    45  ENABLE_YARR_JIT = 1
    53  ENABLE_YARR_JIT = 1
    46 @@ -878,20 +882,20 @@ endif
    54 diff --git a/js/src/assembler/jit/ExecutableAllocator.h b/js/src/assembler/jit/ExecutableAllocator.h
    47  
    55 --- a/js/src/assembler/jit/ExecutableAllocator.h
    48  ###############################################
    56 +++ b/js/src/assembler/jit/ExecutableAllocator.h
    49  # BEGIN kludges for the Nitro assembler
    57 @@ -462,18 +462,16 @@ public:
    50  #
    58              : "r" (code), "r" (reinterpret_cast<char*>(code) + size)
    51  
    59              : "r0", "r1", "r2");
    52  # Needed to "configure" it correctly.  Unfortunately these
    60      }
    53  # flags wind up being applied to all code in js/src, not just
    61  #elif WTF_CPU_SPARC
    54  # the code in js/src/assembler.
    62      static void cacheFlush(void* code, size_t size)
    55 -CXXFLAGS += -DUSE_SYSTEM_MALLOC=1 -DENABLE_ASSEMBLER=1
    63      {
    56 +CXXFLAGS += -DUSE_SYSTEM_MALLOC=1
    64          sync_instruction_memory((caddr_t)code, size);
    57  
    65      }
    58  ifneq (,$(ENABLE_YARR_JIT)$(ENABLE_METHODJIT))
    66 -#else
    59 -CXXFLAGS +=  -DENABLE_JIT=1
    67 -    #error "The cacheFlush support is missing on this platform."
    60 +CXXFLAGS +=  -DENABLE_JIT=1 -DENABLE_ASSEMBLER=1
    68  #endif
    61  endif
    69  
    62  
    70  private:
    63  INCLUDES +=	-I$(srcdir)/assembler -I$(srcdir)/yarr
    71  
    64  
    72  #if ENABLE_ASSEMBLER_WX_EXCLUSIVE
    65  ifdef ENABLE_METHODJIT
    73      static void reprotectRegion(void*, size_t, ProtectionSetting);
    66  # Build a standalone test program that exercises the assembler
    74  #endif
    67  # sources a bit.
       
    68  TESTMAIN_OBJS = \
       
    69 diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp
       
    70 --- a/js/src/jsapi.cpp
       
    71 +++ b/js/src/jsapi.cpp
       
    72 @@ -696,17 +696,19 @@ JS_IsBuiltinFunctionConstructor(JSFuncti
       
    73  static JSBool js_NewRuntimeWasCalled = JS_FALSE;
       
    74  
       
    75  JSRuntime::JSRuntime()
       
    76    : atomsCompartment(NULL),
       
    77  #ifdef JS_THREADSAFE
       
    78      ownerThread_(NULL),
       
    79  #endif
       
    80      tempLifoAlloc(TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE),
       
    81 +#if ENABLE_ASSEMBLER
       
    82      execAlloc_(NULL),
       
    83 +#endif
       
    84      bumpAlloc_(NULL),
       
    85      nativeStackBase(0),
       
    86      nativeStackQuota(0),
       
    87      interpreterFrames(NULL),
       
    88      cxCallback(NULL),
       
    89      compartmentCallback(NULL),
       
    90      activityCallback(NULL),
       
    91      activityCallbackArg(NULL),
       
    92 @@ -851,17 +853,19 @@ JSRuntime::init(uint32_t maxbytes)
       
    93      nativeStackBase = GetNativeStackBase();
       
    94      return true;
       
    95  }
       
    96  
       
    97  JSRuntime::~JSRuntime()
       
    98  {
       
    99      JS_ASSERT(onOwnerThread());
       
   100  
       
   101 +#if ENABLE_ASSEMBLER
       
   102      delete_<JSC::ExecutableAllocator>(execAlloc_);
       
   103 +#endif
       
   104      delete_<WTF::BumpPointerAllocator>(bumpAlloc_);
       
   105  
       
   106  #ifdef DEBUG
       
   107      /* Don't hurt everyone in leaky ol' Mozilla with a fatal JS_ASSERT! */
       
   108      if (!JS_CLIST_IS_EMPTY(&contextList)) {
       
   109          JSContext *cx, *iter = NULL;
       
   110          uintN cxcount = 0;
       
   111          while ((cx = js_ContextIterator(this, JS_TRUE, &iter)) != NULL) {
       
   112 diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp
       
   113 --- a/js/src/jscntxt.cpp
       
   114 +++ b/js/src/jscntxt.cpp
       
   115 @@ -100,19 +100,21 @@ JSRuntime::sizeOfExcludingThis(JSMallocS
       
   116      if (normal)
       
   117          *normal = mallocSizeOf(dtoaState);
       
   118  
       
   119      if (temporary)
       
   120          *temporary = tempLifoAlloc.sizeOfExcludingThis(mallocSizeOf);
       
   121  
       
   122      if (regexpCode) {
       
   123          size_t method = 0, regexp = 0, unused = 0;
       
   124 +#if ENABLE_ASSEMBLER
       
   125          if (execAlloc_)
       
   126              execAlloc_->sizeOfCode(&method, &regexp, &unused);
       
   127          JS_ASSERT(method == 0);     /* this execAlloc is only used for regexp code */
       
   128 +#endif
       
   129          *regexpCode = regexp + unused;
       
   130      }
       
   131  
       
   132      if (stackCommitted)
       
   133          *stackCommitted = stackSpace.sizeOfCommitted();
       
   134  }
       
   135  
       
   136  JS_FRIEND_API(void)
       
   137 @@ -124,33 +126,37 @@ JSRuntime::triggerOperationCallback()
       
   138       */
       
   139      JS_ATOMIC_SET(&interrupt, 1);
       
   140  }
       
   141  
       
   142  void
       
   143  JSRuntime::setJitHardening(bool enabled)
       
   144  {
       
   145      jitHardening = enabled;
       
   146 +#if ENABLE_ASSEMBLER
       
   147      if (execAlloc_)
       
   148          execAlloc_->setRandomize(enabled);
       
   149 +#endif
       
   150  }
       
   151  
       
   152 +#if ENABLE_ASSEMBLER
       
   153  JSC::ExecutableAllocator *
       
   154  JSRuntime::createExecutableAllocator(JSContext *cx)
       
   155  {
       
   156      JS_ASSERT(!execAlloc_);
       
   157      JS_ASSERT(cx->runtime == this);
       
   158  
       
   159      JSC::AllocationBehavior randomize =
       
   160          jitHardening ? JSC::AllocationCanRandomize : JSC::AllocationDeterministic;
       
   161      execAlloc_ = new_<JSC::ExecutableAllocator>(randomize);
       
   162      if (!execAlloc_)
       
   163          js_ReportOutOfMemory(cx);
       
   164      return execAlloc_;
       
   165  }
       
   166 +#endif
       
   167  
       
   168  WTF::BumpPointerAllocator *
       
   169  JSRuntime::createBumpPointerAllocator(JSContext *cx)
       
   170  {
       
   171      JS_ASSERT(!bumpAlloc_);
       
   172      JS_ASSERT(cx->runtime == this);
       
   173  
       
   174      bumpAlloc_ = new_<WTF::BumpPointerAllocator>();
       
   175 diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
       
   176 --- a/js/src/jscntxt.h
       
   177 +++ b/js/src/jscntxt.h
       
   178 @@ -219,26 +219,32 @@ struct JSRuntime : js::RuntimeFriendFiel
       
   179      static const size_t TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE = 1 << 12;
       
   180      js::LifoAlloc tempLifoAlloc;
       
   181  
       
   182    private:
       
   183      /*
       
   184       * Both of these allocators are used for regular expression code which is shared at the
       
   185       * thread-data level.
       
   186       */
       
   187 +#if ENABLE_ASSEMBLER
       
   188      JSC::ExecutableAllocator *execAlloc_;
       
   189 +#endif
       
   190      WTF::BumpPointerAllocator *bumpAlloc_;
       
   191  
       
   192 +#if ENABLE_ASSEMBLER
       
   193      JSC::ExecutableAllocator *createExecutableAllocator(JSContext *cx);
       
   194 +#endif
       
   195      WTF::BumpPointerAllocator *createBumpPointerAllocator(JSContext *cx);
       
   196  
       
   197    public:
       
   198 +#if ENABLE_ASSEMBLER
       
   199      JSC::ExecutableAllocator *getExecutableAllocator(JSContext *cx) {
       
   200          return execAlloc_ ? execAlloc_ : createExecutableAllocator(cx);
       
   201      }
       
   202 +#endif
       
   203      WTF::BumpPointerAllocator *getBumpPointerAllocator(JSContext *cx) {
       
   204          return bumpAlloc_ ? bumpAlloc_ : createBumpPointerAllocator(cx);
       
   205      }
       
   206  
       
   207      /* Base address of the native stack for the current thread. */
       
   208      uintptr_t           nativeStackBase;
       
   209  
       
   210      /* The native stack size limit that runtime should not exceed. */
       
   211 diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h
       
   212 --- a/js/src/jsprvtd.h
       
   213 +++ b/js/src/jsprvtd.h
       
   214 @@ -313,22 +313,23 @@ typedef Handle<BaseShape*>         Handl
       
   215  typedef Handle<types::TypeObject*> HandleTypeObject;
       
   216  typedef Handle<JSString*>          HandleString;
       
   217  typedef Handle<JSAtom*>            HandleAtom;
       
   218  typedef Handle<jsid>               HandleId;
       
   219  typedef Handle<Value>              HandleValue;
       
   220  
       
   221  } /* namespace js */
       
   222  
       
   223 +#if ENABLE_ASSEMBLER
       
   224  namespace JSC {
       
   225  
       
   226  class ExecutableAllocator;
       
   227  
       
   228  } /* namespace JSC */
       
   229 -
       
   230 +#endif
       
   231  namespace WTF {
       
   232  
       
   233  class BumpPointerAllocator;
       
   234  
       
   235  } /* namespace WTF */
       
   236  
       
   237  } /* export "C++" */
       
   238  
    75  
   239 diff --git a/js/src/vm/RegExpObject-inl.h b/js/src/vm/RegExpObject-inl.h
    76 diff --git a/js/src/vm/RegExpObject-inl.h b/js/src/vm/RegExpObject-inl.h
   240 --- a/js/src/vm/RegExpObject-inl.h
    77 --- a/js/src/vm/RegExpObject-inl.h
   241 +++ b/js/src/vm/RegExpObject-inl.h
    78 +++ b/js/src/vm/RegExpObject-inl.h
   242 @@ -132,26 +132,28 @@ RegExpObject::setMultiline(bool enabled)
    79 @@ -132,26 +132,28 @@ RegExpObject::setMultiline(bool enabled)
   269          return obj.asRegExp().getShared(cx, g);
   106          return obj.asRegExp().getShared(cx, g);
   270      return Proxy::regexp_toShared(cx, &obj, g);
   107      return Proxy::regexp_toShared(cx, &obj, g);
   271 diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp
   108 diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp
   272 --- a/js/src/vm/RegExpObject.cpp
   109 --- a/js/src/vm/RegExpObject.cpp
   273 +++ b/js/src/vm/RegExpObject.cpp
   110 +++ b/js/src/vm/RegExpObject.cpp
   274 @@ -162,17 +162,16 @@ MatchPairs::checkAgainst(size_t inputLen
   111 @@ -163,17 +163,16 @@ MatchPairs::checkAgainst(size_t inputLen
   275              continue;
   112              continue;
   276          JS_ASSERT(size_t(p.limit) <= inputLength);
   113          JS_ASSERT(size_t(p.limit) <= inputLength);
   277      }
   114      }
   278  #endif
   115  #endif
   279  }
   116  }
   287      switch (error) {
   124      switch (error) {
   288        case JSC::Yarr::NoError:
   125        case JSC::Yarr::NoError:
   289          JS_NOT_REACHED("Called reportYarrError with value for no error");
   126          JS_NOT_REACHED("Called reportYarrError with value for no error");
   290          return;
   127          return;
   291  #define COMPILE_EMSG(__code, __msg)                                                              \
   128  #define COMPILE_EMSG(__code, __msg)                                                              \
   292 @@ -194,73 +193,36 @@ RegExpCode::reportYarrError(JSContext *c
   129 @@ -195,73 +194,36 @@ RegExpCode::reportYarrError(JSContext *c
   293        COMPILE_EMSG(QuantifierTooLarge, JSMSG_BAD_QUANTIFIER);
   130        COMPILE_EMSG(QuantifierTooLarge, JSMSG_BAD_QUANTIFIER);
   294        COMPILE_EMSG(EscapeUnterminated, JSMSG_TRAILING_SLASH);
   131        COMPILE_EMSG(EscapeUnterminated, JSMSG_TRAILING_SLASH);
   295  #undef COMPILE_EMSG
   132  #undef COMPILE_EMSG
   296        default:
   133        default:
   297          JS_NOT_REACHED("Unknown Yarr error code");
   134          JS_NOT_REACHED("Unknown Yarr error code");
   333 -}
   170 -}
   334 -
   171 -
   335 -#endif /* ENABLE_YARR_JIT */
   172 -#endif /* ENABLE_YARR_JIT */
   336 -
   173 -
   337  bool
   174  bool
   338  RegExpCode::compile(JSContext *cx, JSLinearString &pattern, uintN *parenCount, RegExpFlag flags)
   175  RegExpCode::compile(JSContext *cx, JSLinearString &pattern, unsigned *parenCount, RegExpFlag flags)
   339  {
   176  {
   340 -#if ENABLE_YARR_JIT
   177 -#if ENABLE_YARR_JIT
   341      /* Parse the pattern. */
   178      /* Parse the pattern. */
   342      ErrorCode yarrError;
   179      ErrorCode yarrError;
   343      YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag),
   180      YarrPattern yarrPattern(pattern, bool(flags & IgnoreCaseFlag), bool(flags & MultilineFlag),
   362              js_ReportOutOfMemory(cx);
   199              js_ReportOutOfMemory(cx);
   363              return false;
   200              return false;
   364          }
   201          }
   365  
   202  
   366          JSGlobalData globalData(execAlloc);
   203          JSGlobalData globalData(execAlloc);
   367 @@ -271,58 +233,41 @@ RegExpCode::compile(JSContext *cx, JSLin
   204 @@ -272,58 +234,41 @@ RegExpCode::compile(JSContext *cx, JSLin
   368  #endif
   205  #endif
   369  
   206  
   370      WTF::BumpPointerAllocator *bumpAlloc = cx->runtime->getBumpPointerAllocator(cx);
   207      WTF::BumpPointerAllocator *bumpAlloc = cx->runtime->getBumpPointerAllocator(cx);
   371      if (!bumpAlloc) {
   208      if (!bumpAlloc) {
   372          js_ReportOutOfMemory(cx);
   209          js_ReportOutOfMemory(cx);
   427  static void
   264  static void
   428  regexp_trace(JSTracer *trc, JSObject *obj)
   265  regexp_trace(JSTracer *trc, JSObject *obj)
   429 diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h
   266 diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h
   430 --- a/js/src/vm/RegExpObject.h
   267 --- a/js/src/vm/RegExpObject.h
   431 +++ b/js/src/vm/RegExpObject.h
   268 +++ b/js/src/vm/RegExpObject.h
   432 @@ -46,20 +46,18 @@
   269 @@ -47,20 +47,18 @@
   433  #include <stddef.h>
   270  #include "jscntxt.h"
   434  #include "jsobj.h"
   271  #include "jsobj.h"
   435  
   272  
   436  #include "js/TemplateLib.h"
   273  #include "js/TemplateLib.h"
   437  
   274  
   438  #include "yarr/Yarr.h"
   275  #include "yarr/Yarr.h"
   449   *
   286   *
   450   * There are several engine concepts associated with a single logical regexp:
   287   * There are several engine concepts associated with a single logical regexp:
   451   *
   288   *
   452   *   RegExpObject - The JS-visible object whose .[[Class]] equals "RegExp"
   289   *   RegExpObject - The JS-visible object whose .[[Class]] equals "RegExp"
   453   *
   290   *
   454 @@ -107,78 +105,61 @@ class RegExpObjectBuilder
   291 @@ -108,78 +106,61 @@ class RegExpObjectBuilder
   455  
   292  
   456  JSObject *
   293  JSObject *
   457  CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto);
   294  CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto);
   458  
   295  
   459  namespace detail {
   296  namespace detail {
   528 -#else
   365 -#else
   529 -        return pairCount * 3; /* Should be x2, but PCRE has... needs. */
   366 -        return pairCount * 3; /* Should be x2, but PCRE has... needs. */
   530 -#endif
   367 -#endif
   531      }
   368      }
   532  
   369  
   533      bool compile(JSContext *cx, JSLinearString &pattern, uintN *parenCount, RegExpFlag flags);
   370      bool compile(JSContext *cx, JSLinearString &pattern, unsigned *parenCount, RegExpFlag flags);
   534  
   371  
   535  
   372  
   536      RegExpRunStatus
   373      RegExpRunStatus
   537      execute(JSContext *cx, const jschar *chars, size_t length, size_t start,
   374      execute(JSContext *cx, const jschar *chars, size_t length, size_t start,
   538              int *output, size_t outputCount);
   375              int *output, size_t outputCount);