1 /* |
1 /* |
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 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. |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 package jdk.vm.ci.hotspot; |
23 package jdk.vm.ci.hotspot; |
24 |
24 |
25 import static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass; |
|
26 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; |
|
27 |
|
28 import java.lang.reflect.Array; |
|
29 import java.lang.reflect.Executable; |
25 import java.lang.reflect.Executable; |
30 import java.lang.reflect.Field; |
26 import java.lang.reflect.Field; |
31 import java.lang.reflect.Modifier; |
27 import java.lang.reflect.Modifier; |
32 import java.util.Objects; |
28 import java.util.Objects; |
33 |
29 |
41 import jdk.vm.ci.meta.ResolvedJavaField; |
37 import jdk.vm.ci.meta.ResolvedJavaField; |
42 import jdk.vm.ci.meta.ResolvedJavaMethod; |
38 import jdk.vm.ci.meta.ResolvedJavaMethod; |
43 import jdk.vm.ci.meta.ResolvedJavaType; |
39 import jdk.vm.ci.meta.ResolvedJavaType; |
44 import jdk.vm.ci.meta.Signature; |
40 import jdk.vm.ci.meta.Signature; |
45 import jdk.vm.ci.meta.SpeculationLog; |
41 import jdk.vm.ci.meta.SpeculationLog; |
|
42 import jdk.vm.ci.meta.SpeculationLog.NoSpeculationReason; |
|
43 import jdk.vm.ci.meta.SpeculationLog.Speculation; |
46 |
44 |
47 // JaCoCo Exclude |
45 // JaCoCo Exclude |
48 |
46 |
49 /** |
47 /** |
50 * HotSpot implementation of {@link MetaAccessProvider}. |
48 * HotSpot implementation of {@link MetaAccessProvider}. |
85 |
83 |
86 @Override |
84 @Override |
87 public ResolvedJavaField lookupJavaField(Field reflectionField) { |
85 public ResolvedJavaField lookupJavaField(Field reflectionField) { |
88 Class<?> fieldHolder = reflectionField.getDeclaringClass(); |
86 Class<?> fieldHolder = reflectionField.getDeclaringClass(); |
89 |
87 |
90 HotSpotResolvedObjectType holder = fromObjectClass(fieldHolder); |
88 HotSpotResolvedJavaType holder = runtime.fromClass(fieldHolder); |
|
89 assert holder != null : fieldHolder; |
|
90 ResolvedJavaField[] fields; |
91 if (Modifier.isStatic(reflectionField.getModifiers())) { |
91 if (Modifier.isStatic(reflectionField.getModifiers())) { |
92 final long offset = UNSAFE.staticFieldOffset(reflectionField); |
92 fields = holder.getStaticFields(); |
93 for (ResolvedJavaField field : holder.getStaticFields()) { |
|
94 if (offset == ((HotSpotResolvedJavaField) field).getOffset()) { |
|
95 return field; |
|
96 } |
|
97 } |
|
98 } else { |
93 } else { |
99 final long offset = UNSAFE.objectFieldOffset(reflectionField); |
94 fields = holder.getInstanceFields(false); |
100 for (ResolvedJavaField field : holder.getInstanceFields(false)) { |
95 } |
101 if (offset == ((HotSpotResolvedJavaField) field).getOffset()) { |
96 ResolvedJavaType fieldType = lookupJavaType(reflectionField.getType()); |
102 return field; |
97 for (ResolvedJavaField field : fields) { |
103 } |
98 if (reflectionField.getName().equals(field.getName()) && field.getType().equals(fieldType)) { |
|
99 assert Modifier.isStatic(reflectionField.getModifiers()) == field.isStatic(); |
|
100 return field; |
104 } |
101 } |
105 } |
102 } |
106 |
103 |
107 throw new JVMCIError("unresolved field %s", reflectionField); |
104 throw new JVMCIError("unresolved field %s", reflectionField); |
108 } |
105 } |
145 HotSpotVMConfig config = runtime.getConfig(); |
142 HotSpotVMConfig config = runtime.getConfig(); |
146 return ((~constant.asInt()) >> config.deoptimizationDebugIdShift) & intMaskRight(config.deoptimizationDebugIdBits); |
143 return ((~constant.asInt()) >> config.deoptimizationDebugIdShift) & intMaskRight(config.deoptimizationDebugIdBits); |
147 } |
144 } |
148 |
145 |
149 @Override |
146 @Override |
150 public JavaConstant encodeSpeculation(SpeculationLog.Speculation speculation) { |
147 public JavaConstant encodeSpeculation(Speculation speculation) { |
151 if (speculation.getReason() instanceof SpeculationLog.NoSpeculationReason) { |
148 if (speculation.getReason() instanceof NoSpeculationReason) { |
152 return JavaConstant.LONG_0; |
149 return JavaConstant.LONG_0; |
153 } |
150 } |
154 return ((HotSpotSpeculationLog.HotSpotSpeculation) speculation).getEncoding(); |
151 return ((HotSpotSpeculationLog.HotSpotSpeculation) speculation).getEncoding(); |
155 } |
152 } |
156 |
153 |
157 @Override |
154 @Override |
158 public SpeculationLog.Speculation decodeSpeculation(JavaConstant constant, SpeculationLog speculationLog) { |
155 public Speculation decodeSpeculation(JavaConstant constant, SpeculationLog speculationLog) { |
159 if (constant.equals(JavaConstant.LONG_0)) { |
156 if (constant.equals(JavaConstant.LONG_0)) { |
160 return SpeculationLog.NO_SPECULATION; |
157 return SpeculationLog.NO_SPECULATION; |
161 } |
158 } |
162 assert speculationLog != null : "Must have a speculation log"; |
159 if (speculationLog == null) { |
|
160 throw new IllegalArgumentException("A speculation log is required to decode the speculation denoted by " + constant); |
|
161 } |
163 return speculationLog.lookupSpeculation(constant); |
162 return speculationLog.lookupSpeculation(constant); |
164 } |
163 } |
165 |
164 |
166 public int convertDeoptAction(DeoptimizationAction action) { |
165 public int convertDeoptAction(DeoptimizationAction action) { |
167 HotSpotVMConfig config = runtime.getConfig(); |
166 HotSpotVMConfig config = runtime.getConfig(); |
301 |
300 |
302 if (lookupJavaType == null) { |
301 if (lookupJavaType == null) { |
303 return 0; |
302 return 0; |
304 } else { |
303 } else { |
305 if (lookupJavaType.isArray()) { |
304 if (lookupJavaType.isArray()) { |
306 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object()); |
305 int length = runtime.getHostJVMCIBackend().getConstantReflection().readArrayLength(constant); |
307 ResolvedJavaType elementType = lookupJavaType.getComponentType(); |
306 ResolvedJavaType elementType = lookupJavaType.getComponentType(); |
308 JavaKind elementKind = elementType.getJavaKind(); |
307 JavaKind elementKind = elementType.getJavaKind(); |
309 final int headerSize = getArrayBaseOffset(elementKind); |
308 final int headerSize = runtime.getArrayBaseOffset(elementKind); |
310 int sizeOfElement = getArrayIndexScale(elementKind); |
309 int sizeOfElement = runtime.getArrayIndexScale(elementKind); |
311 int log2ElementSize = CodeUtil.log2(sizeOfElement); |
310 int log2ElementSize = CodeUtil.log2(sizeOfElement); |
312 return computeArrayAllocationSize(length, headerSize, log2ElementSize); |
311 return computeArrayAllocationSize(length, headerSize, log2ElementSize); |
313 } |
312 } |
314 return lookupJavaType.instanceSize(); |
313 return lookupJavaType.instanceSize(); |
315 } |
314 } |