001/* 002 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.hotspot.replacements; 024 025import jdk.internal.jvmci.hotspot.*; 026import jdk.internal.jvmci.meta.*; 027 028import com.oracle.graal.graph.*; 029import com.oracle.graal.graph.spi.*; 030import com.oracle.graal.nodeinfo.*; 031import com.oracle.graal.nodes.CallTargetNode.InvokeKind; 032import com.oracle.graal.nodes.*; 033import com.oracle.graal.nodes.spi.*; 034import com.oracle.graal.replacements.nodes.*; 035 036@NodeInfo 037public final class CallSiteTargetNode extends MacroStateSplitNode implements Canonicalizable, Lowerable { 038 039 public static final NodeClass<CallSiteTargetNode> TYPE = NodeClass.create(CallSiteTargetNode.class); 040 041 public CallSiteTargetNode(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, int bci, JavaType returnType, ValueNode receiver) { 042 super(TYPE, invokeKind, targetMethod, bci, returnType, receiver); 043 } 044 045 private ValueNode getCallSite() { 046 return arguments.get(0); 047 } 048 049 public static ConstantNode tryFold(ValueNode callSite, MetaAccessProvider metaAccess, Assumptions assumptions) { 050 if (callSite != null && callSite.isConstant() && !callSite.isNullConstant()) { 051 HotSpotObjectConstant c = (HotSpotObjectConstant) callSite.asConstant(); 052 JavaConstant target = c.getCallSiteTarget(assumptions); 053 if (target != null) { 054 return ConstantNode.forConstant(target, metaAccess); 055 } 056 } 057 return null; 058 } 059 060 @Override 061 public Node canonical(CanonicalizerTool tool) { 062 ConstantNode target = tryFold(getCallSite(), tool.getMetaAccess(), graph().getAssumptions()); 063 if (target != null) { 064 return target; 065 } 066 067 return this; 068 } 069 070 @Override 071 public void lower(LoweringTool tool) { 072 ConstantNode target = tryFold(getCallSite(), tool.getMetaAccess(), graph().getAssumptions()); 073 074 if (target != null) { 075 graph().replaceFixedWithFloating(this, target); 076 } else { 077 InvokeNode invoke = createInvoke(); 078 graph().replaceFixedWithFixed(this, invoke); 079 invoke.lower(tool); 080 } 081 } 082}