Skip to content

Commit ef119f4

Browse files
committed
more
1 parent a76b379 commit ef119f4

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

actor/src/main/java/org/apache/pekko/actor/dungeon/AbstractActorCell.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,15 @@
1818

1919
import org.apache.pekko.actor.ActorCell;
2020
import org.apache.pekko.dispatch.Mailbox;
21-
import org.apache.pekko.util.Unsafe;
2221

2322
final class AbstractActorCell {
2423
static final VarHandle mailboxHandle;
2524
static final VarHandle childrenHandle;
2625
static final VarHandle nextNameHandle;
27-
static final long functionRefsOffset;
26+
static final VarHandle functionRefsHandle;
2827

2928
static {
3029
try {
31-
functionRefsOffset =
32-
Unsafe.instance.objectFieldOffset(
33-
ActorCell.class.getDeclaredField(
34-
"org$apache$pekko$actor$dungeon$Children$$_functionRefsDoNotCallMeDirectly"));
3530
MethodHandles.Lookup lookup =
3631
MethodHandles.privateLookupIn(ActorCell.class, MethodHandles.lookup());
3732
mailboxHandle =
@@ -49,6 +44,12 @@ final class AbstractActorCell {
4944
ActorCell.class,
5045
"org$apache$pekko$actor$dungeon$Children$$_nextNameDoNotCallMeDirectly",
5146
long.class);
47+
functionRefsHandle =
48+
lookup.findVarHandle(
49+
ActorCell.class,
50+
"org$apache$pekko$actor$dungeon$Children$$_functionRefsDoNotCallMeDirectly",
51+
scala.collection.Map.class);
52+
5253
} catch (Throwable t) {
5354
throw new ExceptionInInitializerError(t);
5455
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.apache.pekko
2323
import pekko.actor._
2424
import pekko.annotation.InternalStableApi
2525
import pekko.serialization.{ Serialization, SerializationExtension, Serializers }
26-
import pekko.util.{ Helpers, Unsafe }
26+
import pekko.util.Helpers
2727

2828
private[pekko] object Children {
2929
val GetNobody = () => Nobody
@@ -64,8 +64,7 @@ private[pekko] trait Children { this: ActorCell =>
6464

6565
@nowarn @volatile private var _functionRefsDoNotCallMeDirectly = Map.empty[String, FunctionRef]
6666
private def functionRefs: Map[String, FunctionRef] =
67-
Unsafe.instance.getObjectVolatile(this, AbstractActorCell.functionRefsOffset).asInstanceOf[Map[String,
68-
FunctionRef]]: @nowarn("cat=deprecation")
67+
AbstractActorCell.functionRefsHandle.get(this).asInstanceOf[Map[String, FunctionRef]]
6968

7069
private[pekko] def getFunctionRefOrNobody(name: String, uid: Int = ActorCell.undefinedUid): InternalActorRef =
7170
functionRefs.getOrElse(name, Children.GetNobody()) match {
@@ -84,8 +83,7 @@ private[pekko] trait Children { this: ActorCell =>
8483
@tailrec def rec(): Unit = {
8584
val old = functionRefs
8685
val added = old.updated(childPath.name, ref)
87-
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.functionRefsOffset, old, added): @nowarn(
88-
"cat=deprecation")) rec()
86+
if (!AbstractActorCell.functionRefsHandle.compareAndSet(this, old, added)) rec()
8987
}
9088
rec()
9189

@@ -100,8 +98,7 @@ private[pekko] trait Children { this: ActorCell =>
10098
if (!old.contains(name)) false
10199
else {
102100
val removed = old - name
103-
if (!Unsafe.instance.compareAndSwapObject(this, AbstractActorCell.functionRefsOffset, old, removed): @nowarn(
104-
"cat=deprecation")) rec()
101+
if (!AbstractActorCell.functionRefsHandle.compareAndSet(this, old, removed)) rec()
105102
else {
106103
ref.stop()
107104
true
@@ -112,9 +109,9 @@ private[pekko] trait Children { this: ActorCell =>
112109
}
113110

114111
protected def stopFunctionRefs(): Unit = {
115-
val refs = Unsafe.instance
116-
.getAndSetObject(this, AbstractActorCell.functionRefsOffset, Map.empty)
117-
.asInstanceOf[Map[String, FunctionRef]]: @nowarn("cat=deprecation")
112+
val refs = AbstractActorCell.functionRefsHandle
113+
.getAndSet(this, Map.empty)
114+
.asInstanceOf[Map[String, FunctionRef]]
118115
refs.valuesIterator.foreach(_.stop())
119116
}
120117

0 commit comments

Comments
 (0)