0N/A/*
1879N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "prims/jvmtiExport.hpp"
1879N/A#include "prims/jvmtiExtensions.hpp"
0N/A
0N/A// the list of extension functions
0N/AGrowableArray<jvmtiExtensionFunctionInfo*>* JvmtiExtensions::_ext_functions;
0N/A
0N/A// the list of extension events
0N/AGrowableArray<jvmtiExtensionEventInfo*>* JvmtiExtensions::_ext_events;
0N/A
0N/A
0N/A// extension function
0N/Astatic jvmtiError JNICALL IsClassUnloadingEnabled(const jvmtiEnv* env, jboolean* enabled, ...) {
0N/A if (enabled == NULL) {
0N/A return JVMTI_ERROR_NULL_POINTER;
0N/A }
0N/A *enabled = (jboolean)ClassUnloading;
0N/A return JVMTI_ERROR_NONE;
0N/A}
0N/A
0N/A// register extension functions and events. In this implementation we
0N/A// have a single extension function (to prove the API) that tests if class
0N/A// unloading is enabled or disabled. We also have a single extension event
0N/A// EXT_EVENT_CLASS_UNLOAD which is used to provide the JVMDI_EVENT_CLASS_UNLOAD
0N/A// event. The function and the event are registered here.
0N/A//
0N/Avoid JvmtiExtensions::register_extensions() {
3863N/A _ext_functions = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiExtensionFunctionInfo*>(1,true);
3863N/A _ext_events = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiExtensionEventInfo*>(1,true);
0N/A
0N/A // register our extension function
0N/A static jvmtiParamInfo func_params[] = {
0N/A { (char*)"IsClassUnloadingEnabled", JVMTI_KIND_OUT, JVMTI_TYPE_JBOOLEAN, JNI_FALSE }
0N/A };
0N/A static jvmtiExtensionFunctionInfo ext_func = {
0N/A (jvmtiExtensionFunction)IsClassUnloadingEnabled,
0N/A (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled",
0N/A (char*)"Tell if class unloading is enabled (-noclassgc)",
0N/A sizeof(func_params)/sizeof(func_params[0]),
0N/A func_params,
0N/A 0, // no non-universal errors
0N/A NULL
0N/A };
0N/A _ext_functions->append(&ext_func);
0N/A
0N/A // register our extension event
0N/A
0N/A static jvmtiParamInfo event_params[] = {
0N/A { (char*)"JNI Environment", JVMTI_KIND_IN, JVMTI_TYPE_JNIENV, JNI_FALSE },
0N/A { (char*)"Thread", JVMTI_KIND_IN, JVMTI_TYPE_JTHREAD, JNI_FALSE },
0N/A { (char*)"Class", JVMTI_KIND_IN, JVMTI_TYPE_JCLASS, JNI_FALSE }
0N/A };
0N/A static jvmtiExtensionEventInfo ext_event = {
0N/A EXT_EVENT_CLASS_UNLOAD,
0N/A (char*)"com.sun.hotspot.events.ClassUnload",
0N/A (char*)"CLASS_UNLOAD event",
0N/A sizeof(event_params)/sizeof(event_params[0]),
0N/A event_params
0N/A };
0N/A _ext_events->append(&ext_event);
0N/A}
0N/A
0N/A
0N/A// return the list of extension functions
0N/A
0N/AjvmtiError JvmtiExtensions::get_functions(JvmtiEnv* env,
0N/A jint* extension_count_ptr,
0N/A jvmtiExtensionFunctionInfo** extensions)
0N/A{
0N/A guarantee(_ext_functions != NULL, "registration not done");
0N/A
0N/A ResourceTracker rt(env);
0N/A
0N/A jvmtiExtensionFunctionInfo* ext_funcs;
0N/A jvmtiError err = rt.allocate(_ext_functions->length() *
0N/A sizeof(jvmtiExtensionFunctionInfo),
0N/A (unsigned char**)&ext_funcs);
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A
0N/A for (int i=0; i<_ext_functions->length(); i++ ) {
0N/A ext_funcs[i].func = _ext_functions->at(i)->func;
0N/A
0N/A char *id = _ext_functions->at(i)->id;
0N/A err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_funcs[i].id));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A strcpy(ext_funcs[i].id, id);
0N/A
0N/A char *desc = _ext_functions->at(i)->short_description;
0N/A err = rt.allocate(strlen(desc)+1,
0N/A (unsigned char**)&(ext_funcs[i].short_description));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A strcpy(ext_funcs[i].short_description, desc);
0N/A
0N/A // params
0N/A
0N/A jint param_count = _ext_functions->at(i)->param_count;
0N/A
0N/A ext_funcs[i].param_count = param_count;
0N/A if (param_count == 0) {
0N/A ext_funcs[i].params = NULL;
0N/A } else {
0N/A err = rt.allocate(param_count*sizeof(jvmtiParamInfo),
0N/A (unsigned char**)&(ext_funcs[i].params));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A jvmtiParamInfo* src_params = _ext_functions->at(i)->params;
0N/A jvmtiParamInfo* dst_params = ext_funcs[i].params;
0N/A
0N/A for (int j=0; j<param_count; j++) {
0N/A err = rt.allocate(strlen(src_params[j].name)+1,
0N/A (unsigned char**)&(dst_params[j].name));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A strcpy(dst_params[j].name, src_params[j].name);
0N/A
0N/A dst_params[j].kind = src_params[j].kind;
0N/A dst_params[j].base_type = src_params[j].base_type;
0N/A dst_params[j].null_ok = src_params[j].null_ok;
0N/A }
0N/A }
0N/A
0N/A // errors
0N/A
0N/A jint error_count = _ext_functions->at(i)->error_count;
0N/A ext_funcs[i].error_count = error_count;
0N/A if (error_count == 0) {
0N/A ext_funcs[i].errors = NULL;
0N/A } else {
0N/A err = rt.allocate(error_count*sizeof(jvmtiError),
0N/A (unsigned char**)&(ext_funcs[i].errors));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A memcpy(ext_funcs[i].errors, _ext_functions->at(i)->errors,
0N/A error_count*sizeof(jvmtiError));
0N/A }
0N/A }
0N/A
0N/A *extension_count_ptr = _ext_functions->length();
0N/A *extensions = ext_funcs;
0N/A return JVMTI_ERROR_NONE;
0N/A}
0N/A
0N/A
0N/A// return the list of extension events
0N/A
0N/AjvmtiError JvmtiExtensions::get_events(JvmtiEnv* env,
0N/A jint* extension_count_ptr,
0N/A jvmtiExtensionEventInfo** extensions)
0N/A{
0N/A guarantee(_ext_events != NULL, "registration not done");
0N/A
0N/A ResourceTracker rt(env);
0N/A
0N/A jvmtiExtensionEventInfo* ext_events;
0N/A jvmtiError err = rt.allocate(_ext_events->length() * sizeof(jvmtiExtensionEventInfo),
0N/A (unsigned char**)&ext_events);
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A
0N/A for (int i=0; i<_ext_events->length(); i++ ) {
0N/A ext_events[i].extension_event_index = _ext_events->at(i)->extension_event_index;
0N/A
0N/A char *id = _ext_events->at(i)->id;
0N/A err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_events[i].id));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A strcpy(ext_events[i].id, id);
0N/A
0N/A char *desc = _ext_events->at(i)->short_description;
0N/A err = rt.allocate(strlen(desc)+1,
0N/A (unsigned char**)&(ext_events[i].short_description));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A strcpy(ext_events[i].short_description, desc);
0N/A
0N/A // params
0N/A
0N/A jint param_count = _ext_events->at(i)->param_count;
0N/A
0N/A ext_events[i].param_count = param_count;
0N/A if (param_count == 0) {
0N/A ext_events[i].params = NULL;
0N/A } else {
0N/A err = rt.allocate(param_count*sizeof(jvmtiParamInfo),
0N/A (unsigned char**)&(ext_events[i].params));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A jvmtiParamInfo* src_params = _ext_events->at(i)->params;
0N/A jvmtiParamInfo* dst_params = ext_events[i].params;
0N/A
0N/A for (int j=0; j<param_count; j++) {
0N/A err = rt.allocate(strlen(src_params[j].name)+1,
0N/A (unsigned char**)&(dst_params[j].name));
0N/A if (err != JVMTI_ERROR_NONE) {
0N/A return err;
0N/A }
0N/A strcpy(dst_params[j].name, src_params[j].name);
0N/A
0N/A dst_params[j].kind = src_params[j].kind;
0N/A dst_params[j].base_type = src_params[j].base_type;
0N/A dst_params[j].null_ok = src_params[j].null_ok;
0N/A }
0N/A }
0N/A }
0N/A
0N/A *extension_count_ptr = _ext_events->length();
0N/A *extensions = ext_events;
0N/A return JVMTI_ERROR_NONE;
0N/A}
0N/A
0N/A// set callback for an extension event and enable/disable it.
0N/A
0N/AjvmtiError JvmtiExtensions::set_event_callback(JvmtiEnv* env,
0N/A jint extension_event_index,
0N/A jvmtiExtensionEvent callback)
0N/A{
0N/A guarantee(_ext_events != NULL, "registration not done");
0N/A
0N/A jvmtiExtensionEventInfo* event = NULL;
0N/A
0N/A // if there are extension events registered then validate that the
0N/A // extension_event_index matches one of the registered events.
0N/A if (_ext_events != NULL) {
0N/A for (int i=0; i<_ext_events->length(); i++ ) {
0N/A if (_ext_events->at(i)->extension_event_index == extension_event_index) {
0N/A event = _ext_events->at(i);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // invalid event index
0N/A if (event == NULL) {
0N/A return JVMTI_ERROR_ILLEGAL_ARGUMENT;
0N/A }
0N/A
0N/A JvmtiEventController::set_extension_event_callback(env, extension_event_index,
0N/A callback);
0N/A
0N/A return JVMTI_ERROR_NONE;
0N/A}