< prev index next >

test/hotspot/jtreg/serviceability/jvmti/8036666/GetObjectLockCount.java

Print this page

  1 /*
  2  * Copyright (c) 2014 SAP SE. 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  */

 39 import com.sun.jdi.ThreadReference;
 40 import com.sun.jdi.Value;
 41 import com.sun.jdi.VirtualMachine;
 42 import com.sun.jdi.connect.Connector;
 43 import com.sun.jdi.connect.Connector.Argument;
 44 import com.sun.jdi.connect.IllegalConnectorArgumentsException;
 45 import com.sun.jdi.connect.LaunchingConnector;
 46 import com.sun.jdi.connect.VMStartException;
 47 import com.sun.jdi.event.BreakpointEvent;
 48 import com.sun.jdi.event.ClassPrepareEvent;
 49 import com.sun.jdi.event.Event;
 50 import com.sun.jdi.event.EventQueue;
 51 import com.sun.jdi.event.EventSet;
 52 import com.sun.jdi.event.VMDeathEvent;
 53 import com.sun.jdi.event.VMDisconnectEvent;
 54 import com.sun.jdi.event.VMStartEvent;
 55 import com.sun.jdi.request.BreakpointRequest;
 56 import com.sun.jdi.request.ClassPrepareRequest;
 57 import com.sun.jdi.request.EventRequestManager;
 58 

 59 
 60 /*
 61  * @test GetObjectLockCount.java
 62  * @bug 8036666
 63  * @summary verify jvm returns correct lock recursion count
 64  * @requires vm.jvmti

 65  * @run compile -g RecursiveObjectLock.java
 66  * @run main/othervm GetObjectLockCount
 67  * @author axel.siebenborn@sap.com
 68  */
 69 
 70 public class GetObjectLockCount {
 71 
 72     public static final String CLASS_NAME  = "RecursiveObjectLock";
 73     public static final String METHOD_NAME = "breakpoint1";
 74     public static final String ARGUMENTS = "";
 75 
 76 
 77     /**
 78      * Find a com.sun.jdi.CommandLineLaunch connector
 79      */
 80     static LaunchingConnector findLaunchingConnector() {
 81         List <Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
 82         Iterator <Connector> iter = connectors.iterator();
 83         while (iter.hasNext()) {
 84             Connector connector = iter.next();
 85             if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
 86                 return (LaunchingConnector)connector;
 87             }
 88         }
 89         throw new Error("No launching connector");
 90     }
 91 
 92     static VirtualMachine launchTarget(String mainArgs) {
 93         LaunchingConnector connector = findLaunchingConnector();
 94         Map<String, Argument>  arguments = connectorArguments(connector, mainArgs);
 95         try {

102             throw new Error("Target VM failed to initialize: " +
103                     exc.getMessage());
104         }
105     }
106     /**
107      * Return the launching connector's arguments.
108      */
109     static Map <String,Connector.Argument> connectorArguments(LaunchingConnector connector, String mainArgs) {
110         Map<String,Connector.Argument> arguments = connector.defaultArguments();
111 
112         Connector.Argument mainArg = (Connector.Argument)arguments.get("main");
113         if (mainArg == null) {
114             throw new Error("Bad launching connector");
115         }
116         mainArg.setValue(mainArgs);
117 
118         Connector.Argument optionsArg = (Connector.Argument)arguments.get("options");
119         if (optionsArg == null) {
120             throw new Error("Bad launching connector");
121         }
122         optionsArg.setValue(ARGUMENTS);
123         return arguments;
124     }
125 
126     private static void addClassWatch(VirtualMachine vm) {
127         EventRequestManager erm = vm.eventRequestManager();
128         ClassPrepareRequest classPrepareRequest = erm
129                 .createClassPrepareRequest();
130         classPrepareRequest.addClassFilter(CLASS_NAME);
131         classPrepareRequest.setEnabled(true);
132     }
133 
134     private static void addBreakpoint(VirtualMachine vm, ReferenceType refType) {
135         Location breakpointLocation = null;
136         List<Location> locs;
137         try {
138             locs = refType.allLineLocations();
139             for (Location loc: locs) {
140                 if (loc.method().name().equals(METHOD_NAME)) {
141                     breakpointLocation = loc;
142                     break;

  1 /*
  2  * Copyright (c) 2014 SAP SE. All rights reserved.
  3  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  */

 40 import com.sun.jdi.ThreadReference;
 41 import com.sun.jdi.Value;
 42 import com.sun.jdi.VirtualMachine;
 43 import com.sun.jdi.connect.Connector;
 44 import com.sun.jdi.connect.Connector.Argument;
 45 import com.sun.jdi.connect.IllegalConnectorArgumentsException;
 46 import com.sun.jdi.connect.LaunchingConnector;
 47 import com.sun.jdi.connect.VMStartException;
 48 import com.sun.jdi.event.BreakpointEvent;
 49 import com.sun.jdi.event.ClassPrepareEvent;
 50 import com.sun.jdi.event.Event;
 51 import com.sun.jdi.event.EventQueue;
 52 import com.sun.jdi.event.EventSet;
 53 import com.sun.jdi.event.VMDeathEvent;
 54 import com.sun.jdi.event.VMDisconnectEvent;
 55 import com.sun.jdi.event.VMStartEvent;
 56 import com.sun.jdi.request.BreakpointRequest;
 57 import com.sun.jdi.request.ClassPrepareRequest;
 58 import com.sun.jdi.request.EventRequestManager;
 59 
 60 import jdk.test.lib.Utils;
 61 
 62 /*
 63  * @test GetObjectLockCount.java
 64  * @bug 8036666
 65  * @summary verify jvm returns correct lock recursion count
 66  * @requires vm.jvmti
 67  * @library /test/lib
 68  * @run compile -g RecursiveObjectLock.java
 69  * @run main/othervm GetObjectLockCount
 70  * @author axel.siebenborn@sap.com
 71  */
 72 
 73 public class GetObjectLockCount {
 74 
 75     public static final String CLASS_NAME  = "RecursiveObjectLock";
 76     public static final String METHOD_NAME = "breakpoint1";


 77 
 78     /**
 79      * Find a com.sun.jdi.CommandLineLaunch connector
 80      */
 81     static LaunchingConnector findLaunchingConnector() {
 82         List <Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
 83         Iterator <Connector> iter = connectors.iterator();
 84         while (iter.hasNext()) {
 85             Connector connector = iter.next();
 86             if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
 87                 return (LaunchingConnector)connector;
 88             }
 89         }
 90         throw new Error("No launching connector");
 91     }
 92 
 93     static VirtualMachine launchTarget(String mainArgs) {
 94         LaunchingConnector connector = findLaunchingConnector();
 95         Map<String, Argument>  arguments = connectorArguments(connector, mainArgs);
 96         try {

103             throw new Error("Target VM failed to initialize: " +
104                     exc.getMessage());
105         }
106     }
107     /**
108      * Return the launching connector's arguments.
109      */
110     static Map <String,Connector.Argument> connectorArguments(LaunchingConnector connector, String mainArgs) {
111         Map<String,Connector.Argument> arguments = connector.defaultArguments();
112 
113         Connector.Argument mainArg = (Connector.Argument)arguments.get("main");
114         if (mainArg == null) {
115             throw new Error("Bad launching connector");
116         }
117         mainArg.setValue(mainArgs);
118 
119         Connector.Argument optionsArg = (Connector.Argument)arguments.get("options");
120         if (optionsArg == null) {
121             throw new Error("Bad launching connector");
122         }
123         optionsArg.setValue(String.join(" ", Utils.getTestJavaOpts()));
124         return arguments;
125     }
126 
127     private static void addClassWatch(VirtualMachine vm) {
128         EventRequestManager erm = vm.eventRequestManager();
129         ClassPrepareRequest classPrepareRequest = erm
130                 .createClassPrepareRequest();
131         classPrepareRequest.addClassFilter(CLASS_NAME);
132         classPrepareRequest.setEnabled(true);
133     }
134 
135     private static void addBreakpoint(VirtualMachine vm, ReferenceType refType) {
136         Location breakpointLocation = null;
137         List<Location> locs;
138         try {
139             locs = refType.allLineLocations();
140             for (Location loc: locs) {
141                 if (loc.method().name().equals(METHOD_NAME)) {
142                     breakpointLocation = loc;
143                     break;
< prev index next >