001/* 002 * Copyright (c) 2009, 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.nodes; 024 025import com.oracle.graal.debug.*; 026import jdk.internal.jvmci.meta.*; 027 028import com.oracle.graal.graph.*; 029import com.oracle.graal.nodeinfo.*; 030import com.oracle.graal.nodes.spi.*; 031 032@NodeInfo(shortName = "Deopt", nameTemplate = "Deopt {p#reason/s}") 033public final class DeoptimizeNode extends AbstractDeoptimizeNode implements Lowerable, LIRLowerable { 034 public static final int DEFAULT_DEBUG_ID = 0; 035 036 public static final NodeClass<DeoptimizeNode> TYPE = NodeClass.create(DeoptimizeNode.class); 037 protected final DeoptimizationAction action; 038 protected final DeoptimizationReason reason; 039 protected final int debugId; 040 protected final JavaConstant speculation; 041 042 public DeoptimizeNode(DeoptimizationAction action, DeoptimizationReason reason) { 043 this(action, reason, DEFAULT_DEBUG_ID, JavaConstant.NULL_POINTER, null); 044 } 045 046 public DeoptimizeNode(DeoptimizationAction action, DeoptimizationReason reason, JavaConstant speculation) { 047 this(action, reason, DEFAULT_DEBUG_ID, speculation, null); 048 } 049 050 public DeoptimizeNode(DeoptimizationAction action, DeoptimizationReason reason, int debugId, JavaConstant speculation, FrameState stateBefore) { 051 super(TYPE, stateBefore); 052 assert action != null; 053 assert reason != null; 054 assert speculation.getKind() == Kind.Object; 055 this.action = action; 056 this.reason = reason; 057 this.debugId = debugId; 058 this.speculation = speculation; 059 } 060 061 public DeoptimizationAction action() { 062 return action; 063 } 064 065 public DeoptimizationReason reason() { 066 return reason; 067 } 068 069 @Override 070 public void lower(LoweringTool tool) { 071 tool.getLowerer().lower(this, tool); 072 } 073 074 @SuppressWarnings("deprecation") 075 public int getDebugId() { 076 int deoptDebugId = debugId; 077 if (deoptDebugId == DEFAULT_DEBUG_ID && (Debug.isDumpEnabledForMethod() || Debug.isLogEnabledForMethod())) { 078 deoptDebugId = this.getId(); 079 } 080 return deoptDebugId; 081 } 082 083 @Override 084 public void generate(NodeLIRBuilderTool gen) { 085 gen.getLIRGeneratorTool().emitDeoptimize(gen.getLIRGeneratorTool().getMetaAccess().encodeDeoptActionAndReason(action, reason, getDebugId()), speculation, gen.state(this)); 086 } 087 088 @Override 089 public ValueNode getActionAndReason(MetaAccessProvider metaAccess) { 090 return ConstantNode.forConstant(metaAccess.encodeDeoptActionAndReason(action, reason, getDebugId()), metaAccess, graph()); 091 } 092 093 @Override 094 public ValueNode getSpeculation(MetaAccessProvider metaAccess) { 095 return ConstantNode.forConstant(speculation, metaAccess, graph()); 096 } 097 098 public JavaConstant getSpeculation() { 099 return speculation; 100 } 101 102 @NodeIntrinsic 103 public static native void deopt(@ConstantNodeParameter DeoptimizationAction action, @ConstantNodeParameter DeoptimizationReason reason); 104}