changeset 22420:e3d9e0f9b50c

cleaned up and added more javadoc to CompilerToVM (JDK-8133194)
author Doug Simon <doug.simon@oracle.com>
date Wed, 12 Aug 2015 17:46:38 +0200
parents c06f5d0a3395
children 2b9729c833ab
files jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/InstalledCode.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVMImpl.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotNmethod.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java src/share/vm/jvmci/jvmciCompilerToVM.cpp
diffstat 8 files changed, 264 insertions(+), 175 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/InstalledCode.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.code/src/jdk/internal/jvmci/code/InstalledCode.java	Wed Aug 12 17:46:38 2015 +0200
@@ -101,7 +101,8 @@
     }
 
     /**
-     * Invalidates this installed code such that any subsequent invocation will throw an
+     * Invalidates this installed code such that any subsequent
+     * {@linkplain #executeVarargs(Object...) invocation} will throw an
      * {@link InvalidInstalledCodeException}.
      */
     public void invalidate() {
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java	Wed Aug 12 17:46:38 2015 +0200
@@ -23,36 +23,37 @@
 
 package jdk.internal.jvmci.hotspot;
 
+import java.lang.reflect.*;
+
 import jdk.internal.jvmci.code.*;
 import jdk.internal.jvmci.hotspotvmconfig.*;
 import jdk.internal.jvmci.meta.*;
 import sun.misc.*;
 
 /**
- * Calls from Java into HotSpot.
+ * Calls from Java into HotSpot. The behavior of all the methods in this class that take a metaspace
+ * pointer as an argument (e.g., {@link #getExceptionTableStart(long)}) is undefined if the argument
+ * does not denote a valid metaspace object.
  */
 public interface CompilerToVM {
 
     /**
-     * Copies the original bytecode of a given method into a new byte array and returns it.
+     * Copies the original bytecode of {@code metaspaceMethod} into a new byte array and returns it.
      *
-     * @param metaspaceMethod the metaspace Method object
-     * @return a new byte array containing the original bytecode
+     * @return a new byte array containing the original bytecode of {@code metaspaceMethod}
      */
     byte[] getBytecode(long metaspaceMethod);
 
     /**
-     * Gets the number of entries in the data structure describing the exception handlers for a
-     * given method.
-     *
-     * @param metaspaceMethod the metaspace Method object
-     * @return the number of entries in the exception handler table for {@code metaspaceMethod}
+     * Gets the number of entries in {@code metaspaceMethod}'s exception handler table or 0 if it
+     * has not exception handler table.
      */
     int getExceptionTableLength(long metaspaceMethod);
 
     /**
-     * Gets the address of the first entry in the exception handler table for a given method. Each
-     * entry is a {@code ExceptionTableElement} native object and is described by these fields:
+     * Gets the address of the first entry in {@code metaspaceMethod}'s exception handler table.
+     *
+     * Each entry is a native object described by these fields:
      *
      * <ul>
      * <li>{@link HotSpotVMConfig#exceptionTableElementSize}</li>
@@ -62,51 +63,40 @@
      * <li>{@link HotSpotVMConfig#exceptionTableElementCatchTypeIndexOffset}
      * </ul>
      *
-     * The behavior of this method is undefined if {@link #getExceptionTableLength(long)} returns 0
-     * for {@code metaspaceMethod}.
-     *
-     * @param metaspaceMethod the metaspace Method object
+     * @return 0 if {@code metaspaceMethod} has no exception handlers (i.e.
+     *         {@code getExceptionTableLength(metaspaceMethod) == 0})
      */
     long getExceptionTableStart(long metaspaceMethod);
 
     /**
-     * Determines if a given metaspace Method object has balanced monitors.
-     *
-     * @param metaspaceMethod the metaspace Method object to query
-     * @return true if the method has balanced monitors
+     * Determines if {@code metaspaceMethod} has balanced monitors.
      */
     boolean hasBalancedMonitors(long metaspaceMethod);
 
     /**
-     * Determines if a given metaspace Method can be inlined. A method may not be inlinable for a
+     * Determines if {@code metaspaceMethod} can be inlined. A method may not be inlinable for a
      * number of reasons such as:
      * <ul>
      * <li>a CompileOracle directive may prevent inlining or compilation of methods</li>
      * <li>the method may have a bytecode breakpoint set</li>
      * <li>the method may have other bytecode features that require special handling by the VM</li>
      * </ul>
-     *
-     * @param metaspaceMethod the metaspace Method object to query
-     * @return true if the method can be inlined
      */
     boolean canInlineMethod(long metaspaceMethod);
 
     /**
-     * Determines if a given metaspace Method should be inlined at any cost. This could be because:
+     * Determines if {@code metaspaceMethod} should be inlined at any cost. This could be because:
      * <ul>
      * <li>a CompileOracle directive may forces inlining of this methods</li>
      * <li>an annotation forces inlining of this method</li>
      * </ul>
-     *
-     * @param metaspaceMethod the metaspace Method object to query
-     * @return true if the method should be inlined
      */
     boolean shouldInlineMethod(long metaspaceMethod);
 
     /**
      * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}.
      *
-     * @param metaspaceMethod the metaspace Method on which to based the search
+     * @param metaspaceMethod the metaspace Method on which to base the search
      * @param actualHolderMetaspaceKlass the best known type of receiver
      * @return the metaspace Method result or 0 is there is no unique concrete method for
      *         {@code metaspaceMethod}
@@ -114,20 +104,15 @@
     long findUniqueConcreteMethod(long actualHolderMetaspaceKlass, long metaspaceMethod);
 
     /**
-     * Returns the implementor for the given interface class, if there is a single implementor.
+     * Gets the implementor for the interface class {@code metaspaceKlass}.
      *
-     * @param metaspaceKlass the metaspace Klass to get the implementor for
-     * @return the implementor as metaspace Klass pointer if there is a single implementor, null if
-     *         there is no implementor, or the input metaspace Klass pointer ({@code metaspaceKlass}
-     *         ) itself if there is more than one implementor.
+     * @return the implementor if there is a single implementor, 0 if there is no implementor, or
+     *         {@code metaspaceKlass} itself if there is more than one implementor
      */
     long getKlassImplementor(long metaspaceKlass);
 
     /**
-     * Determines if a given metaspace method is ignored by security stack walks.
-     *
-     * @param metaspaceMethod the metaspace Method object
-     * @return true if the method is ignored
+     * Determines if {@code metaspaceMethod} is ignored by security stack walks.
      */
     boolean methodIsIgnoredBySecurityStackWalk(long metaspaceMethod);
 
@@ -138,99 +123,154 @@
      * @param accessingClass the context of resolution (must not be null)
      * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will
      *            either return a {@link ResolvedJavaType} or throw an exception
-     * @return a metaspace Klass for {@code name}
+     * @return the metaspace Klass for {@code name} or 0 if resolution failed and
+     *         {@code resolve == false}
      * @throws LinkageError if {@code resolve == true} and the resolution failed
      */
     long lookupType(String name, Class<?> accessingClass, boolean resolve);
 
     /**
-     * Resolves a constant pool entry at index {@code cpi} from the metaspace ConstantPool at
-     * {@code metaspaceConstantPool} to an object by calling
-     * {@code ConstantPool::resolve_constant_at}.
+     * Resolves the entry at index {@code cpi} in {@code metaspaceConstantPool} to an object.
      *
-     * @param metaspaceConstantPool address of a metaspace ConstantPool object
-     * @param cpi a constant pool index
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry that can be
+     * resolved to an object.
      */
     Object resolveConstantInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Resolves a constant pool entry at index {@code cpi} from the metaspace ConstantPool at
-     * {@code metaspaceConstantPool} to an object by calling
-     * {@code ConstantPool::resolve_possibly_cached_constant_at}.
+     * Resolves the entry at index {@code cpi} in {@code metaspaceConstantPool} to an object,
+     * looking in the constant pool cache first.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry that can be
+     * resolved to an object.
      */
     Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Gets the {@code JVM_CONSTANT_NameAndType} reference index constant pool entry at index
-     * {@code cpi} from the metaspace ConstantPool at {@code metaspaceConstantPool} by calling
-     * {@code ConstantPool::name_and_type_ref_index_at}.
+     * Gets the {@code JVM_CONSTANT_NameAndType} index from the entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
+     * {@code JVM_CONSTANT_NameAndType} index.
      */
     int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index {@code cpi}
-     * from the metaspace ConstantPool at {@code metaspaceConstantPool} by calling
-     * {@code ConstantPool::name_ref_at}.
+     * Gets the name of the {@code JVM_CONSTANT_NameAndType} entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote a
+     * {@code JVM_CONSTANT_NameAndType} entry.
      */
     String lookupNameRefInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Gets the signature of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index
-     * {@code cpi} from the metaspace ConstantPool at {@code metaspaceConstantPool} by calling
-     * {@code ConstantPool::signature_ref_at}.
+     * Gets the signature of the {@code JVM_CONSTANT_NameAndType} entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote a
+     * {@code JVM_CONSTANT_NameAndType} entry.
      */
     String lookupSignatureRefInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Gets the klass reference index constant pool entry at index {@code cpi} from the metaspace
-     * ConstantPool at {@code metaspaceConstantPool} by calling
-     * {@code ConstantPool::klass_ref_index_at}.
+     * Gets the {@code JVM_CONSTANT_Class} index from the entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
+     * {@code JVM_CONSTANT_Class} index.
      */
     int lookupKlassRefIndexInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Resolves a constant pool entry at index {@code cpi} from the metaspace ConstantPool at
-     * {@code metaspaceConstantPool} to a metaspace Klass by calling {@code ConstantPool::klass_at}.
-     */
-    long constantPoolKlassAt(long metaspaceConstantPool, int cpi);
-
-    /**
-     * Looks up a class entry in a constant pool.
+     * Looks up a class denoted by the {@code JVM_CONSTANT_Class} entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}. This method does not perform any resolution.
      *
-     * @param metaspaceConstantPool metaspace constant pool pointer
-     * @param cpi constant pool index
-     * @return a metaspace Klass for a resolved method entry, a metaspace Symbol otherwise (with
-     *         tagging)
+     * The behavior of this method is undefined if {@code cpi} does not denote a
+     * {@code JVM_CONSTANT_Class} entry.
+     *
+     * @return a metaspace Klass for a resolved class entry (tagged by
+     *         {@link HotSpotVMConfig#compilerToVMKlassTag}) or a metaspace Symbol otherwise (tagged
+     *         by {@link HotSpotVMConfig#compilerToVMSymbolTag})
      */
     long lookupKlassInPool(long metaspaceConstantPool, int cpi);
 
     /**
-     * Looks up a method entry in a constant pool.
+     * Looks up a method denoted by the entry at index {@code cpi} in {@code metaspaceConstantPool}.
+     * This method does not perform any resolution.
      *
-     * @param metaspaceConstantPool metaspace constant pool pointer
-     * @param cpi constant pool index
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
+     * a method.
+     *
+     * @param opcode the opcode of the instruction for which the lookup is being performed or
+     *            {@code -1}. If non-negative, then resolution checks specific to the bytecode it
+     *            denotes are performed if the method is already resolved. Should any of these
+     *            checks fail, 0 is returned.
      * @return a metaspace Method for a resolved method entry, 0 otherwise
      */
     long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
     /**
-     * Looks up a field entry in a constant pool and attempts to resolve it. The values returned in
-     * {@code info} are:
+     * Ensures that the type referenced by the specified {@code JVM_CONSTANT_InvokeDynamic} entry at
+     * index {@code cpi} in {@code metaspaceConstantPool} is loaded and initialized.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote a
+     * {@code JVM_CONSTANT_InvokeDynamic} entry.
+     */
+    void resolveInvokeDynamicInPool(long metaspaceConstantPool, int cpi);
+
+    /**
+     * Ensures that the type referenced by the entry for a <a
+     * href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.9">signature
+     * polymorphic</a> method at index {@code cpi} in {@code metaspaceConstantPool} is loaded and
+     * initialized.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
+     * a signature polymorphic method.
+     */
+    void resolveInvokeHandleInPool(long metaspaceConstantPool, int cpi);
+
+    /**
+     * Gets the resolved metaspace Klass denoted by the entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}.
+     *
+     * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
+     * a class.
+     *
+     * @throws LinkageError if resolution failed
+     */
+    long resolveKlassInPool(long metaspaceConstantPool, int cpi) throws LinkageError;
+
+    /**
+     * Looks up and attempts to resolve the {@code JVM_CONSTANT_Field} entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}. The values returned in {@code info} are:
      *
      * <pre>
      *     [(int) flags,   // only valid if field is resolved
      *      (int) offset]  // only valid if field is resolved
      * </pre>
      *
-     * @param metaspaceConstantPool metaspace constant pool pointer
-     * @param cpi constant pool index
+     * The behavior of this method is undefined if {@code cpi} does not denote a
+     * {@code JVM_CONSTANT_Field} entry.
+     *
      * @param info an array in which the details of the field are returned
-     * @return true if the field is resolved
+     * @return the metaspace Klass defining the field if resolution is successful, 0 otherwise
      */
-    long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info);
+    long resolveFieldInPool(long metaspaceConstantPool, int cpi, byte opcode, long[] info);
 
-    int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi);
+    /**
+     * Converts {@code cpci} from an index into the cache for {@code metaspaceConstantPool} to an
+     * index directly into {@code metaspaceConstantPool}.
+     *
+     * The behavior of this method is undefined if {@code ccpi} is an invalid constant pool cache
+     * index.
+     */
+    int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpci);
 
