test/jdk/com/sun/jdi/MonitorEventTest.java
changeset 58681 5f14a659a8cb
parent 47216 71c04702a3d5
equal deleted inserted replaced
58676:92e7d617897e 58681:5f14a659a8cb
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    29  *
    29  *
    30  * @run build TestScaffold VMConnection TargetListener TargetAdapter
    30  * @run build TestScaffold VMConnection TargetListener TargetAdapter
    31  * @run compile -g MonitorEventTest.java
    31  * @run compile -g MonitorEventTest.java
    32  * @run driver MonitorEventTest
    32  * @run driver MonitorEventTest
    33  */
    33  */
    34 import com.sun.jdi.*;
    34 import com.sun.jdi.ReferenceType;
    35 import com.sun.jdi.event.*;
    35 import com.sun.jdi.ThreadReference;
    36 import com.sun.jdi.request.*;
    36 import com.sun.jdi.event.BreakpointEvent;
    37 
    37 import com.sun.jdi.event.MonitorContendedEnterEvent;
    38 import java.util.*;
    38 import com.sun.jdi.event.MonitorContendedEnteredEvent;
       
    39 import com.sun.jdi.event.MonitorWaitEvent;
       
    40 import com.sun.jdi.event.MonitorWaitedEvent;
       
    41 import com.sun.jdi.request.EventRequest;
       
    42 import com.sun.jdi.request.MonitorContendedEnterRequest;
       
    43 import com.sun.jdi.request.MonitorContendedEnteredRequest;
       
    44 import com.sun.jdi.request.MonitorWaitRequest;
       
    45 import com.sun.jdi.request.MonitorWaitedRequest;
    39 
    46 
    40 /********** target program **********/
    47 /********** target program **********/
    41 
    48 
    42 class MonitorTestTarg {
    49 class MonitorEventTestTarg {
    43     public static Object endingMonitor;
    50     public static Object endingMonitor;
    44     public static Object startingMonitor;
    51     public static Object startingMonitor;
    45     public static final long timeout = 30 * 6000; // milliseconds
    52     public static final long timeout = 30 * 6000; // milliseconds
    46 
    53 
    47     public static volatile boolean aboutEnterLock;
    54     public static volatile boolean aboutEnterLock;
    89     }
    96     }
    90 }
    97 }
    91 
    98 
    92 class myThread extends Thread {
    99 class myThread extends Thread {
    93     public void run() {
   100     public void run() {
    94         synchronized(MonitorTestTarg.startingMonitor) {
   101         synchronized(MonitorEventTestTarg.startingMonitor) {
    95             MonitorTestTarg.startingMonitor.notify();
   102             MonitorEventTestTarg.startingMonitor.notify();
    96         }
   103         }
    97 
   104 
    98         // contended enter wait until main thread release monitor
   105         // contended enter wait until main thread release monitor
    99         MonitorTestTarg.aboutEnterLock = true;
   106         MonitorEventTestTarg.aboutEnterLock = true;
   100         synchronized (MonitorTestTarg.endingMonitor) {
   107         synchronized (MonitorEventTestTarg.endingMonitor) {
   101         }
   108         }
   102     }
   109     }
   103 }
   110 }
   104 
   111 
   105 
   112 
   106     /********** test program **********/
   113     /********** test program **********/
   107 
   114 
   108 public class MonitorEventTest extends TestScaffold {
   115 public class MonitorEventTest extends TestScaffold {
   109     ReferenceType targetClass;
   116     ReferenceType targetClass;
   110     ThreadReference mainThread;
   117     ThreadReference mainThread;
   111     List monitors;
       
   112     MonitorContendedEnterRequest contendedEnterRequest;
   118     MonitorContendedEnterRequest contendedEnterRequest;
   113     MonitorWaitedRequest monitorWaitedRequest;
   119     MonitorWaitedRequest monitorWaitedRequest;
   114     MonitorContendedEnteredRequest contendedEnteredRequest;
   120     MonitorContendedEnteredRequest contendedEnteredRequest;
   115     MonitorWaitRequest monitorWaitRequest;
   121     MonitorWaitRequest monitorWaitRequest;
   116 
   122 
   158     protected void runTests() throws Exception {
   164     protected void runTests() throws Exception {
   159         /*
   165         /*
   160          * Get to the top of main()
   166          * Get to the top of main()
   161          * to determine targetClass and mainThread
   167          * to determine targetClass and mainThread
   162          */
   168          */
   163         BreakpointEvent bpe = startToMain("MonitorTestTarg");
   169         BreakpointEvent bpe = startToMain("MonitorEventTestTarg");
   164         targetClass = bpe.location().declaringType();
   170         targetClass = bpe.location().declaringType();
   165         mainThread = bpe.thread();
   171         mainThread = bpe.thread();
   166 
   172 
   167         int initialSize = mainThread.frames().size();
       
   168         if (vm().canRequestMonitorEvents()) {
   173         if (vm().canRequestMonitorEvents()) {
   169             contendedEnterRequest = eventRequestManager().createMonitorContendedEnterRequest();
   174             contendedEnterRequest = eventRequestManager().createMonitorContendedEnterRequest();
   170             contendedEnterRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
   175             contendedEnterRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
   171             contendedEnterRequest.enable();
   176             contendedEnterRequest.enable();
   172             contendedEnteredRequest = eventRequestManager().createMonitorContendedEnteredRequest();
   177             contendedEnteredRequest = eventRequestManager().createMonitorContendedEnteredRequest();
   181         } else {
   186         } else {
   182             System.out.println("request monitor events not supported " );
   187             System.out.println("request monitor events not supported " );
   183         }
   188         }
   184 
   189 
   185 
   190 
   186         resumeTo("MonitorTestTarg", "foo", "()V");
   191         resumeTo("MonitorEventTestTarg", "foo", "()V");
   187 
   192 
   188         /*
   193         /*
   189          * resume until end
   194          * resume until end
   190          */
   195          */
   191         listenUntilVMDisconnect();
   196         listenUntilVMDisconnect();