Code clean
This commit is contained in:
@@ -129,7 +129,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
private int myLastLineNumber = -1;
|
||||
private boolean shouldMarkLineNumbers = true;
|
||||
private int finallyDeep = 0;
|
||||
private int finallyDepth = 0;
|
||||
|
||||
public ExpressionCodegen(
|
||||
@NotNull MethodVisitor mv,
|
||||
@@ -1794,7 +1794,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
@Nullable Label afterJumpLabel
|
||||
) {
|
||||
if (finallyBlockStackElement != null) {
|
||||
finallyDeep++;
|
||||
finallyDepth++;
|
||||
assert finallyBlockStackElement.gaps.size() % 2 == 0 : "Finally block gaps are inconsistent";
|
||||
|
||||
BlockStackElement topOfStack = blockStackElements.pop();
|
||||
@@ -1805,13 +1805,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
v.mark(finallyStart);
|
||||
finallyBlockStackElement.addGapLabel(finallyStart);
|
||||
if (InlineCodegenUtil.isFinallyMarkerRequired(context)) {
|
||||
InlineCodegenUtil.generateFinallyMarker(v, finallyDeep, true);
|
||||
InlineCodegenUtil.generateFinallyMarker(v, finallyDepth, true);
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
gen(jetTryExpression.getFinallyBlock().getFinalExpression(), Type.VOID_TYPE);
|
||||
|
||||
if (InlineCodegenUtil.isFinallyMarkerRequired(context)) {
|
||||
InlineCodegenUtil.generateFinallyMarker(v, finallyDeep, false);
|
||||
InlineCodegenUtil.generateFinallyMarker(v, finallyDepth, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1820,7 +1820,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
|
||||
if (finallyBlockStackElement != null) {
|
||||
finallyDeep--;
|
||||
finallyDepth--;
|
||||
Label finallyEnd = afterJumpLabel != null ? afterJumpLabel : new Label();
|
||||
if (afterJumpLabel == null) {
|
||||
v.mark(finallyEnd);
|
||||
@@ -4006,9 +4006,9 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
return new Stack<BlockStackElement>(blockStackElements);
|
||||
}
|
||||
|
||||
public void addBlockStackElementsForNonLocalReturns(@NotNull Stack<BlockStackElement> elements, int finallyDeepIndex) {
|
||||
public void addBlockStackElementsForNonLocalReturns(@NotNull Stack<BlockStackElement> elements, int finallyDepth) {
|
||||
blockStackElements.addAll(elements);
|
||||
this.finallyDeep = finallyDeepIndex;
|
||||
this.finallyDepth = finallyDepth;
|
||||
}
|
||||
|
||||
private static class NonLocalReturnInfo {
|
||||
|
||||
+15
-23
@@ -117,16 +117,14 @@ class IntervalMetaInfo<T : SplittableInterval<T>> {
|
||||
intervalEnds.put(remapped.endLabel, remapped)
|
||||
}
|
||||
|
||||
fun splitCurrentIntervals(by : Interval, keepStart: Boolean): List<SplittedPair<T>> {
|
||||
fun splitCurrentIntervals(by : Interval, keepStart: Boolean): List<SplitPair<T>> {
|
||||
return currentIntervals.map { split(it, by, keepStart) }
|
||||
}
|
||||
|
||||
fun processCurrent(curIns: LabelNode, directOrder: Boolean) {
|
||||
getInterval(curIns, directOrder).forEach {
|
||||
val added = currentIntervals.add(it)
|
||||
if (!added) {
|
||||
assert(added, "Wrong interval structure: $curIns, $it")
|
||||
}
|
||||
assert(added, "Wrong interval structure: $curIns, $it")
|
||||
}
|
||||
|
||||
getInterval(curIns, !directOrder).forEach {
|
||||
@@ -135,28 +133,22 @@ class IntervalMetaInfo<T : SplittableInterval<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
fun split(interval: T, by : Interval, keepStart: Boolean): SplittedPair<T> {
|
||||
val splittedPair = interval.split(by, keepStart)
|
||||
fun split(interval: T, by : Interval, keepStart: Boolean): SplitPair<T> {
|
||||
val split = interval.split(by, keepStart)
|
||||
if (!keepStart) {
|
||||
remapStartLabel(splittedPair.newPart.startLabel, splittedPair.patchedPart)
|
||||
remapStartLabel(split.newPart.startLabel, split.patchedPart)
|
||||
} else {
|
||||
remapEndLabel(splittedPair.newPart.endLabel, splittedPair.patchedPart)
|
||||
remapEndLabel(split.newPart.endLabel, split.patchedPart)
|
||||
}
|
||||
addNewInterval(splittedPair.newPart)
|
||||
return splittedPair
|
||||
addNewInterval(split.newPart)
|
||||
return split
|
||||
}
|
||||
|
||||
fun splitAndRemoveInterval(interval: T, by : Interval, keepStart: Boolean): SplittedPair<T> {
|
||||
val splittedPair = interval.split(by, keepStart)
|
||||
if (!keepStart) {
|
||||
remapStartLabel(splittedPair.newPart.startLabel, splittedPair.patchedPart)
|
||||
} else {
|
||||
remapEndLabel(splittedPair.newPart.endLabel, splittedPair.patchedPart)
|
||||
}
|
||||
val removed = currentIntervals.remove(splittedPair.patchedPart)
|
||||
assert(removed, "Wrong interval structure: $splittedPair")
|
||||
addNewInterval(splittedPair.newPart)
|
||||
return splittedPair
|
||||
fun splitAndRemoveInterval(interval: T, by : Interval, keepStart: Boolean): SplitPair<T> {
|
||||
val splitPair = split(interval, by, keepStart)
|
||||
val removed = currentIntervals.remove(splitPair.patchedPart)
|
||||
assert(removed, {"Wrong interval structure: $splitPair"})
|
||||
return splitPair
|
||||
}
|
||||
|
||||
fun getInterval(curIns: LabelNode, isOpen: Boolean) = if (isOpen) intervalStarts.get(curIns) else intervalEnds.get(curIns)
|
||||
@@ -201,7 +193,7 @@ public class LocalVarNodeWrapper(val node: LocalVariableNode) : Interval, Splitt
|
||||
override val endLabel: LabelNode
|
||||
get() = node.end
|
||||
|
||||
override fun split(split: Interval, keepStart: Boolean): SplittedPair<LocalVarNodeWrapper> {
|
||||
override fun split(split: Interval, keepStart: Boolean): SplitPair<LocalVarNodeWrapper> {
|
||||
val newPartInterval = if (keepStart) {
|
||||
val oldEnd = endLabel
|
||||
node.end = split.startLabel
|
||||
@@ -213,7 +205,7 @@ public class LocalVarNodeWrapper(val node: LocalVariableNode) : Interval, Splitt
|
||||
Pair(oldStart, split.startLabel)
|
||||
}
|
||||
|
||||
return SplittedPair(this, LocalVarNodeWrapper(
|
||||
return SplitPair(this, LocalVarNodeWrapper(
|
||||
LocalVariableNode(node.name, node.desc, node.signature, newPartInterval.first, newPartInterval.second, node.index)
|
||||
))
|
||||
}
|
||||
|
||||
@@ -664,13 +664,13 @@ public class InlineCodegen extends CallGenerator {
|
||||
|
||||
DefaultProcessor processor = new DefaultProcessor(intoNode, offsetForFinallyLocalVar);
|
||||
|
||||
int curFinallyDeep = 0;
|
||||
int curFinallyDepth = 0;
|
||||
AbstractInsnNode curInstr = intoNode.instructions.getFirst();
|
||||
while (curInstr != null) {
|
||||
processor.processInstruction(curInstr, true);
|
||||
if (InlineCodegenUtil.isFinallyStart(curInstr)) {
|
||||
//TODO deep index calc could be more precise
|
||||
curFinallyDeep = getConstant(curInstr.getPrevious());
|
||||
//TODO depth index calc could be more precise
|
||||
curFinallyDepth = getConstant(curInstr.getPrevious());
|
||||
}
|
||||
|
||||
MethodInliner.PointForExternalFinallyBlocks extension = extensionPoints.get(curInstr);
|
||||
@@ -683,7 +683,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
ExpressionCodegen finallyCodegen =
|
||||
new ExpressionCodegen(finallyNode, codegen.getFrameMap(), codegen.getReturnType(),
|
||||
codegen.getContext(), codegen.getState(), codegen.getParentCodegen());
|
||||
finallyCodegen.addBlockStackElementsForNonLocalReturns(codegen.getBlockStackElements(), curFinallyDeep);
|
||||
finallyCodegen.addBlockStackElementsForNonLocalReturns(codegen.getBlockStackElements(), curFinallyDepth);
|
||||
|
||||
FrameMap frameMap = finallyCodegen.getFrameMap();
|
||||
FrameMap.Mark mark = frameMap.mark();
|
||||
@@ -691,12 +691,12 @@ public class InlineCodegen extends CallGenerator {
|
||||
frameMap.enterTemp(Type.INT_TYPE);
|
||||
}
|
||||
|
||||
finallyCodegen.generateFinallyBlocksIfNeeded(extension.returnType, extension.labelNode.getLabel());
|
||||
finallyCodegen.generateFinallyBlocksIfNeeded(extension.returnType, extension.finallyIntervalEnd.getLabel());
|
||||
|
||||
//Exception table for external try/catch/finally blocks will be generated in original codegen after exiting this method
|
||||
InlineCodegenUtil.insertNodeBefore(finallyNode, intoNode, curInstr);
|
||||
|
||||
SimpleInterval splitBy = new SimpleInterval((LabelNode) start.info, extension.labelNode);
|
||||
SimpleInterval splitBy = new SimpleInterval((LabelNode) start.info, extension.finallyIntervalEnd);
|
||||
processor.getTryBlocksMetaInfo().splitCurrentIntervals(splitBy, true);
|
||||
|
||||
processor.getLocalVarsMetaInfo().splitCurrentIntervals(splitBy, true);
|
||||
@@ -719,8 +719,8 @@ public class InlineCodegen extends CallGenerator {
|
||||
AbstractInsnNode curInstr = instructions.getFirst();
|
||||
while (curInstr != null) {
|
||||
if (InlineCodegenUtil.isFinallyMarker(curInstr)) {
|
||||
//just to assert
|
||||
AbstractInsnNode marker = curInstr;
|
||||
//just to assert
|
||||
getConstant(marker.getPrevious());
|
||||
curInstr = curInstr.getNext();
|
||||
instructions.remove(marker.getPrevious());
|
||||
|
||||
@@ -404,8 +404,8 @@ public class InlineCodegenUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateFinallyMarker(@NotNull InstructionAdapter v, int deep, boolean start) {
|
||||
v.iconst(deep);
|
||||
public static void generateFinallyMarker(@NotNull InstructionAdapter v, int depth, boolean start) {
|
||||
v.iconst(depth);
|
||||
v.invokestatic(INLINE_MARKER_CLASS_NAME, start ? INLINE_MARKER_FINALLY_START : INLINE_MARKER_FINALLY_END, "(I)V", false);
|
||||
}
|
||||
|
||||
|
||||
+10
-11
@@ -144,6 +144,7 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
AbstractInsnNode markedReturn = curIns;
|
||||
AbstractInsnNode instrInsertFinallyBefore = markedReturn.getPrevious();
|
||||
AbstractInsnNode nextPrev = instrInsertFinallyBefore.getPrevious().getPrevious();
|
||||
assert markedReturn.getNext() instanceof LabelNode : "Label should be occurred after non-local return";
|
||||
LabelNode newFinallyEnd = (LabelNode) markedReturn.getNext();
|
||||
Type nonLocalReturnType = InlineCodegenUtil.getReturnType(markedReturn.getOpcode());
|
||||
|
||||
@@ -158,7 +159,7 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
|
||||
checkClusterInvariant(clustersFromInnermost);
|
||||
|
||||
int originalDeepIndex = 0;
|
||||
int originalDepthIndex = 0;
|
||||
|
||||
while (tryCatchBlockIterator.hasNext()) {
|
||||
TryBlockCluster<TryCatchBlockNodeInfo> clusterToFindFinally = tryCatchBlockIterator.next();
|
||||
@@ -174,10 +175,8 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
|
||||
FinallyBlockInfo finallyInfo = findFinallyBlockBody(nodeWithDefaultHandlerIfExists, getTryBlocksMetaInfo().getAllIntervals());
|
||||
if (finallyInfo == null) continue;
|
||||
TryCatchBlockNodeInfo defaultHandlerBlock = clusterToFindFinally.getDefaultHandler();
|
||||
assert defaultHandlerBlock != null;
|
||||
|
||||
originalDeepIndex++;
|
||||
originalDepthIndex++;
|
||||
|
||||
instructions.resetLabels();
|
||||
|
||||
@@ -204,7 +203,7 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
!(currentIns instanceof JumpInsnNode) ||
|
||||
labelsInsideFinally.contains(((JumpInsnNode) currentIns).label);
|
||||
|
||||
copyInstruction(finallyBlockCopy, currentIns, isInsOrJumpInsideFinally, originalDeepIndex);
|
||||
copyInstruction(finallyBlockCopy, currentIns, isInsOrJumpInsideFinally, originalDepthIndex);
|
||||
|
||||
currentIns = currentIns.getNext();
|
||||
}
|
||||
@@ -249,12 +248,12 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
@NotNull MethodNode finallyBlockCopy,
|
||||
@NotNull AbstractInsnNode currentIns,
|
||||
boolean isInsOrJumpInsideFinally,
|
||||
int deep
|
||||
int depthShift
|
||||
) {
|
||||
if (isInsOrJumpInsideFinally) {
|
||||
if (InlineCodegenUtil.isFinallyMarker(currentIns.getNext())) {
|
||||
Integer constant = getConstant(currentIns);
|
||||
finallyBlockCopy.visitLdcInsn(constant + deep);
|
||||
finallyBlockCopy.visitLdcInsn(constant + depthShift);
|
||||
} else {
|
||||
currentIns.accept(finallyBlockCopy); //VISIT
|
||||
}
|
||||
@@ -383,7 +382,7 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
// so we should split original interval by inserted finally one
|
||||
for (TryCatchBlockNodeInfo block : updatingClusterBlocks) {
|
||||
//update exception mapping
|
||||
SplittedPair<TryCatchBlockNodeInfo> split = tryBlocksMetaInfo.splitAndRemoveInterval(block, splitBy, false);
|
||||
SplitPair<TryCatchBlockNodeInfo> split = tryBlocksMetaInfo.splitAndRemoveInterval(block, splitBy, false);
|
||||
checkFinally(split.getNewPart());
|
||||
checkFinally(split.getPatchedPart());
|
||||
//block patched in split method
|
||||
@@ -451,14 +450,14 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
AbstractInsnNode meaningful = getNextMeaningful(startFinallyChain);
|
||||
assert meaningful != null : "Can't find meaningful in finally block" + startFinallyChain;
|
||||
|
||||
Integer finallyDeep = getConstant(meaningful);
|
||||
Integer finallyDepth = getConstant(meaningful);
|
||||
AbstractInsnNode endFinallyChainExclusive = nextIntervalWithSameDefaultHandler.getNode().start;
|
||||
AbstractInsnNode current = meaningful.getNext();
|
||||
while (endFinallyChainExclusive != current) {
|
||||
current = current.getNext();
|
||||
if (InlineCodegenUtil.isFinallyEnd(current)) {
|
||||
Integer currentDeep = getConstant(current.getPrevious());
|
||||
if (currentDeep.equals(finallyDeep)) {
|
||||
Integer currentDepth = getConstant(current.getPrevious());
|
||||
if (currentDepth.equals(finallyDepth)) {
|
||||
endFinallyChainExclusive = current.getNext();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
class InvokeCall {
|
||||
private final int index;
|
||||
public final LambdaInfo lambdaInfo;
|
||||
public final int finallyDeep;
|
||||
public final int finallyDepthShift;
|
||||
|
||||
InvokeCall(int index, @Nullable LambdaInfo lambdaInfo, int finallyDeep) {
|
||||
InvokeCall(int index, @Nullable LambdaInfo lambdaInfo, int finallyDepthShift) {
|
||||
this.index = index;
|
||||
this.lambdaInfo = lambdaInfo;
|
||||
this.finallyDeep = finallyDeep;
|
||||
this.finallyDepthShift = finallyDepthShift;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ public class MethodInliner {
|
||||
mapper);
|
||||
|
||||
LocalVarRemapper remapper = new LocalVarRemapper(lambdaParameters, valueParamShift);
|
||||
InlineResult lambdaResult = inliner.doInline(this.mv, remapper, true, info, invokeCall.finallyDeep);//TODO add skipped this and receiver
|
||||
InlineResult lambdaResult = inliner.doInline(this.mv, remapper, true, info, invokeCall.finallyDepthShift);//TODO add skipped this and receiver
|
||||
result.addAllClassesToRemove(lambdaResult);
|
||||
|
||||
//return value boxing/unboxing
|
||||
@@ -756,12 +756,16 @@ public class MethodInliner {
|
||||
|
||||
final Type returnType;
|
||||
|
||||
final LabelNode labelNode;
|
||||
final LabelNode finallyIntervalEnd;
|
||||
|
||||
public PointForExternalFinallyBlocks(@NotNull AbstractInsnNode beforeIns, @NotNull Type returnType, @NotNull LabelNode labelNode) {
|
||||
public PointForExternalFinallyBlocks(
|
||||
@NotNull AbstractInsnNode beforeIns,
|
||||
@NotNull Type returnType,
|
||||
@NotNull LabelNode finallyIntervalEnd
|
||||
) {
|
||||
this.beforeIns = beforeIns;
|
||||
this.returnType = returnType;
|
||||
this.labelNode = labelNode;
|
||||
this.finallyIntervalEnd = finallyIntervalEnd;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ enum class TryCatchPosition {
|
||||
INNER
|
||||
}
|
||||
|
||||
public class SplittedPair<T: Interval>(val patchedPart: T, val newPart: T)
|
||||
public class SplitPair<T: Interval>(val patchedPart: T, val newPart: T)
|
||||
|
||||
class SimpleInterval(override val startLabel: LabelNode, override val endLabel: LabelNode ) : Interval
|
||||
|
||||
@@ -40,7 +40,7 @@ trait Interval {
|
||||
}
|
||||
|
||||
trait SplittableInterval<T: Interval> : Interval {
|
||||
fun split(splitBy: Interval, keepStart: Boolean): SplittedPair<T>
|
||||
fun split(splitBy: Interval, keepStart: Boolean): SplitPair<T>
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class TryCatchBlockNodeInfo(val node: TryCatchBlockNode, val onlyCopyNotProcess:
|
||||
override val type: String?
|
||||
get() = node.type
|
||||
|
||||
override fun split(splitBy: Interval, keepStart: Boolean): SplittedPair<TryCatchBlockNodeInfo> {
|
||||
override fun split(splitBy: Interval, keepStart: Boolean): SplitPair<TryCatchBlockNodeInfo> {
|
||||
val newPartInterval = if (keepStart) {
|
||||
val oldEnd = endLabel
|
||||
node.end = splitBy.startLabel
|
||||
@@ -70,7 +70,7 @@ class TryCatchBlockNodeInfo(val node: TryCatchBlockNode, val onlyCopyNotProcess:
|
||||
node.start = splitBy.endLabel
|
||||
Pair(oldStart, splitBy.startLabel)
|
||||
}
|
||||
return SplittedPair(
|
||||
return SplitPair(
|
||||
this,
|
||||
TryCatchBlockNodeInfo(TryCatchBlockNode(newPartInterval.first, newPartInterval.second, handler, type), onlyCopyNotProcess)
|
||||
)
|
||||
|
||||
@@ -32,11 +32,11 @@ public class InlineMarker {
|
||||
|
||||
}
|
||||
|
||||
public static void finallyStart(int finallyDeep) {
|
||||
public static void finallyStart(int finallyDepth) {
|
||||
|
||||
}
|
||||
|
||||
public static void finallyEnd(int finallyDeep) {
|
||||
public static void finallyEnd(int finallyDepth) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user