use of jdk.vm.ci.meta.JavaMethodProfile in project graal by oracle.
the class StaticAnalysisResultsBuilder method cachedMethodProfile.
private JavaMethodProfile cachedMethodProfile(JavaMethodProfile[] cache, int cacheIdx, Collection<AnalysisMethod> callees) {
JavaMethodProfile result = cache[cacheIdx];
if (result == null) {
result = createMethodProfile(callees);
cache[cacheIdx] = result;
}
return result;
}
use of jdk.vm.ci.meta.JavaMethodProfile in project graal by oracle.
the class StaticAnalysisResultsBuilder method createMethodProfile.
private JavaMethodProfile createMethodProfile(Collection<AnalysisMethod> callees) {
ProfiledMethod[] pitems = new ProfiledMethod[callees.size()];
double probability = 1d / pitems.length;
int idx = 0;
for (AnalysisMethod aMethod : callees) {
ResolvedJavaMethod convertedMethod = converter == null ? aMethod : converter.lookup(aMethod);
pitems[idx++] = new ProfiledMethod(convertedMethod, probability);
}
return new JavaMethodProfile(0, pitems);
}
use of jdk.vm.ci.meta.JavaMethodProfile in project graal by oracle.
the class DevirtualizeCallsPhase method run.
@Override
protected void run(StructuredGraph graph) {
for (Invoke invoke : graph.getInvokes()) {
if (invoke.callTarget() instanceof SubstrateMethodCallTargetNode) {
SubstrateMethodCallTargetNode callTarget = (SubstrateMethodCallTargetNode) invoke.callTarget();
JavaMethodProfile methodProfile = callTarget.getMethodProfile();
if (methodProfile != null) {
if (methodProfile.getMethods().length == 0) {
unreachableInvoke(graph, invoke, callTarget);
} else if (methodProfile.getMethods().length == 1) {
if (callTarget.invokeKind().isIndirect()) {
singleCallee((HostedMethod) methodProfile.getMethods()[0].getMethod(), graph, invoke, callTarget);
}
}
}
}
}
}
use of jdk.vm.ci.meta.JavaMethodProfile in project graal by oracle.
the class StaticAnalysisResultsBuilder method makeMethodProfile.
private JavaMethodProfile makeMethodProfile(Collection<AnalysisMethod> callees) {
if (PointstoOptions.AnalysisSizeCutoff.getValue(bb.getOptions()) != -1 && callees.size() > PointstoOptions.AnalysisSizeCutoff.getValue(bb.getOptions())) {
return null;
}
if (callees.isEmpty()) {
synchronized (methods0) {
return cachedMethodProfile(methods0, 0, callees);
}
} else if (callees.size() == 1) {
synchronized (methods1) {
return cachedMethodProfile(methods1, callees.iterator().next().getId(), callees);
}
}
synchronized (methods) {
JavaMethodProfile created = createMethodProfile(callees);
methods.putIfAbsent(created, created);
return created;
}
}
use of jdk.vm.ci.meta.JavaMethodProfile 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);
}
Aggregations