hotspot/src/share/vm/prims/jvmtiEventController.cpp
author alanb
Thu, 17 Mar 2016 19:04:01 +0000
changeset 36508 5f9eee6b383b
parent 33148 68fa8b6c4340
child 37992 c7ec6a3275f7
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, harold.seigel@oracle.com, lois.foltan@oracle.com, calvin.cheung@oracle.com, christian.tornqvist@oracle.com, erik.joelsson@oracle.com, george.triantafillou@oracle.com, igor.ignatyev@oracle.com, ioi.lam@oracle.com, james.laskey@oracle.com, jean-francois.denise@oracle.com, jiangli.zhou@oracle.com, markus.gronlund@oracle.com, serguei.spitsyn@oracle.com, staffan.larsen@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 33148
diff changeset
     2
 * Copyright (c) 2003, 2016, 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: 4761
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4761
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: 4761
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 "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "jvmtifiles/jvmtiEnv.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "prims/jvmtiEventController.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "prims/jvmtiEventController.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "prims/jvmtiExport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "prims/jvmtiImpl.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "prims/jvmtiThreadState.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/frame.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/thread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/vframe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/vframe_hp.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "runtime/vmThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/vm_operations.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
#ifdef JVMTI_TRACE
16622
32565ca20073 8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
kmo
parents: 8921
diff changeset
    42
#define EC_TRACE(out) do { \
32565ca20073 8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
kmo
parents: 8921
diff changeset
    43
  if (JvmtiTrace::trace_event_controller()) { \
32565ca20073 8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
kmo
parents: 8921
diff changeset
    44
    SafeResourceMark rm; \
32565ca20073 8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
kmo
parents: 8921
diff changeset
    45
    tty->print_cr out; \
32565ca20073 8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
kmo
parents: 8921
diff changeset
    46
  } \
