1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 package org.graalvm.compiler.nodes; 26 27 import org.graalvm.compiler.debug.GraalError; 28 29 import jdk.vm.ci.meta.DeoptimizationAction; 30 import jdk.vm.ci.meta.DeoptimizationReason; 31 import jdk.vm.ci.meta.SpeculationLog; 32 import jdk.vm.ci.meta.SpeculationLog.Speculation; 33 34 public interface StaticDeoptimizingNode extends ValueNodeInterface { 35 getReason()36 DeoptimizationReason getReason(); 37 setReason(DeoptimizationReason reason)38 void setReason(DeoptimizationReason reason); 39 getAction()40 DeoptimizationAction getAction(); 41 setAction(DeoptimizationAction action)42 void setAction(DeoptimizationAction action); 43 getSpeculation()44 Speculation getSpeculation(); 45 46 /** 47 * Describes how much information is gathered when deoptimization triggers. 48 * 49 * This enum is {@link Comparable} and orders its element from highest priority to lowest 50 * priority. 51 */ 52 enum GuardPriority { 53 Speculation, 54 Profile, 55 None; 56 isHigherPriorityThan(GuardPriority other)57 public boolean isHigherPriorityThan(GuardPriority other) { 58 return this.compareTo(other) < 0; 59 } 60 isLowerPriorityThan(GuardPriority other)61 public boolean isLowerPriorityThan(GuardPriority other) { 62 return this.compareTo(other) > 0; 63 } 64 highest()65 public static GuardPriority highest() { 66 return Speculation; 67 } 68 } 69 computePriority()70 default GuardPriority computePriority() { 71 assert getSpeculation() != null; 72 if (!getSpeculation().equals(SpeculationLog.NO_SPECULATION)) { 73 return GuardNode.GuardPriority.Speculation; 74 } 75 switch (getAction()) { 76 case InvalidateReprofile: 77 case InvalidateRecompile: 78 return GuardNode.GuardPriority.Profile; 79 case RecompileIfTooManyDeopts: 80 case InvalidateStopCompiling: 81 case None: 82 return GuardNode.GuardPriority.None; 83 } 84 throw GraalError.shouldNotReachHere(); 85 } 86 mergeActions(DeoptimizationAction a1, DeoptimizationAction a2)87 static DeoptimizationAction mergeActions(DeoptimizationAction a1, DeoptimizationAction a2) { 88 if (a1 == a2) { 89 return a1; 90 } 91 if (a1 == DeoptimizationAction.InvalidateRecompile && a2 == DeoptimizationAction.InvalidateReprofile || 92 a1 == DeoptimizationAction.InvalidateReprofile && a2 == DeoptimizationAction.InvalidateRecompile) { 93 return DeoptimizationAction.InvalidateReprofile; 94 } 95 return null; 96 } 97 } 98