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