+    /**
+     * Gets the appendix object (if any) associated with the entry at index {@code cpi} in
+     * {@code metaspaceConstantPool}.
+     */
     Object lookupAppendixInPool(long metaspaceConstantPool, int cpi);
 
     /**
@@ -261,48 +301,116 @@
      */
     void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, InstalledCode installedCode);
 
+    /**
+     * Resets all compilation statistics.
+     */
     void resetCompilationStatistics();
 
+    /**
+     * Initializes the fields of {@code config}.
+     */
     void initializeConfiguration(HotSpotVMConfig config);
 
+    /**
+     * Resolves the implementation of {@code metaspaceMethod} for virtual dispatches on objects of
+     * dynamic type {@code metaspaceKlassExactReceiver}. This resolution process only searches "up"
+     * the class hierarchy of {@code metaspaceKlassExactReceiver}.
+     *
+     * @param metaspaceKlassCaller the caller or context type used to perform access checks
+     * @return the link-time resolved method (might be abstract) or {@code 0} if it can not be
+     *         linked
+     */
     long resolveMethod(long metaspaceKlassExactReceiver, long metaspaceMethod, long metaspaceKlassCaller);
 
+    /**
+     * Gets the static initializer of {@code metaspaceKlass}.
+     *
+     * @return 0 if {@code metaspaceKlass} has no static initialize
+     */
     long getClassInitializer(long metaspaceKlass);
 
