474 */ 475 @SuppressWarnings("unused") 476 private static Map<Integer, Type> getEffectiveInvalidatedProgramPoints( 477 final Map<Integer, Type> invalidatedProgramPoints, final Object typeInformationFile) { 478 if(invalidatedProgramPoints != null) { 479 return invalidatedProgramPoints; 480 } 481 final Map<Integer, Type> loadedProgramPoints = OptimisticTypesPersistence.load(typeInformationFile); 482 return loadedProgramPoints != null ? loadedProgramPoints : new TreeMap<Integer, Type>(); 483 } 484 485 private FunctionInitializer compileTypeSpecialization(final MethodType actualCallSiteType, final ScriptObject runtimeScope, final boolean persist) { 486 // We're creating an empty script object for holding local variables. AssignSymbols will populate it with 487 // explicit Undefined values for undefined local variables (see AssignSymbols#defineSymbol() and 488 // CompilationEnvironment#declareLocalSymbol()). 489 490 if (log.isEnabled()) { 491 log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType); 492 } 493 494 final boolean persistentCache = usePersistentCodeCache() && persist; 495 String cacheKey = null; 496 if (persistentCache) { 497 final TypeMap typeMap = typeMap(actualCallSiteType); 498 final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId); 499 cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes); 500 final CodeInstaller<ScriptEnvironment> newInstaller = getInstallerForNewCode(); 501 final StoredScript script = newInstaller.loadScript(source, cacheKey); 502 503 if (script != null) { 504 Compiler.updateCompilationId(script.getCompilationId()); 505 return script.installFunction(this, newInstaller); 506 } 507 } 508 509 final FunctionNode fn = reparse(); 510 final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope); 511 final FunctionNode compiledFn = compiler.compile(fn, 512 isSerialized() ? CompilationPhases.COMPILE_ALL_SERIALIZED : CompilationPhases.COMPILE_ALL); 513 514 if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) { 515 compiler.persistClassInfo(cacheKey, compiledFn); 516 } 517 return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints()); 518 } 519 520 boolean usePersistentCodeCache() { 521 final ScriptEnvironment env = installer.getOwner(); 522 return env._persistent_cache && env._optimistic_types; 523 } 524 525 private MethodType explicitParams(final MethodType callSiteType) { 526 if (CompiledFunction.isVarArgsType(callSiteType)) { 527 return null; 528 } 529 530 final MethodType noCalleeThisType = callSiteType.dropParameterTypes(0, 2); // (callee, this) is always in call site type 531 final int callSiteParamCount = noCalleeThisType.parameterCount(); 532 533 // Widen parameters of reference types to Object as we currently don't care for specialization among reference 534 // types. E.g. call site saying (ScriptFunction, Object, String) should still link to (ScriptFunction, Object, Object) 535 final Class<?>[] paramTypes = noCalleeThisType.parameterArray(); 536 boolean changed = false; 537 for (int i = 0; i < paramTypes.length; ++i) { 538 final Class<?> paramType = paramTypes[i]; 539 if (!(paramType.isPrimitive() || paramType == Object.class)) { 540 paramTypes[i] = Object.class; 541 changed = true; 542 } | 474 */ 475 @SuppressWarnings("unused") 476 private static Map<Integer, Type> getEffectiveInvalidatedProgramPoints( 477 final Map<Integer, Type> invalidatedProgramPoints, final Object typeInformationFile) { 478 if(invalidatedProgramPoints != null) { 479 return invalidatedProgramPoints; 480 } 481 final Map<Integer, Type> loadedProgramPoints = OptimisticTypesPersistence.load(typeInformationFile); 482 return loadedProgramPoints != null ? loadedProgramPoints : new TreeMap<Integer, Type>(); 483 } 484 485 private FunctionInitializer compileTypeSpecialization(final MethodType actualCallSiteType, final ScriptObject runtimeScope, final boolean persist) { 486 // We're creating an empty script object for holding local variables. AssignSymbols will populate it with 487 // explicit Undefined values for undefined local variables (see AssignSymbols#defineSymbol() and 488 // CompilationEnvironment#declareLocalSymbol()). 489 490 if (log.isEnabled()) { 491 log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType); 492 } 493 494 final boolean persistentCache = persist && usePersistentCodeCache(); 495 String cacheKey = null; 496 if (persistentCache) { 497 final TypeMap typeMap = typeMap(actualCallSiteType); 498 final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId); 499 cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes); 500 final CodeInstaller<ScriptEnvironment> newInstaller = getInstallerForNewCode(); 501 final StoredScript script = newInstaller.loadScript(source, cacheKey); 502 503 if (script != null) { 504 Compiler.updateCompilationId(script.getCompilationId()); 505 return script.installFunction(this, newInstaller); 506 } 507 } 508 509 final FunctionNode fn = reparse(); 510 final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope); 511 final FunctionNode compiledFn = compiler.compile(fn, 512 isSerialized() ? CompilationPhases.COMPILE_ALL_SERIALIZED : CompilationPhases.COMPILE_ALL); 513 514 if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) { 515 compiler.persistClassInfo(cacheKey, compiledFn); 516 } 517 return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints()); 518 } 519 520 boolean usePersistentCodeCache() { 521 return installer != null && installer.getOwner()._persistent_cache; 522 } 523 524 private MethodType explicitParams(final MethodType callSiteType) { 525 if (CompiledFunction.isVarArgsType(callSiteType)) { 526 return null; 527 } 528 529 final MethodType noCalleeThisType = callSiteType.dropParameterTypes(0, 2); // (callee, this) is always in call site type 530 final int callSiteParamCount = noCalleeThisType.parameterCount(); 531 532 // Widen parameters of reference types to Object as we currently don't care for specialization among reference 533 // types. E.g. call site saying (ScriptFunction, Object, String) should still link to (ScriptFunction, Object, Object) 534 final Class<?>[] paramTypes = noCalleeThisType.parameterArray(); 535 boolean changed = false; 536 for (int i = 0; i < paramTypes.length; ++i) { 537 final Class<?> paramType = paramTypes[i]; 538 if (!(paramType.isPrimitive() || paramType == Object.class)) { 539 paramTypes[i] = Object.class; 540 changed = true; 541 } |