ClassIsAssignableFromNode.java revision 13017:134219a5b0ec
10SN/A/*
20SN/A * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
30SN/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42362SN/A *
50SN/A * This code is free software; you can redistribute it and/or modify it
60SN/A * under the terms of the GNU General Public License version 2 only, as
70SN/A * published by the Free Software Foundation.
80SN/A *
92362SN/A * This code is distributed in the hope that it will be useful, but WITHOUT
100SN/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112362SN/A * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
120SN/A * version 2 for more details (a copy is included in the LICENSE file that
130SN/A * accompanied this code).
140SN/A *
150SN/A * You should have received a copy of the GNU General Public License version
160SN/A * 2 along with this work; if not, write to the Free Software Foundation,
170SN/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
180SN/A *
190SN/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
200SN/A * or visit www.oracle.com if you need additional information or have any
210SN/A * questions.
220SN/A */
232362SN/Apackage org.graalvm.compiler.nodes.java;
242362SN/A
252362SN/Aimport static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_32;
260SN/Aimport static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_32;
270SN/A
280SN/Aimport org.graalvm.compiler.core.common.type.Stamp;
290SN/Aimport org.graalvm.compiler.graph.Node;
300SN/Aimport org.graalvm.compiler.graph.NodeClass;
310SN/Aimport org.graalvm.compiler.graph.spi.Canonicalizable;
320SN/Aimport org.graalvm.compiler.graph.spi.CanonicalizerTool;
330SN/Aimport org.graalvm.compiler.nodeinfo.NodeInfo;
340SN/Aimport org.graalvm.compiler.nodes.BinaryOpLogicNode;
350SN/Aimport org.graalvm.compiler.nodes.LogicConstantNode;
360SN/Aimport org.graalvm.compiler.nodes.ValueNode;
370SN/Aimport org.graalvm.compiler.nodes.spi.Lowerable;
380SN/Aimport org.graalvm.compiler.nodes.spi.LoweringTool;
390SN/A
400SN/Aimport jdk.vm.ci.meta.ConstantReflectionProvider;
410SN/Aimport jdk.vm.ci.meta.ResolvedJavaType;
420SN/Aimport jdk.vm.ci.meta.TriState;
430SN/A
440SN/A/**
450SN/A * The {@code ClassIsAssignableFromNode} represents a type check against {@link Class} instead of
460SN/A * against instances. This is used, for instance, to intrinsify
470SN/A * {@link Class#isAssignableFrom(Class)} .
480SN/A */
490SN/A@NodeInfo(cycles = CYCLES_32, size = SIZE_32)
500SN/Apublic final class ClassIsAssignableFromNode extends BinaryOpLogicNode implements Canonicalizable.Binary<ValueNode>, Lowerable {
510SN/A
520SN/A    public static final NodeClass<ClassIsAssignableFromNode> TYPE = NodeClass.create(ClassIsAssignableFromNode.class);
530SN/A
540SN/A    public ClassIsAssignableFromNode(ValueNode thisClass, ValueNode otherClass) {
550SN/A        super(TYPE, thisClass, otherClass);
560SN/A    }
570SN/A
580SN/A    public ValueNode getThisClass() {
590SN/A        return getX();
600SN/A    }
610SN/A
620SN/A    public ValueNode getOtherClass() {
630SN/A        return getY();
640SN/A    }
650SN/A
660SN/A    @Override
670SN/A    public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
680SN/A        if (forX.isConstant() && forY.isConstant()) {
690SN/A            ConstantReflectionProvider constantReflection = tool.getConstantReflection();
700SN/A            ResolvedJavaType thisType = constantReflection.asJavaType(forX.asJavaConstant());
710SN/A            ResolvedJavaType otherType = constantReflection.asJavaType(forY.asJavaConstant());
720SN/A            if (thisType != null && otherType != null) {
730SN/A                return LogicConstantNode.forBoolean(thisType.isAssignableFrom(otherType));
740SN/A            }
750SN/A        }
760SN/A        return this;
770SN/A    }
780SN/A
790SN/A    @Override
800SN/A    public void lower(LoweringTool tool) {
810SN/A        tool.getLowerer().lower(this, tool);
820SN/A    }
830SN/A
840SN/A    @Override
850SN/A    public Stamp getSucceedingStampForX(boolean negated, Stamp xStamp, Stamp yStamp) {
860SN/A        return null;
870SN/A    }
880SN/A
890SN/A    @Override
900SN/A    public Stamp getSucceedingStampForY(boolean negated, Stamp xStamp, Stamp yStamp) {
910SN/A        return null;
920SN/A    }
930SN/A
940SN/A    @Override
950SN/A    public TriState tryFold(Stamp xStamp, Stamp yStamp) {
960SN/A        return TriState.UNKNOWN;
970SN/A    }
980SN/A
990SN/A}
1000SN/A