+    /**
+     * Determines if {@code metaspaceKlass} or any of its currently loaded subclasses overrides
+     * {@code Object.finalize()}.
+     */
     boolean hasFinalizableSubclass(long metaspaceKlass);
 
     /**
-     * Gets the metaspace Method object corresponding to a given {@link Class} object and slot
-     * number.
-     *
-     * @param holder method holder
-     * @param slot slot number of the method
-     * @return the metaspace Method
+     * Gets the metaspace Method corresponding to {@code holder} and slot number {@code slot} (i.e.
+     * {@link Method#slot} or {@link Constructor#slot}).
      */
+    @SuppressWarnings("javadoc")
     long getMetaspaceMethod(Class<?> holder, int slot);
 
+    /**
+     * Gets the maximum absolute offset of a PC relative call to {@code address} from any position
+     * in the code cache.
+     *
+     * @param address an address that may be called from any code in the code cache
+     * @return -1 if {@code address == 0}
+     */
     long getMaxCallTargetOffset(long address);
 
+    /**
+     * Gets a textual disassembly of {@code codeBlob}.
+     *
+     * @return a non-zero length string containing a disassembly of {@code codeBlob} or null if
+     *         {@code codeBlob} could not be disassembled for some reason
+     */
     String disassembleCodeBlob(long codeBlob);
 
