< prev index next >

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

Print this page
rev 52889 : 8214023: Update Graal
   1 /*
   2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 
  24 
  25 package org.graalvm.compiler.core.test;
  26 
  27 import java.io.ByteArrayOutputStream;
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.lang.reflect.Constructor;
  31 import java.util.HashMap;
  32 
  33 import org.graalvm.compiler.debug.DebugContext;
  34 import org.graalvm.compiler.java.GraphBuilderPhase;
  35 import org.graalvm.compiler.nodes.StructuredGraph;
  36 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  37 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  38 import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
  39 import org.graalvm.compiler.options.OptionValues;
  40 import org.graalvm.compiler.phases.OptimisticOptimizations;
  41 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  42 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  43 import org.graalvm.compiler.phases.tiers.HighTierContext;
  44 import org.junit.Assert;
  45 import org.junit.Test;
  46 
  47 import jdk.vm.ci.meta.Assumptions;
  48 import jdk.vm.ci.meta.Assumptions.Assumption;
  49 import jdk.vm.ci.meta.Assumptions.LeafType;
  50 import jdk.vm.ci.meta.Assumptions.NoFinalizableSubclass;
  51 import jdk.vm.ci.meta.ResolvedJavaMethod;
  52 
  53 public class FinalizableSubclassTest extends GraalCompilerTest {
  54 
  55     /**
  56      * used as template to generate class files at runtime.
  57      */
  58     public static class NoFinalizerEverAAAA {
  59     }
  60 
  61     public static class NoFinalizerYetAAAA {
  62     }


  64     public static final class WithFinalizerAAAA extends NoFinalizerYetAAAA {
  65 
  66         @SuppressWarnings("deprecation")
  67         @Override
  68         protected void finalize() throws Throwable {
  69             super.finalize();
  70         }
  71     }
  72 
  73     private StructuredGraph parseAndProcess(Class<?> cl, AllowAssumptions allowAssumptions) {
  74         Constructor<?>[] constructors = cl.getConstructors();
  75         Assert.assertTrue(constructors.length == 1);
  76         final ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(constructors[0]);
  77         OptionValues options = getInitialOptions();
  78         StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options, null, javaMethod), allowAssumptions).method(javaMethod).build();
  79 
  80         GraphBuilderConfiguration conf = GraphBuilderConfiguration.getSnippetDefault(getDefaultGraphBuilderPlugins());
  81         new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), getProviders().getConstantReflection(), getProviders().getConstantFieldProvider(), conf,
  82                         OptimisticOptimizations.ALL, null).apply(graph);
  83         HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
  84         new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
  85         new CanonicalizerPhase().apply(graph, context);
  86         return graph;
  87     }
  88 
  89     private void checkForRegisterFinalizeNode(Class<?> cl, boolean shouldContainFinalizer, AllowAssumptions allowAssumptions) {
  90         StructuredGraph graph = parseAndProcess(cl, allowAssumptions);
  91         Assert.assertTrue(graph.getNodes().filter(RegisterFinalizerNode.class).count() == (shouldContainFinalizer ? 1 : 0));
  92         int noFinalizerAssumption = 0;
  93         Assumptions assumptions = graph.getAssumptions();
  94         if (assumptions != null) {
  95             for (Assumption a : assumptions) {
  96                 if (a instanceof NoFinalizableSubclass) {
  97                     noFinalizerAssumption++;
  98                 } else if (a instanceof LeafType) {
  99                     // Need to also allow leaf type assumption instead of no finalizable subclass
 100                     // assumption.
 101                     noFinalizerAssumption++;
 102                 }
 103             }
 104         }


   1 /*
   2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 
  24 
  25 package org.graalvm.compiler.core.test;
  26 
  27 import java.io.ByteArrayOutputStream;
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.lang.reflect.Constructor;
  31 import java.util.HashMap;
  32 
  33 import org.graalvm.compiler.debug.DebugContext;
  34 import org.graalvm.compiler.java.GraphBuilderPhase;
  35 import org.graalvm.compiler.nodes.StructuredGraph;
  36 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  37 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  38 import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
  39 import org.graalvm.compiler.options.OptionValues;
  40 import org.graalvm.compiler.phases.OptimisticOptimizations;
  41 import org.graalvm.compiler.phases.common.CanonicalizerPhase;

  42 import org.graalvm.compiler.phases.tiers.HighTierContext;
  43 import org.junit.Assert;
  44 import org.junit.Test;
  45 
  46 import jdk.vm.ci.meta.Assumptions;
  47 import jdk.vm.ci.meta.Assumptions.Assumption;
  48 import jdk.vm.ci.meta.Assumptions.LeafType;
  49 import jdk.vm.ci.meta.Assumptions.NoFinalizableSubclass;
  50 import jdk.vm.ci.meta.ResolvedJavaMethod;
  51 
  52 public class FinalizableSubclassTest extends GraalCompilerTest {
  53 
  54     /**
  55      * used as template to generate class files at runtime.
  56      */
  57     public static class NoFinalizerEverAAAA {
  58     }
  59 
  60     public static class NoFinalizerYetAAAA {
  61     }


  63     public static final class WithFinalizerAAAA extends NoFinalizerYetAAAA {
  64 
  65         @SuppressWarnings("deprecation")
  66         @Override
  67         protected void finalize() throws Throwable {
  68             super.finalize();
  69         }
  70     }
  71 
  72     private StructuredGraph parseAndProcess(Class<?> cl, AllowAssumptions allowAssumptions) {
  73         Constructor<?>[] constructors = cl.getConstructors();
  74         Assert.assertTrue(constructors.length == 1);
  75         final ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(constructors[0]);
  76         OptionValues options = getInitialOptions();
  77         StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options, null, javaMethod), allowAssumptions).method(javaMethod).build();
  78 
  79         GraphBuilderConfiguration conf = GraphBuilderConfiguration.getSnippetDefault(getDefaultGraphBuilderPlugins());
  80         new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), getProviders().getConstantReflection(), getProviders().getConstantFieldProvider(), conf,
  81                         OptimisticOptimizations.ALL, null).apply(graph);
  82         HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
  83         createInliningPhase().apply(graph, context);
  84         new CanonicalizerPhase().apply(graph, context);
  85         return graph;
  86     }
  87 
  88     private void checkForRegisterFinalizeNode(Class<?> cl, boolean shouldContainFinalizer, AllowAssumptions allowAssumptions) {
  89         StructuredGraph graph = parseAndProcess(cl, allowAssumptions);
  90         Assert.assertTrue(graph.getNodes().filter(RegisterFinalizerNode.class).count() == (shouldContainFinalizer ? 1 : 0));
  91         int noFinalizerAssumption = 0;
  92         Assumptions assumptions = graph.getAssumptions();
  93         if (assumptions != null) {
  94             for (Assumption a : assumptions) {
  95                 if (a instanceof NoFinalizableSubclass) {
  96                     noFinalizerAssumption++;
  97                 } else if (a instanceof LeafType) {
  98                     // Need to also allow leaf type assumption instead of no finalizable subclass
  99                     // assumption.
 100                     noFinalizerAssumption++;
 101                 }
 102             }
 103         }


< prev index next >