Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/dyncodgen001.cpp
40951 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 <string.h>24#include "jvmti.h"25#include "agent_common.h"26#include "jni_tools.h"27#include "jvmti_tools.h"2829extern "C" {3031/* ========================================================================== */3233/* scaffold objects */34static jlong timeout = 0;3536/* test objects */37static int eventsCount;3839/* ========================================================================== */4041/* check if any DynamicCodeGenerated events received */42static int checkDynamicCodeGeneratedEvents() {4344NSK_DISPLAY1("DynamicCodeGenerated events received: %d\n", eventsCount);4546if (eventsCount == 0) {47NSK_DISPLAY0("# WARNING: no DynamicCodeGenerated events\n");48NSK_DISPLAY0("# (dynamic code may not be generated at all)\n");49}5051return NSK_TRUE;52}5354/* ========================================================================== */5556JNIEXPORT void JNICALL57DynamicCodeGenerated(jvmtiEnv* jvmti,58const char* name, const void* address, jint length) {5960NSK_DISPLAY3("DynamicCodeGenerated: \"%s\", address=0x%p, length=%d\n",61name, address, length);6263eventsCount++;64}6566/* ========================================================================== */6768/* agent algorithm */69static void JNICALL70agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {7172/* wait for debuggee start */73if (!nsk_jvmti_waitForSync(timeout))74return;7576/* testcase #1: check if any DynamicCodeGenerated events received*/77NSK_DISPLAY0("Testcase #1: check if any DynamicCodeGenerated events received\n");78if (!checkDynamicCodeGeneratedEvents())79nsk_jvmti_setFailStatus();8081/* resume debugee after last sync */82if (!nsk_jvmti_resumeSync())83return;84}8586/* ========================================================================== */8788/* agent library initialization */89#ifdef STATIC_BUILD90JNIEXPORT jint JNICALL Agent_OnLoad_dyncodgen001(JavaVM *jvm, char *options, void *reserved) {91return Agent_Initialize(jvm, options, reserved);92}93JNIEXPORT jint JNICALL Agent_OnAttach_dyncodgen001(JavaVM *jvm, char *options, void *reserved) {94return Agent_Initialize(jvm, options, reserved);95}96JNIEXPORT jint JNI_OnLoad_dyncodgen001(JavaVM *jvm, char *options, void *reserved) {97return JNI_VERSION_1_8;98}99#endif100jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {101jvmtiEnv* jvmti = NULL;102jvmtiEventCallbacks callbacks;103104/* init framework and parse options */105if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))106return JNI_ERR;107108timeout = nsk_jvmti_getWaitTime() * 60000;109NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);110111/* create JVMTI environment */112if (!NSK_VERIFY((jvmti =113nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))114return JNI_ERR;115116memset(&callbacks, 0, sizeof(callbacks));117callbacks.DynamicCodeGenerated = &DynamicCodeGenerated;118if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))119return JNI_ERR;120121/* enable DynamicCodeGenerated event */122if (!NSK_JVMTI_VERIFY(123jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL)))124return JNI_ERR;125126/* register agent proc and arg */127if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))128return JNI_ERR;129130return JNI_OK;131}132133/* ========================================================================== */134135}136137138