35 import java.lang.reflect.Modifier;
36
37 import jdk.vm.ci.code.CodeUtil;
38 import jdk.vm.ci.code.TargetDescription;
39 import jdk.vm.ci.common.JVMCIError;
40 import jdk.vm.ci.meta.DeoptimizationAction;
41 import jdk.vm.ci.meta.DeoptimizationReason;
42 import jdk.vm.ci.meta.JavaConstant;
43 import jdk.vm.ci.meta.JavaKind;
44 import jdk.vm.ci.meta.MetaAccessProvider;
45 import jdk.vm.ci.meta.ResolvedJavaField;
46 import jdk.vm.ci.meta.ResolvedJavaMethod;
47 import jdk.vm.ci.meta.ResolvedJavaType;
48 import jdk.vm.ci.meta.Signature;
49
50 // JaCoCo Exclude
51
52 /**
53 * HotSpot implementation of {@link MetaAccessProvider}.
54 */
55 public class HotSpotMetaAccessProvider implements MetaAccessProvider, HotSpotProxified {
56
57 protected final HotSpotJVMCIRuntimeProvider runtime;
58
59 public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) {
60 this.runtime = runtime;
61 }
62
63 public ResolvedJavaType lookupJavaType(Class<?> clazz) {
64 if (clazz == null) {
65 throw new IllegalArgumentException("Class parameter was null");
66 }
67 return runtime.fromClass(clazz);
68 }
69
70 public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) {
71 if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) {
72 return null;
73 }
74 return ((HotSpotObjectConstant) constant).getType();
75 }
291 return DeoptimizationReason.LoopLimitCheck;
292 }
293 if (reason == config.deoptReasonAliasing) {
294 return DeoptimizationReason.Aliasing;
295 }
296 if (reason == config.deoptReasonTransferToInterpreter) {
297 return DeoptimizationReason.TransferToInterpreter;
298 }
299 throw new JVMCIError("%x", reason);
300 }
301
302 @Override
303 public long getMemorySize(JavaConstant constant) {
304 if (constant.getJavaKind() == JavaKind.Object) {
305 HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant);
306
307 if (lookupJavaType == null) {
308 return 0;
309 } else {
310 if (lookupJavaType.isArray()) {
311 // TODO(tw): Add compressed pointer support.
312 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object());
313 ResolvedJavaType elementType = lookupJavaType.getComponentType();
314 JavaKind elementKind = elementType.getJavaKind();
315 final int headerSize = getArrayBaseOffset(elementKind);
316 TargetDescription target = runtime.getHostJVMCIBackend().getTarget();
317 int sizeOfElement = getArrayIndexScale(elementKind);
318 int alignment = target.wordSize;
319 int log2ElementSize = CodeUtil.log2(sizeOfElement);
320 return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
321 }
322 return lookupJavaType.instanceSize();
323 }
324 } else {
325 return constant.getJavaKind().getByteCount();
326 }
327 }
328
329 /**
330 * Computes the size of the memory chunk allocated for an array. This size accounts for the
331 * array header size, body size and any padding after the last element to satisfy object
|
35 import java.lang.reflect.Modifier;
36
37 import jdk.vm.ci.code.CodeUtil;
38 import jdk.vm.ci.code.TargetDescription;
39 import jdk.vm.ci.common.JVMCIError;
40 import jdk.vm.ci.meta.DeoptimizationAction;
41 import jdk.vm.ci.meta.DeoptimizationReason;
42 import jdk.vm.ci.meta.JavaConstant;
43 import jdk.vm.ci.meta.JavaKind;
44 import jdk.vm.ci.meta.MetaAccessProvider;
45 import jdk.vm.ci.meta.ResolvedJavaField;
46 import jdk.vm.ci.meta.ResolvedJavaMethod;
47 import jdk.vm.ci.meta.ResolvedJavaType;
48 import jdk.vm.ci.meta.Signature;
49
50 // JaCoCo Exclude
51
52 /**
53 * HotSpot implementation of {@link MetaAccessProvider}.
54 */
55 public class HotSpotMetaAccessProvider implements MetaAccessProvider {
56
57 protected final HotSpotJVMCIRuntimeProvider runtime;
58
59 public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) {
60 this.runtime = runtime;
61 }
62
63 public ResolvedJavaType lookupJavaType(Class<?> clazz) {
64 if (clazz == null) {
65 throw new IllegalArgumentException("Class parameter was null");
66 }
67 return runtime.fromClass(clazz);
68 }
69
70 public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) {
71 if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) {
72 return null;
73 }
74 return ((HotSpotObjectConstant) constant).getType();
75 }
291 return DeoptimizationReason.LoopLimitCheck;
292 }
293 if (reason == config.deoptReasonAliasing) {
294 return DeoptimizationReason.Aliasing;
295 }
296 if (reason == config.deoptReasonTransferToInterpreter) {
297 return DeoptimizationReason.TransferToInterpreter;
298 }
299 throw new JVMCIError("%x", reason);
300 }
301
302 @Override
303 public long getMemorySize(JavaConstant constant) {
304 if (constant.getJavaKind() == JavaKind.Object) {
305 HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant);
306
307 if (lookupJavaType == null) {
308 return 0;
309 } else {
310 if (lookupJavaType.isArray()) {
311 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object());
312 ResolvedJavaType elementType = lookupJavaType.getComponentType();
313 JavaKind elementKind = elementType.getJavaKind();
314 final int headerSize = getArrayBaseOffset(elementKind);
315 TargetDescription target = runtime.getHostJVMCIBackend().getTarget();
316 int sizeOfElement = getArrayIndexScale(elementKind);
317 int alignment = target.wordSize;
318 int log2ElementSize = CodeUtil.log2(sizeOfElement);
319 return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
320 }
321 return lookupJavaType.instanceSize();
322 }
323 } else {
324 return constant.getJavaKind().getByteCount();
325 }
326 }
327
328 /**
329 * Computes the size of the memory chunk allocated for an array. This size accounts for the
330 * array header size, body size and any padding after the last element to satisfy object
|