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 7 * published by the Free Software Foundation. 8 * 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.HotSpotResolvedObjectTypeImpl.*; 26 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; 27 28 import java.lang.reflect.*; 29 30 import jdk.vm.ci.code.*; 31 import jdk.vm.ci.common.*; 32 import jdk.vm.ci.meta.*; 33 34 // JaCoCo Exclude 35 36 /** 37 * HotSpot implementation of {@link MetaAccessProvider}. 38 */ 39 public class HotSpotMetaAccessProvider implements MetaAccessProvider, HotSpotProxified { 40 41 protected final HotSpotJVMCIRuntimeProvider runtime; 42 43 public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) { 44 this.runtime = runtime; 45 } 46 47 public ResolvedJavaType lookupJavaType(Class<?> clazz) { 48 if (clazz == null) { 49 throw new IllegalArgumentException("Class parameter was null"); 50 } 51 return runtime.fromClass(clazz); 52 } 275 } 276 if (reason == config.deoptReasonTransferToInterpreter) { 277 return DeoptimizationReason.TransferToInterpreter; 278 } 279 throw new JVMCIError("%x", reason); 280 } 281 282 @Override 283 public long getMemorySize(JavaConstant constant) { 284 if (constant.getJavaKind() == JavaKind.Object) { 285 HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant); 286 287 if (lookupJavaType == null) { 288 return 0; 289 } else { 290 if (lookupJavaType.isArray()) { 291 // TODO(tw): Add compressed pointer support. 292 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object()); 293 ResolvedJavaType elementType = lookupJavaType.getComponentType(); 294 JavaKind elementKind = elementType.getJavaKind(); 295 final int headerSize = runtime.getArrayBaseOffset(elementKind); 296 TargetDescription target = runtime.getHostJVMCIBackend().getTarget(); 297 int sizeOfElement = target.getSizeInBytes(elementKind); 298 int alignment = target.wordSize; 299 int log2ElementSize = CodeUtil.log2(sizeOfElement); 300 return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); 301 } 302 return lookupJavaType.instanceSize(); 303 } 304 } else { 305 return constant.getJavaKind().getByteCount(); 306 } 307 } 308 309 /** 310 * Computes the size of the memory chunk allocated for an array. This size accounts for the 311 * array header size, body size and any padding after the last element to satisfy object 312 * alignment requirements. 313 * 314 * @param length the number of elements in the array 315 * @param alignment the object alignment requirement 316 * @param headerSize the size of the array header 317 * @param log2ElementSize log2 of the size of an element in the array | 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 7 * published by the Free Software Foundation. 8 * 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 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.Constructor; 32 import java.lang.reflect.Executable; 33 import java.lang.reflect.Field; 34 import java.lang.reflect.Method; 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.JavaType; 45 import jdk.vm.ci.meta.MetaAccessProvider; 46 import jdk.vm.ci.meta.ResolvedJavaField; 47 import jdk.vm.ci.meta.ResolvedJavaMethod; 48 import jdk.vm.ci.meta.ResolvedJavaType; 49 import jdk.vm.ci.meta.Signature; 50 51 // JaCoCo Exclude 52 53 /** 54 * HotSpot implementation of {@link MetaAccessProvider}. 55 */ 56 public class HotSpotMetaAccessProvider implements MetaAccessProvider, HotSpotProxified { 57 58 protected final HotSpotJVMCIRuntimeProvider runtime; 59 60 public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) { 61 this.runtime = runtime; 62 } 63 64 public ResolvedJavaType lookupJavaType(Class<?> clazz) { 65 if (clazz == null) { 66 throw new IllegalArgumentException("Class parameter was null"); 67 } 68 return runtime.fromClass(clazz); 69 } 292 } 293 if (reason == config.deoptReasonTransferToInterpreter) { 294 return DeoptimizationReason.TransferToInterpreter; 295 } 296 throw new JVMCIError("%x", reason); 297 } 298 299 @Override 300 public long getMemorySize(JavaConstant constant) { 301 if (constant.getJavaKind() == JavaKind.Object) { 302 HotSpotResolvedObjectType lookupJavaType = lookupJavaType(constant); 303 304 if (lookupJavaType == null) { 305 return 0; 306 } else { 307 if (lookupJavaType.isArray()) { 308 // TODO(tw): Add compressed pointer support. 309 int length = Array.getLength(((HotSpotObjectConstantImpl) constant).object()); 310 ResolvedJavaType elementType = lookupJavaType.getComponentType(); 311 JavaKind elementKind = elementType.getJavaKind(); 312 final int headerSize = getArrayBaseOffset(elementKind); 313 TargetDescription target = runtime.getHostJVMCIBackend().getTarget(); 314 int sizeOfElement = getArrayIndexScale(elementKind); 315 int alignment = target.wordSize; 316 int log2ElementSize = CodeUtil.log2(sizeOfElement); 317 return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); 318 } 319 return lookupJavaType.instanceSize(); 320 } 321 } else { 322 return constant.getJavaKind().getByteCount(); 323 } 324 } 325 326 /** 327 * Computes the size of the memory chunk allocated for an array. This size accounts for the 328 * array header size, body size and any padding after the last element to satisfy object 329 * alignment requirements. 330 * 331 * @param length the number of elements in the array 332 * @param alignment the object alignment requirement 333 * @param headerSize the size of the array header 334 * @param log2ElementSize log2 of the size of an element in the array |