You need to sign in or sign up before continuing.
jvmtiExport.hpp 23.2 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright 1998-2010 Sun Microsystems, Inc.  All Rights Reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

#ifndef _JAVA_JVMTIEXPORT_H_
#define _JAVA_JVMTIEXPORT_H_

// Forward declarations

class JvmtiEventControllerPrivate;
class JvmtiManageCapabilities;
class JvmtiEnv;
class JvmtiThreadState;
class AttachOperation;

#ifndef JVMTI_KERNEL
#define JVMTI_SUPPORT_FLAG(key)                                         \
  private:                                                              \
  static bool  _##key;                                                  \
  public:                                                               \
  inline static void set_##key(bool on)       { _##key = (on != 0); }   \
  inline static bool key()                    { return _##key; }
#else  // JVMTI_KERNEL
#define JVMTI_SUPPORT_FLAG(key)                                           \
  private:                                                                \
  const static bool _##key = false;                                       \
  public:                                                                 \
  inline static void set_##key(bool on)       { report_unsupported(on); } \
  inline static bool key()                    { return _##key; }
#endif // JVMTI_KERNEL


// This class contains the JVMTI interface for the rest of hotspot.
//
class JvmtiExport : public AllStatic {
 private:
  static int         _field_access_count;
  static int         _field_modification_count;

  static bool        _can_access_local_variables;
  static bool        _can_hotswap_or_post_breakpoint;
  static bool        _can_modify_any_class;
  static bool        _can_walk_any_space;

  JVMTI_SUPPORT_FLAG(can_get_source_debug_extension)
  JVMTI_SUPPORT_FLAG(can_maintain_original_method_order)
  JVMTI_SUPPORT_FLAG(can_post_interpreter_events)
68
  JVMTI_SUPPORT_FLAG(can_post_on_exceptions)
D
duke 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  JVMTI_SUPPORT_FLAG(can_post_breakpoint)
  JVMTI_SUPPORT_FLAG(can_post_field_access)
  JVMTI_SUPPORT_FLAG(can_post_field_modification)
  JVMTI_SUPPORT_FLAG(can_post_method_entry)
  JVMTI_SUPPORT_FLAG(can_post_method_exit)
  JVMTI_SUPPORT_FLAG(can_pop_frame)
  JVMTI_SUPPORT_FLAG(can_force_early_return)

  friend class JvmtiEventControllerPrivate;  // should only modify these flags
  JVMTI_SUPPORT_FLAG(should_post_single_step)
  JVMTI_SUPPORT_FLAG(should_post_field_access)
  JVMTI_SUPPORT_FLAG(should_post_field_modification)
  JVMTI_SUPPORT_FLAG(should_post_class_load)
  JVMTI_SUPPORT_FLAG(should_post_class_prepare)
  JVMTI_SUPPORT_FLAG(should_post_class_unload)
  JVMTI_SUPPORT_FLAG(should_post_native_method_bind)
  JVMTI_SUPPORT_FLAG(should_post_compiled_method_load)
  JVMTI_SUPPORT_FLAG(should_post_compiled_method_unload)
  JVMTI_SUPPORT_FLAG(should_post_dynamic_code_generated)
  JVMTI_SUPPORT_FLAG(should_post_monitor_contended_enter)
  JVMTI_SUPPORT_FLAG(should_post_monitor_contended_entered)
  JVMTI_SUPPORT_FLAG(should_post_monitor_wait)
  JVMTI_SUPPORT_FLAG(should_post_monitor_waited)
  JVMTI_SUPPORT_FLAG(should_post_data_dump)
  JVMTI_SUPPORT_FLAG(should_post_garbage_collection_start)
  JVMTI_SUPPORT_FLAG(should_post_garbage_collection_finish)
95
  JVMTI_SUPPORT_FLAG(should_post_on_exceptions)
D
duke 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

  // ------ the below maybe don't have to be (but are for now)
  // fixed conditions here ------------
  // any events can be enabled
  JVMTI_SUPPORT_FLAG(should_post_thread_life)
  JVMTI_SUPPORT_FLAG(should_post_object_free)
  JVMTI_SUPPORT_FLAG(should_post_resource_exhausted)

  // we are holding objects on the heap - need to talk to GC - e.g.
  // breakpoint info
  JVMTI_SUPPORT_FLAG(should_clean_up_heap_objects)
  JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc)

  // If flag cannot be implemented, give an error if on=true
  static void report_unsupported(bool on);

  // these should only be called by the friend class
  friend class JvmtiManageCapabilities;
  inline static void set_can_modify_any_class(bool on)                 { _can_modify_any_class = (on != 0); }
  inline static void set_can_access_local_variables(bool on)           { _can_access_local_variables = (on != 0); }
  inline static void set_can_hotswap_or_post_breakpoint(bool on)       { _can_hotswap_or_post_breakpoint = (on != 0); }
  inline static void set_can_walk_any_space(bool on)                   { _can_walk_any_space = (on != 0); }

  enum {
    JVMTI_VERSION_MASK   = 0x70000000,
    JVMTI_VERSION_VALUE  = 0x30000000,
    JVMDI_VERSION_VALUE  = 0x20000000
  };

  static void post_field_modification(JavaThread *thread, methodOop method, address location,
                                      KlassHandle field_klass, Handle object, jfieldID field,
                                      char sig_type, jvalue *value);


 private:
  // CompiledMethodUnload events are reported from the VM thread so they
  // are collected in lists (of jmethodID/addresses) and the events are posted later
  // from threads posting CompieldMethodLoad or DynamicCodeGenerated events.
  static bool _have_pending_compiled_method_unload_events;
  static GrowableArray<jmethodID>* _pending_compiled_method_unload_method_ids;
  static GrowableArray<const void *>* _pending_compiled_method_unload_code_begins;
  static JavaThread* _current_poster;

  // tests if there are CompiledMethodUnload events pending
  inline static bool have_pending_compiled_method_unload_events() {
    return _have_pending_compiled_method_unload_events;
  }

  // posts any pending CompiledMethodUnload events.
  static void post_pending_compiled_method_unload_events();

  // posts a DynamicCodeGenerated event (internal/private implementation).
  // The public post_dynamic_code_generated* functions make use of the
  // internal implementation.
  static void post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) KERNEL_RETURN;


  // GenerateEvents support to allow posting of CompiledMethodLoad and
  // DynamicCodeGenerated events for a given environment.
  friend class JvmtiCodeBlobEvents;

  static void post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
                                        const void *code_begin, const jint map_length,
                                        const jvmtiAddrLocationMap* map) KERNEL_RETURN;
  static void post_dynamic_code_generated(JvmtiEnv* env, const char *name, const void *code_begin,
                                          const void *code_end) KERNEL_RETURN;

  // The RedefineClasses() API breaks some invariants in the "regular"
  // system. For example, there are sanity checks when GC'ing nmethods
  // that require the containing class to be unloading. However, when a
  // method is redefined, the old method and nmethod can become GC'able
  // without the containing class unloading. The state of becoming
  // GC'able can be asynchronous to the RedefineClasses() call since
  // the old method may still be running and cannot be GC'ed until
  // after all old invocations have finished. Additionally, a method
  // that has not been redefined may have an nmethod that depends on
  // the redefined method. The dependent nmethod will get deopted in
  // this case and may also be GC'able without the containing class
  // being unloaded.
  //
  // This flag indicates whether RedefineClasses() has ever redefined
  // one or more classes during the lifetime of the VM. The flag should
  // only be set by the friend class and can be queried by other sub
  // systems as needed to relax invariant checks.
  static bool _has_redefined_a_class;
  friend class VM_RedefineClasses;
  inline static void set_has_redefined_a_class() {
    _has_redefined_a_class = true;
  }

  // Flag to indicate if the compiler has recorded all dependencies. When the
  // can_redefine_classes capability is enabled in the OnLoad phase then the compiler
  // records all dependencies from startup. However if the capability is first
  // enabled some time later then the dependencies recorded by the compiler
  // are incomplete. This flag is used by RedefineClasses to know if the
  // dependency information is complete or not.
  static bool _all_dependencies_are_recorded;

 public:
  inline static bool has_redefined_a_class() {
    return _has_redefined_a_class;
  }

  inline static bool all_dependencies_are_recorded() {
    return _all_dependencies_are_recorded;
  }

  inline static void set_all_dependencies_are_recorded(bool on) {
    _all_dependencies_are_recorded = (on != 0);
  }


  // let JVMTI know that the JVM_OnLoad code is running
  static void enter_onload_phase();

  // let JVMTI know that the VM isn't up yet (and JVM_OnLoad code isn't running)
  static void enter_primordial_phase();

  // let JVMTI know that the VM isn't up yet but JNI is live
  static void enter_start_phase();

  // let JVMTI know that the VM is fully up and running now
  static void enter_live_phase();

  // ------ can_* conditions (below) are set at OnLoad and never changed ------------
  inline static bool can_modify_any_class()                       { return _can_modify_any_class; }
  inline static bool can_access_local_variables()                 { return _can_access_local_variables; }
  inline static bool can_hotswap_or_post_breakpoint()             { return _can_hotswap_or_post_breakpoint; }
  inline static bool can_walk_any_space()                         { return _can_walk_any_space; }

  // field access management
  static address  get_field_access_count_addr();

  // field modification management
  static address  get_field_modification_count_addr();

  // -----------------

  static bool is_jvmti_version(jint version)                      { return (version & JVMTI_VERSION_MASK) == JVMTI_VERSION_VALUE; }
  static bool is_jvmdi_version(jint version)                      { return (version & JVMTI_VERSION_MASK) == JVMDI_VERSION_VALUE; }
  static jint get_jvmti_interface(JavaVM *jvm, void **penv, jint version);