+    /**
+     * Gets a stack trace element for {@code metaspaceMethod} at bytecode index {@code bci}.
+     */
     StackTraceElement getStackTraceElement(long metaspaceMethod, int bci);
 
-    Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException;
+    /**
+     * Executes some {@code installedCode} with arguments {@code args}.
+     *
+     * @return the result of executing {@code installedCode}
+     * @throws InvalidInstalledCodeException if {@code installedCode} has been invalidated
+     */
+    Object executeInstalledCode(Object[] args, InstalledCode installedCode) throws InvalidInstalledCodeException;
 
-    Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException;
-
+    /**
+     * Gets the line number table for {@code metaspaceMethod}. The line number table is encoded as
+     * (bci, source line number) pairs.
+     *
+     * @return the line number table for {@code metaspaceMethod} or null if it doesn't have one
+     */
     long[] getLineNumberTable(long metaspaceMethod);
 
+    /**
+     * Gets the number of entries in the local variable table for {@code metaspaceMethod}.
+     *
+     * @return the number of entries in the local variable table for {@code metaspaceMethod}
+     */
+    int getLocalVariableTableLength(long metaspaceMethod);
+
+    /**
+     * Gets the address of the first entry in the local variable table for {@code metaspaceMethod}.
+     *
+     * Each entry is a native object described by these fields:
+     *
+     * <ul>
+     * <li>{@link HotSpotVMConfig#localVariableTableElementSize}</li>
+     * <li>{@link HotSpotVMConfig#localVariableTableElementLengthOffset}</li>
+     * <li>{@link HotSpotVMConfig#localVariableTableElementNameCpIndexOffset}</li>
+     * <li>{@link HotSpotVMConfig#localVariableTableElementDescriptorCpIndexOffset}</li>
+     * <li>{@link HotSpotVMConfig#localVariableTableElementSignatureCpIndexOffset}
+     * <li>{@link HotSpotVMConfig#localVariableTableElementSlotOffset}
+     * <li>{@link HotSpotVMConfig#localVariableTableElementStartBciOffset}
+     * </ul>
+     *
+     * @return 0 if {@code metaspaceMethod} does not have a local variable table
+     */
     long getLocalVariableTableStart(long metaspaceMethod);
 
-    int getLocalVariableTableLength(long metaspaceMethod);
-
-    String getFileName(HotSpotResolvedJavaType method);
-
+    /**
+     * Gets the {@link Class} mirror associated with {@code metaspaceKlass}.
+     */
     Class<?> getJavaMirror(long metaspaceKlass);
 
-    long readUnsafeKlassPointer(Object o);
-
     /**
      * Reads an object pointer within a VM data structure. That is, any {@link HotSpotVMField} whose
      * {@link HotSpotVMField#type() type} is {@code "oop"} (e.g.,
@@ -317,22 +425,31 @@
      */
     Object readUncompressedOop(long address);
 
+    /**
+     * Determines if {@code metaspaceMethod} should not be inlined or compiled.
+     */
     void doNotInlineOrCompile(long metaspaceMethod);
 
     /**
-     * Invalidates the profiling information and restarts profiling upon the next invocation.
-     *
-     * @param metaspaceMethod the metaspace Method object
+     * Invalidates the profiling information for {@code metaspaceMethod} and (re)initializes it such
+     * that profiling restarts upon its next invocation.
      */
     void reprofile(long metaspaceMethod);
 
