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