src/hotspot/share/prims/jvmtiThreadState.cpp
author stefank
Fri, 23 Mar 2018 18:54:12 +0100
changeset 49594 898ef81cbc0e
parent 47216 71c04702a3d5
child 50578 e2a7f431f65c
permissions -rw-r--r--
8200106: Move NoSafepointVerifier out from gcLocker.hpp Reviewed-by: coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 23180
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "jvmtifiles/jvmtiEnv.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "prims/jvmtiEventController.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "prims/jvmtiImpl.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "prims/jvmtiThreadState.inline.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 47216
diff changeset
    31
#include "runtime/safepointVerifiers.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/vframe.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// marker for when the stack depth has been reset and is now unknown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// any negative number would work but small ones might obscure an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// underrun error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
static const int UNKNOWN_STACK_DEPTH = -99;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// class JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// Instances of JvmtiThreadState hang off of each thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Thread local storage for JVMTI.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
JvmtiThreadState *JvmtiThreadState::_head = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
JvmtiThreadState::JvmtiThreadState(JavaThread* thread)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  : _thread_event_enable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _thread               = thread;
42895
c97cd79636ec 8165496: assert(_exception_caught == false) failed: _exception_caught is out of phase
dsamersoff
parents: 37992
diff changeset
    53
  _exception_state      = ES_CLEARED;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _debuggable           = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _hide_single_stepping = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _hide_level           = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _pending_step_for_popframe = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _class_being_redefined = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _class_load_kind = jvmti_class_load_kind_load;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _head_env_thread_state = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _dynamic_code_event_collector = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _vm_object_alloc_event_collector = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _the_class_for_redefinition_verification = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _scratch_class_for_redefinition_verification = NULL;
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
    65
  _cur_stack_depth = UNKNOWN_STACK_DEPTH;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // JVMTI ForceEarlyReturn support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _pending_step_for_earlyret = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _earlyret_state = earlyret_inactive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _earlyret_tos = ilgl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _earlyret_value.j = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _earlyret_oop = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // add all the JvmtiEnvThreadState to the new JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    JvmtiEnvIterator it;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      if (env->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        add_env(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // link us into the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    // The thread state list manipulation code must not have safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // See periodic_clean_up().
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 30764
diff changeset
    88
    debug_only(NoSafepointVerifier nosafepoint;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    _prev = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    _next = _head;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    if (_head != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      _head->_prev = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    _head = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // set this as the state for the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  thread->set_jvmti_thread_state(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
JvmtiThreadState::~JvmtiThreadState()   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // clear this as the state for the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  get_thread()->set_jvmti_thread_state(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // zap our env thread states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    JvmtiEnvBase::entering_dying_thread_env_iteration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      JvmtiEnvThreadState* zap = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      ets = it.next(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      delete zap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    JvmtiEnvBase::leaving_dying_thread_env_iteration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // remove us from the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // The thread state list manipulation code must not have safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // See periodic_clean_up().
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 30764
diff changeset
   125
    debug_only(NoSafepointVerifier nosafepoint;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if (_prev == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      assert(_head == this, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      _head = _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      assert(_head != this, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      _prev->_next = _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (_next != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      _next->_prev = _prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    _next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    _prev = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
JvmtiThreadState::periodic_clean_up() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  assert(SafepointSynchronize::is_at_safepoint(), "at safepoint");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // This iteration is initialized with "_head" instead of "JvmtiThreadState::first()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // because the latter requires the JvmtiThreadState_lock.
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 30764
diff changeset
   149
  // This iteration is safe at a safepoint as well, see the NoSafepointVerifier
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // asserts at all list manipulation sites.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  for (JvmtiThreadState *state = _head; state != NULL; state = state->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    // For each environment thread state corresponding to an invalid environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    // unlink it from the list and deallocate it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    JvmtiEnvThreadStateIterator it(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    JvmtiEnvThreadState* previous_ets = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    JvmtiEnvThreadState* ets = it.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    while (ets != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      if (ets->get_env()->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        previous_ets = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        ets = it.next(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        // This one isn't valid, remove it from the list and deallocate it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        JvmtiEnvThreadState* defunct_ets = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        ets = ets->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        if (previous_ets == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
          assert(state->head_env_thread_state() == defunct_ets, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
          state->set_head_env_thread_state(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
          previous_ets->set_next(ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        delete defunct_ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
void JvmtiThreadState::add_env(JvmtiEnvBase *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  JvmtiEnvThreadState *new_ets = new JvmtiEnvThreadState(_thread, env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // add this environment thread state to the end of the list (order is important)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // list deallocation (which occurs at a safepoint) cannot occur simultaneously
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 30764
diff changeset
   184
    debug_only(NoSafepointVerifier nosafepoint;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    JvmtiEnvThreadState* previous_ets = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      previous_ets = ets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    if (previous_ets == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      set_head_env_thread_state(new_ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      previous_ets->set_next(new_ets);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
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::enter_interp_only_mode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  assert(_thread->get_interp_only_mode() == 0, "entering interp only when mode not zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  _thread->increment_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
void JvmtiThreadState::leave_interp_only_mode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  assert(_thread->get_interp_only_mode() == 1, "leaving interp only when mode not one");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  _thread->decrement_interp_only_mode();
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
// Helper routine used in several places
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
int JvmtiThreadState::count_frames() {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   216
  guarantee(SafepointSynchronize::is_at_safepoint() ||
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   217
    (JavaThread *)Thread::current() == get_thread(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   218
    "must be current thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  if (!get_thread()->has_last_Java_frame()) return 0;  // no Java frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  RegisterMap reg_map(get_thread());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  javaVFrame *jvf = get_thread()->last_java_vframe(&reg_map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  while (jvf != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11588
diff changeset
   227
    Method* method = jvf->method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    jvf = jvf->java_sender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    n++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  return n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
void JvmtiThreadState::invalidate_cur_stack_depth() {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   236
  guarantee(SafepointSynchronize::is_at_safepoint() ||
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   237
    (JavaThread *)Thread::current() == get_thread(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   238
    "must be current thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  _cur_stack_depth = UNKNOWN_STACK_DEPTH;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
void JvmtiThreadState::incr_cur_stack_depth() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  guarantee(JavaThread::current() == get_thread(), "must be current thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (!is_interp_only_mode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    _cur_stack_depth = UNKNOWN_STACK_DEPTH;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    ++_cur_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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
void JvmtiThreadState::decr_cur_stack_depth() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  guarantee(JavaThread::current() == get_thread(), "must be current thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  if (!is_interp_only_mode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    _cur_stack_depth = UNKNOWN_STACK_DEPTH;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    --_cur_stack_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
int JvmtiThreadState::cur_stack_depth() {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   267
  guarantee(SafepointSynchronize::is_at_safepoint() ||
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   268
    (JavaThread *)Thread::current() == get_thread(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 13728
diff changeset
   269
    "must be current thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    _cur_stack_depth = count_frames();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    // heavy weight assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    assert(_cur_stack_depth == count_frames(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
           "cur_stack_depth out of sync");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  return _cur_stack_depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
bool JvmtiThreadState::may_be_walked() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
void JvmtiThreadState::process_pending_step_for_popframe() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // We are single stepping as the last part of the PopFrame() dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // so we have some house keeping to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  JavaThread *thr = get_thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  if (thr->popframe_condition() != JavaThread::popframe_inactive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    // If the popframe_condition field is not popframe_inactive, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    // we missed all of the popframe_field cleanup points:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    // - unpack_frames() was not called (nothing to deopt)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    // - remove_activation_preserving_args_entry() was not called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    //   (did not get suspended in a call_vm() family call and did
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    //   not complete a call_vm() family call on the way here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    thr->clear_popframe_condition();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  // clearing the flag indicates we are done with the PopFrame() dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  clr_pending_step_for_popframe();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
11588
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   305
  // If exception was thrown in this frame, need to reset jvmti thread state.
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   306
  // Single stepping may not get enabled correctly by the agent since
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   307
  // exception state is passed in MethodExit event which may be sent at some
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   308
  // time in the future. JDWP agent ignores MethodExit events if caused by
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   309
  // an exception.
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   310
  //
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   311
  if (is_exception_detected()) {
42895
c97cd79636ec 8165496: assert(_exception_caught == false) failed: _exception_caught is out of phase
dsamersoff
parents: 37992
diff changeset
   312
    clear_exception_state();
11588
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   313
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  // If step is pending for popframe then it may not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  // a repeat step. The new_bci and method_id is same as current_bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // and current method_id after pop and step for recursive calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Force the step by clearing the last location.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    ets->clear_current_location();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
// Class:     JvmtiThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
// Function:  update_for_pop_top_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
// Description:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
//   This function removes any frame pop notification request for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
//   the top frame and invalidates both the current stack depth and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
//   all cached frameIDs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
// Called by: PopFrame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
void JvmtiThreadState::update_for_pop_top_frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  if (is_interp_only_mode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    // remove any frame pop notification request for the top frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    // in any environment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    int popframe_number = cur_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
        if (ets->is_frame_pop(popframe_number)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
          ets->clear_frame_pop(popframe_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    // force stack depth to be recalculated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    invalidate_cur_stack_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    assert(!is_enabled(JVMTI_EVENT_FRAME_POP), "Must have no framepops set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  }
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 JvmtiThreadState::process_pending_step_for_earlyret() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // We are single stepping as the last part of the ForceEarlyReturn
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  // dance so we have some house keeping to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  if (is_earlyret_pending()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    // If the earlyret_state field is not earlyret_inactive, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    // we missed all of the earlyret_field cleanup points:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    // - remove_activation() was not called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    //   (did not get suspended in a call_vm() family call and did
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    //   not complete a call_vm() family call on the way here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // One legitimate way for us to miss all the cleanup points is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    // if we got here right after handling a compiled return. If that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // is the case, then we consider our return from compiled code to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    // complete the ForceEarlyReturn request and we clear the condition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    clr_earlyret_pending();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    set_earlyret_oop(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    clr_earlyret_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // clearing the flag indicates we are done with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  // the ForceEarlyReturn() dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  clr_pending_step_for_earlyret();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
11588
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   380
  // If exception was thrown in this frame, need to reset jvmti thread state.
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   381
  // Single stepping may not get enabled correctly by the agent since
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   382
  // exception state is passed in MethodExit event which may be sent at some
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   383
  // time in the future. JDWP agent ignores MethodExit events if caused by
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   384
  // an exception.
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   385
  //
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   386
  if (is_exception_detected()) {
42895
c97cd79636ec 8165496: assert(_exception_caught == false) failed: _exception_caught is out of phase
dsamersoff
parents: 37992
diff changeset
   387
    clear_exception_state();
11588
e616efa1a931 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 7397
diff changeset
   388
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  // If step is pending for earlyret then it may not be a repeat step.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // The new_bci and method_id is same as current_bci and current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // method_id after earlyret and step for recursive calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  // Force the step by clearing the last location.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  JvmtiEnvThreadStateIterator it(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    ets->clear_current_location();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
void JvmtiThreadState::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  f->do_oop((oop*) &_earlyret_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
}