-    void invalidateInstalledCode(InstalledCode hotspotInstalledCode);
+    /**
+     * Invalidates {@code installedCode} such that {@link InvalidInstalledCodeException} will be
+     * raised the next time {@code installedCode} is executed.
+     */
+    void invalidateInstalledCode(InstalledCode installedCode);
 
     /**
      * Collects the current values of all JVMCI benchmark counters, summed up over all threads.
      */
     long[] collectCounters();
 
+    /**
+     * Determines if {@code metaspaceMethodData} is mature.
+     */
     boolean isMature(long metaspaceMethodData);
 
     /**
@@ -348,16 +465,13 @@
     String getGPUs();
 
     /**
-     *
-     * @param metaspaceMethod the method to check
-     * @param entryBCI
-     * @param level the compilation level
-     * @return true if the {@code metaspaceMethod} has code for {@code level}
+     * Determines if {@code metaspaceMethod} has OSR compiled code identified by {@code entryBCI}
+     * for compilation level {@code level}.
      */
     boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level);
 
     /**
-     * Fetch the time stamp used for printing inside hotspot. It's relative to VM start to that all
+     * Fetch the time stamp used for printing inside hotspot. It's relative to VM start so that all
      * events can be ordered.
      *
      * @return milliseconds since VM start
@@ -365,14 +479,12 @@
     long getTimeStamp();
 
     /**
-     * Gets the value of a metaspace {@code Symbol} as a String.
-     *
-     * @param metaspaceSymbol
+     * Gets the value of {@code metaspaceSymbol} as a String.
      */
     String getSymbol(long metaspaceSymbol);
 
     /**
-     * Looks for the next Java stack frame with the given method.
+     * Looks for the next Java stack frame matching an entry in {@code methods}.
      *
      * @param frame the starting point of the search, where {@code null} refers to the topmost frame
      * @param methods the metaspace methods to look for, where {@code null} means that any frame is
@@ -382,23 +494,33 @@
     HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip);
 
     /**
-     * Materialized all virtual objects within the given stack frame and update the locals within
-     * the given stackFrame object.
+     * Materializes all virtual objects within {@code stackFrame} updates its locals.
      *
      * @param invalidate if {@code true}, the compiled method for the stack frame will be
      *            invalidated.
      */
     void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
 
-    void resolveInvokeDynamic(long metaspaceConstantPool, int index);
-
-    void resolveInvokeHandle(long metaspaceConstantPool, int index);
-
+    /**
+     * Gets the v-table index for interface method {@code metaspaceMethod} in the receiver type
+     * {@code metaspaceKlass} or {@link HotSpotVMConfig#invalidVtableIndex} if
+     * {@code metaspaceMethod} is not in {@code metaspaceKlass}'s v-table.
+     */
     int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod);
 
+    /**
+     * Determines if debug info should also be emitted at non-safepoint locations.
+     */
     boolean shouldDebugNonSafepoints();
 
+    /**
+     * Writes {@code length} bytes from {@code buf} starting at offset {@code offset} to the
+     * HotSpot's log stream. No range checking is performed.
+     */
     void writeDebugOutput(byte[] bytes, int offset, int length);
 
+    /**
+     * Flush HotSpot's log stream.
+     */
     void flushDebugOutput();
 }
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVMImpl.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVMImpl.java	Wed Aug 12 17:46:38 2015 +0200
@@ -108,7 +108,7 @@
 
     private native int lookupKlassRefIndexInPool0(long metaspaceConstantPool, int cpi);
 
-    public native long constantPoolKlassAt(long metaspaceConstantPool, int cpi);
+    public native long resolveKlassInPool(long metaspaceConstantPool, int cpi);
 
     @Override
     public native long lookupKlassInPool(long metaspaceConstantPool, int cpi);
@@ -117,7 +117,7 @@
     public native long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
     @Override
-    public native long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info);
+    public native long resolveFieldInPool(long metaspaceConstantPool, int cpi, byte opcode, long[] info);
 
     public int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi) {
         JVMCIError.guarantee(!HotSpotConstantPool.Options.UseConstantPoolCacheJavaCode.getValue(), "");
@@ -159,7 +159,7 @@
     public native StackTraceElement getStackTraceElement(long metaspaceMethod, int bci);
 
     @Override
-    public native Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode);
+    public native Object executeInstalledCode(Object[] args, InstalledCode hotspotInstalledCode);
 
     @Override
     public native long[] getLineNumberTable(long metaspaceMethod);
@@ -171,9 +171,6 @@
     public native int getLocalVariableTableLength(long metaspaceMethod);
 
     @Override
-    public native String getFileName(HotSpotResolvedJavaType method);
-
-    @Override
     public native void reprofile(long metaspaceMethod);
 
     @Override
@@ -183,19 +180,11 @@
     public native Class<?> getJavaMirror(long metaspaceKlass);
 
     @Override
-    public native long readUnsafeKlassPointer(Object o);
-
-    @Override
     public native Object readUncompressedOop(long address);
 
     @Override
     public native void doNotInlineOrCompile(long metaspaceMethod);
 
-    @Override
-    public Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException {
-        return executeCompiledMethodVarargs(new Object[]{arg1, arg2, arg3}, hotspotInstalledCode);
-    }
-
     public synchronized native void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond,
                     InstalledCode installedCode);
 
