Mercurial > hg > graal-compiler
view graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadHubNode.java @ 23351:3bc2598ce1e0
Update JVMCI import: Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Mon, 25 Jan 2016 15:03:43 -0800 |
parents | 048985854416 |
children |
line wrap: on
line source
/* * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.nodes.extended; import jdk.vm.ci.meta.Assumptions; import jdk.vm.ci.meta.Assumptions.AssumptionResult; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaType; import com.oracle.graal.compiler.common.type.ObjectStamp; import com.oracle.graal.compiler.common.type.Stamp; import com.oracle.graal.graph.NodeClass; import com.oracle.graal.graph.spi.Canonicalizable; import com.oracle.graal.graph.spi.CanonicalizerTool; import com.oracle.graal.nodeinfo.NodeInfo; import com.oracle.graal.nodes.ConstantNode; import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.ValueNode; import com.oracle.graal.nodes.calc.FloatingNode; import com.oracle.graal.nodes.spi.Lowerable; import com.oracle.graal.nodes.spi.LoweringTool; import com.oracle.graal.nodes.spi.StampProvider; import com.oracle.graal.nodes.spi.Virtualizable; import com.oracle.graal.nodes.spi.VirtualizerTool; /** * Loads an object's hub. The object is not null-checked by this operation. */ @NodeInfo public final class LoadHubNode extends FloatingNode implements Lowerable, Canonicalizable, Virtualizable { public static final NodeClass<LoadHubNode> TYPE = NodeClass.create(LoadHubNode.class); @Input ValueNode value; public ValueNode getValue() { return value; } private static Stamp hubStamp(StampProvider stampProvider, ValueNode value) { assert value.stamp() instanceof ObjectStamp; return stampProvider.createHubStamp(((ObjectStamp) value.stamp())); } public static ValueNode create(ValueNode value, StampProvider stampProvider, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection) { Stamp stamp = hubStamp(stampProvider, value); ValueNode synonym = findSynonym(value, stamp, null, metaAccess, constantReflection); if (synonym != null) { return synonym; } return new LoadHubNode(stamp, value); } public LoadHubNode(@InjectedNodeParameter StampProvider stampProvider, ValueNode value) { this(hubStamp(stampProvider, value), value); } public LoadHubNode(Stamp stamp, ValueNode value) { super(TYPE, stamp); this.value = value; } @Override public void lower(LoweringTool tool) { tool.getLowerer().lower(this, tool); } @Override public ValueNode canonical(CanonicalizerTool tool) { MetaAccessProvider metaAccess = tool.getMetaAccess(); ValueNode curValue = getValue(); ValueNode newNode = findSynonym(curValue, stamp(), graph(), metaAccess, tool.getConstantReflection()); if (newNode != null) { return newNode; } return this; } public static ValueNode findSynonym(ValueNode curValue, Stamp stamp, StructuredGraph graph, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection) { ResolvedJavaType exactType = findSynonymType(graph, metaAccess, curValue); if (exactType != null) { return ConstantNode.forConstant(stamp, constantReflection.asObjectHub(exactType), metaAccess); } return null; } public static ResolvedJavaType findSynonymType(StructuredGraph graph, MetaAccessProvider metaAccess, ValueNode curValue) { ResolvedJavaType exactType = null; if (metaAccess != null && curValue.stamp() instanceof ObjectStamp) { ObjectStamp objectStamp = (ObjectStamp) curValue.stamp(); if (objectStamp.isExactType()) { exactType = objectStamp.type(); } else if (objectStamp.type() != null && graph != null) { Assumptions assumptions = graph.getAssumptions(); AssumptionResult<ResolvedJavaType> leafConcreteSubtype = objectStamp.type().findLeafConcreteSubtype(); if (leafConcreteSubtype != null && leafConcreteSubtype.canRecordTo(assumptions)) { leafConcreteSubtype.recordTo(assumptions); exactType = leafConcreteSubtype.getResult(); } } } return exactType; } @Override public void virtualize(VirtualizerTool tool) { ValueNode alias = tool.getAlias(getValue()); ResolvedJavaType type = findSynonymType(graph(), tool.getMetaAccessProvider(), alias); if (type != null) { tool.replaceWithValue(ConstantNode.forConstant(stamp(), tool.getConstantReflectionProvider().asObjectHub(type), tool.getMetaAccessProvider(), graph())); } } }