237 238
  static void decode_version_values(jint version, int * major, int * minor,
                                    int * micro);
D
duke 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553

  // single stepping management methods
  static void at_single_stepping_point(JavaThread *thread, methodOop method, address location) KERNEL_RETURN;
  static void expose_single_stepping(JavaThread *thread) KERNEL_RETURN;
  static bool hide_single_stepping(JavaThread *thread) KERNEL_RETURN_(return false;);

  // Methods that notify the debugger that something interesting has happened in the VM.
  static void post_vm_start              ();
  static void post_vm_initialized        ();
  static void post_vm_death              ();

  static void post_single_step           (JavaThread *thread, methodOop method, address location) KERNEL_RETURN;
  static void post_raw_breakpoint        (JavaThread *thread, methodOop method, address location) KERNEL_RETURN;

  static void post_exception_throw       (JavaThread *thread, methodOop method, address location, oop exception) KERNEL_RETURN;
  static void notice_unwind_due_to_exception (JavaThread *thread, methodOop method, address location, oop exception, bool in_handler_frame) KERNEL_RETURN;

  static oop jni_GetField_probe          (JavaThread *thread, jobject jobj,
    oop obj, klassOop klass, jfieldID fieldID, bool is_static)
    KERNEL_RETURN_(return NULL;);
  static oop jni_GetField_probe_nh       (JavaThread *thread, jobject jobj,
    oop obj, klassOop klass, jfieldID fieldID, bool is_static)
    KERNEL_RETURN_(return NULL;);
  static void post_field_access_by_jni   (JavaThread *thread, oop obj,
    klassOop klass, jfieldID fieldID, bool is_static) KERNEL_RETURN;
  static void post_field_access          (JavaThread *thread, methodOop method,
    address location, KlassHandle field_klass, Handle object, jfieldID field) KERNEL_RETURN;
  static oop jni_SetField_probe          (JavaThread *thread, jobject jobj,
    oop obj, klassOop klass, jfieldID fieldID, bool is_static, char sig_type,
    jvalue *value) KERNEL_RETURN_(return NULL;);
  static oop jni_SetField_probe_nh       (JavaThread *thread, jobject jobj,
    oop obj, klassOop klass, jfieldID fieldID, bool is_static, char sig_type,
    jvalue *value) KERNEL_RETURN_(return NULL;);
  static void post_field_modification_by_jni(JavaThread *thread, oop obj,
    klassOop klass, jfieldID fieldID, bool is_static, char sig_type,
    jvalue *value);
  static void post_raw_field_modification(JavaThread *thread, methodOop method,
    address location, KlassHandle field_klass, Handle object, jfieldID field,
    char sig_type, jvalue *value) KERNEL_RETURN;

  static void post_method_entry          (JavaThread *thread, methodOop method, frame current_frame) KERNEL_RETURN;
  static void post_method_exit           (JavaThread *thread, methodOop method, frame current_frame) KERNEL_RETURN;

  static void post_class_load            (JavaThread *thread, klassOop klass) KERNEL_RETURN;
  static void post_class_unload          (klassOop klass) KERNEL_RETURN;
  static void post_class_prepare         (JavaThread *thread, klassOop klass) KERNEL_RETURN;

  static void post_thread_start          (JavaThread *thread) KERNEL_RETURN;
  static void post_thread_end            (JavaThread *thread) KERNEL_RETURN;

  // Support for java.lang.instrument agent loading.
  static bool _should_post_class_file_load_hook;
  inline static void set_should_post_class_file_load_hook(bool on)     { _should_post_class_file_load_hook = on;  }
  inline static bool should_post_class_file_load_hook()           { return _should_post_class_file_load_hook; }
  static void post_class_file_load_hook(symbolHandle h_name, Handle class_loader,
                                        Handle h_protection_domain,
                                        unsigned char **data_ptr, unsigned char **end_ptr,
                                        unsigned char **cached_data_ptr,
                                        jint *cached_length_ptr);
  static void post_native_method_bind(methodOop method, address* function_ptr) KERNEL_RETURN;
  static void post_compiled_method_load(nmethod *nm) KERNEL_RETURN;
  static void post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) KERNEL_RETURN;

  // used at a safepoint to post a CompiledMethodUnload event
  static void post_compiled_method_unload_at_safepoint(jmethodID mid, const void *code_begin) KERNEL_RETURN;

  // similiar to post_dynamic_code_generated except that it can be used to
  // post a DynamicCodeGenerated event while holding locks in the VM. Any event
  // posted using this function is recorded by the enclosing event collector
  // -- JvmtiDynamicCodeEventCollector.
  static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) KERNEL_RETURN;

  static void post_garbage_collection_finish() KERNEL_RETURN;
  static void post_garbage_collection_start() KERNEL_RETURN;
  static void post_data_dump() KERNEL_RETURN;
  static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) KERNEL_RETURN;
  static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) KERNEL_RETURN;
  static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) KERNEL_RETURN;
  static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) KERNEL_RETURN;
  static void post_object_free(JvmtiEnv* env, jlong tag) KERNEL_RETURN;
  static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) KERNEL_RETURN;
  static void record_vm_internal_object_allocation(oop object) KERNEL_RETURN;
  // Post objects collected by vm_object_alloc_event_collector.
  static void post_vm_object_alloc(JavaThread *thread, oop object) KERNEL_RETURN;
  // Collects vm internal objects for later event posting.
  inline static void vm_object_alloc_event_collector(oop object) {
    if (should_post_vm_object_alloc()) {
      record_vm_internal_object_allocation(object);
    }
  }

  static void cleanup_thread             (JavaThread* thread) KERNEL_RETURN;

  static void oops_do(OopClosure* f) KERNEL_RETURN;

  static void transition_pending_onload_raw_monitors() KERNEL_RETURN;

