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.vm.ci.hotspot;
24
25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset;
26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayIndexScale;
27
28 import java.lang.reflect.Array;
29
30 import jdk.vm.ci.common.JVMCIError;
31 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
32 import jdk.vm.ci.meta.Constant;
33 import jdk.vm.ci.meta.ConstantReflectionProvider;
34 import jdk.vm.ci.meta.JavaConstant;
35 import jdk.vm.ci.meta.JavaKind;
36 import jdk.vm.ci.meta.JavaType;
37 import jdk.vm.ci.meta.MemoryAccessProvider;
38 import jdk.vm.ci.meta.MethodHandleAccessProvider;
39 import jdk.vm.ci.meta.ResolvedJavaField;
40 import jdk.vm.ci.meta.ResolvedJavaType;
41
42 /**
43 * HotSpot implementation of {@link ConstantReflectionProvider}.
44 */
45 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified {
46
47 protected final HotSpotJVMCIRuntimeProvider runtime;
48 protected final HotSpotMethodHandleAccessProvider methodHandleAccess;
53 this.methodHandleAccess = new HotSpotMethodHandleAccessProvider(this);
54 this.memoryAccess = new HotSpotMemoryAccessProviderImpl(runtime);
55 }
56
57 public MethodHandleAccessProvider getMethodHandleAccess() {
58 return methodHandleAccess;
59 }
60
61 @Override
62 public MemoryAccessProvider getMemoryAccessProvider() {
63 return memoryAccess;
64 }
65
66 @Override
67 public Boolean constantEquals(Constant x, Constant y) {
68 if (x == y) {
69 return true;
70 } else if (x instanceof HotSpotObjectConstantImpl) {
71 return y instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) x).object() == ((HotSpotObjectConstantImpl) y).object();
72 } else {
73 return x.equals(y);
74 }
75 }
76
77 @Override
78 public Integer readArrayLength(JavaConstant array) {
79 if (array.getJavaKind() != JavaKind.Object || array.isNull()) {
80 return null;
81 }
82
83 Object arrayObject = ((HotSpotObjectConstantImpl) array).object();
84 if (!arrayObject.getClass().isArray()) {
85 return null;
86 }
87 return Array.getLength(arrayObject);
88 }
89
90 public JavaConstant readConstantArrayElement(JavaConstant array, int index) {
91 if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) {
92 JavaConstant element = readArrayElement(array, index);
93 if (element != null && (((HotSpotObjectConstantImpl) array).isDefaultStable() || !element.isDefaultForKind())) {
|
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.vm.ci.hotspot;
24
25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset;
26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayIndexScale;
27
28 import java.lang.reflect.Array;
29 import java.util.Objects;
30
31 import jdk.vm.ci.common.JVMCIError;
32 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
33 import jdk.vm.ci.meta.Constant;
34 import jdk.vm.ci.meta.ConstantReflectionProvider;
35 import jdk.vm.ci.meta.JavaConstant;
36 import jdk.vm.ci.meta.JavaKind;
37 import jdk.vm.ci.meta.JavaType;
38 import jdk.vm.ci.meta.MemoryAccessProvider;
39 import jdk.vm.ci.meta.MethodHandleAccessProvider;
40 import jdk.vm.ci.meta.ResolvedJavaField;
41 import jdk.vm.ci.meta.ResolvedJavaType;
42
43 /**
44 * HotSpot implementation of {@link ConstantReflectionProvider}.
45 */
46 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified {
47
48 protected final HotSpotJVMCIRuntimeProvider runtime;
49 protected final HotSpotMethodHandleAccessProvider methodHandleAccess;
54 this.methodHandleAccess = new HotSpotMethodHandleAccessProvider(this);
55 this.memoryAccess = new HotSpotMemoryAccessProviderImpl(runtime);
56 }
57
58 public MethodHandleAccessProvider getMethodHandleAccess() {
59 return methodHandleAccess;
60 }
61
62 @Override
63 public MemoryAccessProvider getMemoryAccessProvider() {
64 return memoryAccess;
65 }
66
67 @Override
68 public Boolean constantEquals(Constant x, Constant y) {
69 if (x == y) {
70 return true;
71 } else if (x instanceof HotSpotObjectConstantImpl) {
72 return y instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) x).object() == ((HotSpotObjectConstantImpl) y).object();
73 } else {
74 return Objects.equals(x,y);
75 }
76 }
77
78 @Override
79 public Integer readArrayLength(JavaConstant array) {
80 if (array.getJavaKind() != JavaKind.Object || array.isNull()) {
81 return null;
82 }
83
84 Object arrayObject = ((HotSpotObjectConstantImpl) array).object();
85 if (!arrayObject.getClass().isArray()) {
86 return null;
87 }
88 return Array.getLength(arrayObject);
89 }
90
91 public JavaConstant readConstantArrayElement(JavaConstant array, int index) {
92 if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) {
93 JavaConstant element = readArrayElement(array, index);
94 if (element != null && (((HotSpotObjectConstantImpl) array).isDefaultStable() || !element.isDefaultForKind())) {
|