Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/prims/jvmtiExtensions.cpp
32285 views
/*1* Copyright (c) 2003, 2012, 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*22*/2324#include "precompiled.hpp"25#include "prims/jvmtiExport.hpp"26#include "prims/jvmtiExtensions.hpp"2728// the list of extension functions29GrowableArray<jvmtiExtensionFunctionInfo*>* JvmtiExtensions::_ext_functions;3031// the list of extension events32GrowableArray<jvmtiExtensionEventInfo*>* JvmtiExtensions::_ext_events;333435// extension function36static jvmtiError JNICALL IsClassUnloadingEnabled(const jvmtiEnv* env, jboolean* enabled, ...) {37if (enabled == NULL) {38return JVMTI_ERROR_NULL_POINTER;39}40*enabled = (jboolean)ClassUnloading;41return JVMTI_ERROR_NONE;42}4344// register extension functions and events. In this implementation we45// have a single extension function (to prove the API) that tests if class46// unloading is enabled or disabled. We also have a single extension event47// EXT_EVENT_CLASS_UNLOAD which is used to provide the JVMDI_EVENT_CLASS_UNLOAD48// event. The function and the event are registered here.49//50void JvmtiExtensions::register_extensions() {51_ext_functions = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiExtensionFunctionInfo*>(1,true);52_ext_events = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiExtensionEventInfo*>(1,true);5354// register our extension function55static jvmtiParamInfo func_params[] = {56{ (char*)"IsClassUnloadingEnabled", JVMTI_KIND_OUT, JVMTI_TYPE_JBOOLEAN, JNI_FALSE }57};58static jvmtiExtensionFunctionInfo ext_func = {59(jvmtiExtensionFunction)IsClassUnloadingEnabled,60(char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled",61(char*)"Tell if class unloading is enabled (-noclassgc)",62sizeof(func_params)/sizeof(func_params[0]),63func_params,640, // no non-universal errors65NULL66};67_ext_functions->append(&ext_func);6869// register our extension event7071static jvmtiParamInfo event_params[] = {72{ (char*)"JNI Environment", JVMTI_KIND_IN, JVMTI_TYPE_JNIENV, JNI_FALSE },73{ (char*)"Thread", JVMTI_KIND_IN, JVMTI_TYPE_JTHREAD, JNI_FALSE },74{ (char*)"Class", JVMTI_KIND_IN, JVMTI_TYPE_JCLASS, JNI_FALSE }75};76static jvmtiExtensionEventInfo ext_event = {77EXT_EVENT_CLASS_UNLOAD,78(char*)"com.sun.hotspot.events.ClassUnload",79(char*)"CLASS_UNLOAD event",80sizeof(event_params)/sizeof(event_params[0]),81event_params82};83_ext_events->append(&ext_event);84}858687// return the list of extension functions8889jvmtiError JvmtiExtensions::get_functions(JvmtiEnv* env,90jint* extension_count_ptr,91jvmtiExtensionFunctionInfo** extensions)92{93guarantee(_ext_functions != NULL, "registration not done");9495ResourceTracker rt(env);9697jvmtiExtensionFunctionInfo* ext_funcs;98jvmtiError err = rt.allocate(_ext_functions->length() *99sizeof(jvmtiExtensionFunctionInfo),100(unsigned char**)&ext_funcs);101if (err != JVMTI_ERROR_NONE) {102return err;103}104105for (int i=0; i<_ext_functions->length(); i++ ) {106ext_funcs[i].func = _ext_functions->at(i)->func;107108char *id = _ext_functions->at(i)->id;109err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_funcs[i].id));110if (err != JVMTI_ERROR_NONE) {111return err;112}113strcpy(ext_funcs[i].id, id);114115char *desc = _ext_functions->at(i)->short_description;116err = rt.allocate(strlen(desc)+1,117(unsigned char**)&(ext_funcs[i].short_description));118if (err != JVMTI_ERROR_NONE) {119return err;120}121strcpy(ext_funcs[i].short_description, desc);122123// params124125jint param_count = _ext_functions->at(i)->param_count;126127ext_funcs[i].param_count = param_count;128if (param_count == 0) {129ext_funcs[i].params = NULL;130} else {131err = rt.allocate(param_count*sizeof(jvmtiParamInfo),132(unsigned char**)&(ext_funcs[i].params));133if (err != JVMTI_ERROR_NONE) {134return err;135}136jvmtiParamInfo* src_params = _ext_functions->at(i)->params;137jvmtiParamInfo* dst_params = ext_funcs[i].params;138139for (int j=0; j<param_count; j++) {140err = rt.allocate(strlen(src_params[j].name)+1,141(unsigned char**)&(dst_params[j].name));142if (err != JVMTI_ERROR_NONE) {143return err;144}145strcpy(dst_params[j].name, src_params[j].name);146147dst_params[j].kind = src_params[j].kind;148dst_params[j].base_type = src_params[j].base_type;149dst_params[j].null_ok = src_params[j].null_ok;150}151}152153// errors154155jint error_count = _ext_functions->at(i)->error_count;156ext_funcs[i].error_count = error_count;157if (error_count == 0) {158ext_funcs[i].errors = NULL;159} else {160err = rt.allocate(error_count*sizeof(jvmtiError),161(unsigned char**)&(ext_funcs[i].errors));162if (err != JVMTI_ERROR_NONE) {163return err;164}165memcpy(ext_funcs[i].errors, _ext_functions->at(i)->errors,166error_count*sizeof(jvmtiError));167}168}169170*extension_count_ptr = _ext_functions->length();171*extensions = ext_funcs;172return JVMTI_ERROR_NONE;173}174175176// return the list of extension events177178jvmtiError JvmtiExtensions::get_events(JvmtiEnv* env,179jint* extension_count_ptr,180jvmtiExtensionEventInfo** extensions)181{182guarantee(_ext_events != NULL, "registration not done");183184ResourceTracker rt(env);185186jvmtiExtensionEventInfo* ext_events;187jvmtiError err = rt.allocate(_ext_events->length() * sizeof(jvmtiExtensionEventInfo),188(unsigned char**)&ext_events);189if (err != JVMTI_ERROR_NONE) {190return err;191}192193for (int i=0; i<_ext_events->length(); i++ ) {194ext_events[i].extension_event_index = _ext_events->at(i)->extension_event_index;195196char *id = _ext_events->at(i)->id;197err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_events[i].id));198if (err != JVMTI_ERROR_NONE) {199return err;200}201strcpy(ext_events[i].id, id);202203char *desc = _ext_events->at(i)->short_description;204err = rt.allocate(strlen(desc)+1,205(unsigned char**)&(ext_events[i].short_description));206if (err != JVMTI_ERROR_NONE) {207return err;208}209strcpy(ext_events[i].short_description, desc);210211// params212213jint param_count = _ext_events->at(i)->param_count;214215ext_events[i].param_count = param_count;216if (param_count == 0) {217ext_events[i].params = NULL;218} else {219err = rt.allocate(param_count*sizeof(jvmtiParamInfo),220(unsigned char**)&(ext_events[i].params));221if (err != JVMTI_ERROR_NONE) {222return err;223}224jvmtiParamInfo* src_params = _ext_events->at(i)->params;225jvmtiParamInfo* dst_params = ext_events[i].params;226227for (int j=0; j<param_count; j++) {228err = rt.allocate(strlen(src_params[j].name)+1,229(unsigned char**)&(dst_params[j].name));230if (err != JVMTI_ERROR_NONE) {231return err;232}233strcpy(dst_params[j].name, src_params[j].name);234235dst_params[j].kind = src_params[j].kind;236dst_params[j].base_type = src_params[j].base_type;237dst_params[j].null_ok = src_params[j].null_ok;238}239}240}241242*extension_count_ptr = _ext_events->length();243*extensions = ext_events;244return JVMTI_ERROR_NONE;245}246247// set callback for an extension event and enable/disable it.248249jvmtiError JvmtiExtensions::set_event_callback(JvmtiEnv* env,250jint extension_event_index,251jvmtiExtensionEvent callback)252{253guarantee(_ext_events != NULL, "registration not done");254255jvmtiExtensionEventInfo* event = NULL;256257// if there are extension events registered then validate that the258// extension_event_index matches one of the registered events.259if (_ext_events != NULL) {260for (int i=0; i<_ext_events->length(); i++ ) {261if (_ext_events->at(i)->extension_event_index == extension_event_index) {262event = _ext_events->at(i);263break;264}265}266}267268// invalid event index269if (event == NULL) {270return JVMTI_ERROR_ILLEGAL_ARGUMENT;271}272273JvmtiEventController::set_extension_event_callback(env, extension_event_index,274callback);275276return JVMTI_ERROR_NONE;277}278279280