use of com.jopdesign.common.FieldInfo in project jop by jop-devel.
the class AllocationWcetModel method getObjectFields.
public List<Type> getObjectFields(String className) {
List<Type> l = new LinkedList<Type>();
ClassInfo cli = project.getAppInfo().getClassInfo(className);
if (cli.getSuperClassName() != null) {
l.addAll(getObjectFields(cli.getSuperClassName()));
}
for (FieldInfo f : cli.getFields()) {
if (!f.isStatic()) {
l.add(f.getType());
}
}
return l;
}
use of com.jopdesign.common.FieldInfo in project jop by jop-devel.
the class InlineHelper method prepareInlining.
/**
* Prepare the invokee for inlining into the invokesite, by widening access restrictions or renaming
* methods to prevent incorrect method resolving.
* <p>
* This may change the code of the invokee, so this needs to be done before inlining the code.
* The CFG of the invokee will be removed.
* </p><p>
* This code assumes that {@link #canInline(CallString, InvokeSite, MethodInfo)} returned true for this invoke.
* </p>
*
* @param invoker the method where the code will be inlined to.
* @param invokee the method to inline.
*/
public void prepareInlining(MethodInfo invoker, MethodInfo invokee) {
MethodCode code = invokee.getCode();
InstructionList il = code.getInstructionList();
for (InstructionHandle ih : il.getInstructionHandles()) {
Instruction instr = ih.getInstruction();
if (instr instanceof InvokeInstruction) {
InvokeSite invokeSite = code.getInvokeSite(ih);
MethodRef ref = invokeSite.getInvokeeRef();
MethodInfo method = ref.getMethodInfo();
// we already checked that everything can be resolved
// nothing special to do for invokespecial here (checkInvokeSpecial only skips, no special return codes)
// check what we need to do
CheckResult rs = checkNeedsPublic(invoker, invokee, ref.getClassInfo(), method);
if (rs == CheckResult.NEEDS_PUBLIC) {
makePublic(method);
}
if (rs == CheckResult.NEEDS_PUBLIC_RENAME) {
if (method.isPrivate()) {
// TODO check the class for invokers, change to invokevirtual
} else {
// if the method is package visible, we need to rename all overriding methods
// too (but not methods from subclasses in different packages which do not override this)
// TODO update overriding methods
// TODO need to update all possible call sites
}
makePublic(method);
throw new AppInfoError("Implement me!");
}
} else if (instr instanceof FieldInstruction) {
FieldRef ref = code.getFieldRef(ih);
FieldInfo field = ref.getFieldInfo();
// we already checked that everything can be resolved
// check if fields need to be set to public
CheckResult rs = checkNeedsPublic(invoker, invokee, ref.getClassInfo(), field);
if (rs == CheckResult.NEEDS_PUBLIC) {
makePublic(field);
}
if (rs == CheckResult.NEEDS_PUBLIC_RENAME) {
throw new AppInfoError("Invalid returncode: renaming of fields not required");
}
}
}
}
use of com.jopdesign.common.FieldInfo in project jop by jop-devel.
the class InlineHelper method checkCode.
/**
* check the code of the invoked method if it contains instructions which prevent inlining.
*
* @param invoker the method into which the invokee will be inlined.
* @param invokee the invoked method.
* @return true if the code can be inlined and {@link #prepareInlining(MethodInfo, MethodInfo)} will succeed.
*/
private boolean checkCode(MethodInfo invoker, MethodInfo invokee) {
MethodCode code = invokee.getCode();
// Go through code, check for access to fields and invocations
for (InstructionHandle ih : code.getInstructionList(true, false).getInstructionHandles()) {
Instruction instr = ih.getInstruction();
if (instr instanceof InvokeInstruction) {
InvokeSite invokeSite = code.getInvokeSite(ih);
MethodRef ref = invokeSite.getInvokeeRef();
MethodInfo method = ref.getMethodInfo();
if (method == null) {
// TODO perform basic check on classnames if invoked method must already be public?
return false;
}
// invokespecial is somewhat, well, special..
if (invokeSite.isInvokeSpecial()) {
if (checkInvokeSpecial(invoker, invokee, invokeSite, ref.getClassInfo(), method) == CheckResult.SKIP) {
return false;
}
} else {
// check if fields need to be set to public
if (checkNeedsPublic(invoker, invokee, ref.getClassInfo(), method) == CheckResult.SKIP) {
return false;
}
}
} else if (instr instanceof FieldInstruction) {
FieldRef ref = code.getFieldRef(ih);
FieldInfo field = ref.getFieldInfo();
if (field == null) {
// TODO perform basic check on classnames if field is already public?
return false;
}
// check if fields need to be set to public
if (checkNeedsPublic(invoker, invokee, ref.getClassInfo(), field) == CheckResult.SKIP) {
return false;
}
}
}
return true;
}
use of com.jopdesign.common.FieldInfo in project jop by jop-devel.
the class UnusedCodeRemover method removeUnusedMembers.
/**
* Remove all unused classes, methods and fields.
*/
private void removeUnusedMembers() {
AppInfo appInfo = AppInfo.getSingleton();
// we cannot modify the lists while iterating through it
List<ClassInfo> unusedClasses = new LinkedList<ClassInfo>();
List<FieldInfo> unusedFields = new LinkedList<FieldInfo>();
List<MethodInfo> unusedMethods = new LinkedList<MethodInfo>();
int fields = 0;
int methods = 0;
for (ClassInfo cls : appInfo.getClassInfos()) {
if (ucf.getMark(cls) == Mark.UNUSED) {
unusedClasses.add(cls);
logger.debug("Removing unused class " + cls);
continue;
}
unusedFields.clear();
unusedMethods.clear();
if (appInfo.isHwObject(cls)) {
// Do not remove fields from hardware objects, else the mapping gets broken and
// chaos takes over!
logger.debug("Skipping fields of used hardware object " + cls);
} else {
for (FieldInfo f : cls.getFields()) {
if (ucf.getMark(f) == Mark.UNUSED) {
unusedFields.add(f);
}
}
}
for (MethodInfo m : cls.getMethods()) {
Mark mark = ucf.getMark(m);
if (mark == Mark.UNUSED) {
unusedMethods.add(m);
}
if (mark == Mark.MARKED && !m.isNative() && !m.isAbstract()) {
logger.info("Making unused method " + m + " abstract");
m.setAbstract(true);
m.getClassInfo().setAbstract(true);
}
}
for (FieldInfo f : unusedFields) {
fields += removeField(f);
}
for (MethodInfo m : unusedMethods) {
methods += removeMethod(m);
}
}
appInfo.removeClasses(unusedClasses);
int classes = unusedClasses.size();
logger.info("Removed " + classes + (classes == 1 ? " class, " : " classes, ") + fields + (fields == 1 ? " field, " : " fields, ") + methods + (methods == 1 ? " method" : " methods"));
}
use of com.jopdesign.common.FieldInfo in project jop by jop-devel.
the class DFATool method classForField.
public ClassInfo classForField(String className, String fieldName) {
ClassInfo cls = getAppInfo().getClassInfo(className);
if (cls == null) {
logger.info("Unknown class as potential receiver of field access" + className);
return null;
}
// TODO maybe we *do* want to check access here...
FieldInfo field = cls.getFieldInfoInherited(fieldName, false);
return field != null ? field.getClassInfo() : null;
}
Aggregations