use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class HotSpotTruffleRuntime method setDontInlineCallBoundaryMethod.
/**
* Prevents C1 or C2 from inlining a call to a method annotated by {@link TruffleCallBoundary}
* so that we never miss the chance to switch from the Truffle interpreter to compiled code.
*
* @see HotSpotTruffleCompiler#installTruffleCallBoundaryMethods()
*/
public static void setDontInlineCallBoundaryMethod() {
MetaAccessProvider metaAccess = getMetaAccess();
ResolvedJavaType type = metaAccess.lookupJavaType(OptimizedCallTarget.class);
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
if (method.getAnnotation(TruffleCallBoundary.class) != null) {
setNotInlinableOrCompilable(method);
}
}
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.
private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
if (constant instanceof HotSpotObjectConstant) {
ConstantReflectionProvider constantReflection = context.getConstantReflection();
ResolvedJavaType type = constantReflection.asJavaType(constant);
if (type != null) {
MetaAccessProvider metaAccess = context.getMetaAccess();
Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
if (type instanceof HotSpotResolvedObjectType) {
ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
if (((HotSpotObjectConstant) constant).isCompressed()) {
return HotSpotCompressionNode.compress(getClass, oopEncoding);
} else {
return getClass;
}
} else {
/*
* Primitive classes are more difficult since they don't have a corresponding
* Klass* so get them from Class.TYPE for the java box type.
*/
HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
HotSpotResolvedJavaField typeField = null;
for (HotSpotResolvedJavaField f : a) {
if (f.getName().equals("TYPE")) {
typeField = f;
break;
}
}
if (typeField == null) {
throw new GraalError("Can't find TYPE field in class");
}
if (oopEncoding != null) {
stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
}
AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
return read;
} else {
return HotSpotCompressionNode.uncompress(read, oopEncoding);
}
}
}
}
return null;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class ReadNode method canonicalizeRead.
public static ValueNode canonicalizeRead(ValueNode read, AddressNode address, LocationIdentity locationIdentity, CanonicalizerTool tool) {
NodeView view = NodeView.from(tool);
MetaAccessProvider metaAccess = tool.getMetaAccess();
if (tool.canonicalizeReads() && address instanceof OffsetAddressNode) {
OffsetAddressNode objAddress = (OffsetAddressNode) address;
ValueNode object = objAddress.getBase();
if (metaAccess != null && object.isConstant() && !object.isNullConstant() && objAddress.getOffset().isConstant()) {
long displacement = objAddress.getOffset().asJavaConstant().asLong();
int stableDimension = ((ConstantNode) object).getStableDimension();
if (locationIdentity.isImmutable() || stableDimension > 0) {
Constant constant = read.stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), object.asConstant(), displacement);
boolean isDefaultStable = locationIdentity.isImmutable() || ((ConstantNode) object).isDefaultStable();
if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
return ConstantNode.forConstant(read.stamp(view), constant, Math.max(stableDimension - 1, 0), isDefaultStable, metaAccess);
}
}
}
if (locationIdentity.equals(ARRAY_LENGTH_LOCATION)) {
ValueNode length = GraphUtil.arrayLength(object);
if (length != null) {
return length;
}
}
if (locationIdentity instanceof CanonicalizableLocation) {
CanonicalizableLocation canonicalize = (CanonicalizableLocation) locationIdentity;
ValueNode result = canonicalize.canonicalizeRead(read, address, object, tool);
assert result != null && result.stamp(view).isCompatible(read.stamp(view));
return result;
}
}
return read;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class StampFactoryTest method testParameters.
@Test
public void testParameters() throws NoSuchMethodException, SecurityException {
Method method = StampFactoryTest.class.getMethod("test", Integer.TYPE, Object.class, Double.TYPE);
MetaAccessProvider metaAccess = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders().getMetaAccess();
Stamp[] parameterStamps = StampFactory.createParameterStamps(null, metaAccess.lookupJavaMethod(method));
Stamp[] expected = { StampFactory.objectNonNull(TypeReference.createWithoutAssumptions(metaAccess.lookupJavaType(StampFactoryTest.class))), StampFactory.forKind(JavaKind.Int), StampFactory.object(TypeReference.createWithoutAssumptions(metaAccess.lookupJavaType(Object.class))), StampFactory.forKind(JavaKind.Double) };
Assert.assertArrayEquals(expected, parameterStamps);
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class HotSpotTruffleCompilerImpl method compileTruffleCallBoundaryMethod.
/**
* Compiles a method denoted as a
* {@linkplain HotSpotTruffleCompilerRuntime#getTruffleCallBoundaryMethods() Truffle call
* boundary}. The compiled code has a special entry point generated by an
* {@link TruffleCallBoundaryInstrumentationFactory}.
*/
private CompilationResult compileTruffleCallBoundaryMethod(ResolvedJavaMethod javaMethod, CompilationIdentifier compilationId, DebugContext debug) {
Suites newSuites = this.suites.copy();
removeInliningPhase(newSuites);
OptionValues options = TruffleCompilerOptions.getOptions();
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.NO).method(javaMethod).compilationId(compilationId).build();
MetaAccessProvider metaAccess = providers.getMetaAccess();
Plugins plugins = new Plugins(new InvocationPlugins());
HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) providers.getCodeCache();
boolean infoPoints = codeCache.shouldDebugNonSafepoints();
GraphBuilderConfiguration newConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true).withNodeSourcePosition(infoPoints);
new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), newConfig, OptimisticOptimizations.ALL, null).apply(graph);
PhaseSuite<HighTierContext> graphBuilderSuite = getGraphBuilderSuite(codeCache, backend.getSuites());
CompilationResultBuilderFactory factory = getTruffleCallBoundaryInstrumentationFactory(backend.getTarget().arch.getName());
return compileGraph(graph, javaMethod, providers, backend, graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), newSuites, lirSuites, new CompilationResult(compilationId), factory);
}
Aggregations