src/hotspot/share/prims/jvmtiEnvThreadState.cpp
author pliden
Mon, 14 May 2018 15:42:59 +0200
changeset 50102 454fa295105c
parent 49449 ef5d5d343e2a
child 52877 9e041366c764
permissions -rw-r--r--
8202976: Add C1 lea patching support for x86 Reviewed-by: kvn, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2017, 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 "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "jvmtifiles/jvmtiEnv.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "prims/jvmtiEnvThreadState.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "prims/jvmtiEventController.inline.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 "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/handles.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 48105
diff changeset
    35
#include "runtime/interfaceSupport.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/signature.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
    38
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/vframe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "runtime/vm_operations.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// class JvmtiFramePop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
void JvmtiFramePop::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  tty->print_cr("_frame_number=%d", _frame_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// class JvmtiFramePops - private methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
JvmtiFramePops::set(JvmtiFramePop& fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  if (_pops->find(fp.frame_number()) < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _pops->append(fp.frame_number());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
JvmtiFramePops::clear(JvmtiFramePop& fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  assert(_pops->length() > 0, "No more frame pops");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _pops->remove(fp.frame_number());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
int
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
JvmtiFramePops::clear_to(JvmtiFramePop& fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  int cleared = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  while (index < _pops->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    JvmtiFramePop pop = JvmtiFramePop(_pops->at(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (pop.above_on_stack(fp)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      _pops->remove_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      ++cleared;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  return cleared;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// class JvmtiFramePops - public methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
JvmtiFramePops::JvmtiFramePops() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    99
  _pops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int> (2, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
JvmtiFramePops::~JvmtiFramePops() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // return memory to c_heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  delete _pops;
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
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
void JvmtiFramePops::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  int n = _pops->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  for (int i=0; i<n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    JvmtiFramePop fp = JvmtiFramePop(_pops->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    tty->print("%d: ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    fp.print();
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23180
diff changeset
   117
    tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
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
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// class JvmtiEnvThreadState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// Instances of JvmtiEnvThreadState hang off of each JvmtiThreadState,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// one per JvmtiEnv.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
JvmtiEnvThreadState::JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  _event_enable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _thread                 = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  _env                    = (JvmtiEnv*)env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  _next                   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  _frame_pops             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  _current_bci            = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  _current_method_id      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  _breakpoint_posted      = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  _single_stepping_posted = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  _agent_thread_local_storage_data = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
JvmtiEnvThreadState::~JvmtiEnvThreadState()   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  delete _frame_pops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  _frame_pops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
// Given that a new (potential) event has come in,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// maintain the current JVMTI location on a per-thread per-env basis
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
// and use it to filter out duplicate events:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// - instruction rewrites
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// - breakpoint followed by single step
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// - single step at a breakpoint
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   154
void JvmtiEnvThreadState::compare_and_set_current_location(Method* new_method,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                                                           address new_location, jvmtiEvent event) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  int new_bci = new_location - new_method->code_base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // The method is identified and stored as a jmethodID which is safe in this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // case because the class cannot be unloaded while a method is executing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  jmethodID new_method_id = new_method->jmethod_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // the last breakpoint or single step was at this same location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  if (_current_bci == new_bci && _current_method_id == new_method_id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    switch (event) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    case JVMTI_EVENT_BREAKPOINT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      // Repeat breakpoint is complicated. If we previously posted a breakpoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      // event at this location and if we also single stepped at this location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      // then we skip the duplicate breakpoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      _breakpoint_posted = _breakpoint_posted && _single_stepping_posted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    case JVMTI_EVENT_SINGLE_STEP:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      // Repeat single step is easy: just don't post it again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      // If step is pending for popframe then it may not be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      // a repeat step. The new_bci and method_id is same as current_bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      // and current method_id after pop and step for recursive calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      // This has been handled by clearing the location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      _single_stepping_posted = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      assert(false, "invalid event value passed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  set_current_location(new_method_id, new_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  _breakpoint_posted = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  _single_stepping_posted = false;
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
JvmtiFramePops* JvmtiEnvThreadState::get_frame_pops() {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   194
  assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   195
         "frame pop data only accessible from same thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (_frame_pops == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    _frame_pops = new JvmtiFramePops();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    assert(_frame_pops != NULL, "_frame_pops != NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  return _frame_pops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
bool JvmtiEnvThreadState::has_frame_pops() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  return _frame_pops == NULL? false : (_frame_pops->length() > 0);
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 JvmtiEnvThreadState::set_frame_pop(int frame_number) {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   209
  assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   210
         "frame pop data only accessible from same thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  JvmtiFramePop fpop(frame_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  JvmtiEventController::set_frame_pop(this, fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void JvmtiEnvThreadState::clear_frame_pop(int frame_number) {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   217
  assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   218
         "frame pop data only accessible from same thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  JvmtiFramePop fpop(frame_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  JvmtiEventController::clear_frame_pop(this, fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
void JvmtiEnvThreadState::clear_to_frame_pop(int frame_number)  {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   225
  assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   226
         "frame pop data only accessible from same thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  JvmtiFramePop fpop(frame_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  JvmtiEventController::clear_to_frame_pop(this, fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
bool JvmtiEnvThreadState::is_frame_pop(int cur_frame_number) {
23180
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   233
  assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
e87156376bed 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 22519
diff changeset
   234
         "frame pop data only accessible from same thread or at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  if (!get_thread()->is_interp_only_mode() || _frame_pops == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  JvmtiFramePop fp(cur_frame_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  return get_frame_pops()->contains(fp);
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
class VM_GetCurrentLocation : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
   JavaThread *_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
   jmethodID _method_id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
   int _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  VM_GetCurrentLocation(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
     _thread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  VMOp_Type type() const { return VMOp_GetCurrentLocation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    ResourceMark rmark; // _thread != Thread::current()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    RegisterMap rm(_thread, false);
21914
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   257
    // There can be a race condition between a VM_Operation reaching a safepoint
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   258
    // and the target thread exiting from Java execution.
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   259
    // We must recheck the last Java frame still exists.
22519
924605caa9a8 8030027: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Linux-amd64: SIGSEGV in JavaThread::last_java_vframe(RegisterMap*)+0xfa
sspitsyn
parents: 22234
diff changeset
   260
    if (!_thread->is_exiting() && _thread->has_last_Java_frame()) {
21914
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   261
      javaVFrame* vf = _thread->last_java_vframe(&rm);
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   262
      assert(vf != NULL, "must have last java frame");
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   263
      Method* method = vf->method();
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   264
      _method_id = method->jmethod_id();
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   265
      _bci = vf->bci();
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   266
    } else {
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   267
      // Clear current location as the target thread has no Java frames anymore.
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   268
      _method_id = (jmethodID)NULL;
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   269
      _bci = 0;
b60984ed653b 8028126: nsk/jvmti/scenarios/hotswap/HS101/hs101t006 Crashed the vm on Solaris-sparc64 fastdebug builds: only current thread can flush its registers
sspitsyn
parents: 13728
diff changeset
   270
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  void get_current_location(jmethodID *method_id, int *bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    *method_id = _method_id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    *bci = _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  assert(event_type == JVMTI_EVENT_SINGLE_STEP || event_type == JVMTI_EVENT_BREAKPOINT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
         "must be single-step or breakpoint event");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // Current location is used to detect the following:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // 1) a breakpoint event followed by single-stepping to the same bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // 2) single-step to a bytecode that will be transformed to a fast version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // We skip to avoid posting the duplicate single-stepping event.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // If single-stepping is disabled, clear current location so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // single-stepping to the same method and bcp at a later time will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  // detected if single-stepping is enabled at that time (see 4388912).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  // If single-stepping is enabled, set the current location to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // current method and bcp. This covers the following type of case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // e.g., the debugger stepi command:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // - bytecode single stepped
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // - SINGLE_STEP event posted and SINGLE_STEP event disabled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // - SINGLE_STEP event reenabled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // - bytecode rewritten to fast version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // If breakpoint event is disabled, clear current location only if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // single-stepping is not enabled.  Otherwise, keep the thread location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // to detect any duplicate events.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  if (enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    // If enabling breakpoint, no need to reset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    // Can't do anything if empty stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    if (event_type == JVMTI_EVENT_SINGLE_STEP && _thread->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      jmethodID method_id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      int bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      // The java thread stack may not be walkable for a running thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      // so get current location at safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      VM_GetCurrentLocation op(_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      op.get_current_location(&method_id, &bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      set_current_location(method_id, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  } else if (event_type == JVMTI_EVENT_SINGLE_STEP || !is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    // If this is to disable breakpoint, also check if single-step is not enabled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    clear_current_location();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
}