1
1
/*
2
- * Copyright (c) 2019, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
42
42
43
43
import com .oracle .truffle .api .CompilerDirectives ;
44
44
import com .oracle .truffle .api .frame .Frame ;
45
+ import com .oracle .truffle .api .frame .FrameDescriptor ;
45
46
import com .oracle .truffle .api .frame .FrameSlotKind ;
46
47
47
48
public abstract class FrameSlotGuards {
@@ -55,41 +56,73 @@ public static boolean isNotIllegal(Frame frame, int frameSlot) {
55
56
}
56
57
57
58
public static boolean isBooleanKind (Frame frame , int frameSlot ) {
58
- return isKind (frame , frameSlot , FrameSlotKind .Boolean );
59
+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Boolean );
59
60
}
60
61
61
62
public static boolean isIntegerKind (Frame frame , int frameSlot ) {
62
- return isKind (frame , frameSlot , FrameSlotKind .Int );
63
+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Int );
63
64
}
64
65
65
66
public static boolean isLongKind (Frame frame , int frameSlot ) {
66
- return isKind (frame , frameSlot , FrameSlotKind .Long );
67
+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Long );
67
68
}
68
69
69
70
public static boolean isDoubleKind (Frame frame , int frameSlot ) {
70
- return isKind (frame , frameSlot , FrameSlotKind .Double );
71
+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Double );
71
72
}
72
73
73
74
public static boolean isIntOrObjectKind (Frame frame , int frameSlot ) {
74
- return isKind (frame , frameSlot , FrameSlotKind .Int ) || isKind (frame , frameSlot , FrameSlotKind .Object );
75
+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Int ) || isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Object );
75
76
}
76
77
77
78
public static boolean isLongOrObjectKind (Frame frame , int frameSlot ) {
78
- return isKind (frame , frameSlot , FrameSlotKind .Long ) || isKind (frame , frameSlot , FrameSlotKind .Object );
79
+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Long ) || isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Object );
79
80
}
80
81
81
82
public static void ensureObjectKind (Frame frame , int frameSlot ) {
82
83
frame .getFrameDescriptor ().setSlotKind (frameSlot , FrameSlotKind .Object );
83
84
}
84
85
85
- private static boolean isKind ( Frame frame , int frameSlot , FrameSlotKind kind ) {
86
- return frame . getFrameDescriptor (). getSlotKind (frameSlot ) == kind || initialSetKind ( frame , frameSlot , kind ) ;
86
+ public static boolean isNotIllegal ( FrameDescriptor descriptor , int frameSlot ) {
87
+ return descriptor . getSlotKind (frameSlot ) != FrameSlotKind . Illegal ;
87
88
}
88
89
89
- private static boolean initialSetKind (Frame frame , int frameSlot , FrameSlotKind kind ) {
90
- if (frame .getFrameDescriptor ().getSlotKind (frameSlot ) == FrameSlotKind .Illegal ) {
90
+ public static boolean isBooleanKind (FrameDescriptor descriptor , int frameSlot ) {
91
+ return isKind (descriptor , frameSlot , FrameSlotKind .Boolean );
92
+ }
93
+
94
+ public static boolean isIntegerKind (FrameDescriptor descriptor , int frameSlot ) {
95
+ return isKind (descriptor , frameSlot , FrameSlotKind .Int );
96
+ }
97
+
98
+ public static boolean isLongKind (FrameDescriptor descriptor , int frameSlot ) {
99
+ return isKind (descriptor , frameSlot , FrameSlotKind .Long );
100
+ }
101
+
102
+ public static boolean isDoubleKind (FrameDescriptor descriptor , int frameSlot ) {
103
+ return isKind (descriptor , frameSlot , FrameSlotKind .Double );
104
+ }
105
+
106
+ public static boolean isIntOrObjectKind (FrameDescriptor descriptor , int frameSlot ) {
107
+ return isKind (descriptor , frameSlot , FrameSlotKind .Int ) || isKind (descriptor , frameSlot , FrameSlotKind .Object );
108
+ }
109
+
110
+ public static boolean isLongOrObjectKind (FrameDescriptor descriptor , int frameSlot ) {
111
+ return isKind (descriptor , frameSlot , FrameSlotKind .Long ) || isKind (descriptor , frameSlot , FrameSlotKind .Object );
112
+ }
113
+
114
+ public static void ensureObjectKind (FrameDescriptor descriptor , int frameSlot ) {
115
+ descriptor .setSlotKind (frameSlot , FrameSlotKind .Object );
116
+ }
117
+
118
+ private static boolean isKind (FrameDescriptor descriptor , int frameSlot , FrameSlotKind kind ) {
119
+ return descriptor .getSlotKind (frameSlot ) == kind || initialSetKind (descriptor , frameSlot , kind );
120
+ }
121
+
122
+ private static boolean initialSetKind (FrameDescriptor descriptor , int frameSlot , FrameSlotKind kind ) {
123
+ if (descriptor .getSlotKind (frameSlot ) == FrameSlotKind .Illegal ) {
91
124
CompilerDirectives .transferToInterpreterAndInvalidate ();
92
- frame . getFrameDescriptor () .setSlotKind (frameSlot , kind );
125
+ descriptor .setSlotKind (frameSlot , kind );
93
126
return true ;
94
127
}
95
128
return false ;
0 commit comments