Skip to content

Commit 700826b

Browse files
committed
WIP
1 parent 8e42c0f commit 700826b

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ JAVA_DIR = "java/src/json/ext"
1616
JAVA_RAGEL_PATH = "#{JAVA_DIR}/ParserConfig.rl"
1717
JAVA_PARSER_SRC = "#{JAVA_DIR}/ParserConfig.java"
1818
JAVA_SOURCES = FileList["#{JAVA_DIR}/*.java"]
19+
JAVA_VEC_SOURCES = FileList["#{JAVA_DIR}/vectorized/*.java"]
1920
JAVA_CLASSES = []
2021
JRUBY_PARSER_JAR = File.expand_path("lib/json/ext/parser.jar")
2122
JRUBY_GENERATOR_JAR = File.expand_path("lib/json/ext/generator.jar")
@@ -68,7 +69,8 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
6869
classpath = (Dir['java/lib/*.jar'] << 'java/src' << JRUBY_JAR) * ':'
6970
obj = src.sub(/\.java\Z/, '.class')
7071
file obj => src do
71-
sh 'javac', '--enable-preview', '--add-modules', 'jdk.incubator.vector', '-classpath', classpath, '-source', '21', '-target', '21', src
72+
sh 'javac', '-classpath', classpath, '-source', '1.8', '-target', '1.8', src
73+
# '--enable-preview', '--add-modules', 'jdk.incubator.vector',
7274
end
7375
JAVA_CLASSES << obj
7476
end

java/src/json/ext/EscapeScanner.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,19 @@ static class State {
1515
}
1616

1717
static class VectorSupport {
18+
private static String VECTORIZED_ESCAPE_SCANNER_CLASS = "json.ext.vectorized.VectorizedEscapeScanner";
1819
static final EscapeScanner VECTORIZED_ESCAPE_SCANNER;
1920

2021
static {
21-
Optional<Module> vectorModule = ModuleLayer.boot().findModule("jdk.incubator.vector");
2222
EscapeScanner scanner = null;
23-
if (vectorModule.isPresent()) {
24-
try {
25-
Class<?> vectorEscapeScannerClass = EscapeScanner.class.getClassLoader().loadClass("json.ext.VectorizedEscapeScanner");
26-
Constructor<?> vectorizedEscapeScannerConstructor = vectorEscapeScannerClass.getDeclaredConstructor();
27-
scanner = (EscapeScanner) vectorizedEscapeScannerConstructor.newInstance();
28-
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
29-
// Fallback to the ScalarEscapeScanner if we cannot load the VectorizedEscapeScanner.
30-
System.err.println("Failed to load VectorizedEscapeScanner, falling back to ScalarEscapeScanner: " + e.getMessage());
31-
scanner = null;
32-
}
33-
23+
try {
24+
Class<?> vectorEscapeScannerClass = EscapeScanner.class.getClassLoader().loadClass(VECTORIZED_ESCAPE_SCANNER_CLASS);
25+
Constructor<?> vectorizedEscapeScannerConstructor = vectorEscapeScannerClass.getDeclaredConstructor();
26+
scanner = (EscapeScanner) vectorizedEscapeScannerConstructor.newInstance();
27+
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
28+
// Fallback to the ScalarEscapeScanner if we cannot load the VectorizedEscapeScanner.
29+
System.err.println("Failed to load VectorizedEscapeScanner, falling back to ScalarEscapeScanner: " + e.getMessage());
30+
scanner = null;
3431
}
3532
VECTORIZED_ESCAPE_SCANNER = scanner;
3633
}

java/src/json/ext/StringEncoder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
import org.jruby.util.ByteList;
2222
import org.jruby.util.StringSupport;
2323

24-
import jdk.incubator.vector.ByteVector;
25-
import jdk.incubator.vector.VectorSpecies;
26-
import json.ext.VectorizedEscapeScanner;
27-
2824
/**
2925
* An encoder that reads from the given source and outputs its representation
3026
* to another ByteList. The source string is fully checked for UTF-8 validity,

java/src/json/ext/VectorizedEscapeScanner.java renamed to java/src/json/ext/vectorized/VectorizedEscapeScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package json.ext;
1+
package json.ext.vectorized;
22

33
import java.io.IOException;
44

0 commit comments

Comments
 (0)