use of com.jopdesign.common.ClassInfo 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;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class DFATool method createPrologue.
private MethodInfo createPrologue() {
// find ordering for class initializers
ClinitOrder c = new ClinitOrder();
appInfo.iterate(c);
List<ClassInfo> order = c.findOrder();
MethodInfo mainClass = appInfo.getMainMethod();
// create prologue
return buildPrologue(mainClass, statements, flow, order);
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class DFATool method buildPrologue.
private MethodInfo buildPrologue(MethodInfo mainMethod, List<InstructionHandle> statements, Flow flow, List<ClassInfo> clinits) {
// we use a prologue sequence for startup
InstructionList prologue = new InstructionList();
ConstantPoolGen prologueCP = mainMethod.getConstantPoolGen();
Instruction instr;
int idx;
// add magic initializers to prologue sequence
if (!analyzeBootMethod) {
instr = new ICONST(0);
prologue.append(instr);
instr = new ICONST(0);
prologue.append(instr);
idx = prologueCP.addMethodref("com.jopdesign.sys.GC", "init", "(II)V");
instr = new INVOKESTATIC(idx);
prologue.append(instr);
}
// add class initializers
for (ClassInfo clinit : clinits) {
MemberID cSig = appInfo.getClinitSignature(clinit.getClassName());
idx = prologueCP.addMethodref(cSig.getClassName(), cSig.getMemberName(), cSig.getDescriptor().toString());
instr = new INVOKESTATIC(idx);
prologue.append(instr);
}
if (analyzeBootMethod) {
// Let's just analyze the full boot method, so that the callgraph-builder is happy.
// Doing this after clinit, so that we have DFA infos on fields in JVMHelp.init()
idx = prologueCP.addMethodref("com.jopdesign.sys.Startup", "boot", "()V");
instr = new INVOKESTATIC(idx);
prologue.append(instr);
}
// add main method
instr = new ACONST_NULL();
prologue.append(instr);
idx = prologueCP.addMethodref(mainMethod.getClassName(), mainMethod.getShortName(), mainMethod.getDescriptor().toString());
instr = new INVOKESTATIC(idx);
prologue.append(instr);
// // invoke startMission() to ensure analysis of threads
// idx = prologueCP.addMethodref("joprt.RtThread", "startMission", "()V");
// instr = new INVOKESTATIC(idx);
// prologue.append(instr);
instr = new NOP();
prologue.append(instr);
prologue.setPositions(true);
// add prologue to program structure
for (Iterator l = prologue.iterator(); l.hasNext(); ) {
InstructionHandle handle = (InstructionHandle) l.next();
statements.add(handle);
if (handle.getInstruction() instanceof GOTO) {
GOTO g = (GOTO) handle.getInstruction();
flow.addEdge(new FlowEdge(handle, g.getTarget(), FlowEdge.NORMAL_EDGE));
} else if (handle.getNext() != null) {
flow.addEdge(new FlowEdge(handle, handle.getNext(), FlowEdge.NORMAL_EDGE));
}
}
MemberID pSig = new MemberID(prologueName, Descriptor.parse(prologueSig));
MethodInfo mi = mainMethod.getClassInfo().createMethod(pSig, null, prologue);
mi.setAccessType(AccessType.ACC_PRIVATE);
return mi;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class TypeGraph method getJoinNodes.
/** Compute the set of join nodes<br/>
*
* See <quote>Vitek, J., Horspool, R. N., and Krall, A. 1997. Efficient type inclusion tests.
* SIGPLAN Not. 32, 10 (Oct. 1997), 142-157.</quote>
* @return a map from types to join nodes
*/
public Set<ClassInfo> getJoinNodes() {
Set<ClassInfo> joinNodes = new HashSet<ClassInfo>();
Set<ClassInfo> miNodes = new HashSet<ClassInfo>();
for (ClassInfo v : bottomUpTraversal()) {
boolean hasJoinSub = false;
for (DefaultEdge descEdge : outgoingEdgesOf(v)) {
if (miNodes.contains(getEdgeTarget(descEdge))) {
hasJoinSub = true;
}
}
boolean isMiNode = hasJoinSub;
if (inDegreeOf(v) > 1 && !hasJoinSub) {
joinNodes.add(v);
isMiNode = true;
}
if (isMiNode) {
miNodes.add(v);
}
}
return joinNodes;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class TypeGraph method build.
private void build(AppInfo ai, ClassInfo rootNode) {
this.rootNode = rootNode;
Collection<ClassInfo> classes = ai.getClassInfos();
for (ClassInfo ci : classes) {
this.addVertex(ci);
if (ci.getSuperClassInfo() != null) {
if (ci.isInterface() && !ci.getSuperClassInfo().isInterface()) {
// Interface extends java.lang.Object, ignored
} else {
this.addVertex(ci.getSuperClassInfo());
this.addEdge(ci.getSuperClassInfo(), ci);
}
}
/* interface edges */
for (String ifaceClass : ci.getInterfaceNames()) {
ClassInfo iface = ai.getClassInfo(ifaceClass);
assert iface != null : ("TypeGraph.build: Interface " + ifaceClass + " not found");
this.addVertex(iface);
this.addEdge(iface, ci);
}
}
}
Aggregations