nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CompiledFunction.java
changeset 42376 8604f1a50c30
parent 34447 ec4c069f9436
equal deleted inserted replaced
42279:f4e854a77aa3 42376:8604f1a50c30
   150             return linkLogicClass;
   150             return linkLogicClass;
   151         }
   151         }
   152         return null;
   152         return null;
   153     }
   153     }
   154 
   154 
       
   155     boolean convertsNumericArgs() {
       
   156         return isSpecialization() && specialization.convertsNumericArgs();
       
   157     }
       
   158 
   155     int getFlags() {
   159     int getFlags() {
   156         return flags;
   160         return flags;
   157     }
   161     }
   158 
   162 
   159     /**
   163     /**
   386             final Type[] callSiteType = toTypeWithoutCallee(callSiteMethodType, 1); // Always has callee
   390             final Type[] callSiteType = toTypeWithoutCallee(callSiteMethodType, 1); // Always has callee
   387 
   391 
   388             int narrowWeightDelta = 0;
   392             int narrowWeightDelta = 0;
   389             int widenWeightDelta = 0;
   393             int widenWeightDelta = 0;
   390             final int minParamsCount = Math.min(Math.min(thisParamCount, otherParamCount), callSiteParamCount);
   394             final int minParamsCount = Math.min(Math.min(thisParamCount, otherParamCount), callSiteParamCount);
       
   395             final boolean convertsNumericArgs = cf.convertsNumericArgs();
   391             for(int i = 0; i < minParamsCount; ++i) {
   396             for(int i = 0; i < minParamsCount; ++i) {
   392                 final int callSiteParamWeight = getParamType(i, callSiteType, csVarArg).getWeight();
   397                 final Type callSiteParamType = getParamType(i, callSiteType, csVarArg);
       
   398                 final Type thisParamType = getParamType(i, thisType, thisVarArg);
       
   399                 if (!convertsNumericArgs && callSiteParamType.isBoolean() && thisParamType.isNumeric()) {
       
   400                     // When an argument is converted to number by a function it is safe to "widen" booleans to numeric types.
       
   401                     // However, we must avoid this conversion for generic functions such as Array.prototype.push.
       
   402                     return false;
       
   403                 }
       
   404                 final int callSiteParamWeight = callSiteParamType.getWeight();
   393                 // Delta is negative for narrowing, positive for widening
   405                 // Delta is negative for narrowing, positive for widening
   394                 final int thisParamWeightDelta = getParamType(i, thisType, thisVarArg).getWeight() - callSiteParamWeight;
   406                 final int thisParamWeightDelta = thisParamType.getWeight() - callSiteParamWeight;
   395                 final int otherParamWeightDelta = getParamType(i, otherType, otherVarArg).getWeight() - callSiteParamWeight;
   407                 final int otherParamWeightDelta = getParamType(i, otherType, otherVarArg).getWeight() - callSiteParamWeight;
   396                 // Only count absolute values of narrowings
   408                 // Only count absolute values of narrowings
   397                 narrowWeightDelta += Math.max(-thisParamWeightDelta, 0) - Math.max(-otherParamWeightDelta, 0);
   409                 narrowWeightDelta += Math.max(-thisParamWeightDelta, 0) - Math.max(-otherParamWeightDelta, 0);
   398                 // Only count absolute values of widenings
   410                 // Only count absolute values of widenings
   399                 widenWeightDelta += Math.max(thisParamWeightDelta, 0) - Math.max(otherParamWeightDelta, 0);
   411                 widenWeightDelta += Math.max(thisParamWeightDelta, 0) - Math.max(otherParamWeightDelta, 0);