< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/CompressEncoding.java

Print this page




  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.common;
  24 
  25 /**
  26  * A compact representation of the different encoding strategies for Objects and metadata.
  27  */
  28 public final class CompressEncoding {
  29     private final long base;
  30     private final int shift;
  31 
  32     public CompressEncoding(long base, int shift) {
  33         this.base = base;
  34         this.shift = shift;
  35     }
  36 
  37     public int compress(long ptr) {
  38         if (ptr == 0L) {
  39             return 0;
  40         } else {
  41             return (int) ((ptr - base) >>> shift);
  42         }
  43     }
  44 
  45     public boolean hasBase() {
  46         return base != 0;
  47     }
  48 
  49     public boolean hasShift() {
  50         return shift != 0;
  51     }
  52 
  53     public long getBase() {
  54         return base;
  55     }
  56 
  57     public int getShift() {
  58         return shift;
  59     }
  60 
  61     public long uncompress(int ptr) {
  62         if (ptr == 0) {
  63             return 0L;
  64         } else {
  65             return ((ptr & 0xFFFFFFFFL) << shift) + base;
  66         }
  67     }
  68 
  69     @Override
  70     public String toString() {
  71         return "base: " + base + " shift: " + shift;
  72     }
  73 
  74     @Override
  75     public int hashCode() {
  76         final int prime = 31;
  77         int result = 1;
  78         result = prime * result + (int) (base ^ (base >>> 32));
  79         result = prime * result + shift;
  80         return result;
  81     }
  82 
  83     @Override
  84     public boolean equals(Object obj) {
  85         if (obj instanceof CompressEncoding) {
  86             CompressEncoding other = (CompressEncoding) obj;
  87             return base == other.base && shift == other.shift;
  88         } else {
  89             return false;
  90         }

  91     }
  92 }


  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.common;
  24 
  25 /**
  26  * A compact representation of the different encoding strategies for Objects and metadata.
  27  */
  28 public final class CompressEncoding {
  29     private final long base;
  30     private final int shift;
  31 
  32     public CompressEncoding(long base, int shift) {
  33         this.base = base;
  34         this.shift = shift;
  35     }
  36 








  37     public boolean hasBase() {
  38         return base != 0;
  39     }
  40 
  41     public boolean hasShift() {
  42         return shift != 0;
  43     }
  44 
  45     public long getBase() {
  46         return base;
  47     }
  48 
  49     public int getShift() {
  50         return shift;
  51     }
  52 








  53     @Override
  54     public String toString() {
  55         return "base: " + base + " shift: " + shift;
  56     }
  57 
  58     @Override
  59     public int hashCode() {
  60         final int prime = 31;
  61         int result = 1;
  62         result = prime * result + (int) (base ^ (base >>> 32));
  63         result = prime * result + shift;
  64         return result;
  65     }
  66 
  67     @Override
  68     public boolean equals(Object obj) {
  69         if (obj instanceof CompressEncoding) {
  70             CompressEncoding other = (CompressEncoding) obj;
  71             return base == other.base && shift == other.shift;


  72         }
  73         return false;
  74     }
  75 }
< prev index next >