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

Commit

Permalink
Add Thread.onSpinWait MCR
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Mar 2, 2024
1 parent 63152c4 commit a6d0e47
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.OptionalStreamMCR;
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.RuntimeVersionMCR;
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.SetOfMCR;
import net.raphimc.javadowngrader.transformer.j8.methodcallreplacer.ThreadOnSpinWaitMCR;
import net.raphimc.javadowngrader.transformer.j8.methodinserter.PathEndsWithMI;
import net.raphimc.javadowngrader.transformer.j8.methodinserter.PathResolveMI;
import net.raphimc.javadowngrader.transformer.j8.methodinserter.PathStartsWithMI;
Expand Down Expand Up @@ -109,6 +110,8 @@ public Java9ToJava8() {

this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/CharSequence;III)I", new IntegerParseIntMCR());
this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseUnsignedInt", "(Ljava/lang/CharSequence;III)I", new IntegerParseIntMCR());

this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/lang/Thread", "onSpinWait", new ThreadOnSpinWaitMCR());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of JavaDowngrader - https://github.com/RaphiMC/JavaDowngrader
* Copyright (C) 2023-2024 RK_01/RaphiMC and contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.javadowngrader.transformer.j8.methodcallreplacer;

import net.raphimc.javadowngrader.RuntimeDepCollector;
import net.raphimc.javadowngrader.transformer.DowngradeResult;
import net.raphimc.javadowngrader.transformer.MethodCallReplacer;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

public class ThreadOnSpinWaitMCR implements MethodCallReplacer {
@Override
public InsnList getReplacement(ClassNode classNode, MethodNode method, String originalName, String originalDesc, RuntimeDepCollector depCollector, DowngradeResult result) {
final InsnList replacement = new InsnList();
replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Thread", "yield", "()V"));
return replacement;
}
}

0 comments on commit a6d0e47

Please sign in to comment.