hotspot/src/share/vm/prims/jvmtiImpl.hpp
author kamg
Mon, 10 Jan 2011 17:14:53 -0500
changeset 7896 08aadd7aa3ee
parent 7444 be338e543a57
child 7918 ce1e4ae77aea
permissions -rw-r--r--
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent Summary: Make JvmtiGCMark safe to run non-safepoint and instrument CMS Reviewed-by: ysr, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
     2
 * Copyright (c) 1999, 2010, 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: 2137
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2137
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: 2137
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: 6975
diff changeset
    25
#ifndef SHARE_VM_PRIMS_JVMTIIMPL_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    26
#define SHARE_VM_PRIMS_JVMTIIMPL_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    28
#ifndef JVMTI_KERNEL
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
    29
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    30
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    31
#include "jvmtifiles/jvmti.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    32
#include "oops/objArrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    33
#include "prims/jvmtiEnvThreadState.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    34
#include "prims/jvmtiEventController.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    35
#include "prims/jvmtiTrace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    36
#include "prims/jvmtiUtil.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    37
#include "runtime/stackValueCollection.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    38
#include "runtime/vm_operations.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    39
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Forward Declarations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class JvmtiBreakpoint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class JvmtiBreakpoints;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// class GrowableCache, GrowableElement
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// Used by              : JvmtiBreakpointCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// Used by JVMTI methods: none directly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// GrowableCache is a permanent CHeap growable array of <GrowableElement *>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// In addition, the GrowableCache maintains a NULL terminated cache array of type address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// that's created from the element array using the function:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//     address GrowableElement::getCacheValue().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Whenever the GrowableArray changes size, the cache array gets recomputed into a new C_HEAP allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// block of memory. Additionally, every time the cache changes its position in memory, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//    void (*_listener_fun)(void *this_obj, address* cache)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// gets called with the cache's new address. This gives the user of the GrowableCache a callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// to update its pointer to the address cache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
class GrowableElement : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  virtual address getCacheValue()          =0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  virtual bool equals(GrowableElement* e)  =0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  virtual bool lessThan(GrowableElement *e)=0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  virtual GrowableElement *clone()         =0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  virtual void oops_do(OopClosure* f)      =0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
class GrowableCache VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Object pointer passed into cache & listener functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  void *_this_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Array of elements in the collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  GrowableArray<GrowableElement *> *_elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Parallel array of cached values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  address *_cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Listener for changes to the _cache field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Called whenever the _cache field has it's value changed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // (but NOT when cached elements are recomputed).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void (*_listener_fun)(void *, address*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  static bool equals(void *, GrowableElement *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // recache all elements after size change, notify listener
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  void recache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
   GrowableCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
   ~GrowableCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void initialize(void *this_obj, void listener_fun(void *, address*) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // number of elements in the collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  int length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // get the value of the index element in the collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  GrowableElement* at(int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // find the index of the element, -1 if it doesn't exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  int find(GrowableElement* e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // append a copy of the element to the end of the collection, notify listener
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  void append(GrowableElement* e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // insert a copy of the element using lessthan(), notify listener
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  void insert(GrowableElement* e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // remove the element at index, notify listener
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  void remove (int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // clear out all elements and release all heap space, notify listener
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  void clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // apply f to every element and update the cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
};
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
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// class JvmtiBreakpointCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// Used by              : JvmtiBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// Used by JVMTI methods: none directly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// Note   : typesafe wrapper for GrowableCache of JvmtiBreakpoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
class JvmtiBreakpointCache : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  GrowableCache _cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  JvmtiBreakpointCache()  {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  ~JvmtiBreakpointCache() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void initialize(void *this_obj, void listener_fun(void *, address*) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    _cache.initialize(this_obj,listener_fun);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  int length()                          { return _cache.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  JvmtiBreakpoint& at(int index)        { return (JvmtiBreakpoint&) *(_cache.at(index)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  int find(JvmtiBreakpoint& e)          { return _cache.find((GrowableElement *) &e); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  void append(JvmtiBreakpoint& e)       { _cache.append((GrowableElement *) &e); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  void remove (int index)               { _cache.remove(index); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void clear()                          { _cache.clear(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void oops_do(OopClosure* f)           { _cache.oops_do(f); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// class JvmtiBreakpoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// Used by              : JvmtiBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// Used by JVMTI methods: SetBreakpoint, ClearBreakpoint, ClearAllBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// Note: Extends GrowableElement for use in a GrowableCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// A JvmtiBreakpoint describes a location (class, method, bci) to break at.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
typedef void (methodOopDesc::*method_action)(int _bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
class JvmtiBreakpoint : public GrowableElement {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  methodOop             _method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  int                   _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  Bytecodes::Code       _orig_bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  JvmtiBreakpoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  JvmtiBreakpoint(methodOop m_method, jlocation location);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  bool equals(JvmtiBreakpoint& bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  bool lessThan(JvmtiBreakpoint &bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  void copy(JvmtiBreakpoint& bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  bool is_valid();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  address getBcp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  void each_method_version_do(method_action meth_act);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  void set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  void clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  methodOop method() { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // GrowableElement implementation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  address getCacheValue()         { return getBcp(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  bool lessThan(GrowableElement* e) { Unimplemented(); return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  bool equals(GrowableElement* e) { return equals((JvmtiBreakpoint&) *e); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  void oops_do(OopClosure* f)     { f->do_oop((oop *) &_method); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  GrowableElement *clone()        {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    JvmtiBreakpoint *bp = new JvmtiBreakpoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    bp->copy(*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    return bp;
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
// class VM_ChangeBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// Used by              : JvmtiBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
// Used by JVMTI methods: none directly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// Note: A Helper class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// VM_ChangeBreakpoints implements a VM_Operation for ALL modifications to the JvmtiBreakpoints class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
class VM_ChangeBreakpoints : public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  JvmtiBreakpoints* _breakpoints;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  int               _operation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  JvmtiBreakpoint*  _bp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  enum { SET_BREAKPOINT=0, CLEAR_BREAKPOINT=1, CLEAR_ALL_BREAKPOINT=2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    _breakpoints = breakpoints;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    _bp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    _operation = operation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    assert(breakpoints != NULL, "breakpoints != NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    assert(operation == CLEAR_ALL_BREAKPOINT, "unknown breakpoint operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation, JvmtiBreakpoint *bp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    _breakpoints = breakpoints;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    _bp = bp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    _operation = operation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    assert(breakpoints != NULL, "breakpoints != NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    assert(bp != NULL, "bp != NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    assert(operation == SET_BREAKPOINT || operation == CLEAR_BREAKPOINT , "unknown breakpoint operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  VMOp_Type type() const { return VMOp_ChangeBreakpoints; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
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 JvmtiBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// Used by              : JvmtiCurrentBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// Used by JVMTI methods: none directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// Note: A Helper class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
// JvmtiBreakpoints is a GrowableCache of JvmtiBreakpoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
// All changes to the GrowableCache occur at a safepoint using VM_ChangeBreakpoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
// Because _bps is only modified at safepoints, its possible to always use the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
// cached byte code pointers from _bps without doing any synchronization (see JvmtiCurrentBreakpoints).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
// It would be possible to make JvmtiBreakpoints a static class, but I've made it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
// CHeap allocated to emphasize its similarity to JvmtiFramePops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
class JvmtiBreakpoints : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  JvmtiBreakpointCache _bps;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // These should only be used by VM_ChangeBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // to insure they only occur at safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // Todo: add checks for safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  friend class VM_ChangeBreakpoints;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  void set_at_safepoint(JvmtiBreakpoint& bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  void clear_at_safepoint(JvmtiBreakpoint& bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  void clearall_at_safepoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  static void do_element(GrowableElement *e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  JvmtiBreakpoints(void listener_fun(void *, address *));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  ~JvmtiBreakpoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  int length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  int  set(JvmtiBreakpoint& bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  int  clear(JvmtiBreakpoint& bp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  void clearall_in_class_at_safepoint(klassOop klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  void clearall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
// class JvmtiCurrentBreakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
// A static wrapper class for the JvmtiBreakpoints that provides:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// 1. a fast inlined function to check if a byte code pointer is a breakpoint (is_breakpoint).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
// 2. a function for lazily creating the JvmtiBreakpoints class (this is not strictly necessary,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
//    but I'm copying the code from JvmtiThreadState which needs to lazily initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
//    JvmtiFramePops).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
// 3. An oops_do entry point for GC'ing the breakpoint array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
class JvmtiCurrentBreakpoints : public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Current breakpoints, lazily initialized by get_jvmti_breakpoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  static JvmtiBreakpoints *_jvmti_breakpoints;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  // NULL terminated cache of byte-code pointers corresponding to current breakpoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // Updated only at safepoints (with listener_fun) when the cache is moved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // It exists only to make is_breakpoint fast.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  static address          *_breakpoint_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  static inline void set_breakpoint_list(address *breakpoint_list) { _breakpoint_list = breakpoint_list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  static inline address *get_breakpoint_list()                     { return _breakpoint_list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  // Listener for the GrowableCache in _jvmti_breakpoints, updates _breakpoint_list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  static void listener_fun(void *this_obj, address *cache);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  static void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  static void destroy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  // lazily create _jvmti_breakpoints and _breakpoint_list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  static JvmtiBreakpoints& get_jvmti_breakpoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // quickly test whether the bcp matches a cached breakpoint in the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  static inline bool is_breakpoint(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  static void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
// quickly test whether the bcp matches a cached breakpoint in the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
bool JvmtiCurrentBreakpoints::is_breakpoint(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    address *bps = get_breakpoint_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    if (bps == NULL) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    for ( ; (*bps) != NULL; bps++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      if ((*bps) == bcp) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
// The get/set local operations must only be done by the VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// because the interpreter version needs to access oop maps, which can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// only safely be done by the VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// I'm told that in 1.5 oop maps are now protected by a lock and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
// we could get rid of the VM op
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
// However if the VM op is removed then the target thread must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
// be suspended AND a lock will be needed to prevent concurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
// setting of locals to the same java thread. This lock is needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
// to prevent compiledVFrames from trying to add deferred updates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
// to the thread simultaneously.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
class VM_GetOrSetLocal : public VM_Operation {
7444
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   354
 protected:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  JavaThread* _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  JavaThread* _calling_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  jint        _depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  jint        _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  BasicType   _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  jvalue      _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  javaVFrame* _jvf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  bool        _set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
7444
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   364
  // It is possible to get the receiver out of a non-static native wrapper
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   365
  // frame.  Use VM_GetReceiver to do this.
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   366
  virtual bool getting_receiver() const { return false; }
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   367
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  jvmtiError  _result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  vframe* get_vframe();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  javaVFrame* get_java_vframe();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  bool check_slot_type(javaVFrame* vf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // Constructor for non-object getter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // Constructor for object or non-object setter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  // Constructor for object getter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
                   int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  VMOp_Type type() const { return VMOp_GetOrSetLocal; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  jvalue value()         { return _value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  jvmtiError result()    { return _result; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  bool doit_prologue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  bool allow_nested_vm_operations() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  const char* name() const                       { return "get/set locals"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  // Check that the klass is assignable to a type with the given signature.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  static bool is_assignable(const char* ty_sign, Klass* klass, Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
7444
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   398
class VM_GetReceiver : public VM_GetOrSetLocal {
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   399
 protected:
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   400
  virtual bool getting_receiver() const { return true; }
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   401
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   402
 public:
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   403
  VM_GetReceiver(JavaThread* thread, JavaThread* calling_thread, jint depth);
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   404
  const char* name() const                       { return "get receiver"; }
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   405
};
be338e543a57 7004582: Add GetThisObject() function to JVMTI 1.2
kamg
parents: 7408
diff changeset
   406
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
///////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
// class JvmtiSuspendControl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
// Convenience routines for suspending and resuming threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
// All attempts by JVMTI to suspend and resume threads must go through the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
// JvmtiSuspendControl interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
// methods return true if successful
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
class JvmtiSuspendControl : public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // suspend the thread, taking it to a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  static bool suspend(JavaThread *java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  // resume the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  static bool resume(JavaThread *java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  static void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   429
#endif // !JVMTI_KERNEL
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   430
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
// Utility macro that checks for NULL pointers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
#define NULL_CHECK(X, Y) if ((X) == NULL) { return (Y); }
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
   433
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
   434
#endif // SHARE_VM_PRIMS_JVMTIIMPL_HPP