
package orc.run.porce;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;

public abstract class SpecializationConfiguration {
	
	static {
		if (System.getProperty("orc.porce.truffleASTInlining") != null) {
			throw new Error("truffleASTInlining is disabled in the source code. See InternalCPSDispatch.java.");
		}
	}
	/*
	@CompilationFinal
	public static final boolean TruffleASTInlining = Boolean
			.parseBoolean(System.getProperty("orc.porce.truffleASTInlining", "false"));
	*/
	
	@CompilationFinal
	public static final int GetFieldMaxCacheSize = 
		Integer.parseInt(System.getProperty("orc.porce.cache.getFieldMaxCacheSize", "4"));

	@CompilationFinal
	public static final int InternalCallMaxCacheSize =
		Integer.parseInt(System.getProperty("orc.porce.cache.internalCallMaxCacheSize", "12"));
	@CompilationFinal
	public static final int ExternalDirectCallMaxCacheSize =
		Integer.parseInt(System.getProperty("orc.porce.cache.externalDirectCallMaxCacheSize", "8"));
	@CompilationFinal
	public static final int ExternalCPSCallMaxCacheSize = 
		Integer.parseInt(System.getProperty("orc.porce.cache.externalCPSCallMaxCacheSize", "12"));

	/**
	 * The maximum number of ns a functions may take and still have the spawn
	 * inlined.
	 * 
	 * The system property is in floating-point ms.
	 */
	@CompilationFinal
	public static final int InlineAverageTimeLimit = 
		(int) (Double.parseDouble(System.getProperty("orc.porce.inlineAverageTimeLimit", "0.1")) * 1000000);
	@CompilationFinal
	public static final int MinCallsForTimePerCall = 100;

	@CompilationFinal
	public static final boolean UniversalTCO = Boolean
			.parseBoolean(System.getProperty("orc.porce.universalTCO", "false"));
		
	@CompilationFinal
	public static final boolean SelfTCO = Boolean
			.parseBoolean(System.getProperty("orc.porce.selfTCO", "true"));
	
	@CompilationFinal
	public static final boolean InlineForceResolved = Boolean
			.parseBoolean(System.getProperty("orc.porce.optimizations.inlineForceResolved", "true"));
	
	@CompilationFinal
	public static final boolean InlineForceHalted = Boolean
			.parseBoolean(System.getProperty("orc.porce.optimizations.inlineForceHalted", "true"));
	
	@CompilationFinal
	public static final boolean SpecializeOnCounterStates = Boolean
			.parseBoolean(System.getProperty("orc.porce.optimizations.specializeOnCounterStates", "true"));
	
	@CompilationFinal
	public static final boolean ExternalCPSDirectSpecialization = Boolean
			.parseBoolean(System.getProperty("orc.porce.optimizations.externalCPSDirectSpecialization", "true"));
	
	@CompilationFinal
	public static final boolean EnvironmentCaching = Boolean
			.parseBoolean(System.getProperty("orc.porce.optimizations.environmentCaching", "true"));
}

@@ -1480,81 +1480,756 @@
 0);%0A
-%09@CompilationFinal%0A%09public static final int MinCallsForTimePerCall = 100;
+    /**%0A     * The number of calls before computing the time per call. %0A     * %0A     * This is computed from graal.TruffleCompilationThreshold if that is set to a%0A     * small value (less than 105). Otherwise it defaults to 100.%0A     */%0A%09@CompilationFinal%0A%09public static final int MinCallsForTimePerCall;%0A%09%0A%09static %7B%0A%09    int v = -1;%0A%09    v = Integer.parseInt(System.getProperty(%22orc.porce.cache.minCallsForTimePerCall%22, %22-1%22));%0A%09    if (v %3C 0)%0A%09        v = Math.min(Integer.parseInt(System.getProperty(%22graal.TruffleCompilationThreshold%22, %22-1%22)) - 5, 100);%0A        if (v %3C 0)%0A            v = 100;%0A        MinCallsForTimePerCall = v;%0A        System.setProperty(%22orc.porce.cache.minCallsForTimePerCall%22, Integer.toString(MinCallsForTimePerCall));%0A%09%7D
 %0A%0A%09@

Make MinCallsForTimePerCall configurable.