1 /* 2 * Copyright (c) 2015, 2018, 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 24 package jdk.vm.ci.hotspot; 25 26 import jdk.vm.ci.code.InstalledCode; 27 import jdk.vm.ci.code.InvalidInstalledCodeException; 28 import jdk.vm.ci.code.TargetDescription; 29 import jdk.vm.ci.code.stack.InspectedFrameVisitor; 30 import jdk.vm.ci.meta.ConstantPool; 31 import jdk.vm.ci.meta.ResolvedJavaMethod; 32 import java.lang.reflect.Executable; 33 34 /** 35 * A simple "proxy" class to get test access to CompilerToVM package-private methods 36 */ 37 public class CompilerToVMHelper { 38 public static final CompilerToVM CTVM = new CompilerToVM(); 39 getBytecode(HotSpotResolvedJavaMethod method)40 public static byte[] getBytecode(HotSpotResolvedJavaMethod method) { 41 return CTVM.getBytecode((HotSpotResolvedJavaMethodImpl)method); 42 } 43 getExceptionTableLength(HotSpotResolvedJavaMethod method)44 public static int getExceptionTableLength(HotSpotResolvedJavaMethod method) { 45 return CTVM.getExceptionTableLength((HotSpotResolvedJavaMethodImpl)method); 46 } 47 getExceptionTableStart(HotSpotResolvedJavaMethod method)48 public static long getExceptionTableStart(HotSpotResolvedJavaMethod method) { 49 return CTVM.getExceptionTableStart((HotSpotResolvedJavaMethodImpl)method); 50 } 51 getFlagValue(String name)52 public static Object getFlagValue(String name) { 53 return CTVM.getFlagValue(name); 54 } 55 isCompilable(HotSpotResolvedJavaMethod method)56 public static boolean isCompilable(HotSpotResolvedJavaMethod method) { 57 return CTVM.isCompilable((HotSpotResolvedJavaMethodImpl)method); 58 } 59 hasNeverInlineDirective(HotSpotResolvedJavaMethod method)60 public static boolean hasNeverInlineDirective(HotSpotResolvedJavaMethod method) { 61 return CTVM.hasNeverInlineDirective((HotSpotResolvedJavaMethodImpl)method); 62 } 63 shouldInlineMethod(HotSpotResolvedJavaMethod method)64 public static boolean shouldInlineMethod(HotSpotResolvedJavaMethod method) { 65 return CTVM.shouldInlineMethod((HotSpotResolvedJavaMethodImpl)method); 66 } 67 findUniqueConcreteMethod( HotSpotResolvedObjectType actualHolderType, HotSpotResolvedJavaMethod method)68 public static HotSpotResolvedJavaMethod findUniqueConcreteMethod( 69 HotSpotResolvedObjectType actualHolderType, 70 HotSpotResolvedJavaMethod method) { 71 return CTVM.findUniqueConcreteMethod((HotSpotResolvedObjectTypeImpl) actualHolderType, (HotSpotResolvedJavaMethodImpl)method); 72 } 73 getImplementor(HotSpotResolvedObjectType type)74 public static HotSpotResolvedObjectType getImplementor(HotSpotResolvedObjectType type) { 75 return CTVM.getImplementor((HotSpotResolvedObjectTypeImpl) type); 76 } 77 methodIsIgnoredBySecurityStackWalk(HotSpotResolvedJavaMethod method)78 public static boolean methodIsIgnoredBySecurityStackWalk(HotSpotResolvedJavaMethod method) { 79 return CTVM.methodIsIgnoredBySecurityStackWalk((HotSpotResolvedJavaMethodImpl)method); 80 } 81 lookupType(String name, Class<?> accessingClass, boolean resolve)82 public static HotSpotResolvedObjectType lookupType(String name, 83 Class<?> accessingClass, boolean resolve) throws ClassNotFoundException { 84 return CTVM.lookupType(name, accessingClass, resolve); 85 } 86 lookupTypeHelper(String name, Class<?> accessingClass, boolean resolve)87 public static HotSpotResolvedObjectType lookupTypeHelper(String name, 88 Class<?> accessingClass, boolean resolve) { 89 try { 90 return lookupType(name, accessingClass, resolve); 91 } catch (ClassNotFoundException e) { 92 throw (NoClassDefFoundError) new NoClassDefFoundError().initCause(e); 93 } 94 } 95 resolveConstantInPool(ConstantPool constantPool, int cpi)96 public static Object resolveConstantInPool(ConstantPool constantPool, int cpi) { 97 return CTVM.resolveConstantInPool((HotSpotConstantPool) constantPool, cpi); 98 } 99 resolvePossiblyCachedConstantInPool(ConstantPool constantPool, int cpi)100 public static Object resolvePossiblyCachedConstantInPool(ConstantPool constantPool, int cpi) { 101 return CTVM.resolvePossiblyCachedConstantInPool((HotSpotConstantPool) constantPool, cpi); 102 } 103 lookupNameAndTypeRefIndexInPool(ConstantPool constantPool, int cpi)104 public static int lookupNameAndTypeRefIndexInPool(ConstantPool constantPool, int cpi) { 105 return CTVM.lookupNameAndTypeRefIndexInPool((HotSpotConstantPool) constantPool, cpi); 106 } 107 lookupNameInPool(ConstantPool constantPool, int cpi)108 public static String lookupNameInPool(ConstantPool constantPool, int cpi) { 109 return CTVM.lookupNameInPool((HotSpotConstantPool) constantPool, cpi); 110 } 111 lookupSignatureInPool(ConstantPool constantPool, int cpi)112 public static String lookupSignatureInPool(ConstantPool constantPool, int cpi) { 113 return CTVM.lookupSignatureInPool((HotSpotConstantPool) constantPool, cpi); 114 } 115 lookupKlassRefIndexInPool(ConstantPool constantPool, int cpi)116 public static int lookupKlassRefIndexInPool(ConstantPool constantPool, int cpi) { 117 return CTVM.lookupKlassRefIndexInPool((HotSpotConstantPool) constantPool, cpi); 118 } 119 lookupKlassInPool(ConstantPool constantPool, int cpi)120 public static Object lookupKlassInPool(ConstantPool constantPool, int cpi) { 121 return CTVM.lookupKlassInPool((HotSpotConstantPool) constantPool, cpi); 122 } 123 lookupMethodInPool( ConstantPool constantPool, int cpi, byte opcode)124 public static HotSpotResolvedJavaMethod lookupMethodInPool( 125 ConstantPool constantPool, int cpi, byte opcode) { 126 return CTVM.lookupMethodInPool((HotSpotConstantPool) constantPool, cpi, opcode); 127 } 128 resolveInvokeDynamicInPool( ConstantPool constantPool, int cpi)129 public static void resolveInvokeDynamicInPool( 130 ConstantPool constantPool, int cpi) { 131 CTVM.resolveInvokeDynamicInPool((HotSpotConstantPool) constantPool, cpi); 132 } 133 resolveInvokeHandleInPool( ConstantPool constantPool, int cpi)134 public static void resolveInvokeHandleInPool( 135 ConstantPool constantPool, int cpi) { 136 CTVM.resolveInvokeHandleInPool((HotSpotConstantPool) constantPool, cpi); 137 } 138 resolveTypeInPool( ConstantPool constantPool, int cpi)139 public static HotSpotResolvedObjectType resolveTypeInPool( 140 ConstantPool constantPool, int cpi) { 141 return CTVM.resolveTypeInPool((HotSpotConstantPool) constantPool, cpi); 142 } 143 resolveFieldInPool( ConstantPool constantPool, int cpi, ResolvedJavaMethod method, byte opcode, int[] info)144 public static HotSpotResolvedObjectType resolveFieldInPool( 145 ConstantPool constantPool, int cpi, ResolvedJavaMethod method, byte opcode, int[] info) { 146 return CTVM.resolveFieldInPool((HotSpotConstantPool) constantPool, cpi, (HotSpotResolvedJavaMethodImpl) method, opcode, info); 147 } 148 constantPoolRemapInstructionOperandFromCache( ConstantPool constantPool, int cpci)149 public static int constantPoolRemapInstructionOperandFromCache( 150 ConstantPool constantPool, int cpci) { 151 return CTVM.constantPoolRemapInstructionOperandFromCache((HotSpotConstantPool) constantPool, cpci); 152 } 153 lookupAppendixInPool( ConstantPool constantPool, int cpi)154 public static Object lookupAppendixInPool( 155 ConstantPool constantPool, int cpi) { 156 return CTVM.lookupAppendixInPool((HotSpotConstantPool) constantPool, cpi); 157 } 158 installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog)159 public static int installCode(TargetDescription target, 160 HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog) { 161 return CTVM.installCode(target, compiledCode, code, speculationLog); 162 } 163 getMetadata(TargetDescription target, HotSpotCompiledCode compiledCode, HotSpotMetaData metaData)164 public static int getMetadata(TargetDescription target, 165 HotSpotCompiledCode compiledCode, HotSpotMetaData metaData) { 166 return CTVM.getMetadata(target, compiledCode, metaData); 167 } 168 resetCompilationStatistics()169 public static void resetCompilationStatistics() { 170 CTVM.resetCompilationStatistics(); 171 } 172 readConfiguration()173 public static Object[] readConfiguration() { 174 return CTVM.readConfiguration(); 175 } 176 resolveMethod( HotSpotResolvedObjectType exactReceiver, HotSpotResolvedJavaMethod method, HotSpotResolvedObjectType caller)177 public static HotSpotResolvedJavaMethod resolveMethod( 178 HotSpotResolvedObjectType exactReceiver, 179 HotSpotResolvedJavaMethod method, 180 HotSpotResolvedObjectType caller) { 181 return CTVM.resolveMethod((HotSpotResolvedObjectTypeImpl) exactReceiver, (HotSpotResolvedJavaMethodImpl) method, (HotSpotResolvedObjectTypeImpl) caller); 182 } 183 getClassInitializer( HotSpotResolvedObjectType type)184 public static HotSpotResolvedJavaMethod getClassInitializer( 185 HotSpotResolvedObjectType type) { 186 return CTVM.getClassInitializer((HotSpotResolvedObjectTypeImpl) type); 187 } 188 hasFinalizableSubclass(HotSpotResolvedObjectType type)189 public static boolean hasFinalizableSubclass(HotSpotResolvedObjectType type) { 190 return CTVM.hasFinalizableSubclass((HotSpotResolvedObjectTypeImpl) type); 191 } 192 asResolvedJavaMethod( Executable executable)193 public static HotSpotResolvedJavaMethodImpl asResolvedJavaMethod( 194 Executable executable) { 195 return CTVM.asResolvedJavaMethod(executable); 196 } 197 getMaxCallTargetOffset(long address)198 public static long getMaxCallTargetOffset(long address) { 199 return CTVM.getMaxCallTargetOffset(address); 200 } 201 disassembleCodeBlob(InstalledCode codeBlob)202 public static String disassembleCodeBlob(InstalledCode codeBlob) { 203 return CTVM.disassembleCodeBlob(codeBlob); 204 } 205 getStackTraceElement( HotSpotResolvedJavaMethod method, int bci)206 public static StackTraceElement getStackTraceElement( 207 HotSpotResolvedJavaMethod method, int bci) { 208 return CTVM.getStackTraceElement((HotSpotResolvedJavaMethodImpl)method, bci); 209 } 210 executeInstalledCode(Object[] args, InstalledCode installedCode)211 public static Object executeInstalledCode(Object[] args, 212 InstalledCode installedCode) throws InvalidInstalledCodeException { 213 return CTVM.executeInstalledCode(args, installedCode); 214 } 215 getLineNumberTable(HotSpotResolvedJavaMethod method)216 public static long[] getLineNumberTable(HotSpotResolvedJavaMethod method) { 217 return CTVM.getLineNumberTable((HotSpotResolvedJavaMethodImpl)method); 218 } 219 getLocalVariableTableLength(HotSpotResolvedJavaMethod method)220 public static int getLocalVariableTableLength(HotSpotResolvedJavaMethod method) { 221 return CTVM.getLocalVariableTableLength((HotSpotResolvedJavaMethodImpl)method); 222 } 223 getLocalVariableTableStart(HotSpotResolvedJavaMethod method)224 public static long getLocalVariableTableStart(HotSpotResolvedJavaMethod method) { 225 return CTVM.getLocalVariableTableStart((HotSpotResolvedJavaMethodImpl)method); 226 } 227 setNotInlinableOrCompilable(HotSpotResolvedJavaMethod method)228 public static void setNotInlinableOrCompilable(HotSpotResolvedJavaMethod method) { 229 CTVM.setNotInlinableOrCompilable((HotSpotResolvedJavaMethodImpl)method); 230 } 231 reprofile(HotSpotResolvedJavaMethod method)232 public static void reprofile(HotSpotResolvedJavaMethod method) { 233 CTVM.reprofile((HotSpotResolvedJavaMethodImpl)method); 234 } 235 invalidateInstalledCode(InstalledCode installedCode)236 public static void invalidateInstalledCode(InstalledCode installedCode) { 237 CTVM.invalidateInstalledCode(installedCode); 238 } 239 collectCounters()240 public static long[] collectCounters() { 241 return CTVM.collectCounters(); 242 } 243 isMature(long metaspaceMethodData)244 public static boolean isMature(long metaspaceMethodData) { 245 return CTVM.isMature(metaspaceMethodData); 246 } 247 allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI)248 public static int allocateCompileId(HotSpotResolvedJavaMethod method, 249 int entryBCI) { 250 return CTVM.allocateCompileId((HotSpotResolvedJavaMethodImpl) method, entryBCI); 251 } 252 hasCompiledCodeForOSR( HotSpotResolvedJavaMethod method, int entryBCI, int level)253 public static boolean hasCompiledCodeForOSR( 254 HotSpotResolvedJavaMethod method, int entryBCI, int level) { 255 return CTVM.hasCompiledCodeForOSR((HotSpotResolvedJavaMethodImpl) method, entryBCI, level); 256 } 257 getSymbol(long metaspaceSymbol)258 public static String getSymbol(long metaspaceSymbol) { 259 return CTVM.getSymbol(metaspaceSymbol); 260 } 261 iterateFrames( ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip, InspectedFrameVisitor<T> visitor)262 public static <T> T iterateFrames( 263 ResolvedJavaMethod[] initialMethods, 264 ResolvedJavaMethod[] matchingMethods, 265 int initialSkip, 266 InspectedFrameVisitor<T> visitor) { 267 return CTVM.iterateFrames(initialMethods, matchingMethods, initialSkip, visitor); 268 } 269 materializeVirtualObjects( HotSpotStackFrameReference stackFrame, boolean invalidate)270 public static void materializeVirtualObjects( 271 HotSpotStackFrameReference stackFrame, boolean invalidate) { 272 CTVM.materializeVirtualObjects(stackFrame, invalidate); 273 } 274 getVtableIndexForInterfaceMethod(HotSpotResolvedObjectType type, HotSpotResolvedJavaMethod method)275 public static int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectType type, 276 HotSpotResolvedJavaMethod method) { 277 return CTVM.getVtableIndexForInterfaceMethod((HotSpotResolvedObjectTypeImpl) type, (HotSpotResolvedJavaMethodImpl) method); 278 } 279 shouldDebugNonSafepoints()280 public static boolean shouldDebugNonSafepoints() { 281 return CTVM.shouldDebugNonSafepoints(); 282 } 283 writeDebugOutput(byte[] bytes, int offset, int length)284 public static void writeDebugOutput(byte[] bytes, int offset, int length) { 285 CTVM.writeDebugOutput(bytes, offset, length); 286 } 287 flushDebugOutput()288 public static void flushDebugOutput() { 289 CTVM.flushDebugOutput(); 290 } 291 getResolvedJavaMethod(Object base, long displacement)292 public static HotSpotResolvedJavaMethod getResolvedJavaMethod(Object base, 293 long displacement) { 294 return CTVM.getResolvedJavaMethod(base, displacement); 295 } 296 getConstantPool(Object object)297 public static HotSpotConstantPool getConstantPool(Object object) { 298 return CTVM.getConstantPool(object); 299 } 300 getResolvedJavaType(Object base, long displacement, boolean compressed)301 public static HotSpotResolvedObjectType getResolvedJavaType(Object base, 302 long displacement, boolean compressed) { 303 return CTVM.getResolvedJavaType(base, displacement, compressed); 304 } 305 getMetaspacePointer(Object o)306 public static long getMetaspacePointer(Object o) { 307 return ((MetaspaceWrapperObject) o).getMetaspacePointer(); 308 } 309 CompilerToVMClass()310 public static Class<?> CompilerToVMClass() { 311 return CompilerToVM.class; 312 } 313 getMirror(HotSpotResolvedObjectType type)314 public static Class<?> getMirror(HotSpotResolvedObjectType type) { 315 return ((HotSpotResolvedJavaType) type).mirror(); 316 } 317 fromObjectClass(Class<?> theClass)318 public static HotSpotResolvedObjectType fromObjectClass(Class<?> theClass) { 319 return HotSpotResolvedObjectTypeImpl.fromObjectClass(theClass); 320 } 321 } 322