Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/HiddenClass/events/events001a.java
41161 views
/*1* Copyright (c) 2020, 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.HiddenClass.events;2425import nsk.jdi.HiddenClass.events.DebuggeeBase;26import nsk.jdi.HiddenClass.events.HiddenClass;27import nsk.jdi.HiddenClass.events.HCInterf;28import nsk.share.jdi.ArgumentHandler;29import sun.hotspot.WhiteBox;3031/* Debuggee class. */32class events001a extends DebuggeeBase {33private final WhiteBox WB = WhiteBox.getWhiteBox();3435private events001a(ArgumentHandler argHandler) {36super(argHandler);37}3839public static void main(String args[]) {40ArgumentHandler argHandler = new ArgumentHandler(args);41events001a testApp = new events001a(argHandler);42int status = testApp.runIt();43System.exit(DebuggerBase.JCK_STATUS_BASE + status);44}4546public int runIt() {47int status = DebuggerBase.PASSED;48logMsg("\nDebuggee: started");4950try {51testHiddenClass();52} catch (Throwable t) {53status = DebuggerBase.FAILED;54logMsg("FAIL: Throwable was caught in debuggee main: " + t);55}56logMsg("\nDebuggee: finished");57return status;58}5960public void testHiddenClass() throws Exception {61syncWithDebugger();6263// Define a hidden class.64Class<?> hc = HiddenClass.defineHiddenClass();65logMsg("Debuggee: defined a hidden class: " + hc.getName());6667// It is impossible to use a hidden class name to define a variable,68// so we use the interface which the tested hidden class implements.69HCInterf hcObj = (HCInterf)hc.newInstance();70logMsg("Debuggee: created an instance of a hidden class: " + hc.getName());7172syncWithDebugger();7374// Invoke a hidden class method.75logMsg("Debuggee: invoking a method of a hidden class: " + hc.getName());76hcObj.hcMethod();7778// Provoke a hidden class unload event.79// One more hidden class has to be defined to provoke class unload.80// The first hidden class can not be unloaded. There are some JDI Field's81// or Method's associated with the hidden class which keep it alive.82logMsg("Debuggee: started provoking class unload events");83Class<?> hcForUnload = HiddenClass.defineHiddenClass();84hcForUnload = null;85WB.fullGC(); // force full GC with WB to get hidden class unloaded86logMsg("Debuggee: finished provoking class unload events");8788quitSyncWithDebugger();89}90}919293