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.StepRequest.addClassFilter_rt;
25 
26 import nsk.share.*;
27 import nsk.share.jpda.*;
28 import nsk.share.jdi.*;
29 
30 /**
31  * This class is used as debuggee application for the filter_rt002 JDI test.
32  */
33 
34 public class filter_rt002a {
35 
36     //----------------------------------------------------- templete section
37 
38     static final int PASSED = 0;
39     static final int FAILED = 2;
40     static final int PASS_BASE = 95;
41 
42     static ArgumentHandler argHandler;
43     static Log log;
44 
45     //--------------------------------------------------   log procedures
46 
log1(String message)47     public static void log1(String message) {
48         log.display("**> debuggee: " + message);
49     }
50 
logErr(String message)51     private static void logErr(String message) {
52         log.complain("**> debuggee: " + message);
53     }
54 
55     //====================================================== test program
56 
57     static Thread1filter_rt002a thread1 = null;
58 
59     static filter_rt002aTestClass10 obj = new filter_rt002aTestClass10();
60 
61     //------------------------------------------------------ common section
62 
63     static int exitCode = PASSED;
64 
65     static int instruction = 1;
66     static int end         = 0;
67                                    //    static int quit        = 0;
68                                    //    static int continue    = 2;
69     static int maxInstr    = 1;    // 2;
70 
71     static int lineForComm = 2;
72 
methodForCommunication()73     private static void methodForCommunication() {
74         int i1 = instruction;
75         int i2 = i1;
76         int i3 = i2;
77     }
78     //----------------------------------------------------   main method
79 
main(String argv[])80     public static void main (String argv[]) {
81 
82         argHandler = new ArgumentHandler(argv);
83         log = argHandler.createDebugeeLog();
84 
85         log1("debuggee started!");
86 
87         label0:
88             for (int i = 0; ; i++) {
89 
90                 if (instruction > maxInstr) {
91                     logErr("ERROR: unexpected instruction: " + instruction);
92                     exitCode = FAILED;
93                     break ;
94                 }
95 
96                 switch (i) {
97 
98     //------------------------------------------------------  section tested
99 
100                     case 0:
101                             thread1 = new Thread1filter_rt002a("thread1");
102 
103                             synchronized (lockObj) {
104                                 threadStart(thread1);
105                                 log1("methodForCommunication();----");
106                                 methodForCommunication();
107                             }
108 
109     //-------------------------------------------------    standard end section
110 
111                     default:
112                                 instruction = end;
113                                 break;
114                 }
115 
116 
117                 log1("methodForCommunication();");
118                 methodForCommunication();
119                 if (instruction == end)
120                     break;
121 
122 
123             }
124 
125         log1("debuggee exits");
126         System.exit(exitCode + PASS_BASE);
127     }
128 
129     static Object lockObj       = new Object();
130     static Object waitnotifyObj = new Object();
131 
threadStart(Thread t)132     static int threadStart(Thread t) {
133         synchronized (waitnotifyObj) {
134             t.start();
135             try {
136                 waitnotifyObj.wait();
137             } catch ( Exception e) {
138                 exitCode = FAILED;
139                 logErr("       Exception : " + e );
140                 return FAILED;
141             }
142         }
143         return PASSED;
144     }
145 }
146 
147 class filter_rt002aTestClass10{
m10()148     static void m10() {
149         filter_rt002a.log1("entered: m10");
150     }
151 }
152 class filter_rt002aTestClass11 extends filter_rt002aTestClass10{
m11()153     static void m11() {
154         filter_rt002a.log1("entered: m11");
155         filter_rt002aTestClass10.m10();
156     }
157 }
158 
159 class Thread1filter_rt002a extends Thread {
160 
161     String tName = null;
162 
Thread1filter_rt002a(String threadName)163     public Thread1filter_rt002a(String threadName) {
164         super(threadName);
165         tName = threadName;
166     }
167 
run()168     public void run() {
169         filter_rt002a.log1("  'run': enter  :: threadName == " + tName);
170         synchronized(filter_rt002a.waitnotifyObj) {
171             filter_rt002a.waitnotifyObj.notify();
172         }
173         synchronized(filter_rt002a.lockObj) {
174             filter_rt002aTestClass11.m11();
175         }
176         filter_rt002a.log1("  'run': exit   :: threadName == " + tName);
177         return;
178     }
179 }
180