Tencent / TencentKona-8

Tencent Kona is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-term support(LTS) with quarterly updates. Tencent Kona serves as the default JDK internally at Tencent Cloud for cloud computing and other Java applications.
Other
938 stars 146 forks source link

Transplant jmh test Ring.java from Loom #127

Open HangerLIN opened 1 year ago

HangerLIN commented 1 year ago

How to Run the Test

  1. Make sure Java 1.8.0_362_fiber is installed.
  2. Run the command mvn clean packageto build the project.
  3. Run the main method in the class org.example.Ring to start the test.
  4. See the result in the file res.json

changes:

  1. Add jmh dependencies in pom.xml

         <dependencies>
             <dependency>
                 <groupId>org.openjdk.jmh</groupId>
                 <artifactId>jmh-core</artifactId>
                 <version>1.23</version>
             </dependency>
             <dependency>
                 <groupId>org.openjdk.jmh</groupId>
                 <artifactId>jmh-generator-annprocess</artifactId>
                 <version>1.23</version>
             </dependency>
         </dependencies>
  2. Altered the Method for Starting Workers:

    • In the Loom version, the startAll() method was using Thread.startVirtualThread(w); to start virtual threads.
    • In the Kona version, in the same method I use Thread.ofVirtual().scheduler(Executors.newSingleThreadExecutor()).start(w); to start the virtual threads as well.
  3. Modified Channel Creation:

    • In the Loom version, the getChannel() method used the enhanced switch expression syntax:
      return switch(stackFrame) {
      ...
      default -> throw new RuntimeException("Illegal stack parameter value: "+ stackFrame +" (allowed: 1,2,4,8)");
      };
    • In the Kona version, I changed it back to the conventional switch statement since the arrow syntax used in “switch” only can be complied in jdk 14 or other later version.
      switch (stackFrame) {
      ...
      default:
       throw new RuntimeException("Illegal stack parameter value: " + stackFrame + " (allowed: 1,2,4,8)");
      }
johnshajiang commented 1 year ago

@HangerLIN Please remove directory target.

HangerLIN commented 1 year ago

How to Run the Test Make sure Java 1.8.0_362_fiber is installed. Run the command mvn clean packageto build the project. Run the main method in the class org.example.Ring to start the test. See the result in the file res.json changes: Add jmh dependencies in pom.xml

<dependencies>
    <dependency>
        <groupId>org.openjdk.jmh</groupId>
        <artifactId>jmh-core</artifactId>
        <version>1.37</version>
    </dependency>
    <dependency>
        <groupId>org.openjdk.jmh</groupId>
        <artifactId>jmh-generator-annprocess</artifactId>
        <version>1.37</version>
    </dependency>
</dependencies>

Altered the Method for Starting Workers:

In the Loom version, the getChannel() method used the enhanced switch expression syntax:

return switch(stackFrame) {
...
default -> throw new RuntimeException("Illegal stack parameter value: "+ stackFrame +" (allowed: 1,2,4,8)");
};
In the Kona version, I changed it back to the conventional switch statement since the arrow syntax used in “switch” only can be complied in jdk 14 or other later version.
switch (stackFrame) {
...
default:
    throw new RuntimeException("Illegal stack parameter value: " + stackFrame + " (allowed: 1,2,4,8)");
}

Here is the git diff between the original one and the version I made it adapted to Kona.

git diff /Users/lth/Downloads/loom-fibers/test/micro/org/openjdk/bench/loom/ring/Ring.java /Users/lth/Desktop/OpenSourceRecord/kona_copy/TencentKona-8/demo/fiber/Ring_test/src/main/java/org/example/Ring.java
diff --git a/Users/lth/Downloads/loom-fibers/test/micro/org/openjdk/bench/loom/ring/Ring.java b/Users/lth/Desktop/OpenSourceRecord/kona_copy/TencentKona-8/demo/fiber/Ring_test/src/main/java/org/example/Ring.java
old mode 100755
new mode 100644
index 58f74586..98d50663
--- a/Users/lth/Downloads/loom-fibers/test/micro/org/openjdk/bench/loom/ring/Ring.java
+++ b/Users/lth/Desktop/OpenSourceRecord/kona_copy/TencentKona-8/demo/fiber/Ring_test/src/main/java/org/example/Ring.java
@@ -20,8 +20,10 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-package org.openjdk.bench.loom.ring;
+package org.example;

+import org.example.Channel;
+import org.example.Channels;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
 import org.openjdk.jmh.annotations.Fork;
@@ -92,7 +94,6 @@ public class Ring {
     @Param({"true", "false"})
     public boolean singleshot;

-
     @Setup
     @SuppressWarnings("unchecked")
     public void setup() {
@@ -154,14 +155,18 @@ public class Ring {
     }

     Channel<Integer> getChannel() {
-        return switch(stackFrame) {
-            case 1 -> new Channels.ChannelFixedStackR1<>(getQueue(queue), stackDepth, allocalot ? 4242 : 0);
-            case 2 -> new Channels.ChannelFixedStackR2<>(getQueue(queue), stackDepth, allocalot ? 4242 : 0);
-            case 4 -> new Channels.ChannelFixedStackR4<>(getQueue(queue), stackDepth, allocalot ? 4242 : 0);
-            case 8 -> new Channels.ChannelFixedStackR8<>(getQueue(queue), stackDepth, allocalot ? 4242 : 0);
-            default -> throw new RuntimeException("Illegal stack parameter value: "+ stackFrame +" (allowed: 1,2,4,8)");
-        };
-
+        switch (stackFrame) {
+            case 1:
+                return new Channels.ChannelFixedStackR1<>(getQueue(queue), stackDepth, allocalot ? 4242 : 0);
+            case 2:
+                return new Channels.ChannelFixedStackR2<>(getQueue(queue), stackDepth, allocalot ? 4242 : 0);
:
HangerLIN commented 1 year ago

我已经修改了描述文档,请老师过目

johnshajiang commented 1 year ago

我只是确定一下,上面的diff的内容是否显示完整了?是否会一些末尾的行没有显示出来? 至少看起来,switch语句中有些条目,如4,8和default,没有列出来。

HangerLIN commented 1 year ago

我是把原本在终端栏的全部信息都复制上来了

johnshajiang commented 1 year ago

是不是一屏幕不能显示出全部内容? 结尾处是:,我以为后面还有内容。可以把光标继续向下移动。

HangerLIN commented 1 year ago

按照和老师会议谈论内容增加了Ring.java以及 Channel.java的实现逻辑和结果