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 resetCompilationStatistics() {
 152         CTVM.resetCompilationStatistics();
 153     }
 154 
 155     public static long initializeConfiguration(HotSpotVMConfig config) {
 156         return CTVM.initializeConfiguration(config);
 157     }
 158 
 159     public static HotSpotResolvedJavaMethod resolveMethod(
 160             HotSpotResolvedObjectType exactReceiver,
 161             HotSpotResolvedJavaMethod method,
 162             HotSpotResolvedObjectType caller) {
 163         return CTVM.resolveMethod((HotSpotResolvedObjectTypeImpl) exactReceiver, (HotSpotResolvedJavaMethodImpl) method, (HotSpotResolvedObjectTypeImpl) caller);
 164     }
 165 
 166     public static HotSpotResolvedJavaMethod getClassInitializer(
 167             HotSpotResolvedObjectType type) {
 168         return CTVM.getClassInitializer((HotSpotResolvedObjectTypeImpl) type);
 169     }
 170 
 171     public static boolean hasFinalizableSubclass(HotSpotResolvedObjectType type) {
 172         return CTVM.hasFinalizableSubclass((HotSpotResolvedObjectTypeImpl) type);
 173     }
 174 
 175     public static HotSpotResolvedJavaMethodImpl getResolvedJavaMethodAtSlot(
 176             Class<?> holder, int slot) {
 177         return CTVM.getResolvedJavaMethodAtSlot(holder, slot);
 178     }
 179 
 180     public static long getMaxCallTargetOffset(long address) {
 181         return CTVM.getMaxCallTargetOffset(address);
 182     }
 183 
 184     public static String disassembleCodeBlob(InstalledCode codeBlob) {
 185         return CTVM.disassembleCodeBlob(codeBlob);
 186     }
 187 
 188     public static StackTraceElement getStackTraceElement(
 189             HotSpotResolvedJavaMethod method, int bci) {
 190         return CTVM.getStackTraceElement((HotSpotResolvedJavaMethodImpl)method, bci);
 191     }
 192 
 193     public static Object executeInstalledCode(Object[] args,
 194             InstalledCode installedCode) throws InvalidInstalledCodeException {
 195         return CTVM.executeInstalledCode(args, installedCode);
 196     }
 197 
 198     public static long[] getLineNumberTable(HotSpotResolvedJavaMethod method) {
 199         return CTVM.getLineNumberTable((HotSpotResolvedJavaMethodImpl)method);
 200     }
 201 
 202     public static int getLocalVariableTableLength(HotSpotResolvedJavaMethod method) {
 203         return CTVM.getLocalVariableTableLength((HotSpotResolvedJavaMethodImpl)method);
 204     }
 205 
 206     public static long getLocalVariableTableStart(HotSpotResolvedJavaMethod method) {
 207         return CTVM.getLocalVariableTableStart((HotSpotResolvedJavaMethodImpl)method);
 208     }
 209 
 210     public static Object readUncompressedOop(long address) {
 211         return CTVM.readUncompressedOop(address);
 212     }
 213 
 214     public static void doNotInlineOrCompile(HotSpotResolvedJavaMethod method) {
 215         CTVM.doNotInlineOrCompile((HotSpotResolvedJavaMethodImpl)method);
 216     }
 217 
 218     public static void reprofile(HotSpotResolvedJavaMethod method) {
 219         CTVM.reprofile((HotSpotResolvedJavaMethodImpl)method);
 220     }
 221 
 222     public static void invalidateInstalledCode(InstalledCode installedCode) {
 223         CTVM.invalidateInstalledCode(installedCode);
 224     }
 225 
 226     public static long[] collectCounters() {
 227         return CTVM.collectCounters();
 228     }
 229 
 230     public static boolean isMature(long metaspaceMethodData) {
 231         return CTVM.isMature(metaspaceMethodData);
 232     }
 233 
 234     public static int allocateCompileId(HotSpotResolvedJavaMethod method,
 235             int entryBCI) {
 236         return CTVM.allocateCompileId((HotSpotResolvedJavaMethodImpl) method, entryBCI);
 237     }
 238 
 239     public static boolean hasCompiledCodeForOSR(
 240             HotSpotResolvedJavaMethod method, int entryBCI, int level) {
 241         return CTVM.hasCompiledCodeForOSR((HotSpotResolvedJavaMethodImpl) method, entryBCI, level);
 242     }
 243 
 244     public static String getSymbol(long metaspaceSymbol) {
 245         return CTVM.getSymbol(metaspaceSymbol);
 246     }
 247 
 248     public static HotSpotStackFrameReference getNextStackFrame(
 249             HotSpotStackFrameReference frame,
 250             ResolvedJavaMethod[] methods, int initialSkip) {
 251         return CTVM.getNextStackFrame(frame, methods, initialSkip);
 252     }
 253 
 254     public static void materializeVirtualObjects(
 255             HotSpotStackFrameReference stackFrame, boolean invalidate) {
 256         CTVM.materializeVirtualObjects(stackFrame, invalidate);
 257     }
 258 
 259     public static int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectType type,
 260             HotSpotResolvedJavaMethod method) {
 261         return CTVM.getVtableIndexForInterfaceMethod((HotSpotResolvedObjectTypeImpl) type, (HotSpotResolvedJavaMethodImpl) method);
 262     }
 263 
 264     public static boolean shouldDebugNonSafepoints() {
 265         return CTVM.shouldDebugNonSafepoints();
 266     }
 267 
 268     public static void writeDebugOutput(byte[] bytes, int offset, int length) {
 269         CTVM.writeDebugOutput(bytes, offset, length);
 270     }
 271 
 272     public static void flushDebugOutput() {
 273         CTVM.flushDebugOutput();
 274     }
 275 
 276     public static HotSpotResolvedJavaMethod getResolvedJavaMethod(Object base,
 277             long displacement) {
 278         return CTVM.getResolvedJavaMethod(base, displacement);
 279     }
 280 
 281     public static HotSpotConstantPool getConstantPool(Object base, long displacement) {
 282         return CTVM.getConstantPool(base, displacement);
 283     }
 284 
 285     public static HotSpotResolvedObjectType getResolvedJavaType(Object base,
 286             long displacement, boolean compressed) {
 287         return CTVM.getResolvedJavaType(base, displacement, compressed);
 288     }
 289 
 290     public static long getMetaspacePointer(Object o) {
 291         return ((MetaspaceWrapperObject) o).getMetaspacePointer();
 292     }
 293 
 294     public static Class<?> CompilerToVMClass() {
 295         return CompilerToVM.class;
 296     }
 297 
 298     public static Class<?> HotSpotConstantPoolClass() {
 299         return HotSpotConstantPool.class;
 300     }
 301 
 302     public static Class<?> getMirror(HotSpotResolvedObjectType type) {
 303         return ((HotSpotResolvedJavaType) type).mirror();
 304     }
 305 }