annotate src/share/vm/prims/jvmtiImpl.hpp @ 1878:fa83ab460c54

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