#ifndef SERVICES_KERNEL
  // attach support
  static jint load_agent_library(AttachOperation* op, outputStream* out);
#endif // SERVICES_KERNEL

  // SetNativeMethodPrefix support
  static char** get_all_native_method_prefixes(int* count_ptr);

  // call after CMS has completed referencing processing
  static void cms_ref_processing_epilogue() KERNEL_RETURN;
};

// Support class used by JvmtiDynamicCodeEventCollector and others. It
// describes a single code blob by name and address range.
class JvmtiCodeBlobDesc : public CHeapObj {
 private:
  char _name[64];
  address _code_begin;
  address _code_end;

 public:
  JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) {
    assert(name != NULL, "all code blobs must be named");
    strncpy(_name, name, sizeof(_name));
    _name[sizeof(_name)-1] = '\0';
    _code_begin = code_begin;
    _code_end = code_end;
  }
  char* name()                  { return _name; }
  address code_begin()          { return _code_begin; }
  address code_end()            { return _code_end; }
};

// JvmtiEventCollector is a helper class to setup thread for
// event collection.
class JvmtiEventCollector : public StackObj {
 private:
  JvmtiEventCollector* _prev;  // Save previous one to support nested event collector.

 public:
  void setup_jvmti_thread_state(); // Set this collector in current thread.
  void unset_jvmti_thread_state(); // Reset previous collector in current thread.
  virtual bool is_dynamic_code_event()   { return false; }
  virtual bool is_vm_object_alloc_event(){ return false; }
  JvmtiEventCollector *get_prev()        { return _prev; }
};

