< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java

Print this page




 869     }
 870 
 871     /**
 872      * Returns the return type of a function specialization for particular parameter types.<br>
 873      * <b>Be aware that the way this is implemented, it forces full materialization (compilation and installation) of
 874      * code for that specialization.</b>
 875      * @param callSiteType the parameter types at the call site. It must include the mandatory {@code callee} and
 876      * {@code this} parameters, so it needs to start with at least {@code ScriptFunction.class} and
 877      * {@code Object.class} class. Since the return type of the function is calculated from the code itself, it is
 878      * irrelevant and should be set to {@code Object.class}.
 879      * @param runtimeScope a current runtime scope. Can be null but when it's present it will be used as a source of
 880      * current runtime values that can improve the compiler's type speculations (and thus reduce the need for later
 881      * recompilations) if the specialization is not already present and thus needs to be freshly compiled.
 882      * @return the return type of the function specialization.
 883      */
 884     public Class<?> getReturnType(final MethodType callSiteType, final ScriptObject runtimeScope) {
 885         return getBest(callSiteType, runtimeScope, CompiledFunction.NO_FUNCTIONS).type().returnType();
 886     }
 887 
 888     @Override
 889     synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) {
 890         assert isValidCallSite(callSiteType) : callSiteType;
 891 
 892         CompiledFunction existingBest = pickFunction(callSiteType, false);
 893         if (existingBest == null) {
 894             existingBest = pickFunction(callSiteType, true); // try vararg last
 895         }
 896         if (existingBest == null) {
 897             existingBest = addCode(compileTypeSpecialization(callSiteType, runtimeScope, true), callSiteType);
 898         }
 899 
 900         assert existingBest != null;
 901 
 902         //if the best one is an apply to call, it has to match the callsite exactly
 903         //or we need to regenerate
 904         if (existingBest.isApplyToCall()) {
 905             final CompiledFunction best = lookupExactApplyToCall(callSiteType);
 906             if (best != null) {
 907                 return best;
 908             }
 909 




 869     }
 870 
 871     /**
 872      * Returns the return type of a function specialization for particular parameter types.<br>
 873      * <b>Be aware that the way this is implemented, it forces full materialization (compilation and installation) of
 874      * code for that specialization.</b>
 875      * @param callSiteType the parameter types at the call site. It must include the mandatory {@code callee} and
 876      * {@code this} parameters, so it needs to start with at least {@code ScriptFunction.class} and
 877      * {@code Object.class} class. Since the return type of the function is calculated from the code itself, it is
 878      * irrelevant and should be set to {@code Object.class}.
 879      * @param runtimeScope a current runtime scope. Can be null but when it's present it will be used as a source of
 880      * current runtime values that can improve the compiler's type speculations (and thus reduce the need for later
 881      * recompilations) if the specialization is not already present and thus needs to be freshly compiled.
 882      * @return the return type of the function specialization.
 883      */
 884     public Class<?> getReturnType(final MethodType callSiteType, final ScriptObject runtimeScope) {
 885         return getBest(callSiteType, runtimeScope, CompiledFunction.NO_FUNCTIONS).type().returnType();
 886     }
 887 
 888     @Override
 889     synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, final boolean linkLogicOkay) {
 890         assert isValidCallSite(callSiteType) : callSiteType;
 891 
 892         CompiledFunction existingBest = pickFunction(callSiteType, false);
 893         if (existingBest == null) {
 894             existingBest = pickFunction(callSiteType, true); // try vararg last
 895         }
 896         if (existingBest == null) {
 897             existingBest = addCode(compileTypeSpecialization(callSiteType, runtimeScope, true), callSiteType);
 898         }
 899 
 900         assert existingBest != null;
 901 
 902         //if the best one is an apply to call, it has to match the callsite exactly
 903         //or we need to regenerate
 904         if (existingBest.isApplyToCall()) {
 905             final CompiledFunction best = lookupExactApplyToCall(callSiteType);
 906             if (best != null) {
 907                 return best;
 908             }
 909 


< prev index next >