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 import static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass;
28 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
29
30 import java.lang.reflect.Array;
31 import java.lang.reflect.Executable;
32 import java.lang.reflect.Field;
33 import java.lang.reflect.Modifier;
34 import java.util.Objects;
35
36 import jdk.vm.ci.code.CodeUtil;
37 import jdk.vm.ci.code.TargetDescription;
38 import jdk.vm.ci.common.JVMCIError;
39 import jdk.vm.ci.meta.DeoptimizationAction;
40 import jdk.vm.ci.meta.DeoptimizationReason;
41 import jdk.vm.ci.meta.JavaConstant;
42 import jdk.vm.ci.meta.JavaKind;
43 import jdk.vm.ci.meta.MetaAccessProvider;
44 import jdk.vm.ci.meta.ResolvedJavaField;
45 import jdk.vm.ci.meta.ResolvedJavaMethod;
46 import jdk.vm.ci.meta.ResolvedJavaType;
47 import jdk.vm.ci.meta.Signature;
48
49 // JaCoCo Exclude
50
51 /**
52 * HotSpot implementation of {@link MetaAccessProvider}.
53 */
54 public class HotSpotMetaAccessProvider implements MetaAccessProvider {
55
56 protected final HotSpotJVMCIRuntimeProvider runtime;
57
267 }
268 if (reason == config.deoptReasonTransferToInterpreter) {
269 return DeoptimizationReason.TransferToInterpreter;
270 }
271 throw new JVMCIError("%x", reason);
272 }
273
274 @Override
275 public long getMemorySize(JavaConstant constant) {
276 if (constant.getJavaKind() == JavaKind.Object) {
277 HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant);
278
279 if (lookupJavaType == null) {
280 return 0;
281 } else {
282 if (lookupJavaType.isArray()) {
283 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object());
284 ResolvedJavaType elementType = lookupJavaType.getComponentType();
285 JavaKind elementKind = elementType.getJavaKind();
286 final int headerSize = getArrayBaseOffset(elementKind);
287 TargetDescription target = runtime.getHostJVMCIBackend().getTarget();
288 int sizeOfElement = getArrayIndexScale(elementKind);
289 int alignment = target.wordSize;
290 int log2ElementSize = CodeUtil.log2(sizeOfElement);
291 return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
292 }
293 return lookupJavaType.instanceSize();
294 }
295 } else {
296 return constant.getJavaKind().getByteCount();
297 }
298 }
299
300 /**
301 * Computes the size of the memory chunk allocated for an array. This size accounts for the
302 * array header size, body size and any padding after the last element to satisfy object
303 * alignment requirements.
304 *
305 * @param length the number of elements in the array
306 * @param alignment the object alignment requirement
307 * @param headerSize the size of the array header
308 * @param log2ElementSize log2 of the size of an element in the array
309 */
310 public static int computeArrayAllocationSize(int length, int alignment, int headerSize, int log2ElementSize) {
311 int size = (length << log2ElementSize) + headerSize + (alignment - 1);
312 int mask = ~(alignment - 1);
313 return size & mask;
314 }
315 }
|
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 import static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass;
28 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
29
30 import java.lang.reflect.Array;
31 import java.lang.reflect.Executable;
32 import java.lang.reflect.Field;
33 import java.lang.reflect.Modifier;
34 import java.util.Objects;
35
36 import jdk.vm.ci.code.CodeUtil;
37 import jdk.vm.ci.common.JVMCIError;
38 import jdk.vm.ci.meta.DeoptimizationAction;
39 import jdk.vm.ci.meta.DeoptimizationReason;
40 import jdk.vm.ci.meta.JavaConstant;
41 import jdk.vm.ci.meta.JavaKind;
42 import jdk.vm.ci.meta.MetaAccessProvider;
43 import jdk.vm.ci.meta.ResolvedJavaField;
44 import jdk.vm.ci.meta.ResolvedJavaMethod;
45 import jdk.vm.ci.meta.ResolvedJavaType;
46 import jdk.vm.ci.meta.Signature;
47
48 // JaCoCo Exclude
49
50 /**
51 * HotSpot implementation of {@link MetaAccessProvider}.
52 */
53 public class HotSpotMetaAccessProvider implements MetaAccessProvider {
54
55 protected final HotSpotJVMCIRuntimeProvider runtime;
56
266 }
267 if (reason == config.deoptReasonTransferToInterpreter) {
268 return DeoptimizationReason.TransferToInterpreter;
269 }
270 throw new JVMCIError("%x", reason);
271 }
272
273 @Override
274 public long getMemorySize(JavaConstant constant) {
275 if (constant.getJavaKind() == JavaKind.Object) {
276 HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant);
277
278 if (lookupJavaType == null) {
279 return 0;
280 } else {
281 if (lookupJavaType.isArray()) {
282 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object());
283 ResolvedJavaType elementType = lookupJavaType.getComponentType();
284 JavaKind elementKind = elementType.getJavaKind();
285 final int headerSize = getArrayBaseOffset(elementKind);
286 int sizeOfElement = getArrayIndexScale(elementKind);
287 int log2ElementSize = CodeUtil.log2(sizeOfElement);
288 return computeArrayAllocationSize(length, headerSize, log2ElementSize);
289 }
290 return lookupJavaType.instanceSize();
291 }
292 } else {
293 return constant.getJavaKind().getByteCount();
294 }
295 }
296
297 /**
298 * Computes the size of the memory chunk allocated for an array. This size accounts for the
299 * array header size, body size and any padding after the last element to satisfy object
300 * alignment requirements.
301 *
302 * @param length the number of elements in the array
303 * @param headerSize the size of the array header
304 * @param log2ElementSize log2 of the size of an element in the array
305 * @return the size of the memory chunk
306 */
307 public int computeArrayAllocationSize(int length, int headerSize, int log2ElementSize) {
308 HotSpotVMConfig config = runtime.getConfig();
309 int alignment = config.objectAlignment;
310 int size = (length << log2ElementSize) + headerSize + (alignment - 1);
311 int mask = ~(alignment - 1);
312 return size & mask;
313 }
314 }
|