use of com.oracle.graal.pointsto.flow.MethodTypeFlow in project graal by oracle.
the class StaticAnalysisResultsBuilder method makeResults.
public StaticAnalysisResults makeResults(AnalysisMethod method) {
MethodTypeFlow methodFlow = method.getTypeFlow();
MethodFlowsGraph originalFlows = methodFlow.getOriginalMethodFlows();
ArrayList<JavaTypeProfile> paramProfiles = new ArrayList<>(originalFlows.getParameters().length);
for (int i = 0; i < originalFlows.getParameters().length; i++) {
JavaTypeProfile paramProfile = makeTypeProfile(methodFlow.foldTypeFlow(bb, originalFlows.getParameter(i)));
if (paramProfile != null) {
ensureSize(paramProfiles, i);
paramProfiles.set(i, paramProfile);
}
}
JavaTypeProfile[] parameterTypeProfiles = null;
if (paramProfiles.size() > 0) {
parameterTypeProfiles = paramProfiles.toArray(new JavaTypeProfile[paramProfiles.size()]);
}
JavaTypeProfile resultTypeProfile = makeTypeProfile(methodFlow.foldTypeFlow(bb, originalFlows.getResult()));
ArrayList<BytecodeEntry> entries = new ArrayList<>(method.getCodeSize());
for (InstanceOfTypeFlow originalInstanceOf : originalFlows.getInstaceOfFlows()) {
if (BytecodeLocation.hasValidBci(originalInstanceOf.getLocation())) {
int bci = originalInstanceOf.getLocation().getBci();
/* Fold the instanceof flows. */
TypeState instanceOfTypeState = methodFlow.foldTypeFlow(bb, originalInstanceOf);
originalInstanceOf.setState(bb, instanceOfTypeState);
JavaTypeProfile typeProfile = makeTypeProfile(instanceOfTypeState);
if (typeProfile != null) {
ensureSize(entries, bci);
assert entries.get(bci) == null : "In " + method.format("%h.%n(%p)") + " a profile with bci=" + bci + " already exists: " + entries.get(bci);
entries.set(bci, createBytecodeEntry(method, bci, typeProfile, null, null));
}
}
}
for (InvokeTypeFlow originalInvoke : originalFlows.getInvokes()) {
if (BytecodeLocation.hasValidBci(originalInvoke.getLocation())) {
int bci = originalInvoke.getLocation().getBci();
TypeState invokeTypeState = TypeState.forEmpty();
if (originalInvoke.getTargetMethod().hasReceiver()) {
invokeTypeState = methodFlow.foldTypeFlow(bb, originalInvoke.getReceiver());
originalInvoke.setState(bb, invokeTypeState);
}
TypeFlow<?> originalReturn = originalInvoke.getActualReturn();
TypeState returnTypeState = null;
if (originalReturn != null) {
returnTypeState = methodFlow.foldTypeFlow(bb, originalReturn);
originalReturn.setState(bb, returnTypeState);
}
JavaTypeProfile typeProfile = makeTypeProfile(invokeTypeState);
JavaMethodProfile methodProfile = makeMethodProfile(originalInvoke.getCallees());
JavaTypeProfile invokeResultTypeProfile = originalReturn == null ? null : makeTypeProfile(returnTypeState);
if (typeProfile != null || methodProfile != null || invokeResultTypeProfile != null) {
ensureSize(entries, bci);
assert entries.get(bci) == null : "In " + method.format("%h.%n(%p)") + " a profile with bci=" + bci + " already exists: " + entries.get(bci);
entries.set(bci, createBytecodeEntry(method, bci, typeProfile, methodProfile, invokeResultTypeProfile));
}
}
}
if (PointstoOptions.PrintSynchronizedAnalysis.getValue(bb.getOptions())) {
originalFlows.getMonitorEntries().stream().filter(m -> m.getState().typesCount() > 20).sorted(Comparator.comparingInt(m2 -> m2.getState().typesCount())).forEach(monitorEnter -> {
TypeState monitorEntryState = monitorEnter.getState();
String typesString = monitorEntryState.closeToAllInstantiated(bb) ? "close to all instantiated" : StreamSupport.stream(monitorEntryState.types().spliterator(), false).map(AnalysisType::getName).collect(Collectors.joining(", "));
StringBuilder strb = new StringBuilder();
strb.append("Location: ");
String methodName = method.format("%h.%n(%p)");
int bci = monitorEnter.getLocation().getBci();
if (bci != BytecodeLocation.UNKNOWN_BCI) {
StackTraceElement traceElement = method.asStackTraceElement(bci);
String sourceLocation = traceElement.getFileName() + ":" + traceElement.getLineNumber();
strb.append("@(").append(methodName).append(":").append(bci).append(")");
strb.append("=(").append(sourceLocation).append(")");
} else {
strb.append("@(").append(methodName).append(")");
}
strb.append("\n");
strb.append("Synchronized types #: ").append(monitorEntryState.typesCount()).append("\n");
strb.append("Types: ").append(typesString).append("\n");
System.out.println(strb);
});
}
BytecodeEntry first = null;
for (int i = entries.size() - 1; i >= 0; i--) {
BytecodeEntry cur = entries.get(i);
if (cur != null) {
cur.next = first;
first = cur;
}
}
return createStaticAnalysisResults(method, parameterTypeProfiles, resultTypeProfile, first);
}
use of com.oracle.graal.pointsto.flow.MethodTypeFlow in project graal by oracle.
the class BigBang method addRootMethod.
@SuppressWarnings("try")
public AnalysisMethod addRootMethod(AnalysisMethod aMethod) {
if (aMethod.isRootMethod()) {
return aMethod;
}
aMethod.registerAsRootMethod();
final MethodTypeFlow methodFlow = aMethod.getTypeFlow();
try (Indent indent = debug.logAndIndent("add root method %s", aMethod.getName())) {
boolean isStatic = Modifier.isStatic(aMethod.getModifiers());
int paramCount = aMethod.getSignature().getParameterCount(!isStatic);
int offset = 0;
if (!isStatic) {
methodFlow.setInitialReceiverFlow(this, aMethod.getDeclaringClass());
offset = 1;
}
for (int i = offset; i < paramCount; i++) {
AnalysisType declaredParamType = (AnalysisType) aMethod.getSignature().getParameterType(i - offset, aMethod.getDeclaringClass());
if (declaredParamType.getJavaKind() == JavaKind.Object) {
methodFlow.setInitialParameterFlow(this, declaredParamType, i);
}
}
}
postTask(new DebugContextRunnable() {
@Override
public void run(DebugContext ignore) {
methodFlow.addContext(BigBang.this, BigBang.this.contextPolicy().emptyContext(), null);
}
@Override
public DebugContext getDebug(OptionValues ignored, List<DebugHandlersFactory> factories) {
return DebugContext.DISABLED;
}
});
return aMethod;
}
Aggregations