1 /*
   2  * Copyright (c) 2013, 2015, 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 package jdk.vm.ci.meta;
  24 
  25 /**
  26  * Represents a platform-specific low-level type for values.
  27  */
  28 public interface PlatformKind {
  29 
  30     String name();
  31 
  32     JavaConstant getDefaultValue();
  33 
  34     public interface Key {
  35 
  36     }
  37 
  38     public class EnumKey<E extends Enum<E>> implements Key {
  39         private final Enum<E> e;
  40 
  41         public EnumKey(Enum<E> e) {
  42             this.e = e;
  43         }
  44 
  45         @Override
  46         public int hashCode() {
  47             return e.ordinal() ^ e.name().hashCode();
  48         }
  49 
  50         @Override
  51         public boolean equals(Object obj) {
  52             if (obj == this) {
  53                 return true;
  54             }
  55             if (obj instanceof EnumKey) {
  56                 EnumKey<?> that = (EnumKey<?>) obj;
  57                 return this.e == that.e;
  58             }
  59             return false;
  60         }
  61     }
  62 
  63     /**
  64      * Gets a value associated with this object that can be used as a stable key in a map. The
  65      * {@link Object#hashCode()} implementation of the returned value should be stable between VM
  66      * executions.
  67      */
  68     Key getKey();
  69 
  70     /**
  71      * Get the size in bytes of this {@link PlatformKind}.
  72      */
  73     int getSizeInBytes();
  74 
  75     /**
  76      * Returns how many primitive values fit in this {@link PlatformKind}. For scalar types this is
  77      * one, for SIMD types it may be higher.
  78      */
  79     int getVectorLength();
  80 
  81     /**
  82      * Gets a single type char that identifies this type for use in debug output.
  83      */
  84     char getTypeChar();
  85 }