1 /* |
1 /* |
2 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
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. |
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. |
41 |
41 |
42 private final ResolvedJavaType type; |
42 private final ResolvedJavaType type; |
43 private JavaValue[] values; |
43 private JavaValue[] values; |
44 private JavaKind[] slotKinds; |
44 private JavaKind[] slotKinds; |
45 private final int id; |
45 private final int id; |
|
46 private boolean isAutoBox; |
46 |
47 |
47 /** |
48 /** |
48 * Creates a new {@link VirtualObject} for the given type, with the given fields. If |
49 * 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 * {@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 * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If |
56 * @param id a unique id that identifies the object within the debug information for one |
57 * @param id a unique id that identifies the object within the debug information for one |
57 * position in the compiled code. |
58 * position in the compiled code. |
58 * @return a new {@link VirtualObject} instance. |
59 * @return a new {@link VirtualObject} instance. |
59 */ |
60 */ |
60 public static VirtualObject get(ResolvedJavaType type, int id) { |
61 public static VirtualObject get(ResolvedJavaType type, int id) { |
61 return new VirtualObject(type, id); |
62 return new VirtualObject(type, id, false); |
62 } |
63 } |
63 |
64 |
64 private VirtualObject(ResolvedJavaType type, int id) { |
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) { |
65 this.type = type; |
86 this.type = type; |
66 this.id = id; |
87 this.id = id; |
|
88 this.isAutoBox = isAutoBox; |
67 } |
89 } |
68 |
90 |
69 private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set<VirtualObject> visited) { |
91 private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set<VirtualObject> visited) { |
70 if (value instanceof VirtualObject) { |
92 if (value instanceof VirtualObject) { |
71 VirtualObject vo = (VirtualObject) value; |
93 VirtualObject vo = (VirtualObject) value; |
142 public int getId() { |
164 public int getId() { |
143 return id; |
165 return id; |
144 } |
166 } |
145 |
167 |
146 /** |
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 /** |
147 * Overwrites the current set of values with a new one. |
186 * Overwrites the current set of values with a new one. |
148 * |
187 * |
149 * @param values an array containing all the values to be stored into the object when it is |
188 * @param values an array containing all the values to be stored into the object when it is |
150 * recreated. |
189 * recreated. |
151 * @param slotKinds an array containing the Java kinds of the values. This must have the same |
190 * @param slotKinds an array containing the Java kinds of the values. This must have the same |