8232370: Refactor some com.sun.jdi tests to enable IDE integration

Reviewed-by: amenkov, cjplummer, sspitsyn
This commit is contained in:
Christoph Langer 2019-10-17 22:41:36 +02:00
parent f630646baf
commit 3e02a34be9
3 changed files with 36 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,15 +31,22 @@
* @run compile -g MonitorEventTest.java * @run compile -g MonitorEventTest.java
* @run driver MonitorEventTest * @run driver MonitorEventTest
*/ */
import com.sun.jdi.*; import com.sun.jdi.ReferenceType;
import com.sun.jdi.event.*; import com.sun.jdi.ThreadReference;
import com.sun.jdi.request.*; import com.sun.jdi.event.BreakpointEvent;
import com.sun.jdi.event.MonitorContendedEnterEvent;
import java.util.*; import com.sun.jdi.event.MonitorContendedEnteredEvent;
import com.sun.jdi.event.MonitorWaitEvent;
import com.sun.jdi.event.MonitorWaitedEvent;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.MonitorContendedEnterRequest;
import com.sun.jdi.request.MonitorContendedEnteredRequest;
import com.sun.jdi.request.MonitorWaitRequest;
import com.sun.jdi.request.MonitorWaitedRequest;
/********** target program **********/ /********** target program **********/
class MonitorTestTarg { class MonitorEventTestTarg {
public static Object endingMonitor; public static Object endingMonitor;
public static Object startingMonitor; public static Object startingMonitor;
public static final long timeout = 30 * 6000; // milliseconds public static final long timeout = 30 * 6000; // milliseconds
@ -91,13 +98,13 @@ class MonitorTestTarg {
class myThread extends Thread { class myThread extends Thread {
public void run() { public void run() {
synchronized(MonitorTestTarg.startingMonitor) { synchronized(MonitorEventTestTarg.startingMonitor) {
MonitorTestTarg.startingMonitor.notify(); MonitorEventTestTarg.startingMonitor.notify();
} }
// contended enter wait until main thread release monitor // contended enter wait until main thread release monitor
MonitorTestTarg.aboutEnterLock = true; MonitorEventTestTarg.aboutEnterLock = true;
synchronized (MonitorTestTarg.endingMonitor) { synchronized (MonitorEventTestTarg.endingMonitor) {
} }
} }
} }
@ -108,7 +115,6 @@ class myThread extends Thread {
public class MonitorEventTest extends TestScaffold { public class MonitorEventTest extends TestScaffold {
ReferenceType targetClass; ReferenceType targetClass;
ThreadReference mainThread; ThreadReference mainThread;
List monitors;
MonitorContendedEnterRequest contendedEnterRequest; MonitorContendedEnterRequest contendedEnterRequest;
MonitorWaitedRequest monitorWaitedRequest; MonitorWaitedRequest monitorWaitedRequest;
MonitorContendedEnteredRequest contendedEnteredRequest; MonitorContendedEnteredRequest contendedEnteredRequest;
@ -160,11 +166,10 @@ public class MonitorEventTest extends TestScaffold {
* Get to the top of main() * Get to the top of main()
* to determine targetClass and mainThread * to determine targetClass and mainThread
*/ */
BreakpointEvent bpe = startToMain("MonitorTestTarg"); BreakpointEvent bpe = startToMain("MonitorEventTestTarg");
targetClass = bpe.location().declaringType(); targetClass = bpe.location().declaringType();
mainThread = bpe.thread(); mainThread = bpe.thread();
int initialSize = mainThread.frames().size();
if (vm().canRequestMonitorEvents()) { if (vm().canRequestMonitorEvents()) {
contendedEnterRequest = eventRequestManager().createMonitorContendedEnterRequest(); contendedEnterRequest = eventRequestManager().createMonitorContendedEnterRequest();
contendedEnterRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE); contendedEnterRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
@ -183,7 +188,7 @@ public class MonitorEventTest extends TestScaffold {
} }
resumeTo("MonitorTestTarg", "foo", "()V"); resumeTo("MonitorEventTestTarg", "foo", "()V");
/* /*
* resume until end * resume until end

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,15 +33,17 @@
* @run compile -g MonitorFrameInfo.java * @run compile -g MonitorFrameInfo.java
* @run driver MonitorFrameInfo * @run driver MonitorFrameInfo
*/ */
import com.sun.jdi.*; import java.util.List;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
import java.util.*; import com.sun.jdi.InvalidStackFrameException;
import com.sun.jdi.MonitorInfo;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.event.BreakpointEvent;
/********** target program **********/ /********** target program **********/
class MonitorTestTarg { class MonitorFrameInfoTarg {
static void foo3() { static void foo3() {
System.out.println("executing foo3"); System.out.println("executing foo3");
@ -71,7 +73,7 @@ class MonitorTestTarg {
public class MonitorFrameInfo extends TestScaffold { public class MonitorFrameInfo extends TestScaffold {
ReferenceType targetClass; ReferenceType targetClass;
ThreadReference mainThread; ThreadReference mainThread;
List monitors; List<MonitorInfo> monitors;
static int expectedCount = 2; static int expectedCount = 2;
static int[] expectedDepth = { 1, 3 }; static int[] expectedDepth = { 1, 3 };
@ -93,13 +95,13 @@ public class MonitorFrameInfo extends TestScaffold {
* Get to the top of main() * Get to the top of main()
* to determine targetClass and mainThread * to determine targetClass and mainThread
*/ */
BreakpointEvent bpe = startToMain("MonitorTestTarg"); BreakpointEvent bpe = startToMain("MonitorFrameInfoTarg");
targetClass = bpe.location().declaringType(); targetClass = bpe.location().declaringType();
mainThread = bpe.thread(); mainThread = bpe.thread();
int initialSize = mainThread.frames().size(); int initialSize = mainThread.frames().size();
resumeTo("MonitorTestTarg", "foo3", "()V"); resumeTo("MonitorFrameInfoTarg", "foo3", "()V");
if (!mainThread.frame(0).location().method().name() if (!mainThread.frame(0).location().method().name()
.equals("foo3")) { .equals("foo3")) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,14 +44,14 @@ class RedefineImplementorTarg implements Runnable {
} }
public static void main(String[] args) { public static void main(String[] args) {
Runnable r = new B(); Runnable r = new RedefineImplementorB();
B.func(r); RedefineImplementorB.func(r);
B.func(r); // @1 breakpoint RedefineImplementorB.func(r); // @1 breakpoint
} }
} }
class B extends RedefineImplementorTarg { class RedefineImplementorB extends RedefineImplementorTarg {
static void func(Runnable r) { static void func(Runnable r) {
r.run(); r.run();
} }