adding files
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2497 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
f8df8a93c7
commit
b16bcb5bf3
|
@ -0,0 +1,57 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.demandpa.alg.refinepolicy;
|
||||
|
||||
/**
|
||||
* Default {@link RefinementPolicy} implementation, delegating to some provided {@link FieldRefinePolicy} and
|
||||
* {@link CallGraphRefinePolicy}
|
||||
* @author manu
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractRefinementPolicy implements RefinementPolicy {
|
||||
|
||||
protected final CallGraphRefinePolicy cgRefinePolicy;
|
||||
|
||||
protected final FieldRefinePolicy fieldRefinePolicy;
|
||||
|
||||
private static final int DEFAULT_NUM_PASSES = 3;
|
||||
|
||||
private static final int[] DEFAULT_BUDGET_PER_PASS = { 1000, 12000, 12000 };
|
||||
|
||||
public int getBudgetForPass(int passNum) {
|
||||
return DEFAULT_BUDGET_PER_PASS[passNum];
|
||||
}
|
||||
|
||||
public CallGraphRefinePolicy getCallGraphRefinePolicy() {
|
||||
return cgRefinePolicy;
|
||||
}
|
||||
|
||||
public FieldRefinePolicy getFieldRefinePolicy() {
|
||||
return fieldRefinePolicy;
|
||||
}
|
||||
|
||||
public int getNumPasses() {
|
||||
return DEFAULT_NUM_PASSES;
|
||||
}
|
||||
|
||||
public boolean nextPass() {
|
||||
// don't short-circuit since nextPass() can have side-effects
|
||||
boolean fieldNextPass = fieldRefinePolicy.nextPass();
|
||||
boolean callNextPass = cgRefinePolicy.nextPass();
|
||||
return fieldNextPass || callNextPass;
|
||||
}
|
||||
|
||||
public AbstractRefinementPolicy(FieldRefinePolicy fieldRefinePolicy, CallGraphRefinePolicy cgRefinePolicy) {
|
||||
this.cgRefinePolicy = cgRefinePolicy;
|
||||
this.fieldRefinePolicy = fieldRefinePolicy;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.demandpa.alg.refinepolicy;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IField;
|
||||
import com.ibm.wala.demandpa.util.ArrayContents;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
||||
public class TunedFieldRefinementPolicy implements FieldRefinePolicy {
|
||||
|
||||
private final ClassHierarchy cha;
|
||||
|
||||
private final Collection<IClass> typesToRefine = HashSetFactory.make();
|
||||
|
||||
private IClass firstSkippedClass = null;
|
||||
|
||||
public boolean nextPass() {
|
||||
if (firstSkippedClass != null) {
|
||||
typesToRefine.add(firstSkippedClass);
|
||||
firstSkippedClass = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldRefine(IField field) {
|
||||
if (field == ArrayContents.v()) {
|
||||
return true;
|
||||
}
|
||||
IClass classToCheck = removeInner(field.getDeclaringClass());
|
||||
if (superOfAnyEncountered(classToCheck)) {
|
||||
return true;
|
||||
} else {
|
||||
if (firstSkippedClass == null) {
|
||||
firstSkippedClass = classToCheck;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean superOfAnyEncountered(IClass klass) {
|
||||
for (IClass toRefine : typesToRefine) {
|
||||
if (cha.isAssignableFrom(klass, toRefine)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param klass
|
||||
* @return the top-level {@link IClass} where klass is declared, or klass
|
||||
* itself if klass is top-level or if top-level class not loaded
|
||||
*/
|
||||
private IClass removeInner(IClass klass) {
|
||||
ClassLoaderReference cl = klass.getClassLoader().getReference();
|
||||
String klassStr = klass.getName().toString();
|
||||
int dollarIndex = klassStr.indexOf('$');
|
||||
if (dollarIndex == -1) {
|
||||
return klass;
|
||||
} else {
|
||||
String topMostName = klassStr.substring(0, dollarIndex);
|
||||
IClass topMostClass = cha.lookupClass(TypeReference.findOrCreate(cl, topMostName));
|
||||
return (topMostClass != null) ? topMostClass : klass;
|
||||
}
|
||||
}
|
||||
|
||||
public TunedFieldRefinementPolicy(ClassHierarchy cha) {
|
||||
this.cha = cha;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue