hotspot/src/share/vm/prims/jvmtiThreadState.cpp
author ysr
Thu, 03 Dec 2009 15:01:57 -0800
changeset 4461 c17c526d36ef
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6906727: UseCompressedOops: some card-marking fixes related to object arrays Summary: Introduced a new write_ref_array(HeapWords* start, size_t count) method that does the requisite MemRegion range calculation so (some of the) clients of the erstwhile write_ref_array(MemRegion mr) do not need to worry. This removed all external uses of array_size(), which was also simplified and made private. Asserts were added to catch other possible issues. Further, less essential, fixes stemming from this investigation are deferred to CR 6904516 (to follow shortly in hs17). Reviewed-by: kvn, coleenp, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_jvmtiThreadState.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// marker for when the stack depth has been reset and is now unknown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// any negative number would work but small ones might obscure an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// underrun error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
static const int UNKNOWN_STACK_DEPTH = -99;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// class JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Instances of JvmtiThreadState hang off of each thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// Thread local storage for JVMTI.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
JvmtiThreadState *JvmtiThreadState::_head = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
JvmtiThreadState::JvmtiThreadState(JavaThread* thread)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  : _thread_event_enable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _thread               = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _exception_detected   = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _exception_caught     = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _debuggable           = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  _hide_single_stepping = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  _hide_level           = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _pending_step_for_popframe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _class_being_redefined = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _class_load_kind = jvmti_class_load_kind_load;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _head_env_thread_state = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _dynamic_code_event_collector = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _vm_object_alloc_event_collector = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _the_class_for_redefinition_verification = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _scratch_class_for_redefinition_verification = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // JVMTI ForceEarlyReturn support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _pending_step_for_earlyret = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _earlyret_state = earlyret_inactive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _earlyret_tos = ilgl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  _earlyret_value.j = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _earlyret_oop = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // add all the JvmtiEnvThreadState to the new JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    JvmtiEnvIterator it;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      if (env->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        add_env(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // link us into the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    // The thread state list manipulation code must not have safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    // See periodic_clean_up().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    debug_only(No_Safepoint_Verifier nosafepoint;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    _prev = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _next = _head;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    if (_head != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      _head->_prev = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    _head = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // set this as the state for the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  thread->set_jvmti_thread_state(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
JvmtiThreadState::~JvmtiThreadState()   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // clear this as the state for the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  get_thread()->set_jvmti_thread_state(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // zap our env thread states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    JvmtiEnvBase::entering_dying_thread_env_iteration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      JvmtiEnvThreadState* zap = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      ets = it.next(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      delete zap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    JvmtiEnvBase::leaving_dying_thread_env_iteration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // remove us from the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    // The thread state list manipulation code must not have safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    // See periodic_clean_up().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    debug_only(No_Safepoint_Verifier nosafepoint;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    if (_prev == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      assert(_head == this, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      _head = _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      assert(_head != this, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      _prev->_next = _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    if (_next != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      _next->_prev = _prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    _prev = NULL;
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
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
JvmtiThreadState::periodic_clean_up() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  assert(SafepointSynchronize::is_at_safepoint(), "at safepoint");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // This iteration is initialized with "_head" instead of "JvmtiThreadState::first()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // because the latter requires the JvmtiThreadState_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // This iteration is safe at a safepoint as well, see the No_Safepoint_Verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // asserts at all list manipulation sites.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  for (JvmtiThreadState *state = _head; state != NULL; state = state->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    // For each environment thread state corresponding to an invalid environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    // unlink it from the list and deallocate it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    JvmtiEnvThreadStateIterator it(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    JvmtiEnvThreadState* previous_ets = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    JvmtiEnvThreadState* ets = it.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    while (ets != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      if (ets->get_env()->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        previous_ets = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        ets = it.next(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        // This one isn't valid, remove it from the list and deallocate it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        JvmtiEnvThreadState* defunct_ets = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        ets = ets->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        if (previous_ets == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
          assert(state->head_env_thread_state() == defunct_ets, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
          state->set_head_env_thread_state(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
          previous_ets->set_next(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        delete defunct_ets;
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
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void JvmtiThreadState::add_env(JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  JvmtiEnvThreadState *new_ets = new JvmtiEnvThreadState(_thread, env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // add this environment thread state to the end of the list (order is important)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    // list deallocation (which occurs at a safepoint) cannot occur simultaneously
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    debug_only(No_Safepoint_Verifier nosafepoint;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    JvmtiEnvThreadState* previous_ets = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      previous_ets = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    if (previous_ets == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      set_head_env_thread_state(new_ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      previous_ets->set_next(new_ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void JvmtiThreadState::enter_interp_only_mode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(_thread->get_interp_only_mode() == 0, "entering interp only when mode not zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  _thread->increment_interp_only_mode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
void JvmtiThreadState::leave_interp_only_mode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  assert(_thread->get_interp_only_mode() == 1, "leaving interp only when mode not one");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  _thread->decrement_interp_only_mode();
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
// Helper routine used in several places
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
int JvmtiThreadState::count_frames() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  uint32_t debug_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  assert(SafepointSynchronize::is_at_safepoint() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
         JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
         "at safepoint or must be suspended");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (!get_thread()->has_last_Java_frame()) return 0;  // no Java frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  RegisterMap reg_map(get_thread());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  javaVFrame *jvf = get_thread()->last_java_vframe(&reg_map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // tty->print_cr("CSD: counting frames on %s ...",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  //               JvmtiTrace::safe_get_thread_name(get_thread()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  while (jvf != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    methodOop method = jvf->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    // tty->print_cr("CSD: frame - method %s.%s - loc %d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    //               method->klass_name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    //               method->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    //               jvf->bci() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    jvf = jvf->java_sender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    n++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // tty->print_cr("CSD: frame count: %d", n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  return n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
void JvmtiThreadState::invalidate_cur_stack_depth() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  Thread *cur = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  uint32_t debug_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // The caller can be the VMThread at a safepoint, the current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // or the target thread must be suspended.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  guarantee((cur->is_VM_thread() && SafepointSynchronize::is_at_safepoint()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    (JavaThread *)cur == get_thread() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  _cur_stack_depth = UNKNOWN_STACK_DEPTH;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
void JvmtiThreadState::incr_cur_stack_depth() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  guarantee(JavaThread::current() == get_thread(), "must be current thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  if (!is_interp_only_mode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    _cur_stack_depth = UNKNOWN_STACK_DEPTH;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    ++_cur_stack_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
void JvmtiThreadState::decr_cur_stack_depth() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  guarantee(JavaThread::current() == get_thread(), "must be current thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  if (!is_interp_only_mode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    _cur_stack_depth = UNKNOWN_STACK_DEPTH;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    --_cur_stack_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
int JvmtiThreadState::cur_stack_depth() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  uint32_t debug_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  guarantee(JavaThread::current() == get_thread() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    "must be current thread or suspended");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    _cur_stack_depth = count_frames();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    // heavy weight assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    assert(_cur_stack_depth == count_frames(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
           "cur_stack_depth out of sync");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  return _cur_stack_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
bool JvmtiThreadState::may_be_walked() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
void JvmtiThreadState::process_pending_step_for_popframe() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // We are single stepping as the last part of the PopFrame() dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // so we have some house keeping to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  JavaThread *thr = get_thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  if (thr->popframe_condition() != JavaThread::popframe_inactive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    // If the popframe_condition field is not popframe_inactive, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    // we missed all of the popframe_field cleanup points:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    // - unpack_frames() was not called (nothing to deopt)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // - remove_activation_preserving_args_entry() was not called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    //   (did not get suspended in a call_vm() family call and did
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    //   not complete a call_vm() family call on the way here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    thr->clear_popframe_condition();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // clearing the flag indicates we are done with the PopFrame() dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  clr_pending_step_for_popframe();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // If step is pending for popframe then it may not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // a repeat step. The new_bci and method_id is same as current_bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // and current method_id after pop and step for recursive calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // Force the step by clearing the last location.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    ets->clear_current_location();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
// Class:     JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
// Function:  update_for_pop_top_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
// Description:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
//   This function removes any frame pop notification request for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
//   the top frame and invalidates both the current stack depth and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
//   all cached frameIDs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
// Called by: PopFrame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
void JvmtiThreadState::update_for_pop_top_frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  if (is_interp_only_mode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    // remove any frame pop notification request for the top frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    // in any environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    int popframe_number = cur_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
        if (ets->is_frame_pop(popframe_number)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
          ets->clear_frame_pop(popframe_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    // force stack depth to be recalculated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    invalidate_cur_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    assert(!is_enabled(JVMTI_EVENT_FRAME_POP), "Must have no framepops set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
void JvmtiThreadState::process_pending_step_for_earlyret() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  // We are single stepping as the last part of the ForceEarlyReturn
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  // dance so we have some house keeping to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  if (is_earlyret_pending()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    // If the earlyret_state field is not earlyret_inactive, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    // we missed all of the earlyret_field cleanup points:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    // - remove_activation() was not called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    //   (did not get suspended in a call_vm() family call and did
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    //   not complete a call_vm() family call on the way here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // One legitimate way for us to miss all the cleanup points is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    // if we got here right after handling a compiled return. If that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    // is the case, then we consider our return from compiled code to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    // complete the ForceEarlyReturn request and we clear the condition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    clr_earlyret_pending();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    set_earlyret_oop(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    clr_earlyret_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // clearing the flag indicates we are done with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // the ForceEarlyReturn() dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  clr_pending_step_for_earlyret();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  // If step is pending for earlyret then it may not be a repeat step.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  // The new_bci and method_id is same as current_bci and current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // method_id after earlyret and step for recursive calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  // Force the step by clearing the last location.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    ets->clear_current_location();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
void JvmtiThreadState::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  f->do_oop((oop*) &_earlyret_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}