< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.word/src/org/graalvm/compiler/word/WordTypes.java

Print this page
rev 52509 : [mq]: graal


   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.word;
  26 


  27 import org.graalvm.compiler.core.common.type.Stamp;
  28 import org.graalvm.compiler.core.common.type.StampFactory;
  29 import org.graalvm.compiler.nodes.ValueNode;
  30 import org.graalvm.compiler.nodes.type.StampTool;
  31 import org.graalvm.compiler.word.Word.Operation;
  32 import jdk.internal.vm.compiler.word.WordBase;
  33 import jdk.internal.vm.compiler.word.WordFactory;
  34 
  35 import jdk.vm.ci.meta.JavaKind;
  36 import jdk.vm.ci.meta.JavaType;
  37 import jdk.vm.ci.meta.MetaAccessProvider;
  38 import jdk.vm.ci.meta.ResolvedJavaMethod;
  39 import jdk.vm.ci.meta.ResolvedJavaType;
  40 
  41 /**
  42  * Encapsulates information for Java types representing raw words (as opposed to Objects).
  43  */
  44 public class WordTypes {
  45 
  46     /**


  61     /**
  62      * Resolved type for {@link ObjectAccess}.
  63      */
  64     private final ResolvedJavaType objectAccessType;
  65 
  66     /**
  67      * Resolved type for {@link BarrieredAccess}.
  68      */
  69     private final ResolvedJavaType barrieredAccessType;
  70 
  71     private final JavaKind wordKind;
  72 
  73     public WordTypes(MetaAccessProvider metaAccess, JavaKind wordKind) {
  74         this.wordKind = wordKind;
  75         this.wordBaseType = metaAccess.lookupJavaType(WordBase.class);
  76         this.wordImplType = metaAccess.lookupJavaType(Word.class);
  77         this.wordFactoryType = metaAccess.lookupJavaType(WordFactory.class);
  78         this.objectAccessType = metaAccess.lookupJavaType(ObjectAccess.class);
  79         this.barrieredAccessType = metaAccess.lookupJavaType(BarrieredAccess.class);
  80 

  81         Word.ensureInitialized();

  82         this.wordImplType.initialize();
  83     }
  84 
  85     /**
  86      * Determines if a given method denotes a word operation.
  87      */
  88     public boolean isWordOperation(ResolvedJavaMethod targetMethod) {
  89         final boolean isWordFactory = wordFactoryType.equals(targetMethod.getDeclaringClass());
  90         if (isWordFactory) {
  91             return true;
  92         }
  93         final boolean isObjectAccess = objectAccessType.equals(targetMethod.getDeclaringClass());
  94         final boolean isBarrieredAccess = barrieredAccessType.equals(targetMethod.getDeclaringClass());
  95         if (isObjectAccess || isBarrieredAccess) {
  96             assert targetMethod.getAnnotation(Operation.class) != null : targetMethod + " should be annotated with @" + Operation.class.getSimpleName();
  97             return true;
  98         }
  99         return isWord(targetMethod.getDeclaringClass());
 100     }
 101 
 102     /**
 103      * Gets the method annotated with {@link Operation} based on a given method that represents a
 104      * word operation (but may not necessarily have the annotation).
 105      *
 106      * @param callingContextType the {@linkplain ResolvedJavaType type} from which
 107      *            {@code targetMethod} is invoked
 108      * @return the {@link Operation} method resolved for {@code targetMethod} if any
 109      */
 110     public ResolvedJavaMethod getWordOperation(ResolvedJavaMethod targetMethod, ResolvedJavaType callingContextType) {
 111         final boolean isWordBase = wordBaseType.isAssignableFrom(targetMethod.getDeclaringClass());




   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.word;
  26 
  27 import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE;
  28 
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.core.common.type.StampFactory;
  31 import org.graalvm.compiler.nodes.ValueNode;
  32 import org.graalvm.compiler.nodes.type.StampTool;
  33 import org.graalvm.compiler.word.Word.Operation;
  34 import jdk.internal.vm.compiler.word.WordBase;
  35 import jdk.internal.vm.compiler.word.WordFactory;
  36 
  37 import jdk.vm.ci.meta.JavaKind;
  38 import jdk.vm.ci.meta.JavaType;
  39 import jdk.vm.ci.meta.MetaAccessProvider;
  40 import jdk.vm.ci.meta.ResolvedJavaMethod;
  41 import jdk.vm.ci.meta.ResolvedJavaType;
  42 
  43 /**
  44  * Encapsulates information for Java types representing raw words (as opposed to Objects).
  45  */
  46 public class WordTypes {
  47 
  48     /**


  63     /**
  64      * Resolved type for {@link ObjectAccess}.
  65      */
  66     private final ResolvedJavaType objectAccessType;
  67 
  68     /**
  69      * Resolved type for {@link BarrieredAccess}.
  70      */
  71     private final ResolvedJavaType barrieredAccessType;
  72 
  73     private final JavaKind wordKind;
  74 
  75     public WordTypes(MetaAccessProvider metaAccess, JavaKind wordKind) {
  76         this.wordKind = wordKind;
  77         this.wordBaseType = metaAccess.lookupJavaType(WordBase.class);
  78         this.wordImplType = metaAccess.lookupJavaType(Word.class);
  79         this.wordFactoryType = metaAccess.lookupJavaType(WordFactory.class);
  80         this.objectAccessType = metaAccess.lookupJavaType(ObjectAccess.class);
  81         this.barrieredAccessType = metaAccess.lookupJavaType(BarrieredAccess.class);
  82 
  83         if (!IS_BUILDING_NATIVE_IMAGE) {
  84             Word.ensureInitialized();
  85         }
  86         this.wordImplType.initialize();
  87     }
  88 
  89     /**
  90      * Determines if a given method denotes a word operation.
  91      */
  92     public boolean isWordOperation(ResolvedJavaMethod targetMethod) {
  93         final boolean isWordFactory = wordFactoryType.equals(targetMethod.getDeclaringClass());
  94         if (isWordFactory) {
  95             return !targetMethod.isConstructor();
  96         }
  97         final boolean isObjectAccess = objectAccessType.equals(targetMethod.getDeclaringClass());
  98         final boolean isBarrieredAccess = barrieredAccessType.equals(targetMethod.getDeclaringClass());
  99         if (isObjectAccess || isBarrieredAccess) {
 100             assert targetMethod.getAnnotation(Operation.class) != null : targetMethod + " should be annotated with @" + Operation.class.getSimpleName();
 101             return true;
 102         }
 103         return isWord(targetMethod.getDeclaringClass());
 104     }
 105 
 106     /**
 107      * Gets the method annotated with {@link Operation} based on a given method that represents a
 108      * word operation (but may not necessarily have the annotation).
 109      *
 110      * @param callingContextType the {@linkplain ResolvedJavaType type} from which
 111      *            {@code targetMethod} is invoked
 112      * @return the {@link Operation} method resolved for {@code targetMethod} if any
 113      */
 114     public ResolvedJavaMethod getWordOperation(ResolvedJavaMethod targetMethod, ResolvedJavaType callingContextType) {
 115         final boolean isWordBase = wordBaseType.isAssignableFrom(targetMethod.getDeclaringClass());


< prev index next >