Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit a6d0e47

Browse files
committed
Add Thread.onSpinWait MCR
1 parent 63152c4 commit a6d0e47

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/main/java/net/raphimc/javadowngrader/transformer/j8/Java9ToJava8.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.OptionalStreamMCR;
3939
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.RuntimeVersionMCR;
4040
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.SetOfMCR;
41+
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.ThreadOnSpinWaitMCR;
4142
import net.raphimc.javadowngrader.transformer.j8.methodinserter.PathEndsWithMI;
4243
import net.raphimc.javadowngrader.transformer.j8.methodinserter.PathResolveMI;
4344
import net.raphimc.javadowngrader.transformer.j8.methodinserter.PathStartsWithMI;
@@ -109,6 +110,8 @@ public Java9ToJava8() {
109110

110111
this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/CharSequence;III)I", new IntegerParseIntMCR());
111112
this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseUnsignedInt", "(Ljava/lang/CharSequence;III)I", new IntegerParseIntMCR());
113+
114+
this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/lang/Thread", "onSpinWait", new ThreadOnSpinWaitMCR());
112115
}
113116

114117
@Override
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of JavaDowngrader - https://github.com/RaphiMC/JavaDowngrader
3+
* Copyright (C) 2023-2024 RK_01/RaphiMC and contributors
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package net.raphimc.javadowngrader.transformer.j8.methodcallreplacer;
19+
20+
import net.raphimc.javadowngrader.RuntimeDepCollector;
21+
import net.raphimc.javadowngrader.transformer.DowngradeResult;
22+
import net.raphimc.javadowngrader.transformer.MethodCallReplacer;
23+
import org.objectweb.asm.Opcodes;
24+
import org.objectweb.asm.tree.ClassNode;
25+
import org.objectweb.asm.tree.InsnList;
26+
import org.objectweb.asm.tree.MethodInsnNode;
27+
import org.objectweb.asm.tree.MethodNode;
28+
29+
public class ThreadOnSpinWaitMCR implements MethodCallReplacer {
30+
@Override
31+
public InsnList getReplacement(ClassNode classNode, MethodNode method, String originalName, String originalDesc, RuntimeDepCollector depCollector, DowngradeResult result) {
32+
final InsnList replacement = new InsnList();
33+
replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Thread", "yield", "()V"));
34+
return replacement;
35+
}
36+
}

0 commit comments

Comments
 (0)