Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually emit stack frames in EnumValueOfRewriteRule #33

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 will insert the trailing int local for this and all following visitFrame calls; adding it manually would cause duplicate locals in the frame
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,15 @@ 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);
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