Skip to content

Commit 33a9205

Browse files
committed
Make the marking service cache size configuratble.
1 parent df10d7a commit 33a9205

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/main/java/org/truffleruby/core/MarkingService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public ReferenceProcessingService<MarkerReference> service() {
7979
}
8080
}
8181

82-
private static final int KEPT_COUNT_SIZE = 10_000;
82+
private final int cacheSize = context.getOptions().CEXTS_MARKING_CACHE;
8383

8484
private final ThreadLocal<Deque<ArrayList<Object>>> stackPreservation = ThreadLocal.withInitial(() -> new ArrayDeque<>());
8585

86-
private Object[] keptObjects = new Object[KEPT_COUNT_SIZE];
86+
private Object[] keptObjects = new Object[cacheSize];
8787

8888
private int counter = 0;
8989

@@ -104,10 +104,10 @@ private synchronized Object[] addToKeptObjects(Object object) {
104104
keepList.add(object);
105105
}
106106
keptObjects[counter++] = object;
107-
if (counter == KEPT_COUNT_SIZE) {
107+
if (counter == cacheSize) {
108108
counter = 0;
109109
Object[] tmp = keptObjects;
110-
keptObjects = new Object[KEPT_COUNT_SIZE];
110+
keptObjects = new Object[cacheSize];
111111
return tmp;
112112
}
113113
return null;
@@ -123,6 +123,12 @@ public void popStackPreservationFrame() {
123123
stackPreservation.get().pop();
124124
}
125125

126+
public synchronized void runMarkersAndDropKeptList() {
127+
Object[] tmp = keptObjects;
128+
keptObjects = new Object[cacheSize];
129+
runAllMarkers();
130+
}
131+
126132
private synchronized void runAllMarkers() {
127133
MarkerReference currentMarker = getFirst();
128134
MarkerReference nextMarker;

src/main/java/org/truffleruby/options/Options.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public class Options {
145145
public final boolean CEXTS_LOG_LOAD;
146146
public final boolean CEXTS_LOG_WARNINGS;
147147
public final String[] CEXTS_LIBRARY_REMAP;
148+
public final int CEXTS_MARKING_CACHE;
148149
public final boolean LOG_DYNAMIC_CONSTANT_LOOKUP;
149150
public final boolean OPTIONS_LOG;
150151
public final boolean LOG_LOAD;
@@ -273,6 +274,7 @@ public class Options {
273274
CEXTS_LOG_LOAD = builder.getOrDefault(OptionsCatalog.CEXTS_LOG_LOAD);
274275
CEXTS_LOG_WARNINGS = builder.getOrDefault(OptionsCatalog.CEXTS_LOG_WARNINGS);
275276
CEXTS_LIBRARY_REMAP = builder.getOrDefault(OptionsCatalog.CEXTS_LIBRARY_REMAP);
277+
CEXTS_MARKING_CACHE = builder.getOrDefault(OptionsCatalog.CEXTS_MARKING_CACHE);
276278
LOG_DYNAMIC_CONSTANT_LOOKUP = builder.getOrDefault(OptionsCatalog.LOG_DYNAMIC_CONSTANT_LOOKUP);
277279
OPTIONS_LOG = builder.getOrDefault(OptionsCatalog.OPTIONS_LOG);
278280
LOG_LOAD = builder.getOrDefault(OptionsCatalog.LOG_LOAD);
@@ -523,6 +525,8 @@ public Object fromDescription(OptionDescription<?> description) {
523525
return CEXTS_LOG_WARNINGS;
524526
case "ruby.cexts.remap":
525527
return CEXTS_LIBRARY_REMAP;
528+
case "ruby.cexts.marking.cache":
529+
return CEXTS_MARKING_CACHE;
526530
case "ruby.constant.dynamic_lookup.log":
527531
return LOG_DYNAMIC_CONSTANT_LOOKUP;
528532
case "ruby.options.log":

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ public class OptionsCatalog {
616616
"Remap the name of native libraries, written in the form libexample.so:/path/to/actual/libexample.so",
617617
null,
618618
new String[]{});
619+
public static final IntegerOptionDescription CEXTS_MARKING_CACHE = new IntegerOptionDescription(
620+
"ruby.cexts.marking.cache",
621+
"Number of objects converted to native handles before the marker is run",
622+
null,
623+
100);
619624
public static final BooleanOptionDescription LOG_DYNAMIC_CONSTANT_LOOKUP = new BooleanOptionDescription(
620625
"ruby.constant.dynamic_lookup.log",
621626
"Log source code positions where dynamic constant lookup is performed",
@@ -889,6 +894,8 @@ public static OptionDescription<?> fromName(String name) {
889894
return CEXTS_LOG_WARNINGS;
890895
case "ruby.cexts.remap":
891896
return CEXTS_LIBRARY_REMAP;
897+
case "ruby.cexts.marking.cache":
898+
return CEXTS_MARKING_CACHE;
892899
case "ruby.constant.dynamic_lookup.log":
893900
return LOG_DYNAMIC_CONSTANT_LOOKUP;
894901
case "ruby.options.log":
@@ -930,6 +937,7 @@ public static OptionDescription<?>[] allDescriptions() {
930937
CEXT_LOCK,
931938
CEXTS_LOG_LOAD,
932939
CEXTS_LOG_WARNINGS,
940+
CEXTS_MARKING_CACHE,
933941
CEXTS_LIBRARY_REMAP,
934942
CLASS_CACHE,
935943
CLONE_DEFAULT,

tool/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ CEXTS: [cexts, boolean, true, Enable use of C extensions]
136136
CEXTS_LOG_LOAD: [cexts.log.load, boolean, false, Log loading of cexts]
137137
CEXTS_LOG_WARNINGS: [cexts.log.warnings, boolean, false, Log cexts warnings]
138138
CEXTS_LIBRARY_REMAP: [cexts.remap, string-array, [], 'Remap the name of native libraries, written in the form libexample.so:/path/to/actual/libexample.so']
139+
CEXTS_MARKING_CACHE: [cexts.marking.cache, integer, 100, 'Number of objects converted to native handles before the marker is run']
139140

140141
LOG_DYNAMIC_CONSTANT_LOOKUP: [constant.dynamic_lookup.log, boolean, false, Log source code positions where dynamic constant lookup is performed]
141142

0 commit comments

Comments
 (0)