001/* 002 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package jdk.internal.jvmci.hotspot; 024 025import jdk.internal.jvmci.common.*; 026import jdk.internal.jvmci.meta.*; 027import jdk.internal.jvmci.runtime.*; 028import sun.misc.*; 029 030//JaCoCo Exclude 031 032/** 033 * Configuration information for the HotSpot JVMCI runtime. 034 */ 035public interface HotSpotJVMCIRuntimeProvider extends JVMCIRuntime { 036 037 HotSpotVMConfig getConfig(); 038 039 CompilerToVM getCompilerToVM(); 040 041 /** 042 * Converts a name to a Java type. This method attempts to resolve {@code name} to a 043 * {@link ResolvedJavaType}. 044 * 045 * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format 046 * @param accessingType the context of resolution which must be non-null 047 * @param resolve specifies whether resolution failure results in an unresolved type being 048 * return or a {@link LinkageError} being thrown 049 * @return a Java type for {@code name} which is guaranteed to be of type 050 * {@link ResolvedJavaType} if {@code resolve == true} 051 * @throws LinkageError if {@code resolve == true} and the resolution failed 052 * @throws NullPointerException if {@code accessingClass} is {@code null} 053 */ 054 JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve); 055 056 /** 057 * Gets the JVMCI mirror for a {@link Class} object. 058 * 059 * @return the {@link ResolvedJavaType} corresponding to {@code javaClass} 060 */ 061 ResolvedJavaType fromClass(Class<?> clazz); 062 063 /** 064 * The offset from the origin of an array to the first element. 065 * 066 * @return the offset in bytes 067 */ 068 default int getArrayBaseOffset(Kind kind) { 069 switch (kind) { 070 case Boolean: 071 return Unsafe.ARRAY_BOOLEAN_BASE_OFFSET; 072 case Byte: 073 return Unsafe.ARRAY_BYTE_BASE_OFFSET; 074 case Char: 075 return Unsafe.ARRAY_CHAR_BASE_OFFSET; 076 case Short: 077 return Unsafe.ARRAY_SHORT_BASE_OFFSET; 078 case Int: 079 return Unsafe.ARRAY_INT_BASE_OFFSET; 080 case Long: 081 return Unsafe.ARRAY_LONG_BASE_OFFSET; 082 case Float: 083 return Unsafe.ARRAY_FLOAT_BASE_OFFSET; 084 case Double: 085 return Unsafe.ARRAY_DOUBLE_BASE_OFFSET; 086 case Object: 087 return Unsafe.ARRAY_OBJECT_BASE_OFFSET; 088 default: 089 throw new JVMCIError("%s", kind); 090 } 091 } 092 093 /** 094 * The scale used for the index when accessing elements of an array of this kind. 095 * 096 * @return the scale in order to convert the index into a byte offset 097 */ 098 default int getArrayIndexScale(Kind kind) { 099 switch (kind) { 100 case Boolean: 101 return Unsafe.ARRAY_BOOLEAN_INDEX_SCALE; 102 case Byte: 103 return Unsafe.ARRAY_BYTE_INDEX_SCALE; 104 case Char: 105 return Unsafe.ARRAY_CHAR_INDEX_SCALE; 106 case Short: 107 return Unsafe.ARRAY_SHORT_INDEX_SCALE; 108 case Int: 109 return Unsafe.ARRAY_INT_INDEX_SCALE; 110 case Long: 111 return Unsafe.ARRAY_LONG_INDEX_SCALE; 112 case Float: 113 return Unsafe.ARRAY_FLOAT_INDEX_SCALE; 114 case Double: 115 return Unsafe.ARRAY_DOUBLE_INDEX_SCALE; 116 case Object: 117 return Unsafe.ARRAY_OBJECT_INDEX_SCALE; 118 default: 119 throw new JVMCIError("%s", kind); 120 } 121 } 122}