aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannesw <none@none>2014-05-06 12:38:12 +0200
committerhannesw <none@none>2014-05-06 12:38:12 +0200
commit67726fbf7d0d142b5d436dfede4c3f79a2b82be4 (patch)
tree85dfd6c0e9524a53e2d9e069654dfb2d3e987432 /src
parent4ae14685521e0b8db04d64ba1a75371889d437db (diff)
downloadnashorn-67726fbf7d0d142b5d436dfede4c3f79a2b82be4.tar.gz
8041998: RegExp implementation is not thread-safe
Reviewed-by: lagergren, sundar, attila
Diffstat (limited to 'src')
-rw-r--r--src/jdk/nashorn/internal/runtime/regexp/JdkRegExp.java12
-rw-r--r--src/jdk/nashorn/internal/runtime/regexp/JoniRegExp.java12
-rw-r--r--src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java14
3 files changed, 11 insertions, 27 deletions
diff --git a/src/jdk/nashorn/internal/runtime/regexp/JdkRegExp.java b/src/jdk/nashorn/internal/runtime/regexp/JdkRegExp.java
index 9250331d..f5158021 100644
--- a/src/jdk/nashorn/internal/runtime/regexp/JdkRegExp.java
+++ b/src/jdk/nashorn/internal/runtime/regexp/JdkRegExp.java
@@ -46,9 +46,6 @@ public class JdkRegExp extends RegExp {
/** Java regexp pattern to use for match. We compile to one of these */
private Pattern pattern;
- /** The matcher */
- private RegExpMatcher matcher;
-
/**
* Construct a Regular expression from the given {@code source} and {@code flags} strings.
*
@@ -95,14 +92,7 @@ public class JdkRegExp extends RegExp {
return null; // never matches or similar, e.g. a[]
}
- RegExpMatcher currentMatcher = this.matcher;
-
- if (currentMatcher == null || matcher.getInput() != str) {
- currentMatcher = new DefaultMatcher(str);
- this.matcher = currentMatcher;
- }
-
- return currentMatcher;
+ return new DefaultMatcher(str);
}
class DefaultMatcher implements RegExpMatcher {
diff --git a/src/jdk/nashorn/internal/runtime/regexp/JoniRegExp.java b/src/jdk/nashorn/internal/runtime/regexp/JoniRegExp.java
index 5ff98ac5..47dbd7c4 100644
--- a/src/jdk/nashorn/internal/runtime/regexp/JoniRegExp.java
+++ b/src/jdk/nashorn/internal/runtime/regexp/JoniRegExp.java
@@ -44,9 +44,6 @@ public class JoniRegExp extends RegExp {
/** Compiled Joni Regex */
private Regex regex;
- /** Matcher */
- private RegExpMatcher matcher;
-
/**
* Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
*
@@ -95,14 +92,7 @@ public class JoniRegExp extends RegExp {
return null;
}
- RegExpMatcher currentMatcher = this.matcher;
-
- if (currentMatcher == null || input != currentMatcher.getInput()) {
- currentMatcher = new JoniMatcher(input);
- this.matcher = currentMatcher;
- }
-
- return currentMatcher;
+ return new JoniMatcher(input);
}
/**
diff --git a/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java b/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
index 360c11eb..91117d1d 100644
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
+++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
@@ -131,12 +131,13 @@ public final class Regex implements RegexState {
this.warnings = null;
}
- public void compile() {
+ public synchronized MatcherFactory compile() {
if (factory == null && analyser != null) {
- Compiler compiler = new ArrayCompiler(analyser);
+ new ArrayCompiler(analyser).compile();
analyser = null; // only do this once
- compiler.compile();
}
+ assert factory != null;
+ return factory;
}
public Matcher matcher(char[] chars) {
@@ -144,8 +145,11 @@ public final class Regex implements RegexState {
}
public Matcher matcher(char[] chars, int p, int end) {
- compile();
- return factory.create(this, chars, p, end);
+ MatcherFactory matcherFactory = factory;
+ if (matcherFactory == null) {
+ matcherFactory = compile();
+ }
+ return matcherFactory.create(this, chars, p, end);
}
public WarnCallback getWarnings() {