1 /*
   2  * Copyright (c) 2009, 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.internal.jvmci.code;
  24 
  25 import jdk.internal.jvmci.meta.*;
  26 import static jdk.internal.jvmci.meta.MetaUtil.*;
  27 
  28 /**
  29  * Represents the target machine for a compiler, including the CPU architecture, the size of
  30  * pointers and references, alignment of stacks, caches, etc.
  31  */
  32 public class TargetDescription {
  33 
  34     public final Architecture arch;
  35 
  36     /**
  37      * Specifies if this is a multi-processor system.
  38      */
  39     public final boolean isMP;
  40 
  41     /**
  42      * Specifies if this target supports encoding objects inline in the machine code.
  43      */
  44     public final boolean inlineObjects;
  45 
  46     /**
  47      * The machine word size on this target.
  48      */
  49     public final int wordSize;
  50 
  51     /**
  52      * The kind to be used for representing raw pointers and CPU registers.
  53      */
  54     public final JavaKind wordKind;
  55 
  56     /**
  57      * The stack alignment requirement of the platform. For example, from Appendix D of <a
  58      * href="http://www.intel.com/Assets/PDF/manual/248966.pdf">Intel 64 and IA-32 Architectures
  59      * Optimization Reference Manual</a>:
  60      *
  61      * <pre>
  62      *     "It is important to ensure that the stack frame is aligned to a
  63      *      16-byte boundary upon function entry to keep local __m128 data,
  64      *      parameters, and XMM register spill locations aligned throughout
  65      *      a function invocation."
  66      * </pre>
  67      */
  68     public final int stackAlignment;
  69 
  70     /**
  71      * Maximum constant displacement at which a memory access can no longer be an implicit null
  72      * check.
  73      */
  74     public final int implicitNullCheckLimit;
  75 
  76     public TargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) {
  77         this.arch = arch;
  78         this.isMP = isMP;
  79         this.wordSize = arch.getWordSize();
  80         this.wordKind = JavaKind.fromWordSize(wordSize);
  81         this.stackAlignment = stackAlignment;
  82         this.implicitNullCheckLimit = implicitNullCheckLimit;
  83         this.inlineObjects = inlineObjects;
  84     }
  85 
  86     @Override
  87     public final int hashCode() {
  88         throw new UnsupportedOperationException();
  89     }
  90 
  91     @Override
  92     public final boolean equals(Object obj) {
  93         if (this == obj) {
  94             return true;
  95         }
  96         if (obj instanceof TargetDescription) {
  97             TargetDescription that = (TargetDescription) obj;
  98             // @formatter:off
  99             if (this.implicitNullCheckLimit == that.implicitNullCheckLimit &&
 100                 this.inlineObjects == that.inlineObjects &&
 101                 this.isMP == that.isMP &&
 102                 this.stackAlignment == that.stackAlignment &&
 103                 this.wordKind.equals(that.wordKind) &&
 104                 this.wordSize == that.wordSize &&
 105                 this.arch.equals(that.arch)) {
 106                 return true;
 107             }
 108             // @formatter:on
 109         }
 110         return false;
 111     }
 112 
 113     @Override
 114     public String toString() {
 115         return identityHashCodeString(this);
 116     }
 117 
 118     public int getSizeInBytes(PlatformKind kind) {
 119         return kind.getSizeInBytes();
 120     }
 121 
 122     public LIRKind getLIRKind(JavaKind javaKind) {
 123         PlatformKind platformKind = arch.getPlatformKind(javaKind);
 124         if (javaKind.isObject()) {
 125             return LIRKind.reference(platformKind);
 126         } else {
 127             return LIRKind.value(platformKind);
 128         }
 129     }
 130 }