src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/EnumSwitchTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/EnumSwitchTest.java

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test;
  24 
  25 import org.junit.Test;
  26 
  27 import org.graalvm.compiler.nodes.StructuredGraph;
  28 import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
  29 import org.graalvm.compiler.nodes.java.LoadIndexedNode;

  30 import org.graalvm.compiler.phases.Phase;
  31 import org.graalvm.compiler.phases.common.RemoveValueProxyPhase;
  32 import org.graalvm.compiler.phases.tiers.Suites;
  33 
  34 public class EnumSwitchTest extends GraalCompilerTest {
  35 
  36     enum E {
  37         E0,
  38         E1,
  39         E2,
  40         E3,
  41         E4,
  42         E5,
  43         E6,
  44         E7,
  45         E8,
  46         E9,
  47         E10,
  48         E11,
  49         E12,


 120             case E19:
 121             case E20:
 122                 return 1;
 123             case E8:
 124             case E9:
 125             case E10:
 126                 return 2;
 127         }
 128         return -1;
 129     }
 130 
 131     @Test
 132     public void test2() {
 133         for (E e : E.values()) {
 134             test("test2Snippet", e);
 135         }
 136         test("test2Snippet", new Object[]{null});
 137     }
 138 
 139     @Override
 140     protected Suites createSuites() {
 141         Suites ret = super.createSuites();
 142         ret.getHighTier().prependPhase(new Phase() {
 143             @Override
 144             protected void run(StructuredGraph graph) {
 145                 /* Array load from the enum switch map. */
 146                 assertTrue(graph.getNodes().filter(LoadIndexedNode.class).count() == 1);
 147                 /* The actual switch. */
 148                 assertTrue(graph.getNodes().filter(IntegerSwitchNode.class).count() == 1);
 149             }
 150 
 151             @Override
 152             protected CharSequence getName() {
 153                 return "CheckGraphPhase";
 154             }
 155         });
 156         ret.getHighTier().findPhase(RemoveValueProxyPhase.class).add(new Phase() {
 157             @Override
 158             protected void run(StructuredGraph graph) {
 159                 /* Re-writing of the switch cases eliminates the array load. */
 160                 assertTrue(graph.getNodes().filter(LoadIndexedNode.class).count() == 0);
 161                 /* The switch is still there. */


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test;
  24 
  25 import org.junit.Test;
  26 
  27 import org.graalvm.compiler.nodes.StructuredGraph;
  28 import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
  29 import org.graalvm.compiler.nodes.java.LoadIndexedNode;
  30 import org.graalvm.compiler.options.OptionValues;
  31 import org.graalvm.compiler.phases.Phase;
  32 import org.graalvm.compiler.phases.common.RemoveValueProxyPhase;
  33 import org.graalvm.compiler.phases.tiers.Suites;
  34 
  35 public class EnumSwitchTest extends GraalCompilerTest {
  36 
  37     enum E {
  38         E0,
  39         E1,
  40         E2,
  41         E3,
  42         E4,
  43         E5,
  44         E6,
  45         E7,
  46         E8,
  47         E9,
  48         E10,
  49         E11,
  50         E12,


 121             case E19:
 122             case E20:
 123                 return 1;
 124             case E8:
 125             case E9:
 126             case E10:
 127                 return 2;
 128         }
 129         return -1;
 130     }
 131 
 132     @Test
 133     public void test2() {
 134         for (E e : E.values()) {
 135             test("test2Snippet", e);
 136         }
 137         test("test2Snippet", new Object[]{null});
 138     }
 139 
 140     @Override
 141     protected Suites createSuites(OptionValues options) {
 142         Suites ret = super.createSuites(options);
 143         ret.getHighTier().prependPhase(new Phase() {
 144             @Override
 145             protected void run(StructuredGraph graph) {
 146                 /* Array load from the enum switch map. */
 147                 assertTrue(graph.getNodes().filter(LoadIndexedNode.class).count() == 1);
 148                 /* The actual switch. */
 149                 assertTrue(graph.getNodes().filter(IntegerSwitchNode.class).count() == 1);
 150             }
 151 
 152             @Override
 153             protected CharSequence getName() {
 154                 return "CheckGraphPhase";
 155             }
 156         });
 157         ret.getHighTier().findPhase(RemoveValueProxyPhase.class).add(new Phase() {
 158             @Override
 159             protected void run(StructuredGraph graph) {
 160                 /* Re-writing of the switch cases eliminates the array load. */
 161                 assertTrue(graph.getNodes().filter(LoadIndexedNode.class).count() == 0);
 162                 /* The switch is still there. */
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/EnumSwitchTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File