< prev index next >

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/VirtualObject.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2019, 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  */


  26 import java.util.Collections;
  27 import java.util.IdentityHashMap;
  28 import java.util.Set;
  29 
  30 import jdk.vm.ci.meta.JavaKind;
  31 import jdk.vm.ci.meta.JavaValue;
  32 import jdk.vm.ci.meta.ResolvedJavaField;
  33 import jdk.vm.ci.meta.ResolvedJavaType;
  34 
  35 /**
  36  * An instance of this class represents an object whose allocation was removed by escape analysis.
  37  * The information stored in the {@link VirtualObject} is used during deoptimization to recreate the
  38  * object.
  39  */
  40 public final class VirtualObject implements JavaValue {
  41 
  42     private final ResolvedJavaType type;
  43     private JavaValue[] values;
  44     private JavaKind[] slotKinds;
  45     private final int id;
  46     private boolean isAutoBox;
  47 
  48     /**
  49      * Creates a new {@link VirtualObject} for the given type, with the given fields. If
  50      * {@code type} is an instance class then {@code values} provides the values for the fields
  51      * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If
  52      * {@code type} is an array then the length of the values array determines the reallocated array
  53      * length.
  54      *
  55      * @param type the type of the object whose allocation was removed during compilation. This can
  56      *            be either an instance of an array type.
  57      * @param id a unique id that identifies the object within the debug information for one
  58      *            position in the compiled code.
  59      * @return a new {@link VirtualObject} instance.
  60      */
  61     public static VirtualObject get(ResolvedJavaType type, int id) {
  62         return new VirtualObject(type, id, false);
  63     }
  64 
  65     /**
  66      * Creates a new {@link VirtualObject} for the given type, with the given fields. If
  67      * {@code type} is an instance class then {@code values} provides the values for the fields
  68      * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If
  69      * {@code type} is an array then the length of the values array determines the reallocated array
  70      * length.
  71      *
  72      * @param type the type of the object whose allocation was removed during compilation. This can
  73      *            be either an instance of an array type.
  74      * @param id a unique id that identifies the object within the debug information for one
  75      *            position in the compiled code.
  76      * @param isAutoBox a flag that tells the runtime that the object may be a boxed primitive and
  77      *            that it possibly needs to be obtained for the box cache instead of creating
  78      *            a new instance.
  79      * @return a new {@link VirtualObject} instance.
  80      */
  81     public static VirtualObject get(ResolvedJavaType type, int id, boolean isAutoBox) {
  82         return new VirtualObject(type, id, isAutoBox);
  83     }
  84 
  85     private VirtualObject(ResolvedJavaType type, int id, boolean isAutoBox) {
  86         this.type = type;
  87         this.id = id;
  88         this.isAutoBox = isAutoBox;
  89     }
  90 
  91     private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set<VirtualObject> visited) {
  92         if (value instanceof VirtualObject) {
  93             VirtualObject vo = (VirtualObject) value;
  94             buf.append("vobject:").append(vo.type.toJavaName(false)).append(':').append(vo.id);
  95             if (!visited.contains(vo)) {
  96                 visited.add(vo);
  97                 buf.append('{');
  98                 if (vo.values == null) {
  99                     buf.append("<uninitialized>");
 100                 } else {
 101                     if (vo.type.isArray()) {
 102                         for (int i = 0; i < vo.values.length; i++) {
 103                             if (i != 0) {
 104                                 buf.append(',');
 105                             }
 106                             buf.append(i).append('=');
 107                             appendValue(buf, vo.values[i], visited);
 108                         }


 146      * (e.g. during register allocation).
 147      */
 148     @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "`values` is intentional mutable")//
 149     public JavaValue[] getValues() {
 150         return values;
 151     }
 152 
 153     /**
 154      * Returns the kind of the value at {@code index}.
 155      */
 156     public JavaKind getSlotKind(int index) {
 157         return slotKinds[index];
 158     }
 159 
 160     /**
 161      * Returns the unique id that identifies the object within the debug information for one
 162      * position in the compiled code.
 163      */
 164     public int getId() {
 165         return id;
 166     }
 167 
 168     /**
 169      * Returns true if the object is a box. For boxes the deoptimization would check if the value of
 170      * the box is in the cache range and try to return a cached object.
 171      */
 172     public boolean isAutoBox() {
 173       return isAutoBox;
 174     }
 175 
 176     /**
 177      * Sets the value of the box flag.
 178      * @param isAutoBox a flag that tells the runtime that the object may be a boxed primitive and that
 179      *            it possibly needs to be obtained for the box cache instead of creating a new instance.
 180      */
 181     public void setIsAutoBox(boolean isAutoBox) {
 182       this.isAutoBox = isAutoBox;
 183     }
 184 
 185     /**
 186      * Overwrites the current set of values with a new one.
 187      *
 188      * @param values an array containing all the values to be stored into the object when it is
 189      *            recreated.
 190      * @param slotKinds an array containing the Java kinds of the values. This must have the same
 191      *            length as {@code values}. This array is now owned by this object and must not be
 192      *            mutated by the caller.
 193      */
 194     @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `slotKinds`")
 195     public void setValues(JavaValue[] values, JavaKind[] slotKinds) {
 196         assert values.length == slotKinds.length;
 197         this.values = values;
 198         this.slotKinds = slotKinds;
 199     }
 200 
 201     @Override
 202     public int hashCode() {


   1 /*
   2  * Copyright (c) 2010, 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  */


  26 import java.util.Collections;
  27 import java.util.IdentityHashMap;
  28 import java.util.Set;
  29 
  30 import jdk.vm.ci.meta.JavaKind;
  31 import jdk.vm.ci.meta.JavaValue;
  32 import jdk.vm.ci.meta.ResolvedJavaField;
  33 import jdk.vm.ci.meta.ResolvedJavaType;
  34 
  35 /**
  36  * An instance of this class represents an object whose allocation was removed by escape analysis.
  37  * The information stored in the {@link VirtualObject} is used during deoptimization to recreate the
  38  * object.
  39  */
  40 public final class VirtualObject implements JavaValue {
  41 
  42     private final ResolvedJavaType type;
  43     private JavaValue[] values;
  44     private JavaKind[] slotKinds;
  45     private final int id;

  46 
  47     /**
  48      * Creates a new {@link VirtualObject} for the given type, with the given fields. If
  49      * {@code type} is an instance class then {@code values} provides the values for the fields
  50      * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If
  51      * {@code type} is an array then the length of the values array determines the reallocated array
  52      * length.
  53      *
  54      * @param type the type of the object whose allocation was removed during compilation. This can
  55      *            be either an instance of an array type.
  56      * @param id a unique id that identifies the object within the debug information for one
  57      *            position in the compiled code.
  58      * @return a new {@link VirtualObject} instance.
  59      */
  60     public static VirtualObject get(ResolvedJavaType type, int id) {
  61         return new VirtualObject(type, id);
  62     }
  63 
  64     private VirtualObject(ResolvedJavaType type, int id) {




















  65         this.type = type;
  66         this.id = id;

  67     }
  68 
  69     private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set<VirtualObject> visited) {
  70         if (value instanceof VirtualObject) {
  71             VirtualObject vo = (VirtualObject) value;
  72             buf.append("vobject:").append(vo.type.toJavaName(false)).append(':').append(vo.id);
  73             if (!visited.contains(vo)) {
  74                 visited.add(vo);
  75                 buf.append('{');
  76                 if (vo.values == null) {
  77                     buf.append("<uninitialized>");
  78                 } else {
  79                     if (vo.type.isArray()) {
  80                         for (int i = 0; i < vo.values.length; i++) {
  81                             if (i != 0) {
  82                                 buf.append(',');
  83                             }
  84                             buf.append(i).append('=');
  85                             appendValue(buf, vo.values[i], visited);
  86                         }


 124      * (e.g. during register allocation).
 125      */
 126     @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "`values` is intentional mutable")//
 127     public JavaValue[] getValues() {
 128         return values;
 129     }
 130 
 131     /**
 132      * Returns the kind of the value at {@code index}.
 133      */
 134     public JavaKind getSlotKind(int index) {
 135         return slotKinds[index];
 136     }
 137 
 138     /**
 139      * Returns the unique id that identifies the object within the debug information for one
 140      * position in the compiled code.
 141      */
 142     public int getId() {
 143         return id;

















 144     }
 145 
 146     /**
 147      * Overwrites the current set of values with a new one.
 148      *
 149      * @param values an array containing all the values to be stored into the object when it is
 150      *            recreated.
 151      * @param slotKinds an array containing the Java kinds of the values. This must have the same
 152      *            length as {@code values}. This array is now owned by this object and must not be
 153      *            mutated by the caller.
 154      */
 155     @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `slotKinds`")
 156     public void setValues(JavaValue[] values, JavaKind[] slotKinds) {
 157         assert values.length == slotKinds.length;
 158         this.values = values;
 159         this.slotKinds = slotKinds;
 160     }
 161 
 162     @Override
 163     public int hashCode() {


< prev index next >