Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.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_clrbrk002(JavaVM *jvm, char *options, void *reserved) {42return Agent_Initialize(jvm, options, reserved);43}44JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk002(JavaVM *jvm, char *options, void *reserved) {45return Agent_Initialize(jvm, options, reserved);46}47JNIEXPORT jint JNI_OnLoad_clrbrk002(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_clrbrk002_check(JNIEnv *env, jclass cls) {95jvmtiError err;96jmethodID mid;97jlocation start;98jlocation end;99100if (jvmti == NULL) {101printf("JVMTI client was not properly loaded!\n");102return STATUS_FAILED;103}104105if (!caps.can_generate_breakpoint_events) {106return result;107}108109mid = env->GetStaticMethodID(cls, "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I");110if (mid == NULL) {111printf("Cannot find method run\n");112return STATUS_FAILED;113}114115err=jvmti->GetMethodLocation(mid, &start, &end);116if (err != JVMTI_ERROR_NONE) {117printf("(GetMethodLocation) unexpected error: %s (%d)\n",118TranslateError(err), err);119return STATUS_FAILED;120}121122if (printdump == JNI_TRUE) {123printf(">>> location less then starting location check ...\n");124}125err = jvmti->ClearBreakpoint(mid, start - 1);126if (err != JVMTI_ERROR_INVALID_LOCATION) {127printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n");128printf("\tactual: %s (%d)\n", TranslateError(err), err);129result = STATUS_FAILED;130}131132if (printdump == JNI_TRUE) {133printf(">>> location greater then ending location check ...\n");134}135err = jvmti->ClearBreakpoint(mid, end + 1);136if (err != JVMTI_ERROR_INVALID_LOCATION) {137printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n");138printf("\tactual: %s (%d)\n", TranslateError(err), err);139result = STATUS_FAILED;140}141142return result;143}144145}146147148