1 /*
2 * Copyright (c) 2014, 2015, 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 */
180 // invoke the InterfaceA's "defaultMethodB"
181 testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
182
183 // invoke the InterfaceA's "defaultMethodC"
184 testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_A));
185
186 // "defaultMethodD" from InterfaceB is not accessible from here
187 testInvokeNeg(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B),
188 "Attempted to invoke non-existing method");
189
190 // trying to invoke the asbtract method "implementedMethod"
191 testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(TARGET_CLASS_NAME),
192 "Invocation of non-default methods is not supported");
193
194
195 /* Static method calls */
196
197 // invoke interface static method A
198 testInvokePos(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
199
200 // try to invoke static method A on the instance
201 testInvokePos(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
202
203 // invoke interface static method B
204 testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
205
206 // try to invoke static method B on the instance
207 testInvokePos(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
208
209 // try to invoke a virtual method
210 testInvokePos(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_A), true);
211 }
212
213 private void testInterfaceB(ObjectReference ref) {
214 // Test non-virtual calls on InterfaceB
215 ReferenceType ifaceClass = (ReferenceType)vm().classesByName(INTERFACEB_NAME).get(0);
216
217 /* Default method calls */
218
219 // invoke the inherited "defaultMethodA"
220 testInvokePos(ifaceClass, ref, "defaultMethodA", "()I", vm().mirrorOf(RESULT_A));
221
222 // invoke the inherited "defaultMethodB"
223 testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
224
225 // invoke the inherited and overridden "defaultMethodC"
226 testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_B));
227
228 // invoke InterfaceB only "defaultMethodD"
229 testInvokePos(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B));
230
231 // "implementedMethod" is not present in InterfaceB
232 testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_TARGET),
233 "Invocation of non-default methods is not supported");
234
235
236 /* Static method calls*/
237
238 // "staticMethodA" must not be inherited by InterfaceB
239 testInvokeNeg(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
240 "Static interface methods are not inheritable");
241
242 // however it is possible to call "staticMethodA" on the actual instance
243 testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
244 "Static interface methods are not inheritable");
245
246 // "staticMethodB" is overridden in InterfaceB
247 testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
248
249 // the instance invokes the overriden form of "staticMethodB" from InterfaceB
250 testInvokePos(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
251
252 // "staticMethodC" is present only in InterfaceB
253 testInvokePos(ifaceClass, null, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
254
255 // "staticMethodC" should be reachable from the instance too
256 testInvokePos(ifaceClass, ref, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
257 }
258
259 private void testImplementationClass(ReferenceType targetClass, ObjectReference thisObject) {
260 // Test invocations on the implementation object
261
262 /* Default method calls */
263
264 // "defaultMethodA" is accessible and not overridden
265 testInvokePos(targetClass, thisObject, "defaultMethodA", "()I", vm().mirrorOf(RESULT_TARGET));
266
267 // "defaultMethodB" is accessible and overridden in TargetClass
268 testInvokePos(targetClass, thisObject, "defaultMethodB", "()I", vm().mirrorOf(RESULT_TARGET));
269
270 // "defaultMethodC" is accessible and overridden in InterfaceB
271 testInvokePos(targetClass, thisObject, "defaultMethodC", "()I", vm().mirrorOf(RESULT_TARGET));
272
273 // "defaultMethodD" is accessible
274 testInvokePos(targetClass, thisObject, "defaultMethodD", "()I", vm().mirrorOf(RESULT_TARGET));
275
276
|
1 /*
2 * Copyright (c) 2014, 2016, 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 */
180 // invoke the InterfaceA's "defaultMethodB"
181 testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
182
183 // invoke the InterfaceA's "defaultMethodC"
184 testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_A));
185
186 // "defaultMethodD" from InterfaceB is not accessible from here
187 testInvokeNeg(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B),
188 "Attempted to invoke non-existing method");
189
190 // trying to invoke the asbtract method "implementedMethod"
191 testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(TARGET_CLASS_NAME),
192 "Invocation of non-default methods is not supported");
193
194
195 /* Static method calls */
196
197 // invoke interface static method A
198 testInvokePos(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
199
200 // invoking static method A on the instance fails because staticMethodA is not
201 // inherited by TargetClass.
202 testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
203 "Invalid MethodID");
204
205 // invoke interface static method B
206 testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
207
208 // invoking static method B on the instance fails because staticMethodB is not
209 // inherited by TargetClass.
210 testInvokeNeg(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_A),
211 "Invalid MethodID");
212
213 // try to invoke a virtual method
214 testInvokePos(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_A), true);
215 }
216
217 private void testInterfaceB(ObjectReference ref) {
218 // Test non-virtual calls on InterfaceB
219 ReferenceType ifaceClass = (ReferenceType)vm().classesByName(INTERFACEB_NAME).get(0);
220
221 /* Default method calls */
222
223 // invoke the inherited "defaultMethodA"
224 testInvokePos(ifaceClass, ref, "defaultMethodA", "()I", vm().mirrorOf(RESULT_A));
225
226 // invoke the inherited "defaultMethodB"
227 testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
228
229 // invoke the inherited and overridden "defaultMethodC"
230 testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_B));
231
232 // invoke InterfaceB only "defaultMethodD"
233 testInvokePos(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B));
234
235 // "implementedMethod" is not present in InterfaceB
236 testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_TARGET),
237 "Invocation of non-default methods is not supported");
238
239
240 /* Static method calls*/
241
242 // "staticMethodA" must not be inherited by InterfaceB
243 testInvokeNeg(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
244 "Static interface methods are not inheritable");
245
246 // "staticMethodA" is not inherited by InterfaceB even from an actual instance
247 testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
248 "Static interface methods are not inheritable");
249
250 // "staticMethodB" is re-defined in InterfaceB
251 testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
252
253 // the instance fails to invoke the re-defined form of "staticMethodB" from
254 // InterfaceB because staticMethodB is not inherited by TargetClass
255 testInvokeNeg(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_B),
256 "Invalid MethodID");
257
258 // "staticMethodC" is present only in InterfaceB
259 testInvokePos(ifaceClass, null, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
260
261 // "staticMethodC" is not reachable from the instance because staticMethodC
262 // is not inherited by TargetClass.
263 testInvokeNeg(ifaceClass, ref, "staticMethodC", "()I", vm().mirrorOf(RESULT_B),
264 "Invalid MethodID");
265 }
266
267 private void testImplementationClass(ReferenceType targetClass, ObjectReference thisObject) {
268 // Test invocations on the implementation object
269
270 /* Default method calls */
271
272 // "defaultMethodA" is accessible and not overridden
273 testInvokePos(targetClass, thisObject, "defaultMethodA", "()I", vm().mirrorOf(RESULT_TARGET));
274
275 // "defaultMethodB" is accessible and overridden in TargetClass
276 testInvokePos(targetClass, thisObject, "defaultMethodB", "()I", vm().mirrorOf(RESULT_TARGET));
277
278 // "defaultMethodC" is accessible and overridden in InterfaceB
279 testInvokePos(targetClass, thisObject, "defaultMethodC", "()I", vm().mirrorOf(RESULT_TARGET));
280
281 // "defaultMethodD" is accessible
282 testInvokePos(targetClass, thisObject, "defaultMethodD", "()I", vm().mirrorOf(RESULT_TARGET));
283
284
|