src/hotspot/share/prims/jvmtiExtensions.cpp
author sspitsyn
Wed, 10 Apr 2019 17:29:03 -0700
changeset 54497 96230a5ef2ec
parent 47216 71c04702a3d5
permissions -rw-r--r--
8222072: JVMTI GenerateEvents() sends CompiledMethodLoad events to wrong jvmtiEnv Summary: Fix GenerateEvents() to send CompiledMethodLoad events to requesting agent only Reviewed-by: jcbeyler, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13195
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "prims/jvmtiExport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "prims/jvmtiExtensions.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// the list of extension functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
GrowableArray<jvmtiExtensionFunctionInfo*>* JvmtiExtensions::_ext_functions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// the list of extension events
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
GrowableArray<jvmtiExtensionEventInfo*>* JvmtiExtensions::_ext_events;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// extension function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
static jvmtiError JNICALL IsClassUnloadingEnabled(const jvmtiEnv* env, jboolean* enabled, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  if (enabled == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    return JVMTI_ERROR_NULL_POINTER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  *enabled = (jboolean)ClassUnloading;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// register extension functions and events. In this implementation we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// have a single extension function (to prove the API) that tests if class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// unloading is enabled or disabled. We also have a single extension event
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// EXT_EVENT_CLASS_UNLOAD which is used to provide the JVMDI_EVENT_CLASS_UNLOAD
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// event. The function and the event are registered here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
void JvmtiExtensions::register_extensions() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    52
  _ext_functions = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiExtensionFunctionInfo*>(1,true);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    53
  _ext_events = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiExtensionEventInfo*>(1,true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // register our extension function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static jvmtiParamInfo func_params[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    { (char*)"IsClassUnloadingEnabled", JVMTI_KIND_OUT,  JVMTI_TYPE_JBOOLEAN, JNI_FALSE }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  static jvmtiExtensionFunctionInfo ext_func = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    (jvmtiExtensionFunction)IsClassUnloadingEnabled,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    (char*)"Tell if class unloading is enabled (-noclassgc)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    sizeof(func_params)/sizeof(func_params[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    func_params,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    0,              // no non-universal errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _ext_functions->append(&ext_func);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // register our extension event
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static jvmtiParamInfo event_params[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    { (char*)"JNI Environment", JVMTI_KIND_IN, JVMTI_TYPE_JNIENV, JNI_FALSE },
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    { (char*)"Thread", JVMTI_KIND_IN, JVMTI_TYPE_JTHREAD, JNI_FALSE },
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    { (char*)"Class", JVMTI_KIND_IN, JVMTI_TYPE_JCLASS, JNI_FALSE }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static jvmtiExtensionEventInfo ext_event = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    EXT_EVENT_CLASS_UNLOAD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    (char*)"com.sun.hotspot.events.ClassUnload",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    (char*)"CLASS_UNLOAD event",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    sizeof(event_params)/sizeof(event_params[0]),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    event_params
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _ext_events->append(&ext_event);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// return the list of extension functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
jvmtiError JvmtiExtensions::get_functions(JvmtiEnv* env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                                          jint* extension_count_ptr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                                          jvmtiExtensionFunctionInfo** extensions)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  guarantee(_ext_functions != NULL, "registration not done");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  ResourceTracker rt(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  jvmtiExtensionFunctionInfo* ext_funcs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  jvmtiError err = rt.allocate(_ext_functions->length() *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                               sizeof(jvmtiExtensionFunctionInfo),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                               (unsigned char**)&ext_funcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  for (int i=0; i<_ext_functions->length(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    ext_funcs[i].func = _ext_functions->at(i)->func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    char *id = _ext_functions->at(i)->id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_funcs[i].id));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    strcpy(ext_funcs[i].id, id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    char *desc = _ext_functions->at(i)->short_description;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    err = rt.allocate(strlen(desc)+1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
                      (unsigned char**)&(ext_funcs[i].short_description));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    strcpy(ext_funcs[i].short_description, desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // params
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    jint param_count = _ext_functions->at(i)->param_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    ext_funcs[i].param_count = param_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    if (param_count == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      ext_funcs[i].params = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      err = rt.allocate(param_count*sizeof(jvmtiParamInfo),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                        (unsigned char**)&(ext_funcs[i].params));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      jvmtiParamInfo* src_params = _ext_functions->at(i)->params;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      jvmtiParamInfo* dst_params = ext_funcs[i].params;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      for (int j=0; j<param_count; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        err = rt.allocate(strlen(src_params[j].name)+1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                          (unsigned char**)&(dst_params[j].name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
          return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        strcpy(dst_params[j].name, src_params[j].name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        dst_params[j].kind = src_params[j].kind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        dst_params[j].base_type = src_params[j].base_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        dst_params[j].null_ok = src_params[j].null_ok;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    // errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    jint error_count = _ext_functions->at(i)->error_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    ext_funcs[i].error_count = error_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (error_count == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      ext_funcs[i].errors = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      err = rt.allocate(error_count*sizeof(jvmtiError),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
                        (unsigned char**)&(ext_funcs[i].errors));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      memcpy(ext_funcs[i].errors, _ext_functions->at(i)->errors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
             error_count*sizeof(jvmtiError));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  *extension_count_ptr = _ext_functions->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  *extensions = ext_funcs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// return the list of extension events
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
jvmtiError JvmtiExtensions::get_events(JvmtiEnv* env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                                       jint* extension_count_ptr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                                       jvmtiExtensionEventInfo** extensions)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  guarantee(_ext_events != NULL, "registration not done");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  ResourceTracker rt(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  jvmtiExtensionEventInfo* ext_events;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  jvmtiError err = rt.allocate(_ext_events->length() * sizeof(jvmtiExtensionEventInfo),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
                               (unsigned char**)&ext_events);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  for (int i=0; i<_ext_events->length(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    ext_events[i].extension_event_index = _ext_events->at(i)->extension_event_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    char *id = _ext_events->at(i)->id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    err = rt.allocate(strlen(id)+1, (unsigned char**)&(ext_events[i].id));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    strcpy(ext_events[i].id, id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    char *desc = _ext_events->at(i)->short_description;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    err = rt.allocate(strlen(desc)+1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                      (unsigned char**)&(ext_events[i].short_description));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    strcpy(ext_events[i].short_description, desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    // params
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    jint param_count = _ext_events->at(i)->param_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    ext_events[i].param_count = param_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    if (param_count == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      ext_events[i].params = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      err = rt.allocate(param_count*sizeof(jvmtiParamInfo),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
                        (unsigned char**)&(ext_events[i].params));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      jvmtiParamInfo* src_params = _ext_events->at(i)->params;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      jvmtiParamInfo* dst_params = ext_events[i].params;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      for (int j=0; j<param_count; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        err = rt.allocate(strlen(src_params[j].name)+1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
                          (unsigned char**)&(dst_params[j].name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        strcpy(dst_params[j].name, src_params[j].name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        dst_params[j].kind = src_params[j].kind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        dst_params[j].base_type = src_params[j].base_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        dst_params[j].null_ok = src_params[j].null_ok;
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  *extension_count_ptr = _ext_events->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  *extensions = ext_events;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
// set callback for an extension event and enable/disable it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
jvmtiError JvmtiExtensions::set_event_callback(JvmtiEnv* env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                                               jint extension_event_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
                                               jvmtiExtensionEvent callback)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  guarantee(_ext_events != NULL, "registration not done");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  jvmtiExtensionEventInfo* event = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // if there are extension events registered then validate that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // extension_event_index matches one of the registered events.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  if (_ext_events != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    for (int i=0; i<_ext_events->length(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      if (_ext_events->at(i)->extension_event_index == extension_event_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
         event = _ext_events->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
         break;
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // invalid event index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (event == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    return JVMTI_ERROR_ILLEGAL_ARGUMENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  JvmtiEventController::set_extension_event_callback(env, extension_event_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
                                                     callback);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}