Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Event/request/request001a.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.Event.request;2425import nsk.share.*;26import nsk.share.jdi.*;2728/**29* This class is used as debuggee application for the request001 JDI test.30*/3132public class request001a {3334//----------------------------------------------------- templete section3536static final int PASSED = 0;37static final int FAILED = 2;38static final int PASS_BASE = 95;3940static ArgumentHandler argHandler;41static Log log;4243//-------------------------------------------------- log procedures4445private static void log1(String message) {46log.display("**> debuggee: " + message);47}4849private static void logErr(String message) {50log.complain("**> debuggee: " + message);51}5253//====================================================== test program5455static TestClass tcObject = new TestClass();5657static String threadNames[] = {58"awThread", "mwThread", "bpThread", "excThread",59"menThread", "mexThread", "stThread"60};6162static int threadsN = threadNames.length;6364static Thread threads[] = new Thread[threadsN];6566static Thread thread2 = null;6768//------------------------------------------------------ common section6970static int exitCode = PASSED;7172static int instruction = 1;73static int end = 0;7475static int maxInstr = 1; // 2;7677static int lineForComm = 2;7879private static void methodForCommunication() {80int i1 = instruction;81int i2 = i1;82int i3 = i2;83}84//---------------------------------------------------- main method8586public static void main (String argv[]) {8788argHandler = new ArgumentHandler(argv);89log = argHandler.createDebugeeLog();9091log1("debuggee started!");929394label0:95for (int i = 0; ; i++) {9697if (instruction > maxInstr) {98logErr("ERROR: unexpected instruction: " + instruction);99exitCode = FAILED;100break ;101}102103switch (i) {104105//------------------------------------------------------ section tested106107case 0:108thread2 = new Thread3request001a("thread2");109threadStart(thread2);110try {111// we should wait here for thread2 completion (see 6671428)112thread2.join();113} catch (InterruptedException e) {114logErr("ERROR: unexpected exception: " + e);115exitCode = FAILED;116break ;117}118119for (int n1 = 0; n1 < threadsN; n1++) {120if (n1 < threadsN-1)121threads[n1] = new Thread1request001a(threadNames[n1]);122else123threads[n1] = new Thread2request001a(threadNames[n1]);124}125log1(" threads has been created");126127synchronized (lockingObject2) {128log1(" loop: threadStart(threads[n2])");129for (int n2 = 0; n2 < threadsN; n2++)130if ( threadStart(threads[n2]) != PASSED )131break label0;132133log1(" methodForCommunication();");134methodForCommunication();135}136137for (int n2 = 0; n2 < threadsN; n2++) {138synchronized (locks[n2]) {139log1(" synchronized (locks[n2]) : n2 == " + n2);140}141}142143methodForCommunication();144break ;145146//------------------------------------------------- standard end section147148default:149instruction = end;150methodForCommunication();151break label0;152}153}154155System.exit(exitCode + PASS_BASE);156}157158static Object waitnotifyObj = new Object();159static Object lockingObject = new Object();160161static int threadStart(Thread t) {162synchronized (waitnotifyObj) {163t.start();164try {165waitnotifyObj.wait();166} catch ( Exception e) {167exitCode = FAILED;168logErr(" Exception : " + e );169return FAILED;170}171}172return PASSED;173}174175176public static void nullMethod() {177throw new NullPointerException("test");178}179180static Object lockingObject2 = new Object();181static Object locks[] = new Object[threadsN];182183static volatile int n = 0;184185static class Thread1request001a extends Thread {186187int threadIndex;188189public Thread1request001a(String threadName) {190super(threadName);191threadIndex = n;192locks[threadIndex] = new Object();193n++;194}195196public void run() {197log3(" 'run': enter :: threadIndex == " + threadIndex);198199synchronized (locks[threadIndex]) {200log3("enter synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);201synchronized (waitnotifyObj) {202waitnotifyObj.notify();203}204log3(" 'run': exit synchronized (waitnotifyObj)");205206synchronized (lockingObject2) {207TestClass.method();208}209log3("exit synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);210}211return;212}213214}215216static class Thread2request001a extends Thread {217218int threadIndex;219220public Thread2request001a(String threadName) {221super(threadName);222threadIndex = n;223locks[threadIndex] = new Object();224n++;225}226227public void run() {228log3(" 'run': enter :: threadIndex == " + threadIndex);229230synchronized (locks[threadIndex]) {231log3("enter synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);232synchronized (waitnotifyObj) {233waitnotifyObj.notify();234}235m1();236log3("exit synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);237}238return;239}240241private void m1() {242synchronized (lockingObject2) {243log3(" 'm1': enter");244245log3(" 'm1': exit");246}247}248249}250251static class Thread3request001a extends Thread {252253String tName = null;254255public Thread3request001a(String threadName) {256super(threadName);257tName = threadName;258}259260public void run() {261log3(" 'run': enter :: threadName == " + tName);262synchronized (waitnotifyObj) {263waitnotifyObj.notify();264}265log3(" 'run': exit :: threadName == " + tName);266}267}268269270public static void log3(String str) {271log1(Thread.currentThread().getName() + " : " + str);272}273274}275276class TestClass {277278static int breakpointLine = 3;279static String awFieldName = "var1";280static String mwFieldName = "var2";281282static int var1 = 0;283static int var2 = 0;284static int var3 = 0;285286static void method () {287var1 += 1;288var3 += 1;289var2 = var3;290try {291request001a.nullMethod();292} catch ( NullPointerException e ) {293request001a.log3(" NullPointerException : " + e);294}295}296}297298299