Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/NotifyFramePop/NotifyFramePopTest.java
41153 views
/*1* Copyright (c) 2018, 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 Verifies NotifyFramePop request is cleared if JVMTI_EVENT_FRAME_POP is disabled26* @requires vm.jvmti27* @library /test/lib28* @compile NotifyFramePopTest.java29* @run main/othervm/native -agentlib:NotifyFramePopTest NotifyFramePopTest30*/3132import jtreg.SkippedException;3334public class NotifyFramePopTest {35static {36try {37System.loadLibrary("NotifyFramePopTest");38} catch (UnsatisfiedLinkError ex) {39System.err.println("Could not load NotifyFramePopTest library");40System.err.println("java.library.path:"41+ System.getProperty("java.library.path"));42throw ex;43}44}4546public static void main(String args[]) {47if (!canGenerateFramePopEvents()) {48throw new SkippedException("FramePop event is not supported");49}5051// Sanity testing that FRAME_POP works.52test("sanity", true, () -> {53setFramePopNotificationMode(true);54notifyFramePop(null);55});5657// Request notification and then disable FRAME_POP event notification.58// This should not prevent the notification for the frame being cleared59// when we return from the method.60test("requestAndDisable", false, () -> {61setFramePopNotificationMode(true);62notifyFramePop(null);63setFramePopNotificationMode(false);64});6566// Ensure there is no pending event67test("ensureCleared", false, () -> {68setFramePopNotificationMode(true);69});7071log("Test PASSED");72}7374private native static boolean canGenerateFramePopEvents();75private native static void setFramePopNotificationMode(boolean enabled);76private native static void notifyFramePop(Thread thread);77private native static boolean framePopReceived();7879private static void log(String msg) {80System.out.println(msg);81}8283private interface Test {84void test();85}8687private static void test(String name, boolean framePopExpected, Test theTest) {88log("test: " + name);89theTest.test();90boolean actual = framePopReceived();91if (framePopExpected != actual) {92throw new RuntimeException("unexpected notification:"93+ " FramePop expected: " + (framePopExpected ? "yes" : "no")94+ ", actually received: " + (actual ? "yes" : "no"));95}96log(" - OK (" + (actual ? "received" : "NOT received") + ")");97}9899}100101102