Skip to content

Commit

Permalink
Enable inliner for Scala 2 and add Scala 3 inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Oct 9, 2023
1 parent 0943563 commit b7fa606
Show file tree
Hide file tree
Showing 59 changed files with 1,162 additions and 581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object ActorTestKit {
* using default configuration from the reference.conf resources that ship with the Akka libraries.
* The application.conf of your project is not used in this case.
*/
def create(): ActorTestKit =
@noinline def create(): ActorTestKit =
new ActorTestKit(scaladsl.ActorTestKit(TestKitUtils.testNameFromCallStack(classOf[ActorTestKit])))

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ object ActorTestKit {
* When the test has completed you should terminate the `ActorSystem` and
* the testkit with [[ActorTestKit#shutdownTestKit]].
*/
def create(customConfig: Config): ActorTestKit =
@noinline def create(customConfig: Config): ActorTestKit =
new ActorTestKit(scaladsl.ActorTestKit(TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]), customConfig))

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
* using default configuration from the reference.conf resources that ship with the Akka libraries.
* The application.conf of your project is not used in this case.
*/
def this() = this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource])))
@noinline def this() = this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource])))

/**
* Use a custom [[pekko.actor.typed.ActorSystem]] for the actor system.
Expand All @@ -76,7 +76,7 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
/**
* Use a custom config for the actor system.
*/
def this(customConfig: String) =
@noinline def this(customConfig: String) =
this(
ActorTestKit.create(
TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource]),
Expand All @@ -85,13 +85,13 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
/**
* Use a custom config for the actor system.
*/
def this(customConfig: Config) =
@noinline def this(customConfig: Config) =
this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource]), customConfig))

