< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/CallingSequenceBuilder.java

Print this page

 83 
 84     private void verifyBindings(boolean forArguments, Class<?> carrier, List<Binding> bindings) {
 85         if (VERIFY_BINDINGS) {
 86             if (forUpcall == forArguments) {
 87                 verifyBoxBindings(carrier, bindings);
 88             } else {
 89                 verifyUnboxBindings(carrier, bindings);
 90             }
 91         }
 92     }
 93 
 94     private static final Set<Binding.Tag> UNBOX_TAGS = EnumSet.of(
 95         VM_STORE,
 96         //VM_LOAD,
 97         //BUFFER_STORE,
 98         BUFFER_LOAD,
 99         COPY_BUFFER,
100         //ALLOC_BUFFER,
101         //BOX_ADDRESS,
102         UNBOX_ADDRESS,
103         BASE_ADDRESS,
104         //TO_SEGMENT,
105         DUP
106     );
107 
108     private static void verifyUnboxBindings(Class<?> inType, List<Binding> bindings) {
109         Deque<Class<?>> stack = new ArrayDeque<>();
110         stack.push(inType);
111 
112         for (Binding b : bindings) {
113             if (!UNBOX_TAGS.contains(b.tag()))
114                 throw new IllegalArgumentException("Unexpected operator: " + b);
115             b.verify(stack);
116         }
117 
118         if (!stack.isEmpty()) {
119             throw new IllegalArgumentException("Stack must be empty after recipe");
120         }
121     }
122 
123     private static final Set<Binding.Tag> BOX_TAGS = EnumSet.of(
124         //VM_STORE,
125         VM_LOAD,
126         BUFFER_STORE,
127         //BUFFER_LOAD,
128         COPY_BUFFER,
129         ALLOC_BUFFER,
130         BOX_ADDRESS,
131         //UNBOX_ADDRESS,
132         //BASE_ADDRESS,
133         TO_SEGMENT,
134         DUP
135     );
136 
137     private static void verifyBoxBindings(Class<?> expectedOutType, List<Binding> bindings) {
138         Deque<Class<?>> stack = new ArrayDeque<>();
139 
140         for (Binding b : bindings) {
141             if (!BOX_TAGS.contains(b.tag()))
142                 throw new IllegalArgumentException("Unexpected operator: " + b);
143             b.verify(stack);
144         }
145 
146         if (stack.size() != 1) {
147             throw new IllegalArgumentException("Stack must contain exactly 1 value");
148         }
149 
150         Class<?> actualOutType = stack.pop();
151         SharedUtils.checkType(actualOutType, expectedOutType);
152     }

 83 
 84     private void verifyBindings(boolean forArguments, Class<?> carrier, List<Binding> bindings) {
 85         if (VERIFY_BINDINGS) {
 86             if (forUpcall == forArguments) {
 87                 verifyBoxBindings(carrier, bindings);
 88             } else {
 89                 verifyUnboxBindings(carrier, bindings);
 90             }
 91         }
 92     }
 93 
 94     private static final Set<Binding.Tag> UNBOX_TAGS = EnumSet.of(
 95         VM_STORE,
 96         //VM_LOAD,
 97         //BUFFER_STORE,
 98         BUFFER_LOAD,
 99         COPY_BUFFER,
100         //ALLOC_BUFFER,
101         //BOX_ADDRESS,
102         UNBOX_ADDRESS,

103         //TO_SEGMENT,
104         DUP
105     );
106 
107     private static void verifyUnboxBindings(Class<?> inType, List<Binding> bindings) {
108         Deque<Class<?>> stack = new ArrayDeque<>();
109         stack.push(inType);
110 
111         for (Binding b : bindings) {
112             if (!UNBOX_TAGS.contains(b.tag()))
113                 throw new IllegalArgumentException("Unexpected operator: " + b);
114             b.verify(stack);
115         }
116 
117         if (!stack.isEmpty()) {
118             throw new IllegalArgumentException("Stack must be empty after recipe");
119         }
120     }
121 
122     private static final Set<Binding.Tag> BOX_TAGS = EnumSet.of(
123         //VM_STORE,
124         VM_LOAD,
125         BUFFER_STORE,
126         //BUFFER_LOAD,
127         COPY_BUFFER,
128         ALLOC_BUFFER,
129         BOX_ADDRESS,
130         //UNBOX_ADDRESS,

131         TO_SEGMENT,
132         DUP
133     );
134 
135     private static void verifyBoxBindings(Class<?> expectedOutType, List<Binding> bindings) {
136         Deque<Class<?>> stack = new ArrayDeque<>();
137 
138         for (Binding b : bindings) {
139             if (!BOX_TAGS.contains(b.tag()))
140                 throw new IllegalArgumentException("Unexpected operator: " + b);
141             b.verify(stack);
142         }
143 
144         if (stack.size() != 1) {
145             throw new IllegalArgumentException("Stack must contain exactly 1 value");
146         }
147 
148         Class<?> actualOutType = stack.pop();
149         SharedUtils.checkType(actualOutType, expectedOutType);
150     }
< prev index next >