Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DataDumpRequest/datadumpreq001/datadumpreq001.cpp
40955 views
/*1* Copyright (c) 2003, 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#include <stdio.h>24#include <stdlib.h>25#include <string.h>26#include <jvmti.h>27#include "agent_common.h"2829#include "nsk_tools.h"30#include "JVMTITools.h"31#include "jvmti_tools.h"32#include "jni_tools.h"3334extern "C" {3536#define STATUS_FAILED 237#define PASSED 03839static jint result = STATUS_FAILED;40static jvmtiEnv *jvmti = NULL;41static jvmtiEventCallbacks callbacks;42static jboolean eventReceived = JNI_FALSE;4344static jrawMonitorID dataDumpRequestMonitor;4546/** callback functions **/47static void JNICALL DataDumpRequest(jvmtiEnv *env) {48jvmtiPhase phase;4950rawMonitorEnter(env, dataDumpRequestMonitor);5152NSK_DISPLAY0(">>>> DataDumpRequest event received\n");53eventReceived = JNI_TRUE;5455getPhase(jvmti, &phase);5657if (phase != JVMTI_PHASE_LIVE) {58result = STATUS_FAILED;59NSK_COMPLAIN1("TEST FAILED: DataDumpRequest event received during non-live phase %s\n",60TranslatePhase(phase));61} else {62result = PASSED;63NSK_DISPLAY0("CHECK PASSED: DataDumpRequest event received during the live phase as expected\n");64}6566NSK_DISPLAY0("<<<<\n\n");6768rawMonitorNotify(env, dataDumpRequestMonitor);69rawMonitorExit(env, dataDumpRequestMonitor);70}7172static void waitDumpRequestReceived(jvmtiEnv *env) {73rawMonitorEnter(env, dataDumpRequestMonitor);7475while (eventReceived == JNI_FALSE) {76NSK_DISPLAY0("waiting for DataDumpRequest event...\n");77rawMonitorWait(env, dataDumpRequestMonitor, 0);78}7980rawMonitorExit(env, dataDumpRequestMonitor);81}8283JNIEXPORT jint JNICALL84Java_nsk_jvmti_DataDumpRequest_datadumpreq001_waitForResult(JNIEnv *env, jclass cls) {85waitDumpRequestReceived(jvmti);86return result;87}8889#ifdef STATIC_BUILD90JNIEXPORT jint JNICALL Agent_OnLoad_datadumpreq001(JavaVM *jvm, char *options, void *reserved) {91return Agent_Initialize(jvm, options, reserved);92}93JNIEXPORT jint JNICALL Agent_OnAttach_datadumpreq001(JavaVM *jvm, char *options, void *reserved) {94return Agent_Initialize(jvm, options, reserved);95}96JNIEXPORT jint JNI_OnLoad_datadumpreq001(JavaVM *jvm, char *options, void *reserved) {97return JNI_VERSION_1_8;98}99#endif100101jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {102/* init framework and parse options */103if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))104return JNI_ERR;105106/* create JVMTI environment */107jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved);108if (!NSK_VERIFY(jvmti != NULL)) {109return JNI_ERR;110}111112if (createRawMonitor(jvmti, "data dump request monitor", &dataDumpRequestMonitor) != JNI_OK) {113return JNI_ERR;114}115116/* set event callbacks */117NSK_DISPLAY0("setting event callbacks ...\n");118(void) memset(&callbacks, 0, sizeof(callbacks));119callbacks.DataDumpRequest = &DataDumpRequest;120if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))121return JNI_ERR;122123NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");124if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, NULL)))125return JNI_ERR;126NSK_DISPLAY0("enabling the events done\n\n");127128return JNI_OK;129}130131}132133134