1 /* 2 * Copyright (c) 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 */ 23 24 /** 25 * @test 26 * @bug 8075331 27 * @summary Verify that we can call varargs methods 28 * @run build TestScaffold VMConnection TargetAdapter TargetListener 29 * @run compile -g InvokeVarArgs.java 30 * @run driver InvokeVarArgs 31 */ 32 33 import com.sun.jdi.*; 34 import com.sun.jdi.event.*; 35 import java.util.Arrays; 36 37 interface MyInterface { 38 } 39 40 class SomeClass implements MyInterface { 41 } 42 43 class InvokeVarArgsTarg { 44 45 public static void main(String args[]) { 46 new InvokeVarArgsTarg().run(); 47 } 48 49 SomeClass someClass1 = new SomeClass(); 50 SomeClass someClass2 = new SomeClass(); 51 52 MyInterface[] array = new MyInterface[]{someClass1, someClass2}; 53 SomeClass[] array2 = new SomeClass[]{someClass1, someClass2}; 54 55 public void run() { 56 System.out.println("size(array) : " + size(array)); 57 System.out.println("size(array2) : " + size(array2)); 58 } 59 60 int size(Object... value) { 61 return value.length; 62 } 63 } 64 65 public class InvokeVarArgs extends TestScaffold { 66 67 public static void main(String args[]) throws Exception { 68 new InvokeVarArgs(args).startTests(); 69 } 70 71 InvokeVarArgs(String args[]) throws Exception { 72 super(args); 73 } 74 75 protected void runTests() throws Exception { 76 77 BreakpointEvent bpe = startTo("InvokeVarArgsTarg", "run", "()V"); 78 StackFrame frame = bpe.thread().frame(0); 79 ObjectReference targetObj = frame.thisObject(); 80 ReferenceType targetType = (ReferenceType) targetObj.type(); 81 Value arrayVal = targetObj.getValue(targetType.fieldByName("array")); 82 Value array2Val = targetObj.getValue(targetType.fieldByName("array2")); 83 Method sizeMethod = targetType.methodsByName("size", "([Ljava/lang/Object;)I").get(0); 84 85 IntegerValue size = (IntegerValue) targetObj.invokeMethod(bpe.thread(), sizeMethod, Arrays.asList(new Value[]{arrayVal}), 0); 86 if (size.value() != 2) { 87 throw new Exception("size(array) should be 2, but was " + size.value()); 88 } 89 90 size = (IntegerValue) targetObj.invokeMethod(bpe.thread(), sizeMethod, Arrays.asList(new Value[]{array2Val}), 0); 91 if (size.value() != 2) { 92 throw new Exception("size(array2) should be 2, but was " + size.value()); 93 } 94 95 listenUntilVMDisconnect(); 96 } 97 }