use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class AppLoader method processClassName.
private int processClassName(String className) {
AppInfo appInfo = AppInfo.getSingleton();
int cnt = 0;
ClassInfo cls;
if (appInfo.hasClassInfo(className)) {
cls = appInfo.getClassInfo(className);
} else {
cls = appInfo.loadClass(className);
if (cls != null) {
newClasses.add(cls);
cnt++;
}
}
if (cls != null) {
enqueue(cls);
}
return cnt;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class ClinitOrder method printDependency.
/**
* Print the dependency for debugging. Not used at the moment.
* @param warn if true, print with warning level
*/
private void printDependency(boolean warn) {
Priority lvl = warn ? Level.WARN : Level.DEBUG;
Set<ClassInfo> cliSet = clinit.keySet();
for (ClassInfo clinf : cliSet) {
logger.log(lvl, "Class " + clinf.getClassName());
Set<ClassInfo> depends = clinit.get(clinf);
for (ClassInfo clf : depends) {
logger.log(lvl, "\tdepends " + clf.getClassName());
}
}
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class ClinitOrder method visitClass.
@Override
public boolean visitClass(ClassInfo classInfo) {
MethodInfo mi = classInfo.getMethodInfo(clinitSig);
if (mi != null) {
Set<ClassInfo> depends = findDependencies(mi, false);
clinit.put(classInfo, depends);
}
return true;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class ClinitOrder method findDependencies.
private Set<ClassInfo> findDependencies(MethodInfo method, boolean inRec) {
// System.out.println("find dep. in "+cli.clazz.getClassName()+":"+mi.getMethod().getName());
Set<ClassInfo> depends = new HashSet<ClassInfo>();
if (method.isNative() || method.isAbstract()) {
// subclasses???? :-(
return depends;
}
ClassInfo classInfo = method.getClassInfo();
ConstantPoolGen cpoolgen = method.getConstantPoolGen();
InstructionList il = method.getCode().getInstructionList();
InstructionFinder f = new InstructionFinder(il);
// TODO can we encounter an empty instruction list?
//if(il.getStart() == null) {
// return depends;
//}
// find instructions that access the constant pool
// collect all indices to constants in ClassInfo
String cpInstr = "CPInstruction";
for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
InstructionHandle[] match = (InstructionHandle[]) it.next();
InstructionHandle first = match[0];
CPInstruction ii = (CPInstruction) first.getInstruction();
int idx = ii.getIndex();
Constant co = cpoolgen.getConstant(idx);
ClassRef classRef = null;
Set addDepends = null;
ClassInfo clinfo;
MethodInfo minfo;
switch(co.getTag()) {
case Constants.CONSTANT_Class:
classRef = classInfo.getConstantInfo(co).getClassRef();
clinfo = classRef.getClassInfo();
if (clinfo != null) {
minfo = clinfo.getMethodInfo("<init>()V");
if (minfo != null) {
addDepends = findDependencies(minfo, true);
}
}
break;
case Constants.CONSTANT_Fieldref:
case Constants.CONSTANT_InterfaceMethodref:
classRef = classInfo.getConstantInfo(co).getClassRef();
break;
case Constants.CONSTANT_Methodref:
ConstantMethodInfo mref = (ConstantMethodInfo) classInfo.getConstantInfo(co);
classRef = mref.getClassRef();
minfo = mref.getMethodRef().getMethodInfo();
if (minfo != null) {
addDepends = findDependencies(minfo, true);
}
break;
}
if (classRef != null) {
ClassInfo clinf = classRef.getClassInfo();
if (clinf != null) {
if (clinf.getMethodInfo(clinitSig) != null) {
// don't add myself as dependency
if (!clinf.equals(method.getClassInfo())) {
depends.add(clinf);
}
}
}
}
if (addDepends != null) {
for (Object addDepend : addDepends) {
ClassInfo addCli = (ClassInfo) addDepend;
if (addCli.equals(method.getClassInfo())) {
throw new JavaClassFormatError("cyclic indirect <clinit> dependency");
}
depends.add(addCli);
}
}
}
return depends;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class UsedCodeFinder method getClassInfo.
private ClassInfo getClassInfo(MemberID sig) {
String className;
if (sig.isArrayClass()) {
ArrayTypeInfo at = ArrayTypeInfo.parse(sig.getClassName());
if (at.getElementType() instanceof ObjectTypeInfo) {
className = ((ObjectTypeInfo) at.getElementType()).getClassRef().getClassName();
} else {
return null;
}
} else {
className = sig.getClassName();
}
ClassInfo classInfo = appInfo.getClassInfo(className);
if (classInfo == null) {
ignoreClass(className);
}
return classInfo;
}
Aggregations