Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 65924 Details for
Bug 162965
[compiler] dead bytecodes are generated inside conditional expressions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
162965.txt (text/plain), 12.71 KB, created by
Philipe Mulet
on 2007-05-04 10:02:34 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2007-05-04 10:02:34 EDT
Size:
12.71 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java,v >retrieving revision 1.86 >diff -u -r1.86 ConditionalExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 28 Oct 2006 04:11:27 -0000 1.86 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 4 May 2007 14:01:12 -0000 >@@ -234,9 +234,28 @@ > > if (needFalsePart) { > // Jump over the else part >- int position = codeStream.position; >- codeStream.goto_(endifLabel); >- codeStream.updateLastRecordedEndPC(currentScope, position); >+ JumpEndif: { >+ if (falseLabel == null) { >+ if (trueLabel != null) { >+ // implicit falling through the FALSE case >+ cst = this.optimizedIfTrueConstant; >+ boolean isValueIfTrueOptimizedTrue = cst != null && cst != Constant.NotAConstant && cst.booleanValue() == true; >+ if (isValueIfTrueOptimizedTrue) break JumpEndif; // no need to jump over, since branched to true already >+ } >+ } else { >+ // implicit falling through the TRUE case >+ if (trueLabel == null) { >+ cst = this.optimizedIfTrueConstant; >+ boolean isValueIfTrueOptimizedFalse = cst != null && cst != Constant.NotAConstant && cst.booleanValue() == false; >+ if (isValueIfTrueOptimizedFalse) break JumpEndif; // no need to jump over, since branched to false already >+ } else { >+ // no implicit fall through TRUE/FALSE --> should never occur >+ } >+ } >+ int position = codeStream.position; >+ codeStream.goto_(endifLabel); >+ codeStream.updateLastRecordedEndPC(currentScope, position); >+ } > // No need to decrement codestream stack size > // since valueIfTrue was already consumed by branch bytecode > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java,v >retrieving revision 1.10 >diff -u -r1.10 BooleanTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java 20 Jun 2006 13:24:32 -0000 1.10 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java 4 May 2007 14:01:13 -0000 >@@ -1933,7 +1933,265 @@ > assertTrue(false); > } > } >- >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 >+public void test039() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " boolean a = true, b;\n" + >+ " if (a ? false : (b = true))\n" + >+ " a = b;\n" + >+ " System.out.println(\"SUCCESS\");\n" + >+ " }\n" + >+ "}\n", // ================= >+ }, >+ "SUCCESS"); >+ // ensure optimized boolean codegen sequence >+ String expectedOutput = >+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public static void main(java.lang.String[] args);\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [a]\n" + >+ " 2 iload_1 [a]\n" + >+ " 3 ifeq 9\n" + >+ " 6 goto 17\n" + >+ " 9 iconst_1\n" + >+ " 10 dup\n" + >+ " 11 istore_2 [b]\n" + >+ " 12 ifeq 17\n" + >+ " 15 iload_2 [b]\n" + >+ " 16 istore_1 [a]\n" + >+ " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + >+ " 20 ldc <String \"SUCCESS\"> [22]\n" + >+ " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + >+ " 25 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 15, line: 5]\n" + >+ " [pc: 17, line: 6]\n" + >+ " [pc: 25, line: 7]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 26] local: args index: 0 type: java.lang.String[]\n" + >+ " [pc: 2, pc: 26] local: a index: 1 type: boolean\n" + >+ " [pc: 12, pc: 17] local: b index: 2 type: boolean\n"; >+ >+ try { >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } catch (org.eclipse.jdt.core.util.ClassFormatException e) { >+ assertTrue(false); >+ } catch (IOException e) { >+ assertTrue(false); >+ } >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 - variation >+public void test040() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " boolean a = true, b = false;\n" + >+ " if (!(a ? true : (b = true)))\n" + >+ " a = b;\n" + >+ " System.out.println(\"SUCCESS\");\n" + >+ " }\n" + >+ "}\n", // ================= >+ }, >+ "SUCCESS"); >+ // ensure optimized boolean codegen sequence >+ String expectedOutput = >+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public static void main(java.lang.String[] args);\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [a]\n" + >+ " 2 iconst_0\n" + >+ " 3 istore_2 [b]\n" + >+ " 4 iload_1 [a]\n" + >+ " 5 ifeq 11\n" + >+ " 8 goto 19\n" + >+ " 11 iconst_1\n" + >+ " 12 dup\n" + >+ " 13 istore_2 [b]\n" + >+ " 14 ifne 19\n" + >+ " 17 iload_2 [b]\n" + >+ " 18 istore_1 [a]\n" + >+ " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + >+ " 22 ldc <String \"SUCCESS\"> [22]\n" + >+ " 24 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + >+ " 27 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 4, line: 4]\n" + >+ " [pc: 17, line: 5]\n" + >+ " [pc: 19, line: 6]\n" + >+ " [pc: 27, line: 7]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 28] local: args index: 0 type: java.lang.String[]\n" + >+ " [pc: 2, pc: 28] local: a index: 1 type: boolean\n" + >+ " [pc: 4, pc: 28] local: b index: 2 type: boolean\n"; >+ >+ try { >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } catch (org.eclipse.jdt.core.util.ClassFormatException e) { >+ assertTrue(false); >+ } catch (IOException e) { >+ assertTrue(false); >+ } >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 - variation >+public void test041() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " boolean a = true, b = false;\n" + >+ " if (a ? true : (b = false))\n" + >+ " a = b;\n" + >+ " System.out.println(\"SUCCESS\");\n" + >+ " }\n" + >+ "}\n", // ================= >+ }, >+ "SUCCESS"); >+ // ensure optimized boolean codegen sequence >+ String expectedOutput = >+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public static void main(java.lang.String[] args);\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [a]\n" + >+ " 2 iconst_0\n" + >+ " 3 istore_2 [b]\n" + >+ " 4 iload_1 [a]\n" + >+ " 5 ifeq 11\n" + >+ " 8 goto 17\n" + >+ " 11 iconst_0\n" + >+ " 12 dup\n" + >+ " 13 istore_2 [b]\n" + >+ " 14 ifeq 19\n" + >+ " 17 iload_2 [b]\n" + >+ " 18 istore_1 [a]\n" + >+ " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + >+ " 22 ldc <String \"SUCCESS\"> [22]\n" + >+ " 24 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + >+ " 27 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 4, line: 4]\n" + >+ " [pc: 17, line: 5]\n" + >+ " [pc: 19, line: 6]\n" + >+ " [pc: 27, line: 7]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 28] local: args index: 0 type: java.lang.String[]\n" + >+ " [pc: 2, pc: 28] local: a index: 1 type: boolean\n" + >+ " [pc: 4, pc: 28] local: b index: 2 type: boolean\n"; >+ >+ try { >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } catch (org.eclipse.jdt.core.util.ClassFormatException e) { >+ assertTrue(false); >+ } catch (IOException e) { >+ assertTrue(false); >+ } >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 - variation >+public void test042() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " boolean a = true, b;\n" + >+ " if (a ? (b = true) : false)\n" + >+ " a = b;\n" + >+ " System.out.println(\"SUCCESS\");\n" + >+ " } \n" + >+ "}\n", // ================= >+ }, >+ "SUCCESS"); >+ // ensure optimized boolean codegen sequence >+ String expectedOutput = >+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public static void main(java.lang.String[] args);\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [a]\n" + >+ " 2 iload_1 [a]\n" + >+ " 3 ifeq 14\n" + >+ " 6 iconst_1\n" + >+ " 7 dup\n" + >+ " 8 istore_2 [b]\n" + >+ " 9 ifeq 14\n" + >+ " 12 iload_2 [b]\n" + >+ " 13 istore_1 [a]\n" + >+ " 14 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + >+ " 17 ldc <String \"SUCCESS\"> [22]\n" + >+ " 19 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + >+ " 22 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 12, line: 5]\n" + >+ " [pc: 14, line: 6]\n" + >+ " [pc: 22, line: 7]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 23] local: args index: 0 type: java.lang.String[]\n" + >+ " [pc: 2, pc: 23] local: a index: 1 type: boolean\n" + >+ " [pc: 9, pc: 14] local: b index: 2 type: boolean\n"; >+ >+ try { >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } catch (org.eclipse.jdt.core.util.ClassFormatException e) { >+ assertTrue(false); >+ } catch (IOException e) { >+ assertTrue(false); >+ } >+} > public static Class testClass() { > return BooleanTest.class; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 162965
: 65924