1 /*
2  * Copyright (c) 2001, 2018, 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 package nsk.jdi.MethodExitEvent.method;
25 
26 import nsk.share.*;
27 import nsk.share.jpda.*;
28 import nsk.share.jdi.*;
29 
30 import java.io.*;
31 
32 //    THIS TEST IS LINE NUMBER SENSITIVE
33 // This class is the debugged application in the test
34 public class method001a {
35 
36     // exit status constants
37     static final int PASSED = 0;
38     static final int FAILED = 2;
39     static final int JCK_STATUS_BASE = 95;
40 
41     // synchronization commands
42     static final String COMMAND_READY = "ready";
43     static final String COMMAND_QUIT  = "quit";
44     static final String COMMAND_GO    = "go";
45     static final String COMMAND_DONE  = "done";
46 
47     // line numbers for auxilary breakpoints
48     public static final int STARTING_BREAKPOINT_LINE = 86;
49     public static final int ENDING_BREAKPOINT_LINE = 91;
50 
51     // scaffold objects
52     static private ArgumentHandler argHandler;
53     static private Log log;
54     static private IOPipe pipe;
55 
56     // flags and counters
57     static private int flag;
58     static private int depth;
59     static private boolean methodInvoked;
60 
61     // start debuggee
main(String args[])62     public static void main(String args[]) {
63         method001a _method001a = new method001a();
64         System.exit(JCK_STATUS_BASE + _method001a.run(args, System.err));
65     }
66 
67     // perform the test
run(String args[], PrintStream out)68     int run(String args[], PrintStream out) {
69         argHandler = new ArgumentHandler(args);
70         log = new Log(out, argHandler);
71         pipe = argHandler.createDebugeeIOPipe();
72 
73         depth = 10;
74         flag = 0;
75 
76         // notify debugger that debuggee has been started
77         pipe.println(COMMAND_READY);
78 
79         // wait for GO commnad from debugger
80         String command = pipe.readln();
81         if (!command.equals(COMMAND_GO)) {
82             log.complain("TEST BUG: Debugee: unknown command: " + command);
83             return FAILED;
84         }
85 
86         methodInvoked = false; // STARTING_BREAKPOINT_LINE
87 
88         // invoke checked method
89         foo();
90 
91         methodInvoked = true; // ENDING_BREAKPOINT_LINE
92 
93         // notify debugger that checked method has been invoked
94         pipe.println(COMMAND_DONE);
95 
96         // wait for command QUIT from debugger
97         command = pipe.readln();
98         if (!command.equals(COMMAND_QUIT)) {
99             System.err.println("TEST BUG: Debugee: unknown command: " + command);
100             return FAILED;
101         }
102 
103         return PASSED;
104     }
105 
106     // checked method
foo()107     void foo() {
108         flag = 1;
109         if (depth > 1) {
110             depth--;
111             foo();
112         }
113         flag = 3;
114     }
115 }
116