mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-27 02:43:07 +00:00
This commit is contained in:
1 parent
9109a19d5e
commit
6f5dce173b
5 files changed
+47
-12
No files matched your search
@@ -135,7 +135,11 @@ public final class Locals {
|
||||
*/
|
||||
public static LocalVariableNode[] getLocalsAt(ClassNode classNode, MethodNode method, AbstractInsnNode node) {
|
||||
for (int i = 0; i < 3 && (node instanceof LabelNode || node instanceof LineNumberNode); i++) {
|
||||
node = Locals.nextNode(method.instructions, node);
|
||||
AbstractInsnNode nextNode = Locals.nextNode(method.instructions, node);
|
||||
if (nextNode instanceof FrameNode) { // Do not ffwd over frames
|
||||
break;
|
||||
}
|
||||
node = nextNode;
|
||||
}
|
||||
|
||||
ClassInfo classInfo = ClassInfo.forName(classNode.name);
|
||||
@@ -166,6 +170,7 @@ public final class Locals {
|
||||
int frameSize = local;
|
||||
int frameIndex = -1;
|
||||
int lastFrameSize = local;
|
||||
int knownFrameSize = local;
|
||||
VarInsnNode storeInsn = null;
|
||||
|
||||
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
|
||||
@@ -173,9 +178,11 @@ public final class Locals {
|
||||
if (storeInsn != null) {
|
||||
LocalVariableNode storedLocal = Locals.getLocalVariableAt(classNode, method, insn, storeInsn.var);
|
||||
frame[storeInsn.var] = storedLocal;
|
||||
knownFrameSize = Math.max(knownFrameSize, storeInsn.var + 1);
|
||||
if (storedLocal != null && storeInsn.var < method.maxLocals - 1 && storedLocal.desc != null
|
||||
&& Type.getType(storedLocal.desc).getSize() == 2) {
|
||||
frame[storeInsn.var + 1] = null; // TOP
|
||||
knownFrameSize = Math.max(knownFrameSize, storeInsn.var + 2);
|
||||
}
|
||||
storeInsn = null;
|
||||
}
|
||||
@@ -187,12 +194,12 @@ public final class Locals {
|
||||
break handleFrame;
|
||||
}
|
||||
|
||||
int frameNodeSize = Locals.computeFrameSize(frameNode);
|
||||
FrameData frameData = frameIndex < frames.size() ? frames.get(frameIndex) : null;
|
||||
|
||||
if (frameData != null) {
|
||||
if (frameData.type == Opcodes.F_FULL) {
|
||||
frameSize = Math.min(frameSize, frameData.locals);
|
||||
lastFrameSize = frameSize;
|
||||
knownFrameSize = lastFrameSize = frameSize = Math.min(frameNodeSize, frameData.size);
|
||||
} else {
|
||||
frameSize = Locals.getAdjustedFrameSize(frameSize, frameData);
|
||||
}
|
||||
@@ -200,17 +207,25 @@ public final class Locals {
|
||||
frameSize = Locals.getAdjustedFrameSize(frameSize, frameNode);
|
||||
}
|
||||
|
||||
if (frameNode.type == Opcodes.F_CHOP || frameNode.type == Opcodes.F_NEW) {
|
||||
// Sanity check
|
||||
if (frameSize < 0) {
|
||||
throw new IllegalStateException(String.format("Locals entered an invalid state evaluating %s::%s%s at instruction %d (%s). "
|
||||
+ "Initial frame size is %d, calculated a frame size of %d with %s", classNode.name, method.name, method.desc,
|
||||
method.instructions.indexOf(insn), Bytecode.describeNode(insn, false), initialFrameSize, frameSize, frameData));
|
||||
}
|
||||
|
||||
if ((frameData == null && (frameNode.type == Opcodes.F_CHOP || frameNode.type == Opcodes.F_NEW))
|
||||
|| (frameData != null && frameData.type == Opcodes.F_CHOP)) {
|
||||
for (int framePos = frameSize; framePos < frame.length; framePos++) {
|
||||
frame[framePos] = null;
|
||||
}
|
||||
lastFrameSize = frameSize;
|
||||
knownFrameSize = lastFrameSize = frameSize;
|
||||
break handleFrame;
|
||||
}
|
||||
|
||||
int framePos = frameNode.type == Opcodes.F_APPEND ? lastFrameSize : 0;
|
||||
lastFrameSize = frameSize;
|
||||
|
||||
|
||||
// localPos tracks the location in the frame node's locals list, which doesn't leave space for TOP entries
|
||||
for (int localPos = 0; framePos < frame.length; framePos++, localPos++) {
|
||||
// Get the local at the current position in the FrameNode's locals list
|
||||
@@ -239,7 +254,11 @@ public final class Locals {
|
||||
}
|
||||
} else if (localType == null) {
|
||||
if (framePos >= initialFrameSize && framePos >= frameSize && frameSize > 0) {
|
||||
frame[framePos] = null;
|
||||
if (framePos < knownFrameSize) {
|
||||
frame[framePos] = Locals.getLocalVariableAt(classNode, method, insn, framePos);
|
||||
} else {
|
||||
frame[framePos] = null;
|
||||
}
|
||||
}
|
||||
} else if (localType instanceof LabelNode) {
|
||||
// Uninitialised
|
||||
@@ -253,6 +272,7 @@ public final class Locals {
|
||||
boolean isLoad = insn.getOpcode() >= Opcodes.ILOAD && insn.getOpcode() <= Opcodes.SALOAD;
|
||||
if (isLoad) {
|
||||
frame[varNode.var] = Locals.getLocalVariableAt(classNode, method, insn, varNode.var);
|
||||
knownFrameSize = Math.max(knownFrameSize, varNode.var + Type.getType(frame[varNode.var].desc).getSize());
|
||||
} else {
|
||||
// Update the LVT for the opcode AFTER this one, since we always want to know
|
||||
// the frame state BEFORE the *current* instruction to match the contract of
|
||||
|
||||
Reference in new issue
Block a user