/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package nsk.jdi.ObjectReference.invokeMethod;
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
import java.util.*;
import java.io.*;
import nsk.share.*;
import nsk.share.jpda.*;
import nsk.share.jdi.*;
/**
* The test checks that virtual and non-virtual method invocation
* will be performed properly through the JDI method
* com.sun.jdi.ObjectReference.invokeMethod()
.
* A debugger part of the test invokes several debuggee methods,
* overriden in an object reference class, but obtained from
* a reference type of its superclass. The debugger calls the
* JDI method with and without the flag ObjectReference.INVOKE_NONVIRTUAL
* sequentially. It is expected, that methods from the superclass
* instead of from the object reference class will be invoked with
* the flag and vise versa otherwise.
*/
public class invokemethod009 {
// debuggee classes
static final String DEBUGGEE_CLASSES[] = {
"nsk.jdi.ObjectReference.invokeMethod.invokemethod009t",
"nsk.jdi.ObjectReference.invokeMethod.invokemethod009tDummySuperClass",
"nsk.jdi.ObjectReference.invokeMethod.invokemethod009tDummySuperSuperClass"
};
// name of debuggee main thread
static final String DEBUGGEE_THRNAME = "invokemethod009tThr";
// debuggee source line where it should be stopped
static final int DEBUGGEE_STOPATLINE = 69;
// debuggee local var used to find needed stack frame
static final String DEBUGGEE_LOCALVAR =
"invokemethod009tdummyCls";
// tested debuggee methods to be invoked, reference type numbers
// and expected return values
static final int METH_NUM = 4;
static final String DEBUGGEE_METHODS[][] = {
{"longProtMeth", "1", "9223372036854775806"},
{"longMeth", "1", "9223372036854775806"},
{"longProtMeth", "2", "9223372036854775805"},
{"longMeth", "2", "9223372036854775805"}
};
static final int TIMEOUT_DELTA = 1000; // in milliseconds
static final String COMMAND_READY = "ready";
static final String COMMAND_GO = "go";
static final String COMMAND_QUIT = "quit";
private ArgumentHandler argHandler;
private Log log;
private IOPipe pipe;
private Debugee debuggee;
private VirtualMachine vm;
private ThreadReference thrRef = null;
private BreakpointRequest BPreq;
private volatile int tot_res = Consts.TEST_PASSED;
private volatile boolean gotEvent = false;
public static void main (String argv[]) {
System.exit(run(argv,System.out) + Consts.JCK_STATUS_BASE);
}
public static int run(String argv[], PrintStream out) {
return new invokemethod009().runIt(argv, out);
}
private int runIt(String args[], PrintStream out) {
argHandler = new ArgumentHandler(args);
log = new Log(out, argHandler);
Binder binder = new Binder(argHandler, log);
String cmd;
int num = 0;
debuggee = binder.bindToDebugee(DEBUGGEE_CLASSES[0]);
pipe = debuggee.createIOPipe();
vm = debuggee.VM();
debuggee.redirectStderr(log, "invokemethod009t.err> ");
debuggee.resume();
cmd = pipe.readln();
if (!cmd.equals(COMMAND_READY)) {
log.complain("TEST BUG: unknown debuggee command: " + cmd);
tot_res = Consts.TEST_FAILED;
return quitDebuggee();
}
if ((thrRef =
debuggee.threadByName(DEBUGGEE_THRNAME)) == null) {
log.complain("TEST FAILURE: Method Debugee.threadByName() returned null for debuggee thread "
+ DEBUGGEE_THRNAME);
tot_res = Consts.TEST_FAILED;
return quitDebuggee();
}
ReferenceType[] rType = new ReferenceType[3];
// reference types of debuggee main & dummy classes
rType[0] = debuggee.classByName(DEBUGGEE_CLASSES[0]);
rType[1] = debuggee.classByName(DEBUGGEE_CLASSES[1]);
rType[2] = debuggee.classByName(DEBUGGEE_CLASSES[2]);
// Check the tested assersion
try {
suspendAtBP(rType[0], DEBUGGEE_STOPATLINE);
ObjectReference objRef = findObjRef(DEBUGGEE_LOCALVAR);
LinkedList argList = new LinkedList();
argList.add(vm.mirrorOf(9223372036854775807L));
for (int i=0; i