// A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport
// interface. It collects "dynamic code generated" events that are posted
// while holding locks. When the event collector goes out of scope the
// events will be posted.
//
// Usage :-
//
// {
//   JvmtiDynamicCodeEventCollector event_collector;
//   :
//   { MutexLocker ml(...)
//     :
//     JvmtiExport::post_dynamic_code_generated_while_holding_locks(...)
//   }
//   // event collector goes out of scope => post events to profiler.
// }

class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector {
 private:
  GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs;           // collected code blob events

  friend class JvmtiExport;
  void register_stub(const char* name, address start, address end);

 public:
  JvmtiDynamicCodeEventCollector()  KERNEL_RETURN;
  ~JvmtiDynamicCodeEventCollector() KERNEL_RETURN;
  bool is_dynamic_code_event()   { return true; }

};

// Used to record vm internally allocated object oops and post
// vm object alloc event for objects visible to java world.
// Constructor enables JvmtiThreadState flag and all vm allocated
// objects are recorded in a growable array. When destructor is
// called the vm object alloc event is posted for each objects
// visible to java world.
// See jvm.cpp file for its usage.
//
class JvmtiVMObjectAllocEventCollector : public JvmtiEventCollector {
 private:
  GrowableArray<oop>* _allocated; // field to record vm internally allocated object oop.
  bool _enable;                   // This flag is enabled in constructor and disabled
                                  // in destructor before posting event. To avoid
                                  // collection of objects allocated while running java code inside
                                  // agent post_vm_object_alloc() event handler.

