< prev index next >

src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java

Print this page




   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 static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
  27 import static jdk.vm.ci.inittimer.InitTimer.timer;
  28 
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.Method;
  31 
  32 import jdk.vm.ci.code.BytecodeFrame;
  33 import jdk.vm.ci.code.InstalledCode;
  34 import jdk.vm.ci.code.InvalidInstalledCodeException;
  35 import jdk.vm.ci.code.TargetDescription;

  36 import jdk.vm.ci.common.JVMCIError;
  37 import jdk.vm.ci.hotspotvmconfig.HotSpotVMField;
  38 import jdk.vm.ci.inittimer.InitTimer;
  39 import jdk.vm.ci.meta.JavaType;
  40 import jdk.vm.ci.meta.ResolvedJavaMethod;
  41 import jdk.vm.ci.meta.ResolvedJavaType;
  42 import jdk.internal.misc.Unsafe;
  43 
  44 /**
  45  * Calls from Java into HotSpot. The behavior of all the methods in this class that take a native
  46  * pointer as an argument (e.g., {@link #getSymbol(long)}) is undefined if the argument does not
  47  * denote a valid native object.
  48  */
  49 final class CompilerToVM {
  50     /**
  51      * Initializes the native part of the JVMCI runtime.
  52      */
  53     private static native void registerNatives();
  54 
  55     static {
  56         initialize();
  57     }
  58 


  62             registerNatives();
  63         }
  64     }
  65 
  66     /**
  67      * Gets the {@link CompilerToVM} instance associated with the singleton
  68      * {@link HotSpotJVMCIRuntime} instance.
  69      */
  70     public static CompilerToVM compilerToVM() {
  71         return runtime().getCompilerToVM();
  72     }
  73 
  74     /**
  75      * Copies the original bytecode of {@code method} into a new byte array and returns it.
  76      *
  77      * @return a new byte array containing the original bytecode of {@code method}
  78      */
  79     native byte[] getBytecode(HotSpotResolvedJavaMethodImpl method);
  80 
  81     /**
  82      * Gets the number of entries in {@code method}'s exception handler table or 0 if it has not
  83      * exception handler table.
  84      */
  85     native int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method);
  86 
  87     /**
  88      * Gets the address of the first entry in {@code method}'s exception handler table.
  89      *
  90      * Each entry is a native object described by these fields:
  91      *
  92      * <ul>
  93      * <li>{@link HotSpotVMConfig#exceptionTableElementSize}</li>
  94      * <li>{@link HotSpotVMConfig#exceptionTableElementStartPcOffset}</li>
  95      * <li>{@link HotSpotVMConfig#exceptionTableElementEndPcOffset}</li>
  96      * <li>{@link HotSpotVMConfig#exceptionTableElementHandlerPcOffset}</li>
  97      * <li>{@link HotSpotVMConfig#exceptionTableElementCatchTypeIndexOffset}
  98      * </ul>
  99      *
 100      * @return 0 if {@code method} has no exception handlers (i.e.
 101      *         {@code getExceptionTableLength(method) == 0})
 102      */


 298      */
 299     native Object lookupAppendixInPool(HotSpotConstantPool constantPool, int cpi);
 300 
 301     /**
 302      * Installs the result of a compilation into the code cache.
 303      *
 304      * @param target the target where this code should be installed
 305      * @param compiledCode the result of a compilation
 306      * @param code the details of the installed CodeBlob are written to this object
 307      * @return the outcome of the installation which will be one of
 308      *         {@link HotSpotVMConfig#codeInstallResultOk},
 309      *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
 310      *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
 311      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
 312      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
 313      * @throws JVMCIError if there is something wrong with the compiled code or the associated
 314      *             metadata.
 315      */
 316     native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog);
 317 















 318     public native int getMetadata(TargetDescription target, HotSpotCompiledCode compiledCode, HotSpotMetaData metaData);
 319 
 320     /**
 321      * Resets all compilation statistics.
 322      */
 323     native void resetCompilationStatistics();
 324 
 325     /**
 326      * Initializes the fields of {@code config}.
 327      */
 328     native long initializeConfiguration(HotSpotVMConfig config);
 329 
 330     /**
 331      * Resolves the implementation of {@code method} for virtual dispatches on objects of dynamic
 332      * type {@code exactReceiver}. This resolution process only searches "up" the class hierarchy of
 333      * {@code exactReceiver}.
 334      *
 335      * @param caller the caller or context type used to perform access checks
 336      * @return the link-time resolved method (might be abstract) or {@code 0} if it can not be
 337      *         linked


 458      * Determines if {@code method} has OSR compiled code identified by {@code entryBCI} for
 459      * compilation level {@code level}.
 460      */
 461     native boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI, int level);
 462 
 463     /**
 464      * Gets the value of {@code metaspaceSymbol} as a String.
 465      */
 466     native String getSymbol(long metaspaceSymbol);
 467 
 468     /**
 469      * Looks for the next Java stack frame matching an entry in {@code methods}.
 470      *
 471      * @param frame the starting point of the search, where {@code null} refers to the topmost frame
 472      * @param methods the methods to look for, where {@code null} means that any frame is returned
 473      * @return the frame, or {@code null} if the end of the stack was reached during the search
 474      */
 475     native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip);
 476 
 477     /**
 478      * Materializes all virtual objects within {@code stackFrame} updates its locals.
 479      *
 480      * @param invalidate if {@code true}, the compiled method for the stack frame will be
 481      *            invalidated.
 482      */
 483     native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
 484 
 485     /**
 486      * Gets the v-table index for interface method {@code method} in the receiver {@code type} or
 487      * {@link HotSpotVMConfig#invalidVtableIndex} if {@code method} is not in {@code type}'s
 488      * v-table.
 489      *
 490      * @throws InternalError if {@code type} is an interface or {@code method} is not held by an
 491      *             interface or class represented by {@code type} is not initialized
 492      */
 493     native int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpotResolvedJavaMethodImpl method);
 494 
 495     /**
 496      * Determines if debug info should also be emitted at non-safepoint locations.
 497      */
 498 
 499     native boolean shouldDebugNonSafepoints();
 500 
 501     /**
 502      * Writes {@code length} bytes from {@code bytes} starting at offset {@code offset} to the
 503      * HotSpot's log stream.
 504      *
 505      * @exception NullPointerException if {@code bytes == null}
 506      * @exception IndexOutOfBoundsException if copying would cause access of data outside array
 507      *                bounds
 508      */
 509     native void writeDebugOutput(byte[] bytes, int offset, int length);
 510 
 511     /**
 512      * Flush HotSpot's log stream.
 513      */
 514     native void flushDebugOutput();
 515 
 516     /**
 517      * Read a HotSpot Method* value from the memory location described by {@code base} plus
 518      * {@code displacement} and return the {@link HotSpotResolvedJavaMethodImpl} wrapping it. This




   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 static jdk.vm.ci.common.InitTimer.timer;
  27 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;

  28 
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.Method;
  31 
  32 import jdk.vm.ci.code.BytecodeFrame;
  33 import jdk.vm.ci.code.InstalledCode;
  34 import jdk.vm.ci.code.InvalidInstalledCodeException;
  35 import jdk.vm.ci.code.TargetDescription;
  36 import jdk.vm.ci.common.InitTimer;
  37 import jdk.vm.ci.common.JVMCIError;
  38 import jdk.vm.ci.hotspotvmconfig.HotSpotVMField;

  39 import jdk.vm.ci.meta.JavaType;
  40 import jdk.vm.ci.meta.ResolvedJavaMethod;
  41 import jdk.vm.ci.meta.ResolvedJavaType;
  42 import jdk.internal.misc.Unsafe;
  43 
  44 /**
  45  * Calls from Java into HotSpot. The behavior of all the methods in this class that take a native
  46  * pointer as an argument (e.g., {@link #getSymbol(long)}) is undefined if the argument does not
  47  * denote a valid native object.
  48  */
  49 final class CompilerToVM {
  50     /**
  51      * Initializes the native part of the JVMCI runtime.
  52      */
  53     private static native void registerNatives();
  54 
  55     static {
  56         initialize();
  57     }
  58 


  62             registerNatives();
  63         }
  64     }
  65 
  66     /**
  67      * Gets the {@link CompilerToVM} instance associated with the singleton
  68      * {@link HotSpotJVMCIRuntime} instance.
  69      */
  70     public static CompilerToVM compilerToVM() {
  71         return runtime().getCompilerToVM();
  72     }
  73 
  74     /**
  75      * Copies the original bytecode of {@code method} into a new byte array and returns it.
  76      *
  77      * @return a new byte array containing the original bytecode of {@code method}
  78      */
  79     native byte[] getBytecode(HotSpotResolvedJavaMethodImpl method);
  80 
  81     /**
  82      * Gets the number of entries in {@code method}'s exception handler table or 0 if it has no
  83      * exception handler table.
  84      */
  85     native int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method);
  86 
  87     /**
  88      * Gets the address of the first entry in {@code method}'s exception handler table.
  89      *
  90      * Each entry is a native object described by these fields:
  91      *
  92      * <ul>
  93      * <li>{@link HotSpotVMConfig#exceptionTableElementSize}</li>
  94      * <li>{@link HotSpotVMConfig#exceptionTableElementStartPcOffset}</li>
  95      * <li>{@link HotSpotVMConfig#exceptionTableElementEndPcOffset}</li>
  96      * <li>{@link HotSpotVMConfig#exceptionTableElementHandlerPcOffset}</li>
  97      * <li>{@link HotSpotVMConfig#exceptionTableElementCatchTypeIndexOffset}
  98      * </ul>
  99      *
 100      * @return 0 if {@code method} has no exception handlers (i.e.
 101      *         {@code getExceptionTableLength(method) == 0})
 102      */


 298      */
 299     native Object lookupAppendixInPool(HotSpotConstantPool constantPool, int cpi);
 300 
 301     /**
 302      * Installs the result of a compilation into the code cache.
 303      *
 304      * @param target the target where this code should be installed
 305      * @param compiledCode the result of a compilation
 306      * @param code the details of the installed CodeBlob are written to this object
 307      * @return the outcome of the installation which will be one of
 308      *         {@link HotSpotVMConfig#codeInstallResultOk},
 309      *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
 310      *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
 311      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
 312      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
 313      * @throws JVMCIError if there is something wrong with the compiled code or the associated
 314      *             metadata.
 315      */
 316     native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog);
 317 
 318     /**
 319      * Generates the VM metadata for some compiled code and copies them into {@code metaData}. This
 320      * method does not install anything into the code cache.
 321      *
 322      * @param target the target where this code would be installed
 323      * @param compiledCode the result of a compilation
 324      * @param metaData the metadata is written to this object
 325      * @return the outcome of the installation which will be one of
 326      *         {@link HotSpotVMConfig#codeInstallResultOk},
 327      *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
 328      *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
 329      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
 330      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
 331      * @throws JVMCIError if there is something wrong with the compiled code or the metadata
 332      */
 333     public native int getMetadata(TargetDescription target, HotSpotCompiledCode compiledCode, HotSpotMetaData metaData);
 334 
 335     /**
 336      * Resets all compilation statistics.
 337      */
 338     native void resetCompilationStatistics();
 339 
 340     /**
 341      * Initializes the fields of {@code config}.
 342      */
 343     native long initializeConfiguration(HotSpotVMConfig config);
 344 
 345     /**
 346      * Resolves the implementation of {@code method} for virtual dispatches on objects of dynamic
 347      * type {@code exactReceiver}. This resolution process only searches "up" the class hierarchy of
 348      * {@code exactReceiver}.
 349      *
 350      * @param caller the caller or context type used to perform access checks
 351      * @return the link-time resolved method (might be abstract) or {@code 0} if it can not be
 352      *         linked


 473      * Determines if {@code method} has OSR compiled code identified by {@code entryBCI} for
 474      * compilation level {@code level}.
 475      */
 476     native boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI, int level);
 477 
 478     /**
 479      * Gets the value of {@code metaspaceSymbol} as a String.
 480      */
 481     native String getSymbol(long metaspaceSymbol);
 482 
 483     /**
 484      * Looks for the next Java stack frame matching an entry in {@code methods}.
 485      *
 486      * @param frame the starting point of the search, where {@code null} refers to the topmost frame
 487      * @param methods the methods to look for, where {@code null} means that any frame is returned
 488      * @return the frame, or {@code null} if the end of the stack was reached during the search
 489      */
 490     native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip);
 491 
 492     /**
 493      * Materializes all virtual objects within {@code stackFrame} and updates its locals.
 494      *
 495      * @param invalidate if {@code true}, the compiled method for the stack frame will be
 496      *            invalidated
 497      */
 498     native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
 499 
 500     /**
 501      * Gets the v-table index for interface method {@code method} in the receiver {@code type} or
 502      * {@link HotSpotVMConfig#invalidVtableIndex} if {@code method} is not in {@code type}'s
 503      * v-table.
 504      *
 505      * @throws InternalError if {@code type} is an interface or {@code method} is not held by an
 506      *             interface or class represented by {@code type} is not initialized
 507      */
 508     native int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpotResolvedJavaMethodImpl method);
 509 
 510     /**
 511      * Determines if debug info should also be emitted at non-safepoint locations.
 512      */

 513     native boolean shouldDebugNonSafepoints();
 514 
 515     /**
 516      * Writes {@code length} bytes from {@code bytes} starting at offset {@code offset} to the
 517      * HotSpot's log stream.
 518      *
 519      * @exception NullPointerException if {@code bytes == null}
 520      * @exception IndexOutOfBoundsException if copying would cause access of data outside array
 521      *                bounds
 522      */
 523     native void writeDebugOutput(byte[] bytes, int offset, int length);
 524 
 525     /**
 526      * Flush HotSpot's log stream.
 527      */
 528     native void flushDebugOutput();
 529 
 530     /**
 531      * Read a HotSpot Method* value from the memory location described by {@code base} plus
 532      * {@code displacement} and return the {@link HotSpotResolvedJavaMethodImpl} wrapping it. This


< prev index next >