|
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 package org.graalvm.compiler.nodes; |
|
24 |
|
25 import org.graalvm.compiler.debug.GraalError; |
|
26 |
|
27 import jdk.vm.ci.meta.DeoptimizationAction; |
|
28 import jdk.vm.ci.meta.DeoptimizationReason; |
|
29 import jdk.vm.ci.meta.JavaConstant; |
|
30 |
|
31 public interface StaticDeoptimizingNode extends ValueNodeInterface { |
|
32 |
|
33 DeoptimizationReason getReason(); |
|
34 |
|
35 DeoptimizationAction getAction(); |
|
36 |
|
37 JavaConstant getSpeculation(); |
|
38 |
|
39 /** |
|
40 * Describes how much information is gathered when deoptimization triggers. |
|
41 * |
|
42 * This enum is {@link Comparable} and orders its element from highest priority to lowest |
|
43 * priority. |
|
44 */ |
|
45 enum GuardPriority { |
|
46 Speculation, |
|
47 Profile, |
|
48 None; |
|
49 |
|
50 public boolean isHigherPriorityThan(GuardPriority other) { |
|
51 return this.compareTo(other) < 0; |
|
52 } |
|
53 |
|
54 public boolean isLowerPriorityThan(GuardPriority other) { |
|
55 return this.compareTo(other) > 0; |
|
56 } |
|
57 |
|
58 public static GuardPriority highest() { |
|
59 return Speculation; |
|
60 } |
|
61 } |
|
62 |
|
63 default GuardPriority computePriority() { |
|
64 if (getSpeculation() != null && getSpeculation().isNonNull()) { |
|
65 return GuardNode.GuardPriority.Speculation; |
|
66 } |
|
67 switch (getAction()) { |
|
68 case InvalidateReprofile: |
|
69 case InvalidateRecompile: |
|
70 return GuardNode.GuardPriority.Profile; |
|
71 case RecompileIfTooManyDeopts: |
|
72 case InvalidateStopCompiling: |
|
73 case None: |
|
74 return GuardNode.GuardPriority.None; |
|
75 } |
|
76 throw GraalError.shouldNotReachHere(); |
|
77 } |
|
78 } |