Skip to content

Commit 0c23664

Browse files
feli-citascommit-bot@chromium.org
authored andcommitted
[vm/fuzzer] Reduce number of methods per class
Rationale: Decrease avarage runtime. Change-Id: Ia6821c82942eb06efbc09025e667fa0a84b3b6ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117641 Reviewed-by: Aart Bik <[email protected]> Commit-Queue: Felicitas Hetzelt <[email protected]>
1 parent 3135eb5 commit 0c23664

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

runtime/tools/dartfuzz/dartfuzz.dart

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ import 'dartfuzz_ffiapi.dart';
1414
// Version of DartFuzz. Increase this each time changes are made
1515
// to preserve the property that a given version of DartFuzz yields
1616
// the same fuzzed program for a deterministic random seed.
17-
const String version = '1.46';
17+
const String version = '1.47';
1818

1919
// Restriction on statements and expressions.
20-
const int stmtLength = 2;
2120
const int stmtDepth = 1;
2221
const int exprDepth = 2;
22+
const int numStatements = 2;
23+
const int numGlobalVars = 4;
24+
const int numLocalVars = 4;
25+
const int numGlobalMethods = 4;
26+
const int numClassMethods = 3;
27+
const int numMethodParams = 4;
28+
const int numClasses = 4;
2329

2430
// Naming conventions.
2531
const varName = 'var';
@@ -123,17 +129,22 @@ class DartFuzz {
123129
// Setup the types.
124130
localVars = <DartType>[];
125131
iterVars = <String>[];
126-
globalVars = fillTypes1();
132+
133+
globalVars = fillTypes1(limit: numGlobalVars);
127134
globalVars.addAll(DartType.allTypes); // always one each
128-
globalMethods = fillTypes2();
129-
classFields = fillTypes2(limit: 4);
130-
classMethods = fillTypes3(classFields.length);
135+
globalMethods =
136+
fillTypes2(limit2: numGlobalMethods, limit1: numMethodParams);
137+
classFields = fillTypes2(limit2: numClasses, limit1: numLocalVars);
138+
classMethods = fillTypes3(classFields.length,
139+
limit2: numClassMethods, limit1: numMethodParams);
140+
131141
virtualClassMethods = <Map<int, List<int>>>[];
132142
classParents = <int>[];
133143
// Setup optional ffi methods and types.
134144
final ffiStatus = <bool>[for (final _ in globalMethods) false];
135145
if (ffi) {
136-
List<List<DartType>> globalMethodsFfi = fillTypes2(isFfi: true);
146+
List<List<DartType>> globalMethodsFfi = fillTypes2(
147+
limit2: numGlobalMethods, limit1: numMethodParams, isFfi: true);
137148
for (var m in globalMethodsFfi) {
138149
globalMethods.add(m);
139150
ffiStatus.add(true);
@@ -769,7 +780,7 @@ class DartFuzz {
769780

770781
// Emit statements. Returns true if code may fall-through.
771782
bool emitStatements(int depth) {
772-
int s = 1 + rand.nextInt(stmtLength);
783+
int s = 1 + rand.nextInt(numStatements);
773784
for (int i = 0; i < s; i++) {
774785
if (!emitStatement(depth)) {
775786
return false; // rest would be dead code
@@ -1427,9 +1438,9 @@ class DartFuzz {
14271438
}
14281439
}
14291440

1430-
List<DartType> fillTypes1({bool isFfi = false}) {
1441+
List<DartType> fillTypes1({int limit = 4, bool isFfi = false}) {
14311442
final list = <DartType>[];
1432-
for (int i = 0, n = 1 + rand.nextInt(4); i < n; i++) {
1443+
for (int i = 0, n = 1 + rand.nextInt(limit); i < n; i++) {
14331444
if (isFfi) {
14341445
list.add(fp ? oneOf([DartType.INT, DartType.DOUBLE]) : DartType.INT);
14351446
} else {
@@ -1439,18 +1450,20 @@ class DartFuzz {
14391450
return list;
14401451
}
14411452

1442-
List<List<DartType>> fillTypes2({bool isFfi = false, int limit = 4}) {
1453+
List<List<DartType>> fillTypes2(
1454+
{bool isFfi = false, int limit2 = 4, int limit1 = 4}) {
14431455
final list = <List<DartType>>[];
1444-
for (int i = 0, n = 1 + rand.nextInt(limit); i < n; i++) {
1445-
list.add(fillTypes1(isFfi: isFfi));
1456+
for (int i = 0, n = 1 + rand.nextInt(limit2); i < n; i++) {
1457+
list.add(fillTypes1(limit: limit1, isFfi: isFfi));
14461458
}
14471459
return list;
14481460
}
14491461

1450-
List<List<List<DartType>>> fillTypes3(int n) {
1462+
List<List<List<DartType>>> fillTypes3(int n,
1463+
{int limit2 = 4, int limit1 = 4}) {
14511464
final list = <List<List<DartType>>>[];
14521465
for (int i = 0; i < n; i++) {
1453-
list.add(fillTypes2());
1466+
list.add(fillTypes2(limit2: limit2, limit1: limit1));
14541467
}
14551468
return list;
14561469
}

0 commit comments

Comments
 (0)