  //GC support
  void oops_do(OopClosure* f);

  friend class JvmtiExport;
  // Record vm allocated object oop.
  inline void record_allocation(oop obj);

  //GC support
  static void oops_do_for_all_threads(OopClosure* f);

 public:
  JvmtiVMObjectAllocEventCollector()  KERNEL_RETURN;
  ~JvmtiVMObjectAllocEventCollector() KERNEL_RETURN;
  bool is_vm_object_alloc_event()   { return true; }

  bool is_enabled()                 { return _enable; }
  void set_enabled(bool on)         { _enable = on; }
};



// Marker class to disable the posting of VMObjectAlloc events
// within its scope.
//
// Usage :-
//
// {
//   NoJvmtiVMObjectAllocMark njm;
//   :
//   // VMObjAlloc event will not be posted
//   JvmtiExport::vm_object_alloc_event_collector(obj);
//   :
// }

class NoJvmtiVMObjectAllocMark : public StackObj {
 private:
  // enclosing collector if enabled, NULL otherwise
  JvmtiVMObjectAllocEventCollector *_collector;

  bool was_enabled()    { return _collector != NULL; }

 public:
  NoJvmtiVMObjectAllocMark() KERNEL_RETURN;
  ~NoJvmtiVMObjectAllocMark() KERNEL_RETURN;
};


// Base class for reporting GC events to JVMTI.
class JvmtiGCMarker : public StackObj {
 private:
  bool _full;                           // marks a "full" GC
  unsigned int _invocation_count;       // GC invocation count
 protected:
  JvmtiGCMarker(bool full) KERNEL_RETURN;       // protected
  ~JvmtiGCMarker() KERNEL_RETURN;               // protected
};


// Support class used to report GC events to JVMTI. The class is stack
// allocated and should be placed in the doit() implementation of all
// vm operations that do a stop-the-world GC for failed allocation.
//
// Usage :-
//
// void VM_GenCollectForAllocation::doit() {
//   JvmtiGCForAllocationMarker jgcm;
//   :
// }
//
// If jvmti is not enabled the constructor and destructor is essentially
// a no-op (no overhead).
//
class JvmtiGCForAllocationMarker : public JvmtiGCMarker {
 public:
  JvmtiGCForAllocationMarker() : JvmtiGCMarker(false) {
  }
};

// Support class used to report GC events to JVMTI. The class is stack
// allocated and should be placed in the doit() implementation of all
// vm operations that do a "full" stop-the-world GC. This class differs
// from JvmtiGCForAllocationMarker in that this class assumes that a
// "full" GC will happen.
//
// Usage :-
//
// void VM_GenCollectFull::doit() {
//   JvmtiGCFullMarker jgcm;
//   :
// }
//
class JvmtiGCFullMarker : public JvmtiGCMarker {
 public:
  JvmtiGCFullMarker() : JvmtiGCMarker(true) {
  }
};


// JvmtiHideSingleStepping is a helper class for hiding
// internal single step events.
class JvmtiHideSingleStepping : public StackObj {
 private:
  bool         _single_step_hidden;
  JavaThread * _thread;

 public:
  JvmtiHideSingleStepping(JavaThread * thread) {
    assert(thread != NULL, "sanity check");

    _single_step_hidden = false;
    _thread = thread;
    if (JvmtiExport::should_post_single_step()) {
      _single_step_hidden = JvmtiExport::hide_single_stepping(_thread);
    }
  }

  ~JvmtiHideSingleStepping() {
    if (_single_step_hidden) {
      JvmtiExport::expose_single_stepping(_thread);
    }
  }
};

#endif   /* _JAVA_JVMTIEXPORT_H_ */