Path: blob/master/test/hotspot/jtreg/compiler/jsr292/cr8026328/libTest8026328.c
41153 views
/*1* Copyright (c) 2013, 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 <stdio.h>2526#include "jvmti.h"2728#define CLASS_NAME "Lcompiler/jsr292/cr8026328/Test8026328;"29#define METHOD_NAME "main"3031static jvmtiEnv *jvmti = NULL;323334void JNICALL35classprepare(jvmtiEnv* jvmti_env,36JNIEnv* jni_env,37jthread thread,38jclass klass) {3940char* buf;41(*jvmti)->GetClassSignature(jvmti,42klass,43&buf,44NULL);45if (strcmp(CLASS_NAME, buf) == 0) {46jint nMethods;47jmethodID* methods;48int i;49(*jvmti)->GetClassMethods(jvmti,50klass,51&nMethods,52&methods);53for (i = 0; i < nMethods; i++) {54char* name;55(*jvmti)->GetMethodName(jvmti,56methods[i],57&name,58NULL,59NULL);60if (strcmp(METHOD_NAME, name) == 0) {61printf("Setting breakpoint\n");62fflush(stdout);63(*jvmti)->SetBreakpoint(jvmti, methods[i], 0);64}65}66}67}686970void JNICALL71breakpoint(jvmtiEnv* jvmti_env,72JNIEnv* jni_env,73jthread thread,74jmethodID method,75jlocation location) {7677jclass declaring_class;78char* name;79char* cname;80(*jvmti)->GetMethodName(jvmti,81method,82&name,83NULL,84NULL);85(*jvmti)->GetMethodDeclaringClass(jvmti,86method,87&declaring_class);88(*jvmti)->GetClassSignature(jvmti,89declaring_class,90&cname,91NULL);92printf("Hit breakpoint at %s::%s:%d\n", cname, name, (int) location);93fflush(stdout);94}959697JNIEXPORT jint JNICALL98Agent_OnLoad(JavaVM* vm,99char* options,100void* reserved) {101102jvmtiCapabilities capa;103jvmtiEventCallbacks cbs = {0};104105(*vm)->GetEnv(vm, (void**)&jvmti, JVMTI_VERSION_1_0);106107memset(&capa, 0, sizeof(capa));108capa.can_generate_breakpoint_events = 1;109capa.can_generate_single_step_events = 1;110(*jvmti)->AddCapabilities(jvmti, &capa);111112cbs.ClassPrepare = classprepare;113cbs.Breakpoint = breakpoint;114(*jvmti)->SetEventCallbacks(jvmti, &cbs, sizeof(cbs));115(*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, NULL);116(*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL);117printf("Loaded agent\n");118fflush(stdout);119120return 0;121}122123124