Skip to content

Commit

Permalink
Manually emit stack frames in EnumValueOfRewriteRule
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Sep 27, 2024
1 parent 159ba64 commit 8dd5ca4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void generateMethod(final GeneratorAdapterFactory factory, final MethodCa
methodGenerator.visitLookupSwitchInsn(lookupSwitchEndLabel, lookupSwitchKeys, labels);
for (int i = 0; i < labels.length; i++) {
methodGenerator.mark(labels[i]);
// LocalVariableSorter inserts trailing int local for i == 0
methodGenerator.visitFrame(Opcodes.F_NEW, 1, new Object[]{"java/lang/String"}, 1, new Object[]{"java/lang/String"});
// generate case
final List<String> matchingStrings = hashToField.get(lookupSwitchKeys[i]);
if (matchingStrings.size() == 1) {
Expand Down Expand Up @@ -93,11 +95,13 @@ public void generateMethod(final GeneratorAdapterFactory factory, final MethodCa
methodGenerator.goTo(lookupSwitchEndLabel);
if (nestedLabels[j] != lookupSwitchEndLabel) {
methodGenerator.mark(nestedLabels[j]); // mark start of next label (except last one)
methodGenerator.visitFrame(Opcodes.F_NEW, 1, new Object[]{"java/lang/String"}, 1, new Object[]{"java/lang/String"});
}
}
}
}
methodGenerator.mark(lookupSwitchEndLabel);
methodGenerator.visitFrame(Opcodes.F_NEW, 1, new Object[]{"java/lang/String"}, 1, new Object[]{"java/lang/String"});
methodGenerator.loadLocal(tableSwitchIndexLocal);
final Label[] tableSwitchLabels = new Label[tableSwitchIndexToRenamedField.length];
for (int i = 0; i < tableSwitchLabels.length; i++) {
Expand All @@ -108,12 +112,16 @@ public void generateMethod(final GeneratorAdapterFactory factory, final MethodCa
methodGenerator.visitTableSwitchInsn(0, tableSwitchIndexToRenamedField.length - 1, tableSwitchDefaultLabel, tableSwitchLabels);
for (int i = 0; i < tableSwitchIndexToRenamedField.length; i++) {
methodGenerator.mark(tableSwitchLabels[i]);
methodGenerator.visitFrame(Opcodes.F_NEW, 1, new Object[]{"java/lang/String"}, 1, new Object[]{"java/lang/String"});
methodGenerator.push(tableSwitchIndexToRenamedField[i]);
methodGenerator.goTo(tableSwitchEndLabel);
}
methodGenerator.mark(tableSwitchDefaultLabel);
methodGenerator.visitFrame(Opcodes.F_NEW, 1, new Object[]{"java/lang/String"}, 1, new Object[]{"java/lang/String"});
methodGenerator.loadArg(0); // default to the passed in value
methodGenerator.mark(tableSwitchEndLabel);
// LocalVariableSorter inserts trailing int local
methodGenerator.visitFrame(Opcodes.F_NEW, 1, new Object[]{"java/lang/String"}, 2, new Object[]{"java/lang/String", "java/lang/String"});
methodGenerator.invokeStatic(Type.getType(original.owner().descriptorString()), new Method(original.name(), original.descriptor().descriptorString()));
methodGenerator.returnValue();
methodGenerator.endMethod();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/papermc/asm/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public byte[] process(final byte[] bytes) {
final ClassReader classReader = new ClassReader(bytes);
final ClassWriter classWriter;
if (this.copyFromClassReader()) {
classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS);
} else {
classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
}
classReader.accept(this.factory.createVisitor(classWriter), 0);
return classWriter.toByteArray();
Expand Down

0 comments on commit 8dd5ca4

Please sign in to comment.