This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 814962569e don't use unsafe to update nextName (#1892)
814962569e is described below
commit 814962569e7f529c4ee45e274781e62dc39117a9
Author: PJ Fanning <[email protected]>
AuthorDate: Fri Aug 1 08:53:45 2025 +0100
don't use unsafe to update nextName (#1892)
* don't use unsafe to update nextName
* Update Children.scala
* Update Children.scala
* use varhandle
* Update AbstractActorCell.java
* review comment
* Update Children.scala
---
.../apache/pekko/actor/dungeon/AbstractActorCell.java | 16 +++++++++++-----
.../scala/org/apache/pekko/actor/dungeon/Children.scala | 4 ++--
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git
a/actor/src/main/java/org/apache/pekko/actor/dungeon/AbstractActorCell.java
b/actor/src/main/java/org/apache/pekko/actor/dungeon/AbstractActorCell.java
index ce319d3af4..3d4b867900 100644
--- a/actor/src/main/java/org/apache/pekko/actor/dungeon/AbstractActorCell.java
+++ b/actor/src/main/java/org/apache/pekko/actor/dungeon/AbstractActorCell.java
@@ -13,13 +13,16 @@
package org.apache.pekko.actor.dungeon;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+
import org.apache.pekko.actor.ActorCell;
import org.apache.pekko.util.Unsafe;
final class AbstractActorCell {
static final long mailboxOffset;
static final long childrenOffset;
- static final long nextNameOffset;
+ static final VarHandle nextNameHandle;
static final long functionRefsOffset;
static {
@@ -32,14 +35,17 @@ final class AbstractActorCell {
Unsafe.instance.objectFieldOffset(
ActorCell.class.getDeclaredField(
"org$apache$pekko$actor$dungeon$Children$$_childrenRefsDoNotCallMeDirectly"));
- nextNameOffset =
- Unsafe.instance.objectFieldOffset(
- ActorCell.class.getDeclaredField(
-
"org$apache$pekko$actor$dungeon$Children$$_nextNameDoNotCallMeDirectly"));
functionRefsOffset =
Unsafe.instance.objectFieldOffset(
ActorCell.class.getDeclaredField(
"org$apache$pekko$actor$dungeon$Children$$_functionRefsDoNotCallMeDirectly"));
+ MethodHandles.Lookup lookup =
+ MethodHandles.privateLookupIn(ActorCell.class,
MethodHandles.lookup());
+ nextNameHandle =
+ lookup.findVarHandle(
+ ActorCell.class,
+
"org$apache$pekko$actor$dungeon$Children$$_nextNameDoNotCallMeDirectly",
+ long.class);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
diff --git a/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
b/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
index 68b0135184..37beef6073 100644
--- a/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
+++ b/actor/src/main/scala/org/apache/pekko/actor/dungeon/Children.scala
@@ -122,11 +122,11 @@ private[pekko] trait Children { this: ActorCell =>
@nowarn @volatile private var _nextNameDoNotCallMeDirectly = 0L
final protected def randomName(sb: java.lang.StringBuilder): String = {
- val num = Unsafe.instance.getAndAddLong(this,
AbstractActorCell.nextNameOffset, 1): @nowarn("cat=deprecation")
+ val num: Long = AbstractActorCell.nextNameHandle.getAndAdd(this, 1L)
Helpers.base64(num, sb)
}
final protected def randomName(): String = {
- val num = Unsafe.instance.getAndAddLong(this,
AbstractActorCell.nextNameOffset, 1): @nowarn("cat=deprecation")
+ val num: Long = AbstractActorCell.nextNameHandle.getAndAdd(this, 1L)
Helpers.base64(num)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]