Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Thomann2019-01-30 23:39:16 +0000
committerManoj Palat2019-01-30 23:39:16 +0000
commitda04d8f1a677de7cdd83e4f378142a452cdb2bd0 (patch)
treea9a37db560cbe3d45e2230fbbfdfe82d9a7f5359
parent9befbe89d9316367b87d4c09e2038ccd631a3e6a (diff)
downloadeclipse.jdt.core-da04d8f1a677de7cdd83e4f378142a452cdb2bd0.tar.gz
eclipse.jdt.core-da04d8f1a677de7cdd83e4f378142a452cdb2bd0.tar.xz
eclipse.jdt.core-da04d8f1a677de7cdd83e4f378142a452cdb2bd0.zip
Bug 542838 - [12] JEP 325 Switch Expressions - Code GenerationY20190130-2200
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java218
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java23
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java33
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java31
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java32
8 files changed, 260 insertions, 92 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
index 8d52271724..7168a1ece3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
@@ -63,18 +63,18 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] {
"X.java",
"public class X {\n" +
- " static int twice(int i) {\n" +
- " int tw = switch (i) {\n" +
- " case 0 -> i * 0;\n" +
- " case 1 -> 2;\n" +
- " default -> 3;\n" +
- " };\n" +
- " return tw;\n" +
- " }\n" +
- " public static void main(String... args) {\n" +
- " System.out.print(twice(3));\n" +
- " }\n" +
- "}\n"
+ " static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n"
},
"3",
null,
@@ -248,24 +248,24 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] {
"X.java",
"public class X {\n"+
- " static int foo(int i) {\n"+
- " int tw = \n"+
- " switch (i) {\n"+
- " case 1 -> \n"+
- " {\n"+
- " int z = 100;\n"+
- " break z;\n"+
- " }\n"+
- " default -> {\n"+
- " break 12;\n"+
- " }\n"+
- " };\n"+
- " return tw;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.print(foo(1));\n"+
- " }\n"+
- "}\n"
+ " static int foo(int i) {\n"+
+ " int tw = \n"+
+ " switch (i) {\n"+
+ " case 1 -> \n"+
+ " {\n"+
+ " int z = 100;\n"+
+ " break z;\n"+
+ " }\n"+
+ " default -> {\n"+
+ " break 12;\n"+
+ " }\n"+
+ " };\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n"
},
"100",
null,
@@ -431,26 +431,32 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String[] testFiles = new String[] {
"X.java",
"public class X {\n" +
- " @SuppressWarnings(\"preview\")\n" +
- " static int twice(int i) {\n" +
- " switch (i) {\n" +
- " default -> 3;\n" +
- " }\n" +
- " return 0;\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " System.out.print(twice(3));\n" +
- " }\n" +
- "}\n",
+ " @SuppressWarnings(\"preview\")\n" +
+ " static int twice(int i) {\n" +
+ " switch (i) {\n" +
+ " default -> 3;\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n",
};
String expectedProblemLog =
- "0";
- this.runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " default :v = 2;\n" +
+ " ^^^^^\n" +
+ "A switch labeled block in a switch expression should not complete normally\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
- options,
- new String[] {"--enable-preview"});
+ null,
+ true,
+ getCompilerOptions());
}
public void testBug531714_012() {
Map<String, String> options = getCompilerOptions();
@@ -542,6 +548,9 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" default -> null;\n" +
" }.toLowerCase());\n" +
" }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().test(1);\n" +
+ " }\n" +
"}\n"
};
runner.expectedCompilerLog =
@@ -976,8 +985,8 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" case 2, 4: \n" +
" System.out.println(\"Even\");\n" +
" break;\n" +
- " default:\n" +
- " System.out.println(\"Out of range\");\n" +
+ " default:\n" +
+ " System.out.println(\"Out of range\");\n" +
" }\n" +
" }\n" +
"}",
@@ -1045,20 +1054,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String[] testFiles = new String[] {
"X.java",
"public class X {\n" +
- " public static void main(String[] args) {\n" +
- " }\n" +
- " public static void bar(int i) {\n" +
- " switch (i) {\n" +
- " case 1, 3: \n" +
- " System.out.println(\"Odd\");\n" +
- " case 2, 4: \n" +
- " System.out.println(\"Even\");\n" +
- " break;\n" +
- " default:\n" +
- " System.out.println(\"Out of range\");\n" +
- " }\n" +
- " }\n" +
- "}",
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " case 2, 4: \n" +
+ " System.out.println(\"Even\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"Out of range\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
};
String expectedProblemLog =
"----------\n" +
@@ -1086,17 +1095,17 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String[] testFiles = new String[] {
"X.java",
"public class X {\n" +
- " public static void main(String[] args) {\n" +
- " }\n" +
- " public static void bar(int i) {\n" +
- " switch (i) {\n" +
- " case 1, 3: \n" +
- " System.out.println(\"Odd\");\n" +
- " case 2, 4: \n" +
- " System.out.println(\"Even\");\n" +
- " }\n" +
- " }\n" +
- "}",
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " case 2, 4: \n" +
+ " System.out.println(\"Even\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
};
String expectedProblemLog =
"----------\n" +
@@ -1104,7 +1113,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" switch (i) {\n" +
" ^\n" +
"The switch statement should have a default case\n" +
- "----------\n";
+ "----------\n";
this.runNegativeTest(
testFiles,
expectedProblemLog,
@@ -1273,7 +1282,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String[] testFiles = new String[] {
"X.java",
"public class X {\n" +
- " void test(int i) {\n" +
+ " void test(int i) {\n" +
" need(switch (i) {\n" +
" case 1 -> \"\";\n" +
" default -> i == 3 ? null : \"\";\n" +
@@ -1402,4 +1411,65 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String expectedOutput = "3";
runConformTest(testFiles, expectedOutput, options);
}
+ public void testSwitchStatementWithBreakExpression() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) throws Exception {\n" +
+ " switch (i) {\n" +
+ " case 0 -> System.out.println(\"hellow\");\n" +
+ " case 1 -> foo();\n" +
+ " default -> throw new Exception();\n" +
+ " };\n" +
+ " return 0;\n" +
+ " }\n" +
+ "\n" +
+ " static int foo() {\n" +
+ " System.out.println(\"inside foo\");\n" +
+ " return 1;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " try {\n" +
+ " System.out.print(twice(1));\n" +
+ " } catch (Exception e) {\n" +
+ " System.out.print(\"Got Exception\");\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "inside foo\n"
+ + "0",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testSwitchStatementWithEnumValues() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "enum SomeDays {\n" +
+ " Mon, Wed, Fri\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " int testEnum(boolean b) {\n" +
+ " SomeDays day = b ? SomeDays.Mon : null;\n" +
+ " return switch(day) {\n" +
+ " case Mon -> 1;\n" +
+ " case Wed -> 2;\n" +
+ " case Fri -> 3;\n" +
+ " };\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().testEnum(true));\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ },
+ "1",
+ null,
+ new String[] {"--enable-preview"});
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java
index a73556b3cc..ece451e2c2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -39,6 +39,9 @@ public BranchStatement(char[] label, int sourceStart,int sourceEnd) {
protected void generateExpressionResultCode(BlockScope currentScope, CodeStream codeStream) {
// do nothing here
}
+protected void adjustStackSize(BlockScope currentScope, CodeStream codeStream) {
+ // do nothing here
+}
/**
* Branch code generation
*
@@ -70,6 +73,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
}
}
codeStream.goto_(this.targetLabel);
+ adjustStackSize(currentScope, codeStream);
codeStream.recordPositionsFrom(pc, this.sourceStart);
SubRoutineStatement.reenterAllExceptionHandlers(this.subroutines, -1, codeStream);
if (this.initStateIndex != -1) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java
index 3d09418529..34d0e9452e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java
@@ -105,12 +105,27 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
}
return FlowInfo.DEAD_END;
}
-
-
@Override
protected void generateExpressionResultCode(BlockScope currentScope, CodeStream codeStream) {
- if (this.label == null && this.expression != null && (this.switchExpression != null || this.isImplicit)) {
- this.expression.generateCode(currentScope, codeStream, true /* valueRequired */);
+ if (this.label == null && this.expression != null) {
+ this.expression.generateCode(currentScope, codeStream, this.switchExpression != null);
+ }
+}
+@Override
+protected void adjustStackSize(BlockScope currentScope, CodeStream codeStream) {
+ if (this.label == null && this.expression != null && this.switchExpression != null) {
+ TypeBinding postConversionType = this.expression.postConversionType(currentScope);
+ switch(postConversionType.id) {
+ case TypeIds.T_long :
+ case TypeIds.T_double :
+ codeStream.decrStackSize(2);
+ break;
+ case TypeIds.T_void :
+ break;
+ default :
+ codeStream.decrStackSize(1);
+ break;
+ }
}
}
@Override
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
index 0b9830cb55..7763555c82 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
@@ -555,7 +555,7 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression
for (Expression re : this.resultExpressions) {
this.resultExpressionNullStatus.add(re.nullStatus(flowInfo, flowContext));
// wipe information that was meant only for this result expression:
- flowContext.expireNullCheckedFieldInfo();
+ flowContext.expireNullCheckedFieldInfo();
}
}
computeNullStatus(flowInfo, flowContext);
@@ -647,4 +647,8 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression
}
return true;
}
+ @Override
+ public TypeBinding expectedType() {
+ return this.expectedType;
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
index d7492052a8..4f5b7503d1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -406,6 +406,7 @@ public class SwitchStatement extends Expression {
// we can get rid of the generated ordinal value
codeStream.pop();
}
+ valueRequired = hasCases;
} else {
valueRequired = this.expression.constant == Constant.NotAConstant || hasCases;
// generate expression
@@ -471,6 +472,26 @@ public class SwitchStatement extends Expression {
statementGenerateCode(currentScope, codeStream, statement);
}
}
+ boolean enumInSwitchExpression = resolvedType1.isEnum() && this instanceof SwitchExpression;
+ if (this.defaultCase == null && enumInSwitchExpression) {
+ // we want to force an line number entry to get an end position after the switch statement
+ if (this.preSwitchInitStateIndex != -1) {
+ codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.preSwitchInitStateIndex);
+ }
+ defaultLabel.place();
+ /* a default case is not needed for enum if all enum values are used in the switch expression
+ * we need to handle the default case to throw an error (IncompatibleClassChangeError) in order
+ * to make the stack map consistent. All cases will return a value on the stack except the missing default
+ * case.
+ * There is no returned value for the default case so we handle it with an exception thrown. An
+ * IllegalClassChangeError seems legitimate as this would mean the enum type has been recompiled with more
+ * enum constants and the class that is using the switch on the enum has not been recompiled
+ */
+ codeStream.newJavaLangIncompatibleClassChangeError();
+ codeStream.dup();
+ codeStream.invokeJavaLangIncompatibleClassChangeErrorDefaultConstructor();
+ codeStream.athrow();
+ }
// May loose some local variable initializations : affecting the local variable attributes
if (this.mergedInitStateIndex != -1) {
codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
@@ -481,11 +502,19 @@ public class SwitchStatement extends Expression {
}
// place the trailing labels (for break and default case)
this.breakLabel.place();
- if (this.defaultCase == null) {
+ if (this.defaultCase == null && !enumInSwitchExpression) {
// we want to force an line number entry to get an end position after the switch statement
codeStream.recordPositionsFrom(codeStream.position, this.sourceEnd, true);
defaultLabel.place();
}
+ if (valueRequired && this.expectedType() != null) {
+ TypeBinding expectedType = this.expectedType().erasure();
+ /*
+ * is the last goto was optimized the lastAbruptCompletion is equal to -1 which means there is already some value on the
+ * stack so we don't need to add one.
+ */
+ codeStream.recordExpressionType(expectedType, codeStream.lastAbruptCompletion != -1 ? 1 : 0);
+ }
codeStream.recordPositionsFrom(pc, this.sourceStart);
} finally {
if (this.scope != null) this.scope.enclosingCase = null; // no longer inside switch case block
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
index a3b5793bd9..6337561397 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -4567,7 +4567,16 @@ public void invokeJavaLangAssertionErrorDefaultConstructor() {
ConstantPool.Init,
ConstantPool.DefaultConstructorSignature);
}
-
+public void invokeJavaLangIncompatibleClassChangeErrorDefaultConstructor() {
+ // invokespecial: java.lang.IncompatibleClassChangeError.<init>()V
+ invoke(
+ Opcodes.OPC_invokespecial,
+ 1, // receiverAndArgsSize
+ 0, // return type size
+ ConstantPool.JavaLangIncompatibleClassChangeErrorConstantPoolName,
+ ConstantPool.Init,
+ ConstantPool.DefaultConstructorSignature);
+}
public void invokeJavaLangClassDesiredAssertionStatus() {
// invokevirtual: java.lang.Class.desiredAssertionStatus()Z;
invoke(
@@ -6142,7 +6151,19 @@ public void newJavaLangError() {
this.bCodeStream[this.classFileOffset++] = Opcodes.OPC_new;
writeUnsignedShort(this.constantPool.literalIndexForType(ConstantPool.JavaLangErrorConstantPoolName));
}
-
+public void newJavaLangIncompatibleClassChangeError() {
+ // new: java.lang.Error
+ this.countLabels = 0;
+ this.stackDepth++;
+ if (this.stackDepth > this.stackMax)
+ this.stackMax = this.stackDepth;
+ if (this.classFileOffset + 2 >= this.bCodeStream.length) {
+ resizeByteArray();
+ }
+ this.position++;
+ this.bCodeStream[this.classFileOffset++] = Opcodes.OPC_new;
+ writeUnsignedShort(this.constantPool.literalIndexForType(ConstantPool.JavaLangIncompatibleClassChangeErrorConstantPoolName));
+}
public void newNoClassDefFoundError() {
// new: java.lang.NoClassDefFoundError
this.countLabels = 0;
@@ -6297,7 +6318,9 @@ public void record(LocalVariableBinding local) {
public void recordExpressionType(TypeBinding typeBinding) {
// nothing to do
}
-
+public void recordExpressionType(TypeBinding typeBinding, int delta) {
+ // nothing to do
+}
public void recordPositionsFrom(int startPC, int sourcePos) {
this.recordPositionsFrom(startPC, sourcePos, false);
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java
index 276c999ed2..700a70daa5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -167,6 +167,7 @@ public class ConstantPool implements ClassFileConstants, TypeIds {
public static final char[] JavaLangDoubleConstantPoolName = "java/lang/Double".toCharArray(); //$NON-NLS-1$
public static final char[] JavaLangEnumConstantPoolName = "java/lang/Enum".toCharArray(); //$NON-NLS-1$
public static final char[] JavaLangErrorConstantPoolName = "java/lang/Error".toCharArray(); //$NON-NLS-1$
+ public static final char[] JavaLangIncompatibleClassChangeErrorConstantPoolName = "java/lang/IncompatibleClassChangeError".toCharArray(); //$NON-NLS-1$
public static final char[] JavaLangExceptionConstantPoolName = "java/lang/Exception".toCharArray(); //$NON-NLS-1$
public static final char[] JavaLangFloatConstantPoolName = "java/lang/Float".toCharArray(); //$NON-NLS-1$
public static final char[] JavaLangIntegerConstantPoolName = "java/lang/Integer".toCharArray(); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java
index 039f188d76..df03ec309c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 IBM Corporation and others.
+ * Copyright (c) 2006, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -91,10 +91,17 @@ public class StackMapFrameCodeStream extends CodeStream {
StringBuffer buffer = new StringBuffer();
buffer.append('(').append(this.pc).append(',').append(this.delta);
if (this.typeBinding != null) {
- buffer
- .append(',')
- .append(this.typeBinding.qualifiedPackageName())
- .append(this.typeBinding.qualifiedSourceName());
+ if (this.typeBinding.isBaseType()) {
+ buffer
+ .append(',')
+ .append(this.typeBinding.qualifiedSourceName());
+ } else {
+ buffer
+ .append(',')
+ .append(this.typeBinding.qualifiedPackageName())
+ .append('.')
+ .append(this.typeBinding.qualifiedSourceName());
+ }
}
buffer.append(')');
return String.valueOf(buffer);
@@ -226,6 +233,7 @@ public void addFramePosition(int pc) {
public void optimizeBranch(int oldPosition, BranchLabel lbl) {
super.optimizeBranch(oldPosition, lbl);
removeFramePosition(oldPosition);
+ removeStackMapMarkers(oldPosition);
}
public void removeFramePosition(int pc) {
Integer entry = Integer.valueOf(pc);
@@ -237,6 +245,16 @@ public void removeFramePosition(int pc) {
}
}
}
+public void removeStackMapMarkers(int markerOldPosition) {
+ if (this.stackDepthMarkers != null) {
+ for (int i = this.stackDepthMarkers.size() - 1; i >= 0; i--) {
+ StackDepthMarker marker = (StackDepthMarker) this.stackDepthMarkers.get(i);
+ if (marker.pc == markerOldPosition) {
+ this.stackDepthMarkers.remove(i);
+ }
+ }
+ }
+}
@Override
public void addVariable(LocalVariableBinding localBinding) {
if (localBinding.initializationPCs == null) {
@@ -284,6 +302,10 @@ public void decrStackSize(int offset) {
public void recordExpressionType(TypeBinding typeBinding) {
addStackDepthMarker(this.position, 0, typeBinding);
}
+@Override
+public void recordExpressionType(TypeBinding typeBinding, int delta) {
+ addStackDepthMarker(this.position, delta, typeBinding);
+}
/**
* Macro for building a class descriptor object
*/

Back to the top