1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 java.io.OutputStream; 26 27 import jdk.internal.misc.Unsafe; 28 import jdk.vm.ci.common.JVMCIError; 29 import jdk.vm.ci.meta.JavaKind; 30 import jdk.vm.ci.meta.JavaType; 31 import jdk.vm.ci.meta.ResolvedJavaType; 32 import jdk.vm.ci.runtime.JVMCIRuntime; 33 34 /** 35 * Configuration information for the HotSpot JVMCI runtime. 36 */ 37 public interface HotSpotJVMCIRuntimeProvider extends JVMCIRuntime { 38 39 HotSpotVMConfigStore getConfigStore(); 40 41 HotSpotVMConfig getConfig(); 42 43 CompilerToVM getCompilerToVM(); 44 45 /** 46 * Gets an output stream that writes to the HotSpot's {@code tty} stream. 47 */ 48 OutputStream getLogStream(); 49 50 /** 51 * Converts a name to a Java type. This method attempts to resolve {@code name} to a 52 * {@link ResolvedJavaType}. 53 * 54 * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format 55 * @param accessingType the context of resolution which must be non-null 56 * @param resolve specifies whether resolution failure results in an unresolved type being 57 * return or a {@link LinkageError} being thrown 58 * @return a Java type for {@code name} which is guaranteed to be of type 59 * {@link ResolvedJavaType} if {@code resolve == true} 60 * @throws LinkageError if {@code resolve == true} and the resolution failed 61 * @throws NullPointerException if {@code accessingClass} is {@code null} 62 */ 63 JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve); 64 65 /** 66 * Gets the JVMCI mirror for a {@link Class} object. 67 * 68 * @return the {@link ResolvedJavaType} corresponding to {@code javaClass} 69 */ 70 ResolvedJavaType fromClass(Class<?> clazz); 71 72 /** 73 * The offset from the origin of an array to the first element. 74 * 75 * @return the offset in bytes 76 */ 77 static int getArrayBaseOffset(JavaKind kind) { 78 switch (kind) { 79 case Boolean: 80 return Unsafe.ARRAY_BOOLEAN_BASE_OFFSET; 81 case Byte: 82 return Unsafe.ARRAY_BYTE_BASE_OFFSET; 83 case Char: 84 return Unsafe.ARRAY_CHAR_BASE_OFFSET; 85 case Short: 86 return Unsafe.ARRAY_SHORT_BASE_OFFSET; 87 case Int: 88 return Unsafe.ARRAY_INT_BASE_OFFSET; 89 case Long: 90 return Unsafe.ARRAY_LONG_BASE_OFFSET; 91 case Float: 92 return Unsafe.ARRAY_FLOAT_BASE_OFFSET; 93 case Double: 94 return Unsafe.ARRAY_DOUBLE_BASE_OFFSET; 95 case Object: 96 return Unsafe.ARRAY_OBJECT_BASE_OFFSET; 97 default: 98 throw new JVMCIError("%s", kind); 99 } 100 } 101 102 /** 103 * The scale used for the index when accessing elements of an array of this kind. 104 * 105 * @return the scale in order to convert the index into a byte offset 106 */ 107 static int getArrayIndexScale(JavaKind kind) { 108 switch (kind) { 109 case Boolean: 110 return Unsafe.ARRAY_BOOLEAN_INDEX_SCALE; 111 case Byte: 112 return Unsafe.ARRAY_BYTE_INDEX_SCALE; 113 case Char: 114 return Unsafe.ARRAY_CHAR_INDEX_SCALE; 115 case Short: 116 return Unsafe.ARRAY_SHORT_INDEX_SCALE; 117 case Int: 118 return Unsafe.ARRAY_INT_INDEX_SCALE; 119 case Long: 120 return Unsafe.ARRAY_LONG_INDEX_SCALE; 121 case Float: 122 return Unsafe.ARRAY_FLOAT_INDEX_SCALE; 123 case Double: 124 return Unsafe.ARRAY_DOUBLE_INDEX_SCALE; 125 case Object: 126 return Unsafe.ARRAY_OBJECT_INDEX_SCALE; 127 default: 128 throw new JVMCIError("%s", kind); 129 } 130 } 131 }