/**
* Use a custom config for the actor system, and a custom [[pekko.actor.testkit.typed.TestKitSettings]].
*/
def this(customConfig: Config, settings: TestKitSettings) =
@noinline def this(customConfig: Config, settings: TestKitSettings) =
this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource]), customConfig, settings))

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object ActorTestKit {
* using default configuration from the reference.conf resources that ship with the Akka libraries.
* The application.conf of your project is not used in this case.
*/
def apply(): ActorTestKit = {
@noinline def apply(): ActorTestKit = {
val system = ActorSystem(
ActorTestKitGuardian.testKitGuardian,
TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
Expand Down Expand Up @@ -111,7 +111,7 @@ object ActorTestKit {
* When the test has completed you should terminate the `ActorSystem` and
* the testkit with [[ActorTestKit#shutdownTestKit]].
*/
def apply(customConfig: Config): ActorTestKit = {
@noinline def apply(customConfig: Config): ActorTestKit = {
val system = ActorSystem(
ActorTestKitGuardian.testKitGuardian,
TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import pekko.actor.typed.Props
import pekko.util.Timeout

object ActorTestKitBase {
def testNameFromCallStack(): String = TestKitUtils.testNameFromCallStack(classOf[ActorTestKitBase])
@noinline def testNameFromCallStack(): String = TestKitUtils.testNameFromCallStack(classOf[ActorTestKitBase])
}

/**
Expand Down
34 changes: 0 additions & 34 deletions actor/src/main/java/org/apache/pekko/actor/AbstractActorRef.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package org.apache.pekko.dispatch;

import org.apache.pekko.util.Unsafe;
import org.apache.pekko.util.Unsafe$;

/**
* Lock-free bounded non-blocking multiple-producer single-consumer queue based on the works of:
Expand Down Expand Up @@ -45,29 +45,29 @@ protected AbstractBoundedNodeQueue(final int capacity) {
}

private void setEnq(Node<T> n) {
Unsafe.instance.putObjectVolatile(this, enqOffset, n);
Unsafe$.MODULE$.instance().putObjectVolatile(this, enqOffset, n);
}

@SuppressWarnings("unchecked")
private Node<T> getEnq() {
return (Node<T>)Unsafe.instance.getObjectVolatile(this, enqOffset);
return (Node<T>)Unsafe$.MODULE$.instance().getObjectVolatile(this, enqOffset);
}

private boolean casEnq(Node<T> old, Node<T> nju) {
return Unsafe.instance.compareAndSwapObject(this, enqOffset, old, nju);
return Unsafe$.MODULE$.instance().compareAndSwapObject(this, enqOffset, old, nju);
}

private void setDeq(Node<T> n) {
Unsafe.instance.putObjectVolatile(this, deqOffset, n);
Unsafe$.MODULE$.instance().putObjectVolatile(this, deqOffset, n);
}

@SuppressWarnings("unchecked")
private Node<T> getDeq() {
return (Node<T>)Unsafe.instance.getObjectVolatile(this, deqOffset);
return (Node<T>)Unsafe$.MODULE$.instance().getObjectVolatile(this, deqOffset);
}

private boolean casDeq(Node<T> old, Node<T> nju) {
return Unsafe.instance.compareAndSwapObject(this, deqOffset, old, nju);
return Unsafe$.MODULE$.instance().compareAndSwapObject(this, deqOffset, old, nju);
}

protected final Node<T> peekNode() {
Expand Down Expand Up @@ -187,8 +187,8 @@ public final Node<T> pollNode() {

static {
try {
enqOffset = Unsafe.instance.objectFieldOffset(AbstractBoundedNodeQueue.class.getDeclaredField("_enqDoNotCallMeDirectly"));
deqOffset = Unsafe.instance.objectFieldOffset(AbstractBoundedNodeQueue.class.getDeclaredField("_deqDoNotCallMeDirectly"));
enqOffset = Unsafe$.MODULE$.instance().objectFieldOffset(AbstractBoundedNodeQueue.class.getDeclaredField("_enqDoNotCallMeDirectly"));
deqOffset = Unsafe$.MODULE$.instance().objectFieldOffset(AbstractBoundedNodeQueue.class.getDeclaredField("_deqDoNotCallMeDirectly"));
} catch(Throwable t){
throw new ExceptionInInitializerError(t);
}
Expand All @@ -202,18 +202,18 @@ public static class Node<T> {

@SuppressWarnings("unchecked")
public final Node<T> next() {
return (Node<T>)Unsafe.instance.getObjectVolatile(this, nextOffset);
return (Node<T>)Unsafe$.MODULE$.instance().getObjectVolatile(this, nextOffset);
}

protected final void setNext(final Node<T> newNext) {
Unsafe.instance.putOrderedObject(this, nextOffset, newNext);
Unsafe$.MODULE$.instance().putOrderedObject(this, nextOffset, newNext);
}

private final static long nextOffset;

static {
try {
nextOffset = Unsafe.instance.objectFieldOffset(Node.class.getDeclaredField("_nextDoNotCallMeDirectly"));
nextOffset = Unsafe$.MODULE$.instance().objectFieldOffset(Node.class.getDeclaredField("_nextDoNotCallMeDirectly"));
} catch(Throwable t){
throw new ExceptionInInitializerError(t);
}
Expand Down
30 changes: 0 additions & 30 deletions actor/src/main/java/org/apache/pekko/dispatch/AbstractMailbox.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

package org.apache.pekko.dispatch;

import org.apache.pekko.util.Unsafe;
import org.apache.pekko.util.Unsafe$;

abstract class AbstractMessageDispatcher {
final static long shutdownScheduleOffset;
final static long inhabitantsOffset;

static {
try {
shutdownScheduleOffset = Unsafe.instance.objectFieldOffset(MessageDispatcher.class.getDeclaredField("_shutdownScheduleDoNotCallMeDirectly"));
inhabitantsOffset = Unsafe.instance.objectFieldOffset(MessageDispatcher.class.getDeclaredField("_inhabitantsDoNotCallMeDirectly"));
shutdownScheduleOffset = Unsafe$.MODULE$.instance().objectFieldOffset(MessageDispatcher.class.getDeclaredField("_shutdownScheduleDoNotCallMeDirectly"));
inhabitantsOffset = Unsafe$.MODULE$.instance().objectFieldOffset(MessageDispatcher.class.getDeclaredField("_inhabitantsDoNotCallMeDirectly"));
} catch(Throwable t){
throw new ExceptionInInitializerError(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package org.apache.pekko.dispatch;

import org.apache.pekko.util.Unsafe;
import org.apache.pekko.util.Unsafe$;

import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -54,7 +54,7 @@ protected AbstractNodeQueue() {
*/
@SuppressWarnings("unchecked")
protected final Node<T> peekNode() {
final Node<T> tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset));
final Node<T> tail = ((Node<T>)Unsafe$.MODULE$.instance().getObjectVolatile(this, tailOffset));
Node<T> next = tail.next();
if (next == null && get() != tail) {
// if tail != head this is not going to change until producer makes progress
Expand Down Expand Up @@ -110,7 +110,7 @@ public final void addNode(final Node<T> n) {
* @return true if queue was empty at some point in the past
*/
public final boolean isEmpty() {
return Unsafe.instance.getObjectVolatile(this, tailOffset) == get();
return Unsafe$.MODULE$.instance().getObjectVolatile(this, tailOffset) == get();
}

/**
Expand All @@ -126,7 +126,7 @@ public final boolean isEmpty() {
public final int count() {
int count = 0;
final Node<T> head = get();
for(Node<T> n = ((Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset)).next();
for(Node<T> n = ((Node<T>) Unsafe$.MODULE$.instance().getObjectVolatile(this, tailOffset)).next();
n != null && count < Integer.MAX_VALUE;
n = n.next()) {
++count;
Expand Down Expand Up @@ -162,7 +162,7 @@ public final T poll() {
*/
@SuppressWarnings("unchecked")
public final Node<T> pollNode() {
final Node<T> tail = (Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset);
final Node<T> tail = (Node<T>) Unsafe$.MODULE$.instance().getObjectVolatile(this, tailOffset);
Node<T> next = tail.next();
if (next == null && get() != tail) {
// if tail != head this is not going to change until producer makes progress
Expand All @@ -175,7 +175,7 @@ public final Node<T> pollNode() {
else {
tail.value = next.value;
next.value = null;
Unsafe.instance.putOrderedObject(this, tailOffset, next);
Unsafe$.MODULE$.instance().putOrderedObject(this, tailOffset, next);
tail.setNext(null);
return tail;
}
Expand All @@ -185,7 +185,7 @@ public final Node<T> pollNode() {

static {
try {
tailOffset = Unsafe.instance.objectFieldOffset(AbstractNodeQueue.class.getDeclaredField("_tailDoNotCallMeDirectly"));
tailOffset = Unsafe$.MODULE$.instance().objectFieldOffset(AbstractNodeQueue.class.getDeclaredField("_tailDoNotCallMeDirectly"));
} catch(Throwable t){
throw new ExceptionInInitializerError(t);
}
Expand All @@ -206,18 +206,18 @@ public Node(final T value) {

@SuppressWarnings("unchecked")
public final Node<T> next() {
return (Node<T>)Unsafe.instance.getObjectVolatile(this, nextOffset);
return (Node<T>)Unsafe$.MODULE$.instance().getObjectVolatile(this, nextOffset);
}

protected final void setNext(final Node<T> newNext) {
Unsafe.instance.putOrderedObject(this, nextOffset, newNext);
Unsafe$.MODULE$.instance().putOrderedObject(this, nextOffset, newNext);
}

private final static long nextOffset;

static {
try {
nextOffset = Unsafe.instance.objectFieldOffset(Node.class.getDeclaredField("_nextDoNotCallMeDirectly"));
nextOffset = Unsafe$.MODULE$.instance().objectFieldOffset(Node.class.getDeclaredField("_nextDoNotCallMeDirectly"));
} catch(Throwable t){
throw new ExceptionInInitializerError(t);
}
Expand Down
Loading

0 comments on commit b7fa606

Please sign in to comment.