src/share/vm/prims/jvmtiImpl.hpp

Tue, 08 Apr 2008 12:23:15 -0400

author
sgoldman
date
Tue, 08 Apr 2008 12:23:15 -0400
changeset 542
93b6525e3b82
parent 435
a61af66fc99e
child 1046
2f716c0acb64
permissions
-rw-r--r--

6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
Summary: Rewrite frame::safe_for_sender and friends to be safe for collector/analyzer
Reviewed-by: dcubed, kvn

duke@435 1 /*
duke@435 2 * Copyright 1999-2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any 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 JvmtiRawMonitor;
duke@435 30 class JvmtiBreakpoint;
duke@435 31 class JvmtiBreakpoints;
duke@435 32
duke@435 33
duke@435 34 ///////////////////////////////////////////////////////////////
duke@435 35 //
duke@435 36 // class GrowableCache, GrowableElement
duke@435 37 // Used by : JvmtiBreakpointCache
duke@435 38 // Used by JVMTI methods: none directly.
duke@435 39 //
duke@435 40 // GrowableCache is a permanent CHeap growable array of <GrowableElement *>
duke@435 41 //
duke@435 42 // In addition, the GrowableCache maintains a NULL terminated cache array of type address
duke@435 43 // that's created from the element array using the function:
duke@435 44 // address GrowableElement::getCacheValue().
duke@435 45 //
duke@435 46 // Whenever the GrowableArray changes size, the cache array gets recomputed into a new C_HEAP allocated
duke@435 47 // block of memory. Additionally, every time the cache changes its position in memory, the
duke@435 48 // void (*_listener_fun)(void *this_obj, address* cache)
duke@435 49 // gets called with the cache's new address. This gives the user of the GrowableCache a callback
duke@435 50 // to update its pointer to the address cache.
duke@435 51 //
duke@435 52
duke@435 53 class GrowableElement : public CHeapObj {
duke@435 54 public:
duke@435 55 virtual address getCacheValue() =0;
duke@435 56 virtual bool equals(GrowableElement* e) =0;
duke@435 57 virtual bool lessThan(GrowableElement *e)=0;
duke@435 58 virtual GrowableElement *clone() =0;
duke@435 59 virtual void oops_do(OopClosure* f) =0;
duke@435 60 };
duke@435 61
duke@435 62 class GrowableCache VALUE_OBJ_CLASS_SPEC {
duke@435 63
duke@435 64 private:
duke@435 65 // Object pointer passed into cache & listener functions.
duke@435 66 void *_this_obj;
duke@435 67
duke@435 68 // Array of elements in the collection
duke@435 69 GrowableArray<GrowableElement *> *_elements;
duke@435 70
duke@435 71 // Parallel array of cached values
duke@435 72 address *_cache;
duke@435 73
duke@435 74 // Listener for changes to the _cache field.
duke@435 75 // Called whenever the _cache field has it's value changed
duke@435 76 // (but NOT when cached elements are recomputed).
duke@435 77 void (*_listener_fun)(void *, address*);
duke@435 78
duke@435 79 static bool equals(void *, GrowableElement *);
duke@435 80
duke@435 81 // recache all elements after size change, notify listener
duke@435 82 void recache();
duke@435 83
duke@435 84 public:
duke@435 85 GrowableCache();
duke@435 86 ~GrowableCache();
duke@435 87
duke@435 88 void initialize(void *this_obj, void listener_fun(void *, address*) );
duke@435 89
duke@435 90 // number of elements in the collection
duke@435 91 int length();
duke@435 92 // get the value of the index element in the collection
duke@435 93 GrowableElement* at(int index);
duke@435 94 // find the index of the element, -1 if it doesn't exist
duke@435 95 int find(GrowableElement* e);
duke@435 96 // append a copy of the element to the end of the collection, notify listener
duke@435 97 void append(GrowableElement* e);
duke@435 98 // insert a copy of the element using lessthan(), notify listener
duke@435 99 void insert(GrowableElement* e);
duke@435 100 // remove the element at index, notify listener
duke@435 101 void remove (int index);
duke@435 102 // clear out all elements and release all heap space, notify listener
duke@435 103 void clear();
duke@435 104 // apply f to every element and update the cache
duke@435 105 void oops_do(OopClosure* f);
duke@435 106 void gc_epilogue();
duke@435 107 };
duke@435 108
duke@435 109
duke@435 110 ///////////////////////////////////////////////////////////////
duke@435 111 //
duke@435 112 // class JvmtiBreakpointCache
duke@435 113 // Used by : JvmtiBreakpoints
duke@435 114 // Used by JVMTI methods: none directly.
duke@435 115 // Note : typesafe wrapper for GrowableCache of JvmtiBreakpoint
duke@435 116 //
duke@435 117
duke@435 118 class JvmtiBreakpointCache : public CHeapObj {
duke@435 119
duke@435 120 private:
duke@435 121 GrowableCache _cache;
duke@435 122
duke@435 123 public:
duke@435 124 JvmtiBreakpointCache() {}
duke@435 125 ~JvmtiBreakpointCache() {}
duke@435 126
duke@435 127 void initialize(void *this_obj, void listener_fun(void *, address*) ) {
duke@435 128 _cache.initialize(this_obj,listener_fun);
duke@435 129 }
duke@435 130
duke@435 131 int length() { return _cache.length(); }
duke@435 132 JvmtiBreakpoint& at(int index) { return (JvmtiBreakpoint&) *(_cache.at(index)); }
duke@435 133 int find(JvmtiBreakpoint& e) { return _cache.find((GrowableElement *) &e); }
duke@435 134 void append(JvmtiBreakpoint& e) { _cache.append((GrowableElement *) &e); }
duke@435 135 void remove (int index) { _cache.remove(index); }
duke@435 136 void clear() { _cache.clear(); }
duke@435 137 void oops_do(OopClosure* f) { _cache.oops_do(f); }
duke@435 138 void gc_epilogue() { _cache.gc_epilogue(); }
duke@435 139 };
duke@435 140
duke@435 141
duke@435 142 ///////////////////////////////////////////////////////////////
duke@435 143 //
duke@435 144 // class JvmtiBreakpoint
duke@435 145 // Used by : JvmtiBreakpoints
duke@435 146 // Used by JVMTI methods: SetBreakpoint, ClearBreakpoint, ClearAllBreakpoints
duke@435 147 // Note: Extends GrowableElement for use in a GrowableCache
duke@435 148 //
duke@435 149 // A JvmtiBreakpoint describes a location (class, method, bci) to break at.
duke@435 150 //
duke@435 151
duke@435 152 typedef void (methodOopDesc::*method_action)(int _bci);
duke@435 153
duke@435 154 class JvmtiBreakpoint : public GrowableElement {
duke@435 155 private:
duke@435 156 methodOop _method;
duke@435 157 int _bci;
duke@435 158 Bytecodes::Code _orig_bytecode;
duke@435 159
duke@435 160 public:
duke@435 161 JvmtiBreakpoint();
duke@435 162 JvmtiBreakpoint(methodOop m_method, jlocation location);
duke@435 163 bool equals(JvmtiBreakpoint& bp);
duke@435 164 bool lessThan(JvmtiBreakpoint &bp);
duke@435 165 void copy(JvmtiBreakpoint& bp);
duke@435 166 bool is_valid();
duke@435 167 address getBcp();
duke@435 168 void each_method_version_do(method_action meth_act);
duke@435 169 void set();
duke@435 170 void clear();
duke@435 171 void print();
duke@435 172
duke@435 173 methodOop method() { return _method; }
duke@435 174
duke@435 175 // GrowableElement implementation
duke@435 176 address getCacheValue() { return getBcp(); }
duke@435 177 bool lessThan(GrowableElement* e) { Unimplemented(); return false; }
duke@435 178 bool equals(GrowableElement* e) { return equals((JvmtiBreakpoint&) *e); }
duke@435 179 void oops_do(OopClosure* f) { f->do_oop((oop *) &_method); }
duke@435 180 GrowableElement *clone() {
duke@435 181 JvmtiBreakpoint *bp = new JvmtiBreakpoint();
duke@435 182 bp->copy(*this);
duke@435 183 return bp;
duke@435 184 }
duke@435 185 };
duke@435 186
duke@435 187
duke@435 188 ///////////////////////////////////////////////////////////////
duke@435 189 //
duke@435 190 // class VM_ChangeBreakpoints
duke@435 191 // Used by : JvmtiBreakpoints
duke@435 192 // Used by JVMTI methods: none directly.
duke@435 193 // Note: A Helper class.
duke@435 194 //
duke@435 195 // VM_ChangeBreakpoints implements a VM_Operation for ALL modifications to the JvmtiBreakpoints class.
duke@435 196 //
duke@435 197
duke@435 198 class VM_ChangeBreakpoints : public VM_Operation {
duke@435 199 private:
duke@435 200 JvmtiBreakpoints* _breakpoints;
duke@435 201 int _operation;
duke@435 202 JvmtiBreakpoint* _bp;
duke@435 203
duke@435 204 public:
duke@435 205 enum { SET_BREAKPOINT=0, CLEAR_BREAKPOINT=1, CLEAR_ALL_BREAKPOINT=2 };
duke@435 206
duke@435 207 VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation) {
duke@435 208 _breakpoints = breakpoints;
duke@435 209 _bp = NULL;
duke@435 210 _operation = operation;
duke@435 211 assert(breakpoints != NULL, "breakpoints != NULL");
duke@435 212 assert(operation == CLEAR_ALL_BREAKPOINT, "unknown breakpoint operation");
duke@435 213 }
duke@435 214 VM_ChangeBreakpoints(JvmtiBreakpoints* breakpoints, int operation, JvmtiBreakpoint *bp) {
duke@435 215 _breakpoints = breakpoints;
duke@435 216 _bp = bp;
duke@435 217 _operation = operation;
duke@435 218 assert(breakpoints != NULL, "breakpoints != NULL");
duke@435 219 assert(bp != NULL, "bp != NULL");
duke@435 220 assert(operation == SET_BREAKPOINT || operation == CLEAR_BREAKPOINT , "unknown breakpoint operation");
duke@435 221 }
duke@435 222
duke@435 223 VMOp_Type type() const { return VMOp_ChangeBreakpoints; }
duke@435 224 void doit();
duke@435 225 void oops_do(OopClosure* f);
duke@435 226 };
duke@435 227
duke@435 228
duke@435 229 ///////////////////////////////////////////////////////////////
duke@435 230 //
duke@435 231 // class JvmtiBreakpoints
duke@435 232 // Used by : JvmtiCurrentBreakpoints
duke@435 233 // Used by JVMTI methods: none directly
duke@435 234 // Note: A Helper class
duke@435 235 //
duke@435 236 // JvmtiBreakpoints is a GrowableCache of JvmtiBreakpoint.
duke@435 237 // All changes to the GrowableCache occur at a safepoint using VM_ChangeBreakpoints.
duke@435 238 //
duke@435 239 // Because _bps is only modified at safepoints, its possible to always use the
duke@435 240 // cached byte code pointers from _bps without doing any synchronization (see JvmtiCurrentBreakpoints).
duke@435 241 //
duke@435 242 // It would be possible to make JvmtiBreakpoints a static class, but I've made it
duke@435 243 // CHeap allocated to emphasize its similarity to JvmtiFramePops.
duke@435 244 //
duke@435 245
duke@435 246 class JvmtiBreakpoints : public CHeapObj {
duke@435 247 private:
duke@435 248
duke@435 249 JvmtiBreakpointCache _bps;
duke@435 250
duke@435 251 // These should only be used by VM_ChangeBreakpoints
duke@435 252 // to insure they only occur at safepoints.
duke@435 253 // Todo: add checks for safepoint
duke@435 254 friend class VM_ChangeBreakpoints;
duke@435 255 void set_at_safepoint(JvmtiBreakpoint& bp);
duke@435 256 void clear_at_safepoint(JvmtiBreakpoint& bp);
duke@435 257 void clearall_at_safepoint();
duke@435 258
duke@435 259 static void do_element(GrowableElement *e);
duke@435 260
duke@435 261 public:
duke@435 262 JvmtiBreakpoints(void listener_fun(void *, address *));
duke@435 263 ~JvmtiBreakpoints();
duke@435 264
duke@435 265 int length();
duke@435 266 void oops_do(OopClosure* f);
duke@435 267 void gc_epilogue();
duke@435 268 void print();
duke@435 269
duke@435 270 int set(JvmtiBreakpoint& bp);
duke@435 271 int clear(JvmtiBreakpoint& bp);
duke@435 272 void clearall_in_class_at_safepoint(klassOop klass);
duke@435 273 void clearall();
duke@435 274 };
duke@435 275
duke@435 276
duke@435 277 ///////////////////////////////////////////////////////////////
duke@435 278 //
duke@435 279 // class JvmtiCurrentBreakpoints
duke@435 280 //
duke@435 281 // A static wrapper class for the JvmtiBreakpoints that provides:
duke@435 282 // 1. a fast inlined function to check if a byte code pointer is a breakpoint (is_breakpoint).
duke@435 283 // 2. a function for lazily creating the JvmtiBreakpoints class (this is not strictly necessary,
duke@435 284 // but I'm copying the code from JvmtiThreadState which needs to lazily initialize
duke@435 285 // JvmtiFramePops).
duke@435 286 // 3. An oops_do entry point for GC'ing the breakpoint array.
duke@435 287 //
duke@435 288
duke@435 289 class JvmtiCurrentBreakpoints : public AllStatic {
duke@435 290
duke@435 291 private:
duke@435 292
duke@435 293 // Current breakpoints, lazily initialized by get_jvmti_breakpoints();
duke@435 294 static JvmtiBreakpoints *_jvmti_breakpoints;
duke@435 295
duke@435 296 // NULL terminated cache of byte-code pointers corresponding to current breakpoints.
duke@435 297 // Updated only at safepoints (with listener_fun) when the cache is moved.
duke@435 298 // It exists only to make is_breakpoint fast.
duke@435 299 static address *_breakpoint_list;
duke@435 300 static inline void set_breakpoint_list(address *breakpoint_list) { _breakpoint_list = breakpoint_list; }
duke@435 301 static inline address *get_breakpoint_list() { return _breakpoint_list; }
duke@435 302
duke@435 303 // Listener for the GrowableCache in _jvmti_breakpoints, updates _breakpoint_list.
duke@435 304 static void listener_fun(void *this_obj, address *cache);
duke@435 305
duke@435 306 public:
duke@435 307 static void initialize();
duke@435 308 static void destroy();
duke@435 309
duke@435 310 // lazily create _jvmti_breakpoints and _breakpoint_list
duke@435 311 static JvmtiBreakpoints& get_jvmti_breakpoints();
duke@435 312
duke@435 313 // quickly test whether the bcp matches a cached breakpoint in the list
duke@435 314 static inline bool is_breakpoint(address bcp);
duke@435 315
duke@435 316 static void oops_do(OopClosure* f);
duke@435 317 static void gc_epilogue();
duke@435 318 };
duke@435 319
duke@435 320 // quickly test whether the bcp matches a cached breakpoint in the list
duke@435 321 bool JvmtiCurrentBreakpoints::is_breakpoint(address bcp) {
duke@435 322 address *bps = get_breakpoint_list();
duke@435 323 if (bps == NULL) return false;
duke@435 324 for ( ; (*bps) != NULL; bps++) {
duke@435 325 if ((*bps) == bcp) return true;
duke@435 326 }
duke@435 327 return false;
duke@435 328 }
duke@435 329
duke@435 330
duke@435 331 ///////////////////////////////////////////////////////////////
duke@435 332 //
duke@435 333 // class JvmtiRawMonitor
duke@435 334 //
duke@435 335 // Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
duke@435 336 //
duke@435 337 // Wrapper for ObjectMonitor class that saves the Monitor's name
duke@435 338 //
duke@435 339
duke@435 340 class JvmtiRawMonitor : public ObjectMonitor {
duke@435 341 private:
duke@435 342 int _magic;
duke@435 343 char * _name;
duke@435 344 // JVMTI_RM_MAGIC is set in contructor and unset in destructor.
duke@435 345 enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
duke@435 346
duke@435 347 public:
duke@435 348 JvmtiRawMonitor(const char *name);
duke@435 349 ~JvmtiRawMonitor();
duke@435 350 int magic() { return _magic; }
duke@435 351 const char *get_name() { return _name; }
duke@435 352 bool is_valid() { return _magic == JVMTI_RM_MAGIC; }
duke@435 353 };
duke@435 354
duke@435 355 // Onload pending raw monitors
duke@435 356 // Class is used to cache onload or onstart monitor enter
duke@435 357 // which will transition into real monitor when
duke@435 358 // VM is fully initialized.
duke@435 359 class JvmtiPendingMonitors : public AllStatic {
duke@435 360
duke@435 361 private:
duke@435 362 static GrowableArray<JvmtiRawMonitor*> *_monitors; // Cache raw monitor enter
duke@435 363
duke@435 364 inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; }
duke@435 365
duke@435 366 static void dispose() {
duke@435 367 delete monitors();
duke@435 368 }
duke@435 369
duke@435 370 public:
duke@435 371 static void enter(JvmtiRawMonitor *monitor) {
duke@435 372 monitors()->append(monitor);
duke@435 373 }
duke@435 374
duke@435 375 static int count() {
duke@435 376 return monitors()->length();
duke@435 377 }
duke@435 378
duke@435 379 static void destroy(JvmtiRawMonitor *monitor) {
duke@435 380 while (monitors()->contains(monitor)) {
duke@435 381 monitors()->remove(monitor);
duke@435 382 }
duke@435 383 }
duke@435 384
duke@435 385 // Return false if monitor is not found in the list.
duke@435 386 static bool exit(JvmtiRawMonitor *monitor) {
duke@435 387 if (monitors()->contains(monitor)) {
duke@435 388 monitors()->remove(monitor);
duke@435 389 return true;
duke@435 390 } else {
duke@435 391 return false;
duke@435 392 }
duke@435 393 }
duke@435 394
duke@435 395 static void transition_raw_monitors();
duke@435 396 };
duke@435 397
duke@435 398
duke@435 399
duke@435 400 ///////////////////////////////////////////////////////////////
duke@435 401 // The get/set local operations must only be done by the VM thread
duke@435 402 // because the interpreter version needs to access oop maps, which can
duke@435 403 // only safely be done by the VM thread
duke@435 404 //
duke@435 405 // I'm told that in 1.5 oop maps are now protected by a lock and
duke@435 406 // we could get rid of the VM op
duke@435 407 // However if the VM op is removed then the target thread must
duke@435 408 // be suspended AND a lock will be needed to prevent concurrent
duke@435 409 // setting of locals to the same java thread. This lock is needed
duke@435 410 // to prevent compiledVFrames from trying to add deferred updates
duke@435 411 // to the thread simultaneously.
duke@435 412 //
duke@435 413 class VM_GetOrSetLocal : public VM_Operation {
duke@435 414 private:
duke@435 415 JavaThread* _thread;
duke@435 416 JavaThread* _calling_thread;
duke@435 417 jint _depth;
duke@435 418 jint _index;
duke@435 419 BasicType _type;
duke@435 420 jvalue _value;
duke@435 421 javaVFrame* _jvf;
duke@435 422 bool _set;
duke@435 423
duke@435 424 jvmtiError _result;
duke@435 425
duke@435 426 vframe* get_vframe();
duke@435 427 javaVFrame* get_java_vframe();
duke@435 428 bool check_slot_type(javaVFrame* vf);
duke@435 429
duke@435 430 public:
duke@435 431 // Constructor for non-object getter
duke@435 432 VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type);
duke@435 433
duke@435 434 // Constructor for object or non-object setter
duke@435 435 VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value);
duke@435 436
duke@435 437 // Constructor for object getter
duke@435 438 VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth,
duke@435 439 int index);
duke@435 440
duke@435 441 VMOp_Type type() const { return VMOp_GetOrSetLocal; }
duke@435 442 jvalue value() { return _value; }
duke@435 443 jvmtiError result() { return _result; }
duke@435 444
duke@435 445 bool doit_prologue();
duke@435 446 void doit();
duke@435 447 bool allow_nested_vm_operations() const;
duke@435 448 const char* name() const { return "get/set locals"; }
duke@435 449
duke@435 450 // Check that the klass is assignable to a type with the given signature.
duke@435 451 static bool is_assignable(const char* ty_sign, Klass* klass, Thread* thread);
duke@435 452 };
duke@435 453
duke@435 454
duke@435 455 ///////////////////////////////////////////////////////////////
duke@435 456 //
duke@435 457 // class JvmtiSuspendControl
duke@435 458 //
duke@435 459 // Convenience routines for suspending and resuming threads.
duke@435 460 //
duke@435 461 // All attempts by JVMTI to suspend and resume threads must go through the
duke@435 462 // JvmtiSuspendControl interface.
duke@435 463 //
duke@435 464 // methods return true if successful
duke@435 465 //
duke@435 466 class JvmtiSuspendControl : public AllStatic {
duke@435 467 public:
duke@435 468 // suspend the thread, taking it to a safepoint
duke@435 469 static bool suspend(JavaThread *java_thread);
duke@435 470 // resume the thread
duke@435 471 static bool resume(JavaThread *java_thread);
duke@435 472
duke@435 473 static void print();
duke@435 474 };
duke@435 475
duke@435 476 // Utility macro that checks for NULL pointers:
duke@435 477 #define NULL_CHECK(X, Y) if ((X) == NULL) { return (Y); }

mercurial