Skip to content

Commit 06caf7d

Browse files
committed
[GR-58993] Atomics.pause: Limit the number of spin-wait loop iterations.
PullRequest: js/3336
2 parents e614065 + 059b7fc commit 06caf7d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/AtomicsBuiltins.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ protected Object doGeneric(VirtualFrame frame, Object maybeTarget, Object index,
12741274
@ImportStatic({JSRuntime.class})
12751275
public abstract static class AtomicsPauseNode extends JSBuiltinNode {
12761276

1277+
private static final int MAX_SPIN_WAIT = 1024;
1278+
12771279
protected AtomicsPauseNode(JSContext context, JSBuiltin builtin) {
12781280
super(context, builtin);
12791281
}
@@ -1287,7 +1289,8 @@ protected static Object pauseOnce(Object n) {
12871289

12881290
@Specialization
12891291
protected static Object pauseInt(int n) {
1290-
for (int i = 0; i < n; i++) {
1292+
int iterations = Math.min(n, MAX_SPIN_WAIT);
1293+
for (int i = 0; i < iterations; i++) {
12911294
Thread.onSpinWait();
12921295
}
12931296
return Undefined.instance;

0 commit comments

Comments
 (0)