11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * The Universal Permissive License (UPL), Version 1.0
4242
4343import com .oracle .truffle .api .CompilerDirectives ;
4444import com .oracle .truffle .api .frame .Frame ;
45+ import com .oracle .truffle .api .frame .FrameDescriptor ;
4546import com .oracle .truffle .api .frame .FrameSlotKind ;
4647
4748public abstract class FrameSlotGuards {
@@ -55,41 +56,73 @@ public static boolean isNotIllegal(Frame frame, int frameSlot) {
5556 }
5657
5758 public static boolean isBooleanKind (Frame frame , int frameSlot ) {
58- return isKind (frame , frameSlot , FrameSlotKind .Boolean );
59+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Boolean );
5960 }
6061
6162 public static boolean isIntegerKind (Frame frame , int frameSlot ) {
62- return isKind (frame , frameSlot , FrameSlotKind .Int );
63+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Int );
6364 }
6465
6566 public static boolean isLongKind (Frame frame , int frameSlot ) {
66- return isKind (frame , frameSlot , FrameSlotKind .Long );
67+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Long );
6768 }
6869
6970 public static boolean isDoubleKind (Frame frame , int frameSlot ) {
70- return isKind (frame , frameSlot , FrameSlotKind .Double );
71+ return isKind (frame . getFrameDescriptor () , frameSlot , FrameSlotKind .Double );
7172 }
7273
7374 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 );
7576 }
7677
7778 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 );
7980 }
8081
8182 public static void ensureObjectKind (Frame frame , int frameSlot ) {
8283 frame .getFrameDescriptor ().setSlotKind (frameSlot , FrameSlotKind .Object );
8384 }
8485
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 ;
8788 }
8889
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 ) {
91124 CompilerDirectives .transferToInterpreterAndInvalidate ();
92- frame . getFrameDescriptor () .setSlotKind (frameSlot , kind );
125+ descriptor .setSlotKind (frameSlot , kind );
93126 return true ;
94127 }
95128 return false ;
0 commit comments