src/share/vm/prims/jvmtiImpl.hpp

Fri, 22 Oct 2010 15:59:34 -0400

author
acorn
date
Fri, 22 Oct 2010 15:59:34 -0400
changeset 2233
fa83ab460c54
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6988353: refactor contended sync subsystem
Summary: reduce complexity by factoring synchronizer.cpp
Reviewed-by: dholmes, never, coleenp

duke@435 1 /*
trims@1907 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 //
duke@435 26 // Forward Declarations
duke@435 27 //
duke@435 28
duke@435 29 class JvmtiBreakpoint;
duke@435 30 class JvmtiBreakpoints;
duke@435 31
duke@435 32
duke@435 33 ///////////////////////////////////////////////////////////////
duke@435 34 //
duke@435 35 // class GrowableCache, GrowableElement
duke@435 36 // Used by : JvmtiBreakpointCache
duke@435 37 // Used by JVMTI methods: none directly.
duke@435 38 //
duke@435 39 // GrowableCache is a permanent CHeap growable array of <GrowableElement *>
duke@435 40 //
duke@435 41 // In addition, the GrowableCache maintains a NULL terminated cache array of type address
duke@435 42 // that's created from the element array using the function:
duke@435 43 // address GrowableElement::getCacheValue().
duke@435 44 //
duke@435 45 // Whenever the GrowableArray changes size, the cache array gets recomputed into a new C_HEAP allocated
duke@435 46 // block of memory. Additionally, every time the cache changes its position in memory, the
duke@435 47 // void (*_listener_fun)(void *this_obj, address* cache)
duke@435 48 // gets called with the cache's new address. This gives the user of the GrowableCache a callback
duke@435 49 // to update its pointer to the address cache.
duke@435 50 //
duke@435 51
duke@435 52 class GrowableElement : public CHeapObj {
duke@435 53 public:
duke@435 54 virtual address getCacheValue() =0;
duke@435 55 virtual bool equals(GrowableElement* e) =0;
duke@435 56 virtual bool lessThan(GrowableElement *e)=0;
duke@435 57 virtual GrowableElement *clone() =0;
duke@435 58 virtual void oops_do(OopClosure* f) =0;
duke@435 59 };
duke@435 60
duke@435 61 class GrowableCache VALUE_OBJ_CLASS_SPEC {
duke@435 62
duke@435 63 private:
duke@435 64 // Object pointer passed into cache & listener functions.
duke@435 65 void *_this_obj;
duke@435 66
duke@435 67 // Array of elements in the collection
duke@435 68 GrowableArray<GrowableElement *> *_elements;
duke@435 69
duke@435 70 // Parallel array of cached values
duke@435 71 address *_cache;
duke@435 72
duke@435 73 // Listener for changes to the _cache field.
duke@435 74 // Called whenever the _cache field has it's value changed
duke@435 75 // (but NOT when cached elements are recomputed).
duke@435 76 void (*_listener_fun)(void *, address*);
duke@435 77
duke@435 78 static bool equals(void *, GrowableElement *);
duke@435 79
duke@435 80 // recache all elements after size change, notify listener
duke@435 81 void recache();
duke@435 82
duke@435 83 public:
duke@435 84 GrowableCache();
duke@435 85 ~GrowableCache();
duke@435 86
duke@435 87 void initialize(void *this_obj, void listener_fun(void *, address*) );
duke@435 88
duke@435 89 // number of elements in the collection
duke@435 90 int length();
duke@435 91 // get the value of the index element in the collection
duke@435 92 GrowableElement* at(int index);
duke@435 93 // find the index of the element, -1 if it doesn't exist
duke@435 94 int find(GrowableElement* e);
duke@435 95 // append a copy of the element to the end of the collection, notify listener
duke@435 96 void append(GrowableElement* e);
duke@435 97 // insert a copy of the element using lessthan(), notify listener
duke@435 98 void insert(GrowableElement* e);
duke@435 99 // remove the element at index, notify listener
duke@435 100 void remove (int index);
duke@435 101 // clear out all elements and release all heap space, notify listener
duke@435 102 void clear();
duke@435 103 // apply f to every element and update the cache
duke@435 104 void oops_do(OopClosure* f);
duke@435 105 void gc_epilogue();
duke@435 106 };
duke@435 107
duke@435 108
duke@435 109 ///////////////////////////////////////////////////////////////
duke@435 110 //
duke@435 111 // class JvmtiBreakpointCache
duke@435 112 // Used by : JvmtiBreakpoints
duke@435 113 // Used by JVMTI methods: none directly.
duke@435 114 // Note : typesafe wrapper for GrowableCache of JvmtiBreakpoint
duke@435 115 //
duke@435 116
duke@435 117 class JvmtiBreakpointCache : public CHeapObj {
duke@435 118
duke@435 119 private:
duke@435 120 GrowableCache _cache;
duke@435 121
duke@435 122 public:
duke@435 123 JvmtiBreakpointCache() {}
duke@435 124 ~JvmtiBreakpointCache() {}
duke@435 125
duke@435 126 void initialize(void *this_obj, void listener_fun(void *, address*) ) {
duke@435 127 _cache.initialize(this_obj,listener_fun);
duke@435 128 }
duke@435 129
duke@435 130 int length() { return _cache.length(); }
duke@435 131 JvmtiBreakpoint& at(int index) { return (JvmtiBreakpoint&) *(_cache.at(index)); }
duke@435 132 int find(JvmtiBreakpoint& e) { return _cache.find((GrowableElement *) &e); }
duke@435 133 void append(JvmtiBreakpoint& e) { _cache.append((GrowableElement *) &e); }
duke@435 134 void remove (int index) { _cache.remove(index); }
duke@435 135 void clear() { _cache.clear(); }
duke@435 136 void oops_do(OopClosure* f) { _cache.oops_do(f); }
duke@435 137 void gc_epilogue() { _cache.gc_epilogue(); }
duke@435 138 };
duke@435 139
duke@435 140
duke@435 141 ///////////////////////////////////////////////////////////////
duke@435 142 //
duke@435 143 // class JvmtiBreakpoint
duke@435 144 // Used by : JvmtiBreakpoints
duke@435 145 // Used by JVMTI methods: SetBreakpoint, ClearBreakpoint, ClearAllBreakpoints
duke@435 146 // Note: Extends GrowableElement for use in a GrowableCache
duke@435 147 //
duke@435 148 // A JvmtiBreakpoint describes a location (class, method, bci) to break at.
duke@435 149 //
duke@435 150
duke@435 151 typedef void (methodOopDesc::*method_action)(int _bci);
duke@435 152
duke@435 153 class JvmtiBreakpoint : public GrowableElement {
duke@435 154 private:
duke@435 155 methodOop _method;
duke@435 156 int _bci;
duke@435 157 Bytecodes::Code _orig_bytecode;
duke@435 158
duke@435 159 public:
duke@435 160 JvmtiBreakpoint();
duke@435 161 JvmtiBreakpoint(methodOop m_method, jlocation location);
duke@435 162 bool equals(JvmtiBreakpoint& bp);
duke@435 163 bool lessThan(JvmtiBreakpoint &bp);
duke@435 164 void copy(JvmtiBreakpoint& bp);
duke@435 165 bool is_valid();
duke@435 166 address getBcp();
duke@435 167 void each_method_version_do(method_action meth_act);
duke@435 168 void set();
duke@435 169 void clear();
duke@435 170 void print();
duke@435 171
duke@435 172 methodOop method() { return _method; }
duke@435 173
duke@435 174 // GrowableElement implementation
duke@435 175 address getCacheValue() { return getBcp(); }
duke@435 176 bool lessThan(GrowableElement* e) { Unimplemented(); return false; }
duke@435 177 bool equals(GrowableElement* e) { return equals((JvmtiBreakpoint&) *e); }
duke@435 178 void oops_do(OopClosure* f) { f->do_oop((oop *) &_method); }
duke@435 179 GrowableElement *clone() {
duke@435 180 JvmtiBreakpoint *bp = new JvmtiBreakpoint();
duke@435 181 bp->copy(*this);
duke@435 182 return bp;
duke@435 183 }
duke@435 184 };
duke@435 185
duke@435 186
duke@435 187 ///////////////////////////////////////////////////////////////
duke@435 188 //
duke@435 189 // class VM_ChangeBreakpoints
duke@435 190 // Used by : JvmtiBreakpoints
duke@435 191 // Used by JVMTI methods: none directly.
duke@435 192 // Note: A Helper class.
duke@435 193 //
duke@435 194 // VM_ChangeBreakpoints implements a VM_Operation for ALL modifications to the JvmtiBreakpoints class.
duke@435 195 //
duke@435 196
duke@435 197 class VM_ChangeBreakpoints : public VM_Operation {
duke@435 198 private:
duke@435 199 JvmtiBreakpoints* _breakpoints;
duke@435 200 int _operation;
duke@435 201 JvmtiBreakpoint* _bp;
duke@435 202
duke@435 203 public:
duke@435 204 enum { SET_BREAKPOINT=0, CLEAR_BREAKPOINT=1, CLEAR_ALL_BREAKPOINT=2 };
duke@435 205
duke@435 206 VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation) {
duke@435 207 _breakpoints = breakpoints;
duke@435 208 _bp = NULL;
duke@435 209 _operation = operation;
duke@435 210 assert(breakpoints != NULL, "breakpoints != NULL");
duke@435 211 assert(operation == CLEAR_ALL_BREAKPOINT, "unknown breakpoint operation");
duke@435 212 }
duke@435 213 VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation, JvmtiBreakpoint *bp) {
duke@435 214 _breakpoints = breakpoints;
duke@435 215 _bp = bp;
duke@435 216 _operation = operation;
duke@435 217 assert(breakpoints != NULL, "breakpoints != NULL");
duke@435 218 assert(bp != NULL, "bp != NULL");
duke@435 219 assert(operation == SET_BREAKPOINT || operation == CLEAR_BREAKPOINT , "unknown breakpoint operation");
duke@435 220 }
duke@435 221
duke@435 222 VMOp_Type type() const { return VMOp_ChangeBreakpoints; }
duke@435 223 void doit();
duke@435 224 void oops_do(OopClosure* f);
duke@435 225 };
duke@435 226
duke@435 227
duke@435 228 ///////////////////////////////////////////////////////////////
duke@435 229 //
duke@435 230 // class JvmtiBreakpoints
duke@435 231 // Used by : JvmtiCurrentBreakpoints
duke@435 232 // Used by JVMTI methods: none directly
duke@435 233 // Note: A Helper class
duke@435 234 //
duke@435 235 // JvmtiBreakpoints is a GrowableCache of JvmtiBreakpoint.
duke@435 236 // All changes to the GrowableCache occur at a safepoint using VM_ChangeBreakpoints.
duke@435 237 //
duke@435 238 // Because _bps is only modified at safepoints, its possible to always use the
duke@435 239 // cached byte code pointers from _bps without doing any synchronization (see JvmtiCurrentBreakpoints).
duke@435 240 //
duke@435 241 // It would be possible to make JvmtiBreakpoints a static class, but I've made it
duke@435 242 // CHeap allocated to emphasize its similarity to JvmtiFramePops.
duke@435 243 //
duke@435 244
duke@435 245 class JvmtiBreakpoints : public CHeapObj {
duke@435 246 private:
duke@435 247
duke@435 248 JvmtiBreakpointCache _bps;
duke@435 249
duke@435 250 // These should only be used by VM_ChangeBreakpoints
duke@435 251 // to insure they only occur at safepoints.
duke@435 252 // Todo: add checks for safepoint
duke@435 253 friend class VM_ChangeBreakpoints;
duke@435 254 void set_at_safepoint(JvmtiBreakpoint& bp);
duke@435 255 void clear_at_safepoint(JvmtiBreakpoint& bp);
duke@435 256 void clearall_at_safepoint();
duke@435 257
duke@435 258 static void do_element(GrowableElement *e);
duke@435 259
duke@435 260 public:
duke@435 261 JvmtiBreakpoints(void listener_fun(void *, address *));
duke@435 262 ~JvmtiBreakpoints();
duke@435 263
duke@435 264 int length();
duke@435 265 void oops_do(OopClosure* f);
duke@435 266 void gc_epilogue();
duke@435 267 void print();
duke@435 268
duke@435 269 int set(JvmtiBreakpoint& bp);
duke@435 270 int clear(JvmtiBreakpoint& bp);
duke@435 271 void clearall_in_class_at_safepoint(klassOop klass);
duke@435 272 void clearall();
duke@435 273 };
duke@435 274
duke@435 275
duke@435 276 ///////////////////////////////////////////////////////////////
duke@435 277 //
duke@435 278 // class JvmtiCurrentBreakpoints
duke@435 279 //
duke@435 280 // A static wrapper class for the JvmtiBreakpoints that provides:
duke@435 281 // 1. a fast inlined function to check if a byte code pointer is a breakpoint (is_breakpoint).
duke@435 282 // 2. a function for lazily creating the JvmtiBreakpoints class (this is not strictly necessary,
duke@435 283 // but I'm copying the code from JvmtiThreadState which needs to lazily initialize
duke@435 284 // JvmtiFramePops).
duke@435 285 // 3. An oops_do entry point for GC'ing the breakpoint array.
duke@435 286 //
duke@435 287
duke@435 288 class JvmtiCurrentBreakpoints : public AllStatic {
duke@435 289
duke@435 290 private:
duke@435 291
duke@435 292 // Current breakpoints, lazily initialized by get_jvmti_breakpoints();
duke@435 293 static JvmtiBreakpoints *_jvmti_breakpoints;
duke@435 294
duke@435 295 // NULL terminated cache of byte-code pointers corresponding to current breakpoints.
duke@435 296 // Updated only at safepoints (with listener_fun) when the cache is moved.
duke@435 297 // It exists only to make is_breakpoint fast.
duke@435 298 static address *_breakpoint_list;
duke@435 299 static inline void set_breakpoint_list(address *breakpoint_list) { _breakpoint_list = breakpoint_list; }
duke@435 300 static inline address *get_breakpoint_list() { return _breakpoint_list; }
duke@435 301
duke@435 302 // Listener for the GrowableCache in _jvmti_breakpoints, updates _breakpoint_list.
duke@435 303 static void listener_fun(void *this_obj, address *cache);
duke@435 304
duke@435 305 public:
duke@435 306 static void initialize();
duke@435 307 static void destroy();
duke@435 308
duke@435 309 // lazily create _jvmti_breakpoints and _breakpoint_list
duke@435 310 static JvmtiBreakpoints& get_jvmti_breakpoints();
duke@435 311
duke@435 312 // quickly test whether the bcp matches a cached breakpoint in the list
duke@435 313 static inline bool is_breakpoint(address bcp);
duke@435 314
duke@435 315 static void oops_do(OopClosure* f);
duke@435 316 static void gc_epilogue();
duke@435 317 };
duke@435 318
duke@435 319 // quickly test whether the bcp matches a cached breakpoint in the list
duke@435 320 bool JvmtiCurrentBreakpoints::is_breakpoint(address bcp) {
duke@435 321 address *bps = get_breakpoint_list();
duke@435 322 if (bps == NULL) return false;
duke@435 323 for ( ; (*bps) != NULL; bps++) {
duke@435 324 if ((*bps) == bcp) return true;
duke@435 325 }
duke@435 326 return false;
duke@435 327 }
duke@435 328
duke@435 329 ///////////////////////////////////////////////////////////////
duke@435 330 // The get/set local operations must only be done by the VM thread
duke@435 331 // because the interpreter version needs to access oop maps, which can
duke@435 332 // only safely be done by the VM thread
duke@435 333 //
duke@435 334 // I'm told that in 1.5 oop maps are now protected by a lock and
duke@435 335 // we could get rid of the VM op
duke@435 336 // However if the VM op is removed then the target thread must
duke@435 337 // be suspended AND a lock will be needed to prevent concurrent
duke@435 338 // setting of locals to the same java thread. This lock is needed
duke@435 339 // to prevent compiledVFrames from trying to add deferred updates
duke@435 340 // to the thread simultaneously.
duke@435 341 //
duke@435 342 class VM_GetOrSetLocal : public VM_Operation {
duke@435 343 private:
duke@435 344 JavaThread* _thread;
duke@435 345 JavaThread* _calling_thread;
duke@435 346 jint _depth;
duke@435 347 jint _index;
duke@435 348 BasicType _type;
duke@435 349 jvalue _value;
duke@435 350 javaVFrame* _jvf;
duke@435 351 bool _set;
duke@435 352
duke@435 353 jvmtiError _result;
duke@435 354
duke@435 355 vframe* get_vframe();
duke@435 356 javaVFrame* get_java_vframe();
duke@435 357 bool check_slot_type(javaVFrame* vf);
duke@435 358
duke@435 359 public:
duke@435 360 // Constructor for non-object getter
duke@435 361 VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type);
duke@435 362
duke@435 363 // Constructor for object or non-object setter
duke@435 364 VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value);
duke@435 365
duke@435 366 // Constructor for object getter
duke@435 367 VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth,
duke@435 368 int index);
duke@435 369
duke@435 370 VMOp_Type type() const { return VMOp_GetOrSetLocal; }
duke@435 371 jvalue value() { return _value; }
duke@435 372 jvmtiError result() { return _result; }
duke@435 373
duke@435 374 bool doit_prologue();
duke@435 375 void doit();
duke@435 376 bool allow_nested_vm_operations() const;
duke@435 377 const char* name() const { return "get/set locals"; }
duke@435 378
duke@435 379 // Check that the klass is assignable to a type with the given signature.
duke@435 380 static bool is_assignable(const char* ty_sign, Klass* klass, Thread* thread);
duke@435 381 };
duke@435 382
duke@435 383
duke@435 384 ///////////////////////////////////////////////////////////////
duke@435 385 //
duke@435 386 // class JvmtiSuspendControl
duke@435 387 //
duke@435 388 // Convenience routines for suspending and resuming threads.
duke@435 389 //
duke@435 390 // All attempts by JVMTI to suspend and resume threads must go through the
duke@435 391 // JvmtiSuspendControl interface.
duke@435 392 //
duke@435 393 // methods return true if successful
duke@435 394 //
duke@435 395 class JvmtiSuspendControl : public AllStatic {
duke@435 396 public:
duke@435 397 // suspend the thread, taking it to a safepoint
duke@435 398 static bool suspend(JavaThread *java_thread);
duke@435 399 // resume the thread
duke@435 400 static bool resume(JavaThread *java_thread);
duke@435 401
duke@435 402 static void print();
duke@435 403 };
duke@435 404
duke@435 405 // Utility macro that checks for NULL pointers:
duke@435 406 #define NULL_CHECK(X, Y) if ((X) == NULL) { return (Y); }

mercurial