2
2
* ProGuard -- shrinking, optimization, obfuscation, and preverification
5
* Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
5
* Copyright (c) 2002-2015 Eric Lafortune @ GuardSquare
7
7
* This program is free software; you can redistribute it and/or modify it
8
8
* under the terms of the GNU General Public License as published by the Free
76
78
private final int[] codeFragmentLengths = new int[MAXIMUM_LEVELS];
77
79
private final int[][] instructionOffsetMap = new int[MAXIMUM_LEVELS][ClassConstants.TYPICAL_CODE_LENGTH + 1];
79
private ExceptionInfo[] exceptionTable = new ExceptionInfo[ClassConstants.TYPICAL_EXCEPTION_TABLE_LENGTH];
81
private ExceptionInfo[] exceptionTable = new ExceptionInfo[ClassConstants.TYPICAL_EXCEPTION_TABLE_LENGTH];
82
private LineNumberInfo[] lineNumberTable = new LineNumberInfo[ClassConstants.TYPICAL_LINE_NUMBER_TABLE_LENGTH];
81
84
private int expectedStackMapFrameOffset;
347
* Inserts the given line number at the appropriate position in the line
349
* @param lineNumberInfo the line number to be inserted.
350
* @return the index where the line number was actually inserted.
352
public int insertLineNumber(LineNumberInfo lineNumberInfo)
354
return insertLineNumber(0, lineNumberInfo);
359
* Inserts the given line number at the appropriate position in the line
361
* @param minimumIndex the minimum index where the line number may be
363
* @param lineNumberInfo the line number to be inserted.
364
* @return the index where the line number was inserted.
366
public int insertLineNumber(int minimumIndex, LineNumberInfo lineNumberInfo)
370
print(" ", "Line number ["+lineNumberInfo.u2startPC+"]");
373
// Remap the line number right away.
374
visitLineNumberInfo(null, null, null, lineNumberInfo);
378
System.out.println(" -> ["+lineNumberInfo.u2startPC+"] line "+lineNumberInfo.u2lineNumber+(lineNumberInfo.getSource()==null ? "":" ["+lineNumberInfo.getSource()+"]"));
382
(LineNumberInfo[])ArrayUtil.extendArray(lineNumberTable,
383
lineNumberTableLength + 1);
385
// Find the insertion index, starting from the end.
386
// Don't insert before a negative line number, in case of a tie.
387
int index = lineNumberTableLength++;
388
while (index > minimumIndex &&
389
(lineNumberTable[index - 1].u2startPC > lineNumberInfo.u2startPC ||
390
lineNumberTable[index - 1].u2startPC >= lineNumberInfo.u2startPC &&
391
lineNumberTable[index - 1].u2lineNumber >= 0))
393
lineNumberTable[index] = lineNumberTable[--index];
396
lineNumberTable[index] = lineNumberInfo;
403
* Appends the given line number to the line number table.
404
* @param lineNumberInfo the line number to be appended.
406
public void appendLineNumber(LineNumberInfo lineNumberInfo)
410
print(" ", "Line number ["+lineNumberInfo.u2startPC+"]");
413
// Remap the line number right away.
414
visitLineNumberInfo(null, null, null, lineNumberInfo);
418
System.out.println(" -> ["+lineNumberInfo.u2startPC+"] line "+lineNumberInfo.u2lineNumber+(lineNumberInfo.getSource()==null ? "":" ["+lineNumberInfo.getSource()+"]"));
421
// Add the line number.
423
(LineNumberInfo[])ArrayUtil.add(lineNumberTable,
424
lineNumberTableLength++,
343
430
* Wraps up the current code fragment, continuing with the previous one on
458
545
stackSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);
459
546
variableSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);
461
// Remap the line number table and the local variable table.
548
// Add a new line number table for the line numbers, if necessary.
549
if (lineNumberTableLength > 0 &&
550
codeAttribute.getAttribute(clazz, ClassConstants.ATTR_LineNumberTable) == null)
552
int attributeNameIndex =
553
new ConstantPoolEditor((ProgramClass)clazz)
554
.addUtf8Constant(ClassConstants.ATTR_LineNumberTable);
556
new AttributesEditor((ProgramClass)clazz, (ProgramMember)method, codeAttribute, false)
557
.addAttribute(new LineNumberTableAttribute(attributeNameIndex, 0, null));
560
// Copy the line number table and the local variable table.
462
561
codeAttribute.attributesAccept(clazz, method, this);
464
563
// Remap the exception table (done before).
495
599
public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
497
// Remap all line number table entries.
498
lineNumberTableAttribute.lineNumbersAccept(clazz, method, codeAttribute, this);
601
// Didn't we get line number new definitions?
602
if (lineNumberTableLength == 0)
604
// Remap all line number table entries of the existing table.
605
lineNumberTableAttribute.lineNumbersAccept(clazz, method, codeAttribute, this);
609
// Remove line numbers with empty code blocks.
610
// Actually, we'll do this elsewhere, to allow processing the
611
// line numbers of inlined methods.
612
//lineNumberTableLength =
613
// removeEmptyLineNumbers(lineNumberTable,
614
// lineNumberTableLength,
615
// codeAttribute.u4codeLength);
500
// Remove line numbers with empty code blocks.
501
lineNumberTableAttribute.u2lineNumberTableLength =
502
removeEmptyLineNumbers(lineNumberTableAttribute.lineNumberTable,
503
lineNumberTableAttribute.u2lineNumberTableLength,
504
codeAttribute.u4codeLength);
617
// Copy the line number table.
618
lineNumberTableAttribute.lineNumberTable = new LineNumberInfo[lineNumberTableLength];
619
lineNumberTableAttribute.u2lineNumberTableLength = lineNumberTableLength;
620
System.arraycopy(lineNumberTable, 0, lineNumberTableAttribute.lineNumberTable, 0, lineNumberTableLength);
508
624
public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
510
626
// Remap all local variable table entries.