src/share/vm/prims/jvmtiImpl.hpp

Mon, 10 Jan 2011 17:14:53 -0500

author
kamg
date
Mon, 10 Jan 2011 17:14:53 -0500
changeset 2445
7246a374a9f2
parent 2361
09b4dd4f152b
child 2467
9afee0b9fc1d
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

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

mercurial