32565ca20073 8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
kmo
parents: 8921
diff changeset
    47
} while (0)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
#define EC_TRACE(out)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
#endif /*JVMTI_TRACE */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// bits for standard events
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
static const jlong  SINGLE_STEP_BIT = (((jlong)1) << (JVMTI_EVENT_SINGLE_STEP - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
static const jlong  FRAME_POP_BIT = (((jlong)1) << (JVMTI_EVENT_FRAME_POP - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
static const jlong  BREAKPOINT_BIT = (((jlong)1) << (JVMTI_EVENT_BREAKPOINT - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
static const jlong  FIELD_ACCESS_BIT = (((jlong)1) << (JVMTI_EVENT_FIELD_ACCESS - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
static const jlong  FIELD_MODIFICATION_BIT = (((jlong)1) << (JVMTI_EVENT_FIELD_MODIFICATION - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
static const jlong  METHOD_ENTRY_BIT = (((jlong)1) << (JVMTI_EVENT_METHOD_ENTRY - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
static const jlong  METHOD_EXIT_BIT = (((jlong)1) << (JVMTI_EVENT_METHOD_EXIT - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
static const jlong  CLASS_FILE_LOAD_HOOK_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
static const jlong  NATIVE_METHOD_BIND_BIT = (((jlong)1) << (JVMTI_EVENT_NATIVE_METHOD_BIND - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
static const jlong  VM_START_BIT = (((jlong)1) << (JVMTI_EVENT_VM_START - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
static const jlong  VM_INIT_BIT = (((jlong)1) << (JVMTI_EVENT_VM_INIT - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
static const jlong  VM_DEATH_BIT = (((jlong)1) << (JVMTI_EVENT_VM_DEATH - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
static const jlong  CLASS_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_LOAD - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
static const jlong  CLASS_PREPARE_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_PREPARE - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
static const jlong  THREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
static const jlong  THREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
static const jlong  EXCEPTION_THROW_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
static const jlong  EXCEPTION_CATCH_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION_CATCH - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
static const jlong  MONITOR_CONTENDED_ENTER_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTER - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
static const jlong  MONITOR_CONTENDED_ENTERED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
static const jlong  MONITOR_WAIT_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAIT - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
static const jlong  MONITOR_WAITED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAITED - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
static const jlong  DYNAMIC_CODE_GENERATED_BIT = (((jlong)1) << (JVMTI_EVENT_DYNAMIC_CODE_GENERATED - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
static const jlong  DATA_DUMP_BIT = (((jlong)1) << (JVMTI_EVENT_DATA_DUMP_REQUEST - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
static const jlong  COMPILED_METHOD_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_LOAD - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
static const jlong  COMPILED_METHOD_UNLOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
static const jlong  GARBAGE_COLLECTION_START_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_START - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
static const jlong  GARBAGE_COLLECTION_FINISH_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
static const jlong  OBJECT_FREE_BIT = (((jlong)1) << (JVMTI_EVENT_OBJECT_FREE - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
static const jlong  RESOURCE_EXHAUSTED_BIT = (((jlong)1) << (JVMTI_EVENT_RESOURCE_EXHAUSTED - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
static const jlong  VM_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_VM_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// bits for extension events
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
static const jlong  CLASS_UNLOAD_BIT = (((jlong)1) << (EXT_EVENT_CLASS_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
static const jlong  MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                          MONITOR_WAIT_BIT | MONITOR_WAITED_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
static const jlong  EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
static const jlong  INTERP_EVENT_BITS =  SINGLE_STEP_BIT | METHOD_ENTRY_BIT | METHOD_EXIT_BIT |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                                FRAME_POP_BIT | FIELD_ACCESS_BIT | FIELD_MODIFICATION_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
static const jlong  THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                                        BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
static const jlong  NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
static const jlong  EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                               VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                               THREAD_START_BIT | THREAD_END_BIT |
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 33148
diff changeset
   101
                               COMPILED_METHOD_LOAD_BIT | COMPILED_METHOD_UNLOAD_BIT |
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                               DYNAMIC_CODE_GENERATED_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
static const jlong  GLOBAL_EVENT_BITS = ~THREAD_FILTERED_EVENT_BITS;
4761
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   104
static const jlong  SHOULD_POST_ON_EXCEPTIONS_BITS = EXCEPTION_BITS | METHOD_EXIT_BIT | FRAME_POP_BIT;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
// JvmtiEventEnabled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
JvmtiEventEnabled::JvmtiEventEnabled() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
void JvmtiEventEnabled::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  _enabled_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  _init_guard = JEE_INIT_GUARD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
void JvmtiEventEnabled::set_enabled(jvmtiEvent event_type, bool enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  jlong bits = get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  jlong mask = bit_for(event_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    bits |= mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    bits &= ~mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  set_bits(bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// JvmtiEnvThreadEventEnable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
JvmtiEnvThreadEventEnable::JvmtiEnvThreadEventEnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  _event_user_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  _event_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
JvmtiEnvThreadEventEnable::~JvmtiEnvThreadEventEnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  _event_user_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  _event_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// JvmtiThreadEventEnable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
JvmtiThreadEventEnable::JvmtiThreadEventEnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  _event_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
JvmtiThreadEventEnable::~JvmtiThreadEventEnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  _event_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// JvmtiEnvEventEnable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
JvmtiEnvEventEnable::JvmtiEnvEventEnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  _event_user_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  _event_callback_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  _event_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
JvmtiEnvEventEnable::~JvmtiEnvEventEnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  _event_user_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  _event_callback_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  _event_enabled.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// VM_EnterInterpOnlyMode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
class VM_EnterInterpOnlyMode : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  JvmtiThreadState *_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  VM_EnterInterpOnlyMode(JvmtiThreadState *state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  bool allow_nested_vm_operations() const        { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  VMOp_Type type() const { return VMOp_EnterInterpOnlyMode; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // to do: this same function is in jvmtiImpl - should be in one place
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  bool can_be_deoptimized(vframe* vf) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
VM_EnterInterpOnlyMode::VM_EnterInterpOnlyMode(JvmtiThreadState *state)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  : _state(state)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
void VM_EnterInterpOnlyMode::doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // Set up the current stack depth for later tracking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  _state->invalidate_cur_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  _state->enter_interp_only_mode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  JavaThread *thread = _state->get_thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  if (thread->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    // If running in fullspeed mode, single stepping is implemented
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    // as follows: first, the interpreter does not dispatch to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    // compiled code for threads that have single stepping enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    // second, we deoptimize all methods on the thread's stack when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    // interpreted-only mode is enabled the first time for a given
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    // thread (nothing to do if no Java frames yet).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    int num_marked = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    ResourceMark resMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    RegisterMap rm(thread, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    for (vframe* vf = thread->last_java_vframe(&rm); vf; vf = vf->sender()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      if (can_be_deoptimized(vf)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        ((compiledVFrame*) vf)->code()->mark_for_deoptimization();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        ++num_marked;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    if (num_marked > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      VM_Deoptimize op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      VMThread::execute(&op);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// VM_ChangeSingleStep
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
class VM_ChangeSingleStep : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  bool _on;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  VM_ChangeSingleStep(bool on);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  VMOp_Type type() const                         { return VMOp_ChangeSingleStep; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  bool allow_nested_vm_operations() const        { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  void doit();   // method definition is after definition of JvmtiEventControllerPrivate because of scoping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
VM_ChangeSingleStep::VM_ChangeSingleStep(bool on)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  : _on(on != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
// JvmtiEventControllerPrivate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
// Private internal implementation methods for JvmtiEventController.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
// These methods are thread safe either because they are called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// in early VM initialization which is single threaded, or they
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// hold the JvmtiThreadState_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
class JvmtiEventControllerPrivate : public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  static bool _initialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  static void set_should_post_single_step(bool on);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  static void enter_interp_only_mode(JvmtiThreadState *state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  static void leave_interp_only_mode(JvmtiThreadState *state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  static void recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  static jlong recompute_env_enabled(JvmtiEnvBase* env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  static jlong recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  static jlong recompute_thread_enabled(JvmtiThreadState *state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  static void event_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
                        jvmtiEvent event_type, bool enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  static void set_event_callbacks(JvmtiEnvBase *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
                                  const jvmtiEventCallbacks* callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
                                  jint size_of_callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  static void set_extension_event_callback(JvmtiEnvBase *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
                                           jint extension_event_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
                                           jvmtiExtensionEvent callback);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  static void change_field_watch(jvmtiEvent event_type, bool added);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  static void thread_started(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  static void thread_ended(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  static void env_initialize(JvmtiEnvBase *env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  static void env_dispose(JvmtiEnvBase *env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  static void vm_start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  static void vm_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  static void vm_death();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  static void trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  static void trace_changed(jlong now_enabled, jlong changed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
bool JvmtiEventControllerPrivate::_initialized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
void JvmtiEventControllerPrivate::set_should_post_single_step(bool on) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // we have permission to do this, VM op doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  JvmtiExport::set_should_post_single_step(on);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
// This change must always be occur when at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
// Being at a safepoint causes the interpreter to use the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
// safepoint dispatch table which we overload to find single
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
// step points.  Just to be sure that it has been set, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
// call notice_safepoints when turning on single stepping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
// When we leave our current safepoint, should_post_single_step
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
// will be checked by the interpreter, and the table kept
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
// or changed accordingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
void VM_ChangeSingleStep::doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  JvmtiEventControllerPrivate::set_should_post_single_step(_on);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  if (_on) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    Interpreter::notice_safepoints();
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  EC_TRACE(("JVMTI [%s] # Entering interpreter only mode",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
            JvmtiTrace::safe_get_thread_name(state->get_thread())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  VM_EnterInterpOnlyMode op(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
JvmtiEventControllerPrivate::leave_interp_only_mode(JvmtiThreadState *state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  EC_TRACE(("JVMTI [%s] # Leaving interpreter only mode",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
            JvmtiTrace::safe_get_thread_name(state->get_thread())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  state->leave_interp_only_mode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
JvmtiEventControllerPrivate::trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
#ifdef JVMTI_TRACE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  if (JvmtiTrace::trace_event_controller()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    SafeResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    // traces standard events only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      if (changed & bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
        // it changed, print it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
        tty->print_cr("JVMTI [%s] # %s event %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
                      JvmtiTrace::safe_get_thread_name(state->get_thread()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                      (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
#endif /*JVMTI_TRACE */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
JvmtiEventControllerPrivate::trace_changed(jlong now_enabled, jlong changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
#ifdef JVMTI_TRACE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  if (JvmtiTrace::trace_event_controller()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    SafeResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    // traces standard events only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      if (changed & bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        // it changed, print it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        tty->print_cr("JVMTI [-] # %s event %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
                      (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
#endif /*JVMTI_TRACE */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
// For the specified env: compute the currently truly enabled events
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
// set external state accordingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
// Return value and set value must include all events.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
// But outside this class, only non-thread-filtered events can be queried..
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
jlong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
JvmtiEventControllerPrivate::recompute_env_enabled(JvmtiEnvBase* env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  jlong was_enabled = env->env_event_enable()->_event_enabled.get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  jlong now_enabled =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    env->env_event_enable()->_event_callback_enabled.get_bits() &
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    env->env_event_enable()->_event_user_enabled.get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 33148
diff changeset
   413
  switch (env->phase()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  case JVMTI_PHASE_PRIMORDIAL:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  case JVMTI_PHASE_ONLOAD:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    // only these events allowed in primordial or onload phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    now_enabled &= (EARLY_EVENT_BITS & ~THREAD_FILTERED_EVENT_BITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  case JVMTI_PHASE_START:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    // only these events allowed in start phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    now_enabled &= EARLY_EVENT_BITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  case JVMTI_PHASE_LIVE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    // all events allowed during live phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  case JVMTI_PHASE_DEAD:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    // no events allowed when dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    now_enabled = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    assert(false, "no other phases - sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  // will we really send these events to this env
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  env->env_event_enable()->_event_enabled.set_bits(now_enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  trace_changed(now_enabled, (now_enabled ^ was_enabled)  & ~THREAD_FILTERED_EVENT_BITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  return now_enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
// For the specified env and thread: compute the currently truly enabled events
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
// set external state accordingly.  Only thread-filtered events are included.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
jlong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
JvmtiEventControllerPrivate::recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  JvmtiEnv *env = ets->get_env();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  jlong was_enabled = ets->event_enable()->_event_enabled.get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  jlong now_enabled =  THREAD_FILTERED_EVENT_BITS &
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    env->env_event_enable()->_event_callback_enabled.get_bits() &
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    (env->env_event_enable()->_event_user_enabled.get_bits() |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
     ets->event_enable()->_event_user_enabled.get_bits());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  // for frame pops and field watchs, computed enabled state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // is only true if an event has been requested
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  if (!ets->has_frame_pops()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    now_enabled &= ~FRAME_POP_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  if (*((int *)JvmtiExport::get_field_access_count_addr()) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    now_enabled &= ~FIELD_ACCESS_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  if (*((int *)JvmtiExport::get_field_modification_count_addr()) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    now_enabled &= ~FIELD_MODIFICATION_BIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  switch (JvmtiEnv::get_phase()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  case JVMTI_PHASE_DEAD:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    // no events allowed when dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    now_enabled = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  // if anything changed do update
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  if (now_enabled != was_enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    // will we really send these events to this thread x env
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    ets->event_enable()->_event_enabled.set_bits(now_enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    // If the enabled status of the single step or breakpoint events changed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    // the location status may need to change as well.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    jlong changed = now_enabled ^ was_enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    if (changed & SINGLE_STEP_BIT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
      ets->reset_current_location(JVMTI_EVENT_SINGLE_STEP, (now_enabled & SINGLE_STEP_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    if (changed & BREAKPOINT_BIT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      ets->reset_current_location(JVMTI_EVENT_BREAKPOINT,  (now_enabled & BREAKPOINT_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    trace_changed(state, now_enabled, changed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  return now_enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
// For the specified thread: compute the currently truly enabled events
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
// set external state accordingly.  Only thread-filtered events are included.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
jlong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
JvmtiEventControllerPrivate::recompute_thread_enabled(JvmtiThreadState *state) {
2135
f82c3012ec86 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 1
diff changeset
   500
  if (state == NULL) {
f82c3012ec86 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 1
diff changeset
   501
    // associated JavaThread is exiting
f82c3012ec86 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 1
diff changeset
   502
    return (jlong)0;
f82c3012ec86 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 1
diff changeset
   503
  }
f82c3012ec86 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 1
diff changeset
   504
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  jlong was_any_env_enabled = state->thread_event_enable()->_event_enabled.get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  jlong any_env_enabled = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    // This iteration will include JvmtiEnvThreadStates whoses environments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    // have been disposed.  These JvmtiEnvThreadStates must not be filtered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    // as recompute must be called on them to disable their events,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    JvmtiEnvThreadStateIterator it(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      any_env_enabled |= recompute_env_thread_enabled(ets, state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  if (any_env_enabled != was_any_env_enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    // mark if event is truly enabled on this thread in any environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    state->thread_event_enable()->_event_enabled.set_bits(any_env_enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    // compute interp_only mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    bool should_be_interp = (any_env_enabled & INTERP_EVENT_BITS) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    bool is_now_interp = state->is_interp_only_mode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    if (should_be_interp != is_now_interp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      if (should_be_interp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
        enter_interp_only_mode(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
        leave_interp_only_mode(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
4761
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   533
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   534
    // update the JavaThread cached value for thread-specific should_post_on_exceptions value
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   535
    bool should_post_on_exceptions = (any_env_enabled & SHOULD_POST_ON_EXCEPTIONS_BITS) != 0;
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   536
    state->set_should_post_on_exceptions(should_post_on_exceptions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
4761
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   538
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  return any_env_enabled;
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
// Compute truly enabled events - meaning if the event can and could be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
// sent.  An event is truly enabled if it is user enabled on the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
// or globally user enabled, but only if there is a callback or event hook
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
// for it and, for field watch and frame pop, one has been set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
// Compute if truly enabled, per thread, per environment, per combination
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
// (thread x environment), and overall.  These merges are true if any is true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
// True per thread if some environment has callback set and the event is globally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
// enabled or enabled for this thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
// True per environment if the callback is set and the event is globally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
// enabled in this environment or enabled for any thread in this environment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
// True per combination if the environment has the callback set and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
// event is globally enabled in this environment or the event is enabled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
// for this thread and environment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
// All states transitions dependent on these transitions are also handled here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
JvmtiEventControllerPrivate::recompute_enabled() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  // event enabled for any thread in any environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  jlong was_any_env_thread_enabled = JvmtiEventController::_universal_global_event_enabled.get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  jlong any_env_thread_enabled = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24424
diff changeset
   566
  EC_TRACE(("JVMTI [-] # recompute enabled - before " UINT64_FORMAT_X, was_any_env_thread_enabled));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // compute non-thread-filters events.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // This must be done separately from thread-filtered events, since some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // events can occur before any threads exist.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  JvmtiEnvIterator it;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    any_env_thread_enabled |= recompute_env_enabled(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  // We need to create any missing jvmti_thread_state if there are globally set thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  // filtered events and there weren't last time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  if (    (any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) != 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
      (was_any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      MutexLocker mu(Threads_lock);   //hold the Threads_lock for the iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      for (JavaThread *tp = Threads::first(); tp != NULL; tp = tp->next()) {
2135
f82c3012ec86 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 1
diff changeset
   583
        // state_for_while_locked() makes tp->is_exiting() check
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
        JvmtiThreadState::state_for_while_locked(tp);  // create the thread state if missing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    }// release Threads_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // compute and set thread-filtered events
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    any_env_thread_enabled |= recompute_thread_enabled(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  // set universal state (across all envs and threads)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  jlong delta = any_env_thread_enabled ^ was_any_env_thread_enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  if (delta != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    JvmtiExport::set_should_post_field_access((any_env_thread_enabled & FIELD_ACCESS_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    JvmtiExport::set_should_post_field_modification((any_env_thread_enabled & FIELD_MODIFICATION_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    JvmtiExport::set_should_post_class_load((any_env_thread_enabled & CLASS_LOAD_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    JvmtiExport::set_should_post_class_file_load_hook((any_env_thread_enabled & CLASS_FILE_LOAD_HOOK_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    JvmtiExport::set_should_post_native_method_bind((any_env_thread_enabled & NATIVE_METHOD_BIND_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    JvmtiExport::set_should_post_dynamic_code_generated((any_env_thread_enabled & DYNAMIC_CODE_GENERATED_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    JvmtiExport::set_should_post_data_dump((any_env_thread_enabled & DATA_DUMP_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    JvmtiExport::set_should_post_class_prepare((any_env_thread_enabled & CLASS_PREPARE_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    JvmtiExport::set_should_post_class_unload((any_env_thread_enabled & CLASS_UNLOAD_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    JvmtiExport::set_should_post_monitor_contended_enter((any_env_thread_enabled & MONITOR_CONTENDED_ENTER_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    JvmtiExport::set_should_post_monitor_contended_entered((any_env_thread_enabled & MONITOR_CONTENDED_ENTERED_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    JvmtiExport::set_should_post_monitor_wait((any_env_thread_enabled & MONITOR_WAIT_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    JvmtiExport::set_should_post_monitor_waited((any_env_thread_enabled & MONITOR_WAITED_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    JvmtiExport::set_should_post_garbage_collection_start((any_env_thread_enabled & GARBAGE_COLLECTION_START_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    JvmtiExport::set_should_post_garbage_collection_finish((any_env_thread_enabled & GARBAGE_COLLECTION_FINISH_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    JvmtiExport::set_should_post_object_free((any_env_thread_enabled & OBJECT_FREE_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    JvmtiExport::set_should_post_resource_exhausted((any_env_thread_enabled & RESOURCE_EXHAUSTED_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    JvmtiExport::set_should_post_compiled_method_load((any_env_thread_enabled & COMPILED_METHOD_LOAD_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    // need this if we want thread events or we need them to init data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    JvmtiExport::set_should_post_thread_life((any_env_thread_enabled & NEED_THREAD_LIFE_EVENTS) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    // If single stepping is turned on or off, execute the VM op to change it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    if (delta & SINGLE_STEP_BIT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
      switch (JvmtiEnv::get_phase()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
      case JVMTI_PHASE_DEAD:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
        // If the VM is dying we can't execute VM ops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      case JVMTI_PHASE_LIVE: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
        VM_ChangeSingleStep op((any_env_thread_enabled & SINGLE_STEP_BIT) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
        VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
        assert(false, "should never come here before live phase");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    // set global truly enabled, that is, any thread in any environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    JvmtiEventController::_universal_global_event_enabled.set_bits(any_env_thread_enabled);
4761
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   640
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   641
    // set global should_post_on_exceptions
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   642
    JvmtiExport::set_should_post_on_exceptions((any_env_thread_enabled & SHOULD_POST_ON_EXCEPTIONS_BITS) != 0);
bdb7375a1fee 6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents: 2135
diff changeset
   643
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24424
diff changeset
   646
  EC_TRACE(("JVMTI [-] # recompute enabled - after " UINT64_FORMAT_X, any_env_thread_enabled));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
JvmtiEventControllerPrivate::thread_started(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  assert(thread->is_Java_thread(), "Must be JavaThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  assert(thread == Thread::current(), "must be current thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  assert(JvmtiEnvBase::environments_might_exist(), "to enter event controller, JVM TI environments must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  EC_TRACE(("JVMTI [%s] # thread started", JvmtiTrace::safe_get_thread_name(thread)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  // if we have any thread filtered events globally enabled, create/update the thread state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  if ((JvmtiEventController::_universal_global_event_enabled.get_bits() & THREAD_FILTERED_EVENT_BITS) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    // create the thread state if missing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    if (state != NULL) {    // skip threads with no JVMTI thread state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
      recompute_thread_enabled(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
JvmtiEventControllerPrivate::thread_ended(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  // Removes the JvmtiThreadState associated with the specified thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  // May be called after all environments have been disposed.
7897
201a8b00ec91 6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents: 7397
diff changeset
   674
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  EC_TRACE(("JVMTI [%s] # thread ended", JvmtiTrace::safe_get_thread_name(thread)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  JvmtiThreadState *state = thread->jvmti_thread_state();
7897
201a8b00ec91 6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents: 7397
diff changeset
   679
  assert(state != NULL, "else why are we here?");
201a8b00ec91 6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents: 7397
diff changeset
   680
  delete state;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
void JvmtiEventControllerPrivate::set_event_callbacks(JvmtiEnvBase *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
                                                      const jvmtiEventCallbacks* callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
                                                      jint size_of_callbacks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  EC_TRACE(("JVMTI [*] # set event callbacks"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  env->set_event_callbacks(callbacks, size_of_callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  jlong enabled_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    jvmtiEvent evt_t = (jvmtiEvent)ei;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    if (env->has_callback(evt_t)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      enabled_bits |= JvmtiEventEnabled::bit_for(evt_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
JvmtiEventControllerPrivate::set_extension_event_callback(JvmtiEnvBase *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
                                                          jint extension_event_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
                                                          jvmtiExtensionEvent callback)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  EC_TRACE(("JVMTI [*] # set extension event callback"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  // extension events are allocated below JVMTI_MIN_EVENT_TYPE_VAL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  assert(extension_event_index >= (jint)EXT_MIN_EVENT_TYPE_VAL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
         extension_event_index <= (jint)EXT_MAX_EVENT_TYPE_VAL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  // As the bits for both standard (jvmtiEvent) and extension
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  // (jvmtiExtEvents) are stored in the same word we cast here to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  // jvmtiEvent to set/clear the bit for this extension event.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  jvmtiEvent event_type = (jvmtiEvent)extension_event_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  // Prevent a possible race condition where events are re-enabled by a call to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  // set event callbacks, where the DisposeEnvironment occurs after the boiler-plate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  // environment check and before the lock is acquired.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  // We can safely do the is_valid check now, as JvmtiThreadState_lock is held.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  bool enabling = (callback != NULL) && (env->is_valid());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  env->env_event_enable()->set_user_enabled(event_type, enabling);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  // update the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  jvmtiExtEventCallbacks* ext_callbacks = env->ext_callbacks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  switch (extension_event_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    case EXT_EVENT_CLASS_UNLOAD :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
      ext_callbacks->ClassUnload = callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  // update the callback enable/disable bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  jlong bit_for = JvmtiEventEnabled::bit_for(event_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  if (enabling) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
    enabled_bits |= bit_for;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    enabled_bits &= ~bit_for;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
JvmtiEventControllerPrivate::env_initialize(JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  EC_TRACE(("JVMTI [*] # env initialize"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  if (JvmtiEnvBase::is_vm_live()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
    // if we didn't initialize event info already (this is a late
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
    // launched environment), do it now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    event_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  env->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  // add the JvmtiEnvThreadState to each JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    state->add_env(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
    assert((JvmtiEnv*)(state->env_thread_state(env)->get_env()) == env, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  JvmtiEventControllerPrivate::recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
JvmtiEventControllerPrivate::env_dispose(JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  EC_TRACE(("JVMTI [*] # env dispose"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  // Before the environment is marked disposed, disable all events on this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  // environment (by zapping the callbacks).  As a result, the disposed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  // environment will not call event handlers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  set_event_callbacks(env, NULL, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  for (jint extension_event_index = EXT_MIN_EVENT_TYPE_VAL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
       extension_event_index <= EXT_MAX_EVENT_TYPE_VAL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
       ++extension_event_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    set_extension_event_callback(env, extension_event_index, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  // Let the environment finish disposing itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  env->env_dispose();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
JvmtiEventControllerPrivate::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
                                          jvmtiEvent event_type, bool enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  EC_TRACE(("JVMTI [%s] # user %s event %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
            thread==NULL? "ALL": JvmtiTrace::safe_get_thread_name(thread),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
            enabled? "enabled" : "disabled", JvmtiTrace::event_name(event_type)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  if (thread == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    env->env_event_enable()->set_user_enabled(event_type, enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    // create the thread state (if it didn't exist before)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    if (state != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      state->env_thread_state(env)->event_enable()->set_user_enabled(event_type, enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
JvmtiEventControllerPrivate::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  EC_TRACE(("JVMTI [%s] # set frame pop - frame=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
            JvmtiTrace::safe_get_thread_name(ets->get_thread()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
            fpop.frame_number() ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  ets->get_frame_pops()->set(fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  recompute_thread_enabled(ets->get_thread()->jvmti_thread_state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
JvmtiEventControllerPrivate::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  EC_TRACE(("JVMTI [%s] # clear frame pop - frame=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
            JvmtiTrace::safe_get_thread_name(ets->get_thread()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
            fpop.frame_number() ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  ets->get_frame_pops()->clear(fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  recompute_thread_enabled(ets->get_thread()->jvmti_thread_state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  int cleared_cnt = ets->get_frame_pops()->clear_to(fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  EC_TRACE(("JVMTI [%s] # clear to frame pop - frame=%d, count=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
            JvmtiTrace::safe_get_thread_name(ets->get_thread()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
            fpop.frame_number(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
            cleared_cnt ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  if (cleared_cnt > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    recompute_thread_enabled(ets->get_thread()->jvmti_thread_state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  int *count_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  switch (event_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  case JVMTI_EVENT_FIELD_MODIFICATION:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    count_addr = (int *)JvmtiExport::get_field_modification_count_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  case JVMTI_EVENT_FIELD_ACCESS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    count_addr = (int *)JvmtiExport::get_field_access_count_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    assert(false, "incorrect event");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  EC_TRACE(("JVMTI [-] # change field watch - %s %s count=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
            event_type==JVMTI_EVENT_FIELD_MODIFICATION? "modification" : "access",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
            added? "add" : "remove",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
            *count_addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  if (added) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    (*count_addr)++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    if (*count_addr == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
      recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
    if (*count_addr > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
      (*count_addr)--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
      if (*count_addr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
        recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
      assert(false, "field watch out of phase");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
JvmtiEventControllerPrivate::event_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  if (_initialized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  EC_TRACE(("JVMTI [-] # VM live"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  // check that our idea and the spec's idea of threaded events match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    assert(((THREAD_FILTERED_EVENT_BITS & bit) != 0) == JvmtiUtil::event_threaded(ei),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
           "thread filtered event list does not match");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  _initialized = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
JvmtiEventControllerPrivate::vm_start() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  // some events are now able to be enabled (phase has changed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  JvmtiEventControllerPrivate::recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
JvmtiEventControllerPrivate::vm_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  event_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  // all the events are now able to be enabled (phase has changed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  JvmtiEventControllerPrivate::recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
JvmtiEventControllerPrivate::vm_death() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  // events are disabled (phase has changed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  JvmtiEventControllerPrivate::recompute_enabled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
// JvmtiEventController
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
JvmtiEventEnabled JvmtiEventController::_universal_global_event_enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
JvmtiEventController::is_global_event(jvmtiEvent event_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  assert(is_valid_event_type(event_type), "invalid event type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  jlong bit_for = ((jlong)1) << (event_type - TOTAL_MIN_EVENT_TYPE_VAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  return((bit_for & GLOBAL_EVENT_BITS)!=0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
JvmtiEventController::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, jvmtiEvent event_type, bool enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  if (Threads::number_of_threads() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    // during early VM start-up locks don't exist, but we are safely single threaded,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    // call the functionality without holding the JvmtiThreadState_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
JvmtiEventController::set_event_callbacks(JvmtiEnvBase *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
                                          const jvmtiEventCallbacks* callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
                                          jint size_of_callbacks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  if (Threads::number_of_threads() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    // during early VM start-up locks don't exist, but we are safely single threaded,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    // call the functionality without holding the JvmtiThreadState_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
    JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
JvmtiEventController::set_extension_event_callback(JvmtiEnvBase *env,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
                                                   jint extension_event_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
                                                   jvmtiExtensionEvent callback) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  if (Threads::number_of_threads() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
JvmtiEventController::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22234
diff changeset
   991
  MutexLockerEx mu(SafepointSynchronize::is_at_safepoint() ? NULL : JvmtiThreadState_lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  JvmtiEventControllerPrivate::set_frame_pop(ets, fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
JvmtiEventController::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22234
diff changeset
   998
  MutexLockerEx mu(SafepointSynchronize::is_at_safepoint() ? NULL : JvmtiThreadState_lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  JvmtiEventControllerPrivate::clear_frame_pop(ets, fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
JvmtiEventController::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22234
diff changeset
  1005
  MutexLockerEx mu(SafepointSynchronize::is_at_safepoint() ? NULL : JvmtiThreadState_lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  JvmtiEventControllerPrivate::clear_to_frame_pop(ets, fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
JvmtiEventController::change_field_watch(jvmtiEvent event_type, bool added) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  JvmtiEventControllerPrivate::change_field_watch(event_type, added);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
JvmtiEventController::thread_started(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  // operates only on the current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  // JvmtiThreadState_lock grabbed only if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  JvmtiEventControllerPrivate::thread_started(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
JvmtiEventController::thread_ended(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  // operates only on the current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  // JvmtiThreadState_lock grabbed only if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  JvmtiEventControllerPrivate::thread_ended(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
JvmtiEventController::env_initialize(JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  if (Threads::number_of_threads() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    // during early VM start-up locks don't exist, but we are safely single threaded,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    // call the functionality without holding the JvmtiThreadState_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    JvmtiEventControllerPrivate::env_initialize(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    JvmtiEventControllerPrivate::env_initialize(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
JvmtiEventController::env_dispose(JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  if (Threads::number_of_threads() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    // during early VM start-up locks don't exist, but we are safely single threaded,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    // call the functionality without holding the JvmtiThreadState_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    JvmtiEventControllerPrivate::env_dispose(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    JvmtiEventControllerPrivate::env_dispose(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
JvmtiEventController::vm_start() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  if (JvmtiEnvBase::environments_might_exist()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    JvmtiEventControllerPrivate::vm_start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
JvmtiEventController::vm_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  if (JvmtiEnvBase::environments_might_exist()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    JvmtiEventControllerPrivate::vm_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
JvmtiEventController::vm_death() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  if (JvmtiEnvBase::environments_might_exist()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    MutexLocker mu(JvmtiThreadState_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    JvmtiEventControllerPrivate::vm_death();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
}