@@ -230,9 +219,9 @@
 
     private native String getSymbol0(long metaspaceSymbol);
 
-    public native void resolveInvokeDynamic(long metaspaceConstantPool, int index);
+    public native void resolveInvokeDynamicInPool(long metaspaceConstantPool, int index);
 
-    public native void resolveInvokeHandle(long metaspaceConstantPool, int index);
+    public native void resolveInvokeHandleInPool(long metaspaceConstantPool, int index);
 
     public native int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod);
 
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java	Wed Aug 12 17:46:38 2015 +0200
@@ -915,7 +915,7 @@
             long[] info = new long[2];
             long metaspaceKlass;
             try {
-                metaspaceKlass = runtime().getCompilerToVM().resolveField(metaspaceConstantPool, index, (byte) opcode, info);
+                metaspaceKlass = runtime().getCompilerToVM().resolveFieldInPool(metaspaceConstantPool, index, (byte) opcode, info);
             } catch (Throwable t) {
                 /*
                  * If there was an exception resolving the field we give up and return an unresolved
@@ -1004,7 +1004,7 @@
             case Class:
             case UnresolvedClass:
             case UnresolvedClassInError:
-                final long metaspaceKlass = runtime().getCompilerToVM().constantPoolKlassAt(metaspaceConstantPool, index);
+                final long metaspaceKlass = runtime().getCompilerToVM().resolveKlassInPool(metaspaceConstantPool, index);
                 HotSpotResolvedObjectTypeImpl type = HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(metaspaceKlass);
                 Class<?> klass = type.mirror();
                 if (!klass.isPrimitive() && !klass.isArray()) {
@@ -1015,14 +1015,14 @@
                         if (Bytecodes.isInvokeHandleAlias(opcode)) {
                             final int methodRefCacheIndex = rawIndexToConstantPoolIndex(cpi, opcode);
                             if (isInvokeHandle(methodRefCacheIndex, type)) {
-                                runtime().getCompilerToVM().resolveInvokeHandle(metaspaceConstantPool, methodRefCacheIndex);
+                                runtime().getCompilerToVM().resolveInvokeHandleInPool(metaspaceConstantPool, methodRefCacheIndex);
                             }
                         }
                 }
                 break;
             case InvokeDynamic:
                 if (isInvokedynamicIndex(cpi)) {
-                    runtime().getCompilerToVM().resolveInvokeDynamic(metaspaceConstantPool, cpi);
+                    runtime().getCompilerToVM().resolveInvokeDynamicInPool(metaspaceConstantPool, cpi);
                 }
                 break;
             default:
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java	Wed Aug 12 17:46:38 2015 +0200
@@ -22,7 +22,6 @@
  */
 package jdk.internal.jvmci.hotspot;
 
-import static jdk.internal.jvmci.common.UnsafeAccess.*;
 import static jdk.internal.jvmci.inittimer.InitTimer.*;
 
 import java.util.*;
@@ -150,23 +149,6 @@
         return instance.getHostJVMCIBackend().getCodeCache().getTarget().wordKind;
     }
 
-    /**
-     * Reads a klass pointer from a constant object.
-     */
-    public static long unsafeReadKlassPointer(Object object) {
-        return instance.getCompilerToVM().readUnsafeKlassPointer(object);
-    }
-
-    /**
-     * Reads a word value from a given object.
-     */
-    public static long unsafeReadWord(Object object, long offset) {
-        if (getHostWordKind() == Kind.Long) {
-            return unsafe.getLong(object, offset);
-        }
-        return unsafe.getInt(object, offset) & 0xFFFFFFFFL;
-    }
-
     protected/* final */CompilerToVM compilerToVm;
 
     protected final HotSpotVMConfig config;
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotNmethod.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotNmethod.java	Wed Aug 12 17:46:38 2015 +0200
@@ -105,7 +105,7 @@
     public Object executeVarargs(Object... args) throws InvalidInstalledCodeException {
         assert checkArgs(args);
         assert !isExternal();
-        return runtime().getCompilerToVM().executeCompiledMethodVarargs(args, this);
+        return runtime().getCompilerToVM().executeInstalledCode(args, this);
     }
 
     @Override
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java	Wed Aug 12 12:11:33 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotResolvedJavaMethodImpl.java	Wed Aug 12 17:46:38 2015 +0200
@@ -554,7 +554,7 @@
         }
 
         long[] values = runtime().getCompilerToVM().getLineNumberTable(metaspaceMethod);
