|
1 /* |
|
2 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
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 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 * |
|
23 */ |
|
24 # include "incls/_precompiled.incl" |
|
25 # include "incls/_jvmtiManageCapabilities.cpp.incl" |
|
26 |
|
27 static const jint CAPA_SIZE = (JVMTI_INTERNAL_CAPABILITY_COUNT + 7) / 8; |
|
28 |
|
29 // capabilities which are always potentially available |
|
30 jvmtiCapabilities JvmtiManageCapabilities::always_capabilities; |
|
31 |
|
32 // capabilities which are potentially available during OnLoad |
|
33 jvmtiCapabilities JvmtiManageCapabilities::onload_capabilities; |
|
34 |
|
35 // capabilities which are always potentially available |
|
36 // but to only one environment |
|
37 jvmtiCapabilities JvmtiManageCapabilities::always_solo_capabilities; |
|
38 |
|
39 // capabilities which are potentially available during OnLoad |
|
40 // but to only one environment |
|
41 jvmtiCapabilities JvmtiManageCapabilities::onload_solo_capabilities; |
|
42 |
|
43 // remaining capabilities which are always potentially available |
|
44 // but to only one environment |
|
45 jvmtiCapabilities JvmtiManageCapabilities::always_solo_remaining_capabilities; |
|
46 |
|
47 // remaining capabilities which are potentially available during OnLoad |
|
48 // but to only one environment |
|
49 jvmtiCapabilities JvmtiManageCapabilities::onload_solo_remaining_capabilities; |
|
50 |
|
51 // all capabilities ever acquired |
|
52 jvmtiCapabilities JvmtiManageCapabilities::acquired_capabilities; |
|
53 |
|
54 void JvmtiManageCapabilities::initialize() { |
|
55 always_capabilities = init_always_capabilities(); |
|
56 if (JvmtiEnv::get_phase() != JVMTI_PHASE_ONLOAD) { |
|
57 recompute_always_capabilities(); |
|
58 } |
|
59 onload_capabilities = init_onload_capabilities(); |
|
60 always_solo_capabilities = init_always_solo_capabilities(); |
|
61 onload_solo_capabilities = init_onload_solo_capabilities(); |
|
62 always_solo_remaining_capabilities = init_always_solo_capabilities(); |
|
63 onload_solo_remaining_capabilities = init_onload_solo_capabilities(); |
|
64 memset(&acquired_capabilities, 0, sizeof(acquired_capabilities)); |
|
65 } |
|
66 |
|
67 // if the capability sets are initialized in the onload phase then |
|
68 // it happens before class data sharing (CDS) is initialized. If it |
|
69 // turns out that CDS gets disabled then we must adjust the always |
|
70 // capabilities. To ensure a consistent view of the capabililties |
|
71 // anything we add here should already be in the onload set. |
|
72 void JvmtiManageCapabilities::recompute_always_capabilities() { |
|
73 if (!UseSharedSpaces) { |
|
74 jvmtiCapabilities jc = always_capabilities; |
|
75 jc.can_generate_all_class_hook_events = 1; |
|
76 always_capabilities = jc; |
|
77 } |
|
78 } |
|
79 |
|
80 |
|
81 // corresponding init functions |
|
82 jvmtiCapabilities JvmtiManageCapabilities::init_always_capabilities() { |
|
83 jvmtiCapabilities jc; |
|
84 |
|
85 memset(&jc, 0, sizeof(jc)); |
|
86 jc.can_get_bytecodes = 1; |
|
87 jc.can_signal_thread = 1; |
|
88 jc.can_get_source_file_name = 1; |
|
89 jc.can_get_line_numbers = 1; |
|
90 jc.can_get_synthetic_attribute = 1; |
|
91 jc.can_get_monitor_info = 1; |
|
92 jc.can_get_constant_pool = 1; |
|
93 jc.can_generate_monitor_events = 1; |
|
94 jc.can_generate_garbage_collection_events = 1; |
|
95 jc.can_generate_compiled_method_load_events = 1; |
|
96 jc.can_generate_native_method_bind_events = 1; |
|
97 jc.can_generate_vm_object_alloc_events = 1; |
|
98 if (os::is_thread_cpu_time_supported()) { |
|
99 jc.can_get_current_thread_cpu_time = 1; |
|
100 jc.can_get_thread_cpu_time = 1; |
|
101 } |
|
102 jc.can_redefine_classes = 1; |
|
103 jc.can_redefine_any_class = 1; |
|
104 jc.can_retransform_classes = 1; |
|
105 jc.can_retransform_any_class = 1; |
|
106 jc.can_set_native_method_prefix = 1; |
|
107 jc.can_tag_objects = 1; |
|
108 jc.can_generate_object_free_events = 1; |
|
109 jc.can_generate_resource_exhaustion_heap_events = 1; |
|
110 jc.can_generate_resource_exhaustion_threads_events = 1; |
|
111 return jc; |
|
112 } |
|
113 |
|
114 jvmtiCapabilities JvmtiManageCapabilities::init_onload_capabilities() { |
|
115 jvmtiCapabilities jc; |
|
116 |
|
117 memset(&jc, 0, sizeof(jc)); |
|
118 jc.can_pop_frame = 1; |
|
119 jc.can_force_early_return = 1; |
|
120 jc.can_get_source_debug_extension = 1; |
|
121 jc.can_access_local_variables = 1; |
|
122 jc.can_maintain_original_method_order = 1; |
|
123 jc.can_generate_all_class_hook_events = 1; |
|
124 jc.can_generate_single_step_events = 1; |
|
125 jc.can_generate_exception_events = 1; |
|
126 jc.can_generate_frame_pop_events = 1; |
|
127 jc.can_generate_method_entry_events = 1; |
|
128 jc.can_generate_method_exit_events = 1; |
|
129 jc.can_get_owned_monitor_info = 1; |
|
130 jc.can_get_owned_monitor_stack_depth_info = 1; |
|
131 jc.can_get_current_contended_monitor = 1; |
|
132 // jc.can_get_monitor_info = 1; |
|
133 jc.can_tag_objects = 1; // TODO: this should have been removed |
|
134 jc.can_generate_object_free_events = 1; // TODO: this should have been removed |
|
135 return jc; |
|
136 } |
|
137 |
|
138 |
|
139 jvmtiCapabilities JvmtiManageCapabilities::init_always_solo_capabilities() { |
|
140 jvmtiCapabilities jc; |
|
141 |
|
142 memset(&jc, 0, sizeof(jc)); |
|
143 jc.can_suspend = 1; |
|
144 return jc; |
|
145 } |
|
146 |
|
147 |
|
148 jvmtiCapabilities JvmtiManageCapabilities::init_onload_solo_capabilities() { |
|
149 jvmtiCapabilities jc; |
|
150 |
|
151 memset(&jc, 0, sizeof(jc)); |
|
152 jc.can_generate_field_modification_events = 1; |
|
153 jc.can_generate_field_access_events = 1; |
|
154 jc.can_generate_breakpoint_events = 1; |
|
155 return jc; |
|
156 } |
|
157 |
|
158 |
|
159 jvmtiCapabilities *JvmtiManageCapabilities::either(const jvmtiCapabilities *a, const jvmtiCapabilities *b, |
|
160 jvmtiCapabilities *result) { |
|
161 char *ap = (char *)a; |
|
162 char *bp = (char *)b; |
|
163 char *resultp = (char *)result; |
|
164 |
|
165 for (int i = 0; i < CAPA_SIZE; ++i) { |
|
166 *resultp++ = *ap++ | *bp++; |
|
167 } |
|
168 |
|
169 return result; |
|
170 } |
|
171 |
|
172 |
|
173 jvmtiCapabilities *JvmtiManageCapabilities::both(const jvmtiCapabilities *a, const jvmtiCapabilities *b, |
|
174 jvmtiCapabilities *result) { |
|
175 char *ap = (char *)a; |
|
176 char *bp = (char *)b; |
|
177 char *resultp = (char *)result; |
|
178 |
|
179 for (int i = 0; i < CAPA_SIZE; ++i) { |
|
180 *resultp++ = *ap++ & *bp++; |
|
181 } |
|
182 |
|
183 return result; |
|
184 } |
|
185 |
|
186 |
|
187 jvmtiCapabilities *JvmtiManageCapabilities::exclude(const jvmtiCapabilities *a, const jvmtiCapabilities *b, |
|
188 jvmtiCapabilities *result) { |
|
189 char *ap = (char *)a; |
|
190 char *bp = (char *)b; |
|
191 char *resultp = (char *)result; |
|
192 |
|
193 for (int i = 0; i < CAPA_SIZE; ++i) { |
|
194 *resultp++ = *ap++ & ~*bp++; |
|
195 } |
|
196 |
|
197 return result; |
|
198 } |
|
199 |
|
200 |
|
201 bool JvmtiManageCapabilities::has_some(const jvmtiCapabilities *a) { |
|
202 char *ap = (char *)a; |
|
203 |
|
204 for (int i = 0; i < CAPA_SIZE; ++i) { |
|
205 if (*ap++ != 0) { |
|
206 return true; |
|
207 } |
|
208 } |
|
209 |
|
210 return false; |
|
211 } |
|
212 |
|
213 |
|
214 void JvmtiManageCapabilities::copy_capabilities(const jvmtiCapabilities *from, jvmtiCapabilities *to) { |
|
215 char *ap = (char *)from; |
|
216 char *resultp = (char *)to; |
|
217 |
|
218 for (int i = 0; i < CAPA_SIZE; ++i) { |
|
219 *resultp++ = *ap++; |
|
220 } |
|
221 } |
|
222 |
|
223 |
|
224 void JvmtiManageCapabilities::get_potential_capabilities(const jvmtiCapabilities *current, |
|
225 const jvmtiCapabilities *prohibited, |
|
226 jvmtiCapabilities *result) { |
|
227 // exclude prohibited capabilities, must be before adding current |
|
228 exclude(&always_capabilities, prohibited, result); |
|
229 |
|
230 // must include current since it may possess solo capabilities and now prohibited |
|
231 either(result, current, result); |
|
232 |
|
233 // add other remaining |
|
234 either(result, &always_solo_remaining_capabilities, result); |
|
235 |
|
236 // if this is during OnLoad more capabilities are available |
|
237 if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) { |
|
238 either(result, &onload_capabilities, result); |
|
239 either(result, &onload_solo_remaining_capabilities, result); |
|
240 } |
|
241 } |
|
242 |
|
243 jvmtiError JvmtiManageCapabilities::add_capabilities(const jvmtiCapabilities *current, |
|
244 const jvmtiCapabilities *prohibited, |
|
245 const jvmtiCapabilities *desired, |
|
246 jvmtiCapabilities *result) { |
|
247 // check that the capabilities being added are potential capabilities |
|
248 jvmtiCapabilities temp; |
|
249 get_potential_capabilities(current, prohibited, &temp); |
|
250 if (has_some(exclude(desired, &temp, &temp))) { |
|
251 return JVMTI_ERROR_NOT_AVAILABLE; |
|
252 } |
|
253 |
|
254 // add to the set of ever acquired capabilities |
|
255 either(&acquired_capabilities, desired, &acquired_capabilities); |
|
256 |
|
257 // onload capabilities that got added are now permanent - so, also remove from onload |
|
258 both(&onload_capabilities, desired, &temp); |
|
259 either(&always_capabilities, &temp, &always_capabilities); |
|
260 exclude(&onload_capabilities, &temp, &onload_capabilities); |
|
261 |
|
262 // same for solo capabilities (transferred capabilities in the remaining sets handled as part of standard grab - below) |
|
263 both(&onload_solo_capabilities, desired, &temp); |
|
264 either(&always_solo_capabilities, &temp, &always_solo_capabilities); |
|
265 exclude(&onload_solo_capabilities, &temp, &onload_solo_capabilities); |
|
266 |
|
267 // remove solo capabilities that are now taken |
|
268 exclude(&always_solo_remaining_capabilities, desired, &always_solo_remaining_capabilities); |
|
269 exclude(&onload_solo_remaining_capabilities, desired, &onload_solo_remaining_capabilities); |
|
270 |
|
271 // return the result |
|
272 either(current, desired, result); |
|
273 |
|
274 update(); |
|
275 |
|
276 return JVMTI_ERROR_NONE; |
|
277 } |
|
278 |
|
279 |
|
280 void JvmtiManageCapabilities::relinquish_capabilities(const jvmtiCapabilities *current, |
|
281 const jvmtiCapabilities *unwanted, |
|
282 jvmtiCapabilities *result) { |
|
283 jvmtiCapabilities to_trash; |
|
284 jvmtiCapabilities temp; |
|
285 |
|
286 // can't give up what you don't have |
|
287 both(current, unwanted, &to_trash); |
|
288 |
|
289 // restore solo capabilities but only those that belong |
|
290 either(&always_solo_remaining_capabilities, both(&always_solo_capabilities, &to_trash, &temp), |
|
291 &always_solo_remaining_capabilities); |
|
292 either(&onload_solo_remaining_capabilities, both(&onload_solo_capabilities, &to_trash, &temp), |
|
293 &onload_solo_remaining_capabilities); |
|
294 |
|
295 update(); |
|
296 |
|
297 // return the result |
|
298 exclude(current, unwanted, result); |
|
299 } |
|
300 |
|
301 |
|
302 void JvmtiManageCapabilities::update() { |
|
303 jvmtiCapabilities avail; |
|
304 |
|
305 // all capabilities |
|
306 either(&always_capabilities, &always_solo_capabilities, &avail); |
|
307 |
|
308 bool interp_events = |
|
309 avail.can_generate_field_access_events || |
|
310 avail.can_generate_field_modification_events || |
|
311 avail.can_generate_single_step_events || |
|
312 avail.can_generate_frame_pop_events || |
|
313 avail.can_generate_method_entry_events || |
|
314 avail.can_generate_method_exit_events; |
|
315 bool enter_all_methods = |
|
316 interp_events || |
|
317 avail.can_generate_breakpoint_events; |
|
318 UseFastEmptyMethods = !enter_all_methods; |
|
319 UseFastAccessorMethods = !enter_all_methods; |
|
320 |
|
321 if (avail.can_generate_breakpoint_events) { |
|
322 RewriteFrequentPairs = false; |
|
323 } |
|
324 |
|
325 // If can_redefine_classes is enabled in the onload phase then we know that the |
|
326 // dependency information recorded by the compiler is complete. |
|
327 if ((avail.can_redefine_classes || avail.can_retransform_classes) && |
|
328 JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) { |
|
329 JvmtiExport::set_all_dependencies_are_recorded(true); |
|
330 } |
|
331 |
|
332 JvmtiExport::set_can_get_source_debug_extension(avail.can_get_source_debug_extension); |
|
333 JvmtiExport::set_can_examine_or_deopt_anywhere( |
|
334 avail.can_generate_breakpoint_events || |
|
335 interp_events || |
|
336 avail.can_redefine_classes || |
|
337 avail.can_retransform_classes || |
|
338 avail.can_access_local_variables || |
|
339 avail.can_get_owned_monitor_info || |
|
340 avail.can_get_current_contended_monitor || |
|
341 avail.can_get_monitor_info || |
|
342 avail.can_get_owned_monitor_stack_depth_info); |
|
343 JvmtiExport::set_can_maintain_original_method_order(avail.can_maintain_original_method_order); |
|
344 JvmtiExport::set_can_post_interpreter_events(interp_events); |
|
345 JvmtiExport::set_can_hotswap_or_post_breakpoint( |
|
346 avail.can_generate_breakpoint_events || |
|
347 avail.can_redefine_classes || |
|
348 avail.can_retransform_classes); |
|
349 JvmtiExport::set_can_modify_any_class( |
|
350 avail.can_generate_breakpoint_events || |
|
351 avail.can_generate_all_class_hook_events); |
|
352 JvmtiExport::set_can_walk_any_space( |
|
353 avail.can_tag_objects); // disable sharing in onload phase |
|
354 JvmtiExport::set_can_access_local_variables( |
|
355 avail.can_access_local_variables || |
|
356 avail.can_redefine_classes || |
|
357 avail.can_retransform_classes); |
|
358 JvmtiExport::set_can_post_exceptions( |
|
359 avail.can_generate_exception_events || |
|
360 avail.can_generate_frame_pop_events || |
|
361 avail.can_generate_method_exit_events); |
|
362 JvmtiExport::set_can_post_breakpoint(avail.can_generate_breakpoint_events); |
|
363 JvmtiExport::set_can_post_field_access(avail.can_generate_field_access_events); |
|
364 JvmtiExport::set_can_post_field_modification(avail.can_generate_field_modification_events); |
|
365 JvmtiExport::set_can_post_method_entry(avail.can_generate_method_entry_events); |
|
366 JvmtiExport::set_can_post_method_exit(avail.can_generate_method_exit_events || |
|
367 avail.can_generate_frame_pop_events); |
|
368 JvmtiExport::set_can_pop_frame(avail.can_pop_frame); |
|
369 JvmtiExport::set_can_force_early_return(avail.can_force_early_return); |
|
370 JvmtiExport::set_should_clean_up_heap_objects(avail.can_generate_breakpoint_events); |
|
371 } |
|
372 |
|
373 #ifndef PRODUCT |
|
374 |
|
375 void JvmtiManageCapabilities:: print(const jvmtiCapabilities* cap) { |
|
376 tty->print_cr("----- capabilities -----"); |
|
377 if (cap->can_tag_objects) |
|
378 tty->print_cr("can_tag_objects"); |
|
379 if (cap->can_generate_field_modification_events) |
|
380 tty->print_cr("can_generate_field_modification_events"); |
|
381 if (cap->can_generate_field_access_events) |
|
382 tty->print_cr("can_generate_field_access_events"); |
|
383 if (cap->can_get_bytecodes) |
|
384 tty->print_cr("can_get_bytecodes"); |
|
385 if (cap->can_get_synthetic_attribute) |
|
386 tty->print_cr("can_get_synthetic_attribute"); |
|
387 if (cap->can_get_owned_monitor_info) |
|
388 tty->print_cr("can_get_owned_monitor_info"); |
|
389 if (cap->can_get_current_contended_monitor) |
|
390 tty->print_cr("can_get_current_contended_monitor"); |
|
391 if (cap->can_get_monitor_info) |
|
392 tty->print_cr("can_get_monitor_info"); |
|
393 if (cap->can_get_constant_pool) |
|
394 tty->print_cr("can_get_constant_pool"); |
|
395 if (cap->can_pop_frame) |
|
396 tty->print_cr("can_pop_frame"); |
|
397 if (cap->can_force_early_return) |
|
398 tty->print_cr("can_force_early_return"); |
|
399 if (cap->can_redefine_classes) |
|
400 tty->print_cr("can_redefine_classes"); |
|
401 if (cap->can_retransform_classes) |
|
402 tty->print_cr("can_retransform_classes"); |
|
403 if (cap->can_signal_thread) |
|
404 tty->print_cr("can_signal_thread"); |
|
405 if (cap->can_get_source_file_name) |
|
406 tty->print_cr("can_get_source_file_name"); |
|
407 if (cap->can_get_line_numbers) |
|
408 tty->print_cr("can_get_line_numbers"); |
|
409 if (cap->can_get_source_debug_extension) |
|
410 tty->print_cr("can_get_source_debug_extension"); |
|
411 if (cap->can_access_local_variables) |
|
412 tty->print_cr("can_access_local_variables"); |
|
413 if (cap->can_maintain_original_method_order) |
|
414 tty->print_cr("can_maintain_original_method_order"); |
|
415 if (cap->can_generate_single_step_events) |
|
416 tty->print_cr("can_generate_single_step_events"); |
|
417 if (cap->can_generate_exception_events) |
|
418 tty->print_cr("can_generate_exception_events"); |
|
419 if (cap->can_generate_frame_pop_events) |
|
420 tty->print_cr("can_generate_frame_pop_events"); |
|
421 if (cap->can_generate_breakpoint_events) |
|
422 tty->print_cr("can_generate_breakpoint_events"); |
|
423 if (cap->can_suspend) |
|
424 tty->print_cr("can_suspend"); |
|
425 if (cap->can_redefine_any_class ) |
|
426 tty->print_cr("can_redefine_any_class"); |
|
427 if (cap->can_retransform_any_class ) |
|
428 tty->print_cr("can_retransform_any_class"); |
|
429 if (cap->can_get_current_thread_cpu_time) |
|
430 tty->print_cr("can_get_current_thread_cpu_time"); |
|
431 if (cap->can_get_thread_cpu_time) |
|
432 tty->print_cr("can_get_thread_cpu_time"); |
|
433 if (cap->can_generate_method_entry_events) |
|
434 tty->print_cr("can_generate_method_entry_events"); |
|
435 if (cap->can_generate_method_exit_events) |
|
436 tty->print_cr("can_generate_method_exit_events"); |
|
437 if (cap->can_generate_all_class_hook_events) |
|
438 tty->print_cr("can_generate_all_class_hook_events"); |
|
439 if (cap->can_generate_compiled_method_load_events) |
|
440 tty->print_cr("can_generate_compiled_method_load_events"); |
|
441 if (cap->can_generate_monitor_events) |
|
442 tty->print_cr("can_generate_monitor_events"); |
|
443 if (cap->can_generate_vm_object_alloc_events) |
|
444 tty->print_cr("can_generate_vm_object_alloc_events"); |
|
445 if (cap->can_generate_native_method_bind_events) |
|
446 tty->print_cr("can_generate_native_method_bind_events"); |
|
447 if (cap->can_generate_garbage_collection_events) |
|
448 tty->print_cr("can_generate_garbage_collection_events"); |
|
449 if (cap->can_generate_object_free_events) |
|
450 tty->print_cr("can_generate_object_free_events"); |
|
451 if (cap->can_generate_resource_exhaustion_heap_events) |
|
452 tty->print_cr("can_generate_resource_exhaustion_heap_events"); |
|
453 if (cap->can_generate_resource_exhaustion_threads_events) |
|
454 tty->print_cr("can_generate_resource_exhaustion_threads_events"); |
|
455 } |
|
456 |
|
457 #endif |