Skip to content

Commit d8b1553

Browse files
committed
[GR-64109] SVM: Redundant computation in JavaThreads::getCurrentThreadId when assertion is off
PullRequest: graal/20514
2 parents 226ded6 + 45714c2 commit d8b1553

File tree

1 file changed

+6
-2
lines changed
  • substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread

1 file changed

+6
-2
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -439,7 +439,11 @@ static void blockedOn(Target_sun_nio_ch_Interruptible b) {
439439
public static long getCurrentThreadId() {
440440
long id = currentVThreadId.get();
441441
if (GraalDirectives.inIntrinsic()) {
442-
ReplacementsUtil.dynamicAssert(id != 0 && id == getThreadId(Thread.currentThread()), "ids must match");
442+
// The condition may throw so we must manually wrap the assert in this if, otherwise the
443+
// compiler is not allowed to remove the evaluation
444+
if (ReplacementsUtil.REPLACEMENTS_ASSERTIONS_ENABLED) {
445+
ReplacementsUtil.dynamicAssert(id != 0 && id == getThreadId(Thread.currentThread()), "ids must match");
446+
}
443447
} else {
444448
assert id != 0 && id == getThreadId(Thread.currentThread());
445449
}

0 commit comments

Comments
 (0)