-        if (values.length == 0) {
+        if (values == null || values.length == 0) {
             // Empty table so treat is as non-existent
             return null;
         }
--- a/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Wed Aug 12 12:11:33 2015 +0200
+++ b/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Wed Aug 12 17:46:38 2015 +0200
@@ -166,7 +166,9 @@
 C2V_VMENTRY(jlong, getExceptionTableStart, (JNIEnv *, jobject, jlong metaspace_method))
   ResourceMark rm;
   methodHandle method = asMethod(metaspace_method);
-  assert(method->exception_table_length() != 0, "should be handled in Java code");
+  if (method->exception_table_length() == 0) {
+    return 0L;
+  }
   return (jlong) (address) method->exception_table_start();
 C2V_END
 
@@ -311,7 +313,7 @@
   return cp->klass_ref_index_at(index);
 C2V_END
 
-C2V_VMENTRY(jlong, constantPoolKlassAt, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index))
+C2V_VMENTRY(jlong, resolveKlassInPool, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index))
   ConstantPool* cp = (ConstantPool*) metaspace_constant_pool;
   return (jlong) (address) cp->klass_at(index, THREAD);
 C2V_END
@@ -359,7 +361,7 @@
   return cp->remap_instruction_operand_from_cache(index);
 C2V_END
 
-C2V_VMENTRY(jlong, resolveField, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index, jbyte opcode, jlongArray info_handle))
+C2V_VMENTRY(jlong, resolveFieldInPool, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index, jbyte opcode, jlongArray info_handle))
   ResourceMark rm;
   constantPoolHandle cp = (ConstantPool*) metaspace_constant_pool;
   Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
@@ -592,7 +594,7 @@
   return JNIHandles::make_local(THREAD, element);
 C2V_END
 
-C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv*, jobject, jobject args, jobject hotspotInstalledCode))
+C2V_VMENTRY(jobject, executeInstalledCode, (JNIEnv*, jobject, jobject args, jobject hotspotInstalledCode))
   ResourceMark rm;
   HandleMark hm;
 
@@ -718,12 +720,6 @@
   return JNIHandles::make_local(THREAD, klass->java_mirror());
 C2V_END
 
-C2V_VMENTRY(jlong, readUnsafeKlassPointer, (JNIEnv*, jobject, jobject o))
-  oop resolved_o = JNIHandles::resolve(o);
-  jlong klass = (jlong)(address)resolved_o->klass();
-  return klass;
-C2V_END
-
 C2V_VMENTRY(jobject, readUncompressedOop, (JNIEnv*, jobject, jlong addr))
   oop ret = oopDesc::load_decode_heap_oop((oop*)(address)addr);
   return JNIHandles::make_local(THREAD, ret);
@@ -908,7 +904,7 @@
   return NULL;
 C2V_END
 
-C2V_VMENTRY(void, resolveInvokeDynamic, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index))
+C2V_VMENTRY(void, resolveInvokeDynamicInPool, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index))
   ConstantPool* cp = (ConstantPool*)metaspace_constant_pool;
   CallInfo callInfo;
   LinkResolver::resolve_invokedynamic(callInfo, cp, index, CHECK);
@@ -916,7 +912,7 @@
   cp_cache_entry->set_dynamic_call(cp, callInfo);
 C2V_END
 
-C2V_VMENTRY(void, resolveInvokeHandle, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index))
+C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv*, jobject, jlong metaspace_constant_pool, jint index))
   ConstantPool* cp = (ConstantPool*)metaspace_constant_pool;
   CallInfo callInfo;
   LinkResolver::resolve_invokehandle(callInfo, cp, index, CHECK);
@@ -1068,20 +1064,20 @@
   {CC"canInlineMethod",                              CC"("METASPACE_METHOD")Z",                                                FN_PTR(canInlineMethod)},
   {CC"shouldInlineMethod",                           CC"("METASPACE_METHOD")Z",                                                FN_PTR(shouldInlineMethod)},
   {CC"lookupType",                                   CC"("STRING CLASS"Z)"METASPACE_KLASS,                                     FN_PTR(lookupType)},
-  {CC"resolveConstantInPool",                        CC"("METASPACE_CONSTANT_POOL"I)"OBJECT,                                   FN_PTR(resolveConstantInPool)},
-  {CC"resolvePossiblyCachedConstantInPool0",         CC"("METASPACE_CONSTANT_POOL"I)"OBJECT,                                   FN_PTR(resolvePossiblyCachedConstantInPool)},
   {CC"lookupNameRefInPool0",                         CC"("METASPACE_CONSTANT_POOL"I)"STRING,                                   FN_PTR(lookupNameRefInPool)},
   {CC"lookupNameAndTypeRefIndexInPool",              CC"("METASPACE_CONSTANT_POOL"I)I",                                        FN_PTR(lookupNameAndTypeRefIndexInPool)},
   {CC"lookupSignatureRefInPool0",                    CC"("METASPACE_CONSTANT_POOL"I)"STRING,                                   FN_PTR(lookupSignatureRefInPool)},
   {CC"lookupKlassRefIndexInPool0",                   CC"("METASPACE_CONSTANT_POOL"I)I",                                        FN_PTR(lookupKlassRefIndexInPool)},
