src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPoolObject.java
changeset 54669 ad45b3802d4e
parent 52381 7f90bc64b0fc
equal deleted inserted replaced
54668:0bda2308eded 54669:ad45b3802d4e
     1 /*
     1 /*
     2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 package jdk.vm.ci.hotspot;
    23 package jdk.vm.ci.hotspot;
    24 
    24 
    25 import jdk.vm.ci.meta.JavaConstant;
    25 import jdk.vm.ci.meta.JavaConstant;
       
    26 import jdk.vm.ci.meta.JavaKind;
    26 
    27 
    27 /**
    28 /**
    28  * Represents a constant that was retrieved from a constant pool. Used to keep track of the constant
    29  * Represents a constant that was retrieved from a constant pool. Used to keep track of the constant
    29  * pool slot for the constant.
    30  * pool slot for the constant.
    30  */
    31  */
    31 public final class HotSpotConstantPoolObject extends HotSpotObjectConstantImpl {
    32 public final class HotSpotConstantPoolObject implements JavaConstant {
    32 
    33 
    33     static JavaConstant forObject(HotSpotResolvedObjectType type, int cpi, Object object) {
    34     public static JavaConstant forObject(HotSpotResolvedObjectType type, int cpi, JavaConstant object) {
    34         return new HotSpotConstantPoolObject(type, cpi, object);
    35         return new HotSpotConstantPoolObject(type, cpi, object);
    35     }
    36     }
    36 
    37 
    37     public static JavaConstant forObject(HotSpotResolvedObjectType type, int cpi, JavaConstant object) {
    38     private final JavaConstant constant;
    38         return forObject(type, cpi, ((HotSpotObjectConstantImpl) object).object());
       
    39     }
       
    40 
       
    41     private final HotSpotResolvedObjectType type;
    39     private final HotSpotResolvedObjectType type;
    42     private final int cpi;
    40     private final int cpi;
    43 
    41 
    44     public HotSpotResolvedObjectType getCpType() {
    42     public HotSpotResolvedObjectType getCpType() {
    45         return type;
    43         return type;
    47 
    45 
    48     public int getCpi() {
    46     public int getCpi() {
    49         return cpi;
    47         return cpi;
    50     }
    48     }
    51 
    49 
    52     HotSpotConstantPoolObject(HotSpotResolvedObjectType type, int cpi, Object object) {
    50     HotSpotConstantPoolObject(HotSpotResolvedObjectType type, int cpi, JavaConstant constant) {
    53         super(object, false);
       
    54         this.type = type;
    51         this.type = type;
    55         this.cpi = cpi;
    52         this.cpi = cpi;
       
    53         this.constant = constant;
    56     }
    54     }
    57 
    55 
    58     @Override
    56     @Override
    59     public boolean equals(Object o) {
    57     public boolean equals(Object o) {
    60         if (o instanceof HotSpotConstantPoolObject) {
    58         if (o instanceof HotSpotConstantPoolObject) {
    61             if (super.equals(o)) {
    59             HotSpotConstantPoolObject other = (HotSpotConstantPoolObject) o;
    62                 HotSpotConstantPoolObject other = (HotSpotConstantPoolObject) o;
    60             return type.equals(other.type) && cpi == other.cpi && constant.equals(other.constant);
    63                 return type.equals(other.type) && cpi == other.cpi;
       
    64             }
       
    65         }
    61         }
    66         return false;
    62         return false;
       
    63     }
       
    64 
       
    65     @Override
       
    66     public int hashCode() {
       
    67         return constant.hashCode() + cpi + type.hashCode();
       
    68     }
       
    69 
       
    70     @Override
       
    71     public JavaKind getJavaKind() {
       
    72         return constant.getJavaKind();
       
    73     }
       
    74 
       
    75     @Override
       
    76     public boolean isNull() {
       
    77         return constant.isNull();
       
    78     }
       
    79 
       
    80     @Override
       
    81     public boolean isDefaultForKind() {
       
    82         return constant.isDefaultForKind();
       
    83     }
       
    84 
       
    85     @Override
       
    86     public Object asBoxedPrimitive() {
       
    87         return constant.asBoxedPrimitive();
       
    88     }
       
    89 
       
    90     @Override
       
    91     public int asInt() {
       
    92         return constant.asInt();
       
    93     }
       
    94 
       
    95     @Override
       
    96     public boolean asBoolean() {
       
    97         return constant.asBoolean();
       
    98     }
       
    99 
       
   100     @Override
       
   101     public long asLong() {
       
   102         return constant.asLong();
       
   103     }
       
   104 
       
   105     @Override
       
   106     public float asFloat() {
       
   107         return constant.asFloat();
       
   108     }
       
   109 
       
   110     @Override
       
   111     public double asDouble() {
       
   112         return 0;
    67     }
   113     }
    68 
   114 
    69     @Override
   115     @Override
    70     public String toValueString() {
   116     public String toValueString() {
    71         return getCpType().getName() + getCpi();
   117         return getCpType().getName() + getCpi();