Tue, 17 Oct 2017 12:58:25 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_PRIMS_JVMTIIMPL_HPP |
aoqi@0 | 26 | #define SHARE_VM_PRIMS_JVMTIIMPL_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "classfile/systemDictionary.hpp" |
aoqi@0 | 29 | #include "jvmtifiles/jvmti.h" |
aoqi@0 | 30 | #include "oops/objArrayOop.hpp" |
aoqi@0 | 31 | #include "prims/jvmtiEnvThreadState.hpp" |
aoqi@0 | 32 | #include "prims/jvmtiEventController.hpp" |
aoqi@0 | 33 | #include "prims/jvmtiTrace.hpp" |
aoqi@0 | 34 | #include "prims/jvmtiUtil.hpp" |
aoqi@0 | 35 | #include "runtime/stackValueCollection.hpp" |
aoqi@0 | 36 | #include "runtime/vm_operations.hpp" |
aoqi@0 | 37 | |
aoqi@0 | 38 | // |
aoqi@0 | 39 | // Forward Declarations |
aoqi@0 | 40 | // |
aoqi@0 | 41 | |
aoqi@0 | 42 | class JvmtiBreakpoint; |
aoqi@0 | 43 | class JvmtiBreakpoints; |
aoqi@0 | 44 | |
aoqi@0 | 45 | |
aoqi@0 | 46 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 47 | // |
aoqi@0 | 48 | // class GrowableCache, GrowableElement |
aoqi@0 | 49 | // Used by : JvmtiBreakpointCache |
aoqi@0 | 50 | // Used by JVMTI methods: none directly. |
aoqi@0 | 51 | // |
aoqi@0 | 52 | // GrowableCache is a permanent CHeap growable array of <GrowableElement *> |
aoqi@0 | 53 | // |
aoqi@0 | 54 | // In addition, the GrowableCache maintains a NULL terminated cache array of type address |
aoqi@0 | 55 | // that's created from the element array using the function: |
aoqi@0 | 56 | // address GrowableElement::getCacheValue(). |
aoqi@0 | 57 | // |
aoqi@0 | 58 | // Whenever the GrowableArray changes size, the cache array gets recomputed into a new C_HEAP allocated |
aoqi@0 | 59 | // block of memory. Additionally, every time the cache changes its position in memory, the |
aoqi@0 | 60 | // void (*_listener_fun)(void *this_obj, address* cache) |
aoqi@0 | 61 | // gets called with the cache's new address. This gives the user of the GrowableCache a callback |
aoqi@0 | 62 | // to update its pointer to the address cache. |
aoqi@0 | 63 | // |
aoqi@0 | 64 | |
aoqi@0 | 65 | class GrowableElement : public CHeapObj<mtInternal> { |
aoqi@0 | 66 | public: |
aoqi@0 | 67 | virtual address getCacheValue() =0; |
aoqi@0 | 68 | virtual bool equals(GrowableElement* e) =0; |
aoqi@0 | 69 | virtual bool lessThan(GrowableElement *e)=0; |
aoqi@0 | 70 | virtual GrowableElement *clone() =0; |
aoqi@0 | 71 | virtual void oops_do(OopClosure* f) =0; |
aoqi@0 | 72 | virtual void metadata_do(void f(Metadata*)) =0; |
aoqi@0 | 73 | }; |
aoqi@0 | 74 | |
aoqi@0 | 75 | class GrowableCache VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 76 | |
aoqi@0 | 77 | private: |
aoqi@0 | 78 | // Object pointer passed into cache & listener functions. |
aoqi@0 | 79 | void *_this_obj; |
aoqi@0 | 80 | |
aoqi@0 | 81 | // Array of elements in the collection |
aoqi@0 | 82 | GrowableArray<GrowableElement *> *_elements; |
aoqi@0 | 83 | |
aoqi@0 | 84 | // Parallel array of cached values |
aoqi@0 | 85 | address *_cache; |
aoqi@0 | 86 | |
aoqi@0 | 87 | // Listener for changes to the _cache field. |
aoqi@0 | 88 | // Called whenever the _cache field has it's value changed |
aoqi@0 | 89 | // (but NOT when cached elements are recomputed). |
aoqi@0 | 90 | void (*_listener_fun)(void *, address*); |
aoqi@0 | 91 | |
aoqi@0 | 92 | static bool equals(void *, GrowableElement *); |
aoqi@0 | 93 | |
aoqi@0 | 94 | // recache all elements after size change, notify listener |
aoqi@0 | 95 | void recache(); |
aoqi@0 | 96 | |
aoqi@0 | 97 | public: |
aoqi@0 | 98 | GrowableCache(); |
aoqi@0 | 99 | ~GrowableCache(); |
aoqi@0 | 100 | |
aoqi@0 | 101 | void initialize(void *this_obj, void listener_fun(void *, address*) ); |
aoqi@0 | 102 | |
aoqi@0 | 103 | // number of elements in the collection |
aoqi@0 | 104 | int length(); |
aoqi@0 | 105 | // get the value of the index element in the collection |
aoqi@0 | 106 | GrowableElement* at(int index); |
aoqi@0 | 107 | // find the index of the element, -1 if it doesn't exist |
aoqi@0 | 108 | int find(GrowableElement* e); |
aoqi@0 | 109 | // append a copy of the element to the end of the collection, notify listener |
aoqi@0 | 110 | void append(GrowableElement* e); |
aoqi@0 | 111 | // insert a copy of the element using lessthan(), notify listener |
aoqi@0 | 112 | void insert(GrowableElement* e); |
aoqi@0 | 113 | // remove the element at index, notify listener |
aoqi@0 | 114 | void remove (int index); |
aoqi@0 | 115 | // clear out all elements and release all heap space, notify listener |
aoqi@0 | 116 | void clear(); |
aoqi@0 | 117 | // apply f to every element and update the cache |
aoqi@0 | 118 | void oops_do(OopClosure* f); |
aoqi@0 | 119 | // walk metadata to preserve for RedefineClasses |
aoqi@0 | 120 | void metadata_do(void f(Metadata*)); |
aoqi@0 | 121 | // update the cache after a full gc |
aoqi@0 | 122 | void gc_epilogue(); |
aoqi@0 | 123 | }; |
aoqi@0 | 124 | |
aoqi@0 | 125 | |
aoqi@0 | 126 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 127 | // |
aoqi@0 | 128 | // class JvmtiBreakpointCache |
aoqi@0 | 129 | // Used by : JvmtiBreakpoints |
aoqi@0 | 130 | // Used by JVMTI methods: none directly. |
aoqi@0 | 131 | // Note : typesafe wrapper for GrowableCache of JvmtiBreakpoint |
aoqi@0 | 132 | // |
aoqi@0 | 133 | |
aoqi@0 | 134 | class JvmtiBreakpointCache : public CHeapObj<mtInternal> { |
aoqi@0 | 135 | |
aoqi@0 | 136 | private: |
aoqi@0 | 137 | GrowableCache _cache; |
aoqi@0 | 138 | |
aoqi@0 | 139 | public: |
aoqi@0 | 140 | JvmtiBreakpointCache() {} |
aoqi@0 | 141 | ~JvmtiBreakpointCache() {} |
aoqi@0 | 142 | |
aoqi@0 | 143 | void initialize(void *this_obj, void listener_fun(void *, address*) ) { |
aoqi@0 | 144 | _cache.initialize(this_obj,listener_fun); |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | int length() { return _cache.length(); } |
aoqi@0 | 148 | JvmtiBreakpoint& at(int index) { return (JvmtiBreakpoint&) *(_cache.at(index)); } |
aoqi@0 | 149 | int find(JvmtiBreakpoint& e) { return _cache.find((GrowableElement *) &e); } |
aoqi@0 | 150 | void append(JvmtiBreakpoint& e) { _cache.append((GrowableElement *) &e); } |
aoqi@0 | 151 | void remove (int index) { _cache.remove(index); } |
aoqi@0 | 152 | void clear() { _cache.clear(); } |
aoqi@0 | 153 | void oops_do(OopClosure* f) { _cache.oops_do(f); } |
aoqi@0 | 154 | void metadata_do(void f(Metadata*)) { _cache.metadata_do(f); } |
aoqi@0 | 155 | void gc_epilogue() { _cache.gc_epilogue(); } |
aoqi@0 | 156 | }; |
aoqi@0 | 157 | |
aoqi@0 | 158 | |
aoqi@0 | 159 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 160 | // |
aoqi@0 | 161 | // class JvmtiBreakpoint |
aoqi@0 | 162 | // Used by : JvmtiBreakpoints |
aoqi@0 | 163 | // Used by JVMTI methods: SetBreakpoint, ClearBreakpoint, ClearAllBreakpoints |
aoqi@0 | 164 | // Note: Extends GrowableElement for use in a GrowableCache |
aoqi@0 | 165 | // |
aoqi@0 | 166 | // A JvmtiBreakpoint describes a location (class, method, bci) to break at. |
aoqi@0 | 167 | // |
aoqi@0 | 168 | |
aoqi@0 | 169 | typedef void (Method::*method_action)(int _bci); |
aoqi@0 | 170 | |
aoqi@0 | 171 | class JvmtiBreakpoint : public GrowableElement { |
aoqi@0 | 172 | private: |
aoqi@0 | 173 | Method* _method; |
aoqi@0 | 174 | int _bci; |
aoqi@0 | 175 | Bytecodes::Code _orig_bytecode; |
aoqi@0 | 176 | oop _class_holder; // keeps _method memory from being deallocated |
aoqi@0 | 177 | |
aoqi@0 | 178 | public: |
aoqi@0 | 179 | JvmtiBreakpoint(); |
aoqi@0 | 180 | JvmtiBreakpoint(Method* m_method, jlocation location); |
aoqi@0 | 181 | bool equals(JvmtiBreakpoint& bp); |
aoqi@0 | 182 | bool lessThan(JvmtiBreakpoint &bp); |
aoqi@0 | 183 | void copy(JvmtiBreakpoint& bp); |
aoqi@0 | 184 | bool is_valid(); |
aoqi@0 | 185 | address getBcp(); |
aoqi@0 | 186 | void each_method_version_do(method_action meth_act); |
aoqi@0 | 187 | void set(); |
aoqi@0 | 188 | void clear(); |
aoqi@0 | 189 | void print(); |
aoqi@0 | 190 | |
aoqi@0 | 191 | Method* method() { return _method; } |
aoqi@0 | 192 | |
aoqi@0 | 193 | // GrowableElement implementation |
aoqi@0 | 194 | address getCacheValue() { return getBcp(); } |
aoqi@0 | 195 | bool lessThan(GrowableElement* e) { Unimplemented(); return false; } |
aoqi@0 | 196 | bool equals(GrowableElement* e) { return equals((JvmtiBreakpoint&) *e); } |
aoqi@0 | 197 | void oops_do(OopClosure* f) { |
aoqi@0 | 198 | // Mark the method loader as live so the Method* class loader doesn't get |
aoqi@0 | 199 | // unloaded and Method* memory reclaimed. |
aoqi@0 | 200 | f->do_oop(&_class_holder); |
aoqi@0 | 201 | } |
aoqi@0 | 202 | void metadata_do(void f(Metadata*)) { |
aoqi@0 | 203 | // walk metadata to preserve for RedefineClasses |
aoqi@0 | 204 | f(_method); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | |
aoqi@0 | 207 | GrowableElement *clone() { |
aoqi@0 | 208 | JvmtiBreakpoint *bp = new JvmtiBreakpoint(); |
aoqi@0 | 209 | bp->copy(*this); |
aoqi@0 | 210 | return bp; |
aoqi@0 | 211 | } |
aoqi@0 | 212 | }; |
aoqi@0 | 213 | |
aoqi@0 | 214 | |
aoqi@0 | 215 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 216 | // |
aoqi@0 | 217 | // class JvmtiBreakpoints |
aoqi@0 | 218 | // Used by : JvmtiCurrentBreakpoints |
aoqi@0 | 219 | // Used by JVMTI methods: none directly |
aoqi@0 | 220 | // Note: A Helper class |
aoqi@0 | 221 | // |
aoqi@0 | 222 | // JvmtiBreakpoints is a GrowableCache of JvmtiBreakpoint. |
aoqi@0 | 223 | // All changes to the GrowableCache occur at a safepoint using VM_ChangeBreakpoints. |
aoqi@0 | 224 | // |
aoqi@0 | 225 | // Because _bps is only modified at safepoints, its possible to always use the |
aoqi@0 | 226 | // cached byte code pointers from _bps without doing any synchronization (see JvmtiCurrentBreakpoints). |
aoqi@0 | 227 | // |
aoqi@0 | 228 | // It would be possible to make JvmtiBreakpoints a static class, but I've made it |
aoqi@0 | 229 | // CHeap allocated to emphasize its similarity to JvmtiFramePops. |
aoqi@0 | 230 | // |
aoqi@0 | 231 | |
aoqi@0 | 232 | class JvmtiBreakpoints : public CHeapObj<mtInternal> { |
aoqi@0 | 233 | private: |
aoqi@0 | 234 | |
aoqi@0 | 235 | JvmtiBreakpointCache _bps; |
aoqi@0 | 236 | |
aoqi@0 | 237 | // These should only be used by VM_ChangeBreakpoints |
aoqi@0 | 238 | // to insure they only occur at safepoints. |
aoqi@0 | 239 | // Todo: add checks for safepoint |
aoqi@0 | 240 | friend class VM_ChangeBreakpoints; |
aoqi@0 | 241 | void set_at_safepoint(JvmtiBreakpoint& bp); |
aoqi@0 | 242 | void clear_at_safepoint(JvmtiBreakpoint& bp); |
aoqi@0 | 243 | |
aoqi@0 | 244 | static void do_element(GrowableElement *e); |
aoqi@0 | 245 | |
aoqi@0 | 246 | public: |
aoqi@0 | 247 | JvmtiBreakpoints(void listener_fun(void *, address *)); |
aoqi@0 | 248 | ~JvmtiBreakpoints(); |
aoqi@0 | 249 | |
aoqi@0 | 250 | int length(); |
aoqi@0 | 251 | void oops_do(OopClosure* f); |
aoqi@0 | 252 | void metadata_do(void f(Metadata*)); |
aoqi@0 | 253 | void print(); |
aoqi@0 | 254 | |
aoqi@0 | 255 | int set(JvmtiBreakpoint& bp); |
aoqi@0 | 256 | int clear(JvmtiBreakpoint& bp); |
aoqi@0 | 257 | void clearall_in_class_at_safepoint(Klass* klass); |
aoqi@0 | 258 | void gc_epilogue(); |
aoqi@0 | 259 | }; |
aoqi@0 | 260 | |
aoqi@0 | 261 | |
aoqi@0 | 262 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 263 | // |
aoqi@0 | 264 | // class JvmtiCurrentBreakpoints |
aoqi@0 | 265 | // |
aoqi@0 | 266 | // A static wrapper class for the JvmtiBreakpoints that provides: |
aoqi@0 | 267 | // 1. a fast inlined function to check if a byte code pointer is a breakpoint (is_breakpoint). |
aoqi@0 | 268 | // 2. a function for lazily creating the JvmtiBreakpoints class (this is not strictly necessary, |
aoqi@0 | 269 | // but I'm copying the code from JvmtiThreadState which needs to lazily initialize |
aoqi@0 | 270 | // JvmtiFramePops). |
aoqi@0 | 271 | // 3. An oops_do entry point for GC'ing the breakpoint array. |
aoqi@0 | 272 | // |
aoqi@0 | 273 | |
aoqi@0 | 274 | class JvmtiCurrentBreakpoints : public AllStatic { |
aoqi@0 | 275 | |
aoqi@0 | 276 | private: |
aoqi@0 | 277 | |
aoqi@0 | 278 | // Current breakpoints, lazily initialized by get_jvmti_breakpoints(); |
aoqi@0 | 279 | static JvmtiBreakpoints *_jvmti_breakpoints; |
aoqi@0 | 280 | |
aoqi@0 | 281 | // NULL terminated cache of byte-code pointers corresponding to current breakpoints. |
aoqi@0 | 282 | // Updated only at safepoints (with listener_fun) when the cache is moved. |
aoqi@0 | 283 | // It exists only to make is_breakpoint fast. |
aoqi@0 | 284 | static address *_breakpoint_list; |
aoqi@0 | 285 | static inline void set_breakpoint_list(address *breakpoint_list) { _breakpoint_list = breakpoint_list; } |
aoqi@0 | 286 | static inline address *get_breakpoint_list() { return _breakpoint_list; } |
aoqi@0 | 287 | |
aoqi@0 | 288 | // Listener for the GrowableCache in _jvmti_breakpoints, updates _breakpoint_list. |
aoqi@0 | 289 | static void listener_fun(void *this_obj, address *cache); |
aoqi@0 | 290 | |
aoqi@0 | 291 | public: |
aoqi@0 | 292 | static void initialize(); |
aoqi@0 | 293 | static void destroy(); |
aoqi@0 | 294 | |
aoqi@0 | 295 | // lazily create _jvmti_breakpoints and _breakpoint_list |
aoqi@0 | 296 | static JvmtiBreakpoints& get_jvmti_breakpoints(); |
aoqi@0 | 297 | |
aoqi@0 | 298 | // quickly test whether the bcp matches a cached breakpoint in the list |
aoqi@0 | 299 | static inline bool is_breakpoint(address bcp); |
aoqi@0 | 300 | |
aoqi@0 | 301 | static void oops_do(OopClosure* f); |
aoqi@0 | 302 | static void metadata_do(void f(Metadata*)) NOT_JVMTI_RETURN; |
aoqi@0 | 303 | static void gc_epilogue(); |
aoqi@0 | 304 | }; |
aoqi@0 | 305 | |
aoqi@0 | 306 | // quickly test whether the bcp matches a cached breakpoint in the list |
aoqi@0 | 307 | bool JvmtiCurrentBreakpoints::is_breakpoint(address bcp) { |
aoqi@0 | 308 | address *bps = get_breakpoint_list(); |
aoqi@0 | 309 | if (bps == NULL) return false; |
aoqi@0 | 310 | for ( ; (*bps) != NULL; bps++) { |
aoqi@0 | 311 | if ((*bps) == bcp) return true; |
aoqi@0 | 312 | } |
aoqi@0 | 313 | return false; |
aoqi@0 | 314 | } |
aoqi@0 | 315 | |
aoqi@0 | 316 | |
aoqi@0 | 317 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 318 | // |
aoqi@0 | 319 | // class VM_ChangeBreakpoints |
aoqi@0 | 320 | // Used by : JvmtiBreakpoints |
aoqi@0 | 321 | // Used by JVMTI methods: none directly. |
aoqi@0 | 322 | // Note: A Helper class. |
aoqi@0 | 323 | // |
aoqi@0 | 324 | // VM_ChangeBreakpoints implements a VM_Operation for ALL modifications to the JvmtiBreakpoints class. |
aoqi@0 | 325 | // |
aoqi@0 | 326 | |
aoqi@0 | 327 | class VM_ChangeBreakpoints : public VM_Operation { |
aoqi@0 | 328 | private: |
aoqi@0 | 329 | JvmtiBreakpoints* _breakpoints; |
aoqi@0 | 330 | int _operation; |
aoqi@0 | 331 | JvmtiBreakpoint* _bp; |
aoqi@0 | 332 | |
aoqi@0 | 333 | public: |
aoqi@0 | 334 | enum { SET_BREAKPOINT=0, CLEAR_BREAKPOINT=1 }; |
aoqi@0 | 335 | |
aoqi@0 | 336 | VM_ChangeBreakpoints(int operation, JvmtiBreakpoint *bp) { |
aoqi@0 | 337 | JvmtiBreakpoints& current_bps = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); |
aoqi@0 | 338 | _breakpoints = ¤t_bps; |
aoqi@0 | 339 | _bp = bp; |
aoqi@0 | 340 | _operation = operation; |
aoqi@0 | 341 | assert(bp != NULL, "bp != NULL"); |
aoqi@0 | 342 | } |
aoqi@0 | 343 | |
aoqi@0 | 344 | VMOp_Type type() const { return VMOp_ChangeBreakpoints; } |
aoqi@0 | 345 | void doit(); |
aoqi@0 | 346 | void oops_do(OopClosure* f); |
aoqi@0 | 347 | void metadata_do(void f(Metadata*)); |
aoqi@0 | 348 | }; |
aoqi@0 | 349 | |
aoqi@0 | 350 | |
aoqi@0 | 351 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 352 | // The get/set local operations must only be done by the VM thread |
aoqi@0 | 353 | // because the interpreter version needs to access oop maps, which can |
aoqi@0 | 354 | // only safely be done by the VM thread |
aoqi@0 | 355 | // |
aoqi@0 | 356 | // I'm told that in 1.5 oop maps are now protected by a lock and |
aoqi@0 | 357 | // we could get rid of the VM op |
aoqi@0 | 358 | // However if the VM op is removed then the target thread must |
aoqi@0 | 359 | // be suspended AND a lock will be needed to prevent concurrent |
aoqi@0 | 360 | // setting of locals to the same java thread. This lock is needed |
aoqi@0 | 361 | // to prevent compiledVFrames from trying to add deferred updates |
aoqi@0 | 362 | // to the thread simultaneously. |
aoqi@0 | 363 | // |
aoqi@0 | 364 | class VM_GetOrSetLocal : public VM_Operation { |
aoqi@0 | 365 | protected: |
aoqi@0 | 366 | JavaThread* _thread; |
aoqi@0 | 367 | JavaThread* _calling_thread; |
aoqi@0 | 368 | jint _depth; |
aoqi@0 | 369 | jint _index; |
aoqi@0 | 370 | BasicType _type; |
aoqi@0 | 371 | jvalue _value; |
aoqi@0 | 372 | javaVFrame* _jvf; |
aoqi@0 | 373 | bool _set; |
aoqi@0 | 374 | |
aoqi@0 | 375 | // It is possible to get the receiver out of a non-static native wrapper |
aoqi@0 | 376 | // frame. Use VM_GetReceiver to do this. |
aoqi@0 | 377 | virtual bool getting_receiver() const { return false; } |
aoqi@0 | 378 | |
aoqi@0 | 379 | jvmtiError _result; |
aoqi@0 | 380 | |
aoqi@0 | 381 | vframe* get_vframe(); |
aoqi@0 | 382 | javaVFrame* get_java_vframe(); |
aoqi@0 | 383 | bool check_slot_type(javaVFrame* vf); |
aoqi@0 | 384 | |
aoqi@0 | 385 | public: |
aoqi@0 | 386 | // Constructor for non-object getter |
aoqi@0 | 387 | VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type); |
aoqi@0 | 388 | |
aoqi@0 | 389 | // Constructor for object or non-object setter |
aoqi@0 | 390 | VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value); |
aoqi@0 | 391 | |
aoqi@0 | 392 | // Constructor for object getter |
aoqi@0 | 393 | VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, |
aoqi@0 | 394 | int index); |
aoqi@0 | 395 | |
aoqi@0 | 396 | VMOp_Type type() const { return VMOp_GetOrSetLocal; } |
aoqi@0 | 397 | jvalue value() { return _value; } |
aoqi@0 | 398 | jvmtiError result() { return _result; } |
aoqi@0 | 399 | |
aoqi@0 | 400 | bool doit_prologue(); |
aoqi@0 | 401 | void doit(); |
aoqi@0 | 402 | bool allow_nested_vm_operations() const; |
aoqi@0 | 403 | const char* name() const { return "get/set locals"; } |
aoqi@0 | 404 | |
aoqi@0 | 405 | // Check that the klass is assignable to a type with the given signature. |
aoqi@0 | 406 | static bool is_assignable(const char* ty_sign, Klass* klass, Thread* thread); |
aoqi@0 | 407 | }; |
aoqi@0 | 408 | |
aoqi@0 | 409 | class VM_GetReceiver : public VM_GetOrSetLocal { |
aoqi@0 | 410 | protected: |
aoqi@0 | 411 | virtual bool getting_receiver() const { return true; } |
aoqi@0 | 412 | |
aoqi@0 | 413 | public: |
aoqi@0 | 414 | VM_GetReceiver(JavaThread* thread, JavaThread* calling_thread, jint depth); |
aoqi@0 | 415 | const char* name() const { return "get receiver"; } |
aoqi@0 | 416 | }; |
aoqi@0 | 417 | |
aoqi@0 | 418 | |
aoqi@0 | 419 | /////////////////////////////////////////////////////////////// |
aoqi@0 | 420 | // |
aoqi@0 | 421 | // class JvmtiSuspendControl |
aoqi@0 | 422 | // |
aoqi@0 | 423 | // Convenience routines for suspending and resuming threads. |
aoqi@0 | 424 | // |
aoqi@0 | 425 | // All attempts by JVMTI to suspend and resume threads must go through the |
aoqi@0 | 426 | // JvmtiSuspendControl interface. |
aoqi@0 | 427 | // |
aoqi@0 | 428 | // methods return true if successful |
aoqi@0 | 429 | // |
aoqi@0 | 430 | class JvmtiSuspendControl : public AllStatic { |
aoqi@0 | 431 | public: |
aoqi@0 | 432 | // suspend the thread, taking it to a safepoint |
aoqi@0 | 433 | static bool suspend(JavaThread *java_thread); |
aoqi@0 | 434 | // resume the thread |
aoqi@0 | 435 | static bool resume(JavaThread *java_thread); |
aoqi@0 | 436 | |
aoqi@0 | 437 | static void print(); |
aoqi@0 | 438 | }; |
aoqi@0 | 439 | |
aoqi@0 | 440 | |
aoqi@0 | 441 | /** |
aoqi@0 | 442 | * When a thread (such as the compiler thread or VM thread) cannot post a |
aoqi@0 | 443 | * JVMTI event itself because the event needs to be posted from a Java |
aoqi@0 | 444 | * thread, then it can defer the event to the Service thread for posting. |
aoqi@0 | 445 | * The information needed to post the event is encapsulated into this class |
aoqi@0 | 446 | * and then enqueued onto the JvmtiDeferredEventQueue, where the Service |
aoqi@0 | 447 | * thread will pick it up and post it. |
aoqi@0 | 448 | * |
aoqi@0 | 449 | * This is currently only used for posting compiled-method-load and unload |
aoqi@0 | 450 | * events, which we don't want posted from the compiler thread. |
aoqi@0 | 451 | */ |
aoqi@0 | 452 | class JvmtiDeferredEvent VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 453 | friend class JvmtiDeferredEventQueue; |
aoqi@0 | 454 | private: |
aoqi@0 | 455 | typedef enum { |
aoqi@0 | 456 | TYPE_NONE, |
aoqi@0 | 457 | TYPE_COMPILED_METHOD_LOAD, |
aoqi@0 | 458 | TYPE_COMPILED_METHOD_UNLOAD, |
aoqi@0 | 459 | TYPE_DYNAMIC_CODE_GENERATED |
aoqi@0 | 460 | } Type; |
aoqi@0 | 461 | |
aoqi@0 | 462 | Type _type; |
aoqi@0 | 463 | union { |
aoqi@0 | 464 | nmethod* compiled_method_load; |
aoqi@0 | 465 | struct { |
aoqi@0 | 466 | nmethod* nm; |
aoqi@0 | 467 | jmethodID method_id; |
aoqi@0 | 468 | const void* code_begin; |
aoqi@0 | 469 | } compiled_method_unload; |
aoqi@0 | 470 | struct { |
aoqi@0 | 471 | const char* name; |
aoqi@0 | 472 | const void* code_begin; |
aoqi@0 | 473 | const void* code_end; |
aoqi@0 | 474 | } dynamic_code_generated; |
aoqi@0 | 475 | } _event_data; |
aoqi@0 | 476 | |
aoqi@0 | 477 | JvmtiDeferredEvent(Type t) : _type(t) {} |
aoqi@0 | 478 | |
aoqi@0 | 479 | public: |
aoqi@0 | 480 | |
aoqi@0 | 481 | JvmtiDeferredEvent() : _type(TYPE_NONE) {} |
aoqi@0 | 482 | |
aoqi@0 | 483 | // Factory methods |
aoqi@0 | 484 | static JvmtiDeferredEvent compiled_method_load_event(nmethod* nm) |
aoqi@0 | 485 | NOT_JVMTI_RETURN_(JvmtiDeferredEvent()); |
aoqi@0 | 486 | static JvmtiDeferredEvent compiled_method_unload_event(nmethod* nm, |
aoqi@0 | 487 | jmethodID id, const void* code) NOT_JVMTI_RETURN_(JvmtiDeferredEvent()); |
aoqi@0 | 488 | static JvmtiDeferredEvent dynamic_code_generated_event( |
aoqi@0 | 489 | const char* name, const void* begin, const void* end) |
aoqi@0 | 490 | NOT_JVMTI_RETURN_(JvmtiDeferredEvent()); |
aoqi@0 | 491 | |
aoqi@0 | 492 | // Actually posts the event. |
aoqi@0 | 493 | void post() NOT_JVMTI_RETURN; |
aoqi@0 | 494 | }; |
aoqi@0 | 495 | |
aoqi@0 | 496 | /** |
aoqi@0 | 497 | * Events enqueued on this queue wake up the Service thread which dequeues |
aoqi@0 | 498 | * and posts the events. The Service_lock is required to be held |
aoqi@0 | 499 | * when operating on the queue (except for the "pending" events). |
aoqi@0 | 500 | */ |
aoqi@0 | 501 | class JvmtiDeferredEventQueue : AllStatic { |
aoqi@0 | 502 | friend class JvmtiDeferredEvent; |
aoqi@0 | 503 | private: |
aoqi@0 | 504 | class QueueNode : public CHeapObj<mtInternal> { |
aoqi@0 | 505 | private: |
aoqi@0 | 506 | JvmtiDeferredEvent _event; |
aoqi@0 | 507 | QueueNode* _next; |
aoqi@0 | 508 | |
aoqi@0 | 509 | public: |
aoqi@0 | 510 | QueueNode(const JvmtiDeferredEvent& event) |
aoqi@0 | 511 | : _event(event), _next(NULL) {} |
aoqi@0 | 512 | |
aoqi@0 | 513 | const JvmtiDeferredEvent& event() const { return _event; } |
aoqi@0 | 514 | QueueNode* next() const { return _next; } |
aoqi@0 | 515 | |
aoqi@0 | 516 | void set_next(QueueNode* next) { _next = next; } |
aoqi@0 | 517 | }; |
aoqi@0 | 518 | |
aoqi@0 | 519 | static QueueNode* _queue_head; // Hold Service_lock to access |
aoqi@0 | 520 | static QueueNode* _queue_tail; // Hold Service_lock to access |
aoqi@0 | 521 | static volatile QueueNode* _pending_list; // Uses CAS for read/update |
aoqi@0 | 522 | |
aoqi@0 | 523 | // Transfers events from the _pending_list to the _queue. |
aoqi@0 | 524 | static void process_pending_events() NOT_JVMTI_RETURN; |
aoqi@0 | 525 | |
aoqi@0 | 526 | public: |
aoqi@0 | 527 | // Must be holding Service_lock when calling these |
aoqi@0 | 528 | static bool has_events() NOT_JVMTI_RETURN_(false); |
aoqi@0 | 529 | static void enqueue(const JvmtiDeferredEvent& event) NOT_JVMTI_RETURN; |
aoqi@0 | 530 | static JvmtiDeferredEvent dequeue() NOT_JVMTI_RETURN_(JvmtiDeferredEvent()); |
aoqi@0 | 531 | |
aoqi@0 | 532 | // Used to enqueue events without using a lock, for times (such as during |
aoqi@0 | 533 | // safepoint) when we can't or don't want to lock the Service_lock. |
aoqi@0 | 534 | // |
aoqi@0 | 535 | // Events will be held off to the side until there's a call to |
aoqi@0 | 536 | // dequeue(), enqueue(), or process_pending_events() (all of which require |
aoqi@0 | 537 | // the holding of the Service_lock), and will be enqueued at that time. |
aoqi@0 | 538 | static void add_pending_event(const JvmtiDeferredEvent&) NOT_JVMTI_RETURN; |
aoqi@0 | 539 | }; |
aoqi@0 | 540 | |
aoqi@0 | 541 | // Utility macro that checks for NULL pointers: |
aoqi@0 | 542 | #define NULL_CHECK(X, Y) if ((X) == NULL) { return (Y); } |
aoqi@0 | 543 | |
aoqi@0 | 544 | #endif // SHARE_VM_PRIMS_JVMTIIMPL_HPP |