Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/setEnabled/setenabled003a.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.EventRequest.setEnabled;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829/**30* This class is used as debuggee application for the setenabled003 JDI test.31*/3233public class setenabled003a {3435//----------------------------------------------------- templete section3637static final int PASSED = 0;38static final int FAILED = 2;39static final int PASS_BASE = 95;4041static ArgumentHandler argHandler;42static Log log;4344//-------------------------------------------------- log procedures4546public static void log1(String message) {47log.display("**> debuggee: " + message);48}4950private static void logErr(String message) {51log.complain("**> debuggee: " + message);52}5354//====================================================== test program5556static Thread1setenabled003a thread1 = null;5758//------------------------------------------------------ common section5960static int exitCode = PASSED;6162static int instruction = 1;63static int end = 0;64// static int quit = 0;65// static int continue = 2;66static int maxInstr = 1; // 2;6768static int lineForComm = 2;6970private static void methodForCommunication() {71int i1 = instruction;72int i2 = i1;73int i3 = i2;74}75//---------------------------------------------------- main method7677public static void main (String argv[]) {7879argHandler = new ArgumentHandler(argv);80log = argHandler.createDebugeeLog();8182log1("debuggee started!");8384label0:85for (int i = 0; ; i++) {8687if (instruction > maxInstr) {88logErr("ERROR: unexpected instruction: " + instruction);89exitCode = FAILED;90break ;91}9293switch (i) {9495//------------------------------------------------------ section tested9697case 0:98thread1 = new Thread1setenabled003a("thread1");99Thread1setenabled003a.method();100break;101102case 1:103synchronized (lockObj) {104threadStart(thread1);105log1("methodForCommunication();----");106methodForCommunication();107}108// case 2:109try {110thread1.join();111log1("methodForCommunication();----2");112methodForCommunication();113} catch ( InterruptedException e ) {114}115i++;116117118//------------------------------------------------- standard end section119120default:121instruction = end;122break;123}124125log1("methodForCommunication();");126methodForCommunication();127if (instruction == end)128break;129130}131132log1("debuggee exits");133System.exit(exitCode + PASS_BASE);134}135136static Object lockObj = new Object();137static Object waitnotifyObj = new Object();138139static int threadStart(Thread t) {140synchronized (waitnotifyObj) {141t.start();142try {143waitnotifyObj.wait();144} catch ( Exception e) {145exitCode = FAILED;146logErr(" Exception : " + e );147return FAILED;148}149}150return PASSED;151}152}153154class Thread1setenabled003a extends Thread {155156String tName = null;157158public Thread1setenabled003a(String threadName) {159super(threadName);160tName = threadName;161}162163public void run() {164setenabled003a.log1(" 'run': enter :: threadName == " + tName);165synchronized(setenabled003a.waitnotifyObj) {166setenabled003a.waitnotifyObj.notify();167}168169synchronized(setenabled003a.lockObj) {170setenabled003a.log1(" 'run': exit :: threadName == " + tName);171}172return;173}174175static void method() {176setenabled003a.log1(" enetred: method");177}178179}180181182