[jruby-joni] 123/194: reduce number of bytecodes in interpreter loop when CEC is not used
Hideki Yamane
henrich at moszumanska.debian.org
Thu Feb 1 12:04:33 UTC 2018
This is an automated email from the git hooks/post-receive script.
henrich pushed a commit to branch debian/sid
in repository jruby-joni.
commit 2d99410b0034c6baadec078692e57d8e3aeb12fb
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date: Mon Jan 8 21:13:02 2018 +0100
reduce number of bytecodes in interpreter loop when CEC is not used
---
src/org/joni/Analyser.java | 4 ++--
src/org/joni/ArrayCompiler.java | 2 +-
src/org/joni/ByteCodeMachine.java | 31 ++++++++++++++++---------------
src/org/joni/Compiler.java | 2 +-
src/org/joni/Config.java | 2 +-
src/org/joni/Matcher.java | 6 +++---
src/org/joni/StackMachine.java | 17 +++++++++--------
7 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index b92d534..0529dec 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -75,7 +75,7 @@ final class Analyser extends Parser {
regex.repeatRangeHi = null;
regex.numCombExpCheck = 0;
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) regex.numCombExpCheck = 0;
+ if (Config.USE_CEC) regex.numCombExpCheck = 0;
parse();
@@ -128,7 +128,7 @@ final class Analyser extends Parser {
regex.btMemEnd |= regex.captureHistory;
}
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ if (Config.USE_CEC) {
if (env.backrefedMem == 0 || (Config.USE_SUBEXP_CALL && env.numCall == 0)) {
setupCombExpCheck(root, 0);
diff --git a/src/org/joni/ArrayCompiler.java b/src/org/joni/ArrayCompiler.java
index 8b1d963..69b8909 100644
--- a/src/org/joni/ArrayCompiler.java
+++ b/src/org/joni/ArrayCompiler.java
@@ -1186,7 +1186,7 @@ final class ArrayCompiler extends Compiler {
break;
case NodeType.QTFR:
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ if (Config.USE_CEC) {
len = compileCECLengthQuantifierNode((QuantifierNode)node);
} else {
len = compileNonCECLengthQuantifierNode((QuantifierNode)node);
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index c0ede3d..0fc7349 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -20,6 +20,7 @@
package org.joni;
import static org.joni.BitStatus.bsAt;
+import static org.joni.Config.USE_CEC;
import static org.joni.Option.isFindCondition;
import static org.joni.Option.isFindLongest;
import static org.joni.Option.isFindNotEmpty;
@@ -231,8 +232,6 @@ class ByteCodeMachine extends StackMachine {
case OPCode.ANYCHAR_ML_STAR: opAnyCharMLStar(); break;
case OPCode.ANYCHAR_STAR_PEEK_NEXT: opAnyCharStarPeekNext(); break;
case OPCode.ANYCHAR_ML_STAR_PEEK_NEXT: opAnyCharMLStarPeekNext(); break;
- case OPCode.STATE_CHECK_ANYCHAR_STAR: opStateCheckAnyCharStar(); break;
- case OPCode.STATE_CHECK_ANYCHAR_ML_STAR:opStateCheckAnyCharMLStar();break;
case OPCode.WORD: opWord(); break;
case OPCode.NOT_WORD: opNotWord(); break;
@@ -279,11 +278,6 @@ class ByteCodeMachine extends StackMachine {
case OPCode.JUMP: opJump(); continue;
case OPCode.PUSH: opPush(); continue;
- // CEC
- case OPCode.STATE_CHECK_PUSH: opStateCheckPush(); continue;
- case OPCode.STATE_CHECK_PUSH_OR_JUMP: opStateCheckPushOrJump(); continue;
- case OPCode.STATE_CHECK: opStateCheck(); continue;
-
case OPCode.POP: opPop(); continue;
case OPCode.PUSH_OR_JUMP_EXACT1: opPushOrJumpExact1(); continue;
case OPCode.PUSH_IF_PEEK_NEXT: opPushIfPeekNext(); continue;
@@ -316,6 +310,12 @@ class ByteCodeMachine extends StackMachine {
case OPCode.FINISH: return finish();
case OPCode.FAIL: opFail(); continue;
+ case OPCode.STATE_CHECK_ANYCHAR_STAR: if (USE_CEC) {opStateCheckAnyCharStar(); break;}
+ case OPCode.STATE_CHECK_ANYCHAR_ML_STAR:if (USE_CEC) {opStateCheckAnyCharMLStar();break;}
+ case OPCode.STATE_CHECK_PUSH: if (USE_CEC) {opStateCheckPush(); continue;}
+ case OPCode.STATE_CHECK_PUSH_OR_JUMP: if (USE_CEC) {opStateCheckPushOrJump(); continue;}
+ case OPCode.STATE_CHECK: if (USE_CEC) {opStateCheck(); continue;}
+
default:
throw new InternalException(ErrorMessages.ERR_UNDEFINED_BYTECODE);
@@ -367,8 +367,6 @@ class ByteCodeMachine extends StackMachine {
case OPCode.ANYCHAR_ML_STAR: opAnyCharMLStarSb(); break;
case OPCode.ANYCHAR_STAR_PEEK_NEXT: opAnyCharStarPeekNextSb(); break;
case OPCode.ANYCHAR_ML_STAR_PEEK_NEXT: opAnyCharMLStarPeekNextSb(); break;
- case OPCode.STATE_CHECK_ANYCHAR_STAR: opStateCheckAnyCharStarSb(); break;
- case OPCode.STATE_CHECK_ANYCHAR_ML_STAR:opStateCheckAnyCharMLStarSb();break;
case OPCode.WORD: opWordSb(); break;
case OPCode.NOT_WORD: opNotWordSb(); break;
@@ -415,11 +413,6 @@ class ByteCodeMachine extends StackMachine {
case OPCode.JUMP: opJump(); continue;
case OPCode.PUSH: opPush(); continue;
- // CEC
- case OPCode.STATE_CHECK_PUSH: opStateCheckPush(); continue;
- case OPCode.STATE_CHECK_PUSH_OR_JUMP: opStateCheckPushOrJump(); continue;
- case OPCode.STATE_CHECK: opStateCheck(); continue;
-
case OPCode.POP: opPop(); continue;
case OPCode.PUSH_OR_JUMP_EXACT1: opPushOrJumpExact1(); continue;
case OPCode.PUSH_IF_PEEK_NEXT: opPushIfPeekNext(); continue;
@@ -455,6 +448,12 @@ class ByteCodeMachine extends StackMachine {
case OPCode.EXACT1_IC_SB: opExact1ICSb(); break;
case OPCode.EXACTN_IC_SB: opExactNICSb(); continue;
+ case OPCode.STATE_CHECK_ANYCHAR_STAR: if (USE_CEC) {opStateCheckAnyCharStarSb(); break;}
+ case OPCode.STATE_CHECK_ANYCHAR_ML_STAR:if (USE_CEC) {opStateCheckAnyCharMLStarSb();break;}
+ case OPCode.STATE_CHECK_PUSH: if (USE_CEC) {opStateCheckPush(); continue;}
+ case OPCode.STATE_CHECK_PUSH_OR_JUMP: if (USE_CEC) {opStateCheckPushOrJump(); continue;}
+ case OPCode.STATE_CHECK: if (USE_CEC) {opStateCheck(); continue;}
+
default:
throw new InternalException(ErrorMessages.ERR_UNDEFINED_BYTECODE);
@@ -1592,12 +1591,14 @@ class ByteCodeMachine extends StackMachine {
}
/* no need: IS_DYNAMIC_OPTION() == 0 */
+ @SuppressWarnings("unused")
private void opSetOptionPush() {
// option = code[ip++]; // final for now
pushAlt(ip, s, sprev, pkeep);
ip += OPSize.SET_OPTION + OPSize.FAIL;
}
+ @SuppressWarnings("unused")
private void opSetOption() {
// option = code[ip++]; // final for now
}
@@ -1956,7 +1957,7 @@ class ByteCodeMachine extends StackMachine {
sprev = e.getStatePStrPrev();
pkeep = e.getPKeep();
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ if (USE_CEC) {
if (((SCStackEntry)e).getStateCheck() != 0) {
e.type = STATE_CHECK_MARK;
stk++;
diff --git a/src/org/joni/Compiler.java b/src/org/joni/Compiler.java
index 6579218..d226946 100644
--- a/src/org/joni/Compiler.java
+++ b/src/org/joni/Compiler.java
@@ -150,7 +150,7 @@ abstract class Compiler implements ErrorMessages {
break;
case NodeType.QTFR:
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ if (Config.USE_CEC) {
compileCECQuantifierNode((QuantifierNode)node);
} else {
compileNonCECQuantifierNode((QuantifierNode)node);
diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java
index 97d594e..107551c 100644
--- a/src/org/joni/Config.java
+++ b/src/org/joni/Config.java
@@ -43,7 +43,7 @@ public interface Config extends org.jcodings.Config {
final boolean USE_WORD_BEGIN_END = true; /* "\<": word-begin, "\>": word-end */
final boolean USE_POSIX_API_REGION_OPTION = true; /* needed for POSIX API support */
final boolean USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE = true;
- final boolean USE_COMBINATION_EXPLOSION_CHECK = false;
+ final boolean USE_CEC = false;
final int NREGION = 10;
final int MAX_BACKREF_NUM = 1000;
diff --git a/src/org/joni/Matcher.java b/src/org/joni/Matcher.java
index d0b1d62..5d63442 100644
--- a/src/org/joni/Matcher.java
+++ b/src/org/joni/Matcher.java
@@ -97,7 +97,7 @@ public abstract class Matcher extends IntHolder {
public final int matchInterruptible(int at, int range, int option) throws InterruptedException {
msaInit(option, at);
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ if (Config.USE_CEC) {
int offset = at = str;
stateCheckBuffInit(end - str, offset, regex.numCombExpCheck); // move it to construction?
} // USE_COMBINATION_EXPLOSION_CHECK
@@ -374,7 +374,7 @@ public abstract class Matcher extends IntHolder {
prev = -1;
msaInit(option, start);
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) stateCheckBuffClear();
+ if (Config.USE_CEC) stateCheckBuffClear();
if (matchCheck(end, s, prev)) return match(s);
return mismatch();
@@ -385,7 +385,7 @@ public abstract class Matcher extends IntHolder {
if (Config.DEBUG_SEARCH) debugSearch(str, end, start, range);
msaInit(option, origStart);
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ if (Config.USE_CEC) {
int offset = Math.min(start, range) - str;
stateCheckBuffInit(end - str, offset, regex.numCombExpCheck);
}
diff --git a/src/org/joni/StackMachine.java b/src/org/joni/StackMachine.java
index a198ef1..b1280b4 100644
--- a/src/org/joni/StackMachine.java
+++ b/src/org/joni/StackMachine.java
@@ -20,6 +20,7 @@
package org.joni;
import static org.joni.BitStatus.bsAt;
+import static org.joni.Config.USE_CEC;
import java.lang.ref.WeakReference;
import java.util.Arrays;
@@ -66,7 +67,7 @@ abstract class StackMachine extends Matcher implements StackType {
private static StackEntry[] allocateStack() {
StackEntry[]stack = new StackEntry[Config.INIT_MATCH_STACK_SIZE];
- stack[0] = Config.USE_COMBINATION_EXPLOSION_CHECK ? new SCStackEntry() : new StackEntry();
+ stack[0] = USE_CEC ? new SCStackEntry() : new StackEntry();
return stack;
}
@@ -97,7 +98,7 @@ abstract class StackMachine extends Matcher implements StackType {
private final StackEntry ensure1() {
if (stk >= stack.length) doubleStack();
StackEntry e = stack[stk];
- if (e == null) stack[stk] = e = Config.USE_COMBINATION_EXPLOSION_CHECK ? new SCStackEntry() : new StackEntry();
+ if (e == null) stack[stk] = e = USE_CEC ? new SCStackEntry() : new StackEntry();
return e;
}
@@ -166,7 +167,7 @@ abstract class StackMachine extends Matcher implements StackType {
e.setStatePCode(pat);
e.setStatePStr(s);
e.setStatePStrPrev(prev);
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) ((SCStackEntry)e).setStateCheck(0);
+ if (USE_CEC) ((SCStackEntry)e).setStateCheck(0);
e.setPKeep(pkeep);
stk++;
}
@@ -175,7 +176,7 @@ abstract class StackMachine extends Matcher implements StackType {
StackEntry e = stack[stk];
e.type = type;
e.setStatePCode(pat);
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) ((SCStackEntry)e).setStateCheck(0);
+ if (USE_CEC) ((SCStackEntry)e).setStateCheck(0);
stk++;
}
@@ -185,7 +186,7 @@ abstract class StackMachine extends Matcher implements StackType {
e.setStatePCode(pat);
e.setStatePStr(s);
e.setStatePStrPrev(sprev);
- if (Config.USE_COMBINATION_EXPLOSION_CHECK) ((SCStackEntry)e).setStateCheck(stateCheckBuff != null ? snum : 0);
+ if (USE_CEC) ((SCStackEntry)e).setStateCheck(stateCheckBuff != null ? snum : 0);
e.setPKeep(pkeep);
stk++;
}
@@ -345,7 +346,7 @@ abstract class StackMachine extends Matcher implements StackType {
StackEntry e = stack[--stk];
if ((e.type & MASK_POP_USED) != 0) {
return e;
- } else if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ } else if (USE_CEC) {
if (e.type == STATE_CHECK_MARK) stateCheckMark();
}
}
@@ -359,7 +360,7 @@ abstract class StackMachine extends Matcher implements StackType {
} else if (e.type == MEM_START) {
repeatStk[memStartStk + e.getMemNum()] = e.getMemStart();
repeatStk[memEndStk + e.getMemNum()] = e.getMemEnd();
- } else if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ } else if (USE_CEC) {
if (e.type == STATE_CHECK_MARK) stateCheckMark();
}
}
@@ -374,7 +375,7 @@ abstract class StackMachine extends Matcher implements StackType {
} else if (e.type == MEM_END) {
repeatStk[memStartStk + e.getMemNum()] = e.getMemStart();
repeatStk[memEndStk + e.getMemNum()] = e.getMemEnd();
- } else if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
+ } else if (USE_CEC) {
if (e.type == STATE_CHECK_MARK) stateCheckMark();
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git
More information about the pkg-java-commits
mailing list