src/share/vm/prims/jvmtiExtensions.cpp

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 435
a61af66fc99e
child 2314
f95d63e2154a
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

duke@435 1 /*
trims@1907 2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_jvmtiExtensions.cpp.incl"
duke@435 27
duke@435 28 // the list of extension functions
duke@435 29 GrowableArray<jvmtiExtensionFunctionInfo*>* JvmtiExtensions::_ext_functions;
duke@435 30
duke@435 31 // the list of extension events
duke@435 32 GrowableArray<jvmtiExtensionEventInfo*>* JvmtiExtensions::_ext_events;
duke@435 33
duke@435 34
duke@435 35 // extension function
duke@435 36 static jvmtiError JNICALL IsClassUnloadingEnabled(const jvmtiEnv* env, jboolean* enabled, ...) {
duke@435 37 if (enabled == NULL) {
duke@435 38 return JVMTI_ERROR_NULL_POINTER;
duke@435 39 }
duke@435 40 *enabled = (jboolean)ClassUnloading;
duke@435 41 return JVMTI_ERROR_NONE;
duke@435 42 }
duke@435 43
duke@435 44 // register extension functions and events. In this implementation we
duke@435 45 // have a single extension function (to prove the API) that tests if class
duke@435 46 // unloading is enabled or disabled. We also have a single extension event
duke@435 47 // EXT_EVENT_CLASS_UNLOAD which is used to provide the JVMDI_EVENT_CLASS_UNLOAD
duke@435 48 // event. The function and the event are registered here.
duke@435 49 //
duke@435 50 void JvmtiExtensions::register_extensions() {
duke@435 51 _ext_functions = new (ResourceObj::C_HEAP) GrowableArray<jvmtiExtensionFunctionInfo*>(1,true);
duke@435 52 _ext_events = new (ResourceObj::C_HEAP) GrowableArray<jvmtiExtensionEventInfo*>(1,true);
duke@435 53
duke@435 54 // register our extension function
duke@435 55 static jvmtiParamInfo func_params[] = {
duke@435 56 { (char*)"IsClassUnloadingEnabled", JVMTI_KIND_OUT, JVMTI_TYPE_JBOOLEAN, JNI_FALSE }
duke@435 57 };
duke@435 58 static jvmtiExtensionFunctionInfo ext_func = {
duke@435 59 (jvmtiExtensionFunction)IsClassUnloadingEnabled,
duke@435 60 (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled",
duke@435 61 (char*)"Tell if class unloading is enabled (-noclassgc)",
duke@435 62 sizeof(func_params)/sizeof(func_params[0]),
duke@435 63 func_params,
duke@435 64 0, // no non-universal errors
duke@435 65 NULL
duke@435 66 };
duke@435 67 _ext_functions->append(&ext_func);
duke@435 68
duke@435 69 // register our extension event
duke@435 70
duke@435 71 static jvmtiParamInfo event_params[] = {
duke@435 72 { (char*)"JNI Environment", JVMTI_KIND_IN, JVMTI_TYPE_JNIENV, JNI_FALSE },
duke@435 73 { (char*)"Thread", JVMTI_KIND_IN, JVMTI_TYPE_JTHREAD, JNI_FALSE },
duke@435 74 { (char*)"Class", JVMTI_KIND_IN, JVMTI_TYPE_JCLASS, JNI_FALSE }
duke@435 75 };
duke@435 76 static jvmtiExtensionEventInfo ext_event = {
duke@435 77 EXT_EVENT_CLASS_UNLOAD,
duke@435 78 (char*)"com.sun.hotspot.events.ClassUnload",
duke@435 79 (char*)"CLASS_UNLOAD event",
duke@435 80 sizeof(event_params)/sizeof(event_params[0]),
duke@435 81 event_params
duke@435 82 };
duke@435 83 _ext_events->append(&ext_event);
duke@435 84 }
duke@435 85
duke@435 86
duke@435 87 // return the list of extension functions
duke@435 88
duke@435 89 jvmtiError JvmtiExtensions::get_functions(JvmtiEnv* env,
duke@435 90 jint* extension_count_ptr,
duke@435 91 jvmtiExtensionFunctionInfo** extensions)
duke@435 92 {
duke@435 93 guarantee(_ext_functions != NULL, "registration not done");
duke@435 94
duke@435 95 ResourceTracker rt(env);
duke@435 96
duke@435 97 jvmtiExtensionFunctionInfo* ext_funcs;
duke@435 98 jvmtiError err = rt.allocate(_ext_functions->length() *
duke@435 99 sizeof(jvmtiExtensionFunctionInfo),
duke@435 100 (unsigned char**)&ext_funcs);
duke@435 101 if (err != JVMTI_ERROR_NONE) {
duke@435 102 return err;
duke@435 103 }
duke@435 104
duke@435 105 for (int i=0; i<_ext_functions->length(); i++ ) {
duke@435 106 ext_funcs[i].func = _ext_functions->at(i)->func;
duke@435 107
duke@435 108 char *id = _ext_functions->at(i)->id;
duke@435 109 err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_funcs[i].id));
duke@435 110 if (err != JVMTI_ERROR_NONE) {
duke@435 111 return err;
duke@435 112 }
duke@435 113 strcpy(ext_funcs[i].id, id);
duke@435 114
duke@435 115 char *desc = _ext_functions->at(i)->short_description;
duke@435 116 err = rt.allocate(strlen(desc)+1,
duke@435 117 (unsigned char**)&(ext_funcs[i].short_description));
duke@435 118 if (err != JVMTI_ERROR_NONE) {
duke@435 119 return err;
duke@435 120 }
duke@435 121 strcpy(ext_funcs[i].short_description, desc);
duke@435 122
duke@435 123 // params
duke@435 124
duke@435 125 jint param_count = _ext_functions->at(i)->param_count;
duke@435 126
duke@435 127 ext_funcs[i].param_count = param_count;
duke@435 128 if (param_count == 0) {
duke@435 129 ext_funcs[i].params = NULL;
duke@435 130 } else {
duke@435 131 err = rt.allocate(param_count*sizeof(jvmtiParamInfo),
duke@435 132 (unsigned char**)&(ext_funcs[i].params));
duke@435 133 if (err != JVMTI_ERROR_NONE) {
duke@435 134 return err;
duke@435 135 }
duke@435 136 jvmtiParamInfo* src_params = _ext_functions->at(i)->params;
duke@435 137 jvmtiParamInfo* dst_params = ext_funcs[i].params;
duke@435 138
duke@435 139 for (int j=0; j<param_count; j++) {
duke@435 140 err = rt.allocate(strlen(src_params[j].name)+1,
duke@435 141 (unsigned char**)&(dst_params[j].name));
duke@435 142 if (err != JVMTI_ERROR_NONE) {
duke@435 143 return err;
duke@435 144 }
duke@435 145 strcpy(dst_params[j].name, src_params[j].name);
duke@435 146
duke@435 147 dst_params[j].kind = src_params[j].kind;
duke@435 148 dst_params[j].base_type = src_params[j].base_type;
duke@435 149 dst_params[j].null_ok = src_params[j].null_ok;
duke@435 150 }
duke@435 151 }
duke@435 152
duke@435 153 // errors
duke@435 154
duke@435 155 jint error_count = _ext_functions->at(i)->error_count;
duke@435 156 ext_funcs[i].error_count = error_count;
duke@435 157 if (error_count == 0) {
duke@435 158 ext_funcs[i].errors = NULL;
duke@435 159 } else {
duke@435 160 err = rt.allocate(error_count*sizeof(jvmtiError),
duke@435 161 (unsigned char**)&(ext_funcs[i].errors));
duke@435 162 if (err != JVMTI_ERROR_NONE) {
duke@435 163 return err;
duke@435 164 }
duke@435 165 memcpy(ext_funcs[i].errors, _ext_functions->at(i)->errors,
duke@435 166 error_count*sizeof(jvmtiError));
duke@435 167 }
duke@435 168 }
duke@435 169
duke@435 170 *extension_count_ptr = _ext_functions->length();
duke@435 171 *extensions = ext_funcs;
duke@435 172 return JVMTI_ERROR_NONE;
duke@435 173 }
duke@435 174
duke@435 175
duke@435 176 // return the list of extension events
duke@435 177
duke@435 178 jvmtiError JvmtiExtensions::get_events(JvmtiEnv* env,
duke@435 179 jint* extension_count_ptr,
duke@435 180 jvmtiExtensionEventInfo** extensions)
duke@435 181 {
duke@435 182 guarantee(_ext_events != NULL, "registration not done");
duke@435 183
duke@435 184 ResourceTracker rt(env);
duke@435 185
duke@435 186 jvmtiExtensionEventInfo* ext_events;
duke@435 187 jvmtiError err = rt.allocate(_ext_events->length() * sizeof(jvmtiExtensionEventInfo),
duke@435 188 (unsigned char**)&ext_events);
duke@435 189 if (err != JVMTI_ERROR_NONE) {
duke@435 190 return err;
duke@435 191 }
duke@435 192
duke@435 193 for (int i=0; i<_ext_events->length(); i++ ) {
duke@435 194 ext_events[i].extension_event_index = _ext_events->at(i)->extension_event_index;
duke@435 195
duke@435 196 char *id = _ext_events->at(i)->id;
duke@435 197 err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_events[i].id));
duke@435 198 if (err != JVMTI_ERROR_NONE) {
duke@435 199 return err;
duke@435 200 }
duke@435 201 strcpy(ext_events[i].id, id);
duke@435 202
duke@435 203 char *desc = _ext_events->at(i)->short_description;
duke@435 204 err = rt.allocate(strlen(desc)+1,
duke@435 205 (unsigned char**)&(ext_events[i].short_description));
duke@435 206 if (err != JVMTI_ERROR_NONE) {
duke@435 207 return err;
duke@435 208 }
duke@435 209 strcpy(ext_events[i].short_description, desc);
duke@435 210
duke@435 211 // params
duke@435 212
duke@435 213 jint param_count = _ext_events->at(i)->param_count;
duke@435 214
duke@435 215 ext_events[i].param_count = param_count;
duke@435 216 if (param_count == 0) {
duke@435 217 ext_events[i].params = NULL;
duke@435 218 } else {
duke@435 219 err = rt.allocate(param_count*sizeof(jvmtiParamInfo),
duke@435 220 (unsigned char**)&(ext_events[i].params));
duke@435 221 if (err != JVMTI_ERROR_NONE) {
duke@435 222 return err;
duke@435 223 }
duke@435 224 jvmtiParamInfo* src_params = _ext_events->at(i)->params;
duke@435 225 jvmtiParamInfo* dst_params = ext_events[i].params;
duke@435 226
duke@435 227 for (int j=0; j<param_count; j++) {
duke@435 228 err = rt.allocate(strlen(src_params[j].name)+1,
duke@435 229 (unsigned char**)&(dst_params[j].name));
duke@435 230 if (err != JVMTI_ERROR_NONE) {
duke@435 231 return err;
duke@435 232 }
duke@435 233 strcpy(dst_params[j].name, src_params[j].name);
duke@435 234
duke@435 235 dst_params[j].kind = src_params[j].kind;
duke@435 236 dst_params[j].base_type = src_params[j].base_type;
duke@435 237 dst_params[j].null_ok = src_params[j].null_ok;
duke@435 238 }
duke@435 239 }
duke@435 240 }
duke@435 241
duke@435 242 *extension_count_ptr = _ext_events->length();
duke@435 243 *extensions = ext_events;
duke@435 244 return JVMTI_ERROR_NONE;
duke@435 245 }
duke@435 246
duke@435 247 // set callback for an extension event and enable/disable it.
duke@435 248
duke@435 249 jvmtiError JvmtiExtensions::set_event_callback(JvmtiEnv* env,
duke@435 250 jint extension_event_index,
duke@435 251 jvmtiExtensionEvent callback)
duke@435 252 {
duke@435 253 guarantee(_ext_events != NULL, "registration not done");
duke@435 254
duke@435 255 jvmtiExtensionEventInfo* event = NULL;
duke@435 256
duke@435 257 // if there are extension events registered then validate that the
duke@435 258 // extension_event_index matches one of the registered events.
duke@435 259 if (_ext_events != NULL) {
duke@435 260 for (int i=0; i<_ext_events->length(); i++ ) {
duke@435 261 if (_ext_events->at(i)->extension_event_index == extension_event_index) {
duke@435 262 event = _ext_events->at(i);
duke@435 263 break;
duke@435 264 }
duke@435 265 }
duke@435 266 }
duke@435 267
duke@435 268 // invalid event index
duke@435 269 if (event == NULL) {
duke@435 270 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
duke@435 271 }
duke@435 272
duke@435 273 JvmtiEventController::set_extension_event_callback(env, extension_event_index,
duke@435 274 callback);
duke@435 275
duke@435 276 return JVMTI_ERROR_NONE;
duke@435 277 }

mercurial