-  {CC"constantPoolKlassAt",                          CC"("METASPACE_CONSTANT_POOL"I)"METASPACE_KLASS,                          FN_PTR(constantPoolKlassAt)},
   {CC"lookupKlassInPool",                            CC"("METASPACE_CONSTANT_POOL"I)"METASPACE_KLASS,                          FN_PTR(lookupKlassInPool)},
   {CC"lookupAppendixInPool0",                        CC"("METASPACE_CONSTANT_POOL"I)"OBJECT,                                   FN_PTR(lookupAppendixInPool)},
   {CC"lookupMethodInPool",                           CC"("METASPACE_CONSTANT_POOL"IB)"METASPACE_METHOD,                        FN_PTR(lookupMethodInPool)},
   {CC"constantPoolRemapInstructionOperandFromCache0",CC"("METASPACE_CONSTANT_POOL"I)I",                                        FN_PTR(constantPoolRemapInstructionOperandFromCache)},
-  {CC"resolveField",                                 CC"("METASPACE_CONSTANT_POOL"IB[J)"METASPACE_KLASS,                       FN_PTR(resolveField)},
-  {CC"resolveInvokeDynamic",                         CC"("METASPACE_CONSTANT_POOL"I)V",                                        FN_PTR(resolveInvokeDynamic)},
-  {CC"resolveInvokeHandle",                          CC"("METASPACE_CONSTANT_POOL"I)V",                                        FN_PTR(resolveInvokeHandle)},
+  {CC"resolveConstantInPool",                        CC"("METASPACE_CONSTANT_POOL"I)"OBJECT,                                   FN_PTR(resolveConstantInPool)},
+  {CC"resolvePossiblyCachedConstantInPool0",         CC"("METASPACE_CONSTANT_POOL"I)"OBJECT,                                   FN_PTR(resolvePossiblyCachedConstantInPool)},
+  {CC"resolveKlassInPool",                           CC"("METASPACE_CONSTANT_POOL"I)"METASPACE_KLASS,                          FN_PTR(resolveKlassInPool)},
+  {CC"resolveFieldInPool",                           CC"("METASPACE_CONSTANT_POOL"IB[J)"METASPACE_KLASS,                       FN_PTR(resolveFieldInPool)},
+  {CC"resolveInvokeDynamicInPool",                   CC"("METASPACE_CONSTANT_POOL"I)V",                                        FN_PTR(resolveInvokeDynamicInPool)},
+  {CC"resolveInvokeHandleInPool",                    CC"("METASPACE_CONSTANT_POOL"I)V",                                        FN_PTR(resolveInvokeHandleInPool)},
   {CC"resolveMethod",                                CC"("METASPACE_KLASS METASPACE_METHOD METASPACE_KLASS")"METASPACE_METHOD, FN_PTR(resolveMethod)},
   {CC"getVtableIndexForInterface",                   CC"("METASPACE_KLASS METASPACE_METHOD")I",                                FN_PTR(getVtableIndexForInterface)},
   {CC"getClassInitializer",                          CC"("METASPACE_KLASS")"METASPACE_METHOD,                                  FN_PTR(getClassInitializer)},
@@ -1093,14 +1089,13 @@
   {CC"notifyCompilationStatistics",                  CC"(I"HS_RESOLVED_METHOD"ZIJJ"INSTALLED_CODE")V",                         FN_PTR(notifyCompilationStatistics)},
   {CC"resetCompilationStatistics",                   CC"()V",                                                                  FN_PTR(resetCompilationStatistics)},
   {CC"disassembleCodeBlob",                          CC"(J)"STRING,                                                            FN_PTR(disassembleCodeBlob)},
-  {CC"executeCompiledMethodVarargs",                 CC"(["OBJECT INSTALLED_CODE")"OBJECT,                                     FN_PTR(executeCompiledMethodVarargs)},
+  {CC"executeInstalledCode",                         CC"(["OBJECT INSTALLED_CODE")"OBJECT,                                     FN_PTR(executeInstalledCode)},
   {CC"getLineNumberTable",                           CC"("METASPACE_METHOD")[J",                                               FN_PTR(getLineNumberTable)},
   {CC"getLocalVariableTableStart",                   CC"("METASPACE_METHOD")J",                                                FN_PTR(getLocalVariableTableStart)},
   {CC"getLocalVariableTableLength",                  CC"("METASPACE_METHOD")I",                                                FN_PTR(getLocalVariableTableLength)},
   {CC"reprofile",                                    CC"("METASPACE_METHOD")V",                                                FN_PTR(reprofile)},
   {CC"invalidateInstalledCode",                      CC"("INSTALLED_CODE")V",                                                  FN_PTR(invalidateInstalledCode)},
   {CC"getJavaMirror",                                CC"("METASPACE_KLASS")"CLASS,                                             FN_PTR(getJavaMirror)},
-  {CC"readUnsafeKlassPointer",                       CC"("OBJECT")J",                                                          FN_PTR(readUnsafeKlassPointer)},
   {CC"readUncompressedOop",                          CC"(J)"OBJECT,                                                            FN_PTR(readUncompressedOop)},
   {CC"collectCounters",                              CC"()[J",                                                                 FN_PTR(collectCounters)},
   {CC"allocateCompileId",                            CC"("METASPACE_METHOD"I)I",                                               FN_PTR(allocateCompileId)},