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