Fixes for several locals-related issues, fix #398, fix #402, fix #405

This commit is contained in:
Mumfrey committed 2020-10-17 22:10:10 +01:00
1 parent b5299bfebc
commit 0177c2d394
3 files changed
+28 -18

No files matched your search

@@ -529,13 +529,15 @@ public class CallbackInjector extends Injector {
*/
private String generateBadLVTMessage(final Callback callback) {
int position = callback.target.indexOf(callback.node);
List<String> expected = CallbackInjector.summariseLocals(this.methodNode.desc, callback.target.arguments.length + 1);
List<String> found = CallbackInjector.summariseLocals(callback.getDescriptor(), callback.frameSize + (callback.target.isStatic ? 1 : 0));
int targetArgc = callback.target.arguments.length + 1;
List<String> expected = CallbackInjector.summariseLocals(this.methodNode.desc, targetArgc, 255);
List<String> found = CallbackInjector.summariseLocals(callback.getDescriptorWithAllLocals(), targetArgc, expected.size());
if (expected.equals(found)) {
return String.format("Invalid descriptor on %s! Expected %s but found %s", this.info, callback.getDescriptor(), this.methodNode.desc);
}
return String.format("LVT in %s has incompatible changes at opcode %d in callback %s.\nExpected: %s\n Found: %s",
callback.target, position, this, expected, found);
List<String> available = CallbackInjector.summariseLocals(callback.getDescriptorWithAllLocals(), targetArgc, 255);
return String.format("LVT in %s has incompatible changes at opcode %d in callback %s.\n Expected: %s\n Found: %s\nAvailable: %s",
callback.target, position, this.info, expected, found, available);
}
/**
@@ -783,14 +785,14 @@ public class CallbackInjector extends Injector {
return this.isStatic;
}
private static List<String> summariseLocals(String desc, int pos) {
return CallbackInjector.summariseLocals(Type.getArgumentTypes(desc), pos);
private static List<String> summariseLocals(String desc, int pos, int count) {
return CallbackInjector.summariseLocals(Type.getArgumentTypes(desc), pos, count);
}
private static List<String> summariseLocals(Type[] locals, int pos) {
private static List<String> summariseLocals(Type[] locals, int pos, int count) {
List<String> list = new ArrayList<String>();
if (locals != null) {
for (; pos < locals.length; pos++) {
for (; pos < locals.length && list.size() < count; pos++) {
if (locals[pos] != null) {
list.add(locals[pos].toString());
}
@@ -145,13 +145,16 @@ public class LocalVariableDiscriminator {
}
}
Local[] lvt = new Local[this.baseArgIndex + target.arguments.length];
Local[] lvt = new Local[this.baseArgIndex + Bytecode.getArgsSize(target.arguments)];
if (!this.isStatic) {
lvt[0] = new Local("this", Type.getObjectType(target.classNode.name));
}
for (int local = this.baseArgIndex; local < lvt.length; local++) {
Type arg = target.arguments[local - this.baseArgIndex];
lvt[local] = new Local("arg" + local, arg);
for (int local = this.baseArgIndex, arg = 0; local < lvt.length; local++) {
Type argType = target.arguments[arg++];
lvt[local] = new Local("arg" + local, argType);
if (argType.getSize() == 2) {
lvt[++local] = null;
}
}
return lvt;
}
@@ -137,7 +137,7 @@ public final class Locals {
for (int i = 0; i < 3 && (node instanceof LabelNode || node instanceof LineNumberNode); i++) {
node = Locals.nextNode(method.instructions, node);
}
ClassInfo classInfo = ClassInfo.forName(classNode.name);
if (classInfo == null) {
throw new LVTGeneratorError("Could not load class metadata for " + classNode.name + " generating LVT for " + method.name);
@@ -195,7 +195,7 @@ public final class Locals {
frameSize = Locals.getAdjustedFrameSize(frameSize, frameNode);
}
if (frameNode.type == Opcodes.F_CHOP) {
if (frameNode.type == Opcodes.F_CHOP || frameNode.type == Opcodes.F_NEW) {
for (int framePos = frameSize; framePos < frame.length; framePos++) {
frame[framePos] = null;
}
@@ -223,7 +223,7 @@ public final class Locals {
frame[framePos] = null;
} else if (is32bitValue || is64bitValue) {
frame[framePos] = Locals.getLocalVariableAt(classNode, method, insn, framePos);
if (is64bitValue) {
framePos++;
frame[framePos] = null; // TOP
@@ -435,7 +435,7 @@ public final class Locals {
labels[i] = label = new LabelNode();
}
}
if (local == null && locals[j] != null) {
localVariables.add(localNodes[j]);
localNodes[j].end = label;
@@ -447,7 +447,12 @@ public final class Locals {
localNodes[j] = null;
}
String desc = (local.getType() != null) ? local.getType().getDescriptor() : lastKnownType[j];
String desc = lastKnownType[j];
Type localType = local.getType();
if (localType != null) {
desc = "null".equals(localType.getInternalName()) ? Constants.OBJECT_DESC : localType.getDescriptor();
}
localNodes[j] = new LocalVariableNode("var" + j, desc, null, label, null, j);
if (desc != null) {
lastKnownType[j] = desc;
@@ -497,7 +502,7 @@ public final class Locals {
}
return insn;
}
/**
* Compute a new frame size based on the supplied frame type and the size of
* locals contained in the frame (this may differ from the number of actual