Search in sources :

Example 1 with HotSpotResolvedObjectType

use of jdk.vm.ci.hotspot.HotSpotResolvedObjectType 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;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 2 with HotSpotResolvedObjectType

use of jdk.vm.ci.hotspot.HotSpotResolvedObjectType in project graal by oracle.

the class AOTInliningPolicy method isWorthInlining.

@Override
public boolean isWorthInlining(Replacements replacements, MethodInvocation invocation, int inliningDepth, boolean fullyProcessed) {
    final InlineInfo info = invocation.callee();
    for (int i = 0; i < info.numberOfMethods(); ++i) {
        HotSpotResolvedObjectType t = (HotSpotResolvedObjectType) info.methodAt(i).getDeclaringClass();
        if (t.getFingerprint() == 0) {
            return false;
        }
    }
    final double probability = invocation.probability();
    final double relevance = invocation.relevance();
    OptionValues options = info.graph().getOptions();
    if (InlineEverything.getValue(options)) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "inline everything");
        return true;
    }
    if (isIntrinsic(replacements, info)) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "intrinsic");
        return true;
    }
    if (info.shouldInline()) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "forced inlining");
        return true;
    }
    double inliningBonus = getInliningBonus(info);
    int nodes = info.determineNodeCount();
    if (nodes < TrivialInliningSize.getValue(options) * inliningBonus) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "trivial (relevance=%f, probability=%f, bonus=%f, nodes=%d)", relevance, probability, inliningBonus, nodes);
        return true;
    }
    double maximumNodes = computeMaximumSize(relevance, (int) (maxInliningSize(inliningDepth, options) * inliningBonus));
    if (nodes <= maximumNodes) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "relevance-based (relevance=%f, probability=%f, bonus=%f, nodes=%d <= %f)", relevance, probability, inliningBonus, nodes, maximumNodes);
        return true;
    }
    InliningUtil.traceNotInlinedMethod(info, inliningDepth, "relevance-based (relevance=%f, probability=%f, bonus=%f, nodes=%d > %f)", relevance, probability, inliningBonus, nodes, maximumNodes);
    return false;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) InlineInfo(org.graalvm.compiler.phases.common.inlining.info.InlineInfo)

Example 3 with HotSpotResolvedObjectType

use of jdk.vm.ci.hotspot.HotSpotResolvedObjectType in project graal by oracle.

the class HotSpotClassInitializationPlugin method apply.

@Override
public ValueNode apply(GraphBuilderContext builder, ResolvedJavaType type, FrameState frameState) {
    assert shouldApply(builder, type);
    Stamp hubStamp = builder.getStampProvider().createHubStamp((ObjectStamp) StampFactory.objectNonNull());
    ConstantNode hub = builder.append(ConstantNode.forConstant(hubStamp, ((HotSpotResolvedObjectType) type).klass(), builder.getMetaAccess(), builder.getGraph()));
    DeoptimizingFixedWithNextNode result = builder.append(type.isArray() ? new ResolveConstantNode(hub) : new InitializeKlassNode(hub));
    result.setStateBefore(frameState);
    return result;
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode)

Example 4 with HotSpotResolvedObjectType

use of jdk.vm.ci.hotspot.HotSpotResolvedObjectType in project graal by oracle.

the class NewArrayStub method makeConstArgs.

@Override
protected Object[] makeConstArgs() {
    HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) providers.getMetaAccess().lookupJavaType(int[].class);
    int count = method.getSignature().getParameterCount(false);
    Object[] args = new Object[count];
    assert checkConstArg(3, "intArrayHub");
    assert checkConstArg(4, "threadRegister");
    assert checkConstArg(5, "options");
    args[3] = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), intArrayType.klass(), null);
    args[4] = providers.getRegisters().getThreadRegister();
    args[5] = options;
    return args;
}
Also used : HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) StubUtil.verifyObject(org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject)

Example 5 with HotSpotResolvedObjectType

use of jdk.vm.ci.hotspot.HotSpotResolvedObjectType in project graal by oracle.

the class NewInstanceStub method makeConstArgs.

@Override
protected Object[] makeConstArgs() {
    HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) providers.getMetaAccess().lookupJavaType(int[].class);
    int count = method.getSignature().getParameterCount(false);
    Object[] args = new Object[count];
    assert checkConstArg(1, "intArrayHub");
    assert checkConstArg(2, "threadRegister");
    assert checkConstArg(3, "options");
    args[1] = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), intArrayType.klass(), null);
    args[2] = providers.getRegisters().getThreadRegister();
    args[3] = options;
    return args;
}
Also used : HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) StubUtil.verifyObject(org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject)

Aggregations

HotSpotResolvedObjectType (jdk.vm.ci.hotspot.HotSpotResolvedObjectType)12 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)4 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4 HotSpotResolvedJavaField (jdk.vm.ci.hotspot.HotSpotResolvedJavaField)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)2 StubUtil.verifyObject (org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 Test (org.junit.Test)2 File (java.io.File)1 Reference (java.lang.ref.Reference)1 WeakReference (java.lang.ref.WeakReference)1 Method (java.lang.reflect.Method)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 JarFile (java.util.jar.JarFile)1