1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/services/dtraceAttacher.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,138 @@ 1.4 +/* 1.5 + * Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_dtraceAttacher.cpp.incl" 1.30 + 1.31 +#ifdef SOLARIS 1.32 + 1.33 +class VM_DeoptimizeTheWorld : public VM_Operation { 1.34 + public: 1.35 + VMOp_Type type() const { 1.36 + return VMOp_DeoptimizeTheWorld; 1.37 + } 1.38 + void doit() { 1.39 + CodeCache::mark_all_nmethods_for_deoptimization(); 1.40 + ResourceMark rm; 1.41 + DeoptimizationMarker dm; 1.42 + // Deoptimize all activations depending on marked methods 1.43 + Deoptimization::deoptimize_dependents(); 1.44 + 1.45 + // Mark the dependent methods non entrant 1.46 + CodeCache::make_marked_nmethods_not_entrant(); 1.47 + } 1.48 +}; 1.49 + 1.50 +static void set_bool_flag(const char* flag, bool value) { 1.51 + CommandLineFlags::boolAtPut((char*)flag, strlen(flag), &value, 1.52 + ATTACH_ON_DEMAND); 1.53 +} 1.54 + 1.55 +// Enable only the "fine grained" flags. Do *not* touch 1.56 +// the overall "ExtendedDTraceProbes" flag. 1.57 +void DTrace::enable_dprobes(int probes) { 1.58 + bool changed = false; 1.59 + if (!DTraceAllocProbes && (probes & DTRACE_ALLOC_PROBES)) { 1.60 + set_bool_flag("DTraceAllocProbes", true); 1.61 + changed = true; 1.62 + } 1.63 + if (!DTraceMethodProbes && (probes & DTRACE_METHOD_PROBES)) { 1.64 + set_bool_flag("DTraceMethodProbes", true); 1.65 + changed = true; 1.66 + } 1.67 + if (!DTraceMonitorProbes && (probes & DTRACE_MONITOR_PROBES)) { 1.68 + set_bool_flag("DTraceMonitorProbes", true); 1.69 + changed = true; 1.70 + } 1.71 + 1.72 + if (changed) { 1.73 + // one or more flags changed, need to deoptimize 1.74 + VM_DeoptimizeTheWorld op; 1.75 + VMThread::execute(&op); 1.76 + } 1.77 +} 1.78 + 1.79 +// Disable only the "fine grained" flags. Do *not* touch 1.80 +// the overall "ExtendedDTraceProbes" flag. 1.81 +void DTrace::disable_dprobes(int probes) { 1.82 + bool changed = false; 1.83 + if (DTraceAllocProbes && (probes & DTRACE_ALLOC_PROBES)) { 1.84 + set_bool_flag("DTraceAllocProbes", false); 1.85 + changed = true; 1.86 + } 1.87 + if (DTraceMethodProbes && (probes & DTRACE_METHOD_PROBES)) { 1.88 + set_bool_flag("DTraceMethodProbes", false); 1.89 + changed = true; 1.90 + } 1.91 + if (DTraceMonitorProbes && (probes & DTRACE_MONITOR_PROBES)) { 1.92 + set_bool_flag("DTraceMonitorProbes", false); 1.93 + changed = true; 1.94 + } 1.95 + if (changed) { 1.96 + // one or more flags changed, need to deoptimize 1.97 + VM_DeoptimizeTheWorld op; 1.98 + VMThread::execute(&op); 1.99 + } 1.100 +} 1.101 + 1.102 +// Do clean-up on "all door clients detached" event. 1.103 +void DTrace::detach_all_clients() { 1.104 + /* 1.105 + * We restore the state of the fine grained flags 1.106 + * to be consistent with overall ExtendedDTraceProbes. 1.107 + * This way, we will honour command line setting or the 1.108 + * last explicit modification of ExtendedDTraceProbes by 1.109 + * a call to set_extended_dprobes. 1.110 + */ 1.111 + if (ExtendedDTraceProbes) { 1.112 + enable_dprobes(DTRACE_ALL_PROBES); 1.113 + } else { 1.114 + disable_dprobes(DTRACE_ALL_PROBES); 1.115 + } 1.116 +} 1.117 + 1.118 +void DTrace::set_extended_dprobes(bool flag) { 1.119 + // explicit setting of ExtendedDTraceProbes flag 1.120 + set_bool_flag("ExtendedDTraceProbes", flag); 1.121 + 1.122 + // make sure that the fine grained flags reflect the change. 1.123 + if (flag) { 1.124 + enable_dprobes(DTRACE_ALL_PROBES); 1.125 + } else { 1.126 + /* 1.127 + * FIXME: Revisit this: currently all-client-detach detection 1.128 + * does not work and hence disabled. The following scheme does 1.129 + * not work. So, we have to disable fine-grained flags here. 1.130 + * 1.131 + * disable_dprobes call has to be delayed till next "detach all "event. 1.132 + * This is to be done so that concurrent DTrace clients that may 1.133 + * have enabled one or more fine grained dprobes and may be running 1.134 + * still. On "detach all" clients event, we would sync ExtendedDTraceProbes 1.135 + * with fine grained flags which would take care of disabling fine grained flags. 1.136 + */ 1.137 + disable_dprobes(DTRACE_ALL_PROBES); 1.138 + } 1.139 +} 1.140 + 1.141 +#endif /* SOLARIS */