Skip to content

Commit a75bc7a

Browse files
authored
chore: Make code compiles on JDK 23 (#1726)
1 parent b20ec82 commit a75bc7a

File tree

9 files changed

+69
-46
lines changed

9 files changed

+69
-46
lines changed

actor/src/main/scala/org/apache/pekko/actor/LightArrayRevolverScheduler.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ class LightArrayRevolverScheduler(config: Config, log: LoggingAdapter, threadFac
356356

357357
object LightArrayRevolverScheduler {
358358
@nowarn("msg=deprecated")
359-
private[this] val taskOffset = unsafe.objectFieldOffset(classOf[TaskHolder].getDeclaredField("task"))
359+
private[this] val taskOffset =
360+
unsafe.objectFieldOffset(classOf[TaskHolder].getDeclaredField("task")): @nowarn("cat=deprecation")
360361

361362
private class TaskQueue extends AbstractNodeQueue[TaskHolder]
362363

@@ -375,7 +376,8 @@ object LightArrayRevolverScheduler {
375376
private final def extractTask(replaceWith: Runnable): Runnable =
376377
task match {
377378
case t @ (ExecutedTask | CancelledTask) => t
378-
case x => if (unsafe.compareAndSwapObject(this, taskOffset, x, replaceWith)) x else extractTask(replaceWith)
379+
case x => if (unsafe.compareAndSwapObject(this, taskOffset, x, replaceWith): @nowarn("cat=deprecation")) x
380+
else extractTask(replaceWith)
379381
}
380382

381383
private[pekko] final def executeTask(): Boolean = extractTask(ExecutedTask) match {

actor/src/main/scala/org/apache/pekko/actor/RepointableActorRef.scala

+9-5
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,21 @@ private[pekko] class RepointableActorRef(
6666
_lookupDoNotCallMeDirectly
6767
}
6868

69-
def underlying: Cell = Unsafe.instance.getObjectVolatile(this, cellOffset).asInstanceOf[Cell]
70-
def lookup = Unsafe.instance.getObjectVolatile(this, lookupOffset).asInstanceOf[Cell]
69+
def underlying: Cell =
70+
Unsafe.instance.getObjectVolatile(this, cellOffset).asInstanceOf[Cell]: @nowarn("cat=deprecation")
71+
def lookup = Unsafe.instance.getObjectVolatile(this, lookupOffset).asInstanceOf[Cell]: @nowarn("cat=deprecation")
7172

72-
@tailrec final def swapCell(next: Cell): Cell = {
73+
@tailrec
74+
final def swapCell(next: Cell): Cell = {
7375
val old = underlying
74-
if (Unsafe.instance.compareAndSwapObject(this, cellOffset, old, next)) old else swapCell(next)
76+
if (Unsafe.instance.compareAndSwapObject(this, cellOffset, old, next): @nowarn("cat=deprecation")) old
77+
else swapCell(next)
7578
}
7679

7780
@tailrec final def swapLookup(next: Cell): Cell = {
7881
val old = lookup
79-
if (Unsafe.instance.compareAndSwapObject(this, lookupOffset, old, next)) old else swapLookup(next)
82+
if (Unsafe.instance.compareAndSwapObject(this, lookupOffset, old, next): @nowarn("cat=deprecation")) old
83+
else swapLookup(next)
8084
}
8185

8286
/**

actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala

+15-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ private[pekko] trait Children { this: ActorCell =>
3838
private var _childrenRefsDoNotCallMeDirectly: ChildrenContainer = EmptyChildrenContainer
3939

4040
def childrenRefs: ChildrenContainer =
41-
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.childrenOffset).asInstanceOf[ChildrenContainer]
41+
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.childrenOffset).asInstanceOf[ChildrenContainer]: @nowarn(
42+
"cat=deprecation")
4243

4344
final def children: immutable.Iterable[ActorRef] = childrenRefs.children
4445
@nowarn("msg=deprecated")
@@ -65,7 +66,8 @@ private[pekko] trait Children { this: ActorCell =>
6566

6667
@nowarn @volatile private var _functionRefsDoNotCallMeDirectly = Map.empty[String, FunctionRef]
6768
private def functionRefs: Map[String, FunctionRef] =
68-
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.functionRefsOffset).asInstanceOf[Map[String, FunctionRef]]
69+
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.functionRefsOffset).asInstanceOf[Map[String,
70+
FunctionRef]]: @nowarn("cat=deprecation")
6971

7072
private[pekko] def getFunctionRefOrNobody(name: String, uid: Int = ActorCell.undefinedUid): InternalActorRef =
7173
functionRefs.getOrElse(name, Children.GetNobody()) match {
@@ -84,7 +86,8 @@ private[pekko] trait Children { this: ActorCell =>
8486
@tailrec def rec(): Unit = {
8587
val old = functionRefs
8688
val added = old.updated(childPath.name, ref)
87-
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.functionRefsOffset, old, added)) rec()
89+
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.functionRefsOffset, old, added): @nowarn(
90+
"cat=deprecation")) rec()
8891
}
8992
rec()
9093

@@ -99,7 +102,8 @@ private[pekko] trait Children { this: ActorCell =>
99102
if (!old.contains(name)) false
100103
else {
101104
val removed = old - name
102-
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.functionRefsOffset, old, removed)) rec()
105+
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.functionRefsOffset, old, removed): @nowarn(
106+
"cat=deprecation")) rec()
103107
else {
104108
ref.stop()
105109
true
@@ -112,17 +116,17 @@ private[pekko] trait Children { this: ActorCell =>
112116
protected def stopFunctionRefs(): Unit = {
113117
val refs = Unsafe.instance
114118
.getAndSetObject(this, AbstractActorCell.functionRefsOffset, Map.empty)
115-
.asInstanceOf[Map[String, FunctionRef]]
119+
.asInstanceOf[Map[String, FunctionRef]]: @nowarn("cat=deprecation")
116120
refs.valuesIterator.foreach(_.stop())
117121
}
118122

119123
@nowarn @volatile private var _nextNameDoNotCallMeDirectly = 0L
120124
final protected def randomName(sb: java.lang.StringBuilder): String = {
121-
val num = Unsafe.instance.getAndAddLong(this, AbstractActorCell.nextNameOffset, 1)
125+
val num = Unsafe.instance.getAndAddLong(this, AbstractActorCell.nextNameOffset, 1): @nowarn("cat=deprecation")
122126
Helpers.base64(num, sb)
123127
}
124128
final protected def randomName(): String = {
125-
val num = Unsafe.instance.getAndAddLong(this, AbstractActorCell.nextNameOffset, 1)
129+
val num = Unsafe.instance.getAndAddLong(this, AbstractActorCell.nextNameOffset, 1): @nowarn("cat=deprecation")
126130
Helpers.base64(num)
127131
}
128132

@@ -151,7 +155,8 @@ private[pekko] trait Children { this: ActorCell =>
151155
* low level CAS helpers
152156
*/
153157
private final def swapChildrenRefs(oldChildren: ChildrenContainer, newChildren: ChildrenContainer): Boolean =
154-
Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.childrenOffset, oldChildren, newChildren)
158+
Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.childrenOffset, oldChildren, newChildren): @nowarn(
159+
"cat=deprecation")
155160

156161
@tailrec final def reserveChild(name: String): Boolean = {
157162
val c = childrenRefs
@@ -184,7 +189,8 @@ private[pekko] trait Children { this: ActorCell =>
184189
}
185190

186191
final protected def setTerminated(): Unit =
187-
Unsafe.instance.putObjectVolatile(this, AbstractActorCell.childrenOffset, TerminatedChildrenContainer)
192+
Unsafe.instance.putObjectVolatile(this, AbstractActorCell.childrenOffset, TerminatedChildrenContainer): @nowarn(
193+
"cat=deprecation")
188194

189195
/*
190196
* ActorCell-internal API

actor/src/main/scala/org/apache/pekko/actor/dungeon/Dispatch.scala

+6-3
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ private[pekko] trait Dispatch { this: ActorCell =>
5353
}
5454

5555
final def mailbox: Mailbox =
56-
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.mailboxOffset).asInstanceOf[Mailbox]
56+
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.mailboxOffset).asInstanceOf[Mailbox]: @nowarn(
57+
"cat=deprecation")
5758

58-
@tailrec final def swapMailbox(newMailbox: Mailbox): Mailbox = {
59+
@tailrec
60+
final def swapMailbox(newMailbox: Mailbox): Mailbox = {
5961
val oldMailbox = mailbox
60-
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.mailboxOffset, oldMailbox, newMailbox))
62+
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.mailboxOffset, oldMailbox, newMailbox): @nowarn(
63+
"cat=deprecation"))
6164
swapMailbox(newMailbox)
6265
else oldMailbox
6366
}

actor/src/main/scala/org/apache/pekko/dispatch/AbstractDispatcher.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ abstract class MessageDispatcher(val configurator: MessageDispatcherConfigurator
124124
}
125125

126126
private final def addInhabitants(add: Long): Long = {
127-
val old = Unsafe.instance.getAndAddLong(this, inhabitantsOffset, add)
127+
val old = Unsafe.instance.getAndAddLong(this, inhabitantsOffset, add): @nowarn("cat=deprecation")
128128
val ret = old + add
129129
if (ret < 0) {
130130
// We haven't succeeded in decreasing the inhabitants yet but the simple fact that we're trying to
@@ -136,11 +136,12 @@ abstract class MessageDispatcher(val configurator: MessageDispatcherConfigurator
136136
ret
137137
}
138138

139-
final def inhabitants: Long = Unsafe.instance.getLongVolatile(this, inhabitantsOffset)
139+
final def inhabitants: Long = Unsafe.instance.getLongVolatile(this, inhabitantsOffset): @nowarn("cat=deprecation")
140140

141-
private final def shutdownSchedule: Int = Unsafe.instance.getIntVolatile(this, shutdownScheduleOffset)
141+
private final def shutdownSchedule: Int =
142+
Unsafe.instance.getIntVolatile(this, shutdownScheduleOffset): @nowarn("cat=deprecation")
142143
private final def updateShutdownSchedule(expect: Int, update: Int): Boolean =
143-
Unsafe.instance.compareAndSwapInt(this, shutdownScheduleOffset, expect, update)
144+
Unsafe.instance.compareAndSwapInt(this, shutdownScheduleOffset, expect, update): @nowarn("cat=deprecation")
144145

145146
/**
146147
* Creates and returns a mailbox for the given actor.

actor/src/main/scala/org/apache/pekko/dispatch/Mailbox.scala

+13-12
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ import java.util.{ Comparator, Deque, PriorityQueue, Queue }
1717
import java.util.concurrent._
1818
import java.util.concurrent.atomic.AtomicInteger
1919
import java.util.concurrent.locks.ReentrantLock
20-
21-
import scala.annotation.tailrec
20+
import scala.annotation.{ nowarn, tailrec }
2221
import scala.concurrent.duration.{ Duration, FiniteDuration }
2322
import scala.util.control.NonFatal
24-
2523
import com.typesafe.config.Config
26-
2724
import org.apache.pekko
2825
import pekko.actor.{ ActorCell, ActorRef, ActorSystem, DeadLetter, InternalActorRef }
2926
import pekko.annotation.InternalStableApi
@@ -121,7 +118,8 @@ private[pekko] abstract class Mailbox(val messageQueue: MessageQueue)
121118
@volatile
122119
protected var _systemQueueDoNotCallMeDirectly: SystemMessage = _ // null by default
123120

124-
final def currentStatus: Mailbox.Status = Unsafe.instance.getIntVolatile(this, AbstractMailbox.mailboxStatusOffset)
121+
final def currentStatus: Mailbox.Status =
122+
Unsafe.instance.getIntVolatile(this, AbstractMailbox.mailboxStatusOffset): @nowarn("cat=deprecation")
125123

126124
final def shouldProcessMessage: Boolean = (currentStatus & shouldNotProcessMask) == 0
127125

@@ -134,10 +132,11 @@ private[pekko] abstract class Mailbox(val messageQueue: MessageQueue)
134132
final def isScheduled: Boolean = (currentStatus & Scheduled) != 0
135133

136134
protected final def updateStatus(oldStatus: Status, newStatus: Status): Boolean =
137-
Unsafe.instance.compareAndSwapInt(this, AbstractMailbox.mailboxStatusOffset, oldStatus, newStatus)
135+
Unsafe.instance.compareAndSwapInt(this, AbstractMailbox.mailboxStatusOffset, oldStatus, newStatus): @nowarn(
136+
"cat=deprecation")
138137

139138
protected final def setStatus(newStatus: Status): Unit =
140-
Unsafe.instance.putIntVolatile(this, AbstractMailbox.mailboxStatusOffset, newStatus)
139+
Unsafe.instance.putIntVolatile(this, AbstractMailbox.mailboxStatusOffset, newStatus): @nowarn("cat=deprecation")
141140

142141
/**
143142
* Reduce the suspend count by one. Caller does not need to worry about whether
@@ -210,14 +209,16 @@ private[pekko] abstract class Mailbox(val messageQueue: MessageQueue)
210209
// Note: contrary how it looks, there is no allocation here, as SystemMessageList is a value class and as such
211210
// it just exists as a typed view during compile-time. The actual return type is still SystemMessage.
212211
new LatestFirstSystemMessageList(
213-
Unsafe.instance.getObjectVolatile(this, AbstractMailbox.systemMessageOffset).asInstanceOf[SystemMessage])
212+
Unsafe.instance.getObjectVolatile(this, AbstractMailbox.systemMessageOffset).asInstanceOf[
213+
SystemMessage]): @nowarn("cat=deprecation")
214214

215215
protected final def systemQueuePut(_old: LatestFirstSystemMessageList, _new: LatestFirstSystemMessageList): Boolean =
216216
(_old.head eq _new.head) ||
217-
// Note: calling .head is not actually existing on the bytecode level as the parameters _old and _new
218-
// are SystemMessage instances hidden during compile time behind the SystemMessageList value class.
219-
// Without calling .head the parameters would be boxed in SystemMessageList wrapper.
220-
Unsafe.instance.compareAndSwapObject(this, AbstractMailbox.systemMessageOffset, _old.head, _new.head)
217+
// Note: calling .head is not actually existing on the bytecode level as the parameters _old and _new
218+
// are SystemMessage instances hidden during compile time behind the SystemMessageList value class.
219+
// Without calling .head the parameters would be boxed in SystemMessageList wrapper.
220+
Unsafe.instance.compareAndSwapObject(this, AbstractMailbox.systemMessageOffset, _old.head, _new.head): @nowarn(
221+
"cat=deprecation")
221222

222223
final def canBeScheduledForExecution(hasMessageHint: Boolean, hasSystemMessageHint: Boolean): Boolean =
223224
currentStatus match {

actor/src/main/scala/org/apache/pekko/pattern/AskSupport.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ private[pekko] final class PromiseActorRef(
550550
}
551551

552552
private[this] def watchedBy: Set[ActorRef] =
553-
Unsafe.instance.getObjectVolatile(this, watchedByOffset).asInstanceOf[Set[ActorRef]]
553+
Unsafe.instance.getObjectVolatile(this, watchedByOffset).asInstanceOf[Set[ActorRef]]: @nowarn("cat=deprecation")
554554

555555
private[this] def updateWatchedBy(oldWatchedBy: Set[ActorRef], newWatchedBy: Set[ActorRef]): Boolean =
556-
Unsafe.instance.compareAndSwapObject(this, watchedByOffset, oldWatchedBy, newWatchedBy)
556+
Unsafe.instance.compareAndSwapObject(this, watchedByOffset, oldWatchedBy, newWatchedBy): @nowarn("cat=deprecation")
557557

558558
@tailrec // Returns false if the Promise is already completed
559559
private[this] final def addWatcher(watcher: ActorRef): Boolean = watchedBy match {
@@ -573,12 +573,13 @@ private[pekko] final class PromiseActorRef(
573573
case other => if (!updateWatchedBy(other, null)) clearWatchers() else other
574574
}
575575

576-
private[this] def state: AnyRef = Unsafe.instance.getObjectVolatile(this, stateOffset)
576+
private[this] def state: AnyRef = Unsafe.instance.getObjectVolatile(this, stateOffset): @nowarn("cat=deprecation")
577577

578578
private[this] def updateState(oldState: AnyRef, newState: AnyRef): Boolean =
579-
Unsafe.instance.compareAndSwapObject(this, stateOffset, oldState, newState)
579+
Unsafe.instance.compareAndSwapObject(this, stateOffset, oldState, newState): @nowarn("cat=deprecation")
580580

581-
private[this] def setState(newState: AnyRef): Unit = Unsafe.instance.putObjectVolatile(this, stateOffset, newState)
581+
private[this] def setState(newState: AnyRef): Unit =
582+
Unsafe.instance.putObjectVolatile(this, stateOffset, newState): @nowarn("cat=deprecation")
582583

583584
override def getParent: InternalActorRef = provider.tempContainer
584585

actor/src/main/scala/org/apache/pekko/pattern/CircuitBreaker.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,17 @@ class CircuitBreaker(
318318
* @return Whether the previous state matched correctly
319319
*/
320320
private[this] def swapState(oldState: State, newState: State): Boolean =
321-
Unsafe.instance.compareAndSwapObject(this, AbstractCircuitBreaker.stateOffset, oldState, newState)
321+
Unsafe.instance.compareAndSwapObject(this, AbstractCircuitBreaker.stateOffset, oldState, newState): @nowarn(
322+
"cat=deprecation")
322323

323324
/**
324325
* Helper method for accessing underlying state via Unsafe
325326
*
326327
* @return Reference to current state
327328
*/
328329
private[this] def currentState: State =
329-
Unsafe.instance.getObjectVolatile(this, AbstractCircuitBreaker.stateOffset).asInstanceOf[State]
330+
Unsafe.instance.getObjectVolatile(this, AbstractCircuitBreaker.stateOffset).asInstanceOf[State]: @nowarn(
331+
"cat=deprecation")
330332

331333
/**
332334
* Helper method for updating the underlying resetTimeout via Unsafe
@@ -336,13 +338,14 @@ class CircuitBreaker(
336338
this,
337339
AbstractCircuitBreaker.resetTimeoutOffset,
338340
oldResetTimeout,
339-
newResetTimeout)
341+
newResetTimeout): @nowarn("cat=deprecation")
340342

341343
/**
342344
* Helper method for accessing to the underlying resetTimeout via Unsafe
343345
*/
344346
private[this] def currentResetTimeout: FiniteDuration =
345-
Unsafe.instance.getObjectVolatile(this, AbstractCircuitBreaker.resetTimeoutOffset).asInstanceOf[FiniteDuration]
347+
Unsafe.instance.getObjectVolatile(this, AbstractCircuitBreaker.resetTimeoutOffset).asInstanceOf[
348+
FiniteDuration]: @nowarn("cat=deprecation")
346349

347350
/**
348351
* Wraps invocations of asynchronous calls that need to be protected.

remote/src/main/scala/org/apache/pekko/remote/artery/Association.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,15 @@ private[remote] class Association(
271271
* @return Whether the previous state matched correctly
272272
*/
273273
private[artery] def swapState(oldState: AssociationState, newState: AssociationState): Boolean =
274-
Unsafe.instance.compareAndSwapObject(this, AbstractAssociation.sharedStateOffset, oldState, newState)
274+
Unsafe.instance.compareAndSwapObject(this, AbstractAssociation.sharedStateOffset, oldState, newState): @nowarn(
275+
"cat=deprecation")
275276

276277
/**
277278
* @return Reference to current shared state
278279
*/
279280
def associationState: AssociationState =
280-
Unsafe.instance.getObjectVolatile(this, AbstractAssociation.sharedStateOffset).asInstanceOf[AssociationState]
281+
Unsafe.instance.getObjectVolatile(this, AbstractAssociation.sharedStateOffset).asInstanceOf[
282+
AssociationState]: @nowarn("cat=deprecation")
281283

282284
def setControlIdleKillSwitch(killSwitch: OptionVal[SharedKillSwitch]): Unit = {
283285
val current = associationState

0 commit comments

Comments
 (0)