hotspot/src/share/vm/prims/jvmtiEnvBase.hpp
author coleenp
Wed, 14 Jan 2009 20:14:19 -0500
changeset 1904 7aada8102b30
parent 1 489c9b5090e2
child 4491 212bd48525d4
child 2137 b03f1da1a3d3
permissions -rw-r--r--
6793825: Missing include dependancies for GCC without predefined headers Summary: With predefined headers off for gcc, some .inline.hpp files aren't included to make definition visible for inline functions Reviewed-by: jcoomes, xlu
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-2006 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
#ifndef _JAVA_JVMTIENVBASE_H_
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#define _JAVA_JVMTIENVBASE_H_
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Forward Declarations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
class JvmtiEnv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class JvmtiThreadState;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
class JvmtiRawMonitor; // for jvmtiEnv.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class JvmtiEventControllerPrivate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class JvmtiTagMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// One JvmtiEnv object is created per jvmti attachment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// done via JNI GetEnv() call. Multiple attachments are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// allowed in jvmti.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class JvmtiEnvBase : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  static JvmtiEnvBase*     _head_environment;  // head of environment list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  static bool              _globally_initialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  static jvmtiPhase        _phase;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  static volatile int      _dying_thread_env_iteration_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    JDK15_JVMTI_VERSION = JVMTI_VERSION_1_0 +  33,  /* version: 1.0.33  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    JDK16_JVMTI_VERSION = JVMTI_VERSION_1_1 + 102   /* version: 1.1.102 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static jvmtiPhase  get_phase()                    { return _phase; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  static void  set_phase(jvmtiPhase phase)          { _phase = phase; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  static bool is_vm_live()                          { return _phase == JVMTI_PHASE_LIVE; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  static void entering_dying_thread_env_iteration() { ++_dying_thread_env_iteration_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static void leaving_dying_thread_env_iteration()  { --_dying_thread_env_iteration_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static bool is_inside_dying_thread_env_iteration(){ return _dying_thread_env_iteration_count > 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      JVMTI_MAGIC    = 0x71EE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      DISPOSED_MAGIC = 0xDEFC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      BAD_MAGIC      = 0xDEAD
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  jvmtiEnv _jvmti_external;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  jint _magic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  JvmtiEnvBase* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  bool _is_retransformable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  const void *_env_local_storage;     // per env agent allocated data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  jvmtiEventCallbacks _event_callbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  jvmtiExtEventCallbacks _ext_event_callbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  JvmtiTagMap* _tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  JvmtiEnvEventEnable _env_event_enable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  jvmtiCapabilities _current_capabilities;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  jvmtiCapabilities _prohibited_capabilities;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  volatile bool _class_file_load_hook_ever_enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  static volatile bool _needs_clean_up;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  char** _native_method_prefixes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int    _native_method_prefix_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  JvmtiEnvBase();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  ~JvmtiEnvBase();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  void dispose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  void env_dispose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void set_env_local_storage(const void* data)     { _env_local_storage = data; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  const void* get_env_local_storage()              { return _env_local_storage; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void record_class_file_load_hook_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  void record_first_time_class_file_load_hook_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  char** get_native_method_prefixes()              { return _native_method_prefixes; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  int    get_native_method_prefix_count()          { return _native_method_prefix_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  jvmtiError set_native_method_prefixes(jint prefix_count, char** prefixes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  friend class JvmtiEventControllerPrivate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  void set_event_callbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  static void globally_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  static void periodic_clean_up();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  friend class JvmtiEnvIterator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  JvmtiEnv* next_environment()                     { return (JvmtiEnv*)_next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void set_next_environment(JvmtiEnvBase* env)     { _next = env; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static JvmtiEnv* head_environment()              { return (JvmtiEnv*)_head_environment; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  bool is_valid()                                  { return _magic == JVMTI_MAGIC; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  bool is_retransformable()                        { return _is_retransformable; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  static ByteSize jvmti_external_offset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    return byte_offset_of(JvmtiEnvBase, _jvmti_external);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static JvmtiEnv* JvmtiEnv_from_jvmti_env(jvmtiEnv *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    return (JvmtiEnv*)((intptr_t)env - in_bytes(jvmti_external_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  jvmtiCapabilities *get_capabilities()             { return &_current_capabilities; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  jvmtiCapabilities *get_prohibited_capabilities()  { return &_prohibited_capabilities; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static char** get_all_native_method_prefixes(int* count_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // This test will answer true when all environments have been disposed and some have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // not yet been deallocated.  As a result, this test should only be used as an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // optimization for the no environment case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static bool environments_might_exist() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    return head_environment() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static void check_for_periodic_clean_up();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  JvmtiEnvEventEnable *env_event_enable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return &_env_event_enable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  jvmtiError allocate(jlong size, unsigned char** mem_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (size < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      return JVMTI_ERROR_ILLEGAL_ARGUMENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (size == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      *mem_ptr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      *mem_ptr = (unsigned char *)os::malloc((size_t)size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      if (*mem_ptr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        return JVMTI_ERROR_OUT_OF_MEMORY;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  jvmtiError deallocate(unsigned char* mem) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    if (mem != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      os::free(mem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    }
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
  // Memory functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  unsigned char* jvmtiMalloc(jlong size);  // don't use this - call allocate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // method to create a local handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  jobject jni_reference(Handle hndl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    return JNIHandles::make_local(hndl());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // method to create a local handle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // This function allows caller to specify which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // threads local handle table to use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  jobject jni_reference(JavaThread *thread, Handle hndl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    return JNIHandles::make_local(thread, hndl());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // method to destroy a local handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  void destroy_jni_reference(jobject jobj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    JNIHandles::destroy_local(jobj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // method to destroy a local handle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // This function allows caller to specify which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // threads local handle table to use although currently it is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // not used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  void destroy_jni_reference(JavaThread *thread, jobject jobj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    destroy_jni_reference(jobj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  jvmtiEnv* jvmti_external() { return &_jvmti_external; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// Event Dispatch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  bool has_callback(jvmtiEvent event_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    assert(event_type >= JVMTI_MIN_EVENT_TYPE_VAL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
           event_type <= JVMTI_MAX_EVENT_TYPE_VAL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    return ((void**)&_event_callbacks)[event_type-JVMTI_MIN_EVENT_TYPE_VAL] != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  jvmtiEventCallbacks* callbacks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    return &_event_callbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  jvmtiExtEventCallbacks* ext_callbacks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    return &_ext_event_callbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  void set_tag_map(JvmtiTagMap* tag_map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    _tag_map = tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  JvmtiTagMap* tag_map() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    return _tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // return true if event is enabled globally or for any thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // True only if there is a callback for it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  bool is_enabled(jvmtiEvent event_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    return _env_event_enable.is_enabled(event_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
// Random Utilities
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  // helper methods for creating arrays of global JNI Handles from local Handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // allocated into environment specific storage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  jobject * new_jobjectArray(int length, Handle *handles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  jthread * new_jthreadArray(int length, Handle *handles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  jthreadGroup * new_jthreadGroupArray(int length, Handle *handles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // convert from JNIHandle to JavaThread *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  JavaThread  * get_JavaThread(jthread jni_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // convert to a jni jclass from a non-null klassOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  jclass get_jni_class_non_null(klassOop k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  void update_klass_field_access_flag(fieldDescriptor *fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  jint count_locked_objects(JavaThread *java_thread, Handle hobj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
                                   JavaThread* java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
                                   javaVFrame *jvf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
                                   GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                                   jint depth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  vframe* vframeFor(JavaThread* java_thread, jint depth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // get a field descriptor for the specified class and field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  static bool get_field_descriptor(klassOop k, jfieldID field, fieldDescriptor* fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // test for suspend - most (all?) of these should go away
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  static bool is_thread_fully_suspended(JavaThread *thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
                                        bool wait_for_suspend,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
                                        uint32_t *bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // JVMTI API helper functions which are called at safepoint or thread is suspended.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
                                              jmethodID* method_ptr, jlocation* location_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
                                                    jobject object, jvmtiMonitorUsage* info_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  jvmtiError get_stack_trace(JavaThread *java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
                                           jint stack_depth, jint max_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
                                           jvmtiFrameInfo* frame_buffer, jint* count_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  jvmtiError get_current_contended_monitor(JavaThread *calling_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
                                                         JavaThread *java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                                                         jobject *monitor_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
                          GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
                             jvalue value, TosState tos, Handle* ret_ob_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
// This class is the only safe means of iterating through environments.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
// Note that this iteratation includes invalid environments pending
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// deallocation -- in fact, some uses depend on this behavior.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
class JvmtiEnvIterator : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  bool _entry_was_marked;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  JvmtiEnvIterator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    if (Threads::number_of_threads() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      _entry_was_marked = false; // we are single-threaded, no need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      Thread::current()->entering_jvmti_env_iteration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      _entry_was_marked = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  ~JvmtiEnvIterator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    if (_entry_was_marked) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      Thread::current()->leaving_jvmti_env_iteration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  JvmtiEnv* first()                 { return JvmtiEnvBase::head_environment(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
// VM operation to get monitor information with stack depth.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
class VM_GetOwnedMonitorInfo : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  JavaThread* _calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  JavaThread *_java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  VM_GetOwnedMonitorInfo(JvmtiEnv* env, JavaThread* calling_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
                                   JavaThread* java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
                                   GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    _calling_thread = calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    _java_thread = java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    _owned_monitors_list = owned_monitor_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    _result = JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
                                                         _owned_monitors_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  jvmtiError result() { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// VM operation to get object monitor usage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
class VM_GetObjectMonitorUsage : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  jobject _object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  JavaThread* _calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  jvmtiMonitorUsage* _info_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    _object = object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    _calling_thread = calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    _info_ptr = info_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  VMOp_Type type() const { return VMOp_GetObjectMonitorUsage; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  jvmtiError result() { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    _result = ((JvmtiEnvBase*) _env)->get_object_monitor_usage(_calling_thread, _object, _info_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// VM operation to get current contended monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
class VM_GetCurrentContendedMonitor : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  JavaThread *_calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  JavaThread *_java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  jobject *_owned_monitor_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  VM_GetCurrentContendedMonitor(JvmtiEnv *env, JavaThread *calling_thread, JavaThread *java_thread, jobject *mon_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    _calling_thread = calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    _java_thread = java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    _owned_monitor_ptr = mon_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  VMOp_Type type() const { return VMOp_GetCurrentContendedMonitor; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  jvmtiError result() { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    _result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor(_calling_thread,_java_thread,_owned_monitor_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// VM operation to get stack trace at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
class VM_GetStackTrace : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  JavaThread *_java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  jint _start_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  jint _max_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  jvmtiFrameInfo *_frame_buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  jint *_count_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
                   jint start_depth, jint max_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
                   jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    _java_thread = java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    _start_depth = start_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    _max_count = max_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    _frame_buffer = frame_buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    _count_ptr = count_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  jvmtiError result() { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  VMOp_Type type() const { return VMOp_GetStackTrace; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
                                                      _start_depth, _max_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
                                                      _frame_buffer, _count_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
// forward declaration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
struct StackInfoNode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
// VM operation to get stack trace at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
class VM_GetMultipleStackTraces : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  jint _max_frame_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  jvmtiStackInfo *_stack_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  int _frame_count_total;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  struct StackInfoNode *_head;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  JvmtiEnvBase *env()                 { return (JvmtiEnvBase *)_env; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  jint max_frame_count()              { return _max_frame_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  struct StackInfoNode *head()        { return _head; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  void set_head(StackInfoNode *head)  { _head = head; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  void set_result(jvmtiError result)  { _result = result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  void fill_frames(jthread jt, JavaThread *thr, oop thread_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  void allocate_and_fill_stacks(jint thread_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  VM_GetMultipleStackTraces(JvmtiEnv *env, jint max_frame_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    _max_frame_count = max_frame_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    _frame_count_total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    _head = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    _result = JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  VMOp_Type type() const             { return VMOp_GetMultipleStackTraces; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  jvmtiStackInfo *stack_info()       { return _stack_info; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  jvmtiError result()                { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
// VM operation to get stack trace at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
class VM_GetAllStackTraces : public VM_GetMultipleStackTraces {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  JavaThread *_calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  jint _final_thread_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  VM_GetAllStackTraces(JvmtiEnv *env, JavaThread *calling_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
                       jint max_frame_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      : VM_GetMultipleStackTraces(env, max_frame_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    _calling_thread = calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  VMOp_Type type() const          { return VMOp_GetAllStackTraces; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  jint final_thread_count()       { return _final_thread_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
// VM operation to get stack trace at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
class VM_GetThreadListStackTraces : public VM_GetMultipleStackTraces {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  jint _thread_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  const jthread* _thread_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  VM_GetThreadListStackTraces(JvmtiEnv *env, jint thread_count, const jthread* thread_list, jint max_frame_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
      : VM_GetMultipleStackTraces(env, max_frame_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    _thread_count = thread_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    _thread_list = thread_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  VMOp_Type type() const { return VMOp_GetThreadListStackTraces; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
// VM operation to count stack frames at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
class VM_GetFrameCount : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  JvmtiThreadState *_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  jint *_count_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    _state = state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    _count_ptr = count_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  VMOp_Type type() const { return VMOp_GetFrameCount; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  jvmtiError result()    { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    _result = ((JvmtiEnvBase*)_env)->get_frame_count(_state, _count_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
// VM operation to frame location at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
class VM_GetFrameLocation : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  JvmtiEnv *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  JavaThread* _java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  jint _depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  jmethodID* _method_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  jlocation* _location_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  jvmtiError _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  VM_GetFrameLocation(JvmtiEnv *env, JavaThread* java_thread, jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
                      jmethodID* method_ptr, jlocation* location_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    _java_thread = java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    _depth = depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    _method_ptr = method_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    _location_ptr = location_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  VMOp_Type type() const { return VMOp_GetFrameLocation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  jvmtiError result()    { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    _result = ((JvmtiEnvBase*)_env)->get_frame_location(_java_thread, _depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
                                                        _method_ptr, _location_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
// ResourceTracker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
// ResourceTracker works a little like a ResourceMark. All allocates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
// using the resource tracker are recorded. If an allocate using the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
// resource tracker fails the destructor will free any resources
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
// that were allocated using the tracker.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
// The motive for this class is to avoid messy error recovery code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
// in situations where multiple allocations are done in sequence. If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
// the second or subsequent allocation fails it avoids any code to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
// release memory allocated in the previous calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
// Usage :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
//   ResourceTracker rt(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
//   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
//   err = rt.allocate(1024, &ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
class ResourceTracker : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  JvmtiEnv* _env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  GrowableArray<unsigned char*> *_allocations;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  bool _failed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  ResourceTracker(JvmtiEnv* env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  ~ResourceTracker();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  jvmtiError allocate(jlong size, unsigned char** mem_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  unsigned char* allocate(jlong size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  char* strdup(const char* str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
// Jvmti monitor closure to collect off stack monitors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
class JvmtiMonitorClosure: public MonitorClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  JavaThread *_java_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  JavaThread *_calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  jvmtiError _error;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  JvmtiEnvBase *_env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  JvmtiMonitorClosure(JavaThread* thread, JavaThread *calling_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
                      GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
                      JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    _java_thread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    _calling_thread = calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    _owned_monitors_list = owned_monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    _error = JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  void do_monitor(ObjectMonitor* mon);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  jvmtiError error() { return _error;}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
#endif   /* _JAVA_JVMTIENVBASE_H_ */