Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk005/clrbrk005.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 <stdio.h>24#include <string.h>25#include "jvmti.h"26#include "agent_common.h"27#include "JVMTITools.h"2829extern "C" {303132#define PASSED 033#define STATUS_FAILED 23435static jvmtiEnv *jvmti = NULL;36static jvmtiCapabilities caps;37static jint result = PASSED;38static jboolean printdump = JNI_FALSE;3940#ifdef STATIC_BUILD41JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) {42return Agent_Initialize(jvm, options, reserved);43}44JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk005(JavaVM *jvm, char *options, void *reserved) {45return Agent_Initialize(jvm, options, reserved);46}47JNIEXPORT jint JNI_OnLoad_clrbrk005(JavaVM *jvm, char *options, void *reserved) {48return JNI_VERSION_1_8;49}50#endif51jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {52jvmtiError err;53jint res;5455if (options != NULL && strcmp(options, "printdump") == 0) {56printdump = JNI_TRUE;57}5859res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);60if (res != JNI_OK || jvmti == NULL) {61printf("Wrong result of a valid call to GetEnv!\n");62return JNI_ERR;63}6465err = jvmti->GetPotentialCapabilities(&caps);66if (err != JVMTI_ERROR_NONE) {67printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",68TranslateError(err), err);69return JNI_ERR;70}7172err = jvmti->AddCapabilities(&caps);73if (err != JVMTI_ERROR_NONE) {74printf("(AddCapabilities) unexpected error: %s (%d)\n",75TranslateError(err), err);76return JNI_ERR;77}7879err = jvmti->GetCapabilities(&caps);80if (err != JVMTI_ERROR_NONE) {81printf("(GetCapabilities) unexpected error: %s (%d)\n",82TranslateError(err), err);83return JNI_ERR;84}8586if (!caps.can_generate_breakpoint_events) {87printf("Warning: Breakpoint is not implemented\n");88}8990return JNI_OK;91}9293JNIEXPORT jint JNICALL94Java_nsk_jvmti_ClearBreakpoint_clrbrk005_check(JNIEnv *env, jclass cls) {95jvmtiError err;96jmethodID mid;9798if (jvmti == NULL) {99printf("JVMTI client was not properly loaded!\n");100return STATUS_FAILED;101}102103if (!caps.can_generate_breakpoint_events) {104return result;105}106107mid = env->GetStaticMethodID(cls, "checkPoint", "()V");108if (mid == 0) {109printf("Cannot find Method ID for method checkPoint\n");110return STATUS_FAILED;111}112113if (printdump == JNI_TRUE) {114printf(">>> invalid method check ...\n");115}116err = jvmti->ClearBreakpoint(NULL, 0);117if (err != JVMTI_ERROR_INVALID_METHODID) {118printf("Error expected: JVMTI_ERROR_INVALID_METHODID,\n");119printf("\tactual: %s (%d)\n", TranslateError(err), err);120result = STATUS_FAILED;121}122123if (printdump == JNI_TRUE) {124printf(">>> not found check ...\n");125}126err = jvmti->ClearBreakpoint(mid, 0);127if (err != JVMTI_ERROR_NOT_FOUND) {128printf("Error expected: JVMTI_ERROR_NOT_FOUND,\n");129printf("\tactual: %s (%d)\n", TranslateError(err), err);130result = STATUS_FAILED;131}132133if (printdump == JNI_TRUE) {134printf(">>> ... done\n");135}136137return result;138}139140}141142143