Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/HiddenClass/events/events001.java
41161 views
/*1* Copyright (c) 2020, 2021, 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*/2223/*24* @test25* @summary JDI test for hidden classes26*27* @library /vmTestbase28* /test/lib29* @modules java.base/jdk.internal.misc:+open30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32*33* @build nsk.jdi.HiddenClass.events.*34*35* @run main/othervm36* nsk.jdi.HiddenClass.events.events00137* -verbose38* -arch=${os.family}-${os.simpleArch}39* -waittime=540* -debugee.vmkind=java41* -transport.address=dynamic42* -debugee.vmkeys="-Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions43* -XX:+WhiteBoxAPI ${test.vm.opts} ${test.java.opts}"44*/4546package nsk.jdi.HiddenClass.events;4748import com.sun.jdi.Field;49import com.sun.jdi.Method;50import com.sun.jdi.ReferenceType;5152import com.sun.jdi.request.EventRequest;5354import nsk.jdi.HiddenClass.events.DebuggerBase;55import nsk.jdi.HiddenClass.events.EventHandler;5657import nsk.share.Log;58import nsk.share.jdi.ArgumentHandler;5960// This class is the test debugger61public class events001 extends DebuggerBase {62static final String PACKAGE_NAME = "nsk.jdi.HiddenClass.events";63static final String DEBUGGEE_NAME = PACKAGE_NAME + ".events001a";64static final String CHECKED_CLASS = PACKAGE_NAME + ".HiddenClass";65static final String HC_FILTER = CHECKED_CLASS + "/0x*";6667private events001(ArgumentHandler argHandler) {68super(argHandler);69}7071public static void main (String args[]) {72ArgumentHandler argHandler = new ArgumentHandler(args);7374events001 debugger = new events001(argHandler);75System.exit(debugger.run(argHandler) + JCK_STATUS_BASE);76}7778public int run(ArgumentHandler argHandler) {79boolean testFailed = false;80EventRequest breakpointRequest = null;81EventRequest classPrepareRequest = null;82EventRequest classUnloadRequest = null;83EventRequest modWatchpointRequest = null;84launchDebuggee(argHandler, DEBUGGEE_NAME);8586try {87EventHandler eventHandler = EventHandler.createAndStart(this);8889// sync with debuggee90readyCmdSync();9192// request a ClassPrepare event for the hidden class "HiddenClass/0x*"93classPrepareRequest = enableClassPrepareRequest(HC_FILTER);9495// request a ClassUnload event for the hidden class "HiddenClass/0x*"96classUnloadRequest = enableClassUnloadRequest(HC_FILTER);9798// sync with debuggee99runCmdSync();100readyCmdSync();101102// There is a latency in getting events from the debuggee103// on the debugger side over the wire protocol, so we may104// need to wait for ClassPrepareEvent to be posted.105ReferenceType hcRefType = eventHandler.waitAndGetHCRefType();106107/* Hidden class has to be prepared at this point. */108109// request a Breakpoint event in the hidden class method "hcMethod"110Method method = findMethod(hcRefType, "hcMethod");111breakpointRequest = enableBreakpointRequest(method);112113// request a ModificationWatchpoint event on the hidden class field "hcField"114Field field = findField(hcRefType, "hcField");115modWatchpointRequest = enableModificationWatchpointRequest(field, HC_FILTER);116117// sync with debuggee118runCmdSync();119doneCmdSync();120121eventHandler.waitForCompleteness();122testFailed |= eventHandler.failedStatus();123} catch (Throwable t) {124log.complain("FAIL: " + t.getMessage());125t.printStackTrace(log.getOutStream());126testFailed = true;127} finally {128// disable event requests129disableRequest(breakpointRequest, "BreakpointRequest");130disableRequest(classPrepareRequest, "ClassPrepareRequest");131disableRequest(classUnloadRequest, "ClassUnloadRequest");132disableRequest(modWatchpointRequest, "ModificationWatchpointRequest");133134// sync with debuggee135quitCmdSync();136testFailed |= shutdownDebuggee();137}138// check test results139if (testFailed) {140log.complain("# TEST FAILED");141return FAILED;142}143log.display("# TEST PASSED");144return PASSED;145}146}147148149