Skip to content

Commit

Permalink
Garbage collect unused bit-flag org.eclipse.jdt.internal.compiler.cod…
Browse files Browse the repository at this point in the history
…egen.BranchLabel.USED (#3408)

* Fixes #3407
  • Loading branch information
srikanth-sankaran authored Dec 6, 2024
1 parent 7a31ab7 commit 11bf464
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ public void generateCode(

// Generate code for the condition
falseLabel = new BranchLabel(codeStream);
falseLabel.tagBits |= BranchLabel.USED;
this.condition.generateOptimizedBoolean(
currentScope,
codeStream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {

// labels management
BranchLabel actionLabel = new BranchLabel(codeStream);
if (this.action != null) actionLabel.tagBits |= BranchLabel.USED;
actionLabel.place();
this.breakLabel.initialize(codeStream);
boolean hasContinueLabel = this.continueLabel != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {

// label management
BranchLabel actionLabel = new BranchLabel(codeStream);
actionLabel.tagBits |= BranchLabel.USED;
BranchLabel conditionLabel = new BranchLabel(codeStream);
this.breakLabel.initialize(codeStream);
if (this.continueLabel == null || conditionInjectsBindings) {
Expand All @@ -305,7 +304,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
if ((this.condition != null)
&& (this.condition.constant == Constant.NotAConstant)
&& !((this.action == null || this.action.isEmptyBlock()) && (this.increments == null))) {
conditionLabel.tagBits |= BranchLabel.USED;
int jumpPC = codeStream.position;
codeStream.goto_(conditionLabel);
codeStream.recordPositionsFrom(jumpPC, this.condition.sourceStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
}
// label management
BranchLabel actionLabel = new BranchLabel(codeStream);
actionLabel.tagBits |= BranchLabel.USED;
BranchLabel conditionLabel = new BranchLabel(codeStream);
conditionLabel.tagBits |= BranchLabel.USED;
this.breakLabel.initialize(codeStream);
if (this.continueLabel == null) {
// generate the condition (swapped for optimizing)
Expand All @@ -290,7 +288,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
codeStream.recordPositionsFrom(conditionPC, this.elementVariable.sourceStart);
} else {
this.continueLabel.initialize(codeStream);
this.continueLabel.tagBits |= BranchLabel.USED;
// jump over the actionBlock
codeStream.goto_(conditionLabel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ public String toString() {
String literal = this.labelExpressions[i].constant.stringValue();
stringCases[i] = new StringSwitchCase(literal.hashCode(), literal, sourceCaseLabels[i]);
hashCodeCaseLabels[i] = new CaseLabel(codeStream);
hashCodeCaseLabels[i].tagBits |= BranchLabel.USED;
}
Arrays.sort(stringCases);

Expand All @@ -563,13 +562,11 @@ public String toString() {
}

CaseLabel defaultCaseLabel = new CaseLabel(codeStream);
defaultCaseLabel.tagBits |= BranchLabel.USED;

// prepare the labels and constants
this.breakLabel.initialize(codeStream);

BranchLabel defaultBranchLabel = new BranchLabel(codeStream);
if (hasCases) defaultBranchLabel.tagBits |= BranchLabel.USED;
if (this.defaultCase != null) {
this.defaultCase.targetLabel = defaultBranchLabel;
}
Expand Down Expand Up @@ -649,10 +646,9 @@ private <T extends BranchLabel>T[] gatherLabels(CodeStream codeStream, T[] caseL
for (int k = 0; k < length; ++k) {
Expression e = peeledLabelExpressions[k];
if (e instanceof FakeDefaultLiteral) continue;
targetLabels[count++] = (caseLabels[j] = newLabel.apply(codeStream));
targetLabels[count++] = (caseLabels[j++] = newLabel.apply(codeStream));
if (e == this.totalPattern)
this.defaultCase = stmt;
caseLabels[j++].tagBits |= BranchLabel.USED;
}
System.arraycopy(targetLabels, 0, stmt.targetLabels = new BranchLabel[count], 0, count);
}
Expand Down Expand Up @@ -682,7 +678,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {

CaseLabel defaultLabel = new CaseLabel(codeStream);
final boolean hasCases = this.caseCount > 1 || (this.caseCount == 1 && this.defaultCase == null);
if (hasCases) defaultLabel.tagBits |= BranchLabel.USED;
if (this.defaultCase != null) {
this.defaultCase.targetLabel = defaultLabel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
// generate the action
BranchLabel actionLabel = new BranchLabel(codeStream);
if (this.action != null) {
actionLabel.tagBits |= BranchLabel.USED;
// Required to fix 1PR0XVS: LFRE:WINNT - Compiler: variable table for method appears incorrect
if (this.condIfTrueInitStateIndex != -1) {
// insert all locals initialized inside the condition into the action generated prior to the condition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class BranchLabel extends Label {
public int tagBits;
protected int targetStackDepth = -1;
public final static int WIDE = 1;
public final static int USED = 2;
public final static int VALIDATE = 4;
public final static int VALIDATE = 2;
private OperandStack operandStack;


Expand Down Expand Up @@ -194,7 +193,6 @@ protected void trackStackDepth(boolean branch) {
* Put down a reference to the array at the location in the codestream.
*/
void branch() {
this.tagBits |= BranchLabel.USED;
if (this.delegate != null) {
this.delegate.branch();
return;
Expand All @@ -217,7 +215,6 @@ void branch() {
* No support for wide branches yet
*/
void branchWide() {
this.tagBits |= BranchLabel.USED;
if (this.delegate != null) {
this.delegate.branchWide();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ public boolean isStandardLabel(){
*/
@Override
public void place() {
if ((this.tagBits & USED) != 0) {
this.position = this.codeStream.getPosition();
} else {
this.position = this.codeStream.position;
}
this.position = this.codeStream.position;
if (this.instructionPosition != POS_NOT_SET) {
int offset = this.position - this.instructionPosition;
int[] forwardRefs = forwardReferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3690,9 +3690,6 @@ public static TypeBinding getConstantPoolDeclaringClass(Scope currentScope, Meth
}
return constantPoolDeclaringClass;
}
protected int getPosition() {
return this.position;
}

public void getClass(TypeBinding baseType) {
this.countLabels = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int getCount() {
public void place() {
// register the handler inside the codeStream then normal place
this.codeStream.registerExceptionHandler(this);
this.position = this.codeStream.getPosition();
this.position = this.codeStream.position;
this.codeStream.stackDepth = 1;
}

Expand Down

0 comments on commit 11bf464

Please sign in to comment.