summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/fuzzer
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-02-07 08:58:36 -0800
committerCliff Click <cliffc@acm.org>2025-02-07 08:58:36 -0800
commit2aa8c5d1d0659bd1c828134f1a1f14d025a2d0f1 (patch)
tree0532f3ba5d74de006fcaa906dad9b787ebb06e2e /src/test/java/com/seaofnodes/simple/fuzzer
parent68dc63b9390bbe4ec50cc1b814d4e559e459c057 (diff)
downloadSimple-linear-chapter19.tar.gz
Simple-linear-chapter19.zip
Ch# Chapter 19: Instruction Selection and Portable Compilationlinear-chapter19
Co-authored-by: hadha <helsgithub15@gmail.com> Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/fuzzer')
-rw-r--r--src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java19
-rw-r--r--src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java34
-rw-r--r--src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java16
3 files changed, 15 insertions, 54 deletions
diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index f57a0031..f7e0c4ad 100644
--- a/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -82,10 +82,10 @@ public class Fuzzer {
private static void runCheck(String script, boolean valid) {
CodeGen code1;
try {
- code1 = FuzzerUtils.parse(script, false);
+ code1 = FuzzerUtils.parse(script, 123);
} catch (RuntimeException e1) {
try {
- FuzzerUtils.parse(script, true);
+ FuzzerUtils.parse(script, 456);
} catch (RuntimeException e2) {
if (FuzzerUtils.isExceptionFromSameCause(e1, e2)) {
if (!valid || e1.getClass() == Parser.ParseException.class) return;
@@ -95,7 +95,7 @@ public class Fuzzer {
}
throw e1;
}
- CodeGen code2 = FuzzerUtils.parse(script, true);
+ CodeGen code2 = FuzzerUtils.parse(script, 456);
checkGraphs(code1, code2, 0);
checkGraphs(code1, code2, 1);
checkGraphs(code1, code2, 10);
@@ -126,17 +126,16 @@ public class Fuzzer {
var code = new CodeGen(sb.toString());
code.parse();
- int parse_peeps= Node.ITER_CNT;
- int parse_nops = Node.ITER_NOP_CNT;
+ int nids = code.UID();
+ if( nids <= max_nids ) return max_nids; // Smaller, looking for trends as we grow
+ int parse_peeps= code._iter_cnt;
+ int parse_nops = code._iter_nop_cnt;
double parse_nop_ratio = (double)parse_nops/parse_peeps;
- int nids = Node.UID();
- if( nids <= max_nids ) return max_nids;
-
double parse_peeps_per_node = (double)parse_peeps/nids;
code.opto();
- int iter_peeps= Node.ITER_CNT;
- int iter_nops = Node.ITER_NOP_CNT;
+ int iter_peeps= code._iter_cnt;
+ int iter_nops = code._iter_nop_cnt;
double iter_nop_ratio = (double)iter_nops/iter_peeps;
double iter_peeps_per_node = (double)iter_peeps/nids;
diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java b/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java
index 62a149a8..0781ad67 100644
--- a/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java
+++ b/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java
@@ -4,6 +4,7 @@ import com.seaofnodes.simple.CodeGen;
import com.seaofnodes.simple.IterPeeps;
import com.seaofnodes.simple.node.Node;
import com.seaofnodes.simple.node.StopNode;
+import com.seaofnodes.simple.type.TypeInteger;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.invoke.MethodHandle;
@@ -47,31 +48,10 @@ class FuzzerUtils {
}
/**
- * Copy of Node.WVISIST
- * Used to clear as exceptions might happen in the walk and left this bitset not cleared
- */
- private static final BitSet NodeWalkVisit;
-
- /**
- * Write access to Iterate.MID_ASSERT
- * Exception could happen mid assert and left this at true. Used to reset to false prior to parsing.
- */
- private static final MethodHandle set_MID_ASSERT;
-
- /**
* Some problems might trigger debug output. Suppress this output with a null print stream during fuzzing.
*/
public static final PrintStream NULL_PRINT_STREAM = new PrintStream(OutputStream.nullOutputStream());
- static {
- try {
- NodeWalkVisit = getFieldValue(Node.class, "WVISIT");
- set_MID_ASSERT = MethodHandles.lookup().unreflectSetter(getField( IterPeeps.class, "MID_ASSERT"));
- } catch (Exception e) {
- throw new ExceptionInInitializerError(e);
- }
- }
-
/**
* Check that the messages are similar.
*/
@@ -114,21 +94,15 @@ class FuzzerUtils {
/**
* Parse script with peepholes enabled or disabled
*/
- public static CodeGen parse(String script, boolean runPeeps) {
+ public static CodeGen parse(String script, long workListSeed) {
var err = System.err;
var out = System.out;
try {
System.setErr(NULL_PRINT_STREAM);
System.setOut(NULL_PRINT_STREAM);
- try {
- set_MID_ASSERT.invokeExact(false);
- } catch (Throwable e) {
- throw rethrow(e);
- }
- var code = new CodeGen(script);
- return code.parse(!runPeeps).opto().typeCheck().GCM().localSched();
+ var code = new CodeGen(script, TypeInteger.BOT, workListSeed);
+ return code.parse().opto().typeCheck().GCM().localSched();
} finally {
- NodeWalkVisit.clear();
System.setErr(err);
System.setOut(out);
}
diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java
index 86dbe66a..f119fa1a 100644
--- a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java
+++ b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java
@@ -3,12 +3,13 @@ package com.seaofnodes.simple.fuzzer;
import com.seaofnodes.simple.Parser;
import com.seaofnodes.simple.node.ScopeNode;
import com.seaofnodes.simple.type.TypeInteger;
-
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.function.Predicate;
+import static com.seaofnodes.simple.Parser.KEYWORDS;
+
/**
* Generate a pseudo random script.
@@ -34,18 +35,6 @@ public class ScriptGenerator {
* Valid characters for identifiers. The last 10 are not valid for the first character.
*/
private static final String VAR_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
- /**
- * List of keywords not valid for identifiers.
- */
- private static final HashSet<String> KEYWORDS;
-
- static {
- try {
- KEYWORDS = FuzzerUtils.getFieldValue(new Parser(""), "KEYWORDS");
- } catch (Throwable e) {
- throw new ExceptionInInitializerError(e);
- }
- }
/**
* Flag for a statement that it does not pass on control flow to the next statement.
@@ -108,7 +97,6 @@ public class ScriptGenerator {
private static final List<TypeInt> INTTYPES = new ArrayList<>();
static {
- new Parser("", TypeInteger.BOT);
for( var e : Parser.defaultTypes().entrySet() ) {
if( e.getValue() instanceof TypeInteger ) {
INTTYPES.add(new TypeInt(e.getKey()));