< prev index next >

src/jdk/nashorn/internal/codegen/ApplySpecialization.java

Print this page
rev 1494 : 8134731: Function.prototype.apply interacts incorrectly with arguments
Reviewed-by: attila, hannesw


 266             return newCallNode;
 267         }
 268 
 269         return callNode;
 270     }
 271 
 272     private void pushExplodedArgs(final FunctionNode functionNode) {
 273         int start = 0;
 274 
 275         final MethodType actualCallSiteType = compiler.getCallSiteType(functionNode);
 276         if (actualCallSiteType == null) {
 277             throw new TransformFailedException(lc.getCurrentFunction(), "No callsite type");
 278         }
 279         assert actualCallSiteType.parameterType(actualCallSiteType.parameterCount() - 1) != Object[].class : "error vararg callsite passed to apply2call " + functionNode.getName() + " " + actualCallSiteType;
 280 
 281         final TypeMap ptm = compiler.getTypeMap();
 282         if (ptm.needsCallee()) {
 283             start++;
 284         }
 285 
 286         start++; //we always uses this
 287 
 288         final List<IdentNode> params    = functionNode.getParameters();
 289         final List<IdentNode> newParams = new ArrayList<>();
 290         final long to = Math.max(params.size(), actualCallSiteType.parameterCount() - start);
 291         for (int i = 0; i < to; i++) {
 292             if (i >= params.size()) {
 293                 newParams.add(new IdentNode(functionNode.getToken(), functionNode.getFinish(), EXPLODED_ARGUMENT_PREFIX.symbolName() + (i)));
 294             } else {
 295                 newParams.add(params.get(i));
 296             }
 297         }
 298 
 299         callSiteTypes.push(actualCallSiteType);
 300         explodedArguments.push(newParams);
 301     }
 302 
 303     @Override
 304     public boolean enterFunctionNode(final FunctionNode functionNode) {
 305         if (!USE_APPLY2CALL) {
 306             return false;
 307         }
 308 
 309         if (!Global.isBuiltinFunctionPrototypeApply()) {
 310             log.fine("Apply transform disabled: apply/call overridden");
 311             assert !Global.isBuiltinFunctionPrototypeCall() : "call and apply should have the same SwitchPoint";
 312             return false;
 313         }
 314 
 315         if (!compiler.isOnDemandCompilation()) {




 316             return false;
 317         }
 318 
 319         if (functionNode.hasEval()) {
 320             return false;
 321         }
 322 
 323         if (!hasApplies(functionNode)) {
 324             return false;
 325         }
 326 
 327         if (log.isEnabled()) {
 328             log.info("Trying to specialize apply to call in '",
 329                     functionNode.getName(),
 330                     "' params=",
 331                     functionNode.getParameters(),
 332                     " id=",
 333                     functionNode.getId(),
 334                     " source=",
 335                     massageURL(functionNode.getSource().getURL()));




 266             return newCallNode;
 267         }
 268 
 269         return callNode;
 270     }
 271 
 272     private void pushExplodedArgs(final FunctionNode functionNode) {
 273         int start = 0;
 274 
 275         final MethodType actualCallSiteType = compiler.getCallSiteType(functionNode);
 276         if (actualCallSiteType == null) {
 277             throw new TransformFailedException(lc.getCurrentFunction(), "No callsite type");
 278         }
 279         assert actualCallSiteType.parameterType(actualCallSiteType.parameterCount() - 1) != Object[].class : "error vararg callsite passed to apply2call " + functionNode.getName() + " " + actualCallSiteType;
 280 
 281         final TypeMap ptm = compiler.getTypeMap();
 282         if (ptm.needsCallee()) {
 283             start++;
 284         }
 285 
 286         start++; // we always use this
 287 
 288         assert functionNode.getNumOfParams() == 0 : "apply2call on function with named paramaters!";
 289         final List<IdentNode> newParams = new ArrayList<>();
 290         final long to = actualCallSiteType.parameterCount() - start;
 291         for (int i = 0; i < to; i++) {

 292             newParams.add(new IdentNode(functionNode.getToken(), functionNode.getFinish(), EXPLODED_ARGUMENT_PREFIX.symbolName() + (i)));



 293         }
 294 
 295         callSiteTypes.push(actualCallSiteType);
 296         explodedArguments.push(newParams);
 297     }
 298 
 299     @Override
 300     public boolean enterFunctionNode(final FunctionNode functionNode) {
 301         if (!USE_APPLY2CALL) {
 302             return false;
 303         }
 304 
 305         if (!Global.isBuiltinFunctionPrototypeApply()) {
 306             log.fine("Apply transform disabled: apply/call overridden");
 307             assert !Global.isBuiltinFunctionPrototypeCall() : "call and apply should have the same SwitchPoint";
 308             return false;
 309         }
 310 
 311         if (!compiler.isOnDemandCompilation()) {
 312             return false;
 313         }
 314 
 315         if (functionNode.getNumOfParams() != 0) {
 316             return false;
 317         }
 318 
 319         if (functionNode.hasEval()) {
 320             return false;
 321         }
 322 
 323         if (!hasApplies(functionNode)) {
 324             return false;
 325         }
 326 
 327         if (log.isEnabled()) {
 328             log.info("Trying to specialize apply to call in '",
 329                     functionNode.getName(),
 330                     "' params=",
 331                     functionNode.getParameters(),
 332                     " id=",
 333                     functionNode.getId(),
 334                     " source=",
 335                     massageURL(functionNode.getSource().getURL()));


< prev index next >